github.com/tinygo-org/tinygo@v0.31.3-0.20240404173401-90b0bf646c27/src/runtime/runtime_fe310_qemu.go (about)

     1  //go:build fe310 && qemu
     2  
     3  package runtime
     4  
     5  import (
     6  	"runtime/volatile"
     7  	"unsafe"
     8  )
     9  
    10  // Special memory-mapped device to exit tests, created by SiFive.
    11  var testExit = (*volatile.Register32)(unsafe.Pointer(uintptr(0x100000)))
    12  
    13  // ticksToNanoseconds converts CLINT ticks (at 100ns per tick) to nanoseconds.
    14  func ticksToNanoseconds(ticks timeUnit) int64 {
    15  	return int64(ticks) * 100
    16  }
    17  
    18  // nanosecondsToTicks converts nanoseconds to CLINT ticks (at 100ns per tick).
    19  func nanosecondsToTicks(ns int64) timeUnit {
    20  	return timeUnit(ns / 100)
    21  }
    22  
    23  func abort() {
    24  	exit(1)
    25  }
    26  
    27  func exit(code int) {
    28  	if code == 0 {
    29  		// Signal a successful exit.
    30  		testExit.Set(0x5555) // FINISHER_PASS
    31  	} else {
    32  		// Signal a failure. The exit code is stored in the upper 16 bits of the
    33  		// 32 bit value.
    34  		testExit.Set(uint32(code)<<16 | 0x3333) // FINISHER_FAIL
    35  	}
    36  }