File tree Expand file tree Collapse file tree 5 files changed +37
-53
lines changed Expand file tree Collapse file tree 5 files changed +37
-53
lines changed Original file line number Diff line number Diff line change 1- //go:build baremetal && !uefi
1+ //go:build baremetal
22
33package runtime
44
55import (
66 "unsafe"
77)
88
9- //go:extern _heap_start
10- var heapStartSymbol [0 ]byte
11-
12- //go:extern _heap_end
13- var heapEndSymbol [0 ]byte
14-
15- //go:extern _globals_start
16- var globalsStartSymbol [0 ]byte
17-
18- //go:extern _globals_end
19- var globalsEndSymbol [0 ]byte
20-
21- //go:extern _stack_top
22- var stackTopSymbol [0 ]byte
23-
24- var (
25- heapStart = uintptr (unsafe .Pointer (& heapStartSymbol ))
26- heapEnd = uintptr (unsafe .Pointer (& heapEndSymbol ))
27- globalsStart = uintptr (unsafe .Pointer (& globalsStartSymbol ))
28- globalsEnd = uintptr (unsafe .Pointer (& globalsEndSymbol ))
29- stackTop = uintptr (unsafe .Pointer (& stackTopSymbol ))
30- )
31-
32- // growHeap tries to grow the heap size. It returns true if it succeeds, false
33- // otherwise.
34- func growHeap () bool {
35- // On baremetal, there is no way the heap can be grown.
36- return false
37- }
38-
399//export malloc
4010func libc_malloc (size uintptr ) unsafe.Pointer {
4111 // Note: this zeroes the returned buffer which is not necessary.
Original file line number Diff line number Diff line change 1+ //go:build baremetal && !uefi
2+
3+ package runtime
4+
5+ //go:extern _heap_start
6+ var heapStartSymbol [0 ]byte
7+
8+ //go:extern _heap_end
9+ var heapEndSymbol [0 ]byte
10+
11+ //go:extern _globals_start
12+ var globalsStartSymbol [0 ]byte
13+
14+ //go:extern _globals_end
15+ var globalsEndSymbol [0 ]byte
16+
17+ //go:extern _stack_top
18+ var stackTopSymbol [0 ]byte
19+
20+ var (
21+ heapStart = uintptr (unsafe .Pointer (& heapStartSymbol ))
22+ heapEnd = uintptr (unsafe .Pointer (& heapEndSymbol ))
23+ globalsStart = uintptr (unsafe .Pointer (& globalsStartSymbol ))
24+ globalsEnd = uintptr (unsafe .Pointer (& globalsEndSymbol ))
25+ stackTop = uintptr (unsafe .Pointer (& stackTopSymbol ))
26+ )
27+
28+ // growHeap tries to grow the heap size. It returns true if it succeeds, false
29+ // otherwise.
30+ func growHeap () bool {
31+ // On baremetal, there is no way the heap can be grown.
32+ return false
33+ }
Original file line number Diff line number Diff line change 1- //go:build linux && (baremetal || nintendoswitch || wasi) && !uefi
1+ //go:build linux && (baremetal || nintendoswitch || wasi)
22
33// Other systems that aren't operating systems supported by the Go toolchain
44// need to pretend to be an existing operating system. Linux seems like a good
Original file line number Diff line number Diff line change @@ -7,10 +7,6 @@ import (
77 "unsafe"
88)
99
10- const baremetal = true
11-
12- const GOOS = "uefi"
13-
1410// Mark global variables.
1511// Unfortunately, the linker doesn't provide symbols for the start and end of
1612// the data/bss sections. Therefore these addresses need to be determined at
Original file line number Diff line number Diff line change @@ -27,22 +27,6 @@ func nanosecondsToTicks(ns int64) timeUnit {
2727 return timeUnit (x86 .ConvertTicksFromNanoSeconds (uefi .TicksFrequency (), uint64 (ns )))
2828}
2929
30- var timeOffset int64
31-
32- //go:linkname now time.now
33- func now () (sec int64 , nsec int32 , mono int64 ) {
34- mono = nanotime ()
35- efiTime , status := uefi .GetTime ()
36- if status != uefi .EFI_SUCCESS {
37- uefi .DebugPrint ("gettime error" , uint64 (status ))
38- sec = (mono + timeOffset ) / (1000 * 1000 * 1000 )
39- nsec = int32 ((mono + timeOffset ) - sec * (1000 * 1000 * 1000 ))
40- } else {
41- sec , nsec = efiTime .GetEpoch ()
42- }
43- return
44- }
45-
4630func sleepTicks (d timeUnit ) {
4731 if d == 0 {
4832 return
@@ -128,10 +112,11 @@ func growHeap() bool {
128112func init () {
129113 var efiTime uefi.EFI_TIME
130114
115+ mono := nanotime ()
131116 efiTime , status := uefi .GetTime ()
132117 if status == uefi .EFI_SUCCESS {
133118 sec , nsec := efiTime .GetEpoch ()
134- timeOffset = sec * 1000000000 + int64 (nsec )
119+ timeOffset = sec * 1000000000 + int64 (nsec ) - mono
135120 }
136121
137122 go func () {
You can’t perform that action at this time.
0 commit comments