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

     1  //go:build tinygo.riscv
     2  
     3  package runtime
     4  
     5  import "device/riscv"
     6  
     7  const deferExtraRegs = 0
     8  
     9  const callInstSize = 4 // 8 without relaxation, maybe 4 with relaxation
    10  
    11  // RISC-V has a maximum alignment of 16 bytes (both for RV32 and for RV64).
    12  // Source: https://riscv.org/wp-content/uploads/2015/01/riscv-calling.pdf
    13  func align(ptr uintptr) uintptr {
    14  	return (ptr + 15) &^ 15
    15  }
    16  
    17  func getCurrentStackPointer() uintptr {
    18  	return uintptr(stacksave())
    19  }
    20  
    21  // The safest thing to do here would just be to disable interrupts for
    22  // procPin/procUnpin. Note that a global variable is safe in this case, as any
    23  // access to procPinnedMask will happen with interrupts disabled.
    24  
    25  var procPinnedMask uintptr
    26  
    27  //go:linkname procPin sync/atomic.runtime_procPin
    28  func procPin() {
    29  	procPinnedMask = riscv.DisableInterrupts()
    30  }
    31  
    32  //go:linkname procUnpin sync/atomic.runtime_procUnpin
    33  func procUnpin() {
    34  	riscv.EnableInterrupts(procPinnedMask)
    35  }
    36  
    37  func waitForEvents() {
    38  	mask := riscv.DisableInterrupts()
    39  	if !runqueue.Empty() {
    40  		riscv.Asm("wfi")
    41  	}
    42  	riscv.EnableInterrupts(mask)
    43  }