Skip to content

Commit

Permalink
generate error handling pseudo instruction
Browse files Browse the repository at this point in the history
  • Loading branch information
wysiwyng committed Sep 29, 2023
1 parent 8b7f87c commit 5dc331f
Showing 1 changed file with 29 additions and 1 deletion.
30 changes: 29 additions & 1 deletion src/Translation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -332,9 +332,37 @@ BlockLink *Translation::getBlock(BlockLink *prev, const etiss::uint64 &instructi
block.functionglobalCode().push_back("if (cpu->mode != " + toString(cpu_.mode) +
") return ETISS_RETURNCODE_RELOADCURRENTBLOCK;");

etiss::int32 transerror = translateBlock(block);

etiss::instr::InstructionContext err_ctx;
etiss::CodeSet err_cs;
auto vis = mis_->get(cpu_.mode);

err_ctx.cf_delay_slot_ = 0;
err_ctx.force_block_end_ = false;
err_ctx.force_append_next_instr_ = false;
err_ctx.force_block_end_ = false;
err_ctx.current_address_ = block.endaddress_;
err_ctx.current_local_address_ = block.endaddress_ - block.startindex_;
err_ctx.instr_width_fully_evaluated_ = true;
err_ctx.is_not_default_width_ = false;
err_ctx.instr_width_ = vis->width_;

auto err_ins = &vis->getMain()->getInvalid();

etiss::instr::BitArray errba(32, 0);
errba = etiss::RETURNCODE::ILLEGALINSTRUCTION;

err_ins->translate(errba, err_cs, err_ctx);

etiss::RegisterSet dummy;
bool err_ok;

auto err_str = "if (cpu->exception) {\n" + err_cs.toString(dummy, err_ok) + "\n}\n\n";

plugins_initCodeBlock_(plugins_array_, block);

etiss::int32 transerror = translateBlock(block);
block.functionglobalCode().insert(block.functionglobalCode().begin(), err_str);

if (transerror != ETISS_RETURNCODE_NOERROR)
{
Expand Down

0 comments on commit 5dc331f

Please sign in to comment.