From 86de536c8fd176cbcfc31d2d8bb8c86f5d0f414e Mon Sep 17 00:00:00 2001 From: Eyck-Alexander Jentzsch Date: Tue, 23 Jul 2024 14:35:31 +0200 Subject: [PATCH] changes jh globals to seperate riscv specifics --- gen_input/templates/asmjit/CORENAME.cpp.gtl | 23 ++++++++++++++++++--- src/vm/asmjit/vm_tgc5c.cpp | 23 ++++++++++++++++++--- 2 files changed, 40 insertions(+), 6 deletions(-) diff --git a/gen_input/templates/asmjit/CORENAME.cpp.gtl b/gen_input/templates/asmjit/CORENAME.cpp.gtl index 5749f29..9ad7de4 100644 --- a/gen_input/templates/asmjit/CORENAME.cpp.gtl +++ b/gen_input/templates/asmjit/CORENAME.cpp.gtl @@ -91,7 +91,6 @@ protected: using super::gen_wait; using super::gen_leave; using super::gen_sync; - using super::gen_set_tval; using this_class = vm_impl; using compile_func = continuation_e (this_class::*)(virt_addr_t&, code_word_t, jit_holder&); @@ -104,6 +103,8 @@ protected: void gen_instr_prologue(jit_holder& jh); void gen_instr_epilogue(jit_holder& jh); inline void gen_raise(jit_holder& jh, uint16_t trap_id, uint16_t cause); + template >> void gen_set_tval(jit_holder& jh, T new_tval) ; + void gen_set_tval(jit_holder& jh, x86_reg_t _new_tval) ; template::type> inline S sext(U from) { @@ -260,7 +261,7 @@ template void vm_impl::gen_block_prologue(jit_holder& jh){ jh.pc = load_reg_from_mem_Gp(jh, traits::PC); jh.next_pc = load_reg_from_mem_Gp(jh, traits::NEXT_PC); - jh.tval = get_reg_Gp(jh.cc, 64, false); + jh.globals["tval"] = get_reg_Gp(jh.cc, 64, false); } template void vm_impl::gen_block_epilogue(jit_holder& jh){ @@ -283,7 +284,7 @@ void vm_impl::gen_block_epilogue(jit_holder& jh){ call_enter_trap->setArg(0, jh.arch_if_ptr); call_enter_trap->setArg(1, current_trap_state); call_enter_trap->setArg(2, current_pc); - call_enter_trap->setArg(3, jh.tval); + call_enter_trap->setArg(3, jh.globals["tval"]); x86_reg_t current_next_pc = get_reg_for(cc, traits::NEXT_PC); mov(cc, current_next_pc, get_ptr_for(jh, traits::NEXT_PC)); @@ -300,6 +301,22 @@ inline void vm_impl::gen_raise(jit_holder& jh, uint16_t trap_id, uint16_t mov(cc, tmp1, 0x80ULL << 24 | (cause << 16) | trap_id); mov(cc, get_ptr_for(jh, traits::TRAP_STATE), tmp1); } +template +template +void vm_impl::gen_set_tval(jit_holder& jh, T new_tval) { + mov(jh.cc, jh.globals["tval"], new_tval); + } +template +void vm_impl::gen_set_tval(jit_holder& jh, x86_reg_t _new_tval) { + if(std::holds_alternative(_new_tval)) { + x86::Gp new_tval = std::get(_new_tval); + if(new_tval.size() < 8) + new_tval = gen_ext_Gp(jh.cc, new_tval, 64, false); + mov(jh.cc, jh.globals["tval"], new_tval); + } else { + throw std::runtime_error("Variant not supported in gen_set_tval"); + } +} } // namespace tgc5c diff --git a/src/vm/asmjit/vm_tgc5c.cpp b/src/vm/asmjit/vm_tgc5c.cpp index 859c65c..f9d774d 100644 --- a/src/vm/asmjit/vm_tgc5c.cpp +++ b/src/vm/asmjit/vm_tgc5c.cpp @@ -91,7 +91,6 @@ protected: using super::gen_wait; using super::gen_leave; using super::gen_sync; - using super::gen_set_tval; using this_class = vm_impl; using compile_func = continuation_e (this_class::*)(virt_addr_t&, code_word_t, jit_holder&); @@ -104,6 +103,8 @@ protected: void gen_instr_prologue(jit_holder& jh); void gen_instr_epilogue(jit_holder& jh); inline void gen_raise(jit_holder& jh, uint16_t trap_id, uint16_t cause); + template >> void gen_set_tval(jit_holder& jh, T new_tval) ; + void gen_set_tval(jit_holder& jh, x86_reg_t _new_tval) ; template::type> inline S sext(U from) { @@ -4800,7 +4801,7 @@ template void vm_impl::gen_block_prologue(jit_holder& jh){ jh.pc = load_reg_from_mem_Gp(jh, traits::PC); jh.next_pc = load_reg_from_mem_Gp(jh, traits::NEXT_PC); - jh.tval = get_reg_Gp(jh.cc, 64, false); + jh.globals["tval"] = get_reg_Gp(jh.cc, 64, false); } template void vm_impl::gen_block_epilogue(jit_holder& jh){ @@ -4823,7 +4824,7 @@ void vm_impl::gen_block_epilogue(jit_holder& jh){ call_enter_trap->setArg(0, jh.arch_if_ptr); call_enter_trap->setArg(1, current_trap_state); call_enter_trap->setArg(2, current_pc); - call_enter_trap->setArg(3, jh.tval); + call_enter_trap->setArg(3, jh.globals["tval"]); x86_reg_t current_next_pc = get_reg_for(cc, traits::NEXT_PC); mov(cc, current_next_pc, get_ptr_for(jh, traits::NEXT_PC)); @@ -4840,6 +4841,22 @@ inline void vm_impl::gen_raise(jit_holder& jh, uint16_t trap_id, uint16_t mov(cc, tmp1, 0x80ULL << 24 | (cause << 16) | trap_id); mov(cc, get_ptr_for(jh, traits::TRAP_STATE), tmp1); } +template +template +void vm_impl::gen_set_tval(jit_holder& jh, T new_tval) { + mov(jh.cc, jh.globals["tval"], new_tval); + } +template +void vm_impl::gen_set_tval(jit_holder& jh, x86_reg_t _new_tval) { + if(std::holds_alternative(_new_tval)) { + x86::Gp new_tval = std::get(_new_tval); + if(new_tval.size() < 8) + new_tval = gen_ext_Gp(jh.cc, new_tval, 64, false); + mov(jh.cc, jh.globals["tval"], new_tval); + } else { + throw std::runtime_error("Variant not supported in gen_set_tval"); + } +} } // namespace tgc5c