From cc4364f55c2d038a9318600b81c256aeb64f0433 Mon Sep 17 00:00:00 2001 From: Achilleas Anagnostopoulos Date: Wed, 12 Jul 2017 23:40:56 +0100 Subject: [PATCH] Pass the virtual page offset for the kernel to kernel.Kmain Ths page offset is defined in arch/XXX/constants.inc and needs to be passed to the kernel so we can correctly calculate the physical frame addresses that correspond to the ELF section virtual memory addresses. --- src/arch/x86_64/asm/rt0_64.s | 2 ++ src/gopheros/kernel/kmain/kmain.go | 7 ++++--- src/gopheros/stub.go | 2 +- 3 files changed, 7 insertions(+), 4 deletions(-) diff --git a/src/arch/x86_64/asm/rt0_64.s b/src/arch/x86_64/asm/rt0_64.s index efa37a4..efffa3f 100644 --- a/src/arch/x86_64/asm/rt0_64.s +++ b/src/arch/x86_64/asm/rt0_64.s @@ -51,6 +51,8 @@ _rt0_64_entry: extern _kernel_end extern kernel.Kmain + mov rax, PAGE_OFFSET + push rax mov rax, _kernel_end - PAGE_OFFSET push rax mov rax, _kernel_start - PAGE_OFFSET diff --git a/src/gopheros/kernel/kmain/kmain.go b/src/gopheros/kernel/kmain/kmain.go index 7274f59..ff41b03 100644 --- a/src/gopheros/kernel/kmain/kmain.go +++ b/src/gopheros/kernel/kmain/kmain.go @@ -20,18 +20,19 @@ var ( // allocated by the assembly code. // // The rt0 code passes the address of the multiboot info payload provided by the -// bootloader as well as the physical addresses for the kernel start/end. +// bootloader as well as the physical addresses for the kernel start/end. In +// addition, the start of the kernel virtual address space is passed to the +// kernelPageOffset argument. // // Kmain is not expected to return. If it does, the rt0 code will halt the CPU. // //go:noinline -func Kmain(multibootInfoPtr, kernelStart, kernelEnd uintptr) { +func Kmain(multibootInfoPtr, kernelStart, kernelEnd, kernelPageOffset uintptr) { multiboot.SetInfoPtr(multibootInfoPtr) var err *kernel.Error if err = allocator.Init(kernelStart, kernelEnd); err != nil { panic(err) - } else if err = vmm.Init(); err != nil { panic(err) } else if err = goruntime.Init(); err != nil { panic(err) diff --git a/src/gopheros/stub.go b/src/gopheros/stub.go index 73c6d49..3446069 100644 --- a/src/gopheros/stub.go +++ b/src/gopheros/stub.go @@ -11,5 +11,5 @@ var multibootInfoPtr uintptr // A global variable is passed as an argument to Kmain to prevent the compiler // from inlining the actual call and removing Kmain from the generated .o file. func main() { - kmain.Kmain(multibootInfoPtr, 0, 0) + kmain.Kmain(multibootInfoPtr, 0, 0, 0) }