diff --git a/gen_input/templates/interp/CORENAME.cpp.gtl b/gen_input/templates/interp/CORENAME.cpp.gtl index 1e05c8a..a56a6f2 100644 --- a/gen_input/templates/interp/CORENAME.cpp.gtl +++ b/gen_input/templates/interp/CORENAME.cpp.gtl @@ -248,6 +248,12 @@ if(vector) {%> inline void set_tval(uint64_t new_tval){ tval = new_tval; } + + inline bool has_synchronous_exception() const { + auto state = this->core.reg.trap_state; + return (state & 0x80000000ULL) != 0 && (state & 0xffffULL) == 0; + } + uint64_t fetch_count{0}; uint64_t tval{0}; diff --git a/src/vm/interp/vm_rv32gc.cpp b/src/vm/interp/vm_rv32gc.cpp index dfd9dc8..445e4d0 100644 --- a/src/vm/interp/vm_rv32gc.cpp +++ b/src/vm/interp/vm_rv32gc.cpp @@ -126,6 +126,12 @@ template class vm_impl : public iss::interp::vm_base { inline void set_tval(uint64_t new_tval){ tval = new_tval; } + + inline bool has_synchronous_exception() const { + auto state = this->core.reg.trap_state; + return (state & 0x80000000ULL) != 0 && (state & 0xffffULL) == 0; + } + uint64_t fetch_count{0}; uint64_t tval{0}; @@ -813,7 +819,7 @@ typename vm_base::virt_addr_t vm_impl::execute_inst(finish_cond_e co else { uint32_t load_address = (uint32_t)((uint64_t)(*(X+rs1)) + (int64_t)((int16_t)sext<12>(imm))); int8_t res_1 = super::template read_mem(traits::MEM, load_address); - if(this->core.reg.trap_state>=0x80000000UL) throw memory_access_exception(); + if(has_synchronous_exception()) throw memory_access_exception(); int8_t res = (int8_t)res_1; if(rd != 0) { *(X+rd) = (uint32_t)res; @@ -845,7 +851,7 @@ typename vm_base::virt_addr_t vm_impl::execute_inst(finish_cond_e co else { uint32_t load_address = (uint32_t)((uint64_t)(*(X+rs1)) + (int64_t)((int16_t)sext<12>(imm))); int16_t res_2 = super::template read_mem(traits::MEM, load_address); - if(this->core.reg.trap_state>=0x80000000UL) throw memory_access_exception(); + if(has_synchronous_exception()) throw memory_access_exception(); int16_t res = (int16_t)res_2; if(rd != 0) { *(X+rd) = (uint32_t)res; @@ -877,7 +883,7 @@ typename vm_base::virt_addr_t vm_impl::execute_inst(finish_cond_e co else { uint32_t load_address = (uint32_t)((uint64_t)(*(X+rs1)) + (int64_t)((int16_t)sext<12>(imm))); int32_t res_3 = super::template read_mem(traits::MEM, load_address); - if(this->core.reg.trap_state>=0x80000000UL) throw memory_access_exception(); + if(has_synchronous_exception()) throw memory_access_exception(); int32_t res = (int32_t)res_3; if(rd != 0) { *(X+rd) = (uint32_t)res; @@ -909,7 +915,7 @@ typename vm_base::virt_addr_t vm_impl::execute_inst(finish_cond_e co else { uint32_t load_address = (uint32_t)((uint64_t)(*(X+rs1)) + (int64_t)((int16_t)sext<12>(imm))); uint8_t res_4 = super::template read_mem(traits::MEM, load_address); - if(this->core.reg.trap_state>=0x80000000UL) throw memory_access_exception(); + if(has_synchronous_exception()) throw memory_access_exception(); uint8_t res = res_4; if(rd != 0) { *(X+rd) = (uint32_t)res; @@ -941,7 +947,7 @@ typename vm_base::virt_addr_t vm_impl::execute_inst(finish_cond_e co else { uint32_t load_address = (uint32_t)((uint64_t)(*(X+rs1)) + (int64_t)((int16_t)sext<12>(imm))); uint16_t res_5 = super::template read_mem(traits::MEM, load_address); - if(this->core.reg.trap_state>=0x80000000UL) throw memory_access_exception(); + if(has_synchronous_exception()) throw memory_access_exception(); uint16_t res = res_5; if(rd != 0) { *(X+rd) = (uint32_t)res; @@ -973,7 +979,7 @@ typename vm_base::virt_addr_t vm_impl::execute_inst(finish_cond_e co else { uint32_t store_address = (uint32_t)((uint64_t)(*(X+rs1)) + (int64_t)((int16_t)sext<12>(imm))); super::template write_mem(traits::MEM, store_address, (uint8_t)*(X+rs2)); - if(this->core.reg.trap_state>=0x80000000UL) throw memory_access_exception(); + if(has_synchronous_exception()) throw memory_access_exception(); } } break; @@ -1001,7 +1007,7 @@ typename vm_base::virt_addr_t vm_impl::execute_inst(finish_cond_e co else { uint32_t store_address = (uint32_t)((uint64_t)(*(X+rs1)) + (int64_t)((int16_t)sext<12>(imm))); super::template write_mem(traits::MEM, store_address, (uint16_t)*(X+rs2)); - if(this->core.reg.trap_state>=0x80000000UL) throw memory_access_exception(); + if(has_synchronous_exception()) throw memory_access_exception(); } } break; @@ -1029,7 +1035,7 @@ typename vm_base::virt_addr_t vm_impl::execute_inst(finish_cond_e co else { uint32_t store_address = (uint32_t)((uint64_t)(*(X+rs1)) + (int64_t)((int16_t)sext<12>(imm))); super::template write_mem(traits::MEM, store_address, (uint32_t)*(X+rs2)); - if(this->core.reg.trap_state>=0x80000000UL) throw memory_access_exception(); + if(has_synchronous_exception()) throw memory_access_exception(); } } break; @@ -1585,7 +1591,7 @@ typename vm_base::virt_addr_t vm_impl::execute_inst(finish_cond_e co // execute instruction { super::template write_mem(traits::FENCE, traits::fence, (uint8_t)pred << 4 | succ); - if(this->core.reg.trap_state>=0x80000000UL) throw memory_access_exception(); + if(has_synchronous_exception()) throw memory_access_exception(); } break; }// @suppress("No break at end of case") @@ -1677,15 +1683,15 @@ typename vm_base::virt_addr_t vm_impl::execute_inst(finish_cond_e co uint32_t xrs1 = *(X+rs1); if(rd != 0) { uint32_t res_6 = super::template read_mem(traits::CSR, csr); - if(this->core.reg.trap_state>=0x80000000UL) throw memory_access_exception(); + if(has_synchronous_exception()) throw memory_access_exception(); uint32_t xrd = res_6; super::template write_mem(traits::CSR, csr, xrs1); - if(this->core.reg.trap_state>=0x80000000UL) throw memory_access_exception(); + if(has_synchronous_exception()) throw memory_access_exception(); *(X+rd) = xrd; } else { super::template write_mem(traits::CSR, csr, xrs1); - if(this->core.reg.trap_state>=0x80000000UL) throw memory_access_exception(); + if(has_synchronous_exception()) throw memory_access_exception(); } } } @@ -1713,12 +1719,12 @@ typename vm_base::virt_addr_t vm_impl::execute_inst(finish_cond_e co } else { uint32_t res_7 = super::template read_mem(traits::CSR, csr); - if(this->core.reg.trap_state>=0x80000000UL) throw memory_access_exception(); + if(has_synchronous_exception()) throw memory_access_exception(); uint32_t xrd = res_7; uint32_t xrs1 = *(X+rs1); if(rs1 != 0) { super::template write_mem(traits::CSR, csr, xrd | xrs1); - if(this->core.reg.trap_state>=0x80000000UL) throw memory_access_exception(); + if(has_synchronous_exception()) throw memory_access_exception(); } if(rd != 0) { *(X+rd) = xrd; @@ -1749,12 +1755,12 @@ typename vm_base::virt_addr_t vm_impl::execute_inst(finish_cond_e co } else { uint32_t res_8 = super::template read_mem(traits::CSR, csr); - if(this->core.reg.trap_state>=0x80000000UL) throw memory_access_exception(); + if(has_synchronous_exception()) throw memory_access_exception(); uint32_t xrd = res_8; uint32_t xrs1 = *(X+rs1); if(rs1 != 0) { super::template write_mem(traits::CSR, csr, xrd & ~xrs1); - if(this->core.reg.trap_state>=0x80000000UL) throw memory_access_exception(); + if(has_synchronous_exception()) throw memory_access_exception(); } if(rd != 0) { *(X+rd) = xrd; @@ -1785,10 +1791,10 @@ typename vm_base::virt_addr_t vm_impl::execute_inst(finish_cond_e co } else { uint32_t res_9 = super::template read_mem(traits::CSR, csr); - if(this->core.reg.trap_state>=0x80000000UL) throw memory_access_exception(); + if(has_synchronous_exception()) throw memory_access_exception(); uint32_t xrd = res_9; super::template write_mem(traits::CSR, csr, (uint32_t)zimm); - if(this->core.reg.trap_state>=0x80000000UL) throw memory_access_exception(); + if(has_synchronous_exception()) throw memory_access_exception(); if(rd != 0) { *(X+rd) = xrd; } @@ -1818,11 +1824,11 @@ typename vm_base::virt_addr_t vm_impl::execute_inst(finish_cond_e co } else { uint32_t res_10 = super::template read_mem(traits::CSR, csr); - if(this->core.reg.trap_state>=0x80000000UL) throw memory_access_exception(); + if(has_synchronous_exception()) throw memory_access_exception(); uint32_t xrd = res_10; if(zimm != 0) { super::template write_mem(traits::CSR, csr, xrd | (uint32_t)zimm); - if(this->core.reg.trap_state>=0x80000000UL) throw memory_access_exception(); + if(has_synchronous_exception()) throw memory_access_exception(); } if(rd != 0) { *(X+rd) = xrd; @@ -1853,11 +1859,11 @@ typename vm_base::virt_addr_t vm_impl::execute_inst(finish_cond_e co } else { uint32_t res_11 = super::template read_mem(traits::CSR, csr); - if(this->core.reg.trap_state>=0x80000000UL) throw memory_access_exception(); + if(has_synchronous_exception()) throw memory_access_exception(); uint32_t xrd = res_11; if(zimm != 0) { super::template write_mem(traits::CSR, csr, xrd & ~((uint32_t)zimm)); - if(this->core.reg.trap_state>=0x80000000UL) throw memory_access_exception(); + if(has_synchronous_exception()) throw memory_access_exception(); } if(rd != 0) { *(X+rd) = xrd; @@ -1883,7 +1889,7 @@ typename vm_base::virt_addr_t vm_impl::execute_inst(finish_cond_e co // execute instruction { super::template write_mem(traits::FENCE, traits::fencei, imm); - if(this->core.reg.trap_state>=0x80000000UL) throw memory_access_exception(); + if(has_synchronous_exception()) throw memory_access_exception(); } break; }// @suppress("No break at end of case") @@ -2182,10 +2188,10 @@ typename vm_base::virt_addr_t vm_impl::execute_inst(finish_cond_e co if(rd != 0) { uint32_t offs = *(X+rs1); int32_t res_12 = super::template read_mem(traits::MEM, offs); - if(this->core.reg.trap_state>=0x80000000UL) throw memory_access_exception(); + if(has_synchronous_exception()) throw memory_access_exception(); *(X+rd) = (uint32_t)((int32_t)res_12); super::template write_mem(traits::RES, offs, (uint8_t)- 1); - if(this->core.reg.trap_state>=0x80000000UL) throw memory_access_exception(); + if(has_synchronous_exception()) throw memory_access_exception(); } } } @@ -2216,11 +2222,11 @@ typename vm_base::virt_addr_t vm_impl::execute_inst(finish_cond_e co else { uint32_t offs = *(X+rs1); uint8_t res_13 = super::template read_mem(traits::RES, offs); - if(this->core.reg.trap_state>=0x80000000UL) throw memory_access_exception(); + if(has_synchronous_exception()) throw memory_access_exception(); uint32_t res1 = res_13; if(res1 != 0) { super::template write_mem(traits::MEM, offs, (uint32_t)*(X+rs2)); - if(this->core.reg.trap_state>=0x80000000UL) throw memory_access_exception(); + if(has_synchronous_exception()) throw memory_access_exception(); } if(rd != 0) { *(X+rd) = res1? 0 : 1; @@ -2256,11 +2262,11 @@ typename vm_base::virt_addr_t vm_impl::execute_inst(finish_cond_e co uint32_t res = *(X+rs2); if(rd != 0) { int32_t res_14 = super::template read_mem(traits::MEM, offs); - if(this->core.reg.trap_state>=0x80000000UL) throw memory_access_exception(); + if(has_synchronous_exception()) throw memory_access_exception(); *(X+rd) = (uint32_t)((int32_t)res_14); } super::template write_mem(traits::MEM, offs, (uint32_t)res); - if(this->core.reg.trap_state>=0x80000000UL) throw memory_access_exception(); + if(has_synchronous_exception()) throw memory_access_exception(); } } break; @@ -2290,14 +2296,14 @@ typename vm_base::virt_addr_t vm_impl::execute_inst(finish_cond_e co else { uint32_t offs = *(X+rs1); int32_t res_15 = super::template read_mem(traits::MEM, offs); - if(this->core.reg.trap_state>=0x80000000UL) throw memory_access_exception(); + if(has_synchronous_exception()) throw memory_access_exception(); int32_t res1 = (int32_t)res_15; int64_t res2 = (int64_t)(res1) + (int64_t)((int32_t)*(X+rs2)); if(rd != 0) { *(X+rd) = (uint32_t)res1; } super::template write_mem(traits::MEM, offs, (uint32_t)res2); - if(this->core.reg.trap_state>=0x80000000UL) throw memory_access_exception(); + if(has_synchronous_exception()) throw memory_access_exception(); } } break; @@ -2327,14 +2333,14 @@ typename vm_base::virt_addr_t vm_impl::execute_inst(finish_cond_e co else { uint32_t offs = *(X+rs1); uint32_t res_16 = super::template read_mem(traits::MEM, offs); - if(this->core.reg.trap_state>=0x80000000UL) throw memory_access_exception(); + if(has_synchronous_exception()) throw memory_access_exception(); uint32_t res1 = res_16; uint32_t res2 = res1 ^ (uint32_t)*(X+rs2); if(rd != 0) { *(X+rd) = ((uint32_t)(int32_t)(int32_t)res1); } super::template write_mem(traits::MEM, offs, res2); - if(this->core.reg.trap_state>=0x80000000UL) throw memory_access_exception(); + if(has_synchronous_exception()) throw memory_access_exception(); } } break; @@ -2364,14 +2370,14 @@ typename vm_base::virt_addr_t vm_impl::execute_inst(finish_cond_e co else { uint32_t offs = *(X+rs1); uint32_t res_17 = super::template read_mem(traits::MEM, offs); - if(this->core.reg.trap_state>=0x80000000UL) throw memory_access_exception(); + if(has_synchronous_exception()) throw memory_access_exception(); uint32_t res1 = res_17; uint32_t res2 = res1 & (uint32_t)*(X+rs2); if(rd != 0) { *(X+rd) = ((uint32_t)(int32_t)(int32_t)res1); } super::template write_mem(traits::MEM, offs, res2); - if(this->core.reg.trap_state>=0x80000000UL) throw memory_access_exception(); + if(has_synchronous_exception()) throw memory_access_exception(); } } break; @@ -2401,14 +2407,14 @@ typename vm_base::virt_addr_t vm_impl::execute_inst(finish_cond_e co else { uint32_t offs = *(X+rs1); uint32_t res_18 = super::template read_mem(traits::MEM, offs); - if(this->core.reg.trap_state>=0x80000000UL) throw memory_access_exception(); + if(has_synchronous_exception()) throw memory_access_exception(); uint32_t res1 = res_18; uint32_t res2 = res1 | (uint32_t)*(X+rs2); if(rd != 0) { *(X+rd) = ((uint32_t)(int32_t)(int32_t)res1); } super::template write_mem(traits::MEM, offs, res2); - if(this->core.reg.trap_state>=0x80000000UL) throw memory_access_exception(); + if(has_synchronous_exception()) throw memory_access_exception(); } } break; @@ -2438,14 +2444,14 @@ typename vm_base::virt_addr_t vm_impl::execute_inst(finish_cond_e co else { uint32_t offs = *(X+rs1); int32_t res_19 = super::template read_mem(traits::MEM, offs); - if(this->core.reg.trap_state>=0x80000000UL) throw memory_access_exception(); + if(has_synchronous_exception()) throw memory_access_exception(); int32_t res1 = (int32_t)res_19; uint32_t res2 = res1 > (int32_t)*(X+rs2)? (uint32_t)*(X+rs2) : ((uint32_t)res1); if(rd != 0) { *(X+rd) = (uint32_t)res1; } super::template write_mem(traits::MEM, offs, res2); - if(this->core.reg.trap_state>=0x80000000UL) throw memory_access_exception(); + if(has_synchronous_exception()) throw memory_access_exception(); } } break; @@ -2475,14 +2481,14 @@ typename vm_base::virt_addr_t vm_impl::execute_inst(finish_cond_e co else { uint32_t offs = *(X+rs1); int32_t res_20 = super::template read_mem(traits::MEM, offs); - if(this->core.reg.trap_state>=0x80000000UL) throw memory_access_exception(); + if(has_synchronous_exception()) throw memory_access_exception(); int32_t res1 = (int32_t)res_20; uint32_t res2 = res1 < (int32_t)*(X+rs2)? (uint32_t)*(X+rs2) : ((uint32_t)res1); if(rd != 0) { *(X+rd) = (uint32_t)res1; } super::template write_mem(traits::MEM, offs, res2); - if(this->core.reg.trap_state>=0x80000000UL) throw memory_access_exception(); + if(has_synchronous_exception()) throw memory_access_exception(); } } break; @@ -2512,14 +2518,14 @@ typename vm_base::virt_addr_t vm_impl::execute_inst(finish_cond_e co else { uint32_t offs = *(X+rs1); uint32_t res_21 = super::template read_mem(traits::MEM, offs); - if(this->core.reg.trap_state>=0x80000000UL) throw memory_access_exception(); + if(has_synchronous_exception()) throw memory_access_exception(); uint32_t res1 = res_21; uint32_t res2 = res1 > (uint32_t)*(X+rs2)? (uint32_t)*(X+rs2) : res1; if(rd != 0) { *(X+rd) = ((uint32_t)(int32_t)(int32_t)res1); } super::template write_mem(traits::MEM, offs, res2); - if(this->core.reg.trap_state>=0x80000000UL) throw memory_access_exception(); + if(has_synchronous_exception()) throw memory_access_exception(); } } break; @@ -2549,14 +2555,14 @@ typename vm_base::virt_addr_t vm_impl::execute_inst(finish_cond_e co else { uint32_t offs = *(X+rs1); uint32_t res_22 = super::template read_mem(traits::MEM, offs); - if(this->core.reg.trap_state>=0x80000000UL) throw memory_access_exception(); + if(has_synchronous_exception()) throw memory_access_exception(); uint32_t res1 = res_22; uint32_t res2 = res1 < (int32_t)*(X+rs2)? (uint32_t)*(X+rs2) : res1; if(rd != 0) { *(X+rd) = ((uint32_t)(int32_t)(int32_t)res1); } super::template write_mem(traits::MEM, offs, res2); - if(this->core.reg.trap_state>=0x80000000UL) throw memory_access_exception(); + if(has_synchronous_exception()) throw memory_access_exception(); } } break; @@ -2605,7 +2611,7 @@ typename vm_base::virt_addr_t vm_impl::execute_inst(finish_cond_e co { uint32_t offs = (uint32_t)((uint64_t)(*(X+rs1 + 8)) + (uint64_t)(uimm)); int32_t res_23 = super::template read_mem(traits::MEM, offs); - if(this->core.reg.trap_state>=0x80000000UL) throw memory_access_exception(); + if(has_synchronous_exception()) throw memory_access_exception(); *(X+rd + 8) = (uint32_t)(int32_t)res_23; } break; @@ -2629,7 +2635,7 @@ typename vm_base::virt_addr_t vm_impl::execute_inst(finish_cond_e co { uint32_t offs = (uint32_t)((uint64_t)(*(X+rs1 + 8)) + (uint64_t)(uimm)); super::template write_mem(traits::MEM, offs, (uint32_t)*(X+rs2 + 8)); - if(this->core.reg.trap_state>=0x80000000UL) throw memory_access_exception(); + if(has_synchronous_exception()) throw memory_access_exception(); } break; }// @suppress("No break at end of case") @@ -3053,7 +3059,7 @@ typename vm_base::virt_addr_t vm_impl::execute_inst(finish_cond_e co else { uint32_t offs = (uint32_t)((uint64_t)(*(X+2)) + (uint64_t)(uimm)); int32_t res_24 = super::template read_mem(traits::MEM, offs); - if(this->core.reg.trap_state>=0x80000000UL) throw memory_access_exception(); + if(has_synchronous_exception()) throw memory_access_exception(); *(X+rd) = (uint32_t)(int32_t)res_24; } } @@ -3221,7 +3227,7 @@ typename vm_base::virt_addr_t vm_impl::execute_inst(finish_cond_e co else { uint32_t offs = (uint32_t)((uint64_t)(*(X+2)) + (uint64_t)(uimm)); super::template write_mem(traits::MEM, offs, (uint32_t)*(X+rs2)); - if(this->core.reg.trap_state>=0x80000000UL) throw memory_access_exception(); + if(has_synchronous_exception()) throw memory_access_exception(); } } break; @@ -3266,7 +3272,7 @@ typename vm_base::virt_addr_t vm_impl::execute_inst(finish_cond_e co else { uint32_t offs = (uint32_t)((uint64_t)(*(X+rs1)) + (int64_t)((int16_t)sext<12>(imm))); uint32_t res_25 = super::template read_mem(traits::MEM, offs); - if(this->core.reg.trap_state>=0x80000000UL) throw memory_access_exception(); + if(has_synchronous_exception()) throw memory_access_exception(); *(F+rd) = NaNBox32(res_25); } } @@ -3296,7 +3302,7 @@ typename vm_base::virt_addr_t vm_impl::execute_inst(finish_cond_e co else { uint32_t offs = (uint32_t)((uint64_t)(*(X+rs1)) + (int64_t)((int16_t)sext<12>(imm))); super::template write_mem(traits::MEM, offs, (uint32_t)*(F+rs2)); - if(this->core.reg.trap_state>=0x80000000UL) throw memory_access_exception(); + if(has_synchronous_exception()) throw memory_access_exception(); } } break; @@ -3968,7 +3974,7 @@ typename vm_base::virt_addr_t vm_impl::execute_inst(finish_cond_e co { uint32_t offs = (uint32_t)((uint64_t)(*(X+rs1 + 8)) + (uint64_t)(uimm)); uint32_t res_26 = super::template read_mem(traits::MEM, offs); - if(this->core.reg.trap_state>=0x80000000UL) throw memory_access_exception(); + if(has_synchronous_exception()) throw memory_access_exception(); uint32_t res = (uint32_t)res_26; *(F+rd + 8) = NaNBox32(res); } @@ -3994,7 +4000,7 @@ typename vm_base::virt_addr_t vm_impl::execute_inst(finish_cond_e co { uint32_t offs = (uint32_t)((uint64_t)(*(X+rs1 + 8)) + (uint64_t)(uimm)); super::template write_mem(traits::MEM, offs, (uint32_t)*(F+rs2 + 8)); - if(this->core.reg.trap_state>=0x80000000UL) throw memory_access_exception(); + if(has_synchronous_exception()) throw memory_access_exception(); } break; }// @suppress("No break at end of case") @@ -4017,7 +4023,7 @@ typename vm_base::virt_addr_t vm_impl::execute_inst(finish_cond_e co { uint32_t offs = (uint32_t)((uint64_t)(*(X+2)) + (uint64_t)(uimm)); uint32_t res_27 = super::template read_mem(traits::MEM, offs); - if(this->core.reg.trap_state>=0x80000000UL) throw memory_access_exception(); + if(has_synchronous_exception()) throw memory_access_exception(); uint32_t res = (uint32_t)res_27; *(F+rd) = NaNBox32(res); } @@ -4042,7 +4048,7 @@ typename vm_base::virt_addr_t vm_impl::execute_inst(finish_cond_e co { uint32_t offs = (uint32_t)((uint64_t)(*(X+2)) + (uint64_t)(uimm)); super::template write_mem(traits::MEM, offs, (uint32_t)*(F+rs2)); - if(this->core.reg.trap_state>=0x80000000UL) throw memory_access_exception(); + if(has_synchronous_exception()) throw memory_access_exception(); } break; }// @suppress("No break at end of case") @@ -4070,7 +4076,7 @@ typename vm_base::virt_addr_t vm_impl::execute_inst(finish_cond_e co else { uint32_t offs = (uint32_t)((uint64_t)(*(X+rs1)) + (int64_t)((int16_t)sext<12>(imm))); uint64_t res_28 = super::template read_mem(traits::MEM, offs); - if(this->core.reg.trap_state>=0x80000000UL) throw memory_access_exception(); + if(has_synchronous_exception()) throw memory_access_exception(); *(F+rd) = NaNBox64(res_28); } } @@ -4100,7 +4106,7 @@ typename vm_base::virt_addr_t vm_impl::execute_inst(finish_cond_e co else { uint32_t offs = (uint32_t)((uint64_t)(*(X+rs1)) + (int64_t)((int16_t)sext<12>(imm))); super::template write_mem(traits::MEM, offs, (uint64_t)*(F+rs2)); - if(this->core.reg.trap_state>=0x80000000UL) throw memory_access_exception(); + if(has_synchronous_exception()) throw memory_access_exception(); } } break; @@ -4766,7 +4772,7 @@ typename vm_base::virt_addr_t vm_impl::execute_inst(finish_cond_e co { uint32_t offs = (uint32_t)((uint64_t)(*(X+rs1 + 8)) + (uint64_t)(uimm)); uint64_t res_29 = super::template read_mem(traits::MEM, offs); - if(this->core.reg.trap_state>=0x80000000UL) throw memory_access_exception(); + if(has_synchronous_exception()) throw memory_access_exception(); uint64_t res = (uint64_t)res_29; *(F+rd + 8) = NaNBox64(res); } @@ -4792,7 +4798,7 @@ typename vm_base::virt_addr_t vm_impl::execute_inst(finish_cond_e co { uint32_t offs = (uint32_t)((uint64_t)(*(X+rs1 + 8)) + (uint64_t)(uimm)); super::template write_mem(traits::MEM, offs, (uint64_t)*(F+rs2 + 8)); - if(this->core.reg.trap_state>=0x80000000UL) throw memory_access_exception(); + if(has_synchronous_exception()) throw memory_access_exception(); } break; }// @suppress("No break at end of case") @@ -4815,7 +4821,7 @@ typename vm_base::virt_addr_t vm_impl::execute_inst(finish_cond_e co { uint32_t offs = (uint32_t)((uint64_t)(*(X+2)) + (uint64_t)(uimm)); uint64_t res_30 = super::template read_mem(traits::MEM, offs); - if(this->core.reg.trap_state>=0x80000000UL) throw memory_access_exception(); + if(has_synchronous_exception()) throw memory_access_exception(); uint64_t res = (uint64_t)res_30; *(F+rd) = NaNBox64(res); } @@ -4840,7 +4846,7 @@ typename vm_base::virt_addr_t vm_impl::execute_inst(finish_cond_e co { uint32_t offs = (uint32_t)((uint64_t)(*(X+2)) + (uint64_t)(uimm)); super::template write_mem(traits::MEM, offs, (uint64_t)*(F+rs2)); - if(this->core.reg.trap_state>=0x80000000UL) throw memory_access_exception(); + if(has_synchronous_exception()) throw memory_access_exception(); } break; }// @suppress("No break at end of case") @@ -4860,7 +4866,7 @@ typename vm_base::virt_addr_t vm_impl::execute_inst(finish_cond_e co // execute instruction { super::template write_mem(traits::FENCE, traits::fencevma, ((uint16_t)(uint8_t)rs1<<8)|(uint8_t)asid); - if(this->core.reg.trap_state>=0x80000000UL) throw memory_access_exception(); + if(has_synchronous_exception()) throw memory_access_exception(); } break; }// @suppress("No break at end of case") diff --git a/src/vm/interp/vm_rv32gcv.cpp b/src/vm/interp/vm_rv32gcv.cpp index 55cd5ea..1d3c26c 100644 --- a/src/vm/interp/vm_rv32gcv.cpp +++ b/src/vm/interp/vm_rv32gcv.cpp @@ -238,6 +238,12 @@ template class vm_impl : public iss::interp::vm_base { inline void set_tval(uint64_t new_tval){ tval = new_tval; } + + inline bool has_synchronous_exception() const { + auto state = this->core.reg.trap_state; + return (state & 0x80000000ULL) != 0 && (state & 0xffffULL) == 0; + } + uint64_t fetch_count{0}; uint64_t tval{0}; @@ -1784,7 +1790,7 @@ typename vm_base::virt_addr_t vm_impl::execute_inst(finish_cond_e co else { uint32_t load_address = (uint32_t)((uint64_t)(*(X+rs1)) + (int64_t)((int16_t)sext<12>(imm))); int8_t res_1 = super::template read_mem(traits::MEM, load_address); - if(this->core.reg.trap_state>=0x80000000UL) throw memory_access_exception(); + if(has_synchronous_exception()) throw memory_access_exception(); int8_t res = (int8_t)res_1; if(rd != 0) { *(X+rd) = (uint32_t)res; @@ -1816,7 +1822,7 @@ typename vm_base::virt_addr_t vm_impl::execute_inst(finish_cond_e co else { uint32_t load_address = (uint32_t)((uint64_t)(*(X+rs1)) + (int64_t)((int16_t)sext<12>(imm))); int16_t res_2 = super::template read_mem(traits::MEM, load_address); - if(this->core.reg.trap_state>=0x80000000UL) throw memory_access_exception(); + if(has_synchronous_exception()) throw memory_access_exception(); int16_t res = (int16_t)res_2; if(rd != 0) { *(X+rd) = (uint32_t)res; @@ -1848,7 +1854,7 @@ typename vm_base::virt_addr_t vm_impl::execute_inst(finish_cond_e co else { uint32_t load_address = (uint32_t)((uint64_t)(*(X+rs1)) + (int64_t)((int16_t)sext<12>(imm))); int32_t res_3 = super::template read_mem(traits::MEM, load_address); - if(this->core.reg.trap_state>=0x80000000UL) throw memory_access_exception(); + if(has_synchronous_exception()) throw memory_access_exception(); int32_t res = (int32_t)res_3; if(rd != 0) { *(X+rd) = (uint32_t)res; @@ -1880,7 +1886,7 @@ typename vm_base::virt_addr_t vm_impl::execute_inst(finish_cond_e co else { uint32_t load_address = (uint32_t)((uint64_t)(*(X+rs1)) + (int64_t)((int16_t)sext<12>(imm))); uint8_t res_4 = super::template read_mem(traits::MEM, load_address); - if(this->core.reg.trap_state>=0x80000000UL) throw memory_access_exception(); + if(has_synchronous_exception()) throw memory_access_exception(); uint8_t res = res_4; if(rd != 0) { *(X+rd) = (uint32_t)res; @@ -1912,7 +1918,7 @@ typename vm_base::virt_addr_t vm_impl::execute_inst(finish_cond_e co else { uint32_t load_address = (uint32_t)((uint64_t)(*(X+rs1)) + (int64_t)((int16_t)sext<12>(imm))); uint16_t res_5 = super::template read_mem(traits::MEM, load_address); - if(this->core.reg.trap_state>=0x80000000UL) throw memory_access_exception(); + if(has_synchronous_exception()) throw memory_access_exception(); uint16_t res = res_5; if(rd != 0) { *(X+rd) = (uint32_t)res; @@ -1944,7 +1950,7 @@ typename vm_base::virt_addr_t vm_impl::execute_inst(finish_cond_e co else { uint32_t store_address = (uint32_t)((uint64_t)(*(X+rs1)) + (int64_t)((int16_t)sext<12>(imm))); super::template write_mem(traits::MEM, store_address, (uint8_t)*(X+rs2)); - if(this->core.reg.trap_state>=0x80000000UL) throw memory_access_exception(); + if(has_synchronous_exception()) throw memory_access_exception(); } } break; @@ -1972,7 +1978,7 @@ typename vm_base::virt_addr_t vm_impl::execute_inst(finish_cond_e co else { uint32_t store_address = (uint32_t)((uint64_t)(*(X+rs1)) + (int64_t)((int16_t)sext<12>(imm))); super::template write_mem(traits::MEM, store_address, (uint16_t)*(X+rs2)); - if(this->core.reg.trap_state>=0x80000000UL) throw memory_access_exception(); + if(has_synchronous_exception()) throw memory_access_exception(); } } break; @@ -2000,7 +2006,7 @@ typename vm_base::virt_addr_t vm_impl::execute_inst(finish_cond_e co else { uint32_t store_address = (uint32_t)((uint64_t)(*(X+rs1)) + (int64_t)((int16_t)sext<12>(imm))); super::template write_mem(traits::MEM, store_address, (uint32_t)*(X+rs2)); - if(this->core.reg.trap_state>=0x80000000UL) throw memory_access_exception(); + if(has_synchronous_exception()) throw memory_access_exception(); } } break; @@ -2556,7 +2562,7 @@ typename vm_base::virt_addr_t vm_impl::execute_inst(finish_cond_e co // execute instruction { super::template write_mem(traits::FENCE, traits::fence, (uint8_t)pred << 4 | succ); - if(this->core.reg.trap_state>=0x80000000UL) throw memory_access_exception(); + if(has_synchronous_exception()) throw memory_access_exception(); } break; }// @suppress("No break at end of case") @@ -2648,15 +2654,15 @@ typename vm_base::virt_addr_t vm_impl::execute_inst(finish_cond_e co uint32_t xrs1 = *(X+rs1); if(rd != 0) { uint32_t res_6 = super::template read_mem(traits::CSR, csr); - if(this->core.reg.trap_state>=0x80000000UL) throw memory_access_exception(); + if(has_synchronous_exception()) throw memory_access_exception(); uint32_t xrd = res_6; super::template write_mem(traits::CSR, csr, xrs1); - if(this->core.reg.trap_state>=0x80000000UL) throw memory_access_exception(); + if(has_synchronous_exception()) throw memory_access_exception(); *(X+rd) = xrd; } else { super::template write_mem(traits::CSR, csr, xrs1); - if(this->core.reg.trap_state>=0x80000000UL) throw memory_access_exception(); + if(has_synchronous_exception()) throw memory_access_exception(); } } } @@ -2684,12 +2690,12 @@ typename vm_base::virt_addr_t vm_impl::execute_inst(finish_cond_e co } else { uint32_t res_7 = super::template read_mem(traits::CSR, csr); - if(this->core.reg.trap_state>=0x80000000UL) throw memory_access_exception(); + if(has_synchronous_exception()) throw memory_access_exception(); uint32_t xrd = res_7; uint32_t xrs1 = *(X+rs1); if(rs1 != 0) { super::template write_mem(traits::CSR, csr, xrd | xrs1); - if(this->core.reg.trap_state>=0x80000000UL) throw memory_access_exception(); + if(has_synchronous_exception()) throw memory_access_exception(); } if(rd != 0) { *(X+rd) = xrd; @@ -2720,12 +2726,12 @@ typename vm_base::virt_addr_t vm_impl::execute_inst(finish_cond_e co } else { uint32_t res_8 = super::template read_mem(traits::CSR, csr); - if(this->core.reg.trap_state>=0x80000000UL) throw memory_access_exception(); + if(has_synchronous_exception()) throw memory_access_exception(); uint32_t xrd = res_8; uint32_t xrs1 = *(X+rs1); if(rs1 != 0) { super::template write_mem(traits::CSR, csr, xrd & ~xrs1); - if(this->core.reg.trap_state>=0x80000000UL) throw memory_access_exception(); + if(has_synchronous_exception()) throw memory_access_exception(); } if(rd != 0) { *(X+rd) = xrd; @@ -2756,10 +2762,10 @@ typename vm_base::virt_addr_t vm_impl::execute_inst(finish_cond_e co } else { uint32_t res_9 = super::template read_mem(traits::CSR, csr); - if(this->core.reg.trap_state>=0x80000000UL) throw memory_access_exception(); + if(has_synchronous_exception()) throw memory_access_exception(); uint32_t xrd = res_9; super::template write_mem(traits::CSR, csr, (uint32_t)zimm); - if(this->core.reg.trap_state>=0x80000000UL) throw memory_access_exception(); + if(has_synchronous_exception()) throw memory_access_exception(); if(rd != 0) { *(X+rd) = xrd; } @@ -2789,11 +2795,11 @@ typename vm_base::virt_addr_t vm_impl::execute_inst(finish_cond_e co } else { uint32_t res_10 = super::template read_mem(traits::CSR, csr); - if(this->core.reg.trap_state>=0x80000000UL) throw memory_access_exception(); + if(has_synchronous_exception()) throw memory_access_exception(); uint32_t xrd = res_10; if(zimm != 0) { super::template write_mem(traits::CSR, csr, xrd | (uint32_t)zimm); - if(this->core.reg.trap_state>=0x80000000UL) throw memory_access_exception(); + if(has_synchronous_exception()) throw memory_access_exception(); } if(rd != 0) { *(X+rd) = xrd; @@ -2824,11 +2830,11 @@ typename vm_base::virt_addr_t vm_impl::execute_inst(finish_cond_e co } else { uint32_t res_11 = super::template read_mem(traits::CSR, csr); - if(this->core.reg.trap_state>=0x80000000UL) throw memory_access_exception(); + if(has_synchronous_exception()) throw memory_access_exception(); uint32_t xrd = res_11; if(zimm != 0) { super::template write_mem(traits::CSR, csr, xrd & ~((uint32_t)zimm)); - if(this->core.reg.trap_state>=0x80000000UL) throw memory_access_exception(); + if(has_synchronous_exception()) throw memory_access_exception(); } if(rd != 0) { *(X+rd) = xrd; @@ -2854,7 +2860,7 @@ typename vm_base::virt_addr_t vm_impl::execute_inst(finish_cond_e co // execute instruction { super::template write_mem(traits::FENCE, traits::fencei, imm); - if(this->core.reg.trap_state>=0x80000000UL) throw memory_access_exception(); + if(has_synchronous_exception()) throw memory_access_exception(); } break; }// @suppress("No break at end of case") @@ -3153,10 +3159,10 @@ typename vm_base::virt_addr_t vm_impl::execute_inst(finish_cond_e co if(rd != 0) { uint32_t offs = *(X+rs1); int32_t res_12 = super::template read_mem(traits::MEM, offs); - if(this->core.reg.trap_state>=0x80000000UL) throw memory_access_exception(); + if(has_synchronous_exception()) throw memory_access_exception(); *(X+rd) = (uint32_t)((int32_t)res_12); super::template write_mem(traits::RES, offs, (uint8_t)- 1); - if(this->core.reg.trap_state>=0x80000000UL) throw memory_access_exception(); + if(has_synchronous_exception()) throw memory_access_exception(); } } } @@ -3187,11 +3193,11 @@ typename vm_base::virt_addr_t vm_impl::execute_inst(finish_cond_e co else { uint32_t offs = *(X+rs1); uint8_t res_13 = super::template read_mem(traits::RES, offs); - if(this->core.reg.trap_state>=0x80000000UL) throw memory_access_exception(); + if(has_synchronous_exception()) throw memory_access_exception(); uint32_t res1 = res_13; if(res1 != 0) { super::template write_mem(traits::MEM, offs, (uint32_t)*(X+rs2)); - if(this->core.reg.trap_state>=0x80000000UL) throw memory_access_exception(); + if(has_synchronous_exception()) throw memory_access_exception(); } if(rd != 0) { *(X+rd) = res1? 0 : 1; @@ -3227,11 +3233,11 @@ typename vm_base::virt_addr_t vm_impl::execute_inst(finish_cond_e co uint32_t res = *(X+rs2); if(rd != 0) { int32_t res_14 = super::template read_mem(traits::MEM, offs); - if(this->core.reg.trap_state>=0x80000000UL) throw memory_access_exception(); + if(has_synchronous_exception()) throw memory_access_exception(); *(X+rd) = (uint32_t)((int32_t)res_14); } super::template write_mem(traits::MEM, offs, (uint32_t)res); - if(this->core.reg.trap_state>=0x80000000UL) throw memory_access_exception(); + if(has_synchronous_exception()) throw memory_access_exception(); } } break; @@ -3261,14 +3267,14 @@ typename vm_base::virt_addr_t vm_impl::execute_inst(finish_cond_e co else { uint32_t offs = *(X+rs1); int32_t res_15 = super::template read_mem(traits::MEM, offs); - if(this->core.reg.trap_state>=0x80000000UL) throw memory_access_exception(); + if(has_synchronous_exception()) throw memory_access_exception(); int32_t res1 = (int32_t)res_15; int64_t res2 = (int64_t)(res1) + (int64_t)((int32_t)*(X+rs2)); if(rd != 0) { *(X+rd) = (uint32_t)res1; } super::template write_mem(traits::MEM, offs, (uint32_t)res2); - if(this->core.reg.trap_state>=0x80000000UL) throw memory_access_exception(); + if(has_synchronous_exception()) throw memory_access_exception(); } } break; @@ -3298,14 +3304,14 @@ typename vm_base::virt_addr_t vm_impl::execute_inst(finish_cond_e co else { uint32_t offs = *(X+rs1); uint32_t res_16 = super::template read_mem(traits::MEM, offs); - if(this->core.reg.trap_state>=0x80000000UL) throw memory_access_exception(); + if(has_synchronous_exception()) throw memory_access_exception(); uint32_t res1 = res_16; uint32_t res2 = res1 ^ (uint32_t)*(X+rs2); if(rd != 0) { *(X+rd) = ((uint32_t)(int32_t)(int32_t)res1); } super::template write_mem(traits::MEM, offs, res2); - if(this->core.reg.trap_state>=0x80000000UL) throw memory_access_exception(); + if(has_synchronous_exception()) throw memory_access_exception(); } } break; @@ -3335,14 +3341,14 @@ typename vm_base::virt_addr_t vm_impl::execute_inst(finish_cond_e co else { uint32_t offs = *(X+rs1); uint32_t res_17 = super::template read_mem(traits::MEM, offs); - if(this->core.reg.trap_state>=0x80000000UL) throw memory_access_exception(); + if(has_synchronous_exception()) throw memory_access_exception(); uint32_t res1 = res_17; uint32_t res2 = res1 & (uint32_t)*(X+rs2); if(rd != 0) { *(X+rd) = ((uint32_t)(int32_t)(int32_t)res1); } super::template write_mem(traits::MEM, offs, res2); - if(this->core.reg.trap_state>=0x80000000UL) throw memory_access_exception(); + if(has_synchronous_exception()) throw memory_access_exception(); } } break; @@ -3372,14 +3378,14 @@ typename vm_base::virt_addr_t vm_impl::execute_inst(finish_cond_e co else { uint32_t offs = *(X+rs1); uint32_t res_18 = super::template read_mem(traits::MEM, offs); - if(this->core.reg.trap_state>=0x80000000UL) throw memory_access_exception(); + if(has_synchronous_exception()) throw memory_access_exception(); uint32_t res1 = res_18; uint32_t res2 = res1 | (uint32_t)*(X+rs2); if(rd != 0) { *(X+rd) = ((uint32_t)(int32_t)(int32_t)res1); } super::template write_mem(traits::MEM, offs, res2); - if(this->core.reg.trap_state>=0x80000000UL) throw memory_access_exception(); + if(has_synchronous_exception()) throw memory_access_exception(); } } break; @@ -3409,14 +3415,14 @@ typename vm_base::virt_addr_t vm_impl::execute_inst(finish_cond_e co else { uint32_t offs = *(X+rs1); int32_t res_19 = super::template read_mem(traits::MEM, offs); - if(this->core.reg.trap_state>=0x80000000UL) throw memory_access_exception(); + if(has_synchronous_exception()) throw memory_access_exception(); int32_t res1 = (int32_t)res_19; uint32_t res2 = res1 > (int32_t)*(X+rs2)? (uint32_t)*(X+rs2) : ((uint32_t)res1); if(rd != 0) { *(X+rd) = (uint32_t)res1; } super::template write_mem(traits::MEM, offs, res2); - if(this->core.reg.trap_state>=0x80000000UL) throw memory_access_exception(); + if(has_synchronous_exception()) throw memory_access_exception(); } } break; @@ -3446,14 +3452,14 @@ typename vm_base::virt_addr_t vm_impl::execute_inst(finish_cond_e co else { uint32_t offs = *(X+rs1); int32_t res_20 = super::template read_mem(traits::MEM, offs); - if(this->core.reg.trap_state>=0x80000000UL) throw memory_access_exception(); + if(has_synchronous_exception()) throw memory_access_exception(); int32_t res1 = (int32_t)res_20; uint32_t res2 = res1 < (int32_t)*(X+rs2)? (uint32_t)*(X+rs2) : ((uint32_t)res1); if(rd != 0) { *(X+rd) = (uint32_t)res1; } super::template write_mem(traits::MEM, offs, res2); - if(this->core.reg.trap_state>=0x80000000UL) throw memory_access_exception(); + if(has_synchronous_exception()) throw memory_access_exception(); } } break; @@ -3483,14 +3489,14 @@ typename vm_base::virt_addr_t vm_impl::execute_inst(finish_cond_e co else { uint32_t offs = *(X+rs1); uint32_t res_21 = super::template read_mem(traits::MEM, offs); - if(this->core.reg.trap_state>=0x80000000UL) throw memory_access_exception(); + if(has_synchronous_exception()) throw memory_access_exception(); uint32_t res1 = res_21; uint32_t res2 = res1 > (uint32_t)*(X+rs2)? (uint32_t)*(X+rs2) : res1; if(rd != 0) { *(X+rd) = ((uint32_t)(int32_t)(int32_t)res1); } super::template write_mem(traits::MEM, offs, res2); - if(this->core.reg.trap_state>=0x80000000UL) throw memory_access_exception(); + if(has_synchronous_exception()) throw memory_access_exception(); } } break; @@ -3520,14 +3526,14 @@ typename vm_base::virt_addr_t vm_impl::execute_inst(finish_cond_e co else { uint32_t offs = *(X+rs1); uint32_t res_22 = super::template read_mem(traits::MEM, offs); - if(this->core.reg.trap_state>=0x80000000UL) throw memory_access_exception(); + if(has_synchronous_exception()) throw memory_access_exception(); uint32_t res1 = res_22; uint32_t res2 = res1 < (int32_t)*(X+rs2)? (uint32_t)*(X+rs2) : res1; if(rd != 0) { *(X+rd) = ((uint32_t)(int32_t)(int32_t)res1); } super::template write_mem(traits::MEM, offs, res2); - if(this->core.reg.trap_state>=0x80000000UL) throw memory_access_exception(); + if(has_synchronous_exception()) throw memory_access_exception(); } } break; @@ -3576,7 +3582,7 @@ typename vm_base::virt_addr_t vm_impl::execute_inst(finish_cond_e co { uint32_t offs = (uint32_t)((uint64_t)(*(X+rs1 + 8)) + (uint64_t)(uimm)); int32_t res_23 = super::template read_mem(traits::MEM, offs); - if(this->core.reg.trap_state>=0x80000000UL) throw memory_access_exception(); + if(has_synchronous_exception()) throw memory_access_exception(); *(X+rd + 8) = (uint32_t)(int32_t)res_23; } break; @@ -3600,7 +3606,7 @@ typename vm_base::virt_addr_t vm_impl::execute_inst(finish_cond_e co { uint32_t offs = (uint32_t)((uint64_t)(*(X+rs1 + 8)) + (uint64_t)(uimm)); super::template write_mem(traits::MEM, offs, (uint32_t)*(X+rs2 + 8)); - if(this->core.reg.trap_state>=0x80000000UL) throw memory_access_exception(); + if(has_synchronous_exception()) throw memory_access_exception(); } break; }// @suppress("No break at end of case") @@ -4024,7 +4030,7 @@ typename vm_base::virt_addr_t vm_impl::execute_inst(finish_cond_e co else { uint32_t offs = (uint32_t)((uint64_t)(*(X+2)) + (uint64_t)(uimm)); int32_t res_24 = super::template read_mem(traits::MEM, offs); - if(this->core.reg.trap_state>=0x80000000UL) throw memory_access_exception(); + if(has_synchronous_exception()) throw memory_access_exception(); *(X+rd) = (uint32_t)(int32_t)res_24; } } @@ -4192,7 +4198,7 @@ typename vm_base::virt_addr_t vm_impl::execute_inst(finish_cond_e co else { uint32_t offs = (uint32_t)((uint64_t)(*(X+2)) + (uint64_t)(uimm)); super::template write_mem(traits::MEM, offs, (uint32_t)*(X+rs2)); - if(this->core.reg.trap_state>=0x80000000UL) throw memory_access_exception(); + if(has_synchronous_exception()) throw memory_access_exception(); } } break; @@ -4237,7 +4243,7 @@ typename vm_base::virt_addr_t vm_impl::execute_inst(finish_cond_e co else { uint32_t offs = (uint32_t)((uint64_t)(*(X+rs1)) + (int64_t)((int16_t)sext<12>(imm))); uint32_t res_25 = super::template read_mem(traits::MEM, offs); - if(this->core.reg.trap_state>=0x80000000UL) throw memory_access_exception(); + if(has_synchronous_exception()) throw memory_access_exception(); *(F+rd) = NaNBox32(res_25); } } @@ -4267,7 +4273,7 @@ typename vm_base::virt_addr_t vm_impl::execute_inst(finish_cond_e co else { uint32_t offs = (uint32_t)((uint64_t)(*(X+rs1)) + (int64_t)((int16_t)sext<12>(imm))); super::template write_mem(traits::MEM, offs, (uint32_t)*(F+rs2)); - if(this->core.reg.trap_state>=0x80000000UL) throw memory_access_exception(); + if(has_synchronous_exception()) throw memory_access_exception(); } } break; @@ -4939,7 +4945,7 @@ typename vm_base::virt_addr_t vm_impl::execute_inst(finish_cond_e co { uint32_t offs = (uint32_t)((uint64_t)(*(X+rs1 + 8)) + (uint64_t)(uimm)); uint32_t res_26 = super::template read_mem(traits::MEM, offs); - if(this->core.reg.trap_state>=0x80000000UL) throw memory_access_exception(); + if(has_synchronous_exception()) throw memory_access_exception(); uint32_t res = (uint32_t)res_26; *(F+rd + 8) = NaNBox32(res); } @@ -4965,7 +4971,7 @@ typename vm_base::virt_addr_t vm_impl::execute_inst(finish_cond_e co { uint32_t offs = (uint32_t)((uint64_t)(*(X+rs1 + 8)) + (uint64_t)(uimm)); super::template write_mem(traits::MEM, offs, (uint32_t)*(F+rs2 + 8)); - if(this->core.reg.trap_state>=0x80000000UL) throw memory_access_exception(); + if(has_synchronous_exception()) throw memory_access_exception(); } break; }// @suppress("No break at end of case") @@ -4988,7 +4994,7 @@ typename vm_base::virt_addr_t vm_impl::execute_inst(finish_cond_e co { uint32_t offs = (uint32_t)((uint64_t)(*(X+2)) + (uint64_t)(uimm)); uint32_t res_27 = super::template read_mem(traits::MEM, offs); - if(this->core.reg.trap_state>=0x80000000UL) throw memory_access_exception(); + if(has_synchronous_exception()) throw memory_access_exception(); uint32_t res = (uint32_t)res_27; *(F+rd) = NaNBox32(res); } @@ -5013,7 +5019,7 @@ typename vm_base::virt_addr_t vm_impl::execute_inst(finish_cond_e co { uint32_t offs = (uint32_t)((uint64_t)(*(X+2)) + (uint64_t)(uimm)); super::template write_mem(traits::MEM, offs, (uint32_t)*(F+rs2)); - if(this->core.reg.trap_state>=0x80000000UL) throw memory_access_exception(); + if(has_synchronous_exception()) throw memory_access_exception(); } break; }// @suppress("No break at end of case") @@ -5041,7 +5047,7 @@ typename vm_base::virt_addr_t vm_impl::execute_inst(finish_cond_e co else { uint32_t offs = (uint32_t)((uint64_t)(*(X+rs1)) + (int64_t)((int16_t)sext<12>(imm))); uint64_t res_28 = super::template read_mem(traits::MEM, offs); - if(this->core.reg.trap_state>=0x80000000UL) throw memory_access_exception(); + if(has_synchronous_exception()) throw memory_access_exception(); *(F+rd) = NaNBox64(res_28); } } @@ -5071,7 +5077,7 @@ typename vm_base::virt_addr_t vm_impl::execute_inst(finish_cond_e co else { uint32_t offs = (uint32_t)((uint64_t)(*(X+rs1)) + (int64_t)((int16_t)sext<12>(imm))); super::template write_mem(traits::MEM, offs, (uint64_t)*(F+rs2)); - if(this->core.reg.trap_state>=0x80000000UL) throw memory_access_exception(); + if(has_synchronous_exception()) throw memory_access_exception(); } } break; @@ -5737,7 +5743,7 @@ typename vm_base::virt_addr_t vm_impl::execute_inst(finish_cond_e co { uint32_t offs = (uint32_t)((uint64_t)(*(X+rs1 + 8)) + (uint64_t)(uimm)); uint64_t res_29 = super::template read_mem(traits::MEM, offs); - if(this->core.reg.trap_state>=0x80000000UL) throw memory_access_exception(); + if(has_synchronous_exception()) throw memory_access_exception(); uint64_t res = (uint64_t)res_29; *(F+rd + 8) = NaNBox64(res); } @@ -5763,7 +5769,7 @@ typename vm_base::virt_addr_t vm_impl::execute_inst(finish_cond_e co { uint32_t offs = (uint32_t)((uint64_t)(*(X+rs1 + 8)) + (uint64_t)(uimm)); super::template write_mem(traits::MEM, offs, (uint64_t)*(F+rs2 + 8)); - if(this->core.reg.trap_state>=0x80000000UL) throw memory_access_exception(); + if(has_synchronous_exception()) throw memory_access_exception(); } break; }// @suppress("No break at end of case") @@ -5786,7 +5792,7 @@ typename vm_base::virt_addr_t vm_impl::execute_inst(finish_cond_e co { uint32_t offs = (uint32_t)((uint64_t)(*(X+2)) + (uint64_t)(uimm)); uint64_t res_30 = super::template read_mem(traits::MEM, offs); - if(this->core.reg.trap_state>=0x80000000UL) throw memory_access_exception(); + if(has_synchronous_exception()) throw memory_access_exception(); uint64_t res = (uint64_t)res_30; *(F+rd) = NaNBox64(res); } @@ -5811,7 +5817,7 @@ typename vm_base::virt_addr_t vm_impl::execute_inst(finish_cond_e co { uint32_t offs = (uint32_t)((uint64_t)(*(X+2)) + (uint64_t)(uimm)); super::template write_mem(traits::MEM, offs, (uint64_t)*(F+rs2)); - if(this->core.reg.trap_state>=0x80000000UL) throw memory_access_exception(); + if(has_synchronous_exception()) throw memory_access_exception(); } break; }// @suppress("No break at end of case") @@ -5831,7 +5837,7 @@ typename vm_base::virt_addr_t vm_impl::execute_inst(finish_cond_e co // execute instruction { super::template write_mem(traits::FENCE, traits::fencevma, ((uint16_t)(uint8_t)rs1<<8)|(uint8_t)asid); - if(this->core.reg.trap_state>=0x80000000UL) throw memory_access_exception(); + if(has_synchronous_exception()) throw memory_access_exception(); } break; }// @suppress("No break at end of case") diff --git a/src/vm/interp/vm_rv32i.cpp b/src/vm/interp/vm_rv32i.cpp index 560bbe2..6726b31 100644 --- a/src/vm/interp/vm_rv32i.cpp +++ b/src/vm/interp/vm_rv32i.cpp @@ -122,6 +122,12 @@ template class vm_impl : public iss::interp::vm_base { inline void set_tval(uint64_t new_tval){ tval = new_tval; } + + inline bool has_synchronous_exception() const { + auto state = this->core.reg.trap_state; + return (state & 0x80000000ULL) != 0 && (state & 0xffffULL) == 0; + } + uint64_t fetch_count{0}; uint64_t tval{0}; @@ -669,7 +675,7 @@ typename vm_base::virt_addr_t vm_impl::execute_inst(finish_cond_e co else { uint32_t load_address = (uint32_t)((uint64_t)(*(X+rs1)) + (int64_t)((int16_t)sext<12>(imm))); int8_t res_1 = super::template read_mem(traits::MEM, load_address); - if(this->core.reg.trap_state>=0x80000000UL) throw memory_access_exception(); + if(has_synchronous_exception()) throw memory_access_exception(); int8_t res = (int8_t)res_1; if(rd != 0) { *(X+rd) = (uint32_t)res; @@ -701,7 +707,7 @@ typename vm_base::virt_addr_t vm_impl::execute_inst(finish_cond_e co else { uint32_t load_address = (uint32_t)((uint64_t)(*(X+rs1)) + (int64_t)((int16_t)sext<12>(imm))); int16_t res_2 = super::template read_mem(traits::MEM, load_address); - if(this->core.reg.trap_state>=0x80000000UL) throw memory_access_exception(); + if(has_synchronous_exception()) throw memory_access_exception(); int16_t res = (int16_t)res_2; if(rd != 0) { *(X+rd) = (uint32_t)res; @@ -733,7 +739,7 @@ typename vm_base::virt_addr_t vm_impl::execute_inst(finish_cond_e co else { uint32_t load_address = (uint32_t)((uint64_t)(*(X+rs1)) + (int64_t)((int16_t)sext<12>(imm))); int32_t res_3 = super::template read_mem(traits::MEM, load_address); - if(this->core.reg.trap_state>=0x80000000UL) throw memory_access_exception(); + if(has_synchronous_exception()) throw memory_access_exception(); int32_t res = (int32_t)res_3; if(rd != 0) { *(X+rd) = (uint32_t)res; @@ -765,7 +771,7 @@ typename vm_base::virt_addr_t vm_impl::execute_inst(finish_cond_e co else { uint32_t load_address = (uint32_t)((uint64_t)(*(X+rs1)) + (int64_t)((int16_t)sext<12>(imm))); uint8_t res_4 = super::template read_mem(traits::MEM, load_address); - if(this->core.reg.trap_state>=0x80000000UL) throw memory_access_exception(); + if(has_synchronous_exception()) throw memory_access_exception(); uint8_t res = res_4; if(rd != 0) { *(X+rd) = (uint32_t)res; @@ -797,7 +803,7 @@ typename vm_base::virt_addr_t vm_impl::execute_inst(finish_cond_e co else { uint32_t load_address = (uint32_t)((uint64_t)(*(X+rs1)) + (int64_t)((int16_t)sext<12>(imm))); uint16_t res_5 = super::template read_mem(traits::MEM, load_address); - if(this->core.reg.trap_state>=0x80000000UL) throw memory_access_exception(); + if(has_synchronous_exception()) throw memory_access_exception(); uint16_t res = res_5; if(rd != 0) { *(X+rd) = (uint32_t)res; @@ -829,7 +835,7 @@ typename vm_base::virt_addr_t vm_impl::execute_inst(finish_cond_e co else { uint32_t store_address = (uint32_t)((uint64_t)(*(X+rs1)) + (int64_t)((int16_t)sext<12>(imm))); super::template write_mem(traits::MEM, store_address, (uint8_t)*(X+rs2)); - if(this->core.reg.trap_state>=0x80000000UL) throw memory_access_exception(); + if(has_synchronous_exception()) throw memory_access_exception(); } } break; @@ -857,7 +863,7 @@ typename vm_base::virt_addr_t vm_impl::execute_inst(finish_cond_e co else { uint32_t store_address = (uint32_t)((uint64_t)(*(X+rs1)) + (int64_t)((int16_t)sext<12>(imm))); super::template write_mem(traits::MEM, store_address, (uint16_t)*(X+rs2)); - if(this->core.reg.trap_state>=0x80000000UL) throw memory_access_exception(); + if(has_synchronous_exception()) throw memory_access_exception(); } } break; @@ -885,7 +891,7 @@ typename vm_base::virt_addr_t vm_impl::execute_inst(finish_cond_e co else { uint32_t store_address = (uint32_t)((uint64_t)(*(X+rs1)) + (int64_t)((int16_t)sext<12>(imm))); super::template write_mem(traits::MEM, store_address, (uint32_t)*(X+rs2)); - if(this->core.reg.trap_state>=0x80000000UL) throw memory_access_exception(); + if(has_synchronous_exception()) throw memory_access_exception(); } } break; @@ -1441,7 +1447,7 @@ typename vm_base::virt_addr_t vm_impl::execute_inst(finish_cond_e co // execute instruction { super::template write_mem(traits::FENCE, traits::fence, (uint8_t)pred << 4 | succ); - if(this->core.reg.trap_state>=0x80000000UL) throw memory_access_exception(); + if(has_synchronous_exception()) throw memory_access_exception(); } break; }// @suppress("No break at end of case") @@ -1533,15 +1539,15 @@ typename vm_base::virt_addr_t vm_impl::execute_inst(finish_cond_e co uint32_t xrs1 = *(X+rs1); if(rd != 0) { uint32_t res_6 = super::template read_mem(traits::CSR, csr); - if(this->core.reg.trap_state>=0x80000000UL) throw memory_access_exception(); + if(has_synchronous_exception()) throw memory_access_exception(); uint32_t xrd = res_6; super::template write_mem(traits::CSR, csr, xrs1); - if(this->core.reg.trap_state>=0x80000000UL) throw memory_access_exception(); + if(has_synchronous_exception()) throw memory_access_exception(); *(X+rd) = xrd; } else { super::template write_mem(traits::CSR, csr, xrs1); - if(this->core.reg.trap_state>=0x80000000UL) throw memory_access_exception(); + if(has_synchronous_exception()) throw memory_access_exception(); } } } @@ -1569,12 +1575,12 @@ typename vm_base::virt_addr_t vm_impl::execute_inst(finish_cond_e co } else { uint32_t res_7 = super::template read_mem(traits::CSR, csr); - if(this->core.reg.trap_state>=0x80000000UL) throw memory_access_exception(); + if(has_synchronous_exception()) throw memory_access_exception(); uint32_t xrd = res_7; uint32_t xrs1 = *(X+rs1); if(rs1 != 0) { super::template write_mem(traits::CSR, csr, xrd | xrs1); - if(this->core.reg.trap_state>=0x80000000UL) throw memory_access_exception(); + if(has_synchronous_exception()) throw memory_access_exception(); } if(rd != 0) { *(X+rd) = xrd; @@ -1605,12 +1611,12 @@ typename vm_base::virt_addr_t vm_impl::execute_inst(finish_cond_e co } else { uint32_t res_8 = super::template read_mem(traits::CSR, csr); - if(this->core.reg.trap_state>=0x80000000UL) throw memory_access_exception(); + if(has_synchronous_exception()) throw memory_access_exception(); uint32_t xrd = res_8; uint32_t xrs1 = *(X+rs1); if(rs1 != 0) { super::template write_mem(traits::CSR, csr, xrd & ~xrs1); - if(this->core.reg.trap_state>=0x80000000UL) throw memory_access_exception(); + if(has_synchronous_exception()) throw memory_access_exception(); } if(rd != 0) { *(X+rd) = xrd; @@ -1641,10 +1647,10 @@ typename vm_base::virt_addr_t vm_impl::execute_inst(finish_cond_e co } else { uint32_t res_9 = super::template read_mem(traits::CSR, csr); - if(this->core.reg.trap_state>=0x80000000UL) throw memory_access_exception(); + if(has_synchronous_exception()) throw memory_access_exception(); uint32_t xrd = res_9; super::template write_mem(traits::CSR, csr, (uint32_t)zimm); - if(this->core.reg.trap_state>=0x80000000UL) throw memory_access_exception(); + if(has_synchronous_exception()) throw memory_access_exception(); if(rd != 0) { *(X+rd) = xrd; } @@ -1674,11 +1680,11 @@ typename vm_base::virt_addr_t vm_impl::execute_inst(finish_cond_e co } else { uint32_t res_10 = super::template read_mem(traits::CSR, csr); - if(this->core.reg.trap_state>=0x80000000UL) throw memory_access_exception(); + if(has_synchronous_exception()) throw memory_access_exception(); uint32_t xrd = res_10; if(zimm != 0) { super::template write_mem(traits::CSR, csr, xrd | (uint32_t)zimm); - if(this->core.reg.trap_state>=0x80000000UL) throw memory_access_exception(); + if(has_synchronous_exception()) throw memory_access_exception(); } if(rd != 0) { *(X+rd) = xrd; @@ -1709,11 +1715,11 @@ typename vm_base::virt_addr_t vm_impl::execute_inst(finish_cond_e co } else { uint32_t res_11 = super::template read_mem(traits::CSR, csr); - if(this->core.reg.trap_state>=0x80000000UL) throw memory_access_exception(); + if(has_synchronous_exception()) throw memory_access_exception(); uint32_t xrd = res_11; if(zimm != 0) { super::template write_mem(traits::CSR, csr, xrd & ~((uint32_t)zimm)); - if(this->core.reg.trap_state>=0x80000000UL) throw memory_access_exception(); + if(has_synchronous_exception()) throw memory_access_exception(); } if(rd != 0) { *(X+rd) = xrd; @@ -1739,7 +1745,7 @@ typename vm_base::virt_addr_t vm_impl::execute_inst(finish_cond_e co // execute instruction { super::template write_mem(traits::FENCE, traits::fencei, imm); - if(this->core.reg.trap_state>=0x80000000UL) throw memory_access_exception(); + if(has_synchronous_exception()) throw memory_access_exception(); } break; }// @suppress("No break at end of case") diff --git a/src/vm/interp/vm_rv32imac.cpp b/src/vm/interp/vm_rv32imac.cpp index e33c38e..6c6d106 100644 --- a/src/vm/interp/vm_rv32imac.cpp +++ b/src/vm/interp/vm_rv32imac.cpp @@ -122,6 +122,12 @@ template class vm_impl : public iss::interp::vm_base { inline void set_tval(uint64_t new_tval){ tval = new_tval; } + + inline bool has_synchronous_exception() const { + auto state = this->core.reg.trap_state; + return (state & 0x80000000ULL) != 0 && (state & 0xffffULL) == 0; + } + uint64_t fetch_count{0}; uint64_t tval{0}; @@ -718,7 +724,7 @@ typename vm_base::virt_addr_t vm_impl::execute_inst(finish_cond_e co else { uint32_t load_address = (uint32_t)((uint64_t)(*(X+rs1)) + (int64_t)((int16_t)sext<12>(imm))); int8_t res_1 = super::template read_mem(traits::MEM, load_address); - if(this->core.reg.trap_state>=0x80000000UL) throw memory_access_exception(); + if(has_synchronous_exception()) throw memory_access_exception(); int8_t res = (int8_t)res_1; if(rd != 0) { *(X+rd) = (uint32_t)res; @@ -750,7 +756,7 @@ typename vm_base::virt_addr_t vm_impl::execute_inst(finish_cond_e co else { uint32_t load_address = (uint32_t)((uint64_t)(*(X+rs1)) + (int64_t)((int16_t)sext<12>(imm))); int16_t res_2 = super::template read_mem(traits::MEM, load_address); - if(this->core.reg.trap_state>=0x80000000UL) throw memory_access_exception(); + if(has_synchronous_exception()) throw memory_access_exception(); int16_t res = (int16_t)res_2; if(rd != 0) { *(X+rd) = (uint32_t)res; @@ -782,7 +788,7 @@ typename vm_base::virt_addr_t vm_impl::execute_inst(finish_cond_e co else { uint32_t load_address = (uint32_t)((uint64_t)(*(X+rs1)) + (int64_t)((int16_t)sext<12>(imm))); int32_t res_3 = super::template read_mem(traits::MEM, load_address); - if(this->core.reg.trap_state>=0x80000000UL) throw memory_access_exception(); + if(has_synchronous_exception()) throw memory_access_exception(); int32_t res = (int32_t)res_3; if(rd != 0) { *(X+rd) = (uint32_t)res; @@ -814,7 +820,7 @@ typename vm_base::virt_addr_t vm_impl::execute_inst(finish_cond_e co else { uint32_t load_address = (uint32_t)((uint64_t)(*(X+rs1)) + (int64_t)((int16_t)sext<12>(imm))); uint8_t res_4 = super::template read_mem(traits::MEM, load_address); - if(this->core.reg.trap_state>=0x80000000UL) throw memory_access_exception(); + if(has_synchronous_exception()) throw memory_access_exception(); uint8_t res = res_4; if(rd != 0) { *(X+rd) = (uint32_t)res; @@ -846,7 +852,7 @@ typename vm_base::virt_addr_t vm_impl::execute_inst(finish_cond_e co else { uint32_t load_address = (uint32_t)((uint64_t)(*(X+rs1)) + (int64_t)((int16_t)sext<12>(imm))); uint16_t res_5 = super::template read_mem(traits::MEM, load_address); - if(this->core.reg.trap_state>=0x80000000UL) throw memory_access_exception(); + if(has_synchronous_exception()) throw memory_access_exception(); uint16_t res = res_5; if(rd != 0) { *(X+rd) = (uint32_t)res; @@ -878,7 +884,7 @@ typename vm_base::virt_addr_t vm_impl::execute_inst(finish_cond_e co else { uint32_t store_address = (uint32_t)((uint64_t)(*(X+rs1)) + (int64_t)((int16_t)sext<12>(imm))); super::template write_mem(traits::MEM, store_address, (uint8_t)*(X+rs2)); - if(this->core.reg.trap_state>=0x80000000UL) throw memory_access_exception(); + if(has_synchronous_exception()) throw memory_access_exception(); } } break; @@ -906,7 +912,7 @@ typename vm_base::virt_addr_t vm_impl::execute_inst(finish_cond_e co else { uint32_t store_address = (uint32_t)((uint64_t)(*(X+rs1)) + (int64_t)((int16_t)sext<12>(imm))); super::template write_mem(traits::MEM, store_address, (uint16_t)*(X+rs2)); - if(this->core.reg.trap_state>=0x80000000UL) throw memory_access_exception(); + if(has_synchronous_exception()) throw memory_access_exception(); } } break; @@ -934,7 +940,7 @@ typename vm_base::virt_addr_t vm_impl::execute_inst(finish_cond_e co else { uint32_t store_address = (uint32_t)((uint64_t)(*(X+rs1)) + (int64_t)((int16_t)sext<12>(imm))); super::template write_mem(traits::MEM, store_address, (uint32_t)*(X+rs2)); - if(this->core.reg.trap_state>=0x80000000UL) throw memory_access_exception(); + if(has_synchronous_exception()) throw memory_access_exception(); } } break; @@ -1490,7 +1496,7 @@ typename vm_base::virt_addr_t vm_impl::execute_inst(finish_cond_e co // execute instruction { super::template write_mem(traits::FENCE, traits::fence, (uint8_t)pred << 4 | succ); - if(this->core.reg.trap_state>=0x80000000UL) throw memory_access_exception(); + if(has_synchronous_exception()) throw memory_access_exception(); } break; }// @suppress("No break at end of case") @@ -1582,15 +1588,15 @@ typename vm_base::virt_addr_t vm_impl::execute_inst(finish_cond_e co uint32_t xrs1 = *(X+rs1); if(rd != 0) { uint32_t res_6 = super::template read_mem(traits::CSR, csr); - if(this->core.reg.trap_state>=0x80000000UL) throw memory_access_exception(); + if(has_synchronous_exception()) throw memory_access_exception(); uint32_t xrd = res_6; super::template write_mem(traits::CSR, csr, xrs1); - if(this->core.reg.trap_state>=0x80000000UL) throw memory_access_exception(); + if(has_synchronous_exception()) throw memory_access_exception(); *(X+rd) = xrd; } else { super::template write_mem(traits::CSR, csr, xrs1); - if(this->core.reg.trap_state>=0x80000000UL) throw memory_access_exception(); + if(has_synchronous_exception()) throw memory_access_exception(); } } } @@ -1618,12 +1624,12 @@ typename vm_base::virt_addr_t vm_impl::execute_inst(finish_cond_e co } else { uint32_t res_7 = super::template read_mem(traits::CSR, csr); - if(this->core.reg.trap_state>=0x80000000UL) throw memory_access_exception(); + if(has_synchronous_exception()) throw memory_access_exception(); uint32_t xrd = res_7; uint32_t xrs1 = *(X+rs1); if(rs1 != 0) { super::template write_mem(traits::CSR, csr, xrd | xrs1); - if(this->core.reg.trap_state>=0x80000000UL) throw memory_access_exception(); + if(has_synchronous_exception()) throw memory_access_exception(); } if(rd != 0) { *(X+rd) = xrd; @@ -1654,12 +1660,12 @@ typename vm_base::virt_addr_t vm_impl::execute_inst(finish_cond_e co } else { uint32_t res_8 = super::template read_mem(traits::CSR, csr); - if(this->core.reg.trap_state>=0x80000000UL) throw memory_access_exception(); + if(has_synchronous_exception()) throw memory_access_exception(); uint32_t xrd = res_8; uint32_t xrs1 = *(X+rs1); if(rs1 != 0) { super::template write_mem(traits::CSR, csr, xrd & ~xrs1); - if(this->core.reg.trap_state>=0x80000000UL) throw memory_access_exception(); + if(has_synchronous_exception()) throw memory_access_exception(); } if(rd != 0) { *(X+rd) = xrd; @@ -1690,10 +1696,10 @@ typename vm_base::virt_addr_t vm_impl::execute_inst(finish_cond_e co } else { uint32_t res_9 = super::template read_mem(traits::CSR, csr); - if(this->core.reg.trap_state>=0x80000000UL) throw memory_access_exception(); + if(has_synchronous_exception()) throw memory_access_exception(); uint32_t xrd = res_9; super::template write_mem(traits::CSR, csr, (uint32_t)zimm); - if(this->core.reg.trap_state>=0x80000000UL) throw memory_access_exception(); + if(has_synchronous_exception()) throw memory_access_exception(); if(rd != 0) { *(X+rd) = xrd; } @@ -1723,11 +1729,11 @@ typename vm_base::virt_addr_t vm_impl::execute_inst(finish_cond_e co } else { uint32_t res_10 = super::template read_mem(traits::CSR, csr); - if(this->core.reg.trap_state>=0x80000000UL) throw memory_access_exception(); + if(has_synchronous_exception()) throw memory_access_exception(); uint32_t xrd = res_10; if(zimm != 0) { super::template write_mem(traits::CSR, csr, xrd | (uint32_t)zimm); - if(this->core.reg.trap_state>=0x80000000UL) throw memory_access_exception(); + if(has_synchronous_exception()) throw memory_access_exception(); } if(rd != 0) { *(X+rd) = xrd; @@ -1758,11 +1764,11 @@ typename vm_base::virt_addr_t vm_impl::execute_inst(finish_cond_e co } else { uint32_t res_11 = super::template read_mem(traits::CSR, csr); - if(this->core.reg.trap_state>=0x80000000UL) throw memory_access_exception(); + if(has_synchronous_exception()) throw memory_access_exception(); uint32_t xrd = res_11; if(zimm != 0) { super::template write_mem(traits::CSR, csr, xrd & ~((uint32_t)zimm)); - if(this->core.reg.trap_state>=0x80000000UL) throw memory_access_exception(); + if(has_synchronous_exception()) throw memory_access_exception(); } if(rd != 0) { *(X+rd) = xrd; @@ -1788,7 +1794,7 @@ typename vm_base::virt_addr_t vm_impl::execute_inst(finish_cond_e co // execute instruction { super::template write_mem(traits::FENCE, traits::fencei, imm); - if(this->core.reg.trap_state>=0x80000000UL) throw memory_access_exception(); + if(has_synchronous_exception()) throw memory_access_exception(); } break; }// @suppress("No break at end of case") @@ -2087,10 +2093,10 @@ typename vm_base::virt_addr_t vm_impl::execute_inst(finish_cond_e co if(rd != 0) { uint32_t offs = *(X+rs1); int32_t res_12 = super::template read_mem(traits::MEM, offs); - if(this->core.reg.trap_state>=0x80000000UL) throw memory_access_exception(); + if(has_synchronous_exception()) throw memory_access_exception(); *(X+rd) = (uint32_t)((int32_t)res_12); super::template write_mem(traits::RES, offs, (uint8_t)- 1); - if(this->core.reg.trap_state>=0x80000000UL) throw memory_access_exception(); + if(has_synchronous_exception()) throw memory_access_exception(); } } } @@ -2121,11 +2127,11 @@ typename vm_base::virt_addr_t vm_impl::execute_inst(finish_cond_e co else { uint32_t offs = *(X+rs1); uint8_t res_13 = super::template read_mem(traits::RES, offs); - if(this->core.reg.trap_state>=0x80000000UL) throw memory_access_exception(); + if(has_synchronous_exception()) throw memory_access_exception(); uint32_t res1 = res_13; if(res1 != 0) { super::template write_mem(traits::MEM, offs, (uint32_t)*(X+rs2)); - if(this->core.reg.trap_state>=0x80000000UL) throw memory_access_exception(); + if(has_synchronous_exception()) throw memory_access_exception(); } if(rd != 0) { *(X+rd) = res1? 0 : 1; @@ -2161,11 +2167,11 @@ typename vm_base::virt_addr_t vm_impl::execute_inst(finish_cond_e co uint32_t res = *(X+rs2); if(rd != 0) { int32_t res_14 = super::template read_mem(traits::MEM, offs); - if(this->core.reg.trap_state>=0x80000000UL) throw memory_access_exception(); + if(has_synchronous_exception()) throw memory_access_exception(); *(X+rd) = (uint32_t)((int32_t)res_14); } super::template write_mem(traits::MEM, offs, (uint32_t)res); - if(this->core.reg.trap_state>=0x80000000UL) throw memory_access_exception(); + if(has_synchronous_exception()) throw memory_access_exception(); } } break; @@ -2195,14 +2201,14 @@ typename vm_base::virt_addr_t vm_impl::execute_inst(finish_cond_e co else { uint32_t offs = *(X+rs1); int32_t res_15 = super::template read_mem(traits::MEM, offs); - if(this->core.reg.trap_state>=0x80000000UL) throw memory_access_exception(); + if(has_synchronous_exception()) throw memory_access_exception(); int32_t res1 = (int32_t)res_15; int64_t res2 = (int64_t)(res1) + (int64_t)((int32_t)*(X+rs2)); if(rd != 0) { *(X+rd) = (uint32_t)res1; } super::template write_mem(traits::MEM, offs, (uint32_t)res2); - if(this->core.reg.trap_state>=0x80000000UL) throw memory_access_exception(); + if(has_synchronous_exception()) throw memory_access_exception(); } } break; @@ -2232,14 +2238,14 @@ typename vm_base::virt_addr_t vm_impl::execute_inst(finish_cond_e co else { uint32_t offs = *(X+rs1); uint32_t res_16 = super::template read_mem(traits::MEM, offs); - if(this->core.reg.trap_state>=0x80000000UL) throw memory_access_exception(); + if(has_synchronous_exception()) throw memory_access_exception(); uint32_t res1 = res_16; uint32_t res2 = res1 ^ (uint32_t)*(X+rs2); if(rd != 0) { *(X+rd) = ((uint32_t)(int32_t)(int32_t)res1); } super::template write_mem(traits::MEM, offs, res2); - if(this->core.reg.trap_state>=0x80000000UL) throw memory_access_exception(); + if(has_synchronous_exception()) throw memory_access_exception(); } } break; @@ -2269,14 +2275,14 @@ typename vm_base::virt_addr_t vm_impl::execute_inst(finish_cond_e co else { uint32_t offs = *(X+rs1); uint32_t res_17 = super::template read_mem(traits::MEM, offs); - if(this->core.reg.trap_state>=0x80000000UL) throw memory_access_exception(); + if(has_synchronous_exception()) throw memory_access_exception(); uint32_t res1 = res_17; uint32_t res2 = res1 & (uint32_t)*(X+rs2); if(rd != 0) { *(X+rd) = ((uint32_t)(int32_t)(int32_t)res1); } super::template write_mem(traits::MEM, offs, res2); - if(this->core.reg.trap_state>=0x80000000UL) throw memory_access_exception(); + if(has_synchronous_exception()) throw memory_access_exception(); } } break; @@ -2306,14 +2312,14 @@ typename vm_base::virt_addr_t vm_impl::execute_inst(finish_cond_e co else { uint32_t offs = *(X+rs1); uint32_t res_18 = super::template read_mem(traits::MEM, offs); - if(this->core.reg.trap_state>=0x80000000UL) throw memory_access_exception(); + if(has_synchronous_exception()) throw memory_access_exception(); uint32_t res1 = res_18; uint32_t res2 = res1 | (uint32_t)*(X+rs2); if(rd != 0) { *(X+rd) = ((uint32_t)(int32_t)(int32_t)res1); } super::template write_mem(traits::MEM, offs, res2); - if(this->core.reg.trap_state>=0x80000000UL) throw memory_access_exception(); + if(has_synchronous_exception()) throw memory_access_exception(); } } break; @@ -2343,14 +2349,14 @@ typename vm_base::virt_addr_t vm_impl::execute_inst(finish_cond_e co else { uint32_t offs = *(X+rs1); int32_t res_19 = super::template read_mem(traits::MEM, offs); - if(this->core.reg.trap_state>=0x80000000UL) throw memory_access_exception(); + if(has_synchronous_exception()) throw memory_access_exception(); int32_t res1 = (int32_t)res_19; uint32_t res2 = res1 > (int32_t)*(X+rs2)? (uint32_t)*(X+rs2) : ((uint32_t)res1); if(rd != 0) { *(X+rd) = (uint32_t)res1; } super::template write_mem(traits::MEM, offs, res2); - if(this->core.reg.trap_state>=0x80000000UL) throw memory_access_exception(); + if(has_synchronous_exception()) throw memory_access_exception(); } } break; @@ -2380,14 +2386,14 @@ typename vm_base::virt_addr_t vm_impl::execute_inst(finish_cond_e co else { uint32_t offs = *(X+rs1); int32_t res_20 = super::template read_mem(traits::MEM, offs); - if(this->core.reg.trap_state>=0x80000000UL) throw memory_access_exception(); + if(has_synchronous_exception()) throw memory_access_exception(); int32_t res1 = (int32_t)res_20; uint32_t res2 = res1 < (int32_t)*(X+rs2)? (uint32_t)*(X+rs2) : ((uint32_t)res1); if(rd != 0) { *(X+rd) = (uint32_t)res1; } super::template write_mem(traits::MEM, offs, res2); - if(this->core.reg.trap_state>=0x80000000UL) throw memory_access_exception(); + if(has_synchronous_exception()) throw memory_access_exception(); } } break; @@ -2417,14 +2423,14 @@ typename vm_base::virt_addr_t vm_impl::execute_inst(finish_cond_e co else { uint32_t offs = *(X+rs1); uint32_t res_21 = super::template read_mem(traits::MEM, offs); - if(this->core.reg.trap_state>=0x80000000UL) throw memory_access_exception(); + if(has_synchronous_exception()) throw memory_access_exception(); uint32_t res1 = res_21; uint32_t res2 = res1 > (uint32_t)*(X+rs2)? (uint32_t)*(X+rs2) : res1; if(rd != 0) { *(X+rd) = ((uint32_t)(int32_t)(int32_t)res1); } super::template write_mem(traits::MEM, offs, res2); - if(this->core.reg.trap_state>=0x80000000UL) throw memory_access_exception(); + if(has_synchronous_exception()) throw memory_access_exception(); } } break; @@ -2454,14 +2460,14 @@ typename vm_base::virt_addr_t vm_impl::execute_inst(finish_cond_e co else { uint32_t offs = *(X+rs1); uint32_t res_22 = super::template read_mem(traits::MEM, offs); - if(this->core.reg.trap_state>=0x80000000UL) throw memory_access_exception(); + if(has_synchronous_exception()) throw memory_access_exception(); uint32_t res1 = res_22; uint32_t res2 = res1 < (int32_t)*(X+rs2)? (uint32_t)*(X+rs2) : res1; if(rd != 0) { *(X+rd) = ((uint32_t)(int32_t)(int32_t)res1); } super::template write_mem(traits::MEM, offs, res2); - if(this->core.reg.trap_state>=0x80000000UL) throw memory_access_exception(); + if(has_synchronous_exception()) throw memory_access_exception(); } } break; @@ -2510,7 +2516,7 @@ typename vm_base::virt_addr_t vm_impl::execute_inst(finish_cond_e co { uint32_t offs = (uint32_t)((uint64_t)(*(X+rs1 + 8)) + (uint64_t)(uimm)); int32_t res_23 = super::template read_mem(traits::MEM, offs); - if(this->core.reg.trap_state>=0x80000000UL) throw memory_access_exception(); + if(has_synchronous_exception()) throw memory_access_exception(); *(X+rd + 8) = (uint32_t)(int32_t)res_23; } break; @@ -2534,7 +2540,7 @@ typename vm_base::virt_addr_t vm_impl::execute_inst(finish_cond_e co { uint32_t offs = (uint32_t)((uint64_t)(*(X+rs1 + 8)) + (uint64_t)(uimm)); super::template write_mem(traits::MEM, offs, (uint32_t)*(X+rs2 + 8)); - if(this->core.reg.trap_state>=0x80000000UL) throw memory_access_exception(); + if(has_synchronous_exception()) throw memory_access_exception(); } break; }// @suppress("No break at end of case") @@ -2958,7 +2964,7 @@ typename vm_base::virt_addr_t vm_impl::execute_inst(finish_cond_e co else { uint32_t offs = (uint32_t)((uint64_t)(*(X+2)) + (uint64_t)(uimm)); int32_t res_24 = super::template read_mem(traits::MEM, offs); - if(this->core.reg.trap_state>=0x80000000UL) throw memory_access_exception(); + if(has_synchronous_exception()) throw memory_access_exception(); *(X+rd) = (uint32_t)(int32_t)res_24; } } @@ -3126,7 +3132,7 @@ typename vm_base::virt_addr_t vm_impl::execute_inst(finish_cond_e co else { uint32_t offs = (uint32_t)((uint64_t)(*(X+2)) + (uint64_t)(uimm)); super::template write_mem(traits::MEM, offs, (uint32_t)*(X+rs2)); - if(this->core.reg.trap_state>=0x80000000UL) throw memory_access_exception(); + if(has_synchronous_exception()) throw memory_access_exception(); } } break; diff --git a/src/vm/interp/vm_rv64gc.cpp b/src/vm/interp/vm_rv64gc.cpp index 63adc2e..ef0b463 100644 --- a/src/vm/interp/vm_rv64gc.cpp +++ b/src/vm/interp/vm_rv64gc.cpp @@ -126,6 +126,12 @@ template class vm_impl : public iss::interp::vm_base { inline void set_tval(uint64_t new_tval){ tval = new_tval; } + + inline bool has_synchronous_exception() const { + auto state = this->core.reg.trap_state; + return (state & 0x80000000ULL) != 0 && (state & 0xffffULL) == 0; + } + uint64_t fetch_count{0}; uint64_t tval{0}; @@ -853,7 +859,7 @@ typename vm_base::virt_addr_t vm_impl::execute_inst(finish_cond_e co else { uint64_t load_address = (uint64_t)((uint128_t)(*(X+rs1)) + (int128_t)((int16_t)sext<12>(imm))); int8_t res_1 = super::template read_mem(traits::MEM, load_address); - if(this->core.reg.trap_state>=0x80000000UL) throw memory_access_exception(); + if(has_synchronous_exception()) throw memory_access_exception(); int8_t res = (int8_t)res_1; if(rd != 0) { *(X+rd) = (uint64_t)res; @@ -885,7 +891,7 @@ typename vm_base::virt_addr_t vm_impl::execute_inst(finish_cond_e co else { uint64_t load_address = (uint64_t)((uint128_t)(*(X+rs1)) + (int128_t)((int16_t)sext<12>(imm))); int16_t res_2 = super::template read_mem(traits::MEM, load_address); - if(this->core.reg.trap_state>=0x80000000UL) throw memory_access_exception(); + if(has_synchronous_exception()) throw memory_access_exception(); int16_t res = (int16_t)res_2; if(rd != 0) { *(X+rd) = (uint64_t)res; @@ -917,7 +923,7 @@ typename vm_base::virt_addr_t vm_impl::execute_inst(finish_cond_e co else { uint64_t load_address = (uint64_t)((uint128_t)(*(X+rs1)) + (int128_t)((int16_t)sext<12>(imm))); int32_t res_3 = super::template read_mem(traits::MEM, load_address); - if(this->core.reg.trap_state>=0x80000000UL) throw memory_access_exception(); + if(has_synchronous_exception()) throw memory_access_exception(); int32_t res = (int32_t)res_3; if(rd != 0) { *(X+rd) = (uint64_t)res; @@ -949,7 +955,7 @@ typename vm_base::virt_addr_t vm_impl::execute_inst(finish_cond_e co else { uint64_t load_address = (uint64_t)((uint128_t)(*(X+rs1)) + (int128_t)((int16_t)sext<12>(imm))); uint8_t res_4 = super::template read_mem(traits::MEM, load_address); - if(this->core.reg.trap_state>=0x80000000UL) throw memory_access_exception(); + if(has_synchronous_exception()) throw memory_access_exception(); uint8_t res = res_4; if(rd != 0) { *(X+rd) = (uint64_t)res; @@ -981,7 +987,7 @@ typename vm_base::virt_addr_t vm_impl::execute_inst(finish_cond_e co else { uint64_t load_address = (uint64_t)((uint128_t)(*(X+rs1)) + (int128_t)((int16_t)sext<12>(imm))); uint16_t res_5 = super::template read_mem(traits::MEM, load_address); - if(this->core.reg.trap_state>=0x80000000UL) throw memory_access_exception(); + if(has_synchronous_exception()) throw memory_access_exception(); uint16_t res = res_5; if(rd != 0) { *(X+rd) = (uint64_t)res; @@ -1013,7 +1019,7 @@ typename vm_base::virt_addr_t vm_impl::execute_inst(finish_cond_e co else { uint64_t store_address = (uint64_t)((uint128_t)(*(X+rs1)) + (int128_t)((int16_t)sext<12>(imm))); super::template write_mem(traits::MEM, store_address, (uint8_t)*(X+rs2)); - if(this->core.reg.trap_state>=0x80000000UL) throw memory_access_exception(); + if(has_synchronous_exception()) throw memory_access_exception(); } } break; @@ -1041,7 +1047,7 @@ typename vm_base::virt_addr_t vm_impl::execute_inst(finish_cond_e co else { uint64_t store_address = (uint64_t)((uint128_t)(*(X+rs1)) + (int128_t)((int16_t)sext<12>(imm))); super::template write_mem(traits::MEM, store_address, (uint16_t)*(X+rs2)); - if(this->core.reg.trap_state>=0x80000000UL) throw memory_access_exception(); + if(has_synchronous_exception()) throw memory_access_exception(); } } break; @@ -1069,7 +1075,7 @@ typename vm_base::virt_addr_t vm_impl::execute_inst(finish_cond_e co else { uint64_t store_address = (uint64_t)((uint128_t)(*(X+rs1)) + (int128_t)((int16_t)sext<12>(imm))); super::template write_mem(traits::MEM, store_address, (uint32_t)*(X+rs2)); - if(this->core.reg.trap_state>=0x80000000UL) throw memory_access_exception(); + if(has_synchronous_exception()) throw memory_access_exception(); } } break; @@ -1625,7 +1631,7 @@ typename vm_base::virt_addr_t vm_impl::execute_inst(finish_cond_e co // execute instruction { super::template write_mem(traits::FENCE, traits::fence, (uint8_t)pred << 4 | succ); - if(this->core.reg.trap_state>=0x80000000UL) throw memory_access_exception(); + if(has_synchronous_exception()) throw memory_access_exception(); } break; }// @suppress("No break at end of case") @@ -1716,7 +1722,7 @@ typename vm_base::virt_addr_t vm_impl::execute_inst(finish_cond_e co else { uint64_t offs = (uint64_t)((uint128_t)(*(X+rs1)) + (int128_t)((int16_t)sext<12>(imm))); uint32_t res_6 = super::template read_mem(traits::MEM, offs); - if(this->core.reg.trap_state>=0x80000000UL) throw memory_access_exception(); + if(has_synchronous_exception()) throw memory_access_exception(); uint32_t res = (uint32_t)res_6; if(rd != 0) { *(X+rd) = (uint64_t)res; @@ -1748,7 +1754,7 @@ typename vm_base::virt_addr_t vm_impl::execute_inst(finish_cond_e co else { uint64_t offs = (uint64_t)((uint128_t)(*(X+rs1)) + (int128_t)((int16_t)sext<12>(imm))); int64_t res_7 = super::template read_mem(traits::MEM, offs); - if(this->core.reg.trap_state>=0x80000000UL) throw memory_access_exception(); + if(has_synchronous_exception()) throw memory_access_exception(); int64_t res = (int64_t)res_7; if(rd != 0) { *(X+rd) = (uint64_t)res; @@ -1780,7 +1786,7 @@ typename vm_base::virt_addr_t vm_impl::execute_inst(finish_cond_e co else { uint64_t offs = (uint64_t)((uint128_t)(*(X+rs1)) + (int128_t)((int16_t)sext<12>(imm))); super::template write_mem(traits::MEM, offs, (uint64_t)*(X+rs2)); - if(this->core.reg.trap_state>=0x80000000UL) throw memory_access_exception(); + if(has_synchronous_exception()) throw memory_access_exception(); } } break; @@ -2071,15 +2077,15 @@ typename vm_base::virt_addr_t vm_impl::execute_inst(finish_cond_e co uint64_t xrs1 = *(X+rs1); if(rd != 0) { uint64_t res_8 = super::template read_mem(traits::CSR, csr); - if(this->core.reg.trap_state>=0x80000000UL) throw memory_access_exception(); + if(has_synchronous_exception()) throw memory_access_exception(); uint64_t xrd = res_8; super::template write_mem(traits::CSR, csr, xrs1); - if(this->core.reg.trap_state>=0x80000000UL) throw memory_access_exception(); + if(has_synchronous_exception()) throw memory_access_exception(); *(X+rd) = xrd; } else { super::template write_mem(traits::CSR, csr, xrs1); - if(this->core.reg.trap_state>=0x80000000UL) throw memory_access_exception(); + if(has_synchronous_exception()) throw memory_access_exception(); } } } @@ -2107,12 +2113,12 @@ typename vm_base::virt_addr_t vm_impl::execute_inst(finish_cond_e co } else { uint64_t res_9 = super::template read_mem(traits::CSR, csr); - if(this->core.reg.trap_state>=0x80000000UL) throw memory_access_exception(); + if(has_synchronous_exception()) throw memory_access_exception(); uint64_t xrd = res_9; uint64_t xrs1 = *(X+rs1); if(rs1 != 0) { super::template write_mem(traits::CSR, csr, xrd | xrs1); - if(this->core.reg.trap_state>=0x80000000UL) throw memory_access_exception(); + if(has_synchronous_exception()) throw memory_access_exception(); } if(rd != 0) { *(X+rd) = xrd; @@ -2143,12 +2149,12 @@ typename vm_base::virt_addr_t vm_impl::execute_inst(finish_cond_e co } else { uint64_t res_10 = super::template read_mem(traits::CSR, csr); - if(this->core.reg.trap_state>=0x80000000UL) throw memory_access_exception(); + if(has_synchronous_exception()) throw memory_access_exception(); uint64_t xrd = res_10; uint64_t xrs1 = *(X+rs1); if(rs1 != 0) { super::template write_mem(traits::CSR, csr, xrd & ~xrs1); - if(this->core.reg.trap_state>=0x80000000UL) throw memory_access_exception(); + if(has_synchronous_exception()) throw memory_access_exception(); } if(rd != 0) { *(X+rd) = xrd; @@ -2179,10 +2185,10 @@ typename vm_base::virt_addr_t vm_impl::execute_inst(finish_cond_e co } else { uint64_t res_11 = super::template read_mem(traits::CSR, csr); - if(this->core.reg.trap_state>=0x80000000UL) throw memory_access_exception(); + if(has_synchronous_exception()) throw memory_access_exception(); uint64_t xrd = res_11; super::template write_mem(traits::CSR, csr, (uint64_t)zimm); - if(this->core.reg.trap_state>=0x80000000UL) throw memory_access_exception(); + if(has_synchronous_exception()) throw memory_access_exception(); if(rd != 0) { *(X+rd) = xrd; } @@ -2212,11 +2218,11 @@ typename vm_base::virt_addr_t vm_impl::execute_inst(finish_cond_e co } else { uint64_t res_12 = super::template read_mem(traits::CSR, csr); - if(this->core.reg.trap_state>=0x80000000UL) throw memory_access_exception(); + if(has_synchronous_exception()) throw memory_access_exception(); uint64_t xrd = res_12; if(zimm != 0) { super::template write_mem(traits::CSR, csr, xrd | (uint64_t)zimm); - if(this->core.reg.trap_state>=0x80000000UL) throw memory_access_exception(); + if(has_synchronous_exception()) throw memory_access_exception(); } if(rd != 0) { *(X+rd) = xrd; @@ -2247,11 +2253,11 @@ typename vm_base::virt_addr_t vm_impl::execute_inst(finish_cond_e co } else { uint64_t res_13 = super::template read_mem(traits::CSR, csr); - if(this->core.reg.trap_state>=0x80000000UL) throw memory_access_exception(); + if(has_synchronous_exception()) throw memory_access_exception(); uint64_t xrd = res_13; if(zimm != 0) { super::template write_mem(traits::CSR, csr, xrd & ~((uint64_t)zimm)); - if(this->core.reg.trap_state>=0x80000000UL) throw memory_access_exception(); + if(has_synchronous_exception()) throw memory_access_exception(); } if(rd != 0) { *(X+rd) = xrd; @@ -2277,7 +2283,7 @@ typename vm_base::virt_addr_t vm_impl::execute_inst(finish_cond_e co // execute instruction { super::template write_mem(traits::FENCE, traits::fencei, imm); - if(this->core.reg.trap_state>=0x80000000UL) throw memory_access_exception(); + if(has_synchronous_exception()) throw memory_access_exception(); } break; }// @suppress("No break at end of case") @@ -2768,10 +2774,10 @@ typename vm_base::virt_addr_t vm_impl::execute_inst(finish_cond_e co if(rd != 0) { uint64_t offs = *(X+rs1); int32_t res_14 = super::template read_mem(traits::MEM, offs); - if(this->core.reg.trap_state>=0x80000000UL) throw memory_access_exception(); + if(has_synchronous_exception()) throw memory_access_exception(); *(X+rd) = (uint64_t)((int32_t)res_14); super::template write_mem(traits::RES, offs, (uint8_t)- 1); - if(this->core.reg.trap_state>=0x80000000UL) throw memory_access_exception(); + if(has_synchronous_exception()) throw memory_access_exception(); } } } @@ -2802,11 +2808,11 @@ typename vm_base::virt_addr_t vm_impl::execute_inst(finish_cond_e co else { uint64_t offs = *(X+rs1); uint8_t res_15 = super::template read_mem(traits::RES, offs); - if(this->core.reg.trap_state>=0x80000000UL) throw memory_access_exception(); + if(has_synchronous_exception()) throw memory_access_exception(); uint32_t res1 = res_15; if(res1 != 0) { super::template write_mem(traits::MEM, offs, (uint32_t)*(X+rs2)); - if(this->core.reg.trap_state>=0x80000000UL) throw memory_access_exception(); + if(has_synchronous_exception()) throw memory_access_exception(); } if(rd != 0) { *(X+rd) = res1? 0 : 1; @@ -2842,11 +2848,11 @@ typename vm_base::virt_addr_t vm_impl::execute_inst(finish_cond_e co uint64_t res = *(X+rs2); if(rd != 0) { int32_t res_16 = super::template read_mem(traits::MEM, offs); - if(this->core.reg.trap_state>=0x80000000UL) throw memory_access_exception(); + if(has_synchronous_exception()) throw memory_access_exception(); *(X+rd) = (uint64_t)((int32_t)res_16); } super::template write_mem(traits::MEM, offs, (uint32_t)res); - if(this->core.reg.trap_state>=0x80000000UL) throw memory_access_exception(); + if(has_synchronous_exception()) throw memory_access_exception(); } } break; @@ -2876,14 +2882,14 @@ typename vm_base::virt_addr_t vm_impl::execute_inst(finish_cond_e co else { uint64_t offs = *(X+rs1); int32_t res_17 = super::template read_mem(traits::MEM, offs); - if(this->core.reg.trap_state>=0x80000000UL) throw memory_access_exception(); + if(has_synchronous_exception()) throw memory_access_exception(); int32_t res1 = (int32_t)res_17; int64_t res2 = (int64_t)(res1) + (int64_t)((int32_t)*(X+rs2)); if(rd != 0) { *(X+rd) = (uint64_t)res1; } super::template write_mem(traits::MEM, offs, (uint32_t)res2); - if(this->core.reg.trap_state>=0x80000000UL) throw memory_access_exception(); + if(has_synchronous_exception()) throw memory_access_exception(); } } break; @@ -2913,14 +2919,14 @@ typename vm_base::virt_addr_t vm_impl::execute_inst(finish_cond_e co else { uint64_t offs = *(X+rs1); uint32_t res_18 = super::template read_mem(traits::MEM, offs); - if(this->core.reg.trap_state>=0x80000000UL) throw memory_access_exception(); + if(has_synchronous_exception()) throw memory_access_exception(); uint32_t res1 = res_18; uint32_t res2 = res1 ^ (uint32_t)*(X+rs2); if(rd != 0) { *(X+rd) = ((uint64_t)(int64_t)(int32_t)res1); } super::template write_mem(traits::MEM, offs, res2); - if(this->core.reg.trap_state>=0x80000000UL) throw memory_access_exception(); + if(has_synchronous_exception()) throw memory_access_exception(); } } break; @@ -2950,14 +2956,14 @@ typename vm_base::virt_addr_t vm_impl::execute_inst(finish_cond_e co else { uint64_t offs = *(X+rs1); uint32_t res_19 = super::template read_mem(traits::MEM, offs); - if(this->core.reg.trap_state>=0x80000000UL) throw memory_access_exception(); + if(has_synchronous_exception()) throw memory_access_exception(); uint32_t res1 = res_19; uint32_t res2 = res1 & (uint32_t)*(X+rs2); if(rd != 0) { *(X+rd) = ((uint64_t)(int64_t)(int32_t)res1); } super::template write_mem(traits::MEM, offs, res2); - if(this->core.reg.trap_state>=0x80000000UL) throw memory_access_exception(); + if(has_synchronous_exception()) throw memory_access_exception(); } } break; @@ -2987,14 +2993,14 @@ typename vm_base::virt_addr_t vm_impl::execute_inst(finish_cond_e co else { uint64_t offs = *(X+rs1); uint32_t res_20 = super::template read_mem(traits::MEM, offs); - if(this->core.reg.trap_state>=0x80000000UL) throw memory_access_exception(); + if(has_synchronous_exception()) throw memory_access_exception(); uint32_t res1 = res_20; uint32_t res2 = res1 | (uint32_t)*(X+rs2); if(rd != 0) { *(X+rd) = ((uint64_t)(int64_t)(int32_t)res1); } super::template write_mem(traits::MEM, offs, res2); - if(this->core.reg.trap_state>=0x80000000UL) throw memory_access_exception(); + if(has_synchronous_exception()) throw memory_access_exception(); } } break; @@ -3024,14 +3030,14 @@ typename vm_base::virt_addr_t vm_impl::execute_inst(finish_cond_e co else { uint64_t offs = *(X+rs1); int32_t res_21 = super::template read_mem(traits::MEM, offs); - if(this->core.reg.trap_state>=0x80000000UL) throw memory_access_exception(); + if(has_synchronous_exception()) throw memory_access_exception(); int32_t res1 = (int32_t)res_21; uint32_t res2 = res1 > (int32_t)*(X+rs2)? (uint32_t)*(X+rs2) : ((uint32_t)res1); if(rd != 0) { *(X+rd) = (uint64_t)res1; } super::template write_mem(traits::MEM, offs, res2); - if(this->core.reg.trap_state>=0x80000000UL) throw memory_access_exception(); + if(has_synchronous_exception()) throw memory_access_exception(); } } break; @@ -3061,14 +3067,14 @@ typename vm_base::virt_addr_t vm_impl::execute_inst(finish_cond_e co else { uint64_t offs = *(X+rs1); int32_t res_22 = super::template read_mem(traits::MEM, offs); - if(this->core.reg.trap_state>=0x80000000UL) throw memory_access_exception(); + if(has_synchronous_exception()) throw memory_access_exception(); int32_t res1 = (int32_t)res_22; uint32_t res2 = res1 < (int32_t)*(X+rs2)? (uint32_t)*(X+rs2) : ((uint32_t)res1); if(rd != 0) { *(X+rd) = (uint64_t)res1; } super::template write_mem(traits::MEM, offs, res2); - if(this->core.reg.trap_state>=0x80000000UL) throw memory_access_exception(); + if(has_synchronous_exception()) throw memory_access_exception(); } } break; @@ -3098,14 +3104,14 @@ typename vm_base::virt_addr_t vm_impl::execute_inst(finish_cond_e co else { uint64_t offs = *(X+rs1); uint32_t res_23 = super::template read_mem(traits::MEM, offs); - if(this->core.reg.trap_state>=0x80000000UL) throw memory_access_exception(); + if(has_synchronous_exception()) throw memory_access_exception(); uint32_t res1 = res_23; uint32_t res2 = res1 > (uint32_t)*(X+rs2)? (uint32_t)*(X+rs2) : res1; if(rd != 0) { *(X+rd) = ((uint64_t)(int64_t)(int32_t)res1); } super::template write_mem(traits::MEM, offs, res2); - if(this->core.reg.trap_state>=0x80000000UL) throw memory_access_exception(); + if(has_synchronous_exception()) throw memory_access_exception(); } } break; @@ -3135,14 +3141,14 @@ typename vm_base::virt_addr_t vm_impl::execute_inst(finish_cond_e co else { uint64_t offs = *(X+rs1); uint32_t res_24 = super::template read_mem(traits::MEM, offs); - if(this->core.reg.trap_state>=0x80000000UL) throw memory_access_exception(); + if(has_synchronous_exception()) throw memory_access_exception(); uint32_t res1 = res_24; uint32_t res2 = res1 < (int32_t)*(X+rs2)? (uint32_t)*(X+rs2) : res1; if(rd != 0) { *(X+rd) = ((uint64_t)(int64_t)(int32_t)res1); } super::template write_mem(traits::MEM, offs, res2); - if(this->core.reg.trap_state>=0x80000000UL) throw memory_access_exception(); + if(has_synchronous_exception()) throw memory_access_exception(); } } break; @@ -3172,10 +3178,10 @@ typename vm_base::virt_addr_t vm_impl::execute_inst(finish_cond_e co if(rd != 0) { uint64_t offs = *(X+rs1); int64_t res_25 = super::template read_mem(traits::MEM, offs); - if(this->core.reg.trap_state>=0x80000000UL) throw memory_access_exception(); + if(has_synchronous_exception()) throw memory_access_exception(); *(X+rd) = (uint64_t)((int64_t)res_25); super::template write_mem(traits::RES, offs, (uint8_t)- 1); - if(this->core.reg.trap_state>=0x80000000UL) throw memory_access_exception(); + if(has_synchronous_exception()) throw memory_access_exception(); } } } @@ -3206,11 +3212,11 @@ typename vm_base::virt_addr_t vm_impl::execute_inst(finish_cond_e co else { uint64_t offs = *(X+rs1); uint8_t res_26 = super::template read_mem(traits::RES, offs); - if(this->core.reg.trap_state>=0x80000000UL) throw memory_access_exception(); + if(has_synchronous_exception()) throw memory_access_exception(); uint64_t res = res_26; if(res != 0) { super::template write_mem(traits::MEM, offs, *(X+rs2)); - if(this->core.reg.trap_state>=0x80000000UL) throw memory_access_exception(); + if(has_synchronous_exception()) throw memory_access_exception(); } if(rd != 0) { *(X+rd) = res? 0 : 1; @@ -3246,11 +3252,11 @@ typename vm_base::virt_addr_t vm_impl::execute_inst(finish_cond_e co uint64_t res = *(X+rs2); if(rd != 0) { int64_t res_27 = super::template read_mem(traits::MEM, offs); - if(this->core.reg.trap_state>=0x80000000UL) throw memory_access_exception(); + if(has_synchronous_exception()) throw memory_access_exception(); *(X+rd) = (uint64_t)((int64_t)res_27); } super::template write_mem(traits::MEM, offs, (uint64_t)res); - if(this->core.reg.trap_state>=0x80000000UL) throw memory_access_exception(); + if(has_synchronous_exception()) throw memory_access_exception(); } } break; @@ -3280,14 +3286,14 @@ typename vm_base::virt_addr_t vm_impl::execute_inst(finish_cond_e co else { uint64_t offs = *(X+rs1); uint64_t res_28 = super::template read_mem(traits::MEM, offs); - if(this->core.reg.trap_state>=0x80000000UL) throw memory_access_exception(); + if(has_synchronous_exception()) throw memory_access_exception(); uint64_t res1 = res_28; uint64_t res2 = (uint64_t)((uint128_t)(res1) + (uint128_t)(*(X+rs2))); if(rd != 0) { *(X+rd) = (uint64_t)res1; } super::template write_mem(traits::MEM, offs, res2); - if(this->core.reg.trap_state>=0x80000000UL) throw memory_access_exception(); + if(has_synchronous_exception()) throw memory_access_exception(); } } break; @@ -3317,14 +3323,14 @@ typename vm_base::virt_addr_t vm_impl::execute_inst(finish_cond_e co else { uint64_t offs = *(X+rs1); uint64_t res_29 = super::template read_mem(traits::MEM, offs); - if(this->core.reg.trap_state>=0x80000000UL) throw memory_access_exception(); + if(has_synchronous_exception()) throw memory_access_exception(); uint64_t res1 = res_29; uint64_t res2 = res1 ^ *(X+rs2); if(rd != 0) { *(X+rd) = ((uint64_t)(int64_t)res1); } super::template write_mem(traits::MEM, offs, res2); - if(this->core.reg.trap_state>=0x80000000UL) throw memory_access_exception(); + if(has_synchronous_exception()) throw memory_access_exception(); } } break; @@ -3354,14 +3360,14 @@ typename vm_base::virt_addr_t vm_impl::execute_inst(finish_cond_e co else { uint64_t offs = *(X+rs1); uint64_t res_30 = super::template read_mem(traits::MEM, offs); - if(this->core.reg.trap_state>=0x80000000UL) throw memory_access_exception(); + if(has_synchronous_exception()) throw memory_access_exception(); uint64_t res1 = res_30; uint64_t res2 = res1 & *(X+rs2); if(rd != 0) { *(X+rd) = (uint64_t)res1; } super::template write_mem(traits::MEM, offs, res2); - if(this->core.reg.trap_state>=0x80000000UL) throw memory_access_exception(); + if(has_synchronous_exception()) throw memory_access_exception(); } } break; @@ -3391,14 +3397,14 @@ typename vm_base::virt_addr_t vm_impl::execute_inst(finish_cond_e co else { uint64_t offs = *(X+rs1); uint64_t res_31 = super::template read_mem(traits::MEM, offs); - if(this->core.reg.trap_state>=0x80000000UL) throw memory_access_exception(); + if(has_synchronous_exception()) throw memory_access_exception(); uint64_t res1 = res_31; uint64_t res2 = res1 | *(X+rs2); if(rd != 0) { *(X+rd) = (uint64_t)res1; } super::template write_mem(traits::MEM, offs, res2); - if(this->core.reg.trap_state>=0x80000000UL) throw memory_access_exception(); + if(has_synchronous_exception()) throw memory_access_exception(); } } break; @@ -3428,14 +3434,14 @@ typename vm_base::virt_addr_t vm_impl::execute_inst(finish_cond_e co else { uint64_t offs = *(X+rs1); int64_t res_32 = super::template read_mem(traits::MEM, offs); - if(this->core.reg.trap_state>=0x80000000UL) throw memory_access_exception(); + if(has_synchronous_exception()) throw memory_access_exception(); int64_t res1 = (int64_t)res_32; uint64_t res2 = res1 > (int64_t)*(X+rs2)? (uint64_t)*(X+rs2) : ((uint64_t)res1); if(rd != 0) { *(X+rd) = (uint64_t)res1; } super::template write_mem(traits::MEM, offs, res2); - if(this->core.reg.trap_state>=0x80000000UL) throw memory_access_exception(); + if(has_synchronous_exception()) throw memory_access_exception(); } } break; @@ -3465,14 +3471,14 @@ typename vm_base::virt_addr_t vm_impl::execute_inst(finish_cond_e co else { uint64_t offs = *(X+rs1); int64_t res_33 = super::template read_mem(traits::MEM, offs); - if(this->core.reg.trap_state>=0x80000000UL) throw memory_access_exception(); + if(has_synchronous_exception()) throw memory_access_exception(); int64_t res1 = (int64_t)res_33; uint64_t res2 = res1 < (int64_t)*(X+rs2)? (uint64_t)*(X+rs2) : ((uint64_t)res1); if(rd != 0) { *(X+rd) = (uint64_t)res1; } super::template write_mem(traits::MEM, offs, res2); - if(this->core.reg.trap_state>=0x80000000UL) throw memory_access_exception(); + if(has_synchronous_exception()) throw memory_access_exception(); } } break; @@ -3502,14 +3508,14 @@ typename vm_base::virt_addr_t vm_impl::execute_inst(finish_cond_e co else { uint64_t offs = *(X+rs1); uint64_t res_34 = super::template read_mem(traits::MEM, offs); - if(this->core.reg.trap_state>=0x80000000UL) throw memory_access_exception(); + if(has_synchronous_exception()) throw memory_access_exception(); uint64_t res1 = res_34; uint64_t res2 = res1 > *(X+rs2)? *(X+rs2) : res1; if(rd != 0) { *(X+rd) = (uint64_t)res1; } super::template write_mem(traits::MEM, offs, res2); - if(this->core.reg.trap_state>=0x80000000UL) throw memory_access_exception(); + if(has_synchronous_exception()) throw memory_access_exception(); } } break; @@ -3539,14 +3545,14 @@ typename vm_base::virt_addr_t vm_impl::execute_inst(finish_cond_e co else { uint64_t offs = *(X+rs1); uint64_t res_35 = super::template read_mem(traits::MEM, offs); - if(this->core.reg.trap_state>=0x80000000UL) throw memory_access_exception(); + if(has_synchronous_exception()) throw memory_access_exception(); uint64_t res1 = res_35; uint64_t res2 = res1 < *(X+rs2)? (uint64_t)*(X+rs2) : res1; if(rd != 0) { *(X+rd) = (uint64_t)res1; } super::template write_mem(traits::MEM, offs, res2); - if(this->core.reg.trap_state>=0x80000000UL) throw memory_access_exception(); + if(has_synchronous_exception()) throw memory_access_exception(); } } break; @@ -3595,7 +3601,7 @@ typename vm_base::virt_addr_t vm_impl::execute_inst(finish_cond_e co { uint64_t offs = (uint64_t)((uint128_t)(*(X+rs1 + 8)) + (uint128_t)(uimm)); int32_t res_36 = super::template read_mem(traits::MEM, offs); - if(this->core.reg.trap_state>=0x80000000UL) throw memory_access_exception(); + if(has_synchronous_exception()) throw memory_access_exception(); *(X+rd + 8) = (uint64_t)(int32_t)res_36; } break; @@ -3619,7 +3625,7 @@ typename vm_base::virt_addr_t vm_impl::execute_inst(finish_cond_e co { uint64_t offs = (uint64_t)((uint128_t)(*(X+rs1 + 8)) + (uint128_t)(uimm)); uint64_t res_37 = super::template read_mem(traits::MEM, offs); - if(this->core.reg.trap_state>=0x80000000UL) throw memory_access_exception(); + if(has_synchronous_exception()) throw memory_access_exception(); *(X+rd + 8) = (uint64_t)res_37; } break; @@ -3643,7 +3649,7 @@ typename vm_base::virt_addr_t vm_impl::execute_inst(finish_cond_e co { uint64_t offs = (uint64_t)((uint128_t)(*(X+rs1 + 8)) + (uint128_t)(uimm)); super::template write_mem(traits::MEM, offs, (uint32_t)*(X+rs2 + 8)); - if(this->core.reg.trap_state>=0x80000000UL) throw memory_access_exception(); + if(has_synchronous_exception()) throw memory_access_exception(); } break; }// @suppress("No break at end of case") @@ -3666,7 +3672,7 @@ typename vm_base::virt_addr_t vm_impl::execute_inst(finish_cond_e co { uint64_t offs = (uint64_t)((uint128_t)(*(X+rs1 + 8)) + (uint128_t)(uimm)); super::template write_mem(traits::MEM, offs, *(X+rs2 + 8)); - if(this->core.reg.trap_state>=0x80000000UL) throw memory_access_exception(); + if(has_synchronous_exception()) throw memory_access_exception(); } break; }// @suppress("No break at end of case") @@ -4132,7 +4138,7 @@ typename vm_base::virt_addr_t vm_impl::execute_inst(finish_cond_e co else { uint64_t offs = (uint64_t)((uint128_t)(*(X+2)) + (uint128_t)(uimm)); int32_t res_38 = super::template read_mem(traits::MEM, offs); - if(this->core.reg.trap_state>=0x80000000UL) throw memory_access_exception(); + if(has_synchronous_exception()) throw memory_access_exception(); *(X+rd) = (uint64_t)(int32_t)res_38; } } @@ -4160,7 +4166,7 @@ typename vm_base::virt_addr_t vm_impl::execute_inst(finish_cond_e co else { uint64_t offs = (uint64_t)((uint128_t)(*(X+2)) + (uint128_t)(uimm)); uint64_t res_39 = super::template read_mem(traits::MEM, offs); - if(this->core.reg.trap_state>=0x80000000UL) throw memory_access_exception(); + if(has_synchronous_exception()) throw memory_access_exception(); uint64_t res = (uint64_t)res_39; *(X+rd) = res; } @@ -4329,7 +4335,7 @@ typename vm_base::virt_addr_t vm_impl::execute_inst(finish_cond_e co else { uint64_t offs = (uint64_t)((uint128_t)(*(X+2)) + (uint128_t)(uimm)); super::template write_mem(traits::MEM, offs, (uint32_t)*(X+rs2)); - if(this->core.reg.trap_state>=0x80000000UL) throw memory_access_exception(); + if(has_synchronous_exception()) throw memory_access_exception(); } } break; @@ -4356,7 +4362,7 @@ typename vm_base::virt_addr_t vm_impl::execute_inst(finish_cond_e co else { uint64_t offs = (uint64_t)((uint128_t)(*(X+2)) + (uint128_t)(uimm)); super::template write_mem(traits::MEM, offs, (uint64_t)*(X+rs2)); - if(this->core.reg.trap_state>=0x80000000UL) throw memory_access_exception(); + if(has_synchronous_exception()) throw memory_access_exception(); } } break; @@ -4401,7 +4407,7 @@ typename vm_base::virt_addr_t vm_impl::execute_inst(finish_cond_e co else { uint64_t offs = (uint32_t)((uint128_t)(*(X+rs1)) + (int128_t)((int16_t)sext<12>(imm))); uint32_t res_40 = super::template read_mem(traits::MEM, offs); - if(this->core.reg.trap_state>=0x80000000UL) throw memory_access_exception(); + if(has_synchronous_exception()) throw memory_access_exception(); *(F+rd) = NaNBox32(res_40); } } @@ -4431,7 +4437,7 @@ typename vm_base::virt_addr_t vm_impl::execute_inst(finish_cond_e co else { uint64_t offs = (uint32_t)((uint128_t)(*(X+rs1)) + (int128_t)((int16_t)sext<12>(imm))); super::template write_mem(traits::MEM, offs, (uint32_t)*(F+rs2)); - if(this->core.reg.trap_state>=0x80000000UL) throw memory_access_exception(); + if(has_synchronous_exception()) throw memory_access_exception(); } } break; @@ -5233,7 +5239,7 @@ typename vm_base::virt_addr_t vm_impl::execute_inst(finish_cond_e co else { uint64_t offs = (uint64_t)((uint128_t)(*(X+rs1)) + (int128_t)((int16_t)sext<12>(imm))); uint64_t res_41 = super::template read_mem(traits::MEM, offs); - if(this->core.reg.trap_state>=0x80000000UL) throw memory_access_exception(); + if(has_synchronous_exception()) throw memory_access_exception(); *(F+rd) = NaNBox64(res_41); } } @@ -5263,7 +5269,7 @@ typename vm_base::virt_addr_t vm_impl::execute_inst(finish_cond_e co else { uint64_t offs = (uint64_t)((uint128_t)(*(X+rs1)) + (int128_t)((int16_t)sext<12>(imm))); super::template write_mem(traits::MEM, offs, (uint64_t)*(F+rs2)); - if(this->core.reg.trap_state>=0x80000000UL) throw memory_access_exception(); + if(has_synchronous_exception()) throw memory_access_exception(); } } break; @@ -6109,7 +6115,7 @@ typename vm_base::virt_addr_t vm_impl::execute_inst(finish_cond_e co { uint64_t offs = (uint64_t)((uint128_t)(*(X+rs1 + 8)) + (uint128_t)(uimm)); uint64_t res_42 = super::template read_mem(traits::MEM, offs); - if(this->core.reg.trap_state>=0x80000000UL) throw memory_access_exception(); + if(has_synchronous_exception()) throw memory_access_exception(); uint64_t res = (uint64_t)res_42; *(F+rd + 8) = NaNBox64(res); } @@ -6135,7 +6141,7 @@ typename vm_base::virt_addr_t vm_impl::execute_inst(finish_cond_e co { uint64_t offs = (uint64_t)((uint128_t)(*(X+rs1 + 8)) + (uint128_t)(uimm)); super::template write_mem(traits::MEM, offs, (uint64_t)*(F+rs2 + 8)); - if(this->core.reg.trap_state>=0x80000000UL) throw memory_access_exception(); + if(has_synchronous_exception()) throw memory_access_exception(); } break; }// @suppress("No break at end of case") @@ -6158,7 +6164,7 @@ typename vm_base::virt_addr_t vm_impl::execute_inst(finish_cond_e co { uint64_t offs = (uint64_t)((uint128_t)(*(X+2)) + (uint128_t)(uimm)); uint64_t res_43 = super::template read_mem(traits::MEM, offs); - if(this->core.reg.trap_state>=0x80000000UL) throw memory_access_exception(); + if(has_synchronous_exception()) throw memory_access_exception(); uint64_t res = (uint64_t)res_43; *(F+rd) = NaNBox64(res); } @@ -6183,7 +6189,7 @@ typename vm_base::virt_addr_t vm_impl::execute_inst(finish_cond_e co { uint64_t offs = (uint64_t)((uint128_t)(*(X+2)) + (uint128_t)(uimm)); super::template write_mem(traits::MEM, offs, (uint64_t)*(F+rs2)); - if(this->core.reg.trap_state>=0x80000000UL) throw memory_access_exception(); + if(has_synchronous_exception()) throw memory_access_exception(); } break; }// @suppress("No break at end of case") @@ -6203,7 +6209,7 @@ typename vm_base::virt_addr_t vm_impl::execute_inst(finish_cond_e co // execute instruction { super::template write_mem(traits::FENCE, traits::fencevma, ((uint16_t)(uint8_t)rs1<<8)|(uint8_t)asid); - if(this->core.reg.trap_state>=0x80000000UL) throw memory_access_exception(); + if(has_synchronous_exception()) throw memory_access_exception(); } break; }// @suppress("No break at end of case") diff --git a/src/vm/interp/vm_rv64gcv.cpp b/src/vm/interp/vm_rv64gcv.cpp index 46bbc4b..a26de43 100644 --- a/src/vm/interp/vm_rv64gcv.cpp +++ b/src/vm/interp/vm_rv64gcv.cpp @@ -238,6 +238,12 @@ template class vm_impl : public iss::interp::vm_base { inline void set_tval(uint64_t new_tval){ tval = new_tval; } + + inline bool has_synchronous_exception() const { + auto state = this->core.reg.trap_state; + return (state & 0x80000000ULL) != 0 && (state & 0xffffULL) == 0; + } + uint64_t fetch_count{0}; uint64_t tval{0}; @@ -1824,7 +1830,7 @@ typename vm_base::virt_addr_t vm_impl::execute_inst(finish_cond_e co else { uint64_t load_address = (uint64_t)((uint128_t)(*(X+rs1)) + (int128_t)((int16_t)sext<12>(imm))); int8_t res_1 = super::template read_mem(traits::MEM, load_address); - if(this->core.reg.trap_state>=0x80000000UL) throw memory_access_exception(); + if(has_synchronous_exception()) throw memory_access_exception(); int8_t res = (int8_t)res_1; if(rd != 0) { *(X+rd) = (uint64_t)res; @@ -1856,7 +1862,7 @@ typename vm_base::virt_addr_t vm_impl::execute_inst(finish_cond_e co else { uint64_t load_address = (uint64_t)((uint128_t)(*(X+rs1)) + (int128_t)((int16_t)sext<12>(imm))); int16_t res_2 = super::template read_mem(traits::MEM, load_address); - if(this->core.reg.trap_state>=0x80000000UL) throw memory_access_exception(); + if(has_synchronous_exception()) throw memory_access_exception(); int16_t res = (int16_t)res_2; if(rd != 0) { *(X+rd) = (uint64_t)res; @@ -1888,7 +1894,7 @@ typename vm_base::virt_addr_t vm_impl::execute_inst(finish_cond_e co else { uint64_t load_address = (uint64_t)((uint128_t)(*(X+rs1)) + (int128_t)((int16_t)sext<12>(imm))); int32_t res_3 = super::template read_mem(traits::MEM, load_address); - if(this->core.reg.trap_state>=0x80000000UL) throw memory_access_exception(); + if(has_synchronous_exception()) throw memory_access_exception(); int32_t res = (int32_t)res_3; if(rd != 0) { *(X+rd) = (uint64_t)res; @@ -1920,7 +1926,7 @@ typename vm_base::virt_addr_t vm_impl::execute_inst(finish_cond_e co else { uint64_t load_address = (uint64_t)((uint128_t)(*(X+rs1)) + (int128_t)((int16_t)sext<12>(imm))); uint8_t res_4 = super::template read_mem(traits::MEM, load_address); - if(this->core.reg.trap_state>=0x80000000UL) throw memory_access_exception(); + if(has_synchronous_exception()) throw memory_access_exception(); uint8_t res = res_4; if(rd != 0) { *(X+rd) = (uint64_t)res; @@ -1952,7 +1958,7 @@ typename vm_base::virt_addr_t vm_impl::execute_inst(finish_cond_e co else { uint64_t load_address = (uint64_t)((uint128_t)(*(X+rs1)) + (int128_t)((int16_t)sext<12>(imm))); uint16_t res_5 = super::template read_mem(traits::MEM, load_address); - if(this->core.reg.trap_state>=0x80000000UL) throw memory_access_exception(); + if(has_synchronous_exception()) throw memory_access_exception(); uint16_t res = res_5; if(rd != 0) { *(X+rd) = (uint64_t)res; @@ -1984,7 +1990,7 @@ typename vm_base::virt_addr_t vm_impl::execute_inst(finish_cond_e co else { uint64_t store_address = (uint64_t)((uint128_t)(*(X+rs1)) + (int128_t)((int16_t)sext<12>(imm))); super::template write_mem(traits::MEM, store_address, (uint8_t)*(X+rs2)); - if(this->core.reg.trap_state>=0x80000000UL) throw memory_access_exception(); + if(has_synchronous_exception()) throw memory_access_exception(); } } break; @@ -2012,7 +2018,7 @@ typename vm_base::virt_addr_t vm_impl::execute_inst(finish_cond_e co else { uint64_t store_address = (uint64_t)((uint128_t)(*(X+rs1)) + (int128_t)((int16_t)sext<12>(imm))); super::template write_mem(traits::MEM, store_address, (uint16_t)*(X+rs2)); - if(this->core.reg.trap_state>=0x80000000UL) throw memory_access_exception(); + if(has_synchronous_exception()) throw memory_access_exception(); } } break; @@ -2040,7 +2046,7 @@ typename vm_base::virt_addr_t vm_impl::execute_inst(finish_cond_e co else { uint64_t store_address = (uint64_t)((uint128_t)(*(X+rs1)) + (int128_t)((int16_t)sext<12>(imm))); super::template write_mem(traits::MEM, store_address, (uint32_t)*(X+rs2)); - if(this->core.reg.trap_state>=0x80000000UL) throw memory_access_exception(); + if(has_synchronous_exception()) throw memory_access_exception(); } } break; @@ -2596,7 +2602,7 @@ typename vm_base::virt_addr_t vm_impl::execute_inst(finish_cond_e co // execute instruction { super::template write_mem(traits::FENCE, traits::fence, (uint8_t)pred << 4 | succ); - if(this->core.reg.trap_state>=0x80000000UL) throw memory_access_exception(); + if(has_synchronous_exception()) throw memory_access_exception(); } break; }// @suppress("No break at end of case") @@ -2687,7 +2693,7 @@ typename vm_base::virt_addr_t vm_impl::execute_inst(finish_cond_e co else { uint64_t offs = (uint64_t)((uint128_t)(*(X+rs1)) + (int128_t)((int16_t)sext<12>(imm))); uint32_t res_6 = super::template read_mem(traits::MEM, offs); - if(this->core.reg.trap_state>=0x80000000UL) throw memory_access_exception(); + if(has_synchronous_exception()) throw memory_access_exception(); uint32_t res = (uint32_t)res_6; if(rd != 0) { *(X+rd) = (uint64_t)res; @@ -2719,7 +2725,7 @@ typename vm_base::virt_addr_t vm_impl::execute_inst(finish_cond_e co else { uint64_t offs = (uint64_t)((uint128_t)(*(X+rs1)) + (int128_t)((int16_t)sext<12>(imm))); int64_t res_7 = super::template read_mem(traits::MEM, offs); - if(this->core.reg.trap_state>=0x80000000UL) throw memory_access_exception(); + if(has_synchronous_exception()) throw memory_access_exception(); int64_t res = (int64_t)res_7; if(rd != 0) { *(X+rd) = (uint64_t)res; @@ -2751,7 +2757,7 @@ typename vm_base::virt_addr_t vm_impl::execute_inst(finish_cond_e co else { uint64_t offs = (uint64_t)((uint128_t)(*(X+rs1)) + (int128_t)((int16_t)sext<12>(imm))); super::template write_mem(traits::MEM, offs, (uint64_t)*(X+rs2)); - if(this->core.reg.trap_state>=0x80000000UL) throw memory_access_exception(); + if(has_synchronous_exception()) throw memory_access_exception(); } } break; @@ -3042,15 +3048,15 @@ typename vm_base::virt_addr_t vm_impl::execute_inst(finish_cond_e co uint64_t xrs1 = *(X+rs1); if(rd != 0) { uint64_t res_8 = super::template read_mem(traits::CSR, csr); - if(this->core.reg.trap_state>=0x80000000UL) throw memory_access_exception(); + if(has_synchronous_exception()) throw memory_access_exception(); uint64_t xrd = res_8; super::template write_mem(traits::CSR, csr, xrs1); - if(this->core.reg.trap_state>=0x80000000UL) throw memory_access_exception(); + if(has_synchronous_exception()) throw memory_access_exception(); *(X+rd) = xrd; } else { super::template write_mem(traits::CSR, csr, xrs1); - if(this->core.reg.trap_state>=0x80000000UL) throw memory_access_exception(); + if(has_synchronous_exception()) throw memory_access_exception(); } } } @@ -3078,12 +3084,12 @@ typename vm_base::virt_addr_t vm_impl::execute_inst(finish_cond_e co } else { uint64_t res_9 = super::template read_mem(traits::CSR, csr); - if(this->core.reg.trap_state>=0x80000000UL) throw memory_access_exception(); + if(has_synchronous_exception()) throw memory_access_exception(); uint64_t xrd = res_9; uint64_t xrs1 = *(X+rs1); if(rs1 != 0) { super::template write_mem(traits::CSR, csr, xrd | xrs1); - if(this->core.reg.trap_state>=0x80000000UL) throw memory_access_exception(); + if(has_synchronous_exception()) throw memory_access_exception(); } if(rd != 0) { *(X+rd) = xrd; @@ -3114,12 +3120,12 @@ typename vm_base::virt_addr_t vm_impl::execute_inst(finish_cond_e co } else { uint64_t res_10 = super::template read_mem(traits::CSR, csr); - if(this->core.reg.trap_state>=0x80000000UL) throw memory_access_exception(); + if(has_synchronous_exception()) throw memory_access_exception(); uint64_t xrd = res_10; uint64_t xrs1 = *(X+rs1); if(rs1 != 0) { super::template write_mem(traits::CSR, csr, xrd & ~xrs1); - if(this->core.reg.trap_state>=0x80000000UL) throw memory_access_exception(); + if(has_synchronous_exception()) throw memory_access_exception(); } if(rd != 0) { *(X+rd) = xrd; @@ -3150,10 +3156,10 @@ typename vm_base::virt_addr_t vm_impl::execute_inst(finish_cond_e co } else { uint64_t res_11 = super::template read_mem(traits::CSR, csr); - if(this->core.reg.trap_state>=0x80000000UL) throw memory_access_exception(); + if(has_synchronous_exception()) throw memory_access_exception(); uint64_t xrd = res_11; super::template write_mem(traits::CSR, csr, (uint64_t)zimm); - if(this->core.reg.trap_state>=0x80000000UL) throw memory_access_exception(); + if(has_synchronous_exception()) throw memory_access_exception(); if(rd != 0) { *(X+rd) = xrd; } @@ -3183,11 +3189,11 @@ typename vm_base::virt_addr_t vm_impl::execute_inst(finish_cond_e co } else { uint64_t res_12 = super::template read_mem(traits::CSR, csr); - if(this->core.reg.trap_state>=0x80000000UL) throw memory_access_exception(); + if(has_synchronous_exception()) throw memory_access_exception(); uint64_t xrd = res_12; if(zimm != 0) { super::template write_mem(traits::CSR, csr, xrd | (uint64_t)zimm); - if(this->core.reg.trap_state>=0x80000000UL) throw memory_access_exception(); + if(has_synchronous_exception()) throw memory_access_exception(); } if(rd != 0) { *(X+rd) = xrd; @@ -3218,11 +3224,11 @@ typename vm_base::virt_addr_t vm_impl::execute_inst(finish_cond_e co } else { uint64_t res_13 = super::template read_mem(traits::CSR, csr); - if(this->core.reg.trap_state>=0x80000000UL) throw memory_access_exception(); + if(has_synchronous_exception()) throw memory_access_exception(); uint64_t xrd = res_13; if(zimm != 0) { super::template write_mem(traits::CSR, csr, xrd & ~((uint64_t)zimm)); - if(this->core.reg.trap_state>=0x80000000UL) throw memory_access_exception(); + if(has_synchronous_exception()) throw memory_access_exception(); } if(rd != 0) { *(X+rd) = xrd; @@ -3248,7 +3254,7 @@ typename vm_base::virt_addr_t vm_impl::execute_inst(finish_cond_e co // execute instruction { super::template write_mem(traits::FENCE, traits::fencei, imm); - if(this->core.reg.trap_state>=0x80000000UL) throw memory_access_exception(); + if(has_synchronous_exception()) throw memory_access_exception(); } break; }// @suppress("No break at end of case") @@ -3739,10 +3745,10 @@ typename vm_base::virt_addr_t vm_impl::execute_inst(finish_cond_e co if(rd != 0) { uint64_t offs = *(X+rs1); int32_t res_14 = super::template read_mem(traits::MEM, offs); - if(this->core.reg.trap_state>=0x80000000UL) throw memory_access_exception(); + if(has_synchronous_exception()) throw memory_access_exception(); *(X+rd) = (uint64_t)((int32_t)res_14); super::template write_mem(traits::RES, offs, (uint8_t)- 1); - if(this->core.reg.trap_state>=0x80000000UL) throw memory_access_exception(); + if(has_synchronous_exception()) throw memory_access_exception(); } } } @@ -3773,11 +3779,11 @@ typename vm_base::virt_addr_t vm_impl::execute_inst(finish_cond_e co else { uint64_t offs = *(X+rs1); uint8_t res_15 = super::template read_mem(traits::RES, offs); - if(this->core.reg.trap_state>=0x80000000UL) throw memory_access_exception(); + if(has_synchronous_exception()) throw memory_access_exception(); uint32_t res1 = res_15; if(res1 != 0) { super::template write_mem(traits::MEM, offs, (uint32_t)*(X+rs2)); - if(this->core.reg.trap_state>=0x80000000UL) throw memory_access_exception(); + if(has_synchronous_exception()) throw memory_access_exception(); } if(rd != 0) { *(X+rd) = res1? 0 : 1; @@ -3813,11 +3819,11 @@ typename vm_base::virt_addr_t vm_impl::execute_inst(finish_cond_e co uint64_t res = *(X+rs2); if(rd != 0) { int32_t res_16 = super::template read_mem(traits::MEM, offs); - if(this->core.reg.trap_state>=0x80000000UL) throw memory_access_exception(); + if(has_synchronous_exception()) throw memory_access_exception(); *(X+rd) = (uint64_t)((int32_t)res_16); } super::template write_mem(traits::MEM, offs, (uint32_t)res); - if(this->core.reg.trap_state>=0x80000000UL) throw memory_access_exception(); + if(has_synchronous_exception()) throw memory_access_exception(); } } break; @@ -3847,14 +3853,14 @@ typename vm_base::virt_addr_t vm_impl::execute_inst(finish_cond_e co else { uint64_t offs = *(X+rs1); int32_t res_17 = super::template read_mem(traits::MEM, offs); - if(this->core.reg.trap_state>=0x80000000UL) throw memory_access_exception(); + if(has_synchronous_exception()) throw memory_access_exception(); int32_t res1 = (int32_t)res_17; int64_t res2 = (int64_t)(res1) + (int64_t)((int32_t)*(X+rs2)); if(rd != 0) { *(X+rd) = (uint64_t)res1; } super::template write_mem(traits::MEM, offs, (uint32_t)res2); - if(this->core.reg.trap_state>=0x80000000UL) throw memory_access_exception(); + if(has_synchronous_exception()) throw memory_access_exception(); } } break; @@ -3884,14 +3890,14 @@ typename vm_base::virt_addr_t vm_impl::execute_inst(finish_cond_e co else { uint64_t offs = *(X+rs1); uint32_t res_18 = super::template read_mem(traits::MEM, offs); - if(this->core.reg.trap_state>=0x80000000UL) throw memory_access_exception(); + if(has_synchronous_exception()) throw memory_access_exception(); uint32_t res1 = res_18; uint32_t res2 = res1 ^ (uint32_t)*(X+rs2); if(rd != 0) { *(X+rd) = ((uint64_t)(int64_t)(int32_t)res1); } super::template write_mem(traits::MEM, offs, res2); - if(this->core.reg.trap_state>=0x80000000UL) throw memory_access_exception(); + if(has_synchronous_exception()) throw memory_access_exception(); } } break; @@ -3921,14 +3927,14 @@ typename vm_base::virt_addr_t vm_impl::execute_inst(finish_cond_e co else { uint64_t offs = *(X+rs1); uint32_t res_19 = super::template read_mem(traits::MEM, offs); - if(this->core.reg.trap_state>=0x80000000UL) throw memory_access_exception(); + if(has_synchronous_exception()) throw memory_access_exception(); uint32_t res1 = res_19; uint32_t res2 = res1 & (uint32_t)*(X+rs2); if(rd != 0) { *(X+rd) = ((uint64_t)(int64_t)(int32_t)res1); } super::template write_mem(traits::MEM, offs, res2); - if(this->core.reg.trap_state>=0x80000000UL) throw memory_access_exception(); + if(has_synchronous_exception()) throw memory_access_exception(); } } break; @@ -3958,14 +3964,14 @@ typename vm_base::virt_addr_t vm_impl::execute_inst(finish_cond_e co else { uint64_t offs = *(X+rs1); uint32_t res_20 = super::template read_mem(traits::MEM, offs); - if(this->core.reg.trap_state>=0x80000000UL) throw memory_access_exception(); + if(has_synchronous_exception()) throw memory_access_exception(); uint32_t res1 = res_20; uint32_t res2 = res1 | (uint32_t)*(X+rs2); if(rd != 0) { *(X+rd) = ((uint64_t)(int64_t)(int32_t)res1); } super::template write_mem(traits::MEM, offs, res2); - if(this->core.reg.trap_state>=0x80000000UL) throw memory_access_exception(); + if(has_synchronous_exception()) throw memory_access_exception(); } } break; @@ -3995,14 +4001,14 @@ typename vm_base::virt_addr_t vm_impl::execute_inst(finish_cond_e co else { uint64_t offs = *(X+rs1); int32_t res_21 = super::template read_mem(traits::MEM, offs); - if(this->core.reg.trap_state>=0x80000000UL) throw memory_access_exception(); + if(has_synchronous_exception()) throw memory_access_exception(); int32_t res1 = (int32_t)res_21; uint32_t res2 = res1 > (int32_t)*(X+rs2)? (uint32_t)*(X+rs2) : ((uint32_t)res1); if(rd != 0) { *(X+rd) = (uint64_t)res1; } super::template write_mem(traits::MEM, offs, res2); - if(this->core.reg.trap_state>=0x80000000UL) throw memory_access_exception(); + if(has_synchronous_exception()) throw memory_access_exception(); } } break; @@ -4032,14 +4038,14 @@ typename vm_base::virt_addr_t vm_impl::execute_inst(finish_cond_e co else { uint64_t offs = *(X+rs1); int32_t res_22 = super::template read_mem(traits::MEM, offs); - if(this->core.reg.trap_state>=0x80000000UL) throw memory_access_exception(); + if(has_synchronous_exception()) throw memory_access_exception(); int32_t res1 = (int32_t)res_22; uint32_t res2 = res1 < (int32_t)*(X+rs2)? (uint32_t)*(X+rs2) : ((uint32_t)res1); if(rd != 0) { *(X+rd) = (uint64_t)res1; } super::template write_mem(traits::MEM, offs, res2); - if(this->core.reg.trap_state>=0x80000000UL) throw memory_access_exception(); + if(has_synchronous_exception()) throw memory_access_exception(); } } break; @@ -4069,14 +4075,14 @@ typename vm_base::virt_addr_t vm_impl::execute_inst(finish_cond_e co else { uint64_t offs = *(X+rs1); uint32_t res_23 = super::template read_mem(traits::MEM, offs); - if(this->core.reg.trap_state>=0x80000000UL) throw memory_access_exception(); + if(has_synchronous_exception()) throw memory_access_exception(); uint32_t res1 = res_23; uint32_t res2 = res1 > (uint32_t)*(X+rs2)? (uint32_t)*(X+rs2) : res1; if(rd != 0) { *(X+rd) = ((uint64_t)(int64_t)(int32_t)res1); } super::template write_mem(traits::MEM, offs, res2); - if(this->core.reg.trap_state>=0x80000000UL) throw memory_access_exception(); + if(has_synchronous_exception()) throw memory_access_exception(); } } break; @@ -4106,14 +4112,14 @@ typename vm_base::virt_addr_t vm_impl::execute_inst(finish_cond_e co else { uint64_t offs = *(X+rs1); uint32_t res_24 = super::template read_mem(traits::MEM, offs); - if(this->core.reg.trap_state>=0x80000000UL) throw memory_access_exception(); + if(has_synchronous_exception()) throw memory_access_exception(); uint32_t res1 = res_24; uint32_t res2 = res1 < (int32_t)*(X+rs2)? (uint32_t)*(X+rs2) : res1; if(rd != 0) { *(X+rd) = ((uint64_t)(int64_t)(int32_t)res1); } super::template write_mem(traits::MEM, offs, res2); - if(this->core.reg.trap_state>=0x80000000UL) throw memory_access_exception(); + if(has_synchronous_exception()) throw memory_access_exception(); } } break; @@ -4143,10 +4149,10 @@ typename vm_base::virt_addr_t vm_impl::execute_inst(finish_cond_e co if(rd != 0) { uint64_t offs = *(X+rs1); int64_t res_25 = super::template read_mem(traits::MEM, offs); - if(this->core.reg.trap_state>=0x80000000UL) throw memory_access_exception(); + if(has_synchronous_exception()) throw memory_access_exception(); *(X+rd) = (uint64_t)((int64_t)res_25); super::template write_mem(traits::RES, offs, (uint8_t)- 1); - if(this->core.reg.trap_state>=0x80000000UL) throw memory_access_exception(); + if(has_synchronous_exception()) throw memory_access_exception(); } } } @@ -4177,11 +4183,11 @@ typename vm_base::virt_addr_t vm_impl::execute_inst(finish_cond_e co else { uint64_t offs = *(X+rs1); uint8_t res_26 = super::template read_mem(traits::RES, offs); - if(this->core.reg.trap_state>=0x80000000UL) throw memory_access_exception(); + if(has_synchronous_exception()) throw memory_access_exception(); uint64_t res = res_26; if(res != 0) { super::template write_mem(traits::MEM, offs, *(X+rs2)); - if(this->core.reg.trap_state>=0x80000000UL) throw memory_access_exception(); + if(has_synchronous_exception()) throw memory_access_exception(); } if(rd != 0) { *(X+rd) = res? 0 : 1; @@ -4217,11 +4223,11 @@ typename vm_base::virt_addr_t vm_impl::execute_inst(finish_cond_e co uint64_t res = *(X+rs2); if(rd != 0) { int64_t res_27 = super::template read_mem(traits::MEM, offs); - if(this->core.reg.trap_state>=0x80000000UL) throw memory_access_exception(); + if(has_synchronous_exception()) throw memory_access_exception(); *(X+rd) = (uint64_t)((int64_t)res_27); } super::template write_mem(traits::MEM, offs, (uint64_t)res); - if(this->core.reg.trap_state>=0x80000000UL) throw memory_access_exception(); + if(has_synchronous_exception()) throw memory_access_exception(); } } break; @@ -4251,14 +4257,14 @@ typename vm_base::virt_addr_t vm_impl::execute_inst(finish_cond_e co else { uint64_t offs = *(X+rs1); uint64_t res_28 = super::template read_mem(traits::MEM, offs); - if(this->core.reg.trap_state>=0x80000000UL) throw memory_access_exception(); + if(has_synchronous_exception()) throw memory_access_exception(); uint64_t res1 = res_28; uint64_t res2 = (uint64_t)((uint128_t)(res1) + (uint128_t)(*(X+rs2))); if(rd != 0) { *(X+rd) = (uint64_t)res1; } super::template write_mem(traits::MEM, offs, res2); - if(this->core.reg.trap_state>=0x80000000UL) throw memory_access_exception(); + if(has_synchronous_exception()) throw memory_access_exception(); } } break; @@ -4288,14 +4294,14 @@ typename vm_base::virt_addr_t vm_impl::execute_inst(finish_cond_e co else { uint64_t offs = *(X+rs1); uint64_t res_29 = super::template read_mem(traits::MEM, offs); - if(this->core.reg.trap_state>=0x80000000UL) throw memory_access_exception(); + if(has_synchronous_exception()) throw memory_access_exception(); uint64_t res1 = res_29; uint64_t res2 = res1 ^ *(X+rs2); if(rd != 0) { *(X+rd) = ((uint64_t)(int64_t)res1); } super::template write_mem(traits::MEM, offs, res2); - if(this->core.reg.trap_state>=0x80000000UL) throw memory_access_exception(); + if(has_synchronous_exception()) throw memory_access_exception(); } } break; @@ -4325,14 +4331,14 @@ typename vm_base::virt_addr_t vm_impl::execute_inst(finish_cond_e co else { uint64_t offs = *(X+rs1); uint64_t res_30 = super::template read_mem(traits::MEM, offs); - if(this->core.reg.trap_state>=0x80000000UL) throw memory_access_exception(); + if(has_synchronous_exception()) throw memory_access_exception(); uint64_t res1 = res_30; uint64_t res2 = res1 & *(X+rs2); if(rd != 0) { *(X+rd) = (uint64_t)res1; } super::template write_mem(traits::MEM, offs, res2); - if(this->core.reg.trap_state>=0x80000000UL) throw memory_access_exception(); + if(has_synchronous_exception()) throw memory_access_exception(); } } break; @@ -4362,14 +4368,14 @@ typename vm_base::virt_addr_t vm_impl::execute_inst(finish_cond_e co else { uint64_t offs = *(X+rs1); uint64_t res_31 = super::template read_mem(traits::MEM, offs); - if(this->core.reg.trap_state>=0x80000000UL) throw memory_access_exception(); + if(has_synchronous_exception()) throw memory_access_exception(); uint64_t res1 = res_31; uint64_t res2 = res1 | *(X+rs2); if(rd != 0) { *(X+rd) = (uint64_t)res1; } super::template write_mem(traits::MEM, offs, res2); - if(this->core.reg.trap_state>=0x80000000UL) throw memory_access_exception(); + if(has_synchronous_exception()) throw memory_access_exception(); } } break; @@ -4399,14 +4405,14 @@ typename vm_base::virt_addr_t vm_impl::execute_inst(finish_cond_e co else { uint64_t offs = *(X+rs1); int64_t res_32 = super::template read_mem(traits::MEM, offs); - if(this->core.reg.trap_state>=0x80000000UL) throw memory_access_exception(); + if(has_synchronous_exception()) throw memory_access_exception(); int64_t res1 = (int64_t)res_32; uint64_t res2 = res1 > (int64_t)*(X+rs2)? (uint64_t)*(X+rs2) : ((uint64_t)res1); if(rd != 0) { *(X+rd) = (uint64_t)res1; } super::template write_mem(traits::MEM, offs, res2); - if(this->core.reg.trap_state>=0x80000000UL) throw memory_access_exception(); + if(has_synchronous_exception()) throw memory_access_exception(); } } break; @@ -4436,14 +4442,14 @@ typename vm_base::virt_addr_t vm_impl::execute_inst(finish_cond_e co else { uint64_t offs = *(X+rs1); int64_t res_33 = super::template read_mem(traits::MEM, offs); - if(this->core.reg.trap_state>=0x80000000UL) throw memory_access_exception(); + if(has_synchronous_exception()) throw memory_access_exception(); int64_t res1 = (int64_t)res_33; uint64_t res2 = res1 < (int64_t)*(X+rs2)? (uint64_t)*(X+rs2) : ((uint64_t)res1); if(rd != 0) { *(X+rd) = (uint64_t)res1; } super::template write_mem(traits::MEM, offs, res2); - if(this->core.reg.trap_state>=0x80000000UL) throw memory_access_exception(); + if(has_synchronous_exception()) throw memory_access_exception(); } } break; @@ -4473,14 +4479,14 @@ typename vm_base::virt_addr_t vm_impl::execute_inst(finish_cond_e co else { uint64_t offs = *(X+rs1); uint64_t res_34 = super::template read_mem(traits::MEM, offs); - if(this->core.reg.trap_state>=0x80000000UL) throw memory_access_exception(); + if(has_synchronous_exception()) throw memory_access_exception(); uint64_t res1 = res_34; uint64_t res2 = res1 > *(X+rs2)? *(X+rs2) : res1; if(rd != 0) { *(X+rd) = (uint64_t)res1; } super::template write_mem(traits::MEM, offs, res2); - if(this->core.reg.trap_state>=0x80000000UL) throw memory_access_exception(); + if(has_synchronous_exception()) throw memory_access_exception(); } } break; @@ -4510,14 +4516,14 @@ typename vm_base::virt_addr_t vm_impl::execute_inst(finish_cond_e co else { uint64_t offs = *(X+rs1); uint64_t res_35 = super::template read_mem(traits::MEM, offs); - if(this->core.reg.trap_state>=0x80000000UL) throw memory_access_exception(); + if(has_synchronous_exception()) throw memory_access_exception(); uint64_t res1 = res_35; uint64_t res2 = res1 < *(X+rs2)? (uint64_t)*(X+rs2) : res1; if(rd != 0) { *(X+rd) = (uint64_t)res1; } super::template write_mem(traits::MEM, offs, res2); - if(this->core.reg.trap_state>=0x80000000UL) throw memory_access_exception(); + if(has_synchronous_exception()) throw memory_access_exception(); } } break; @@ -4566,7 +4572,7 @@ typename vm_base::virt_addr_t vm_impl::execute_inst(finish_cond_e co { uint64_t offs = (uint64_t)((uint128_t)(*(X+rs1 + 8)) + (uint128_t)(uimm)); int32_t res_36 = super::template read_mem(traits::MEM, offs); - if(this->core.reg.trap_state>=0x80000000UL) throw memory_access_exception(); + if(has_synchronous_exception()) throw memory_access_exception(); *(X+rd + 8) = (uint64_t)(int32_t)res_36; } break; @@ -4590,7 +4596,7 @@ typename vm_base::virt_addr_t vm_impl::execute_inst(finish_cond_e co { uint64_t offs = (uint64_t)((uint128_t)(*(X+rs1 + 8)) + (uint128_t)(uimm)); uint64_t res_37 = super::template read_mem(traits::MEM, offs); - if(this->core.reg.trap_state>=0x80000000UL) throw memory_access_exception(); + if(has_synchronous_exception()) throw memory_access_exception(); *(X+rd + 8) = (uint64_t)res_37; } break; @@ -4614,7 +4620,7 @@ typename vm_base::virt_addr_t vm_impl::execute_inst(finish_cond_e co { uint64_t offs = (uint64_t)((uint128_t)(*(X+rs1 + 8)) + (uint128_t)(uimm)); super::template write_mem(traits::MEM, offs, (uint32_t)*(X+rs2 + 8)); - if(this->core.reg.trap_state>=0x80000000UL) throw memory_access_exception(); + if(has_synchronous_exception()) throw memory_access_exception(); } break; }// @suppress("No break at end of case") @@ -4637,7 +4643,7 @@ typename vm_base::virt_addr_t vm_impl::execute_inst(finish_cond_e co { uint64_t offs = (uint64_t)((uint128_t)(*(X+rs1 + 8)) + (uint128_t)(uimm)); super::template write_mem(traits::MEM, offs, *(X+rs2 + 8)); - if(this->core.reg.trap_state>=0x80000000UL) throw memory_access_exception(); + if(has_synchronous_exception()) throw memory_access_exception(); } break; }// @suppress("No break at end of case") @@ -5103,7 +5109,7 @@ typename vm_base::virt_addr_t vm_impl::execute_inst(finish_cond_e co else { uint64_t offs = (uint64_t)((uint128_t)(*(X+2)) + (uint128_t)(uimm)); int32_t res_38 = super::template read_mem(traits::MEM, offs); - if(this->core.reg.trap_state>=0x80000000UL) throw memory_access_exception(); + if(has_synchronous_exception()) throw memory_access_exception(); *(X+rd) = (uint64_t)(int32_t)res_38; } } @@ -5131,7 +5137,7 @@ typename vm_base::virt_addr_t vm_impl::execute_inst(finish_cond_e co else { uint64_t offs = (uint64_t)((uint128_t)(*(X+2)) + (uint128_t)(uimm)); uint64_t res_39 = super::template read_mem(traits::MEM, offs); - if(this->core.reg.trap_state>=0x80000000UL) throw memory_access_exception(); + if(has_synchronous_exception()) throw memory_access_exception(); uint64_t res = (uint64_t)res_39; *(X+rd) = res; } @@ -5300,7 +5306,7 @@ typename vm_base::virt_addr_t vm_impl::execute_inst(finish_cond_e co else { uint64_t offs = (uint64_t)((uint128_t)(*(X+2)) + (uint128_t)(uimm)); super::template write_mem(traits::MEM, offs, (uint32_t)*(X+rs2)); - if(this->core.reg.trap_state>=0x80000000UL) throw memory_access_exception(); + if(has_synchronous_exception()) throw memory_access_exception(); } } break; @@ -5327,7 +5333,7 @@ typename vm_base::virt_addr_t vm_impl::execute_inst(finish_cond_e co else { uint64_t offs = (uint64_t)((uint128_t)(*(X+2)) + (uint128_t)(uimm)); super::template write_mem(traits::MEM, offs, (uint64_t)*(X+rs2)); - if(this->core.reg.trap_state>=0x80000000UL) throw memory_access_exception(); + if(has_synchronous_exception()) throw memory_access_exception(); } } break; @@ -5372,7 +5378,7 @@ typename vm_base::virt_addr_t vm_impl::execute_inst(finish_cond_e co else { uint64_t offs = (uint32_t)((uint128_t)(*(X+rs1)) + (int128_t)((int16_t)sext<12>(imm))); uint32_t res_40 = super::template read_mem(traits::MEM, offs); - if(this->core.reg.trap_state>=0x80000000UL) throw memory_access_exception(); + if(has_synchronous_exception()) throw memory_access_exception(); *(F+rd) = NaNBox32(res_40); } } @@ -5402,7 +5408,7 @@ typename vm_base::virt_addr_t vm_impl::execute_inst(finish_cond_e co else { uint64_t offs = (uint32_t)((uint128_t)(*(X+rs1)) + (int128_t)((int16_t)sext<12>(imm))); super::template write_mem(traits::MEM, offs, (uint32_t)*(F+rs2)); - if(this->core.reg.trap_state>=0x80000000UL) throw memory_access_exception(); + if(has_synchronous_exception()) throw memory_access_exception(); } } break; @@ -6204,7 +6210,7 @@ typename vm_base::virt_addr_t vm_impl::execute_inst(finish_cond_e co else { uint64_t offs = (uint64_t)((uint128_t)(*(X+rs1)) + (int128_t)((int16_t)sext<12>(imm))); uint64_t res_41 = super::template read_mem(traits::MEM, offs); - if(this->core.reg.trap_state>=0x80000000UL) throw memory_access_exception(); + if(has_synchronous_exception()) throw memory_access_exception(); *(F+rd) = NaNBox64(res_41); } } @@ -6234,7 +6240,7 @@ typename vm_base::virt_addr_t vm_impl::execute_inst(finish_cond_e co else { uint64_t offs = (uint64_t)((uint128_t)(*(X+rs1)) + (int128_t)((int16_t)sext<12>(imm))); super::template write_mem(traits::MEM, offs, (uint64_t)*(F+rs2)); - if(this->core.reg.trap_state>=0x80000000UL) throw memory_access_exception(); + if(has_synchronous_exception()) throw memory_access_exception(); } } break; @@ -7080,7 +7086,7 @@ typename vm_base::virt_addr_t vm_impl::execute_inst(finish_cond_e co { uint64_t offs = (uint64_t)((uint128_t)(*(X+rs1 + 8)) + (uint128_t)(uimm)); uint64_t res_42 = super::template read_mem(traits::MEM, offs); - if(this->core.reg.trap_state>=0x80000000UL) throw memory_access_exception(); + if(has_synchronous_exception()) throw memory_access_exception(); uint64_t res = (uint64_t)res_42; *(F+rd + 8) = NaNBox64(res); } @@ -7106,7 +7112,7 @@ typename vm_base::virt_addr_t vm_impl::execute_inst(finish_cond_e co { uint64_t offs = (uint64_t)((uint128_t)(*(X+rs1 + 8)) + (uint128_t)(uimm)); super::template write_mem(traits::MEM, offs, (uint64_t)*(F+rs2 + 8)); - if(this->core.reg.trap_state>=0x80000000UL) throw memory_access_exception(); + if(has_synchronous_exception()) throw memory_access_exception(); } break; }// @suppress("No break at end of case") @@ -7129,7 +7135,7 @@ typename vm_base::virt_addr_t vm_impl::execute_inst(finish_cond_e co { uint64_t offs = (uint64_t)((uint128_t)(*(X+2)) + (uint128_t)(uimm)); uint64_t res_43 = super::template read_mem(traits::MEM, offs); - if(this->core.reg.trap_state>=0x80000000UL) throw memory_access_exception(); + if(has_synchronous_exception()) throw memory_access_exception(); uint64_t res = (uint64_t)res_43; *(F+rd) = NaNBox64(res); } @@ -7154,7 +7160,7 @@ typename vm_base::virt_addr_t vm_impl::execute_inst(finish_cond_e co { uint64_t offs = (uint64_t)((uint128_t)(*(X+2)) + (uint128_t)(uimm)); super::template write_mem(traits::MEM, offs, (uint64_t)*(F+rs2)); - if(this->core.reg.trap_state>=0x80000000UL) throw memory_access_exception(); + if(has_synchronous_exception()) throw memory_access_exception(); } break; }// @suppress("No break at end of case") @@ -7174,7 +7180,7 @@ typename vm_base::virt_addr_t vm_impl::execute_inst(finish_cond_e co // execute instruction { super::template write_mem(traits::FENCE, traits::fencevma, ((uint16_t)(uint8_t)rs1<<8)|(uint8_t)asid); - if(this->core.reg.trap_state>=0x80000000UL) throw memory_access_exception(); + if(has_synchronous_exception()) throw memory_access_exception(); } break; }// @suppress("No break at end of case") diff --git a/src/vm/interp/vm_rv64i.cpp b/src/vm/interp/vm_rv64i.cpp index 4faf132..8136e43 100644 --- a/src/vm/interp/vm_rv64i.cpp +++ b/src/vm/interp/vm_rv64i.cpp @@ -122,6 +122,12 @@ template class vm_impl : public iss::interp::vm_base { inline void set_tval(uint64_t new_tval){ tval = new_tval; } + + inline bool has_synchronous_exception() const { + auto state = this->core.reg.trap_state; + return (state & 0x80000000ULL) != 0 && (state & 0xffffULL) == 0; + } + uint64_t fetch_count{0}; uint64_t tval{0}; @@ -681,7 +687,7 @@ typename vm_base::virt_addr_t vm_impl::execute_inst(finish_cond_e co else { uint64_t load_address = (uint64_t)((uint128_t)(*(X+rs1)) + (int128_t)((int16_t)sext<12>(imm))); int8_t res_1 = super::template read_mem(traits::MEM, load_address); - if(this->core.reg.trap_state>=0x80000000UL) throw memory_access_exception(); + if(has_synchronous_exception()) throw memory_access_exception(); int8_t res = (int8_t)res_1; if(rd != 0) { *(X+rd) = (uint64_t)res; @@ -713,7 +719,7 @@ typename vm_base::virt_addr_t vm_impl::execute_inst(finish_cond_e co else { uint64_t load_address = (uint64_t)((uint128_t)(*(X+rs1)) + (int128_t)((int16_t)sext<12>(imm))); int16_t res_2 = super::template read_mem(traits::MEM, load_address); - if(this->core.reg.trap_state>=0x80000000UL) throw memory_access_exception(); + if(has_synchronous_exception()) throw memory_access_exception(); int16_t res = (int16_t)res_2; if(rd != 0) { *(X+rd) = (uint64_t)res; @@ -745,7 +751,7 @@ typename vm_base::virt_addr_t vm_impl::execute_inst(finish_cond_e co else { uint64_t load_address = (uint64_t)((uint128_t)(*(X+rs1)) + (int128_t)((int16_t)sext<12>(imm))); int32_t res_3 = super::template read_mem(traits::MEM, load_address); - if(this->core.reg.trap_state>=0x80000000UL) throw memory_access_exception(); + if(has_synchronous_exception()) throw memory_access_exception(); int32_t res = (int32_t)res_3; if(rd != 0) { *(X+rd) = (uint64_t)res; @@ -777,7 +783,7 @@ typename vm_base::virt_addr_t vm_impl::execute_inst(finish_cond_e co else { uint64_t load_address = (uint64_t)((uint128_t)(*(X+rs1)) + (int128_t)((int16_t)sext<12>(imm))); uint8_t res_4 = super::template read_mem(traits::MEM, load_address); - if(this->core.reg.trap_state>=0x80000000UL) throw memory_access_exception(); + if(has_synchronous_exception()) throw memory_access_exception(); uint8_t res = res_4; if(rd != 0) { *(X+rd) = (uint64_t)res; @@ -809,7 +815,7 @@ typename vm_base::virt_addr_t vm_impl::execute_inst(finish_cond_e co else { uint64_t load_address = (uint64_t)((uint128_t)(*(X+rs1)) + (int128_t)((int16_t)sext<12>(imm))); uint16_t res_5 = super::template read_mem(traits::MEM, load_address); - if(this->core.reg.trap_state>=0x80000000UL) throw memory_access_exception(); + if(has_synchronous_exception()) throw memory_access_exception(); uint16_t res = res_5; if(rd != 0) { *(X+rd) = (uint64_t)res; @@ -841,7 +847,7 @@ typename vm_base::virt_addr_t vm_impl::execute_inst(finish_cond_e co else { uint64_t store_address = (uint64_t)((uint128_t)(*(X+rs1)) + (int128_t)((int16_t)sext<12>(imm))); super::template write_mem(traits::MEM, store_address, (uint8_t)*(X+rs2)); - if(this->core.reg.trap_state>=0x80000000UL) throw memory_access_exception(); + if(has_synchronous_exception()) throw memory_access_exception(); } } break; @@ -869,7 +875,7 @@ typename vm_base::virt_addr_t vm_impl::execute_inst(finish_cond_e co else { uint64_t store_address = (uint64_t)((uint128_t)(*(X+rs1)) + (int128_t)((int16_t)sext<12>(imm))); super::template write_mem(traits::MEM, store_address, (uint16_t)*(X+rs2)); - if(this->core.reg.trap_state>=0x80000000UL) throw memory_access_exception(); + if(has_synchronous_exception()) throw memory_access_exception(); } } break; @@ -897,7 +903,7 @@ typename vm_base::virt_addr_t vm_impl::execute_inst(finish_cond_e co else { uint64_t store_address = (uint64_t)((uint128_t)(*(X+rs1)) + (int128_t)((int16_t)sext<12>(imm))); super::template write_mem(traits::MEM, store_address, (uint32_t)*(X+rs2)); - if(this->core.reg.trap_state>=0x80000000UL) throw memory_access_exception(); + if(has_synchronous_exception()) throw memory_access_exception(); } } break; @@ -1453,7 +1459,7 @@ typename vm_base::virt_addr_t vm_impl::execute_inst(finish_cond_e co // execute instruction { super::template write_mem(traits::FENCE, traits::fence, (uint8_t)pred << 4 | succ); - if(this->core.reg.trap_state>=0x80000000UL) throw memory_access_exception(); + if(has_synchronous_exception()) throw memory_access_exception(); } break; }// @suppress("No break at end of case") @@ -1544,7 +1550,7 @@ typename vm_base::virt_addr_t vm_impl::execute_inst(finish_cond_e co else { uint64_t offs = (uint64_t)((uint128_t)(*(X+rs1)) + (int128_t)((int16_t)sext<12>(imm))); uint32_t res_6 = super::template read_mem(traits::MEM, offs); - if(this->core.reg.trap_state>=0x80000000UL) throw memory_access_exception(); + if(has_synchronous_exception()) throw memory_access_exception(); uint32_t res = (uint32_t)res_6; if(rd != 0) { *(X+rd) = (uint64_t)res; @@ -1576,7 +1582,7 @@ typename vm_base::virt_addr_t vm_impl::execute_inst(finish_cond_e co else { uint64_t offs = (uint64_t)((uint128_t)(*(X+rs1)) + (int128_t)((int16_t)sext<12>(imm))); int64_t res_7 = super::template read_mem(traits::MEM, offs); - if(this->core.reg.trap_state>=0x80000000UL) throw memory_access_exception(); + if(has_synchronous_exception()) throw memory_access_exception(); int64_t res = (int64_t)res_7; if(rd != 0) { *(X+rd) = (uint64_t)res; @@ -1608,7 +1614,7 @@ typename vm_base::virt_addr_t vm_impl::execute_inst(finish_cond_e co else { uint64_t offs = (uint64_t)((uint128_t)(*(X+rs1)) + (int128_t)((int16_t)sext<12>(imm))); super::template write_mem(traits::MEM, offs, (uint64_t)*(X+rs2)); - if(this->core.reg.trap_state>=0x80000000UL) throw memory_access_exception(); + if(has_synchronous_exception()) throw memory_access_exception(); } } break; @@ -1899,15 +1905,15 @@ typename vm_base::virt_addr_t vm_impl::execute_inst(finish_cond_e co uint64_t xrs1 = *(X+rs1); if(rd != 0) { uint64_t res_8 = super::template read_mem(traits::CSR, csr); - if(this->core.reg.trap_state>=0x80000000UL) throw memory_access_exception(); + if(has_synchronous_exception()) throw memory_access_exception(); uint64_t xrd = res_8; super::template write_mem(traits::CSR, csr, xrs1); - if(this->core.reg.trap_state>=0x80000000UL) throw memory_access_exception(); + if(has_synchronous_exception()) throw memory_access_exception(); *(X+rd) = xrd; } else { super::template write_mem(traits::CSR, csr, xrs1); - if(this->core.reg.trap_state>=0x80000000UL) throw memory_access_exception(); + if(has_synchronous_exception()) throw memory_access_exception(); } } } @@ -1935,12 +1941,12 @@ typename vm_base::virt_addr_t vm_impl::execute_inst(finish_cond_e co } else { uint64_t res_9 = super::template read_mem(traits::CSR, csr); - if(this->core.reg.trap_state>=0x80000000UL) throw memory_access_exception(); + if(has_synchronous_exception()) throw memory_access_exception(); uint64_t xrd = res_9; uint64_t xrs1 = *(X+rs1); if(rs1 != 0) { super::template write_mem(traits::CSR, csr, xrd | xrs1); - if(this->core.reg.trap_state>=0x80000000UL) throw memory_access_exception(); + if(has_synchronous_exception()) throw memory_access_exception(); } if(rd != 0) { *(X+rd) = xrd; @@ -1971,12 +1977,12 @@ typename vm_base::virt_addr_t vm_impl::execute_inst(finish_cond_e co } else { uint64_t res_10 = super::template read_mem(traits::CSR, csr); - if(this->core.reg.trap_state>=0x80000000UL) throw memory_access_exception(); + if(has_synchronous_exception()) throw memory_access_exception(); uint64_t xrd = res_10; uint64_t xrs1 = *(X+rs1); if(rs1 != 0) { super::template write_mem(traits::CSR, csr, xrd & ~xrs1); - if(this->core.reg.trap_state>=0x80000000UL) throw memory_access_exception(); + if(has_synchronous_exception()) throw memory_access_exception(); } if(rd != 0) { *(X+rd) = xrd; @@ -2007,10 +2013,10 @@ typename vm_base::virt_addr_t vm_impl::execute_inst(finish_cond_e co } else { uint64_t res_11 = super::template read_mem(traits::CSR, csr); - if(this->core.reg.trap_state>=0x80000000UL) throw memory_access_exception(); + if(has_synchronous_exception()) throw memory_access_exception(); uint64_t xrd = res_11; super::template write_mem(traits::CSR, csr, (uint64_t)zimm); - if(this->core.reg.trap_state>=0x80000000UL) throw memory_access_exception(); + if(has_synchronous_exception()) throw memory_access_exception(); if(rd != 0) { *(X+rd) = xrd; } @@ -2040,11 +2046,11 @@ typename vm_base::virt_addr_t vm_impl::execute_inst(finish_cond_e co } else { uint64_t res_12 = super::template read_mem(traits::CSR, csr); - if(this->core.reg.trap_state>=0x80000000UL) throw memory_access_exception(); + if(has_synchronous_exception()) throw memory_access_exception(); uint64_t xrd = res_12; if(zimm != 0) { super::template write_mem(traits::CSR, csr, xrd | (uint64_t)zimm); - if(this->core.reg.trap_state>=0x80000000UL) throw memory_access_exception(); + if(has_synchronous_exception()) throw memory_access_exception(); } if(rd != 0) { *(X+rd) = xrd; @@ -2075,11 +2081,11 @@ typename vm_base::virt_addr_t vm_impl::execute_inst(finish_cond_e co } else { uint64_t res_13 = super::template read_mem(traits::CSR, csr); - if(this->core.reg.trap_state>=0x80000000UL) throw memory_access_exception(); + if(has_synchronous_exception()) throw memory_access_exception(); uint64_t xrd = res_13; if(zimm != 0) { super::template write_mem(traits::CSR, csr, xrd & ~((uint64_t)zimm)); - if(this->core.reg.trap_state>=0x80000000UL) throw memory_access_exception(); + if(has_synchronous_exception()) throw memory_access_exception(); } if(rd != 0) { *(X+rd) = xrd; @@ -2105,7 +2111,7 @@ typename vm_base::virt_addr_t vm_impl::execute_inst(finish_cond_e co // execute instruction { super::template write_mem(traits::FENCE, traits::fencei, imm); - if(this->core.reg.trap_state>=0x80000000UL) throw memory_access_exception(); + if(has_synchronous_exception()) throw memory_access_exception(); } break; }// @suppress("No break at end of case") diff --git a/src/vm/interp/vm_rv64imac.cpp b/src/vm/interp/vm_rv64imac.cpp index 7658558..a07df49 100644 --- a/src/vm/interp/vm_rv64imac.cpp +++ b/src/vm/interp/vm_rv64imac.cpp @@ -122,6 +122,12 @@ template class vm_impl : public iss::interp::vm_base { inline void set_tval(uint64_t new_tval){ tval = new_tval; } + + inline bool has_synchronous_exception() const { + auto state = this->core.reg.trap_state; + return (state & 0x80000000ULL) != 0 && (state & 0xffffULL) == 0; + } + uint64_t fetch_count{0}; uint64_t tval{0}; @@ -752,7 +758,7 @@ typename vm_base::virt_addr_t vm_impl::execute_inst(finish_cond_e co else { uint64_t load_address = (uint64_t)((uint128_t)(*(X+rs1)) + (int128_t)((int16_t)sext<12>(imm))); int8_t res_1 = super::template read_mem(traits::MEM, load_address); - if(this->core.reg.trap_state>=0x80000000UL) throw memory_access_exception(); + if(has_synchronous_exception()) throw memory_access_exception(); int8_t res = (int8_t)res_1; if(rd != 0) { *(X+rd) = (uint64_t)res; @@ -784,7 +790,7 @@ typename vm_base::virt_addr_t vm_impl::execute_inst(finish_cond_e co else { uint64_t load_address = (uint64_t)((uint128_t)(*(X+rs1)) + (int128_t)((int16_t)sext<12>(imm))); int16_t res_2 = super::template read_mem(traits::MEM, load_address); - if(this->core.reg.trap_state>=0x80000000UL) throw memory_access_exception(); + if(has_synchronous_exception()) throw memory_access_exception(); int16_t res = (int16_t)res_2; if(rd != 0) { *(X+rd) = (uint64_t)res; @@ -816,7 +822,7 @@ typename vm_base::virt_addr_t vm_impl::execute_inst(finish_cond_e co else { uint64_t load_address = (uint64_t)((uint128_t)(*(X+rs1)) + (int128_t)((int16_t)sext<12>(imm))); int32_t res_3 = super::template read_mem(traits::MEM, load_address); - if(this->core.reg.trap_state>=0x80000000UL) throw memory_access_exception(); + if(has_synchronous_exception()) throw memory_access_exception(); int32_t res = (int32_t)res_3; if(rd != 0) { *(X+rd) = (uint64_t)res; @@ -848,7 +854,7 @@ typename vm_base::virt_addr_t vm_impl::execute_inst(finish_cond_e co else { uint64_t load_address = (uint64_t)((uint128_t)(*(X+rs1)) + (int128_t)((int16_t)sext<12>(imm))); uint8_t res_4 = super::template read_mem(traits::MEM, load_address); - if(this->core.reg.trap_state>=0x80000000UL) throw memory_access_exception(); + if(has_synchronous_exception()) throw memory_access_exception(); uint8_t res = res_4; if(rd != 0) { *(X+rd) = (uint64_t)res; @@ -880,7 +886,7 @@ typename vm_base::virt_addr_t vm_impl::execute_inst(finish_cond_e co else { uint64_t load_address = (uint64_t)((uint128_t)(*(X+rs1)) + (int128_t)((int16_t)sext<12>(imm))); uint16_t res_5 = super::template read_mem(traits::MEM, load_address); - if(this->core.reg.trap_state>=0x80000000UL) throw memory_access_exception(); + if(has_synchronous_exception()) throw memory_access_exception(); uint16_t res = res_5; if(rd != 0) { *(X+rd) = (uint64_t)res; @@ -912,7 +918,7 @@ typename vm_base::virt_addr_t vm_impl::execute_inst(finish_cond_e co else { uint64_t store_address = (uint64_t)((uint128_t)(*(X+rs1)) + (int128_t)((int16_t)sext<12>(imm))); super::template write_mem(traits::MEM, store_address, (uint8_t)*(X+rs2)); - if(this->core.reg.trap_state>=0x80000000UL) throw memory_access_exception(); + if(has_synchronous_exception()) throw memory_access_exception(); } } break; @@ -940,7 +946,7 @@ typename vm_base::virt_addr_t vm_impl::execute_inst(finish_cond_e co else { uint64_t store_address = (uint64_t)((uint128_t)(*(X+rs1)) + (int128_t)((int16_t)sext<12>(imm))); super::template write_mem(traits::MEM, store_address, (uint16_t)*(X+rs2)); - if(this->core.reg.trap_state>=0x80000000UL) throw memory_access_exception(); + if(has_synchronous_exception()) throw memory_access_exception(); } } break; @@ -968,7 +974,7 @@ typename vm_base::virt_addr_t vm_impl::execute_inst(finish_cond_e co else { uint64_t store_address = (uint64_t)((uint128_t)(*(X+rs1)) + (int128_t)((int16_t)sext<12>(imm))); super::template write_mem(traits::MEM, store_address, (uint32_t)*(X+rs2)); - if(this->core.reg.trap_state>=0x80000000UL) throw memory_access_exception(); + if(has_synchronous_exception()) throw memory_access_exception(); } } break; @@ -1524,7 +1530,7 @@ typename vm_base::virt_addr_t vm_impl::execute_inst(finish_cond_e co // execute instruction { super::template write_mem(traits::FENCE, traits::fence, (uint8_t)pred << 4 | succ); - if(this->core.reg.trap_state>=0x80000000UL) throw memory_access_exception(); + if(has_synchronous_exception()) throw memory_access_exception(); } break; }// @suppress("No break at end of case") @@ -1615,7 +1621,7 @@ typename vm_base::virt_addr_t vm_impl::execute_inst(finish_cond_e co else { uint64_t offs = (uint64_t)((uint128_t)(*(X+rs1)) + (int128_t)((int16_t)sext<12>(imm))); uint32_t res_6 = super::template read_mem(traits::MEM, offs); - if(this->core.reg.trap_state>=0x80000000UL) throw memory_access_exception(); + if(has_synchronous_exception()) throw memory_access_exception(); uint32_t res = (uint32_t)res_6; if(rd != 0) { *(X+rd) = (uint64_t)res; @@ -1647,7 +1653,7 @@ typename vm_base::virt_addr_t vm_impl::execute_inst(finish_cond_e co else { uint64_t offs = (uint64_t)((uint128_t)(*(X+rs1)) + (int128_t)((int16_t)sext<12>(imm))); int64_t res_7 = super::template read_mem(traits::MEM, offs); - if(this->core.reg.trap_state>=0x80000000UL) throw memory_access_exception(); + if(has_synchronous_exception()) throw memory_access_exception(); int64_t res = (int64_t)res_7; if(rd != 0) { *(X+rd) = (uint64_t)res; @@ -1679,7 +1685,7 @@ typename vm_base::virt_addr_t vm_impl::execute_inst(finish_cond_e co else { uint64_t offs = (uint64_t)((uint128_t)(*(X+rs1)) + (int128_t)((int16_t)sext<12>(imm))); super::template write_mem(traits::MEM, offs, (uint64_t)*(X+rs2)); - if(this->core.reg.trap_state>=0x80000000UL) throw memory_access_exception(); + if(has_synchronous_exception()) throw memory_access_exception(); } } break; @@ -1970,15 +1976,15 @@ typename vm_base::virt_addr_t vm_impl::execute_inst(finish_cond_e co uint64_t xrs1 = *(X+rs1); if(rd != 0) { uint64_t res_8 = super::template read_mem(traits::CSR, csr); - if(this->core.reg.trap_state>=0x80000000UL) throw memory_access_exception(); + if(has_synchronous_exception()) throw memory_access_exception(); uint64_t xrd = res_8; super::template write_mem(traits::CSR, csr, xrs1); - if(this->core.reg.trap_state>=0x80000000UL) throw memory_access_exception(); + if(has_synchronous_exception()) throw memory_access_exception(); *(X+rd) = xrd; } else { super::template write_mem(traits::CSR, csr, xrs1); - if(this->core.reg.trap_state>=0x80000000UL) throw memory_access_exception(); + if(has_synchronous_exception()) throw memory_access_exception(); } } } @@ -2006,12 +2012,12 @@ typename vm_base::virt_addr_t vm_impl::execute_inst(finish_cond_e co } else { uint64_t res_9 = super::template read_mem(traits::CSR, csr); - if(this->core.reg.trap_state>=0x80000000UL) throw memory_access_exception(); + if(has_synchronous_exception()) throw memory_access_exception(); uint64_t xrd = res_9; uint64_t xrs1 = *(X+rs1); if(rs1 != 0) { super::template write_mem(traits::CSR, csr, xrd | xrs1); - if(this->core.reg.trap_state>=0x80000000UL) throw memory_access_exception(); + if(has_synchronous_exception()) throw memory_access_exception(); } if(rd != 0) { *(X+rd) = xrd; @@ -2042,12 +2048,12 @@ typename vm_base::virt_addr_t vm_impl::execute_inst(finish_cond_e co } else { uint64_t res_10 = super::template read_mem(traits::CSR, csr); - if(this->core.reg.trap_state>=0x80000000UL) throw memory_access_exception(); + if(has_synchronous_exception()) throw memory_access_exception(); uint64_t xrd = res_10; uint64_t xrs1 = *(X+rs1); if(rs1 != 0) { super::template write_mem(traits::CSR, csr, xrd & ~xrs1); - if(this->core.reg.trap_state>=0x80000000UL) throw memory_access_exception(); + if(has_synchronous_exception()) throw memory_access_exception(); } if(rd != 0) { *(X+rd) = xrd; @@ -2078,10 +2084,10 @@ typename vm_base::virt_addr_t vm_impl::execute_inst(finish_cond_e co } else { uint64_t res_11 = super::template read_mem(traits::CSR, csr); - if(this->core.reg.trap_state>=0x80000000UL) throw memory_access_exception(); + if(has_synchronous_exception()) throw memory_access_exception(); uint64_t xrd = res_11; super::template write_mem(traits::CSR, csr, (uint64_t)zimm); - if(this->core.reg.trap_state>=0x80000000UL) throw memory_access_exception(); + if(has_synchronous_exception()) throw memory_access_exception(); if(rd != 0) { *(X+rd) = xrd; } @@ -2111,11 +2117,11 @@ typename vm_base::virt_addr_t vm_impl::execute_inst(finish_cond_e co } else { uint64_t res_12 = super::template read_mem(traits::CSR, csr); - if(this->core.reg.trap_state>=0x80000000UL) throw memory_access_exception(); + if(has_synchronous_exception()) throw memory_access_exception(); uint64_t xrd = res_12; if(zimm != 0) { super::template write_mem(traits::CSR, csr, xrd | (uint64_t)zimm); - if(this->core.reg.trap_state>=0x80000000UL) throw memory_access_exception(); + if(has_synchronous_exception()) throw memory_access_exception(); } if(rd != 0) { *(X+rd) = xrd; @@ -2146,11 +2152,11 @@ typename vm_base::virt_addr_t vm_impl::execute_inst(finish_cond_e co } else { uint64_t res_13 = super::template read_mem(traits::CSR, csr); - if(this->core.reg.trap_state>=0x80000000UL) throw memory_access_exception(); + if(has_synchronous_exception()) throw memory_access_exception(); uint64_t xrd = res_13; if(zimm != 0) { super::template write_mem(traits::CSR, csr, xrd & ~((uint64_t)zimm)); - if(this->core.reg.trap_state>=0x80000000UL) throw memory_access_exception(); + if(has_synchronous_exception()) throw memory_access_exception(); } if(rd != 0) { *(X+rd) = xrd; @@ -2176,7 +2182,7 @@ typename vm_base::virt_addr_t vm_impl::execute_inst(finish_cond_e co // execute instruction { super::template write_mem(traits::FENCE, traits::fencei, imm); - if(this->core.reg.trap_state>=0x80000000UL) throw memory_access_exception(); + if(has_synchronous_exception()) throw memory_access_exception(); } break; }// @suppress("No break at end of case") @@ -2667,10 +2673,10 @@ typename vm_base::virt_addr_t vm_impl::execute_inst(finish_cond_e co if(rd != 0) { uint64_t offs = *(X+rs1); int32_t res_14 = super::template read_mem(traits::MEM, offs); - if(this->core.reg.trap_state>=0x80000000UL) throw memory_access_exception(); + if(has_synchronous_exception()) throw memory_access_exception(); *(X+rd) = (uint64_t)((int32_t)res_14); super::template write_mem(traits::RES, offs, (uint8_t)- 1); - if(this->core.reg.trap_state>=0x80000000UL) throw memory_access_exception(); + if(has_synchronous_exception()) throw memory_access_exception(); } } } @@ -2701,11 +2707,11 @@ typename vm_base::virt_addr_t vm_impl::execute_inst(finish_cond_e co else { uint64_t offs = *(X+rs1); uint8_t res_15 = super::template read_mem(traits::RES, offs); - if(this->core.reg.trap_state>=0x80000000UL) throw memory_access_exception(); + if(has_synchronous_exception()) throw memory_access_exception(); uint32_t res1 = res_15; if(res1 != 0) { super::template write_mem(traits::MEM, offs, (uint32_t)*(X+rs2)); - if(this->core.reg.trap_state>=0x80000000UL) throw memory_access_exception(); + if(has_synchronous_exception()) throw memory_access_exception(); } if(rd != 0) { *(X+rd) = res1? 0 : 1; @@ -2741,11 +2747,11 @@ typename vm_base::virt_addr_t vm_impl::execute_inst(finish_cond_e co uint64_t res = *(X+rs2); if(rd != 0) { int32_t res_16 = super::template read_mem(traits::MEM, offs); - if(this->core.reg.trap_state>=0x80000000UL) throw memory_access_exception(); + if(has_synchronous_exception()) throw memory_access_exception(); *(X+rd) = (uint64_t)((int32_t)res_16); } super::template write_mem(traits::MEM, offs, (uint32_t)res); - if(this->core.reg.trap_state>=0x80000000UL) throw memory_access_exception(); + if(has_synchronous_exception()) throw memory_access_exception(); } } break; @@ -2775,14 +2781,14 @@ typename vm_base::virt_addr_t vm_impl::execute_inst(finish_cond_e co else { uint64_t offs = *(X+rs1); int32_t res_17 = super::template read_mem(traits::MEM, offs); - if(this->core.reg.trap_state>=0x80000000UL) throw memory_access_exception(); + if(has_synchronous_exception()) throw memory_access_exception(); int32_t res1 = (int32_t)res_17; int64_t res2 = (int64_t)(res1) + (int64_t)((int32_t)*(X+rs2)); if(rd != 0) { *(X+rd) = (uint64_t)res1; } super::template write_mem(traits::MEM, offs, (uint32_t)res2); - if(this->core.reg.trap_state>=0x80000000UL) throw memory_access_exception(); + if(has_synchronous_exception()) throw memory_access_exception(); } } break; @@ -2812,14 +2818,14 @@ typename vm_base::virt_addr_t vm_impl::execute_inst(finish_cond_e co else { uint64_t offs = *(X+rs1); uint32_t res_18 = super::template read_mem(traits::MEM, offs); - if(this->core.reg.trap_state>=0x80000000UL) throw memory_access_exception(); + if(has_synchronous_exception()) throw memory_access_exception(); uint32_t res1 = res_18; uint32_t res2 = res1 ^ (uint32_t)*(X+rs2); if(rd != 0) { *(X+rd) = ((uint64_t)(int64_t)(int32_t)res1); } super::template write_mem(traits::MEM, offs, res2); - if(this->core.reg.trap_state>=0x80000000UL) throw memory_access_exception(); + if(has_synchronous_exception()) throw memory_access_exception(); } } break; @@ -2849,14 +2855,14 @@ typename vm_base::virt_addr_t vm_impl::execute_inst(finish_cond_e co else { uint64_t offs = *(X+rs1); uint32_t res_19 = super::template read_mem(traits::MEM, offs); - if(this->core.reg.trap_state>=0x80000000UL) throw memory_access_exception(); + if(has_synchronous_exception()) throw memory_access_exception(); uint32_t res1 = res_19; uint32_t res2 = res1 & (uint32_t)*(X+rs2); if(rd != 0) { *(X+rd) = ((uint64_t)(int64_t)(int32_t)res1); } super::template write_mem(traits::MEM, offs, res2); - if(this->core.reg.trap_state>=0x80000000UL) throw memory_access_exception(); + if(has_synchronous_exception()) throw memory_access_exception(); } } break; @@ -2886,14 +2892,14 @@ typename vm_base::virt_addr_t vm_impl::execute_inst(finish_cond_e co else { uint64_t offs = *(X+rs1); uint32_t res_20 = super::template read_mem(traits::MEM, offs); - if(this->core.reg.trap_state>=0x80000000UL) throw memory_access_exception(); + if(has_synchronous_exception()) throw memory_access_exception(); uint32_t res1 = res_20; uint32_t res2 = res1 | (uint32_t)*(X+rs2); if(rd != 0) { *(X+rd) = ((uint64_t)(int64_t)(int32_t)res1); } super::template write_mem(traits::MEM, offs, res2); - if(this->core.reg.trap_state>=0x80000000UL) throw memory_access_exception(); + if(has_synchronous_exception()) throw memory_access_exception(); } } break; @@ -2923,14 +2929,14 @@ typename vm_base::virt_addr_t vm_impl::execute_inst(finish_cond_e co else { uint64_t offs = *(X+rs1); int32_t res_21 = super::template read_mem(traits::MEM, offs); - if(this->core.reg.trap_state>=0x80000000UL) throw memory_access_exception(); + if(has_synchronous_exception()) throw memory_access_exception(); int32_t res1 = (int32_t)res_21; uint32_t res2 = res1 > (int32_t)*(X+rs2)? (uint32_t)*(X+rs2) : ((uint32_t)res1); if(rd != 0) { *(X+rd) = (uint64_t)res1; } super::template write_mem(traits::MEM, offs, res2); - if(this->core.reg.trap_state>=0x80000000UL) throw memory_access_exception(); + if(has_synchronous_exception()) throw memory_access_exception(); } } break; @@ -2960,14 +2966,14 @@ typename vm_base::virt_addr_t vm_impl::execute_inst(finish_cond_e co else { uint64_t offs = *(X+rs1); int32_t res_22 = super::template read_mem(traits::MEM, offs); - if(this->core.reg.trap_state>=0x80000000UL) throw memory_access_exception(); + if(has_synchronous_exception()) throw memory_access_exception(); int32_t res1 = (int32_t)res_22; uint32_t res2 = res1 < (int32_t)*(X+rs2)? (uint32_t)*(X+rs2) : ((uint32_t)res1); if(rd != 0) { *(X+rd) = (uint64_t)res1; } super::template write_mem(traits::MEM, offs, res2); - if(this->core.reg.trap_state>=0x80000000UL) throw memory_access_exception(); + if(has_synchronous_exception()) throw memory_access_exception(); } } break; @@ -2997,14 +3003,14 @@ typename vm_base::virt_addr_t vm_impl::execute_inst(finish_cond_e co else { uint64_t offs = *(X+rs1); uint32_t res_23 = super::template read_mem(traits::MEM, offs); - if(this->core.reg.trap_state>=0x80000000UL) throw memory_access_exception(); + if(has_synchronous_exception()) throw memory_access_exception(); uint32_t res1 = res_23; uint32_t res2 = res1 > (uint32_t)*(X+rs2)? (uint32_t)*(X+rs2) : res1; if(rd != 0) { *(X+rd) = ((uint64_t)(int64_t)(int32_t)res1); } super::template write_mem(traits::MEM, offs, res2); - if(this->core.reg.trap_state>=0x80000000UL) throw memory_access_exception(); + if(has_synchronous_exception()) throw memory_access_exception(); } } break; @@ -3034,14 +3040,14 @@ typename vm_base::virt_addr_t vm_impl::execute_inst(finish_cond_e co else { uint64_t offs = *(X+rs1); uint32_t res_24 = super::template read_mem(traits::MEM, offs); - if(this->core.reg.trap_state>=0x80000000UL) throw memory_access_exception(); + if(has_synchronous_exception()) throw memory_access_exception(); uint32_t res1 = res_24; uint32_t res2 = res1 < (int32_t)*(X+rs2)? (uint32_t)*(X+rs2) : res1; if(rd != 0) { *(X+rd) = ((uint64_t)(int64_t)(int32_t)res1); } super::template write_mem(traits::MEM, offs, res2); - if(this->core.reg.trap_state>=0x80000000UL) throw memory_access_exception(); + if(has_synchronous_exception()) throw memory_access_exception(); } } break; @@ -3071,10 +3077,10 @@ typename vm_base::virt_addr_t vm_impl::execute_inst(finish_cond_e co if(rd != 0) { uint64_t offs = *(X+rs1); int64_t res_25 = super::template read_mem(traits::MEM, offs); - if(this->core.reg.trap_state>=0x80000000UL) throw memory_access_exception(); + if(has_synchronous_exception()) throw memory_access_exception(); *(X+rd) = (uint64_t)((int64_t)res_25); super::template write_mem(traits::RES, offs, (uint8_t)- 1); - if(this->core.reg.trap_state>=0x80000000UL) throw memory_access_exception(); + if(has_synchronous_exception()) throw memory_access_exception(); } } } @@ -3105,11 +3111,11 @@ typename vm_base::virt_addr_t vm_impl::execute_inst(finish_cond_e co else { uint64_t offs = *(X+rs1); uint8_t res_26 = super::template read_mem(traits::RES, offs); - if(this->core.reg.trap_state>=0x80000000UL) throw memory_access_exception(); + if(has_synchronous_exception()) throw memory_access_exception(); uint64_t res = res_26; if(res != 0) { super::template write_mem(traits::MEM, offs, *(X+rs2)); - if(this->core.reg.trap_state>=0x80000000UL) throw memory_access_exception(); + if(has_synchronous_exception()) throw memory_access_exception(); } if(rd != 0) { *(X+rd) = res? 0 : 1; @@ -3145,11 +3151,11 @@ typename vm_base::virt_addr_t vm_impl::execute_inst(finish_cond_e co uint64_t res = *(X+rs2); if(rd != 0) { int64_t res_27 = super::template read_mem(traits::MEM, offs); - if(this->core.reg.trap_state>=0x80000000UL) throw memory_access_exception(); + if(has_synchronous_exception()) throw memory_access_exception(); *(X+rd) = (uint64_t)((int64_t)res_27); } super::template write_mem(traits::MEM, offs, (uint64_t)res); - if(this->core.reg.trap_state>=0x80000000UL) throw memory_access_exception(); + if(has_synchronous_exception()) throw memory_access_exception(); } } break; @@ -3179,14 +3185,14 @@ typename vm_base::virt_addr_t vm_impl::execute_inst(finish_cond_e co else { uint64_t offs = *(X+rs1); uint64_t res_28 = super::template read_mem(traits::MEM, offs); - if(this->core.reg.trap_state>=0x80000000UL) throw memory_access_exception(); + if(has_synchronous_exception()) throw memory_access_exception(); uint64_t res1 = res_28; uint64_t res2 = (uint64_t)((uint128_t)(res1) + (uint128_t)(*(X+rs2))); if(rd != 0) { *(X+rd) = (uint64_t)res1; } super::template write_mem(traits::MEM, offs, res2); - if(this->core.reg.trap_state>=0x80000000UL) throw memory_access_exception(); + if(has_synchronous_exception()) throw memory_access_exception(); } } break; @@ -3216,14 +3222,14 @@ typename vm_base::virt_addr_t vm_impl::execute_inst(finish_cond_e co else { uint64_t offs = *(X+rs1); uint64_t res_29 = super::template read_mem(traits::MEM, offs); - if(this->core.reg.trap_state>=0x80000000UL) throw memory_access_exception(); + if(has_synchronous_exception()) throw memory_access_exception(); uint64_t res1 = res_29; uint64_t res2 = res1 ^ *(X+rs2); if(rd != 0) { *(X+rd) = ((uint64_t)(int64_t)res1); } super::template write_mem(traits::MEM, offs, res2); - if(this->core.reg.trap_state>=0x80000000UL) throw memory_access_exception(); + if(has_synchronous_exception()) throw memory_access_exception(); } } break; @@ -3253,14 +3259,14 @@ typename vm_base::virt_addr_t vm_impl::execute_inst(finish_cond_e co else { uint64_t offs = *(X+rs1); uint64_t res_30 = super::template read_mem(traits::MEM, offs); - if(this->core.reg.trap_state>=0x80000000UL) throw memory_access_exception(); + if(has_synchronous_exception()) throw memory_access_exception(); uint64_t res1 = res_30; uint64_t res2 = res1 & *(X+rs2); if(rd != 0) { *(X+rd) = (uint64_t)res1; } super::template write_mem(traits::MEM, offs, res2); - if(this->core.reg.trap_state>=0x80000000UL) throw memory_access_exception(); + if(has_synchronous_exception()) throw memory_access_exception(); } } break; @@ -3290,14 +3296,14 @@ typename vm_base::virt_addr_t vm_impl::execute_inst(finish_cond_e co else { uint64_t offs = *(X+rs1); uint64_t res_31 = super::template read_mem(traits::MEM, offs); - if(this->core.reg.trap_state>=0x80000000UL) throw memory_access_exception(); + if(has_synchronous_exception()) throw memory_access_exception(); uint64_t res1 = res_31; uint64_t res2 = res1 | *(X+rs2); if(rd != 0) { *(X+rd) = (uint64_t)res1; } super::template write_mem(traits::MEM, offs, res2); - if(this->core.reg.trap_state>=0x80000000UL) throw memory_access_exception(); + if(has_synchronous_exception()) throw memory_access_exception(); } } break; @@ -3327,14 +3333,14 @@ typename vm_base::virt_addr_t vm_impl::execute_inst(finish_cond_e co else { uint64_t offs = *(X+rs1); int64_t res_32 = super::template read_mem(traits::MEM, offs); - if(this->core.reg.trap_state>=0x80000000UL) throw memory_access_exception(); + if(has_synchronous_exception()) throw memory_access_exception(); int64_t res1 = (int64_t)res_32; uint64_t res2 = res1 > (int64_t)*(X+rs2)? (uint64_t)*(X+rs2) : ((uint64_t)res1); if(rd != 0) { *(X+rd) = (uint64_t)res1; } super::template write_mem(traits::MEM, offs, res2); - if(this->core.reg.trap_state>=0x80000000UL) throw memory_access_exception(); + if(has_synchronous_exception()) throw memory_access_exception(); } } break; @@ -3364,14 +3370,14 @@ typename vm_base::virt_addr_t vm_impl::execute_inst(finish_cond_e co else { uint64_t offs = *(X+rs1); int64_t res_33 = super::template read_mem(traits::MEM, offs); - if(this->core.reg.trap_state>=0x80000000UL) throw memory_access_exception(); + if(has_synchronous_exception()) throw memory_access_exception(); int64_t res1 = (int64_t)res_33; uint64_t res2 = res1 < (int64_t)*(X+rs2)? (uint64_t)*(X+rs2) : ((uint64_t)res1); if(rd != 0) { *(X+rd) = (uint64_t)res1; } super::template write_mem(traits::MEM, offs, res2); - if(this->core.reg.trap_state>=0x80000000UL) throw memory_access_exception(); + if(has_synchronous_exception()) throw memory_access_exception(); } } break; @@ -3401,14 +3407,14 @@ typename vm_base::virt_addr_t vm_impl::execute_inst(finish_cond_e co else { uint64_t offs = *(X+rs1); uint64_t res_34 = super::template read_mem(traits::MEM, offs); - if(this->core.reg.trap_state>=0x80000000UL) throw memory_access_exception(); + if(has_synchronous_exception()) throw memory_access_exception(); uint64_t res1 = res_34; uint64_t res2 = res1 > *(X+rs2)? *(X+rs2) : res1; if(rd != 0) { *(X+rd) = (uint64_t)res1; } super::template write_mem(traits::MEM, offs, res2); - if(this->core.reg.trap_state>=0x80000000UL) throw memory_access_exception(); + if(has_synchronous_exception()) throw memory_access_exception(); } } break; @@ -3438,14 +3444,14 @@ typename vm_base::virt_addr_t vm_impl::execute_inst(finish_cond_e co else { uint64_t offs = *(X+rs1); uint64_t res_35 = super::template read_mem(traits::MEM, offs); - if(this->core.reg.trap_state>=0x80000000UL) throw memory_access_exception(); + if(has_synchronous_exception()) throw memory_access_exception(); uint64_t res1 = res_35; uint64_t res2 = res1 < *(X+rs2)? (uint64_t)*(X+rs2) : res1; if(rd != 0) { *(X+rd) = (uint64_t)res1; } super::template write_mem(traits::MEM, offs, res2); - if(this->core.reg.trap_state>=0x80000000UL) throw memory_access_exception(); + if(has_synchronous_exception()) throw memory_access_exception(); } } break; @@ -3494,7 +3500,7 @@ typename vm_base::virt_addr_t vm_impl::execute_inst(finish_cond_e co { uint64_t offs = (uint64_t)((uint128_t)(*(X+rs1 + 8)) + (uint128_t)(uimm)); int32_t res_36 = super::template read_mem(traits::MEM, offs); - if(this->core.reg.trap_state>=0x80000000UL) throw memory_access_exception(); + if(has_synchronous_exception()) throw memory_access_exception(); *(X+rd + 8) = (uint64_t)(int32_t)res_36; } break; @@ -3518,7 +3524,7 @@ typename vm_base::virt_addr_t vm_impl::execute_inst(finish_cond_e co { uint64_t offs = (uint64_t)((uint128_t)(*(X+rs1 + 8)) + (uint128_t)(uimm)); uint64_t res_37 = super::template read_mem(traits::MEM, offs); - if(this->core.reg.trap_state>=0x80000000UL) throw memory_access_exception(); + if(has_synchronous_exception()) throw memory_access_exception(); *(X+rd + 8) = (uint64_t)res_37; } break; @@ -3542,7 +3548,7 @@ typename vm_base::virt_addr_t vm_impl::execute_inst(finish_cond_e co { uint64_t offs = (uint64_t)((uint128_t)(*(X+rs1 + 8)) + (uint128_t)(uimm)); super::template write_mem(traits::MEM, offs, (uint32_t)*(X+rs2 + 8)); - if(this->core.reg.trap_state>=0x80000000UL) throw memory_access_exception(); + if(has_synchronous_exception()) throw memory_access_exception(); } break; }// @suppress("No break at end of case") @@ -3565,7 +3571,7 @@ typename vm_base::virt_addr_t vm_impl::execute_inst(finish_cond_e co { uint64_t offs = (uint64_t)((uint128_t)(*(X+rs1 + 8)) + (uint128_t)(uimm)); super::template write_mem(traits::MEM, offs, *(X+rs2 + 8)); - if(this->core.reg.trap_state>=0x80000000UL) throw memory_access_exception(); + if(has_synchronous_exception()) throw memory_access_exception(); } break; }// @suppress("No break at end of case") @@ -4031,7 +4037,7 @@ typename vm_base::virt_addr_t vm_impl::execute_inst(finish_cond_e co else { uint64_t offs = (uint64_t)((uint128_t)(*(X+2)) + (uint128_t)(uimm)); int32_t res_38 = super::template read_mem(traits::MEM, offs); - if(this->core.reg.trap_state>=0x80000000UL) throw memory_access_exception(); + if(has_synchronous_exception()) throw memory_access_exception(); *(X+rd) = (uint64_t)(int32_t)res_38; } } @@ -4059,7 +4065,7 @@ typename vm_base::virt_addr_t vm_impl::execute_inst(finish_cond_e co else { uint64_t offs = (uint64_t)((uint128_t)(*(X+2)) + (uint128_t)(uimm)); uint64_t res_39 = super::template read_mem(traits::MEM, offs); - if(this->core.reg.trap_state>=0x80000000UL) throw memory_access_exception(); + if(has_synchronous_exception()) throw memory_access_exception(); uint64_t res = (uint64_t)res_39; *(X+rd) = res; } @@ -4228,7 +4234,7 @@ typename vm_base::virt_addr_t vm_impl::execute_inst(finish_cond_e co else { uint64_t offs = (uint64_t)((uint128_t)(*(X+2)) + (uint128_t)(uimm)); super::template write_mem(traits::MEM, offs, (uint32_t)*(X+rs2)); - if(this->core.reg.trap_state>=0x80000000UL) throw memory_access_exception(); + if(has_synchronous_exception()) throw memory_access_exception(); } } break; @@ -4255,7 +4261,7 @@ typename vm_base::virt_addr_t vm_impl::execute_inst(finish_cond_e co else { uint64_t offs = (uint64_t)((uint128_t)(*(X+2)) + (uint128_t)(uimm)); super::template write_mem(traits::MEM, offs, (uint64_t)*(X+rs2)); - if(this->core.reg.trap_state>=0x80000000UL) throw memory_access_exception(); + if(has_synchronous_exception()) throw memory_access_exception(); } } break; diff --git a/src/vm/interp/vm_tgc5c.cpp b/src/vm/interp/vm_tgc5c.cpp index a94138c..d326b04 100644 --- a/src/vm/interp/vm_tgc5c.cpp +++ b/src/vm/interp/vm_tgc5c.cpp @@ -122,6 +122,12 @@ template class vm_impl : public iss::interp::vm_base { inline void set_tval(uint64_t new_tval){ tval = new_tval; } + + inline bool has_synchronous_exception() const { + auto state = this->core.reg.trap_state; + return (state & 0x80000000ULL) != 0 && (state & 0xffffULL) == 0; + } + uint64_t fetch_count{0}; uint64_t tval{0}; @@ -707,7 +713,7 @@ typename vm_base::virt_addr_t vm_impl::execute_inst(finish_cond_e co else { uint32_t load_address = (uint32_t)((uint64_t)(*(X+rs1)) + (int64_t)((int16_t)sext<12>(imm))); int8_t res_1 = super::template read_mem(traits::MEM, load_address); - if(this->core.reg.trap_state>=0x80000000UL) throw memory_access_exception(); + if(has_synchronous_exception()) throw memory_access_exception(); int8_t res = (int8_t)res_1; if(rd != 0) { *(X+rd) = (uint32_t)res; @@ -739,7 +745,7 @@ typename vm_base::virt_addr_t vm_impl::execute_inst(finish_cond_e co else { uint32_t load_address = (uint32_t)((uint64_t)(*(X+rs1)) + (int64_t)((int16_t)sext<12>(imm))); int16_t res_2 = super::template read_mem(traits::MEM, load_address); - if(this->core.reg.trap_state>=0x80000000UL) throw memory_access_exception(); + if(has_synchronous_exception()) throw memory_access_exception(); int16_t res = (int16_t)res_2; if(rd != 0) { *(X+rd) = (uint32_t)res; @@ -771,7 +777,7 @@ typename vm_base::virt_addr_t vm_impl::execute_inst(finish_cond_e co else { uint32_t load_address = (uint32_t)((uint64_t)(*(X+rs1)) + (int64_t)((int16_t)sext<12>(imm))); int32_t res_3 = super::template read_mem(traits::MEM, load_address); - if(this->core.reg.trap_state>=0x80000000UL) throw memory_access_exception(); + if(has_synchronous_exception()) throw memory_access_exception(); int32_t res = (int32_t)res_3; if(rd != 0) { *(X+rd) = (uint32_t)res; @@ -803,7 +809,7 @@ typename vm_base::virt_addr_t vm_impl::execute_inst(finish_cond_e co else { uint32_t load_address = (uint32_t)((uint64_t)(*(X+rs1)) + (int64_t)((int16_t)sext<12>(imm))); uint8_t res_4 = super::template read_mem(traits::MEM, load_address); - if(this->core.reg.trap_state>=0x80000000UL) throw memory_access_exception(); + if(has_synchronous_exception()) throw memory_access_exception(); uint8_t res = res_4; if(rd != 0) { *(X+rd) = (uint32_t)res; @@ -835,7 +841,7 @@ typename vm_base::virt_addr_t vm_impl::execute_inst(finish_cond_e co else { uint32_t load_address = (uint32_t)((uint64_t)(*(X+rs1)) + (int64_t)((int16_t)sext<12>(imm))); uint16_t res_5 = super::template read_mem(traits::MEM, load_address); - if(this->core.reg.trap_state>=0x80000000UL) throw memory_access_exception(); + if(has_synchronous_exception()) throw memory_access_exception(); uint16_t res = res_5; if(rd != 0) { *(X+rd) = (uint32_t)res; @@ -867,7 +873,7 @@ typename vm_base::virt_addr_t vm_impl::execute_inst(finish_cond_e co else { uint32_t store_address = (uint32_t)((uint64_t)(*(X+rs1)) + (int64_t)((int16_t)sext<12>(imm))); super::template write_mem(traits::MEM, store_address, (uint8_t)*(X+rs2)); - if(this->core.reg.trap_state>=0x80000000UL) throw memory_access_exception(); + if(has_synchronous_exception()) throw memory_access_exception(); } } break; @@ -895,7 +901,7 @@ typename vm_base::virt_addr_t vm_impl::execute_inst(finish_cond_e co else { uint32_t store_address = (uint32_t)((uint64_t)(*(X+rs1)) + (int64_t)((int16_t)sext<12>(imm))); super::template write_mem(traits::MEM, store_address, (uint16_t)*(X+rs2)); - if(this->core.reg.trap_state>=0x80000000UL) throw memory_access_exception(); + if(has_synchronous_exception()) throw memory_access_exception(); } } break; @@ -923,7 +929,7 @@ typename vm_base::virt_addr_t vm_impl::execute_inst(finish_cond_e co else { uint32_t store_address = (uint32_t)((uint64_t)(*(X+rs1)) + (int64_t)((int16_t)sext<12>(imm))); super::template write_mem(traits::MEM, store_address, (uint32_t)*(X+rs2)); - if(this->core.reg.trap_state>=0x80000000UL) throw memory_access_exception(); + if(has_synchronous_exception()) throw memory_access_exception(); } } break; @@ -1479,7 +1485,7 @@ typename vm_base::virt_addr_t vm_impl::execute_inst(finish_cond_e co // execute instruction { super::template write_mem(traits::FENCE, traits::fence, (uint8_t)pred << 4 | succ); - if(this->core.reg.trap_state>=0x80000000UL) throw memory_access_exception(); + if(has_synchronous_exception()) throw memory_access_exception(); } break; }// @suppress("No break at end of case") @@ -1571,15 +1577,15 @@ typename vm_base::virt_addr_t vm_impl::execute_inst(finish_cond_e co uint32_t xrs1 = *(X+rs1); if(rd != 0) { uint32_t res_6 = super::template read_mem(traits::CSR, csr); - if(this->core.reg.trap_state>=0x80000000UL) throw memory_access_exception(); + if(has_synchronous_exception()) throw memory_access_exception(); uint32_t xrd = res_6; super::template write_mem(traits::CSR, csr, xrs1); - if(this->core.reg.trap_state>=0x80000000UL) throw memory_access_exception(); + if(has_synchronous_exception()) throw memory_access_exception(); *(X+rd) = xrd; } else { super::template write_mem(traits::CSR, csr, xrs1); - if(this->core.reg.trap_state>=0x80000000UL) throw memory_access_exception(); + if(has_synchronous_exception()) throw memory_access_exception(); } } } @@ -1607,12 +1613,12 @@ typename vm_base::virt_addr_t vm_impl::execute_inst(finish_cond_e co } else { uint32_t res_7 = super::template read_mem(traits::CSR, csr); - if(this->core.reg.trap_state>=0x80000000UL) throw memory_access_exception(); + if(has_synchronous_exception()) throw memory_access_exception(); uint32_t xrd = res_7; uint32_t xrs1 = *(X+rs1); if(rs1 != 0) { super::template write_mem(traits::CSR, csr, xrd | xrs1); - if(this->core.reg.trap_state>=0x80000000UL) throw memory_access_exception(); + if(has_synchronous_exception()) throw memory_access_exception(); } if(rd != 0) { *(X+rd) = xrd; @@ -1643,12 +1649,12 @@ typename vm_base::virt_addr_t vm_impl::execute_inst(finish_cond_e co } else { uint32_t res_8 = super::template read_mem(traits::CSR, csr); - if(this->core.reg.trap_state>=0x80000000UL) throw memory_access_exception(); + if(has_synchronous_exception()) throw memory_access_exception(); uint32_t xrd = res_8; uint32_t xrs1 = *(X+rs1); if(rs1 != 0) { super::template write_mem(traits::CSR, csr, xrd & ~xrs1); - if(this->core.reg.trap_state>=0x80000000UL) throw memory_access_exception(); + if(has_synchronous_exception()) throw memory_access_exception(); } if(rd != 0) { *(X+rd) = xrd; @@ -1679,10 +1685,10 @@ typename vm_base::virt_addr_t vm_impl::execute_inst(finish_cond_e co } else { uint32_t res_9 = super::template read_mem(traits::CSR, csr); - if(this->core.reg.trap_state>=0x80000000UL) throw memory_access_exception(); + if(has_synchronous_exception()) throw memory_access_exception(); uint32_t xrd = res_9; super::template write_mem(traits::CSR, csr, (uint32_t)zimm); - if(this->core.reg.trap_state>=0x80000000UL) throw memory_access_exception(); + if(has_synchronous_exception()) throw memory_access_exception(); if(rd != 0) { *(X+rd) = xrd; } @@ -1712,11 +1718,11 @@ typename vm_base::virt_addr_t vm_impl::execute_inst(finish_cond_e co } else { uint32_t res_10 = super::template read_mem(traits::CSR, csr); - if(this->core.reg.trap_state>=0x80000000UL) throw memory_access_exception(); + if(has_synchronous_exception()) throw memory_access_exception(); uint32_t xrd = res_10; if(zimm != 0) { super::template write_mem(traits::CSR, csr, xrd | (uint32_t)zimm); - if(this->core.reg.trap_state>=0x80000000UL) throw memory_access_exception(); + if(has_synchronous_exception()) throw memory_access_exception(); } if(rd != 0) { *(X+rd) = xrd; @@ -1747,11 +1753,11 @@ typename vm_base::virt_addr_t vm_impl::execute_inst(finish_cond_e co } else { uint32_t res_11 = super::template read_mem(traits::CSR, csr); - if(this->core.reg.trap_state>=0x80000000UL) throw memory_access_exception(); + if(has_synchronous_exception()) throw memory_access_exception(); uint32_t xrd = res_11; if(zimm != 0) { super::template write_mem(traits::CSR, csr, xrd & ~((uint32_t)zimm)); - if(this->core.reg.trap_state>=0x80000000UL) throw memory_access_exception(); + if(has_synchronous_exception()) throw memory_access_exception(); } if(rd != 0) { *(X+rd) = xrd; @@ -1777,7 +1783,7 @@ typename vm_base::virt_addr_t vm_impl::execute_inst(finish_cond_e co // execute instruction { super::template write_mem(traits::FENCE, traits::fencei, imm); - if(this->core.reg.trap_state>=0x80000000UL) throw memory_access_exception(); + if(has_synchronous_exception()) throw memory_access_exception(); } break; }// @suppress("No break at end of case") @@ -2095,7 +2101,7 @@ typename vm_base::virt_addr_t vm_impl::execute_inst(finish_cond_e co { uint32_t offs = (uint32_t)((uint64_t)(*(X+rs1 + 8)) + (uint64_t)(uimm)); int32_t res_12 = super::template read_mem(traits::MEM, offs); - if(this->core.reg.trap_state>=0x80000000UL) throw memory_access_exception(); + if(has_synchronous_exception()) throw memory_access_exception(); *(X+rd + 8) = (uint32_t)(int32_t)res_12; } break; @@ -2119,7 +2125,7 @@ typename vm_base::virt_addr_t vm_impl::execute_inst(finish_cond_e co { uint32_t offs = (uint32_t)((uint64_t)(*(X+rs1 + 8)) + (uint64_t)(uimm)); super::template write_mem(traits::MEM, offs, (uint32_t)*(X+rs2 + 8)); - if(this->core.reg.trap_state>=0x80000000UL) throw memory_access_exception(); + if(has_synchronous_exception()) throw memory_access_exception(); } break; }// @suppress("No break at end of case") @@ -2545,7 +2551,7 @@ typename vm_base::virt_addr_t vm_impl::execute_inst(finish_cond_e co else { uint32_t offs = (uint32_t)((uint64_t)(*(X+2)) + (uint64_t)(uimm)); int32_t res_13 = super::template read_mem(traits::MEM, offs); - if(this->core.reg.trap_state>=0x80000000UL) throw memory_access_exception(); + if(has_synchronous_exception()) throw memory_access_exception(); *(X+rd) = (uint32_t)(int32_t)res_13; } } @@ -2713,7 +2719,7 @@ typename vm_base::virt_addr_t vm_impl::execute_inst(finish_cond_e co else { uint32_t offs = (uint32_t)((uint64_t)(*(X+2)) + (uint64_t)(uimm)); super::template write_mem(traits::MEM, offs, (uint32_t)*(X+rs2)); - if(this->core.reg.trap_state>=0x80000000UL) throw memory_access_exception(); + if(has_synchronous_exception()) throw memory_access_exception(); } } break;