Background
During the migration of TinyGo device packages to goplus/lib/emb, we discovered that RISC-V CSR (Control and Status Register) operations require built-in compiler support.
Problem Description
Current Status
- File:
emb/device/riscv/csr.go
- Functions:
CSR.Get(), CSR.Set(), CSR.SetBits(), CSR.ClearBits()
- Error: missing function body
TinyGo Implementation
In TinyGo, these CSR operations are implemented as compiler intrinsics:
- File:
tinygo/compiler/inlineasm.go
- Function:
func (b *builder) emitCSROperation(call *ssa.CallCommon) (llvm.Value, error)
Current Temporary Solution
func (csr CSR) Get() uintptr {
// TODO(zzy): implement tinygo/compiler/inlineasm.go emitCSROperation
panic("TODO: CSR.Get()")
return 0
}
Requirements
Option 1: LLGO Compiler Built-in Support
- Add built-in support for RISC-V CSR operations in LLGO compiler
- Similar to TinyGo's approach, generate corresponding LLVM IR at compiler level
Option 2: Use AsmFull to implement
Related Files
emb/device/riscv/csr.go - CSR operation functions that need implementation
- TinyGo reference implementation:
tinygo/compiler/inlineasm.go
- Validation targets:
riscv-qemu, hifive1b and other RISC-V targets
Priority
This is a blocking issue for complete TinyGo device package migration, affecting embedded development support for RISC-V platforms.
Technical Details
The CSR operations are fundamental for RISC-V embedded programming:
- CSR.Get(): Read CSR register value
- CSR.Set(): Write CSR register value
- CSR.SetBits(): Atomically set specific bits
- CSR.ClearBits(): Atomically clear specific bits
These operations typically compile to RISC-V CSR instructions like csrr, csrw, csrs, csrc.
Background
During the migration of TinyGo device packages to goplus/lib/emb, we discovered that RISC-V CSR (Control and Status Register) operations require built-in compiler support.
Problem Description
Current Status
emb/device/riscv/csr.goCSR.Get(),CSR.Set(),CSR.SetBits(),CSR.ClearBits()TinyGo Implementation
In TinyGo, these CSR operations are implemented as compiler intrinsics:
tinygo/compiler/inlineasm.gofunc (b *builder) emitCSROperation(call *ssa.CallCommon) (llvm.Value, error)Current Temporary Solution
Requirements
Option 1: LLGO Compiler Built-in Support
Option 2: Use AsmFull to implement
Related Files
emb/device/riscv/csr.go- CSR operation functions that need implementationtinygo/compiler/inlineasm.goriscv-qemu,hifive1band other RISC-V targetsPriority
This is a blocking issue for complete TinyGo device package migration, affecting embedded development support for RISC-V platforms.
Technical Details
The CSR operations are fundamental for RISC-V embedded programming:
These operations typically compile to RISC-V CSR instructions like
csrr,csrw,csrs,csrc.