diff options
| author | 0x221E <0x221E@0xinfinity.dev> | 2026-06-11 20:10:31 +0200 |
|---|---|---|
| committer | 0x221E <0x221E@0xinfinity.dev> | 2026-06-11 20:11:56 +0200 |
| commit | 6d559b7e50dbab428d324b4ddaed9db7a8ced887 (patch) | |
| tree | c2e807a19d2d0b6054e13a6d3ece16750796198d /stage1 | |
| download | tmpbootloader-master.tar.gz | |
Diffstat (limited to 'stage1')
| -rw-r--r-- | stage1/32bit.c | 22 | ||||
| -rwxr-xr-x | stage1/32bit.o | bin | 0 -> 796 bytes | |||
| -rw-r--r-- | stage1/entry.S | 56 | ||||
| -rw-r--r-- | stage1/stage1.S | 84 | ||||
| -rw-r--r-- | stage1/stage1.h | 8 |
5 files changed, 170 insertions, 0 deletions
diff --git a/stage1/32bit.c b/stage1/32bit.c new file mode 100644 index 0000000..1e4a7ef --- /dev/null +++ b/stage1/32bit.c @@ -0,0 +1,22 @@ +#define STAGE1 +#include "stage1.h" + +#include <stddef.h> +#include <stdint.h> +#include <vga.h> +#include <printk.h> +#include <string.h> + +void centry(void) +{ + vga_setup(25,80); + + uint8_t color = vga_color(0xF, 0); + + write("Bootloader is set to 32-bit mode.", color); + + while (1) { + asm ("cli"); + asm ("hlt"); + } +} diff --git a/stage1/32bit.o b/stage1/32bit.o Binary files differnew file mode 100755 index 0000000..bd221e3 --- /dev/null +++ b/stage1/32bit.o diff --git a/stage1/entry.S b/stage1/entry.S new file mode 100644 index 0000000..81390d9 --- /dev/null +++ b/stage1/entry.S @@ -0,0 +1,56 @@ +.intel_syntax noprefix + +.section .mbr, "ax" + +.extern _stack_start +.extern _stack_end +.extern centry + +.global _start +.code16 + +_start: + xor ax, ax + mov ds, ax + jmp 0x0:_entry + +_entry: + mov ah, 0x42 + mov si, offset dap + + int 0x13 + + jc error + + mov ah, 0x0E + mov al, 'S' + mov bh, 0x0 + mov bl, 0x0 + + int 0x10 + + jmp 0x0:stage1_sector + + cli + hlt + +error: + mov ah, 0x0e + mov al, 'E' + mov bh, 0x0 + mov bl, 0x0 + + int 0x10 + + cli + hlt + +.section .mbr_data, "aw" + +dap: + .byte 0x10 + .byte 0 + .word 14 + .word 0x7e00 + .word 0x0 + .quad 1 diff --git a/stage1/stage1.S b/stage1/stage1.S new file mode 100644 index 0000000..e11e36b --- /dev/null +++ b/stage1/stage1.S @@ -0,0 +1,84 @@ +.intel_syntax noprefix +.code16 + +.extern _stack_start +.extern _stack_end + +.global stage1_sector + +.section .stage1, "ax" + +stage1_sector: + xor ax, ax + + mov ah, 0x0e + mov al, 'C' + mov bh, 0x0 + mov bl, 0x0 + + int 0x10 + + cli + + lgdt gdtr + + mov eax, cr0 + or eax, (1 << 0) + mov cr0, eax + + jmp 0x8:_32_start + + cli + hlt + +.code32 +_32_start: + mov eax, 0x10 + + mov ds, ax + mov ss, ax + mov es, ax + mov fs, ax + mov gs, ax + + jmp 0x8:_32_entry + + cli + hlt + +_32_entry: + mov eax, offset _stack_start + mov ebp, eax + mov eax, offset _stack_end + mov esp, eax + + call centry + + cli + hlt + +.code16 +.section .stage1_ro, "aw" + +gdt: + .quad 0x0 // Null seg + + .word 0xFFFF // Code seg + .word 0x0000 + .byte 0x0 + .byte 0b10011011 // A=1 RW=1 DC=0 E=1 S=1 DPL=00 P=1 + .byte 0b11001111 + .byte 0x0000 + + .word 0xFFFF // Data Seg + .word 0x0000 + .byte 0x0 + .byte 0b10010011 // A=1 RW=1 DC=0 E=0 S=1 DPL=00 P=1 + .byte 0b11001111 + .byte 0x0000 + +end_gdt: + +gdtr: + .word end_gdt - gdt - 1 + .long gdt diff --git a/stage1/stage1.h b/stage1/stage1.h new file mode 100644 index 0000000..cf29acb --- /dev/null +++ b/stage1/stage1.h @@ -0,0 +1,8 @@ +#ifndef STAGE1_H +#define STAGE1_H + +#include <defs.h> + +void centry(void) BLSEC_TEXT; + +#endif |
