Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions gen_input/templates/interp/CORENAME.cpp.gtl
Original file line number Diff line number Diff line change
Expand Up @@ -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};

Expand Down
130 changes: 68 additions & 62 deletions src/vm/interp/vm_rv32gc.cpp

Large diffs are not rendered by default.

130 changes: 68 additions & 62 deletions src/vm/interp/vm_rv32gcv.cpp

Large diffs are not rendered by default.

52 changes: 29 additions & 23 deletions src/vm/interp/vm_rv32i.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,12 @@ template <typename ARCH> class vm_impl : public iss::interp::vm_base<ARCH> {
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};

Expand Down Expand Up @@ -669,7 +675,7 @@ typename vm_base<ARCH>::virt_addr_t vm_impl<ARCH>::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<int8_t>(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;
Expand Down Expand Up @@ -701,7 +707,7 @@ typename vm_base<ARCH>::virt_addr_t vm_impl<ARCH>::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<int16_t>(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;
Expand Down Expand Up @@ -733,7 +739,7 @@ typename vm_base<ARCH>::virt_addr_t vm_impl<ARCH>::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<int32_t>(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;
Expand Down Expand Up @@ -765,7 +771,7 @@ typename vm_base<ARCH>::virt_addr_t vm_impl<ARCH>::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<uint8_t>(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;
Expand Down Expand Up @@ -797,7 +803,7 @@ typename vm_base<ARCH>::virt_addr_t vm_impl<ARCH>::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<uint16_t>(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;
Expand Down Expand Up @@ -829,7 +835,7 @@ typename vm_base<ARCH>::virt_addr_t vm_impl<ARCH>::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<uint8_t>(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;
Expand Down Expand Up @@ -857,7 +863,7 @@ typename vm_base<ARCH>::virt_addr_t vm_impl<ARCH>::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<uint16_t>(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;
Expand Down Expand Up @@ -885,7 +891,7 @@ typename vm_base<ARCH>::virt_addr_t vm_impl<ARCH>::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<uint32_t>(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;
Expand Down Expand Up @@ -1441,7 +1447,7 @@ typename vm_base<ARCH>::virt_addr_t vm_impl<ARCH>::execute_inst(finish_cond_e co
// execute instruction
{
super::template write_mem<uint32_t>(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")
Expand Down Expand Up @@ -1533,15 +1539,15 @@ typename vm_base<ARCH>::virt_addr_t vm_impl<ARCH>::execute_inst(finish_cond_e co
uint32_t xrs1 = *(X+rs1);
if(rd != 0) {
uint32_t res_6 = super::template read_mem<uint32_t>(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<uint32_t>(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<uint32_t>(traits::CSR, csr, xrs1);
if(this->core.reg.trap_state>=0x80000000UL) throw memory_access_exception();
if(has_synchronous_exception()) throw memory_access_exception();
}
}
}
Expand Down Expand Up @@ -1569,12 +1575,12 @@ typename vm_base<ARCH>::virt_addr_t vm_impl<ARCH>::execute_inst(finish_cond_e co
}
else {
uint32_t res_7 = super::template read_mem<uint32_t>(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<uint32_t>(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;
Expand Down Expand Up @@ -1605,12 +1611,12 @@ typename vm_base<ARCH>::virt_addr_t vm_impl<ARCH>::execute_inst(finish_cond_e co
}
else {
uint32_t res_8 = super::template read_mem<uint32_t>(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<uint32_t>(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;
Expand Down Expand Up @@ -1641,10 +1647,10 @@ typename vm_base<ARCH>::virt_addr_t vm_impl<ARCH>::execute_inst(finish_cond_e co
}
else {
uint32_t res_9 = super::template read_mem<uint32_t>(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<uint32_t>(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;
}
Expand Down Expand Up @@ -1674,11 +1680,11 @@ typename vm_base<ARCH>::virt_addr_t vm_impl<ARCH>::execute_inst(finish_cond_e co
}
else {
uint32_t res_10 = super::template read_mem<uint32_t>(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<uint32_t>(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;
Expand Down Expand Up @@ -1709,11 +1715,11 @@ typename vm_base<ARCH>::virt_addr_t vm_impl<ARCH>::execute_inst(finish_cond_e co
}
else {
uint32_t res_11 = super::template read_mem<uint32_t>(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<uint32_t>(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;
Expand All @@ -1739,7 +1745,7 @@ typename vm_base<ARCH>::virt_addr_t vm_impl<ARCH>::execute_inst(finish_cond_e co
// execute instruction
{
super::template write_mem<uint32_t>(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")
Expand Down
Loading
Loading