From dab9791fab729e6d45a83002b0fb5f58255603d3 Mon Sep 17 00:00:00 2001 From: Luke Kenneth Casson Leighton Date: Sat, 13 Oct 2018 14:40:30 +0100 Subject: [PATCH] add sv_reg_t --- riscv/sv_insn_decl.h | 460 ++++++++++++++++++++++++++++++++++++++ riscv/sv_insn_redirect.cc | 122 ++++++++-- riscv/sv_insn_redirect.h | 69 ++++-- riscv/sv_reg.h | 130 +++++++++++ 4 files changed, 749 insertions(+), 32 deletions(-) create mode 100644 riscv/sv_insn_decl.h create mode 100644 riscv/sv_reg.h diff --git a/riscv/sv_insn_decl.h b/riscv/sv_insn_decl.h new file mode 100644 index 0000000..f8378a9 --- /dev/null +++ b/riscv/sv_insn_decl.h @@ -0,0 +1,460 @@ + reg_t (rv32_bne) (processor_t* p, insn_t s_insn, reg_t pc); + reg_t (rv64_bne) (processor_t* p, insn_t s_insn, reg_t pc); + reg_t (rv32_fsqrt_s) (processor_t* p, insn_t s_insn, reg_t pc); + reg_t (rv64_fsqrt_s) (processor_t* p, insn_t s_insn, reg_t pc); + reg_t (rv32_c_lwsp) (processor_t* p, insn_t s_insn, reg_t pc); + reg_t (rv64_c_lwsp) (processor_t* p, insn_t s_insn, reg_t pc); + reg_t (rv32_fsgnj_d) (processor_t* p, insn_t s_insn, reg_t pc); + reg_t (rv64_fsgnj_d) (processor_t* p, insn_t s_insn, reg_t pc); + reg_t (rv32_addw) (processor_t* p, insn_t s_insn, reg_t pc); + reg_t (rv64_addw) (processor_t* p, insn_t s_insn, reg_t pc); + reg_t (rv32_fadd_d) (processor_t* p, insn_t s_insn, reg_t pc); + reg_t (rv64_fadd_d) (processor_t* p, insn_t s_insn, reg_t pc); + reg_t (rv32_fmul_s) (processor_t* p, insn_t s_insn, reg_t pc); + reg_t (rv64_fmul_s) (processor_t* p, insn_t s_insn, reg_t pc); + reg_t (rv32_fmadd_d) (processor_t* p, insn_t s_insn, reg_t pc); + reg_t (rv64_fmadd_d) (processor_t* p, insn_t s_insn, reg_t pc); + reg_t (rv32_xor) (processor_t* p, insn_t s_insn, reg_t pc); + reg_t (rv64_xor) (processor_t* p, insn_t s_insn, reg_t pc); + reg_t (rv32_jal) (processor_t* p, insn_t s_insn, reg_t pc); + reg_t (rv64_jal) (processor_t* p, insn_t s_insn, reg_t pc); + reg_t (rv32_c_ebreak) (processor_t* p, insn_t s_insn, reg_t pc); + reg_t (rv64_c_ebreak) (processor_t* p, insn_t s_insn, reg_t pc); + reg_t (rv32_fcvt_s_l) (processor_t* p, insn_t s_insn, reg_t pc); + reg_t (rv64_fcvt_s_l) (processor_t* p, insn_t s_insn, reg_t pc); + reg_t (rv32_c_xor) (processor_t* p, insn_t s_insn, reg_t pc); + reg_t (rv64_c_xor) (processor_t* p, insn_t s_insn, reg_t pc); + reg_t (rv32_fcvt_l_q) (processor_t* p, insn_t s_insn, reg_t pc); + reg_t (rv64_fcvt_l_q) (processor_t* p, insn_t s_insn, reg_t pc); + reg_t (rv32_c_lw) (processor_t* p, insn_t s_insn, reg_t pc); + reg_t (rv64_c_lw) (processor_t* p, insn_t s_insn, reg_t pc); + reg_t (rv32_sc_d) (processor_t* p, insn_t s_insn, reg_t pc); + reg_t (rv64_sc_d) (processor_t* p, insn_t s_insn, reg_t pc); + reg_t (rv32_amomax_w) (processor_t* p, insn_t s_insn, reg_t pc); + reg_t (rv64_amomax_w) (processor_t* p, insn_t s_insn, reg_t pc); + reg_t (rv32_beq) (processor_t* p, insn_t s_insn, reg_t pc); + reg_t (rv64_beq) (processor_t* p, insn_t s_insn, reg_t pc); + reg_t (rv32_c_lui) (processor_t* p, insn_t s_insn, reg_t pc); + reg_t (rv64_c_lui) (processor_t* p, insn_t s_insn, reg_t pc); + reg_t (rv32_remu) (processor_t* p, insn_t s_insn, reg_t pc); + reg_t (rv64_remu) (processor_t* p, insn_t s_insn, reg_t pc); + reg_t (rv32_fsgnjx_d) (processor_t* p, insn_t s_insn, reg_t pc); + reg_t (rv64_fsgnjx_d) (processor_t* p, insn_t s_insn, reg_t pc); + reg_t (rv32_fcvt_s_wu) (processor_t* p, insn_t s_insn, reg_t pc); + reg_t (rv64_fcvt_s_wu) (processor_t* p, insn_t s_insn, reg_t pc); + reg_t (rv32_c_fsw) (processor_t* p, insn_t s_insn, reg_t pc); + reg_t (rv64_c_fsw) (processor_t* p, insn_t s_insn, reg_t pc); + reg_t (rv32_fnmsub_d) (processor_t* p, insn_t s_insn, reg_t pc); + reg_t (rv64_fnmsub_d) (processor_t* p, insn_t s_insn, reg_t pc); + reg_t (rv32_feq_d) (processor_t* p, insn_t s_insn, reg_t pc); + reg_t (rv64_feq_d) (processor_t* p, insn_t s_insn, reg_t pc); + reg_t (rv32_c_flw) (processor_t* p, insn_t s_insn, reg_t pc); + reg_t (rv64_c_flw) (processor_t* p, insn_t s_insn, reg_t pc); + reg_t (rv32_fsq) (processor_t* p, insn_t s_insn, reg_t pc); + reg_t (rv64_fsq) (processor_t* p, insn_t s_insn, reg_t pc); + reg_t (rv32_csrrs) (processor_t* p, insn_t s_insn, reg_t pc); + reg_t (rv64_csrrs) (processor_t* p, insn_t s_insn, reg_t pc); + reg_t (rv32_fcvt_d_q) (processor_t* p, insn_t s_insn, reg_t pc); + reg_t (rv64_fcvt_d_q) (processor_t* p, insn_t s_insn, reg_t pc); + reg_t (rv32_c_srai) (processor_t* p, insn_t s_insn, reg_t pc); + reg_t (rv64_c_srai) (processor_t* p, insn_t s_insn, reg_t pc); + reg_t (rv32_c_jal) (processor_t* p, insn_t s_insn, reg_t pc); + reg_t (rv64_c_jal) (processor_t* p, insn_t s_insn, reg_t pc); + reg_t (rv32_and) (processor_t* p, insn_t s_insn, reg_t pc); + reg_t (rv64_and) (processor_t* p, insn_t s_insn, reg_t pc); + reg_t (rv32_c_and) (processor_t* p, insn_t s_insn, reg_t pc); + reg_t (rv64_c_and) (processor_t* p, insn_t s_insn, reg_t pc); + reg_t (rv32_amoor_w) (processor_t* p, insn_t s_insn, reg_t pc); + reg_t (rv64_amoor_w) (processor_t* p, insn_t s_insn, reg_t pc); + reg_t (rv32_bgeu) (processor_t* p, insn_t s_insn, reg_t pc); + reg_t (rv64_bgeu) (processor_t* p, insn_t s_insn, reg_t pc); + reg_t (rv32_fnmadd_d) (processor_t* p, insn_t s_insn, reg_t pc); + reg_t (rv64_fnmadd_d) (processor_t* p, insn_t s_insn, reg_t pc); + reg_t (rv32_ecall) (processor_t* p, insn_t s_insn, reg_t pc); + reg_t (rv64_ecall) (processor_t* p, insn_t s_insn, reg_t pc); + reg_t (rv32_c_andi) (processor_t* p, insn_t s_insn, reg_t pc); + reg_t (rv64_c_andi) (processor_t* p, insn_t s_insn, reg_t pc); + reg_t (rv32_mret) (processor_t* p, insn_t s_insn, reg_t pc); + reg_t (rv64_mret) (processor_t* p, insn_t s_insn, reg_t pc); + reg_t (rv32_fsgnjx_q) (processor_t* p, insn_t s_insn, reg_t pc); + reg_t (rv64_fsgnjx_q) (processor_t* p, insn_t s_insn, reg_t pc); + reg_t (rv32_fsub_s) (processor_t* p, insn_t s_insn, reg_t pc); + reg_t (rv64_fsub_s) (processor_t* p, insn_t s_insn, reg_t pc); + reg_t (rv32_fence_i) (processor_t* p, insn_t s_insn, reg_t pc); + reg_t (rv64_fence_i) (processor_t* p, insn_t s_insn, reg_t pc); + reg_t (rv32_fnmadd_s) (processor_t* p, insn_t s_insn, reg_t pc); + reg_t (rv64_fnmadd_s) (processor_t* p, insn_t s_insn, reg_t pc); + reg_t (rv32_fcvt_d_w) (processor_t* p, insn_t s_insn, reg_t pc); + reg_t (rv64_fcvt_d_w) (processor_t* p, insn_t s_insn, reg_t pc); + reg_t (rv32_c_j) (processor_t* p, insn_t s_insn, reg_t pc); + reg_t (rv64_c_j) (processor_t* p, insn_t s_insn, reg_t pc); + reg_t (rv32_blt) (processor_t* p, insn_t s_insn, reg_t pc); + reg_t (rv64_blt) (processor_t* p, insn_t s_insn, reg_t pc); + reg_t (rv32_sltiu) (processor_t* p, insn_t s_insn, reg_t pc); + reg_t (rv64_sltiu) (processor_t* p, insn_t s_insn, reg_t pc); + reg_t (rv32_fmul_q) (processor_t* p, insn_t s_insn, reg_t pc); + reg_t (rv64_fmul_q) (processor_t* p, insn_t s_insn, reg_t pc); + reg_t (rv32_feq_q) (processor_t* p, insn_t s_insn, reg_t pc); + reg_t (rv64_feq_q) (processor_t* p, insn_t s_insn, reg_t pc); + reg_t (rv32_fclass_q) (processor_t* p, insn_t s_insn, reg_t pc); + reg_t (rv64_fclass_q) (processor_t* p, insn_t s_insn, reg_t pc); + reg_t (rv32_ld) (processor_t* p, insn_t s_insn, reg_t pc); + reg_t (rv64_ld) (processor_t* p, insn_t s_insn, reg_t pc); + reg_t (rv32_c_add) (processor_t* p, insn_t s_insn, reg_t pc); + reg_t (rv64_c_add) (processor_t* p, insn_t s_insn, reg_t pc); + reg_t (rv32_srl) (processor_t* p, insn_t s_insn, reg_t pc); + reg_t (rv64_srl) (processor_t* p, insn_t s_insn, reg_t pc); + reg_t (rv32_ebreak) (processor_t* p, insn_t s_insn, reg_t pc); + reg_t (rv64_ebreak) (processor_t* p, insn_t s_insn, reg_t pc); + reg_t (rv32_fmv_d_x) (processor_t* p, insn_t s_insn, reg_t pc); + reg_t (rv64_fmv_d_x) (processor_t* p, insn_t s_insn, reg_t pc); + reg_t (rv32_fmin_s) (processor_t* p, insn_t s_insn, reg_t pc); + reg_t (rv64_fmin_s) (processor_t* p, insn_t s_insn, reg_t pc); + reg_t (rv32_fmax_d) (processor_t* p, insn_t s_insn, reg_t pc); + reg_t (rv64_fmax_d) (processor_t* p, insn_t s_insn, reg_t pc); + reg_t (rv32_c_fsd) (processor_t* p, insn_t s_insn, reg_t pc); + reg_t (rv64_c_fsd) (processor_t* p, insn_t s_insn, reg_t pc); + reg_t (rv32_xori) (processor_t* p, insn_t s_insn, reg_t pc); + reg_t (rv64_xori) (processor_t* p, insn_t s_insn, reg_t pc); + reg_t (rv32_c_bnez) (processor_t* p, insn_t s_insn, reg_t pc); + reg_t (rv64_c_bnez) (processor_t* p, insn_t s_insn, reg_t pc); + reg_t (rv32_sltu) (processor_t* p, insn_t s_insn, reg_t pc); + reg_t (rv64_sltu) (processor_t* p, insn_t s_insn, reg_t pc); + reg_t (rv32_divuw) (processor_t* p, insn_t s_insn, reg_t pc); + reg_t (rv64_divuw) (processor_t* p, insn_t s_insn, reg_t pc); + reg_t (rv32_fdiv_s) (processor_t* p, insn_t s_insn, reg_t pc); + reg_t (rv64_fdiv_s) (processor_t* p, insn_t s_insn, reg_t pc); + reg_t (rv32_flt_d) (processor_t* p, insn_t s_insn, reg_t pc); + reg_t (rv64_flt_d) (processor_t* p, insn_t s_insn, reg_t pc); + reg_t (rv32_c_srli) (processor_t* p, insn_t s_insn, reg_t pc); + reg_t (rv64_c_srli) (processor_t* p, insn_t s_insn, reg_t pc); + reg_t (rv32_sv_beq) (processor_t* p, insn_t s_insn, reg_t pc); + reg_t (rv64_sv_beq) (processor_t* p, insn_t s_insn, reg_t pc); + reg_t (rv32_sraw) (processor_t* p, insn_t s_insn, reg_t pc); + reg_t (rv64_sraw) (processor_t* p, insn_t s_insn, reg_t pc); + reg_t (rv32_c_jr) (processor_t* p, insn_t s_insn, reg_t pc); + reg_t (rv64_c_jr) (processor_t* p, insn_t s_insn, reg_t pc); + reg_t (rv32_amominu_d) (processor_t* p, insn_t s_insn, reg_t pc); + reg_t (rv64_amominu_d) (processor_t* p, insn_t s_insn, reg_t pc); + reg_t (rv32_fcvt_s_w) (processor_t* p, insn_t s_insn, reg_t pc); + reg_t (rv64_fcvt_s_w) (processor_t* p, insn_t s_insn, reg_t pc); + reg_t (rv32_auipc) (processor_t* p, insn_t s_insn, reg_t pc); + reg_t (rv64_auipc) (processor_t* p, insn_t s_insn, reg_t pc); + reg_t (rv32_slli) (processor_t* p, insn_t s_insn, reg_t pc); + reg_t (rv64_slli) (processor_t* p, insn_t s_insn, reg_t pc); + reg_t (rv32_c_mv) (processor_t* p, insn_t s_insn, reg_t pc); + reg_t (rv64_c_mv) (processor_t* p, insn_t s_insn, reg_t pc); + reg_t (rv32_c_sub) (processor_t* p, insn_t s_insn, reg_t pc); + reg_t (rv64_c_sub) (processor_t* p, insn_t s_insn, reg_t pc); + reg_t (rv32_fsqrt_q) (processor_t* p, insn_t s_insn, reg_t pc); + reg_t (rv64_fsqrt_q) (processor_t* p, insn_t s_insn, reg_t pc); + reg_t (rv32_fnmadd_q) (processor_t* p, insn_t s_insn, reg_t pc); + reg_t (rv64_fnmadd_q) (processor_t* p, insn_t s_insn, reg_t pc); + reg_t (rv32_srli) (processor_t* p, insn_t s_insn, reg_t pc); + reg_t (rv64_srli) (processor_t* p, insn_t s_insn, reg_t pc); + reg_t (rv32_fsgnjn_q) (processor_t* p, insn_t s_insn, reg_t pc); + reg_t (rv64_fsgnjn_q) (processor_t* p, insn_t s_insn, reg_t pc); + reg_t (rv32_c_fsdsp) (processor_t* p, insn_t s_insn, reg_t pc); + reg_t (rv64_c_fsdsp) (processor_t* p, insn_t s_insn, reg_t pc); + reg_t (rv32_c_li) (processor_t* p, insn_t s_insn, reg_t pc); + reg_t (rv64_c_li) (processor_t* p, insn_t s_insn, reg_t pc); + reg_t (rv32_fclass_s) (processor_t* p, insn_t s_insn, reg_t pc); + reg_t (rv64_fclass_s) (processor_t* p, insn_t s_insn, reg_t pc); + reg_t (rv32_amoadd_w) (processor_t* p, insn_t s_insn, reg_t pc); + reg_t (rv64_amoadd_w) (processor_t* p, insn_t s_insn, reg_t pc); + reg_t (rv32_bltu) (processor_t* p, insn_t s_insn, reg_t pc); + reg_t (rv64_bltu) (processor_t* p, insn_t s_insn, reg_t pc); + reg_t (rv32_fcvt_s_q) (processor_t* p, insn_t s_insn, reg_t pc); + reg_t (rv64_fcvt_s_q) (processor_t* p, insn_t s_insn, reg_t pc); + reg_t (rv32_lr_d) (processor_t* p, insn_t s_insn, reg_t pc); + reg_t (rv64_lr_d) (processor_t* p, insn_t s_insn, reg_t pc); + reg_t (rv32_mulw) (processor_t* p, insn_t s_insn, reg_t pc); + reg_t (rv64_mulw) (processor_t* p, insn_t s_insn, reg_t pc); + reg_t (rv32_c_fld) (processor_t* p, insn_t s_insn, reg_t pc); + reg_t (rv64_c_fld) (processor_t* p, insn_t s_insn, reg_t pc); + reg_t (rv32_rem) (processor_t* p, insn_t s_insn, reg_t pc); + reg_t (rv64_rem) (processor_t* p, insn_t s_insn, reg_t pc); + reg_t (rv32_amoand_d) (processor_t* p, insn_t s_insn, reg_t pc); + reg_t (rv64_amoand_d) (processor_t* p, insn_t s_insn, reg_t pc); + reg_t (rv32_fsqrt_d) (processor_t* p, insn_t s_insn, reg_t pc); + reg_t (rv64_fsqrt_d) (processor_t* p, insn_t s_insn, reg_t pc); + reg_t (rv32_add) (processor_t* p, insn_t s_insn, reg_t pc); + reg_t (rv64_add) (processor_t* p, insn_t s_insn, reg_t pc); + reg_t (rv32_fcvt_w_s) (processor_t* p, insn_t s_insn, reg_t pc); + reg_t (rv64_fcvt_w_s) (processor_t* p, insn_t s_insn, reg_t pc); + reg_t (rv32_sfence_vma) (processor_t* p, insn_t s_insn, reg_t pc); + reg_t (rv64_sfence_vma) (processor_t* p, insn_t s_insn, reg_t pc); + reg_t (rv32_fmsub_s) (processor_t* p, insn_t s_insn, reg_t pc); + reg_t (rv64_fmsub_s) (processor_t* p, insn_t s_insn, reg_t pc); + reg_t (rv32_c_addi) (processor_t* p, insn_t s_insn, reg_t pc); + reg_t (rv64_c_addi) (processor_t* p, insn_t s_insn, reg_t pc); + reg_t (rv32_lhu) (processor_t* p, insn_t s_insn, reg_t pc); + reg_t (rv64_lhu) (processor_t* p, insn_t s_insn, reg_t pc); + reg_t (rv32_sv_csrrwi) (processor_t* p, insn_t s_insn, reg_t pc); + reg_t (rv64_sv_csrrwi) (processor_t* p, insn_t s_insn, reg_t pc); + reg_t (rv32_jalr) (processor_t* p, insn_t s_insn, reg_t pc); + reg_t (rv64_jalr) (processor_t* p, insn_t s_insn, reg_t pc); + reg_t (rv32_subw) (processor_t* p, insn_t s_insn, reg_t pc); + reg_t (rv64_subw) (processor_t* p, insn_t s_insn, reg_t pc); + reg_t (rv32_addiw) (processor_t* p, insn_t s_insn, reg_t pc); + reg_t (rv64_addiw) (processor_t* p, insn_t s_insn, reg_t pc); + reg_t (rv32_fsgnj_s) (processor_t* p, insn_t s_insn, reg_t pc); + reg_t (rv64_fsgnj_s) (processor_t* p, insn_t s_insn, reg_t pc); + reg_t (rv32_bge) (processor_t* p, insn_t s_insn, reg_t pc); + reg_t (rv64_bge) (processor_t* p, insn_t s_insn, reg_t pc); + reg_t (rv32_fcvt_d_l) (processor_t* p, insn_t s_insn, reg_t pc); + reg_t (rv64_fcvt_d_l) (processor_t* p, insn_t s_insn, reg_t pc); + reg_t (rv32_divw) (processor_t* p, insn_t s_insn, reg_t pc); + reg_t (rv64_divw) (processor_t* p, insn_t s_insn, reg_t pc); + reg_t (rv32_fcvt_d_s) (processor_t* p, insn_t s_insn, reg_t pc); + reg_t (rv64_fcvt_d_s) (processor_t* p, insn_t s_insn, reg_t pc); + reg_t (rv32_flt_q) (processor_t* p, insn_t s_insn, reg_t pc); + reg_t (rv64_flt_q) (processor_t* p, insn_t s_insn, reg_t pc); + reg_t (rv32_c_addw) (processor_t* p, insn_t s_insn, reg_t pc); + reg_t (rv64_c_addw) (processor_t* p, insn_t s_insn, reg_t pc); + reg_t (rv32_csrrwi) (processor_t* p, insn_t s_insn, reg_t pc); + reg_t (rv64_csrrwi) (processor_t* p, insn_t s_insn, reg_t pc); + reg_t (rv32_mulhsu) (processor_t* p, insn_t s_insn, reg_t pc); + reg_t (rv64_mulhsu) (processor_t* p, insn_t s_insn, reg_t pc); + reg_t (rv32_amoswap_w) (processor_t* p, insn_t s_insn, reg_t pc); + reg_t (rv64_amoswap_w) (processor_t* p, insn_t s_insn, reg_t pc); + reg_t (rv32_fmsub_q) (processor_t* p, insn_t s_insn, reg_t pc); + reg_t (rv64_fmsub_q) (processor_t* p, insn_t s_insn, reg_t pc); + reg_t (rv32_c_subw) (processor_t* p, insn_t s_insn, reg_t pc); + reg_t (rv64_c_subw) (processor_t* p, insn_t s_insn, reg_t pc); + reg_t (rv32_fmv_x_d) (processor_t* p, insn_t s_insn, reg_t pc); + reg_t (rv64_fmv_x_d) (processor_t* p, insn_t s_insn, reg_t pc); + reg_t (rv32_fcvt_d_lu) (processor_t* p, insn_t s_insn, reg_t pc); + reg_t (rv64_fcvt_d_lu) (processor_t* p, insn_t s_insn, reg_t pc); + reg_t (rv32_fmin_d) (processor_t* p, insn_t s_insn, reg_t pc); + reg_t (rv64_fmin_d) (processor_t* p, insn_t s_insn, reg_t pc); + reg_t (rv32_mulhu) (processor_t* p, insn_t s_insn, reg_t pc); + reg_t (rv64_mulhu) (processor_t* p, insn_t s_insn, reg_t pc); + reg_t (rv32_amoswap_d) (processor_t* p, insn_t s_insn, reg_t pc); + reg_t (rv64_amoswap_d) (processor_t* p, insn_t s_insn, reg_t pc); + reg_t (rv32_fsgnj_q) (processor_t* p, insn_t s_insn, reg_t pc); + reg_t (rv64_fsgnj_q) (processor_t* p, insn_t s_insn, reg_t pc); + reg_t (rv32_fcvt_q_d) (processor_t* p, insn_t s_insn, reg_t pc); + reg_t (rv64_fcvt_q_d) (processor_t* p, insn_t s_insn, reg_t pc); + reg_t (rv32_fmul_d) (processor_t* p, insn_t s_insn, reg_t pc); + reg_t (rv64_fmul_d) (processor_t* p, insn_t s_insn, reg_t pc); + reg_t (rv32_lh) (processor_t* p, insn_t s_insn, reg_t pc); + reg_t (rv64_lh) (processor_t* p, insn_t s_insn, reg_t pc); + reg_t (rv32_fcvt_q_lu) (processor_t* p, insn_t s_insn, reg_t pc); + reg_t (rv64_fcvt_q_lu) (processor_t* p, insn_t s_insn, reg_t pc); + reg_t (rv32_fcvt_w_q) (processor_t* p, insn_t s_insn, reg_t pc); + reg_t (rv64_fcvt_w_q) (processor_t* p, insn_t s_insn, reg_t pc); + reg_t (rv32_c_addi4spn) (processor_t* p, insn_t s_insn, reg_t pc); + reg_t (rv64_c_addi4spn) (processor_t* p, insn_t s_insn, reg_t pc); + reg_t (rv32_fmsub_d) (processor_t* p, insn_t s_insn, reg_t pc); + reg_t (rv64_fmsub_d) (processor_t* p, insn_t s_insn, reg_t pc); + reg_t (rv32_fmv_x_w) (processor_t* p, insn_t s_insn, reg_t pc); + reg_t (rv64_fmv_x_w) (processor_t* p, insn_t s_insn, reg_t pc); + reg_t (rv32_lb) (processor_t* p, insn_t s_insn, reg_t pc); + reg_t (rv64_lb) (processor_t* p, insn_t s_insn, reg_t pc); + reg_t (rv32_fnmsub_q) (processor_t* p, insn_t s_insn, reg_t pc); + reg_t (rv64_fnmsub_q) (processor_t* p, insn_t s_insn, reg_t pc); + reg_t (rv32_fcvt_wu_s) (processor_t* p, insn_t s_insn, reg_t pc); + reg_t (rv64_fcvt_wu_s) (processor_t* p, insn_t s_insn, reg_t pc); + reg_t (rv32_fsw) (processor_t* p, insn_t s_insn, reg_t pc); + reg_t (rv64_fsw) (processor_t* p, insn_t s_insn, reg_t pc); + reg_t (rv32_slti) (processor_t* p, insn_t s_insn, reg_t pc); + reg_t (rv64_slti) (processor_t* p, insn_t s_insn, reg_t pc); + reg_t (rv32_wfi) (processor_t* p, insn_t s_insn, reg_t pc); + reg_t (rv64_wfi) (processor_t* p, insn_t s_insn, reg_t pc); + reg_t (rv32_c_or) (processor_t* p, insn_t s_insn, reg_t pc); + reg_t (rv64_c_or) (processor_t* p, insn_t s_insn, reg_t pc); + reg_t (rv32_fsub_q) (processor_t* p, insn_t s_insn, reg_t pc); + reg_t (rv64_fsub_q) (processor_t* p, insn_t s_insn, reg_t pc); + reg_t (rv32_fadd_q) (processor_t* p, insn_t s_insn, reg_t pc); + reg_t (rv64_fadd_q) (processor_t* p, insn_t s_insn, reg_t pc); + reg_t (rv32_remw) (processor_t* p, insn_t s_insn, reg_t pc); + reg_t (rv64_remw) (processor_t* p, insn_t s_insn, reg_t pc); + reg_t (rv32_lr_w) (processor_t* p, insn_t s_insn, reg_t pc); + reg_t (rv64_lr_w) (processor_t* p, insn_t s_insn, reg_t pc); + reg_t (rv32_srai) (processor_t* p, insn_t s_insn, reg_t pc); + reg_t (rv64_srai) (processor_t* p, insn_t s_insn, reg_t pc); + reg_t (rv32_slliw) (processor_t* p, insn_t s_insn, reg_t pc); + reg_t (rv64_slliw) (processor_t* p, insn_t s_insn, reg_t pc); + reg_t (rv32_csrrc) (processor_t* p, insn_t s_insn, reg_t pc); + reg_t (rv64_csrrc) (processor_t* p, insn_t s_insn, reg_t pc); + reg_t (rv32_sh) (processor_t* p, insn_t s_insn, reg_t pc); + reg_t (rv64_sh) (processor_t* p, insn_t s_insn, reg_t pc); + reg_t (rv32_fmin_q) (processor_t* p, insn_t s_insn, reg_t pc); + reg_t (rv64_fmin_q) (processor_t* p, insn_t s_insn, reg_t pc); + reg_t (rv32_amomaxu_w) (processor_t* p, insn_t s_insn, reg_t pc); + reg_t (rv64_amomaxu_w) (processor_t* p, insn_t s_insn, reg_t pc); + reg_t (rv32_ori) (processor_t* p, insn_t s_insn, reg_t pc); + reg_t (rv64_ori) (processor_t* p, insn_t s_insn, reg_t pc); + reg_t (rv32_csrrsi) (processor_t* p, insn_t s_insn, reg_t pc); + reg_t (rv64_csrrsi) (processor_t* p, insn_t s_insn, reg_t pc); + reg_t (rv32_flw) (processor_t* p, insn_t s_insn, reg_t pc); + reg_t (rv64_flw) (processor_t* p, insn_t s_insn, reg_t pc); + reg_t (rv32_sd) (processor_t* p, insn_t s_insn, reg_t pc); + reg_t (rv64_sd) (processor_t* p, insn_t s_insn, reg_t pc); + reg_t (rv32_fcvt_w_d) (processor_t* p, insn_t s_insn, reg_t pc); + reg_t (rv64_fcvt_w_d) (processor_t* p, insn_t s_insn, reg_t pc); + reg_t (rv32_sub) (processor_t* p, insn_t s_insn, reg_t pc); + reg_t (rv64_sub) (processor_t* p, insn_t s_insn, reg_t pc); + reg_t (rv32_fnmsub_s) (processor_t* p, insn_t s_insn, reg_t pc); + reg_t (rv64_fnmsub_s) (processor_t* p, insn_t s_insn, reg_t pc); + reg_t (rv32_c_slli) (processor_t* p, insn_t s_insn, reg_t pc); + reg_t (rv64_c_slli) (processor_t* p, insn_t s_insn, reg_t pc); + reg_t (rv32_c_flwsp) (processor_t* p, insn_t s_insn, reg_t pc); + reg_t (rv64_c_flwsp) (processor_t* p, insn_t s_insn, reg_t pc); + reg_t (rv32_fcvt_q_w) (processor_t* p, insn_t s_insn, reg_t pc); + reg_t (rv64_fcvt_q_w) (processor_t* p, insn_t s_insn, reg_t pc); + reg_t (rv32_fmadd_q) (processor_t* p, insn_t s_insn, reg_t pc); + reg_t (rv64_fmadd_q) (processor_t* p, insn_t s_insn, reg_t pc); + reg_t (rv32_csrrw) (processor_t* p, insn_t s_insn, reg_t pc); + reg_t (rv64_csrrw) (processor_t* p, insn_t s_insn, reg_t pc); + reg_t (rv32_fcvt_s_lu) (processor_t* p, insn_t s_insn, reg_t pc); + reg_t (rv64_fcvt_s_lu) (processor_t* p, insn_t s_insn, reg_t pc); + reg_t (rv32_csrrci) (processor_t* p, insn_t s_insn, reg_t pc); + reg_t (rv64_csrrci) (processor_t* p, insn_t s_insn, reg_t pc); + reg_t (rv32_fmax_s) (processor_t* p, insn_t s_insn, reg_t pc); + reg_t (rv64_fmax_s) (processor_t* p, insn_t s_insn, reg_t pc); + reg_t (rv32_c_beqz) (processor_t* p, insn_t s_insn, reg_t pc); + reg_t (rv64_c_beqz) (processor_t* p, insn_t s_insn, reg_t pc); + reg_t (rv32_andi) (processor_t* p, insn_t s_insn, reg_t pc); + reg_t (rv64_andi) (processor_t* p, insn_t s_insn, reg_t pc); + reg_t (rv32_sc_w) (processor_t* p, insn_t s_insn, reg_t pc); + reg_t (rv64_sc_w) (processor_t* p, insn_t s_insn, reg_t pc); + reg_t (rv32_lui) (processor_t* p, insn_t s_insn, reg_t pc); + reg_t (rv64_lui) (processor_t* p, insn_t s_insn, reg_t pc); + reg_t (rv32_amomin_d) (processor_t* p, insn_t s_insn, reg_t pc); + reg_t (rv64_amomin_d) (processor_t* p, insn_t s_insn, reg_t pc); + reg_t (rv32_c_jalr) (processor_t* p, insn_t s_insn, reg_t pc); + reg_t (rv64_c_jalr) (processor_t* p, insn_t s_insn, reg_t pc); + reg_t (rv32_amoor_d) (processor_t* p, insn_t s_insn, reg_t pc); + reg_t (rv64_amoor_d) (processor_t* p, insn_t s_insn, reg_t pc); + reg_t (rv32_fmax_q) (processor_t* p, insn_t s_insn, reg_t pc); + reg_t (rv64_fmax_q) (processor_t* p, insn_t s_insn, reg_t pc); + reg_t (rv32_feq_s) (processor_t* p, insn_t s_insn, reg_t pc); + reg_t (rv64_feq_s) (processor_t* p, insn_t s_insn, reg_t pc); + reg_t (rv32_mul) (processor_t* p, insn_t s_insn, reg_t pc); + reg_t (rv64_mul) (processor_t* p, insn_t s_insn, reg_t pc); + reg_t (rv32_srlw) (processor_t* p, insn_t s_insn, reg_t pc); + reg_t (rv64_srlw) (processor_t* p, insn_t s_insn, reg_t pc); + reg_t (rv32_sb) (processor_t* p, insn_t s_insn, reg_t pc); + reg_t (rv64_sb) (processor_t* p, insn_t s_insn, reg_t pc); + reg_t (rv32_c_fswsp) (processor_t* p, insn_t s_insn, reg_t pc); + reg_t (rv64_c_fswsp) (processor_t* p, insn_t s_insn, reg_t pc); + reg_t (rv32_lwu) (processor_t* p, insn_t s_insn, reg_t pc); + reg_t (rv64_lwu) (processor_t* p, insn_t s_insn, reg_t pc); + reg_t (rv32_addi) (processor_t* p, insn_t s_insn, reg_t pc); + reg_t (rv64_addi) (processor_t* p, insn_t s_insn, reg_t pc); + reg_t (rv32_fld) (processor_t* p, insn_t s_insn, reg_t pc); + reg_t (rv64_fld) (processor_t* p, insn_t s_insn, reg_t pc); + reg_t (rv32_fle_d) (processor_t* p, insn_t s_insn, reg_t pc); + reg_t (rv64_fle_d) (processor_t* p, insn_t s_insn, reg_t pc); + reg_t (rv32_or) (processor_t* p, insn_t s_insn, reg_t pc); + reg_t (rv64_or) (processor_t* p, insn_t s_insn, reg_t pc); + reg_t (rv32_srliw) (processor_t* p, insn_t s_insn, reg_t pc); + reg_t (rv64_srliw) (processor_t* p, insn_t s_insn, reg_t pc); + reg_t (rv32_amoand_w) (processor_t* p, insn_t s_insn, reg_t pc); + reg_t (rv64_amoand_w) (processor_t* p, insn_t s_insn, reg_t pc); + reg_t (rv32_divu) (processor_t* p, insn_t s_insn, reg_t pc); + reg_t (rv64_divu) (processor_t* p, insn_t s_insn, reg_t pc); + reg_t (rv32_fadd_s) (processor_t* p, insn_t s_insn, reg_t pc); + reg_t (rv64_fadd_s) (processor_t* p, insn_t s_insn, reg_t pc); + reg_t (rv32_dret) (processor_t* p, insn_t s_insn, reg_t pc); + reg_t (rv64_dret) (processor_t* p, insn_t s_insn, reg_t pc); + reg_t (rv32_fcvt_l_s) (processor_t* p, insn_t s_insn, reg_t pc); + reg_t (rv64_fcvt_l_s) (processor_t* p, insn_t s_insn, reg_t pc); + reg_t (rv32_amomax_d) (processor_t* p, insn_t s_insn, reg_t pc); + reg_t (rv64_amomax_d) (processor_t* p, insn_t s_insn, reg_t pc); + reg_t (rv32_amomaxu_d) (processor_t* p, insn_t s_insn, reg_t pc); + reg_t (rv64_amomaxu_d) (processor_t* p, insn_t s_insn, reg_t pc); + reg_t (rv32_fsgnjn_s) (processor_t* p, insn_t s_insn, reg_t pc); + reg_t (rv64_fsgnjn_s) (processor_t* p, insn_t s_insn, reg_t pc); + reg_t (rv32_fcvt_s_d) (processor_t* p, insn_t s_insn, reg_t pc); + reg_t (rv64_fcvt_s_d) (processor_t* p, insn_t s_insn, reg_t pc); + reg_t (rv32_fdiv_d) (processor_t* p, insn_t s_insn, reg_t pc); + reg_t (rv64_fdiv_d) (processor_t* p, insn_t s_insn, reg_t pc); + reg_t (rv32_fcvt_q_l) (processor_t* p, insn_t s_insn, reg_t pc); + reg_t (rv64_fcvt_q_l) (processor_t* p, insn_t s_insn, reg_t pc); + reg_t (rv32_fence) (processor_t* p, insn_t s_insn, reg_t pc); + reg_t (rv64_fence) (processor_t* p, insn_t s_insn, reg_t pc); + reg_t (rv32_fsgnjx_s) (processor_t* p, insn_t s_insn, reg_t pc); + reg_t (rv64_fsgnjx_s) (processor_t* p, insn_t s_insn, reg_t pc); + reg_t (rv32_fclass_d) (processor_t* p, insn_t s_insn, reg_t pc); + reg_t (rv64_fclass_d) (processor_t* p, insn_t s_insn, reg_t pc); + reg_t (rv32_fdiv_q) (processor_t* p, insn_t s_insn, reg_t pc); + reg_t (rv64_fdiv_q) (processor_t* p, insn_t s_insn, reg_t pc); + reg_t (rv32_fcvt_q_s) (processor_t* p, insn_t s_insn, reg_t pc); + reg_t (rv64_fcvt_q_s) (processor_t* p, insn_t s_insn, reg_t pc); + reg_t (rv32_flt_s) (processor_t* p, insn_t s_insn, reg_t pc); + reg_t (rv64_flt_s) (processor_t* p, insn_t s_insn, reg_t pc); + reg_t (rv32_amominu_w) (processor_t* p, insn_t s_insn, reg_t pc); + reg_t (rv64_amominu_w) (processor_t* p, insn_t s_insn, reg_t pc); + reg_t (rv32_sra) (processor_t* p, insn_t s_insn, reg_t pc); + reg_t (rv64_sra) (processor_t* p, insn_t s_insn, reg_t pc); + reg_t (rv32_sret) (processor_t* p, insn_t s_insn, reg_t pc); + reg_t (rv64_sret) (processor_t* p, insn_t s_insn, reg_t pc); + reg_t (rv32_amoxor_d) (processor_t* p, insn_t s_insn, reg_t pc); + reg_t (rv64_amoxor_d) (processor_t* p, insn_t s_insn, reg_t pc); + reg_t (rv32_mulh) (processor_t* p, insn_t s_insn, reg_t pc); + reg_t (rv64_mulh) (processor_t* p, insn_t s_insn, reg_t pc); + reg_t (rv32_sll) (processor_t* p, insn_t s_insn, reg_t pc); + reg_t (rv64_sll) (processor_t* p, insn_t s_insn, reg_t pc); + reg_t (rv32_lbu) (processor_t* p, insn_t s_insn, reg_t pc); + reg_t (rv64_lbu) (processor_t* p, insn_t s_insn, reg_t pc); + reg_t (rv32_fcvt_wu_d) (processor_t* p, insn_t s_insn, reg_t pc); + reg_t (rv64_fcvt_wu_d) (processor_t* p, insn_t s_insn, reg_t pc); + reg_t (rv32_sraiw) (processor_t* p, insn_t s_insn, reg_t pc); + reg_t (rv64_sraiw) (processor_t* p, insn_t s_insn, reg_t pc); + reg_t (rv32_sllw) (processor_t* p, insn_t s_insn, reg_t pc); + reg_t (rv64_sllw) (processor_t* p, insn_t s_insn, reg_t pc); + reg_t (rv32_sw) (processor_t* p, insn_t s_insn, reg_t pc); + reg_t (rv64_sw) (processor_t* p, insn_t s_insn, reg_t pc); + reg_t (rv32_fcvt_lu_d) (processor_t* p, insn_t s_insn, reg_t pc); + reg_t (rv64_fcvt_lu_d) (processor_t* p, insn_t s_insn, reg_t pc); + reg_t (rv32_c_swsp) (processor_t* p, insn_t s_insn, reg_t pc); + reg_t (rv64_c_swsp) (processor_t* p, insn_t s_insn, reg_t pc); + reg_t (rv32_fsub_d) (processor_t* p, insn_t s_insn, reg_t pc); + reg_t (rv64_fsub_d) (processor_t* p, insn_t s_insn, reg_t pc); + reg_t (rv32_fle_s) (processor_t* p, insn_t s_insn, reg_t pc); + reg_t (rv64_fle_s) (processor_t* p, insn_t s_insn, reg_t pc); + reg_t (rv32_amomin_w) (processor_t* p, insn_t s_insn, reg_t pc); + reg_t (rv64_amomin_w) (processor_t* p, insn_t s_insn, reg_t pc); + reg_t (rv32_c_fldsp) (processor_t* p, insn_t s_insn, reg_t pc); + reg_t (rv64_c_fldsp) (processor_t* p, insn_t s_insn, reg_t pc); + reg_t (rv32_fsd) (processor_t* p, insn_t s_insn, reg_t pc); + reg_t (rv64_fsd) (processor_t* p, insn_t s_insn, reg_t pc); + reg_t (rv32_flq) (processor_t* p, insn_t s_insn, reg_t pc); + reg_t (rv64_flq) (processor_t* p, insn_t s_insn, reg_t pc); + reg_t (rv32_fcvt_d_wu) (processor_t* p, insn_t s_insn, reg_t pc); + reg_t (rv64_fcvt_d_wu) (processor_t* p, insn_t s_insn, reg_t pc); + reg_t (rv32_fmv_w_x) (processor_t* p, insn_t s_insn, reg_t pc); + reg_t (rv64_fmv_w_x) (processor_t* p, insn_t s_insn, reg_t pc); + reg_t (rv32_slt) (processor_t* p, insn_t s_insn, reg_t pc); + reg_t (rv64_slt) (processor_t* p, insn_t s_insn, reg_t pc); + reg_t (rv32_fle_q) (processor_t* p, insn_t s_insn, reg_t pc); + reg_t (rv64_fle_q) (processor_t* p, insn_t s_insn, reg_t pc); + reg_t (rv32_fcvt_l_d) (processor_t* p, insn_t s_insn, reg_t pc); + reg_t (rv64_fcvt_l_d) (processor_t* p, insn_t s_insn, reg_t pc); + reg_t (rv32_fcvt_lu_q) (processor_t* p, insn_t s_insn, reg_t pc); + reg_t (rv64_fcvt_lu_q) (processor_t* p, insn_t s_insn, reg_t pc); + reg_t (rv32_fcvt_wu_q) (processor_t* p, insn_t s_insn, reg_t pc); + reg_t (rv64_fcvt_wu_q) (processor_t* p, insn_t s_insn, reg_t pc); + reg_t (rv32_amoadd_d) (processor_t* p, insn_t s_insn, reg_t pc); + reg_t (rv64_amoadd_d) (processor_t* p, insn_t s_insn, reg_t pc); + reg_t (rv32_fmadd_s) (processor_t* p, insn_t s_insn, reg_t pc); + reg_t (rv64_fmadd_s) (processor_t* p, insn_t s_insn, reg_t pc); + reg_t (rv32_c_sw) (processor_t* p, insn_t s_insn, reg_t pc); + reg_t (rv64_c_sw) (processor_t* p, insn_t s_insn, reg_t pc); + reg_t (rv32_remuw) (processor_t* p, insn_t s_insn, reg_t pc); + reg_t (rv64_remuw) (processor_t* p, insn_t s_insn, reg_t pc); + reg_t (rv32_div) (processor_t* p, insn_t s_insn, reg_t pc); + reg_t (rv64_div) (processor_t* p, insn_t s_insn, reg_t pc); + reg_t (rv32_fcvt_lu_s) (processor_t* p, insn_t s_insn, reg_t pc); + reg_t (rv64_fcvt_lu_s) (processor_t* p, insn_t s_insn, reg_t pc); + reg_t (rv32_lw) (processor_t* p, insn_t s_insn, reg_t pc); + reg_t (rv64_lw) (processor_t* p, insn_t s_insn, reg_t pc); + reg_t (rv32_fsgnjn_d) (processor_t* p, insn_t s_insn, reg_t pc); + reg_t (rv64_fsgnjn_d) (processor_t* p, insn_t s_insn, reg_t pc); + reg_t (rv32_amoxor_w) (processor_t* p, insn_t s_insn, reg_t pc); + reg_t (rv64_amoxor_w) (processor_t* p, insn_t s_insn, reg_t pc); + reg_t (rv32_fcvt_q_wu) (processor_t* p, insn_t s_insn, reg_t pc); + reg_t (rv64_fcvt_q_wu) (processor_t* p, insn_t s_insn, reg_t pc); diff --git a/riscv/sv_insn_redirect.cc b/riscv/sv_insn_redirect.cc index e8b18ba..07eb84f 100644 --- a/riscv/sv_insn_redirect.cc +++ b/riscv/sv_insn_redirect.cc @@ -4,24 +4,39 @@ void (sv_proc_t::WRITE_FRD)(float32_t value) { fprintf(stderr, "WRITE_FRD float32_t %f\n", (float)value.v); - DO_WRITE_FREG( insn->rd(), freg(value) ); + DO_WRITE_FREG( _insn->rd(), freg(value) ); } void (sv_proc_t::WRITE_FRD)(float64_t value) { fprintf(stderr, "WRITE_FRD float64_t %g\n", (double)value.v); - DO_WRITE_FREG( insn->rd(), freg(value) ); + DO_WRITE_FREG( _insn->rd(), freg(value) ); } void (sv_proc_t::WRITE_FRD)(freg_t value) { - fprintf(stderr, "WRITE_FRD freg_t %lx\n", value.v); - DO_WRITE_FREG( insn->rd(), freg(value) ); + fprintf(stderr, "WRITE_FRD freg_t %lx\n", value.v[0]); + DO_WRITE_FREG( _insn->rd(), freg(value) ); } -void (sv_proc_t::WRITE_RD)(reg_t value) +void (sv_proc_t::WRITE_RD)(bool value) { - WRITE_REG( insn->rd(), value ); + WRITE_REG( _insn->rd(), value ? 1 : 0); +} + +void (sv_proc_t::WRITE_RD)(sv_reg_t value) +{ + WRITE_REG( _insn->rd(), value.get_data() ); +} + +void (sv_proc_t::WRITE_RD)(int_fast64_t value) +{ + WRITE_REG( _insn->rd(), value ); // XXX TODO: replace properly +} + +void (sv_proc_t::WRITE_RD)(uint_fast64_t value) +{ + WRITE_REG( _insn->rd(), value ); // XXX TODO: replace properly } /* @@ -31,28 +46,107 @@ reg_t (sv_proc_t::READ_REG)(uint64_t i) } */ -reg_t sv_proc_t::get_rs1() +sv_reg_t sv_proc_t::get_rs1() +{ + return sv_uint64_t(_insn->p->get_state()->XPR[_insn->rs1()]); +} + +sv_reg_t sv_proc_t::get_rs2() +{ + return sv_uint64_t(_insn->p->get_state()->XPR[_insn->rs2()]); +} + +sv_reg_t sv_proc_t::get_rvc_rs1s() +{ + return sv_uint64_t(_insn->p->get_state()->XPR[_insn->rvc_rs1s()]); +} + +sv_reg_t sv_proc_t::get_rvc_rs2s() +{ + return sv_uint64_t(_insn->p->get_state()->XPR[_insn->rvc_rs2s()]); +} + +sv_reg_t sv_proc_t::get_rvc_rs1() +{ + return sv_uint64_t(_insn->p->get_state()->XPR[_insn->rvc_rs1()]); +} + +sv_reg_t sv_proc_t::get_rvc_rs2() +{ + return sv_uint64_t(_insn->p->get_state()->XPR[_insn->rvc_rs2()]); +} + +sv_reg_t sv_proc_t::get_rs3() +{ + return sv_uint64_t(_insn->p->get_state()->XPR[_insn->rs3()]); +} + +sv_reg_t sv_proc_t::get_rvc_sp() +{ + return sv_uint64_t(_insn->p->get_state()->XPR[X_SP]); +} + +sv_reg_t sv_proc_t::uint64_max() +{ + return sv_uint64_t((UINT64_C(18446744073709551615))); +} + +sv_reg_t (sv_proc_t::sext_xlen)(sv_reg_t v) +{ + uint64_t x = v.as_uint64(); + x = (((sreg_t)(x) << (64-xlen)) >> (64-xlen)); + return sv_uint64_t(x); +} + +sv_reg_t (sv_proc_t::zext_xlen)(sv_reg_t v) { - return insn->p->get_state()->XPR[insn->rs1()]; + uint64_t x = v.as_uint64(); + x = (((reg_t)(x) << (64-xlen)) >> (64-xlen)); + return sv_uint64_t(x); } -reg_t sv_proc_t::get_rs2() +sv_reg_t (sv_proc_t::sext32)(uint_fast32_t v) { - return insn->p->get_state()->XPR[insn->rs2()]; + return sext32((uint64_t)v); // XXX TODO do properly } -reg_t sv_proc_t::get_rs3() +sv_reg_t (sv_proc_t::sext32)(sv_reg_t v) { - return insn->p->get_state()->XPR[insn->rs3()]; + uint64_t x = v.as_uint64(); + x = ((sreg_t)(int32_t)(x)); + return sv_uint64_t(x); +} + +sv_reg_t (sv_proc_t::zext32)(sv_reg_t v) +{ + uint64_t x = v.as_uint64(); + x = ((reg_t)(uint32_t)(x)); + return sv_uint64_t(x); } freg_t sv_proc_t::get_frs1() { - return READ_FREG(insn->rs1()); + return READ_FREG(_insn->rs1()); } freg_t sv_proc_t::get_frs2() { - return READ_FREG(insn->rs2()); + return READ_FREG(_insn->rs2()); +} + +sv_reg_t sv_reg_t::make_sv_int64_t (int64_t v) const +{ + return sv_sreg_t(v); +} + +sv_reg_t sv_reg_t::make_sv_uint64_t (uint64_t v) const +{ + return sv_uint64_t(v); +} + + +sv_reg_t::operator sv_sreg_t () const +{ + return sv_sreg_t ( as_uint64() ); } diff --git a/riscv/sv_insn_redirect.h b/riscv/sv_insn_redirect.h index fc3cbb9..158e42f 100644 --- a/riscv/sv_insn_redirect.h +++ b/riscv/sv_insn_redirect.h @@ -4,14 +4,25 @@ #include #include "decode.h" #include "sv_decode.h" +#include "sv_reg.h" #undef RS1 #undef RS2 #undef RS3 #undef FRS1 #undef FRS2 +#undef RVC_RS1 +#undef RVC_RS2 +#undef RVC_RS1S +#undef RVC_RS2S #undef WRITE_FRD #undef WRITE_RD +#undef RVC_SP +#undef sext_xlen +#undef zext_xlen +#undef sext32 +#undef zext32 +#undef UINT64_MAX class processor_t; class insn_t; @@ -21,44 +32,66 @@ class insn_t; #define RS1 get_rs1() #define RS2 get_rs2() #define RS3 get_rs3() - -/* -class RS2 { - public: - sv_insn_t *_insn; - RS2() : _insn(NULL) {} - //sv_insn_t & operator = (sv_insn_t &i) - //{ _insn = &i; return i; } - operator reg_t () const &; -}; -*/ +#define RVC_RS1 get_rvc_rs1() +#define RVC_RS2 get_rvc_rs2() +#define RVC_RS1S get_rvc_rs1s() +#define RVC_RS2S get_rvc_rs2s() +#define RVC_SP get_rvc_sp() +#define UINT64_MAX uint64_max() class sv_proc_t { public: - sv_proc_t(processor_t *_p) : p(_p), insn(NULL), xlen(0) {} - void (WRITE_RD)(reg_t value); + sv_proc_t(processor_t *_p) : p(_p), _insn(NULL), xlen(0) {} + void (WRITE_RD)(bool value); // f32_eq calls this: XXX TODO investigate + void (WRITE_RD)(sv_reg_t value); + void (WRITE_RD)(int_fast64_t value); // XXX TODO investigate + void (WRITE_RD)(uint_fast64_t value); // XXX TODO investigate void (WRITE_FRD)(freg_t value); void (WRITE_FRD)(float64_t value); void (WRITE_FRD)(float32_t value); //reg_t (READ_REG)(uint64_t i); processor_t *p; - sv_insn_t *insn; + sv_insn_t *_insn; int xlen; + class { + public: + sv_insn_t *_insn; + //sv_insn_t & operator = (sv_insn_t &i) + //{ _insn = &i; return i; } + operator sv_insn_t() & { return *this->_insn; } + } insn; + void set_insn(sv_insn_t *i, int x) { - this->insn = i; + this->_insn = i; this->xlen = x; + this->insn._insn = i; } - reg_t get_rs1(); - reg_t get_rs2(); - reg_t get_rs3(); + sv_reg_t get_rs1(); + sv_reg_t get_rs2(); + sv_reg_t get_rs3(); + + sv_reg_t get_rvc_sp(); + sv_reg_t get_rvc_rs1(); + sv_reg_t get_rvc_rs2(); + sv_reg_t get_rvc_rs1s(); + sv_reg_t get_rvc_rs2s(); + + sv_reg_t uint64_max(); freg_t get_frs1(); freg_t get_frs2(); + //sv_reg_t (sext_xlen)(reg_t &v); // WARNING... + sv_reg_t (zext_xlen)(sv_reg_t v); + sv_reg_t (sext_xlen)(sv_reg_t v); + sv_reg_t (sext32)(uint_fast32_t v); // XXX TODO + sv_reg_t (sext32)(sv_reg_t v); + sv_reg_t (zext32)(sv_reg_t v); + #include "sv_insn_decl.h" }; diff --git a/riscv/sv_reg.h b/riscv/sv_reg.h new file mode 100644 index 0000000..7bf35be --- /dev/null +++ b/riscv/sv_reg.h @@ -0,0 +1,130 @@ +#ifndef SV_REG_H +#define SV_REG_H + +#include +#include "decode.h" + +#define DECL_1OP( op ) \ + bool operator op () const { \ + return op (this->as_uint64()); } + +#define DECL_BOP( op ) \ + bool operator op (const sv_reg_t& rhs) const { \ + return this->as_uint64() op rhs.as_uint64(); } + +#define DECL_BOPE( op ) \ + bool operator op (int rhs) const { \ + return this->as_uint64() op ((unsigned int)rhs); } \ + bool operator op (long int rhs) const { \ + return this->as_uint64() op ((unsigned long int)rhs); } + +#define DECL_OP( type, op ) \ + sv_reg_t operator op (const sv_reg_t& rhs) const { \ + return make_##type( (this->as_uint64() op rhs.as_uint64()) ); } \ + sv_reg_t operator op (const reg_t& rhs) const { \ + return make_##type( (this->as_uint64() op rhs) ); } \ + sv_reg_t operator op (const sreg_t& rhs) const { \ + return make_##type( (this->as_uint64() op rhs) ); } \ + sv_reg_t operator op (int rhs) const { \ + return make_##type( (this->as_uint64() op rhs) ); } + +#define op_bneg ~ +#define op_xor ^ +#define op_or | +#define op_and & +#define op_plus + +#define op_minus - +#define op_div / +#define op_rem % +#define op_mul * +#define op_gt > +#define op_ge >= +#define op_lt < +#define op_le <= +#define op_eq == +#define op_ne != +#define op_sl << +#define op_sr >> + +class sv_uint64_t; +class sv_sreg_t; + +class sv_reg_t { +public: + virtual ~sv_reg_t() {} + // using a type which accommodates all values + virtual uint64_t as_uint64() const { return 0; }; + +public: + DECL_BOP( op_ge ) + DECL_BOP( op_gt ) + DECL_BOP( op_eq ) + DECL_BOPE( op_eq ) + DECL_BOP( op_ne ) + DECL_BOPE( op_ne ) + DECL_BOP( op_le ) + DECL_BOP( op_lt ) + DECL_1OP( op_bneg ) + DECL_OP( sv_uint64_t, op_or ) + DECL_OP( sv_uint64_t, op_xor ) + DECL_OP( sv_uint64_t, op_and ) + DECL_OP( sv_uint64_t, op_plus ) + DECL_OP( sv_uint64_t, op_minus ) + DECL_OP( sv_uint64_t, op_div ) + DECL_OP( sv_uint64_t, op_rem ) + DECL_OP( sv_uint64_t, op_mul ) + DECL_OP( sv_uint64_t, op_sl ) + DECL_OP( sv_uint64_t, op_sr ) + + operator char () const // XXX TODO, make_sv_char_t + { return make_sv_int64_t( (sreg_t) (as_uint64()) ); } + operator int32_t () // XXX TODO, make_sv_char_t + { return make_sv_int64_t( (sreg_t) (as_uint64()) ); } + operator uint32_t () const // TODO, make_sv_uint32_t + { return make_sv_uint64_t( (sreg_t) (as_uint64()) ); } + operator sv_sreg_t () const; + operator sreg_t () const + { return make_sv_int64_t( (sreg_t) (as_uint64()) ); } + operator reg_t () const + { return make_sv_uint64_t( (reg_t) (as_uint64()) ); } + //operator uint_fast64_t () const + // { return make_sv_uint64_t( (reg_t) (as_uint64()) ); } + //operator int_fast64_t () const + //{ return make_sv_int64_t( (sreg_t) (as_uint64()) ); } + // ... +public: + uint64_t get_data() { return as_uint64(); } + sv_reg_t make_sv_uint64_t (uint64_t v) const; + sv_reg_t make_sv_int64_t (int64_t v) const; +}; + +class sv_sreg_t : public sv_reg_t { +public: + sv_sreg_t(int64_t v) : data(v) {} +// ... +private: + virtual uint64_t as_uint64() const { return this->data; } +private: + int64_t data; +}; + +class sv_uint64_t : public sv_reg_t { +public: + sv_uint64_t(uint64_t v) : data(v) {} +// ... +private: + virtual uint64_t as_uint64() const { return this->data; } +private: + uint64_t data; +}; + +class sv_uint16_t : public sv_reg_t { +// ... +private: + virtual uint64_t as_uint64() const { return this->data; } +private: + uint16_t data; +}; + + +#endif -- 2.30.2