Fix: Fixed QEMU and Bootloader errors (started from 32-bit -> 64-bit)
This commit is contained in:
parent
f2f3037313
commit
751c1f527d
40
boot.asm
40
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
|
||||
|
||||
|
||||
6
build.sh
6
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
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user