Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Instruction Pointer Updated for Illegal Instruction Codes #141

Closed
JoGei opened this issue Nov 20, 2023 · 2 comments
Closed

Instruction Pointer Updated for Illegal Instruction Codes #141

JoGei opened this issue Nov 20, 2023 · 2 comments
Assignees
Labels
bug Something isn't working help wanted Extra attention is needed

Comments

@JoGei
Copy link
Member

JoGei commented Nov 20, 2023

When encountering an Illegal Instruction, e.g., false opcode or target registers, the instruction pointer is still updated before the codeblock returns an exception.
When handling the exception the current Instruction Pointer is put in the MEPC such that software can identify the illegal instruction. In ETISS, this is not accurate because the instruction pointer was updated in the illegal instruction with its default increment (+2/+4) which leads to the MEPC being set not to the illegal instruction, but its default successor.

Here is an Example:

// -----------------------------------------------------------------------------
partInit.code() += "cpu->instructionPointer = " + std::to_string(ic.current_address_ + 2U) + ";\n";
if (imm == 0U) {
partInit.code() += "exception = ETISS_RETURNCODE_ILLEGALINSTRUCTION;\n";
}
if ((rd % 32U) != 0U) {
partInit.code() += "*((RV32IMACFD*)cpu)->X[" + std::to_string(rd % 32) + "] = " + std::to_string(((etiss_int32)((imm) << (14)) >> (14))) + ";\n";
}
partInit.code() += "if (exception) return exception;\n";
// -----------------------------------------------------------------------------

Possible fixes, I could think of:

  • only update instruction pointer on legal instructions
  • store the illegal instruction pointer somewhere to consume by exception handling
@JoGei JoGei added bug Something isn't working help wanted Extra attention is needed labels Nov 20, 2023
@wysiwyng
Copy link
Contributor

this should be fixed in #127, please test.

@JoGei
Copy link
Member Author

JoGei commented Nov 20, 2023

Yes looks good. Will close when #127 is upstream.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working help wanted Extra attention is needed
Projects
None yet
Development

No branches or pull requests

2 participants