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

Merge pull request #45 from achilleasa/enable-support-for-defer

Enable support for defer
This commit is contained in:
Achilleas Anagnostopoulos 2017-07-14 08:11:37 +01:00 committed by GitHub
commit a05c135355
4 changed files with 23 additions and 5 deletions

View File

@ -95,6 +95,7 @@ _rt0_64_setup_go_runtime_structs:
; Link m0 to the g0
extern runtime.m0
mov rbx, runtime.m0
mov qword [rbx+GO_M_CURG], rsi ; m.curg = g0
mov qword [rbx+GO_M_G0], rsi ; m.g0 = g0
mov qword [rsi+GO_G_M], rbx ; g.m = m

View File

@ -21,6 +21,7 @@ var (
typeLinksInitFn = typeLinksInit
itabsInitFn = itabsInit
initGoPackagesFn = initGoPackages
procResizeFn = procResize
// A seed for the pseudo-random number generator used by getRandomData
prngSeed = 0xdeadc0de
@ -44,6 +45,9 @@ func mallocInit()
//go:linkname mSysStatInc runtime.mSysStatInc
func mSysStatInc(*uint64, uintptr)
//go:linkname procResize runtime.procresize
func procResize(int32) uintptr
// initGoPackages is an alias to main.init which recursively calls the init()
// methods in all imported packages. Unless this function is called, things like
// package errors will not be properly initialized causing various problems when
@ -184,11 +188,20 @@ func Init() *kernel.Error {
typeLinksInitFn() // uses maps, activeModules
itabsInitFn() // uses activeModules
// Set processor count to 1. This initializes the p pointer in the
// currently active m allowing the kernel to register defer functions
SetCPUCount(1)
initGoPackagesFn()
return nil
}
// SetCPUCount registers the number of available CPUs with the Go runtime.
func SetCPUCount(numCPUs int32) {
procResizeFn(numCPUs)
}
func init() {
// Dummy calls so the compiler does not optimize away the functions in
// this file.

View File

@ -267,6 +267,7 @@ func TestInit(t *testing.T) {
typeLinksInitFn = typeLinksInit
itabsInitFn = itabsInit
initGoPackagesFn = initGoPackages
procResizeFn = procResize
}()
mallocInitFn = func() {}
@ -275,7 +276,7 @@ func TestInit(t *testing.T) {
typeLinksInitFn = func() {}
itabsInitFn = func() {}
initGoPackagesFn = func() {}
procResizeFn = func(_ int32) uintptr { return 0 }
if err := Init(); err != nil {
t.Fatal(t)
}

View File

@ -39,10 +39,13 @@ func Kmain(multibootInfoPtr, kernelStart, kernelEnd, kernelPageOffset uintptr) {
panic(err)
}
// After goruntime.Init returns we can safely use defer
defer func() {
// Use kfmt.Panic instead of panic to prevent the compiler from
// treating kernel.Panic as dead-code and eliminating it.
kfmt.Panic(errKmainReturned)
}()
// Detect and initialize hardware
hal.DetectHardware()
// Use kfmt.Panic instead of panic to prevent the compiler from
// treating kernel.Panic as dead-code and eliminating it.
kfmt.Panic(errKmainReturned)
}