1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-26 08:27:45 +00:00

Kernel: Support specifying a 64-bit KERNEL_BASE address

The kernel doesn't currently boot when using an address other than
0xc0000000 because the page tables aren't set up properly for that
but this at least lets us build the kernel.
This commit is contained in:
Gunnar Beutner 2021-07-16 09:37:45 +02:00 committed by Andreas Kling
parent 9b431cbe42
commit acf8f2a2a3
2 changed files with 34 additions and 10 deletions

View file

@ -519,20 +519,32 @@ pae_supported:
movl %eax, %cr0 movl %eax, %cr0
/* set up stack */ /* set up stack */
mov $stack_top, %esp mov $(stack_top - KERNEL_BASE), %esp
and $-16, %esp and $-16, %esp
/* jump into C++ land */
addl $KERNEL_BASE, %ebx
movl %ebx, multiboot_info_ptr
#if ARCH(X86_64) #if ARCH(X86_64)
/* Now we are in 32-bit compatibility mode, We still need to load a 64-bit GDT */ /* Now we are in 32-bit compatibility mode, We still need to load a 64-bit GDT */
lgdt gdt64ptr mov $(gdt64ptr - KERNEL_BASE), %eax
ljmpl $code64_sel, $1f lgdt (%eax)
ljmpl $code64_sel, $(1f - KERNEL_BASE)
.code64 .code64
1: 1:
movl %ebx, %ebx
movabs $KERNEL_BASE, %rax
addq %rax, %rbx
movabs $multiboot_info_ptr, %rax
movq %rbx, (%rax)
movabs $gdt64ptr, %rax
lgdt (%rax)
movabs $1f, %rax
jmp *%rax
1:
movabs $KERNEL_BASE, %rax
addq %rax, %rsp
mov $0, %ax mov $0, %ax
mov %ax, %ss mov %ax, %ss
mov %ax, %ds mov %ax, %ds
@ -542,11 +554,17 @@ pae_supported:
mov %cr3, %rax mov %cr3, %rax
mov %rax, %cr3 mov %rax, %cr3
#else #else
addl $KERNEL_BASE, %ebx
movl %ebx, multiboot_info_ptr
/* jmp to an address above the 3GB mark */ /* jmp to an address above the 3GB mark */
movl $1f,%eax movl $1f, %eax
jmp *%eax jmp *%eax
1: 1:
add $KERNEL_BASE, %esp
movl %cr3, %eax movl %cr3, %eax
movl %eax, %cr3 movl %eax, %cr3
#endif #endif
@ -561,10 +579,12 @@ pae_supported:
addl $8, %edi addl $8, %edi
loop 1b loop 1b
call init
#if ARCH(X86_64) #if ARCH(X86_64)
movabs $init, %rax
call *%rax
add $4, %rsp add $4, %rsp
#else #else
call init
add $4, %esp add $4, %esp
#endif #endif

View file

@ -92,12 +92,16 @@ apic_ap_start32:
movl %eax, %cr0 movl %eax, %cr0
/* load the temporary 64-bit gdt from boot that points above 3GB */ /* load the temporary 64-bit gdt from boot that points above 3GB */
lgdt gdt64ptr mov $(gdt64ptr - KERNEL_BASE), %eax
lgdt (%eax)
/* jump above 3GB into our identity mapped area now */ /* jump above 3GB into our identity mapped area now */
ljmpl $code64_sel, $(apic_ap_start64 - apic_ap_start + 0xc0008000) ljmpl $code64_sel, $(apic_ap_start64 - apic_ap_start + 0xc0008000)
.code64 .code64
apic_ap_start64: apic_ap_start64:
movabs $gdt64ptr, %rax
lgdt (%rax)
mov $0, %ax mov $0, %ax
mov %ax, %ss mov %ax, %ss
mov %ax, %ds mov %ax, %ds