Skip to content

Commit

Permalink
[BOX32][INTERP] Added some support for BOUND opcode ([ARM64_DYNAREC] …
Browse files Browse the repository at this point in the history
…too)
  • Loading branch information
ptitSeb committed Feb 20, 2025
1 parent ee3ee53 commit a252e87
Show file tree
Hide file tree
Showing 5 changed files with 50 additions and 9 deletions.
35 changes: 29 additions & 6 deletions src/dynarec/arm64/dynarec_arm64_00.c
Original file line number Diff line number Diff line change
Expand Up @@ -821,13 +821,36 @@ uintptr_t dynarec64_00(dynarec_arm_t* dyn, uintptr_t addr, uintptr_t ip, int nin
}
break;
case 0x62:
if(rex.is32bits) {
// BOUND here
DEFAULT;
INST_NAME("BOUND Gd, Ed");
nextop = F8;
if(rex.is32bits && MODREG) {
addr = geted(dyn, addr, ninst, nextop, &wback, x1, &fixedaddress, NULL, 0, 0, rex, NULL, 0, 0);
LDRxw_U12(x2, wback, 0);
LDRxw_U12(x3, wback, 4+(rex.w*4));
GETGD;
GETIP(ip);
CMPSxw_REG(gd, x2);
B_MARK(cLT);
CMPSxw_REG(gd, x3);
B_MARK(cGT);
B_NEXT_nocond;
MARK;
STORE_XEMU_CALL(xRIP);
CALL(native_br, -1);
LOAD_XEMU_CALL(xRIP);
} else {
INST_NAME("BOUND Gd, Ed");
nextop = F8;
FAKEED;
if(BOX64DRENV(dynarec_safeflags)>1) {
READFLAGS(X_PEND);
} else {
SETFLAGS(X_ALL, SF_SET_NODF); // Hack to set flags in "don't care" state
}
GETIP(ip);
STORE_XEMU_CALL(xRIP);
CALL(native_ud, -1);
LOAD_XEMU_CALL(xRIP);
jump_to_epilog(dyn, 0, xRIP, ninst);
*need_epilog = 0;
*ok = 0;
}
break;
case 0x63:
Expand Down
7 changes: 7 additions & 0 deletions src/dynarec/dynarec_native_functions.c
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,13 @@ void native_ud(x64emu_t* emu)
emit_signal(emu, SIGILL, (void*)R_RIP, 0);
}

void native_br(x64emu_t* emu)
{
if(BOX64ENV(dynarec_test))
emu->test.test = 0;
emit_signal(emu, SIGSEGV, (void*)R_RIP, 0xb09d);
}

void native_priv(x64emu_t* emu)
{
emu->test.test = 0;
Expand Down
1 change: 1 addition & 0 deletions src/dynarec/dynarec_native_functions.h
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ void native_pclmul_y(x64emu_t* emu, int gy, int vy, void* p, uint32_t u8);
void native_clflush(x64emu_t* emu, void* p);

void native_ud(x64emu_t* emu);
void native_br(x64emu_t* emu);
void native_priv(x64emu_t* emu);
void native_singlestep(x64emu_t* emu);
void native_int3(x64emu_t* emu);
Expand Down
9 changes: 6 additions & 3 deletions src/emu/x64run.c
Original file line number Diff line number Diff line change
Expand Up @@ -432,9 +432,12 @@ int Run(x64emu_t *emu, int step)
}
break;
case 0x62: /* BOUND Gd, Ed */
if(rex.is32bits) {
nextop = F8;
FAKEED(0);
nextop = F8;
if(rex.is32bits && MODREG) {
GETGD;
int* bounds = (int*)GETEA(0);
if(bounds[0]<GD->dword[0] || bounds[1]>GD->dword[0])
emit_signal(emu, SIGSEGV, (void*)R_RIP, 0xb09d);
} else {
unimp = 1;
goto fini;
Expand Down
7 changes: 7 additions & 0 deletions src/libtools/signals.c
Original file line number Diff line number Diff line change
Expand Up @@ -1241,6 +1241,10 @@ void my_sigactionhandler_oldcode_64(x64emu_t* emu, int32_t sig, int simple, sigi
sigcontext->uc_mcontext.gregs[X64_TRAPNO] = 14;
if(!mmapped) info2->si_code = 1;
info2->si_errno = 0;
} else if (info->si_errno==0xb09d) {
sigcontext->uc_mcontext.gregs[X64_ERR] = 0;
sigcontext->uc_mcontext.gregs[X64_TRAPNO] = 5;
info2->si_errno = 0;
}else {
sigcontext->uc_mcontext.gregs[X64_ERR] = 0x14|((sysmapped && !(real_prot&PROT_READ))?0:1);
sigcontext->uc_mcontext.gregs[X64_TRAPNO] = 14;
Expand Down Expand Up @@ -2088,6 +2092,9 @@ void emit_signal(x64emu_t* emu, int sig, void* addr, int code)
} else if(sig==SIGSEGV && code==0xecec) {
info.si_errno = 0xecec;
info.si_code = SEGV_ACCERR;
} else if (sig==SIGSEGV && code==0xb09d) {
info.si_errno = 0xb09d;
info.si_code = 0;
}
info.si_addr = addr;
const char* x64name = NULL;
Expand Down

0 comments on commit a252e87

Please sign in to comment.