-
Notifications
You must be signed in to change notification settings - Fork 1.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
continue in THUMB mode if CPSR register has T bit #1801
base: master
Are you sure you want to change the base?
Conversation
currently only PC | 1 being set will trigger thumb mode, but actually if T bit is set in CPSR, we should run in thumb mode.
There is already the function Can you provide a small example to show what is not correct handle? |
@PhilippTakacs view this #include <unicorn/unicorn.h>
#include <unicorn/arm.h>
#include <stdio.h>
static void hook_code(uc_engine *uc, uint64_t address, uint32_t size,
void *user_data)
{
printf(">>> Tracing instruction at 0x%" PRIx64
", instruction size = 0x%x\n",
address, size);
}
void run() {
// mov r0, 9; bx r0; <some thumb instruction>
#define ARM_CODE "\x09\x00\xA0\xE3\x10\xFF\x2F\xE1\x18\x88"
uc_engine *uc;
uc_err err;
uc_hook trace1;
// start in arm mode
err = uc_open(UC_ARCH_ARM, UC_MODE_ARM, &uc);
if (err) {
printf("failed uc_open!\n");
return;
}
uc_mem_map(uc, 0, 2 * 1024 * 1024, UC_PROT_ALL);
uc_mem_write(uc, 0, ARM_CODE, sizeof(ARM_CODE) - 1);
uc_hook_add(uc, &trace1, UC_HOOK_CODE, hook_code, NULL, 0, 0xFFFFFFFF);
uc_emu_start(uc, 0, 0 + sizeof(ARM_CODE) - 1, 0, 0);
return;
}
void step() {
// mov r0, 9; bx r0; <some thumb instruction>
#define ARM_CODE "\x09\x00\xA0\xE3\x10\xFF\x2F\xE1\x18\x88"
uc_engine *uc;
uc_err err;
uc_hook trace1;
int i;
// start in arm mode
err = uc_open(UC_ARCH_ARM, UC_MODE_ARM, &uc);
if (err) {
printf("failed uc_open!\n");
return;
}
uc_mem_map(uc, 0, 2 * 1024 * 1024, UC_PROT_ALL);
uc_mem_write(uc, 0, ARM_CODE, sizeof(ARM_CODE) - 1);
uc_hook_add(uc, &trace1, UC_HOOK_CODE, hook_code, NULL, 0, 0xFFFFFFFF);
for (i = 0; i < 3; i++) {
uint32_t pc;
uc_reg_read(uc, UC_ARM_REG_PC, &pc);
uc_emu_start(uc, pc, 0 + sizeof(ARM_CODE) - 1, 0, 1);
}
return;
}
int main(void)
{
printf(">>> emulation with 'run'\n");
run();
printf(">>> emulation with 'step'\n");
step();
return 0;
} they should behave the same, do you agree? |
(the current behavior is
|
with my PR they behave same:
|
I see the problem, but I'm unsure about the solution. Because what about setting THUMB mode direct like in following example:
Or what about going back to normal mode like in this example:
A better solution would be to check for |
|
Sorry for late on this discussion.
|
A bit context for my last comment. I understand the the motivation for this change, but it looks a bit inconsistent. Because there is already |
currently only PC | 1 being set will trigger thumb mode, but actually if T bit is set in CPSR, we should run in thumb mode.