mirror of
https://github.com/taigrr/gopher-os
synced 2025-01-18 04:43:13 -08:00
The linked.ld script is extended to include the _kernel_start and _kernel_end symbols which are passed by the rt0 code to Kmain. The allocator converts these addresses to a start/end frame index by rounding down the kernel start address to the nearest page and rounding up the kernel end address to the nearest page. When allocating frames, the allocator will treat the region defined by these 2 indices as reserved and skip over it.
31 lines
1.0 KiB
Go
31 lines
1.0 KiB
Go
package kmain
|
|
|
|
import (
|
|
"github.com/achilleasa/gopher-os/kernel/hal"
|
|
"github.com/achilleasa/gopher-os/kernel/hal/multiboot"
|
|
"github.com/achilleasa/gopher-os/kernel/kfmt/early"
|
|
"github.com/achilleasa/gopher-os/kernel/mem/pmm/allocator"
|
|
)
|
|
|
|
// Kmain is the only Go symbol that is visible (exported) from the rt0 initialization
|
|
// code. This function is invoked by the rt0 assembly code after setting up the GDT
|
|
// and setting up a a minimal g0 struct that allows Go code using the 4K stack
|
|
// 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.
|
|
//
|
|
// Kmain is not expected to return. If it does, the rt0 code will halt the CPU.
|
|
//
|
|
//go:noinline
|
|
func Kmain(multibootInfoPtr, kernelStart, kernelEnd uintptr) {
|
|
multiboot.SetInfoPtr(multibootInfoPtr)
|
|
|
|
hal.InitTerminal()
|
|
hal.ActiveTerminal.Clear()
|
|
|
|
if err := allocator.Init(kernelStart, kernelEnd); err != nil {
|
|
early.Printf("[%s] error: %s\n", err.Module, err.Message)
|
|
}
|
|
}
|