Skip to content

Commit a975589

Browse files
committed
sys/risc-v: Conditionally omit EBREAK and ECALL
This allows us to "overwrite" them in the Zicsr extension.
1 parent 2a5bd50 commit a975589

File tree

2 files changed

+18
-9
lines changed

2 files changed

+18
-9
lines changed

vadl/test/resources/testSource/sys/risc-v/rv3264im.vadl

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,11 @@ instruction set architecture RV3264I = {
2727
constant Arch32 = 32 // 32 bit architecture
2828
constant Arch64 = 64 // 64 bit architecture
2929

30+
// use `with("DoEBreakCall=EBreakCallDisabled")` to omit EBREAK and ECALL
31+
model DoEBreakCall(): Id = { EBreakCallEnabled }
32+
constant EBreakCallEnabled = true
33+
constant EBreakCallDisabled = false
34+
3035
constant MLen = $ArchSize() // MLen = 32 or 64 depending on ArchSize
3136
constant SftLen = (MLen / 32) + 4 // number of bits needed for shift amount (5 or 6)
3237
constant WLen = 32 // 32 bit word length in 64 bit mode
@@ -250,8 +255,10 @@ instruction set architecture RV3264I = {
250255
$JLinkInstr (JALR ; Itype ; X(rs1) ; opcode = 0b110'0111, // jump and link register
251256
funct3 = 0b000 ; imm as SInt<12> ; ("(", register(rs1), ")"))
252257

253-
$ECallInstr (ECALL ; 0) // environment (sys) call
254-
// $ECallInstr (EBREAK; 1) // environment (sys) break
258+
match : IsaDefs ($DoEBreakCall() = EBreakCallEnabled =>
259+
$ECallInstr (ECALL ; 0) // environment (sys) call
260+
$ECallInstr (EBREAK; 1) // environment (sys) break
261+
; _ => )
255262

256263
$Arch3264 ( // ((((((((((((((((((((((((((((((((((((((((
257264

vadl/test/resources/testSource/sys/risc-v/rv32csr.vadl

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
// RISC-V 32 IM Zicsr instruction set (CSR - Control and Status Registers)
55

6-
import rv3264im::RV3264IM
6+
import rv3264im::RV3264IM with ("DoEBreakCall=EBreakCallDisabled") // omit EBREAK and ECALL as we define them here
77

88
instruction set architecture RV32IM extending RV3264IM = {}
99

@@ -136,17 +136,19 @@ instruction set architecture RV32Zicsr extending RV32IM = {
136136
// mstatus.mpp := PRV::M // we only support machine mode at the moment
137137
// mstatus.mie := 0
138138
// clear two lsb
139-
PC := mtvec & ~0x3
139+
PC := mtvec
140140
}
141141

142142
//// INSTRUCTIONS ////
143143

144-
// Environment Breakpoint
145-
instruction EBREAK : Itype =
146-
raise Exc(ExcCode::BREAKPOINT)
144+
model ECallInstr (name : Id, imm : Lit, excCode: Id) : IsaDefs = {
145+
instruction $name : Itype = raise Exc(ExcCode::$excCode) // ecall / ebreak instructions
146+
encoding $name = {opcode = 0b111'0011, funct3 = 0b000, rd = 0b0'0000, rs1 = 0b0'0000, imm = $imm}
147+
assembly $name = (mnemonic)
148+
}
147149

148-
encoding EBREAK = { opcode = 0b111'0011, funct3 = 0b000, imm = 0b0000'0000'0001, rs1 = 0b00000, rd = 0b00000 }
149-
assembly EBREAK = mnemonic
150+
$ECallInstr (ECALL ; 0; M_ECALL) // environment (sys) call
151+
$ECallInstr (EBREAK; 1; BREAKPOINT) // environment (sys) break
150152

151153
// return from trap
152154
instruction MRET: Itype = {

0 commit comments

Comments
 (0)