From c81fd8b758917968b8bfc02f8264b38a062cb52d Mon Sep 17 00:00:00 2001 From: Achilleas Anagnostopoulos Date: Sat, 17 Jun 2017 08:18:07 +0100 Subject: [PATCH] Pass kernel start/end physical address to Kmain --- arch/x86_64/asm/rt0_64.s | 7 +++++++ arch/x86_64/script/linker.ld.in | 4 ++++ kernel/kmain/kmain.go | 4 ++-- stub.go | 2 +- 4 files changed, 14 insertions(+), 3 deletions(-) diff --git a/arch/x86_64/asm/rt0_64.s b/arch/x86_64/asm/rt0_64.s index e39a2f9..19fd1b1 100644 --- a/arch/x86_64/asm/rt0_64.s +++ b/arch/x86_64/asm/rt0_64.s @@ -1,4 +1,5 @@ ; vim: set ft=nasm : +%include "constants.inc" section .bss align 8 @@ -55,8 +56,14 @@ _rt0_64_entry: ; Call the kernel entry point passing a pointer to the multiboot data ; copied by the 32-bit entry code extern multiboot_data + extern _kernel_start + extern _kernel_end extern kernel.Kmain + mov rax, _kernel_end - PAGE_OFFSET + push rax + mov rax, _kernel_start - PAGE_OFFSET + push rax mov rax, multiboot_data push rax call kernel.Kmain diff --git a/arch/x86_64/script/linker.ld.in b/arch/x86_64/script/linker.ld.in index 7d3cf53..31a8ae0 100644 --- a/arch/x86_64/script/linker.ld.in +++ b/arch/x86_64/script/linker.ld.in @@ -7,6 +7,8 @@ SECTIONS { * but load it at physical address 1M */ . = VMA; + _kernel_start = .; + .text BLOCK(4K) : AT(ADDR(.text) - PAGE_OFFSET) { /* The multiboot header must be present in the first 4K of the kernel @@ -36,4 +38,6 @@ SECTIONS { *(COMMON) *(.bss) } + + _kernel_end = ALIGN(4K); } diff --git a/kernel/kmain/kmain.go b/kernel/kmain/kmain.go index cd9f81d..e9d3f63 100644 --- a/kernel/kmain/kmain.go +++ b/kernel/kmain/kmain.go @@ -13,12 +13,12 @@ import ( // allocated by the assembly code. // // The rt0 code passes the address of the multiboot info payload provided by the -// bootloader. +// bootloader as well as the physical addresses for the kernel start/end. // // Kmain is not expected to return. If it does, the rt0 code will halt the CPU. // //go:noinline -func Kmain(multibootInfoPtr uintptr) { +func Kmain(multibootInfoPtr, kernelStart, kernelEnd uintptr) { multiboot.SetInfoPtr(multibootInfoPtr) hal.InitTerminal() diff --git a/stub.go b/stub.go index 5263408..0e62711 100644 --- a/stub.go +++ b/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) + kmain.Kmain(multibootInfoPtr, 0, 0) }