Reorganized some CPU structures a bit and fixed inappropriate behavior of some mem.c functions on 64-bit binaries (and made mem.c aware of ARM64 as well), fixes both 64-bit recompilers, closes #1215.

This commit is contained in:
OBattler
2021-08-27 13:31:47 +02:00
parent eb827a6629
commit ddc7c5b78a
20 changed files with 181 additions and 176 deletions

View File

@@ -65,9 +65,8 @@ uint32_t old_rammask = 0xffffffff;
int soft_reset_mask = 0;
int in_smm = 0, smi_line = 0, smi_latched = 0, smm_in_hlt = 0;
int smi_block = 0;
uint32_t smbase = 0x30000;
int smi_latched = 0;
int smm_in_hlt = 0, smi_block = 0;
uint32_t addr64, addr64_2;
uint32_t addr64a[8], addr64a_2[8];
@@ -1845,7 +1844,6 @@ sysret(uint32_t fetchdat)
/* This is for compatibility with new x87 code. */
void codegen_set_rounding_mode(int mode)
{
/* cpu_state.new_npxc = (cpu_state.old_npxc & ~0xc00) | (cpu_state.npxc & 0xc00); */
cpu_state.new_npxc = (cpu_state.old_npxc & ~0xc00) | (mode << 10);
/* cpu_state.new_npxc = (cpu_state.old_npxc & ~0xc00) | (mode << 10); */
}
#endif

View File

@@ -391,10 +391,10 @@ exec386_dynarec_dyn(void)
codeblock_t *block = codeblock_hash[hash];
#endif
int valid_block = 0;
#ifdef USE_NEW_DYNAREC
if (!cpu_state.abrt)
#else
if (block && !cpu_state.abrt)
#endif
{
@@ -535,6 +535,9 @@ exec386_dynarec_dyn(void)
cpu_block_end = 0;
x86_was_reset = 0;
#if defined(__APPLE__) && defined(__aarch64__)
pthread_jit_write_protect_np(0);
#endif
codegen_block_start_recompile(block);
codegen_in_recompile = 1;
@@ -585,21 +588,21 @@ exec386_dynarec_dyn(void)
#endif
CPU_BLOCK_END();
if (cpu_state.flags & T_FLAG)
CPU_BLOCK_END();
if (smi_line)
CPU_BLOCK_END();
if (nmi && nmi_enable && nmi_mask)
CPU_BLOCK_END();
if ((cpu_state.flags & I_FLAG) && pic.int_pending && !cpu_end_block_after_ins)
CPU_BLOCK_END();
if (cpu_end_block_after_ins) {
cpu_end_block_after_ins--;
if (!cpu_end_block_after_ins)
CPU_BLOCK_END();
}
if (smi_line)
CPU_BLOCK_END();
else if (cpu_state.flags & T_FLAG)
CPU_BLOCK_END();
else if (nmi && nmi_enable && nmi_mask)
CPU_BLOCK_END();
else if ((cpu_state.flags & I_FLAG) && pic.int_pending && !cpu_end_block_after_ins)
CPU_BLOCK_END();
if (cpu_state.abrt) {
if (!(cpu_state.abrt & ABRT_EXPECTED))
codegen_block_remove();
@@ -616,6 +619,9 @@ exec386_dynarec_dyn(void)
codegen_reset();
codegen_in_recompile = 0;
#if defined(__APPLE__) && defined(__aarch64__)
pthread_jit_write_protect_np(1);
#endif
} else if (!cpu_state.abrt) {
/* Mark block but do not recompile */
#ifdef USE_NEW_DYNAREC
@@ -642,8 +648,8 @@ exec386_dynarec_dyn(void)
cpu_state.ssegs = 0;
codegen_endpc = (cs + cpu_state.pc) + 8;
fetchdat = fastreadl(cs + cpu_state.pc);
#ifdef ENABLE_386_DYNAREC_LOG
if (in_smm)
x386_dynarec_log("[%04X:%08X] fetchdat = %08X\n", CS, cpu_state.pc, fetchdat);
@@ -677,13 +683,13 @@ exec386_dynarec_dyn(void)
#endif
CPU_BLOCK_END();
if (cpu_state.flags & T_FLAG)
CPU_BLOCK_END();
if (smi_line)
CPU_BLOCK_END();
else if (cpu_state.flags & T_FLAG)
if (nmi && nmi_enable && nmi_mask)
CPU_BLOCK_END();
else if (nmi && nmi_enable && nmi_mask)
CPU_BLOCK_END();
else if ((cpu_state.flags & I_FLAG) && pic.int_pending && !cpu_end_block_after_ins)
if ((cpu_state.flags & I_FLAG) && pic.int_pending && !cpu_end_block_after_ins)
CPU_BLOCK_END();
if (cpu_end_block_after_ins) {

View File

@@ -210,11 +210,12 @@ typedef union {
} x86reg;
typedef struct {
uint32_t base;
uint32_t limit;
uint8_t access, ar_high;
int8_t checked; /*Non-zero if selector is known to be valid*/
uint16_t seg;
uint32_t base, limit,
limit_low, limit_high;
uint32_t limit_low, limit_high;
int checked; /*Non-zero if selector is known to be valid*/
} x86seg;
typedef union {
@@ -352,9 +353,9 @@ typedef struct {
} rm_data;
uint8_t ssegs, ismmx,
abrt, pad;
abrt, _smi_line;
int _cycles;
int _cycles, _in_smm;
uint16_t npxs, npxc;
@@ -364,8 +365,6 @@ typedef struct {
MMX_REG MM[8];
uint16_t old_npxc, new_npxc;
#ifdef USE_NEW_DYNAREC
uint32_t old_fp_control, new_fp_control;
#if defined i386 || defined __i386 || defined __i386__ || defined _X86_ || defined _M_IX86
@@ -374,6 +373,8 @@ typedef struct {
#if defined i386 || defined __i386 || defined __i386__ || defined _X86_ || defined _M_IX86 || defined __amd64__ || defined _M_X64
uint32_t trunc_fp_control;
#endif
#else
uint16_t old_npxc, new_npxc;
#endif
x86seg seg_cs, seg_ds, seg_es, seg_ss,
@@ -385,8 +386,17 @@ typedef struct {
} CR0;
uint16_t flags, eflags;
uint32_t _smbase;
} cpu_state_t;
#define in_smm cpu_state._in_smm
#define smi_line cpu_state._smi_line
#define smbase cpu_state._smbase
/*The cpu_state.flags below must match in both cpu_cur_status and block->status for a block
to be valid*/
#define CPU_STATUS_USE32 (1 << 0)
@@ -495,9 +505,8 @@ extern int hasfpu;
extern uint32_t cpu_features;
extern int in_smm, smi_line, smi_latched, smm_in_hlt;
extern int smi_latched, smm_in_hlt;
extern int smi_block;
extern uint32_t smbase;
#ifdef USE_NEW_DYNAREC
extern uint16_t cpu_cur_status;