From 865f46c46777bc765467485a6724af7baa7badea Mon Sep 17 00:00:00 2001 From: Achilleas Anagnostopoulos Date: Thu, 23 Mar 2017 07:10:01 +0000 Subject: [PATCH] Define kernel entry-points in Go --- boot.go | 18 ++++++++++++++++++ kernel/kmain.go | 5 +++++ 2 files changed, 23 insertions(+) create mode 100644 boot.go create mode 100644 kernel/kmain.go diff --git a/boot.go b/boot.go new file mode 100644 index 0000000..fb85268 --- /dev/null +++ b/boot.go @@ -0,0 +1,18 @@ +package main + +import "github.com/achilleasa/gopher-os/kernel" + +// main is the only Go symbol that is visible (exported) from the rt0 initialization +// code. This function works as a trampoline for calling the actual kernel entrypoint +// (kernel.Kmain) and its intentionally defined to prevent the Go compiler from +// optimizing away the actual kernel code as its not aware of the presence of the +// rt0 code. +// +// The main 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. +// +// main is not expected to return. If it does, the rt0 code will halt the CPU. +func main() { + kernel.Kmain() +} diff --git a/kernel/kmain.go b/kernel/kmain.go new file mode 100644 index 0000000..85c1df0 --- /dev/null +++ b/kernel/kmain.go @@ -0,0 +1,5 @@ +package kernel + +// Kmain is invoked by the boot.go and implements the actual kernel entrypoint. +func Kmain() { +}