Add test and close #1477

This commit is contained in:
lazymio 2021-11-03 21:40:13 +01:00
parent 1a82248292
commit 67e2386da6
No known key found for this signature in database
GPG Key ID: DFF27E34A47CB873
2 changed files with 31 additions and 0 deletions

View File

@ -380,6 +380,10 @@ static inline bool cpu_handle_exception(CPUState *cpu, int *ret)
// Unicorn: Imported from https://github.com/unicorn-engine/unicorn/pull/1098 // Unicorn: Imported from https://github.com/unicorn-engine/unicorn/pull/1098
CPUMIPSState *env = &(MIPS_CPU(cpu)->env); CPUMIPSState *env = &(MIPS_CPU(cpu)->env);
env->active_tc.PC = uc->next_pc; env->active_tc.PC = uc->next_pc;
#endif
#if defined(TARGET_RISCV)
CPURISCVState *env = &(RISCV_CPU(uc->cpu)->env);
env->pc += 4;
#endif #endif
// Unicorn: call registered interrupt callbacks // Unicorn: call registered interrupt callbacks
catched = false; catched = false;

View File

@ -341,6 +341,32 @@ static void test_riscv64_fp_move_to_int(void)
uc_close(uc); uc_close(uc);
} }
static void test_riscv64_ecall_cb(uc_engine *uc, uint32_t intno, void *data)
{
uc_emu_stop(uc);
return;
}
static void test_riscv64_ecall()
{
uc_engine *uc;
char code[] = "\x73\x00\x00\x00"; // ecall
uint64_t r_pc;
uc_hook h;
uc_common_setup(&uc, UC_ARCH_RISCV, UC_MODE_RISCV64, code,
sizeof(code) - 1);
OK(uc_hook_add(uc, &h, UC_HOOK_INTR, test_riscv64_ecall_cb, NULL, 1, 0));
OK(uc_emu_start(uc, code_start, code_start + sizeof(code) - 1, 0, 0));
OK(uc_reg_read(uc, UC_RISCV_REG_PC, &r_pc));
TEST_CHECK(r_pc == code_start + 4);
OK(uc_close(uc));
}
TEST_LIST = {{"test_riscv32_nop", test_riscv32_nop}, TEST_LIST = {{"test_riscv32_nop", test_riscv32_nop},
{"test_riscv64_nop", test_riscv64_nop}, {"test_riscv64_nop", test_riscv64_nop},
{"test_riscv32_3steps_pc_update", test_riscv32_3steps_pc_update}, {"test_riscv32_3steps_pc_update", test_riscv32_3steps_pc_update},
@ -351,4 +377,5 @@ TEST_LIST = {{"test_riscv32_nop", test_riscv32_nop},
{"test_riscv64_fp_move", test_riscv64_fp_move}, {"test_riscv64_fp_move", test_riscv64_fp_move},
{"test_riscv64_fp_move_from_int", test_riscv64_fp_move_from_int}, {"test_riscv64_fp_move_from_int", test_riscv64_fp_move_from_int},
{"test_riscv64_fp_move_to_int", test_riscv64_fp_move_to_int}, {"test_riscv64_fp_move_to_int", test_riscv64_fp_move_to_int},
{"test_riscv64_ecall", test_riscv64_ecall},
{NULL, NULL}}; {NULL, NULL}};