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:
commit
a05c135355
@ -95,6 +95,7 @@ _rt0_64_setup_go_runtime_structs:
|
|||||||
; Link m0 to the g0
|
; Link m0 to the g0
|
||||||
extern runtime.m0
|
extern runtime.m0
|
||||||
mov rbx, 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 [rbx+GO_M_G0], rsi ; m.g0 = g0
|
||||||
mov qword [rsi+GO_G_M], rbx ; g.m = m
|
mov qword [rsi+GO_G_M], rbx ; g.m = m
|
||||||
|
|
||||||
|
@ -21,6 +21,7 @@ var (
|
|||||||
typeLinksInitFn = typeLinksInit
|
typeLinksInitFn = typeLinksInit
|
||||||
itabsInitFn = itabsInit
|
itabsInitFn = itabsInit
|
||||||
initGoPackagesFn = initGoPackages
|
initGoPackagesFn = initGoPackages
|
||||||
|
procResizeFn = procResize
|
||||||
|
|
||||||
// A seed for the pseudo-random number generator used by getRandomData
|
// A seed for the pseudo-random number generator used by getRandomData
|
||||||
prngSeed = 0xdeadc0de
|
prngSeed = 0xdeadc0de
|
||||||
@ -44,6 +45,9 @@ func mallocInit()
|
|||||||
//go:linkname mSysStatInc runtime.mSysStatInc
|
//go:linkname mSysStatInc runtime.mSysStatInc
|
||||||
func mSysStatInc(*uint64, uintptr)
|
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()
|
// initGoPackages is an alias to main.init which recursively calls the init()
|
||||||
// methods in all imported packages. Unless this function is called, things like
|
// methods in all imported packages. Unless this function is called, things like
|
||||||
// package errors will not be properly initialized causing various problems when
|
// package errors will not be properly initialized causing various problems when
|
||||||
@ -184,11 +188,20 @@ func Init() *kernel.Error {
|
|||||||
typeLinksInitFn() // uses maps, activeModules
|
typeLinksInitFn() // uses maps, activeModules
|
||||||
itabsInitFn() // uses 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()
|
initGoPackagesFn()
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// SetCPUCount registers the number of available CPUs with the Go runtime.
|
||||||
|
func SetCPUCount(numCPUs int32) {
|
||||||
|
procResizeFn(numCPUs)
|
||||||
|
}
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
// Dummy calls so the compiler does not optimize away the functions in
|
// Dummy calls so the compiler does not optimize away the functions in
|
||||||
// this file.
|
// this file.
|
||||||
|
@ -267,6 +267,7 @@ func TestInit(t *testing.T) {
|
|||||||
typeLinksInitFn = typeLinksInit
|
typeLinksInitFn = typeLinksInit
|
||||||
itabsInitFn = itabsInit
|
itabsInitFn = itabsInit
|
||||||
initGoPackagesFn = initGoPackages
|
initGoPackagesFn = initGoPackages
|
||||||
|
procResizeFn = procResize
|
||||||
}()
|
}()
|
||||||
|
|
||||||
mallocInitFn = func() {}
|
mallocInitFn = func() {}
|
||||||
@ -275,7 +276,7 @@ func TestInit(t *testing.T) {
|
|||||||
typeLinksInitFn = func() {}
|
typeLinksInitFn = func() {}
|
||||||
itabsInitFn = func() {}
|
itabsInitFn = func() {}
|
||||||
initGoPackagesFn = func() {}
|
initGoPackagesFn = func() {}
|
||||||
|
procResizeFn = func(_ int32) uintptr { return 0 }
|
||||||
if err := Init(); err != nil {
|
if err := Init(); err != nil {
|
||||||
t.Fatal(t)
|
t.Fatal(t)
|
||||||
}
|
}
|
||||||
|
@ -39,10 +39,13 @@ func Kmain(multibootInfoPtr, kernelStart, kernelEnd, kernelPageOffset uintptr) {
|
|||||||
panic(err)
|
panic(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Detect and initialize hardware
|
// After goruntime.Init returns we can safely use defer
|
||||||
hal.DetectHardware()
|
defer func() {
|
||||||
|
|
||||||
// Use kfmt.Panic instead of panic to prevent the compiler from
|
// Use kfmt.Panic instead of panic to prevent the compiler from
|
||||||
// treating kernel.Panic as dead-code and eliminating it.
|
// treating kernel.Panic as dead-code and eliminating it.
|
||||||
kfmt.Panic(errKmainReturned)
|
kfmt.Panic(errKmainReturned)
|
||||||
|
}()
|
||||||
|
|
||||||
|
// Detect and initialize hardware
|
||||||
|
hal.DetectHardware()
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user