github.com/tinygo-org/tinygo@v0.31.3-0.20240404173401-90b0bf646c27/src/runtime/runtime_cortexm.go (about) 1 //go:build cortexm 2 3 package runtime 4 5 import ( 6 "unsafe" 7 ) 8 9 //go:extern _sbss 10 var _sbss [0]byte 11 12 //go:extern _ebss 13 var _ebss [0]byte 14 15 //go:extern _sdata 16 var _sdata [0]byte 17 18 //go:extern _sidata 19 var _sidata [0]byte 20 21 //go:extern _edata 22 var _edata [0]byte 23 24 func preinit() { 25 // Initialize .bss: zero-initialized global variables. 26 ptr := unsafe.Pointer(&_sbss) 27 for ptr != unsafe.Pointer(&_ebss) { 28 *(*uint32)(ptr) = 0 29 ptr = unsafe.Add(ptr, 4) 30 } 31 32 // Initialize .data: global variables initialized from flash. 33 src := unsafe.Pointer(&_sidata) 34 dst := unsafe.Pointer(&_sdata) 35 for dst != unsafe.Pointer(&_edata) { 36 *(*uint32)(dst) = *(*uint32)(src) 37 dst = unsafe.Add(dst, 4) 38 src = unsafe.Add(src, 4) 39 } 40 } 41 42 // The stack layout at the moment an interrupt occurs. 43 // Registers can be accessed if the stack pointer is cast to a pointer to this 44 // struct. 45 type interruptStack struct { 46 R0 uintptr 47 R1 uintptr 48 R2 uintptr 49 R3 uintptr 50 R12 uintptr 51 LR uintptr 52 PC uintptr 53 PSR uintptr 54 }