fix(m68k): correct SR register read (#2161)

The SR register in the `CPUM68KState` struct does not contain the value
of the lower 5 flags. To compute them, we must OR the CCR values with
the SR register to get the true SR value.
This commit is contained in:
Amaan Qureshi
2025-04-12 23:03:08 -04:00
committed by GitHub
parent f0bdeb5a74
commit aa86641e16
7 changed files with 54 additions and 2 deletions

View File

@@ -37,4 +37,29 @@ static void test_move_to_sr(void)
OK(uc_close(uc));
}
TEST_LIST = {{"test_move_to_sr", test_move_to_sr}, {NULL, NULL}};
static void test_sr_contains_flags(void)
{
uc_engine *uc;
uint8_t code[] = {
0x76, 0xed, // moveq #-19, %d3
};
uint32_t d3, sr;
uc_common_setup(&uc, UC_ARCH_M68K, UC_MODE_BIG_ENDIAN, code, sizeof(code),
UC_CPU_M68K_M68000);
OK(uc_emu_start(uc, code_start, code_start + sizeof(code), 0, 0));
OK(uc_reg_read(uc, UC_M68K_REG_D3, &d3));
OK(uc_reg_read(uc, UC_M68K_REG_SR, &sr));
TEST_CHECK(d3 == 0xFFFFFFED);
TEST_CHECK((sr & 0x8) /* N flag */ == 0x8);
OK(uc_close(uc));
}
TEST_LIST = {{"test_move_to_sr", test_move_to_sr},
{"test_sr_contains_flags", test_sr_contains_flags},
{NULL, NULL}};