- function `decode_action calculate_action(
- input [6:0] funct7,
- input [2:0] funct3,
- input [4:0] rd,
- input [4:0] rs1,
- input [4:0] rs2,
- input [31:0] immediate,
- input [6:0] opcode);
- begin
- case(opcode)
- `opcode_system: begin
- case(funct3)
- `funct3_ecall_ebreak:
- if((rs1 != 0) | (rd != 0) | ((immediate & ~32'b1) != 0))
- calculate_action = `decode_action_trap_illegal_instruction;
- else
- calculate_action = `decode_action_trap_ecall_ebreak;
- `funct3_csrrw,
- `funct3_csrrs,
- `funct3_csrrc,
- `funct3_csrrwi,
- `funct3_csrrsi,
- `funct3_csrrci:
- calculate_action = `decode_action_csr;
- default:
- calculate_action = `decode_action_trap_illegal_instruction;
- endcase
- end
- `opcode_load_fp,
- `opcode_custom_0,
- `opcode_op_imm_32,
- `opcode_48b_escape_0,
- `opcode_store_fp,
- `opcode_custom_1,
- `opcode_amo,
- `opcode_op_32,
- `opcode_64b_escape,
- `opcode_madd,
- `opcode_msub,
- `opcode_nmsub,
- `opcode_nmadd,
- `opcode_op_fp,
- `opcode_reserved_10101,
- `opcode_rv128_0,
- `opcode_48b_escape_1,
- `opcode_reserved_11010,
- `opcode_reserved_11101,
- `opcode_rv128_1,
- `opcode_80b_escape: begin
- calculate_action = `decode_action_trap_illegal_instruction;
- end
- default:
- calculate_action = `decode_action_trap_illegal_instruction;
- endcase
- end
- endfunction
-
- assign decode_action = calculate_action(funct7,
- funct3,
- rd,
- rs1,
- rs2,
- immediate,
- opcode);
-
- endmodule
-"""
+ this is a first level case statement that calls down to 2nd
+ level case (and in some cases if logic) mostly using funct3
+ (funct7 in the case of arith ops).
+ """
+ c = {}
+ c[OP.load ] = self.calculate_load_action()
+ c[OP.misc_mem] = self.calculate_misc_action()
+ c[OP.op_imm ] = self.calculate_op_action()
+ c[OP.op ] = self.calculate_op_action()
+ c[OP.lui ] = self.decode_action.eq(DA.lui_auipc)
+ c[OP.auipc ] = self.decode_action.eq(DA.lui_auipc)
+ c[OP.store ] = self.calculate_store_action()
+ c[OP.branch ] = self.calculate_branch_action()
+ c[OP.jalr ] = self.calculate_jalr_action()
+ c[OP.jal ] = self.decode_action.eq(DA.jal)
+ c[OP.system ] = self.calculate_system_action()
+
+ # big batch of unrecognised opcodes: throw trap.
+ for o in [ OP.load_fp, OP.custom_0, OP.op_imm_32,
+ OP.op_48b_escape_0, OP.store_fp, OP.custom_1,
+ OP.amo, OP.op_32, OP.op_64b_escape,
+ OP.madd, OP.msub, OP.nmsub,
+ OP.nmadd, OP.op_fp, OP.reserved_10101,
+ OP.rv128_0, OP.op_48b_escape_1, OP.reserved_11010,
+ OP.reserved_11101, OP.rv128_1, OP.op_80b_escape,
+ "default", ]:
+ c[o] = self.decode_action.eq(DA.trap_illegal_instruction)