github.com/aykevl/tinygo@v0.5.0/src/runtime/runtime_cortexm.go (about) 1 // +build cortexm 2 3 package runtime 4 5 import ( 6 "device/arm" 7 "unsafe" 8 ) 9 10 //go:extern _sbss 11 var _sbss unsafe.Pointer 12 13 //go:extern _ebss 14 var _ebss unsafe.Pointer 15 16 //go:extern _sdata 17 var _sdata unsafe.Pointer 18 19 //go:extern _sidata 20 var _sidata unsafe.Pointer 21 22 //go:extern _edata 23 var _edata unsafe.Pointer 24 25 func preinit() { 26 // Initialize .bss: zero-initialized global variables. 27 ptr := uintptr(unsafe.Pointer(&_sbss)) 28 for ptr != uintptr(unsafe.Pointer(&_ebss)) { 29 *(*uint32)(unsafe.Pointer(ptr)) = 0 30 ptr += 4 31 } 32 33 // Initialize .data: global variables initialized from flash. 34 src := uintptr(unsafe.Pointer(&_sidata)) 35 dst := uintptr(unsafe.Pointer(&_sdata)) 36 for dst != uintptr(unsafe.Pointer(&_edata)) { 37 *(*uint32)(unsafe.Pointer(dst)) = *(*uint32)(unsafe.Pointer(src)) 38 dst += 4 39 src += 4 40 } 41 } 42 43 func abort() { 44 for { 45 arm.Asm("wfi") 46 } 47 } 48 49 // Implement memset for LLVM and compiler-rt. 50 //go:export memset 51 func libc_memset(ptr unsafe.Pointer, c byte, size uintptr) { 52 for i := uintptr(0); i < size; i++ { 53 *(*byte)(unsafe.Pointer(uintptr(ptr) + i)) = c 54 } 55 } 56 57 // Implement memmove for LLVM and compiler-rt. 58 //go:export memmove 59 func libc_memmove(dst, src unsafe.Pointer, size uintptr) { 60 memmove(dst, src, size) 61 }