-
-
Notifications
You must be signed in to change notification settings - Fork 299
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[ARM64_DYNAREC] Improved signal handling and flags handling (tbd on o…
…ther archs)
- Loading branch information
Showing
8 changed files
with
271 additions
and
50 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
#include <stddef.h> | ||
#include <stdio.h> | ||
#include <ucontext.h> | ||
|
||
#include "debug.h" | ||
#include "dynablock.h" | ||
#include "x64emu.h" | ||
#include "emu/x64emu_private.h" | ||
#include "x64run.h" | ||
#include "emu/x64run_private.h" | ||
#include "dynarec/dynablock_private.h" | ||
#include "dynarec_arm64_arch.h" | ||
|
||
size_t get_size_arch(dynarec_arm_t* dyn) | ||
{ | ||
if(!box64_dynarec_nativeflags) | ||
return 0; | ||
return dyn->isize*sizeof(arch_flags_t); | ||
} | ||
|
||
void populate_arch(dynarec_arm_t* dyn, void* p) | ||
{ | ||
if(!box64_dynarec_nativeflags) | ||
return; | ||
|
||
arch_flags_t* flags = p; | ||
for(int i=0; i<dyn->size; ++i) { | ||
flags[i].defered = dyn->insts[i].f_entry.dfnone==0; | ||
flags[i].vf = dyn->insts[i].need_nat_flags&NF_VF; | ||
flags[i].nf = dyn->insts[i].need_nat_flags&NF_SF; | ||
flags[i].eq = dyn->insts[i].need_nat_flags&NF_EQ; | ||
flags[i].cf = dyn->insts[i].need_nat_flags&NF_CF; | ||
flags[i].inv_cf = !dyn->insts[i].normal_carry; | ||
} | ||
} | ||
|
||
int getX64AddressInst(dynablock_t* db, uintptr_t native_addr); // define is signal.c | ||
|
||
// NZCV N | ||
#define NZCV_N 31 | ||
// NZCV Z | ||
#define NZCV_Z 30 | ||
// NZCV C | ||
#define NZCV_C 29 | ||
// NZCV V | ||
#define NZCV_V 28 | ||
|
||
void adjust_arch(dynablock_t* db, x64emu_t* emu, ucontext_t* p, uintptr_t x64pc) | ||
{ | ||
if(!db->arch_size || !db->arch) | ||
return; | ||
arch_flags_t* flags = db->arch; | ||
int ninst = getX64AddressInst(db, x64pc); | ||
printf_log(LOG_INFO, "adjust_arch(...), db=%p, x64pc=%p, nints=%d, flags:%s %c%c%c%c%s\n", db, (void*)x64pc, ninst, flags[ninst-1].defered?"defered":"", flags[ninst-1].vf?'V':' ', flags[ninst-1].nf?'S':' ', flags[ninst-1].eq?'Z':' ', flags[ninst-1].cf?'C':' ', (flags[ninst-1].cf && flags[ninst-1].inv_cf)?"inverted":""); | ||
if(ninst<0) | ||
return; | ||
if(ninst==0) { | ||
CHECK_FLAGS(emu); | ||
return; | ||
} | ||
if(flags[ninst-1].defered) { | ||
CHECK_FLAGS(emu); | ||
//return; | ||
} | ||
if(flags[ninst-1].nf) { | ||
CONDITIONAL_SET_FLAG(p->uc_mcontext.pstate&(1<<NZCV_N), F_SF); | ||
} | ||
if(flags[ninst-1].vf) { | ||
CONDITIONAL_SET_FLAG(p->uc_mcontext.pstate&(1<<NZCV_V), F_OF); | ||
} | ||
if(flags[ninst-1].eq) { | ||
CONDITIONAL_SET_FLAG(p->uc_mcontext.pstate&(1<<NZCV_Z), F_ZF); | ||
} | ||
if(flags[ninst-1].cf) { | ||
if(flags[ninst-1].inv_cf) { | ||
CONDITIONAL_SET_FLAG((p->uc_mcontext.pstate&(1<<NZCV_C))==0, F_CF); | ||
} else { | ||
CONDITIONAL_SET_FLAG(p->uc_mcontext.pstate&(1<<NZCV_C), F_CF); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
#ifndef __DYNAREC_ARM_ARCH_H__ | ||
#define __DYNAREC_ARM_ARCH_H__ | ||
|
||
#include <stddef.h> | ||
#include <ucontext.h> | ||
|
||
#include "x64emu.h" | ||
#include "box64context.h" | ||
#include "dynarec.h" | ||
#include "dynarec_arm64_private.h" | ||
|
||
typedef struct arch_flags_s | ||
{ | ||
uint8_t defered:1; | ||
uint8_t nf:1; | ||
uint8_t eq:1; | ||
uint8_t vf:1; | ||
uint8_t cf:1; | ||
uint8_t inv_cf:1; | ||
} arch_flags_t; | ||
|
||
// get size of arch specific info (can be 0) | ||
size_t get_size_arch(dynarec_arm_t* dyn); | ||
//populate the array | ||
void populate_arch(dynarec_arm_t* dyn, void* p); | ||
//adjust flags and more | ||
void adjust_arch(dynablock_t* db, x64emu_t* emu, ucontext_t* p, uintptr_t native_addr); | ||
#endif // __DYNAREC_ARM_ARCH_H__ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.