From 70839bbbf2ffd76e9bb8c00edf6c4b0d361139b0 Mon Sep 17 00:00:00 2001 From: Eyck-Alexander Jentzsch Date: Sat, 23 Sep 2023 10:35:21 +0200 Subject: [PATCH] changes templates for correct plugin callback in case of trap --- gen_input/templates/tcc/CORENAME.cpp.gtl | 2 ++ src/vm/tcc/vm_tgc5c.cpp | 26 +++++++++++++----------- 2 files changed, 16 insertions(+), 12 deletions(-) diff --git a/gen_input/templates/tcc/CORENAME.cpp.gtl b/gen_input/templates/tcc/CORENAME.cpp.gtl index 9900d60..1a51d40 100644 --- a/gen_input/templates/tcc/CORENAME.cpp.gtl +++ b/gen_input/templates/tcc/CORENAME.cpp.gtl @@ -305,6 +305,8 @@ template void vm_impl::gen_wait(tu_builder& tu, unsigned t } template void vm_impl::gen_trap_behavior(tu_builder& tu) { + tu("trap_entry_plugin:"); + this->gen_sync(tu, POST_SYNC, -1); tu("trap_entry:"); tu("enter_trap(core_ptr, *trap_state, *pc, 0);"); tu.store(traits::LAST_BRANCH, tu.constant(std::numeric_limits::max(),32)); diff --git a/src/vm/tcc/vm_tgc5c.cpp b/src/vm/tcc/vm_tgc5c.cpp index 5e93d1a..a94d30a 100644 --- a/src/vm/tcc/vm_tgc5c.cpp +++ b/src/vm/tcc/vm_tgc5c.cpp @@ -462,12 +462,11 @@ private: this->gen_raise_trap(tu, 0, 2); } else{ - auto addr_mask = tu.assignment(tu.constant((uint32_t)- 2,32),32); auto new_pc = tu.assignment(tu.ext((tu.bitwise_and( (tu.add( tu.load(rs1+ traits::X0, 0), tu.constant((int16_t)sext<12>(imm),16))), - addr_mask)),32,false),32); + tu.constant(~ 0x1,8))),32,false),32); tu.open_if(tu.urem( new_pc, tu.constant(static_cast(traits:: INSTR_ALIGNMENT),32))); @@ -477,7 +476,9 @@ private: tu.store(rd + traits::X0, tu.constant((uint32_t)(PC+ 4),32)); } - auto PC_val_v = tu.assignment("PC_val", new_pc,32); + auto PC_val_v = tu.assignment("PC_val", tu.bitwise_and( + new_pc, + tu.constant(~ 0x1,8)),32); tu.store(traits::NEXT_PC, PC_val_v); tu.store(traits::LAST_BRANCH, tu.constant(2U, 2)); tu.close_scope(); @@ -2472,7 +2473,7 @@ private: tu.open_if(tu.icmp(ICmpInst::ICMP_NE, tu.load(rs2+ traits::X0, 0), tu.constant( 0,8))); - auto MMIN = tu.assignment(tu.constant((uint32_t)1<<(static_cast(traits:: XLEN)-1),32),32); + auto MMIN = tu.assignment(tu.constant( 1<<(static_cast(traits:: XLEN)-1),8),32); tu.open_if(tu.logical_and( tu.icmp(ICmpInst::ICMP_EQ, tu.load(rs1+ traits::X0, 0), @@ -3303,12 +3304,12 @@ private: pc=pc+ 2; gen_set_pc(tu, pc, traits::NEXT_PC); tu.open_scope(); - if(rs1&&rs1(traits:: RFS)){ auto addr_mask = tu.assignment(tu.constant((uint32_t)- 2,32),32); - auto PC_val_v = tu.assignment("PC_val", tu.bitwise_and( - tu.load(rs1%static_cast(traits:: RFS)+ traits::X0, 0), - addr_mask),32); - tu.store(traits::NEXT_PC, PC_val_v); - tu.store(traits::LAST_BRANCH, tu.constant(2U, 2)); + if(rs1&&rs1(traits:: RFS)) { + auto PC_val_v = tu.assignment("PC_val", tu.bitwise_and( + tu.load(rs1%static_cast(traits:: RFS)+ traits::X0, 0), + tu.constant(~ 0x1,8)),32); + tu.store(traits::NEXT_PC, PC_val_v); + tu.store(traits::LAST_BRANCH, tu.constant(2U, 2)); } else{ this->gen_raise_trap(tu, 0, 2); @@ -3401,13 +3402,12 @@ private: this->gen_raise_trap(tu, 0, 2); } else{ - auto addr_mask = tu.assignment(tu.constant((uint32_t)- 2,32),32); auto new_pc = tu.assignment(tu.load(rs1+ traits::X0, 0),32); tu.store(1 + traits::X0, tu.constant((uint32_t)(PC+ 2),32)); auto PC_val_v = tu.assignment("PC_val", tu.bitwise_and( new_pc, - addr_mask),32); + tu.constant(~ 0x1,8)),32); tu.store(traits::NEXT_PC, PC_val_v); tu.store(traits::LAST_BRANCH, tu.constant(2U, 2)); } @@ -3626,6 +3626,8 @@ template void vm_impl::gen_wait(tu_builder& tu, unsigned t } template void vm_impl::gen_trap_behavior(tu_builder& tu) { + tu("trap_entry_plugin:"); + this->gen_sync(tu, POST_SYNC, -1); tu("trap_entry:"); tu("enter_trap(core_ptr, *trap_state, *pc, 0);"); tu.store(traits::LAST_BRANCH, tu.constant(std::numeric_limits::max(),32));