@@ -90,8 +90,8 @@ RV_EXCEPTION_LIST
90
90
static inline bool op_load (struct riscv_t * rv , uint32_t insn UNUSED )
91
91
{
92
92
/* I-type
93
- * 31 26 21 16 11 9 6 0
94
- * [ rd 5][ rs1 5][ immhi 5][ immlo 7][fun3][ opcode 7]
93
+ * 31 20 19 15 14 12 11 7 6 0
94
+ * | imm[11:0] | rs1 | funct3 | rd | opcode |
95
95
*/
96
96
const int32_t imm = dec_itype_imm (insn );
97
97
const uint32_t rs1 = dec_rs1 (insn );
@@ -167,8 +167,8 @@ static inline bool op_misc_mem(struct riscv_t *rv, uint32_t insn UNUSED)
167
167
static inline bool op_op_imm (struct riscv_t * rv , uint32_t insn )
168
168
{
169
169
/* I-type
170
- * 31 26 21 16 11 9 6 0
171
- * [ rd 5][ rs1 5][ immhi 5][ immlo 7][fun3][ opcode 7]
170
+ * 31 20 19 15 14 12 11 7 6 0
171
+ * | imm[11:0] | rs1 | funct3 | rd | opcode |
172
172
*/
173
173
const int32_t imm = dec_itype_imm (insn );
174
174
const uint32_t rd = dec_rd (insn );
@@ -268,8 +268,8 @@ static inline bool op_op_imm(struct riscv_t *rv, uint32_t insn)
268
268
static inline bool op_auipc (struct riscv_t * rv , uint32_t insn )
269
269
{
270
270
/* U-type
271
- * 31 26 21 16 11 9 6 0
272
- * [ rd 5][ upper immediate 19][ opcode 7]
271
+ * 31 12 11 7 6 0
272
+ * | imm[31:12] | rd | opcode |
273
273
*/
274
274
const uint32_t rd = dec_rd (insn );
275
275
const uint32_t val = dec_utype_imm (insn ) + rv -> PC ;
@@ -287,7 +287,8 @@ static inline bool op_auipc(struct riscv_t *rv, uint32_t insn)
287
287
static inline bool op_store (struct riscv_t * rv , uint32_t insn )
288
288
{
289
289
/* S-type
290
- * | imm[11:5] | rs2 | rs1 | imm[4:0] | rd | opcode |
290
+ * 31 25 24 20 19 15 14 12 11 7 6 0
291
+ * | imm[11:5] | rs2 | rs1 | funct3 | imm[4:0] | opcode |
291
292
*/
292
293
const int32_t imm = dec_stype_imm (insn );
293
294
const uint32_t rs1 = dec_rs1 (insn ), rs2 = dec_rs2 (insn );
@@ -335,8 +336,8 @@ static inline bool op_store(struct riscv_t *rv, uint32_t insn)
335
336
static inline bool op_op (struct riscv_t * rv , uint32_t insn )
336
337
{
337
338
/* R-type
338
- * 31 26 21 16 11 9 6 0
339
- * [ rd 5][ rs1 5][ rs2 5][ funct 10][ opcode 7]
339
+ * 31 25 24 20 19 15 14 12 11 7 6 0
340
+ * | funct7 | rs2 | rs1 | funct3 | rd | opcode |
340
341
*/
341
342
const uint32_t rd = dec_rd (insn );
342
343
const uint32_t funct3 = dec_funct3 (insn );
@@ -496,8 +497,8 @@ static inline bool op_op(struct riscv_t *rv, uint32_t insn)
496
497
static inline bool op_lui (struct riscv_t * rv , uint32_t insn )
497
498
{
498
499
/* U-type
499
- * 31 26 21 16 11 9 6 0
500
- * [ rd 5][ upper immediate 19][ opcode 7]
500
+ * 31 12 11 7 6 0
501
+ * | imm[31:12] | rd | opcode |
501
502
*/
502
503
const uint32_t rd = dec_rd (insn );
503
504
const uint32_t val = dec_utype_imm (insn );
@@ -517,8 +518,8 @@ static inline bool op_branch(struct riscv_t *rv, uint32_t insn)
517
518
const uint32_t pc = rv -> PC ;
518
519
519
520
/* B-type
520
- * 31 26 21 16 11 9 6 0
521
- * [ immhi 5][ rs1 5][ rs2 5][ immlo 7][fun3][ opcode 7]
521
+ * 31 30 25 24 20 19 15 14 12 11 8 7 6 0
522
+ * | imm[12] | imm[10:5] | rs2 | rs1 | funct3 | imm[4:1] | imm[11] | opcode|
522
523
*/
523
524
const uint32_t func3 = dec_funct3 (insn );
524
525
const int32_t imm = dec_btype_imm (insn );
@@ -586,8 +587,8 @@ static inline bool op_jalr(struct riscv_t *rv, uint32_t insn)
586
587
const uint32_t pc = rv -> PC ;
587
588
588
589
/* I-type
589
- * 31 26 21 16 11 9 6 0
590
- * [ rd 5][ rs1 5][ immhi 5][ immlo 7][fun3][ opcode 7]
590
+ * 31 20 19 15 14 12 11 7 6 0
591
+ * | imm[11:0] | rs1 | funct3 | rd | opcode |
591
592
*/
592
593
const uint32_t rd = dec_rd (insn );
593
594
const uint32_t rs1 = dec_rs1 (insn );
@@ -627,8 +628,8 @@ static inline bool op_jal(struct riscv_t *rv, uint32_t insn)
627
628
const uint32_t pc = rv -> PC ;
628
629
629
630
/* J-type
630
- * 31 26 21 16 11 9 6 0
631
- * [ jump target 25][ opcode 7]
631
+ * 31 30 21 20 19 12 11 7 6 0
632
+ * | imm[20] | imm[10:1] | imm[11] | imm[19:12] | rd | opcode |
632
633
*/
633
634
const uint32_t rd = dec_rd (insn );
634
635
const int32_t rel = dec_jtype_imm (insn );
@@ -752,10 +753,15 @@ static uint32_t csr_csrrc(struct riscv_t *rv, uint32_t csr, uint32_t val)
752
753
static inline bool op_system (struct riscv_t * rv , uint32_t insn )
753
754
{
754
755
/* I-type
755
- * 31 26 21 16 11 9 6 0
756
- * [ rd 5][ rs1 5][ immhi 5][ immlo 7][fun3][ opcode 7]
756
+ * system instruction
757
+ * 31 20 19 15 14 12 11 7 6 0
758
+ * | funct12 | rs1 | funct3 | rd | opcode |
759
+ *
760
+ * csr instruction
761
+ * 31 20 19 15 14 12 11 7 6 0
762
+ * | csr | rs1 | funct3 | rd | opcode |
757
763
*/
758
- const int32_t imm = dec_itype_imm (insn );
764
+ const int32_t funct12 = dec_funct12 (insn );
759
765
const int32_t csr = dec_csr (insn );
760
766
const uint32_t funct3 = dec_funct3 (insn );
761
767
const uint32_t rs1 = dec_rs1 (insn );
@@ -764,13 +770,13 @@ static inline bool op_system(struct riscv_t *rv, uint32_t insn)
764
770
/* dispatch by func3 field */
765
771
switch (funct3 ) {
766
772
case 0 :
767
- switch (imm ) { /* dispatch from imm field */
768
- case 0 : /* ECALL: Environment Call */
773
+ switch (funct12 ) { /* dispatch from imm field */
774
+ case 0 : /* ECALL: Environment Call */
769
775
rv -> io .on_ecall (rv );
770
776
break ;
771
777
case 1 : /* EBREAK: Environment Break */
772
778
rv -> io .on_ebreak (rv );
773
- break ;
779
+ return true ;
774
780
case 0x002 : /* URET: Return from handling an interrupt or exception */
775
781
case 0x102 : /* SRET */
776
782
case 0x202 : /* HRET */
0 commit comments