1
0
mirror of https://github.com/taigrr/gopher-os synced 2025-01-18 04:43:13 -08:00

Pass kernel start/end physical address to Kmain

This commit is contained in:
Achilleas Anagnostopoulos 2017-06-17 08:18:07 +01:00
parent ad0bf0a4ca
commit c81fd8b758
4 changed files with 14 additions and 3 deletions

View File

@ -1,4 +1,5 @@
; vim: set ft=nasm : ; vim: set ft=nasm :
%include "constants.inc"
section .bss section .bss
align 8 align 8
@ -55,8 +56,14 @@ _rt0_64_entry:
; Call the kernel entry point passing a pointer to the multiboot data ; Call the kernel entry point passing a pointer to the multiboot data
; copied by the 32-bit entry code ; copied by the 32-bit entry code
extern multiboot_data extern multiboot_data
extern _kernel_start
extern _kernel_end
extern kernel.Kmain extern kernel.Kmain
mov rax, _kernel_end - PAGE_OFFSET
push rax
mov rax, _kernel_start - PAGE_OFFSET
push rax
mov rax, multiboot_data mov rax, multiboot_data
push rax push rax
call kernel.Kmain call kernel.Kmain

View File

@ -7,6 +7,8 @@ SECTIONS {
* but load it at physical address 1M */ * but load it at physical address 1M */
. = VMA; . = VMA;
_kernel_start = .;
.text BLOCK(4K) : AT(ADDR(.text) - PAGE_OFFSET) .text BLOCK(4K) : AT(ADDR(.text) - PAGE_OFFSET)
{ {
/* The multiboot header must be present in the first 4K of the kernel /* The multiboot header must be present in the first 4K of the kernel
@ -36,4 +38,6 @@ SECTIONS {
*(COMMON) *(COMMON)
*(.bss) *(.bss)
} }
_kernel_end = ALIGN(4K);
} }

View File

@ -13,12 +13,12 @@ import (
// allocated by the assembly code. // allocated by the assembly code.
// //
// The rt0 code passes the address of the multiboot info payload provided by the // 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. // Kmain is not expected to return. If it does, the rt0 code will halt the CPU.
// //
//go:noinline //go:noinline
func Kmain(multibootInfoPtr uintptr) { func Kmain(multibootInfoPtr, kernelStart, kernelEnd uintptr) {
multiboot.SetInfoPtr(multibootInfoPtr) multiboot.SetInfoPtr(multibootInfoPtr)
hal.InitTerminal() hal.InitTerminal()

View File

@ -11,5 +11,5 @@ var multibootInfoPtr uintptr
// A global variable is passed as an argument to Kmain to prevent the compiler // 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. // from inlining the actual call and removing Kmain from the generated .o file.
func main() { func main() {
kmain.Kmain(multibootInfoPtr) kmain.Kmain(multibootInfoPtr, 0, 0)
} }