diff --git a/bootloader/stage1.asm b/bootloader/stage1.asm index 1c557c4d..0595d02d 100644 --- a/bootloader/stage1.asm +++ b/bootloader/stage1.asm @@ -14,9 +14,9 @@ jmp rm_start ; Start in real mode rm_start: ; Set stack space (4K) and stack segment - mov ax, 0x70 + xor ax, ax mov ss, ax - mov sp, 2048 + mov sp, 0x4000 ; Set data segment mov ax, 0x7C0 @@ -90,7 +90,7 @@ rm_start: ; Run the stage 2 - jmp dword 0x90:0x0 + jmp dword 0x410:0x0 extensions_not_supported: mov si, extensions_not_supported_msg @@ -115,7 +115,7 @@ DAP: .null db 0x0 .count dw 2 .offset dw 0 -.segment dw 0x90 +.segment dw 0x410 .lba dd 1 .lba48 dd 0 diff --git a/bootloader/stage2.asm b/bootloader/stage2.asm index 6d10250a..9aa9baa2 100644 --- a/bootloader/stage2.asm +++ b/bootloader/stage2.asm @@ -12,7 +12,8 @@ jmp second_step %include "intel_16.asm" %include "sectors.asm" -KERNEL_BASE equ 0x200 ; 0x200:0x0 = 0x2000 +FREE_BASE equ 0x4500 +KERNEL_BASE equ 0x600 ; 0x600:0x0 (0x6000) DAP: .size db 0x10 @@ -23,10 +24,10 @@ DAP: .lba dd 0 .lba48 dd 0 -; Loaded at 0x90:0x0 +; Loaded at 0x410:0x0 (0x4100) second_step: ; Set data segment - mov ax, 0x90 + mov ax, 0x410 mov ds, ax ; Used for disk access @@ -39,7 +40,7 @@ second_step: ; 1. Read the MBR to get partition table mov byte [DAP.count], 1 - mov word [DAP.offset], 0x1000 + mov word [DAP.offset], FREE_BASE mov word [DAP.segment], 0 mov dword [DAP.lba], 0 @@ -50,13 +51,13 @@ second_step: jc read_failed - mov ax, [gs:(0x1000 + 446 + 8)] + mov ax, [gs:(FREE_BASE + 446 + 8)] mov [partition_start], ax ; 2. Read the VBR of the partition to get FAT informations mov byte [DAP.count], 1 - mov word [DAP.offset], 0x1000 + mov word [DAP.offset], FREE_BASE mov word [DAP.segment], 0 mov di, [partition_start] @@ -69,19 +70,19 @@ second_step: jc read_failed - mov ah, [gs:(0x1000 + 13)] + mov ah, [gs:(FREE_BASE + 13)] mov [sectors_per_cluster], ah - mov ax, [gs:(0x1000 + 14)] + mov ax, [gs:(FREE_BASE + 14)] mov [reserved_sectors], ax - mov ah, [gs:(0x1000 + 16)] + mov ah, [gs:(FREE_BASE + 16)] mov [number_of_fat], ah - mov ax, [gs:(0x1000 + 36)] + mov ax, [gs:(FREE_BASE + 36)] mov [sectors_per_fat], ax - mov ax, [gs:(0x1000 + 44)] + mov ax, [gs:(FREE_BASE + 44)] mov [root_dir_start], ax ; fat_begin = partition_start + reserved_sectors @@ -108,7 +109,7 @@ second_step: mov ah, [sectors_per_cluster] mov byte [DAP.count], ah - mov word [DAP.offset], 0x1000 + mov word [DAP.offset], FREE_BASE mov word [DAP.segment], 0 ; Compute LBA from root_dir_start @@ -128,7 +129,7 @@ second_step: jc read_failed - mov si, 0x1000 + mov si, FREE_BASE xor cx, cx .next: @@ -265,7 +266,7 @@ second_step: ; Read the FAT sector mov word [DAP.count], 1 - mov word [DAP.offset], 0x100 + mov word [DAP.offset], FREE_BASE mov word [DAP.segment], 0x0 mov word [DAP.lba], ax @@ -281,9 +282,9 @@ second_step: shl si, 2 ; cluster low - mov ax, [gs:(0x100 + si)] + mov ax, [gs:(FREE_BASE + si)] ; cluster high - mov bx, [gs:(0x100 + si + 2)] + mov bx, [gs:(FREE_BASE + si + 2)] cmp bx, 0x0FFF jl .ok diff --git a/kernel/linker.ld b/kernel/linker.ld index 273a355d..c7dc4fc1 100644 --- a/kernel/linker.ld +++ b/kernel/linker.ld @@ -2,14 +2,29 @@ ENTRY(kernel_main) SECTIONS { - /* This is where the micro kernel will load the code */ - . = 0x2000; + /* This is where the bootloader will load the code */ + . = 0x6000; .text_16 BLOCK(512) : ALIGN(512) { boot_16_64.o(.text) } + .rodata_16 BLOCK(512) : ALIGN(512) + { + boot_16_64.o(.rodata) + } + + .bss_16 BLOCK(512) : ALIGN(512) + { + boot_16_64.o(.bss) + } + + .data_16 BLOCK(512) : ALIGN(512) + { + boot_16_64.o(.data) + } + .text_32 BLOCK(512) : ALIGN(512) { boot_32_64.o(.text) diff --git a/kernel/src/boot/boot_16.cpp b/kernel/src/boot/boot_16.cpp index cf609181..3e0bb614 100644 --- a/kernel/src/boot/boot_16.cpp +++ b/kernel/src/boot/boot_16.cpp @@ -31,6 +31,10 @@ typedef uint64_t size_t; #define CODE_16 #include "e820.hpp" //Just for the address of the e820 map + +e820::bios_e820_entry e820::bios_e820_entries[e820::MAX_E820_ENTRIES]; +int16_t e820::bios_e820_entry_count = 0; + namespace { struct gdt_ptr { diff --git a/kernel/src/e820.cpp b/kernel/src/e820.cpp index 5ae2e17f..b239be2b 100644 --- a/kernel/src/e820.cpp +++ b/kernel/src/e820.cpp @@ -7,10 +7,6 @@ #include "e820.hpp" - -e820::bios_e820_entry e820::bios_e820_entries[e820::MAX_E820_ENTRIES]; -int16_t e820::bios_e820_entry_count = 0; - namespace { e820::mmapentry e820_mmap[e820::MAX_E820_ENTRIES];