Skip to content

Commit 6233b76

Browse files
committed
fix(arm): correct write to ARM coprocessor
This code was commented out since 2021, but by default, the error code was initialized to `UC_REG_OK`, so there was no error returned until #1835, where this was changed to be initialized to `UC_REG_ERR_ARG`. As a result, any write to `UC_ARM_REG_C1_C0_2` returned an error.
1 parent d568885 commit 6233b76

File tree

2 files changed

+27
-5
lines changed

2 files changed

+27
-5
lines changed

qemu/target/arm/unicorn_arm.c

+4-4
Original file line numberDiff line numberDiff line change
@@ -434,10 +434,10 @@ uc_err reg_write(void *_env, int mode, unsigned int regid, const void *value,
434434
env->regs[15] = (*(uint32_t *)value & ~1);
435435
*setpc = 1;
436436
break;
437-
// case UC_ARM_REG_C1_C0_2:
438-
// env->cp15.c1_coproc = *(int32_t *)value;
439-
// break;
440-
437+
case UC_ARM_REG_C1_C0_2:
438+
CHECK_REG_TYPE(int32_t);
439+
env->cp15.cpacr_el1 = *(int32_t *)value;
440+
break;
441441
case UC_ARM_REG_C13_C0_3:
442442
CHECK_REG_TYPE(int32_t);
443443
env->cp15.tpidrro_el[0] = *(int32_t *)value;

tests/unit/test_arm.c

+23-1
Original file line numberDiff line numberDiff line change
@@ -815,6 +815,27 @@ static void test_armeb_be32_thumb2(void)
815815
OK(uc_close(uc));
816816
}
817817

818+
static void test_arm_cp15_c1_c0_2(void)
819+
{
820+
uc_engine *uc;
821+
uint32_t val = 0x12345678;
822+
uint32_t read_val;
823+
824+
// Initialize emulator in ARM mode
825+
OK(uc_open(UC_ARCH_ARM, UC_MODE_ARM, &uc));
826+
OK(uc_ctl_set_cpu_model(uc, UC_CPU_ARM_CORTEX_A15));
827+
828+
// Write to CP15 C1_C0_2
829+
OK(uc_reg_write(uc, UC_ARM_REG_C1_C0_2, &val));
830+
831+
// Read from CP15 C1_C0_2
832+
OK(uc_reg_read(uc, UC_ARM_REG_C1_C0_2, &read_val));
833+
834+
TEST_CHECK(read_val == val);
835+
836+
OK(uc_close(uc));
837+
}
838+
818839
TEST_LIST = {{"test_arm_nop", test_arm_nop},
819840
{"test_arm_thumb_sub", test_arm_thumb_sub},
820841
{"test_armeb_sub", test_armeb_sub},
@@ -840,4 +861,5 @@ TEST_LIST = {{"test_arm_nop", test_arm_nop},
840861
{"test_arm_context_save", test_arm_context_save},
841862
{"test_arm_thumb2", test_arm_thumb2},
842863
{"test_armeb_be32_thumb2", test_armeb_be32_thumb2},
843-
{NULL, NULL}};
864+
{"test_arm_cp15_c1_c0_2", test_arm_cp15_c1_c0_2},
865+
{NULL, NULL}};

0 commit comments

Comments
 (0)