diff --git a/SoraOS b/SoraOS index 8601973..79db673 100755 Binary files a/SoraOS and b/SoraOS differ diff --git a/boot.asm b/boot.asm index c7cd83b..933bccd 100644 --- a/boot.asm +++ b/boot.asm @@ -21,6 +21,18 @@ _start: mov eax, pml4_table mov cr3, eax ; Load the PML4 table into CR3 + ; Link PML4 -> PDPT + mov dword [pml4_table], pdpt_table + 0x3 + mov dword [pml4_table + 4], 0x0 + + ; Link PDPT -> PD + mov dword [pdpt_table], pd_table + 0x3 + mov dword [pdpt_table + 4], 0x0 + + ; Link PD -> 2MB Physical Page 0 + mov dword [pd_table], 0x83 + mov dword [pd_table + 4], 0x0 + mov eax, cr4 or eax, 0x20 ; Enable PAE mov cr4, eax @@ -45,15 +57,6 @@ kernel_stack_bottom: resb 16 * 1024 kernel_stack_top: -gdt_ptr: - dw 0 ; Limit (set by linker/code later) - dq 0 ; Base Address (set by linker/code later) -gdt_start: ; Start of the actual GDT entries - ; Entry 0: Null Descriptor - dq 0x0000000000000000 - dq 0x00AF9A000000FFFF - dq 0x00AF92000000FFFF -gdt_end: pml4_table: ; Define a simple PML4 table here (identity mapping for simplicity) @@ -61,6 +64,25 @@ pml4_table: resb 4096 ; Reserve 4 KB for the PML4 table pml4_end: +pdpt_table: + resb 4096 ; Reserve 4 KB for the PDPT table +pdpt_end: + +pd_table: + resb 4096 ; Reserve 4 KB for the PD table +pd_end: + +section .data +gdt_ptr: + dw (gdt_end - gdt_start - 1) ; Limit (set by linker/code later) + dq gdt_start ; Base Address (set by linker/code later) +gdt_start: ; Start of the actual GDT entries + ; Entry 0: Null Descriptor + dq 0x0000000000000000 + dq 0x00AF9A000000FFFF + dq 0x00AF92000000FFFF +gdt_end: + section .text [bits 64] ; Tell NASM to assemble in 64-bit mode diff --git a/build.sh b/build.sh index e6b90e2..1e54115 100755 --- a/build.sh +++ b/build.sh @@ -1,8 +1,8 @@ echo ">>> Compiling bootloader" -nasm boot.asm -o boot.o -f elf64 +nasm boot.asm -o boot.o -f elf32 echo ">>> Compiling kernel" -gcc kernel.c -o kernel.o -c -m64 -ffreestanding -nostdlib +gcc kernel.c -o kernel.o -c -m32 -ffreestanding -nostdlib -no-pie echo ">>> Linking kernel" -ld -T linker.ld -o SoraOS boot.o kernel.o +gcc -m32 -nostdlib -no-pie -T linker.ld -o SoraOS boot.o kernel.o diff --git a/kernel.o b/kernel.o index ddcc3d6..25eef42 100644 Binary files a/kernel.o and b/kernel.o differ diff --git a/linker.ld b/linker.ld index 2dce285..28df9ed 100644 --- a/linker.ld +++ b/linker.ld @@ -1,3 +1,4 @@ +OUTPUT_FORMAT(elf32-i386) ENTRY(_start) SECTIONS