Skip to content

Commit

Permalink
Kernel: Support specifying a 64-bit KERNEL_BASE address
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
gunnarbeutner authored and awesomekling committed Jul 16, 2021
1 parent 9b431cb commit acf8f2a
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 10 deletions.
38 changes: 29 additions & 9 deletions Kernel/Arch/x86/common/Boot/boot.S
Original file line number Diff line number Diff line change
Expand Up @@ -519,20 +519,32 @@ pae_supported:
movl %eax, %cr0

/* set up stack */
mov $stack_top, %esp
mov $(stack_top - KERNEL_BASE), %esp
and $-16, %esp

/* jump into C++ land */
addl $KERNEL_BASE, %ebx
movl %ebx, multiboot_info_ptr

#if ARCH(X86_64)
/* Now we are in 32-bit compatibility mode, We still need to load a 64-bit GDT */
lgdt gdt64ptr
ljmpl $code64_sel, $1f
mov $(gdt64ptr - KERNEL_BASE), %eax
lgdt (%eax)
ljmpl $code64_sel, $(1f - KERNEL_BASE)

.code64
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 %ax, %ss
mov %ax, %ds
Expand All @@ -542,11 +554,17 @@ pae_supported:

mov %cr3, %rax
mov %rax, %cr3

#else
addl $KERNEL_BASE, %ebx
movl %ebx, multiboot_info_ptr

/* jmp to an address above the 3GB mark */
movl $1f,%eax
movl $1f, %eax
jmp *%eax
1:
add $KERNEL_BASE, %esp

movl %cr3, %eax
movl %eax, %cr3
#endif
Expand All @@ -561,10 +579,12 @@ pae_supported:
addl $8, %edi
loop 1b

call init
#if ARCH(X86_64)
movabs $init, %rax
call *%rax
add $4, %rsp
#else
call init
add $4, %esp
#endif

Expand Down
6 changes: 5 additions & 1 deletion Kernel/Arch/x86/x86_64/Boot/ap_setup.S
Original file line number Diff line number Diff line change
Expand Up @@ -92,12 +92,16 @@ apic_ap_start32:
movl %eax, %cr0

/* 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 */
ljmpl $code64_sel, $(apic_ap_start64 - apic_ap_start + 0xc0008000)
.code64
apic_ap_start64:
movabs $gdt64ptr, %rax
lgdt (%rax)

mov $0, %ax
mov %ax, %ss
mov %ax, %ds
Expand Down

0 comments on commit acf8f2a

Please sign in to comment.