Skip to content

Commit

Permalink
feat: Decode uarch ECALL and EBREAK
Browse files Browse the repository at this point in the history
  • Loading branch information
mpernambuco committed Dec 15, 2023
1 parent e8cafb4 commit 1f2871c
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 0 deletions.
44 changes: 44 additions & 0 deletions src/tests/machine-bind.lua
Original file line number Diff line number Diff line change
Expand Up @@ -1114,4 +1114,48 @@ do_test("Test unhappy paths of verify_uarch_step_state_transition", function(mac
assert_error("Mismatch in root hash of access 1", function(log) log.accesses[1].sibling_hashes[1] = bad_hash end)
end)

print("\n\n testing unsupported uarch instructions ")

local uarch_ecall_program = {
0x00000073, -- ecall
}

local uarch_ebreak_program = {
0x00100073, -- ebreak
}

local uarch_illegal_insn_program = {
0x00000000, -- some illegal instruction
}

test_util.make_do_test(build_machine, machine_type, {
uarch = {
ram = { image_filename = test_util.create_test_uarch_program(uarch_ecall_program) },
},
})("Detect unsupported ECALL instruction", function(machine)
local success, err = pcall(machine.run_uarch, machine)
assert(success == false)
assert(err:match("ECALL is not supported"))
end)

test_util.make_do_test(build_machine, machine_type, {
uarch = {
ram = { image_filename = test_util.create_test_uarch_program(uarch_ebreak_program) },
},
})("Detect unsupported EBREAK instruction", function(machine)
local success, err = pcall(machine.run_uarch, machine)
assert(success == false)
assert(err:match("EBREAK is not supported"))
end)

test_util.make_do_test(build_machine, machine_type, {
uarch = {
ram = { image_filename = test_util.create_test_uarch_program(uarch_illegal_insn_program) },
},
})("Detect illegal instruction", function(machine)
local success, err = pcall(machine.run_uarch, machine)
assert(success == false)
assert(err:match("illegal instruction"))
end)

print("\n\nAll machine binding tests for type " .. machine_type .. " passed")
4 changes: 4 additions & 0 deletions src/uarch-step.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1086,6 +1086,10 @@ static inline void executeInsn(UarchState &a, uint32 insn, uint64 pc) {
return executeSLTI(a, insn, pc);
} else if (insnMatchOpcodeFunct3(insn, 0xf, 0x0)) {
return executeFENCE(a, insn, pc);
} else if (insn == uint32(0x73)) {
throw std::runtime_error("ECALL is not supported");
} else if (insn == uint32(0x100073)) {
throw std::runtime_error("EBREAK is not supported");
}
throw std::runtime_error("illegal instruction");
}
Expand Down

0 comments on commit 1f2871c

Please sign in to comment.