Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/internal/task/task_stack_cortexm.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// +build scheduler.tasks, cortexm
// +build scheduler.tasks,cortexm

package task

Expand Down
2 changes: 1 addition & 1 deletion src/runtime/gc_conservative.go
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ func (b gcBlock) unmark() {
// No memory may be allocated before this is called. That means the runtime and
// any packages the runtime depends upon may not allocate memory during package
// initialization.
func init() {
func initHeap() {
totalSize := heapEnd - heapStart

// Allocate some memory to keep 2 bits of information about every block.
Expand Down
4 changes: 4 additions & 0 deletions src/runtime/gc_leaking.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,3 +45,7 @@ func KeepAlive(x interface{}) {
func SetFinalizer(obj interface{}, finalizer interface{}) {
// Unimplemented.
}

func initHeap() {
// Nothing to initialize.
}
4 changes: 4 additions & 0 deletions src/runtime/gc_none.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,3 +27,7 @@ func KeepAlive(x interface{}) {
func SetFinalizer(obj interface{}, finalizer interface{}) {
// Unimplemented.
}

func initHeap() {
// Nothing to initialize.
}
12 changes: 4 additions & 8 deletions src/runtime/runtime_arm7tdmi.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,20 +30,16 @@ var _sidata [0]byte
//go:extern _edata
var _edata [0]byte

func postinit() {}

// Entry point for Go. Initialize all packages and call main.main().
//go:export main
func main() {
// Initialize .data and .bss sections.
preinit()

// Run initializers of all packages.
initAll()

// Compiler-generated call to main.main().
go callMain()

// Run the scheduler.
scheduler()
// Run program.
run()
}

func preinit() {
Expand Down
6 changes: 3 additions & 3 deletions src/runtime/runtime_atsamd21.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,12 @@ import (

type timeUnit int64

func postinit() {}

//go:export Reset_Handler
func main() {
preinit()
initAll()
go callMain()
scheduler()
run()
abort()
}

Expand Down
6 changes: 3 additions & 3 deletions src/runtime/runtime_atsamd51.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,12 @@ import (

type timeUnit int64

func postinit() {}

//go:export Reset_Handler
func main() {
preinit()
initAll()
go callMain()
scheduler()
run()
abort()
}

Expand Down
4 changes: 1 addition & 3 deletions src/runtime/runtime_avr.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,7 @@ var _ebss [0]byte
//go:export main
func main() {
preinit()
initAll()
postinit()
callMain()
run()
abort()
}

Expand Down
6 changes: 3 additions & 3 deletions src/runtime/runtime_cortexm_qemu.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,12 @@ const tickMicros = 1

var timestamp timeUnit

func postinit() {}

//go:export Reset_Handler
func main() {
preinit()
initAll()
go callMain()
scheduler()
run()
arm.SemihostingCall(arm.SemihostingReportException, arm.SemihostingApplicationExit)
abort()
}
Expand Down
6 changes: 3 additions & 3 deletions src/runtime/runtime_fe310.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ var _sidata [0]byte
//go:extern _edata
var _edata [0]byte

func postinit() {}

//go:export main
func main() {
// Zero the PLIC enable bits on startup: they are not zeroed at reset.
Expand All @@ -51,9 +53,7 @@ func main() {

preinit()
initPeripherals()
initAll()
go callMain()
scheduler()
run()
abort()
}

Expand Down
6 changes: 3 additions & 3 deletions src/runtime/runtime_nrf.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,13 @@ const tickMicros = 1024 * 32
//go:linkname systemInit SystemInit
func systemInit()

func postinit() {}

//go:export Reset_Handler
func main() {
systemInit()
preinit()
initAll()
go callMain()
scheduler()
run()
abort()
}

Expand Down
6 changes: 3 additions & 3 deletions src/runtime/runtime_stm32.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@ package runtime

type timeUnit int64

func postinit() {}

//go:export Reset_Handler
func main() {
preinit()
initAll()
go callMain()
scheduler()
run()
abort()
}
17 changes: 6 additions & 11 deletions src/runtime/runtime_unix.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,7 @@ func clock_gettime(clk_id int32, ts *timespec)

const heapSize = 1 * 1024 * 1024 // 1MB to start

var (
heapStart = uintptr(malloc(heapSize))
heapEnd = heapStart + heapSize
)
var heapStart, heapEnd uintptr

type timeUnit int64

Expand All @@ -45,17 +42,15 @@ type timespec struct {

const CLOCK_MONOTONIC_RAW = 4

func postinit() {}

// Entry point for Go. Initialize all packages and call main.main().
//go:export main
func main() int {
// Run initializers of all packages.
initAll()

// Compiler-generated call to main.main().
go callMain()
heapStart = uintptr(malloc(heapSize))
heapEnd = heapStart + heapSize

// Run scheduler.
scheduler()
run()

// For libc compatibility.
return 0
Expand Down
10 changes: 7 additions & 3 deletions src/runtime/runtime_wasm.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,15 @@ type wasiIOVec struct {
//export fd_write
func fd_write(id uint32, iovs *wasiIOVec, iovs_len uint, nwritten *uint) (errno uint)

func postinit() {}

//export _start
func _start() {
initAll()
go callMain()
scheduler()
// These need to be initialized early so that the heap can be initialized.
heapStart = uintptr(unsafe.Pointer(&heapStartSymbol))
heapEnd = uintptr(wasm_memory_size(0) * wasmPageSize)

run()
}

// Using global variables to avoid heap allocation.
Expand Down
12 changes: 12 additions & 0 deletions src/runtime/scheduler_any.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,15 @@ func sleep(duration int64) {
addSleepTask(task.Current(), duration)
task.Pause()
}

// run is called by the program entry point to execute the go program.
// With a scheduler, init and the main function are invoked in a goroutine before starting the scheduler.
func run() {
initHeap()
go func() {
initAll()
postinit()
callMain()
}()
scheduler()
}
9 changes: 9 additions & 0 deletions src/runtime/scheduler_none.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,12 @@ func sleep(duration int64) {
func getSystemStackPointer() uintptr {
return getCurrentStackPointer()
}

// run is called by the program entry point to execute the go program.
// With the "none" scheduler, init and the main function are invoked directly.
func run() {
initHeap()
initAll()
postinit()
callMain()
}