Skip to content

Commit f0826b1

Browse files
committed
[#2391] test: cover mret without U-mode
1 parent d7dd352 commit f0826b1

1 file changed

Lines changed: 25 additions & 0 deletions

File tree

tests/unit/test_riscv.c

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,30 @@ static void test_riscv64_nop(void)
5555
OK(uc_close(uc));
5656
}
5757

58+
static void test_riscv64_mret_without_u(void)
59+
{
60+
uc_engine *uc;
61+
const char code[] = "\x73\x00\x20\x30"; // mret
62+
uint64_t misa;
63+
uint64_t mstatus = 3ULL << 11;
64+
uint64_t mepc = code_start + sizeof(code) - 1;
65+
66+
OK(uc_open(UC_ARCH_RISCV, UC_MODE_RISCV64, &uc));
67+
OK(uc_mem_map(uc, code_start, code_len, UC_PROT_ALL));
68+
OK(uc_mem_write(uc, code_start, code, sizeof(code) - 1));
69+
OK(uc_reg_read(uc, UC_RISCV_REG_MISA, &misa));
70+
misa &= ~(1ULL << 20);
71+
OK(uc_reg_write(uc, UC_RISCV_REG_MISA, &misa));
72+
OK(uc_reg_write(uc, UC_RISCV_REG_MSTATUS, &mstatus));
73+
OK(uc_reg_write(uc, UC_RISCV_REG_MEPC, &mepc));
74+
75+
OK(uc_emu_start(uc, code_start,
76+
code_start + sizeof(code) - 1, 0, 0));
77+
OK(uc_reg_read(uc, UC_RISCV_REG_MSTATUS, &mstatus));
78+
TEST_CHECK(((mstatus >> 11) & 3) == 3);
79+
OK(uc_close(uc));
80+
}
81+
5882
static void test_riscv32_until_pc_update(void)
5983
{
6084
uc_engine *uc;
@@ -911,6 +935,7 @@ static void test_riscv_priv(void)
911935
TEST_LIST = {
912936
{"test_riscv32_nop", test_riscv32_nop},
913937
{"test_riscv64_nop", test_riscv64_nop},
938+
{"test_riscv64_mret_without_u", test_riscv64_mret_without_u},
914939
{"test_riscv32_3steps_pc_update", test_riscv32_3steps_pc_update},
915940
{"test_riscv64_3steps_pc_update", test_riscv64_3steps_pc_update},
916941
{"test_riscv64_until_at_page_end", test_riscv64_until_at_page_end},

0 commit comments

Comments
 (0)