From fa9d9381b7d82a7ea2b2a4989e589087ae8b0641 Mon Sep 17 00:00:00 2001 From: SarahW Date: Fri, 2 Jun 2017 22:01:09 +0100 Subject: [PATCH] Clear flat DS/SS status on segment load during block. Fixes LBA 2. --- src/codegen_ops_x86-64.h | 87 +++++++++++++--------------------------- src/codegen_ops_x86.h | 66 ++++++++++-------------------- src/codegen_x86-64.c | 5 ++- src/codegen_x86.c | 4 ++ src/x86.h | 3 ++ src/x86seg.c | 8 ++++ 6 files changed, 68 insertions(+), 105 deletions(-) diff --git a/src/codegen_ops_x86-64.h b/src/codegen_ops_x86-64.h index 561b73a..3742053 100644 --- a/src/codegen_ops_x86-64.h +++ b/src/codegen_ops_x86-64.h @@ -869,9 +869,7 @@ static inline void CHECK_SEG_READ(x86seg *seg) return; if (seg->checked) return; - if ((seg == &_ds) && (cpu_cur_status & CPU_STATUS_FLATDS)) - return; - if ((seg == &_ss) && (cpu_cur_status & CPU_STATUS_FLATSS)) + if ((seg == &_ds) && codegen_flat_ds) return; if (IS_32_ADDR(&seg->base)) @@ -907,9 +905,7 @@ static inline void CHECK_SEG_WRITE(x86seg *seg) return; if (seg->checked) return; - if ((seg == &_ds) && (cpu_cur_status & CPU_STATUS_FLATDS)) - return; - if ((seg == &_ss) && (cpu_cur_status & CPU_STATUS_FLATSS)) + if ((seg == &_ds) && codegen_flat_ds) return; if (IS_32_ADDR(&seg->base)) @@ -937,9 +933,7 @@ static inline void CHECK_SEG_WRITE(x86seg *seg) } static inline void CHECK_SEG_LIMITS(x86seg *seg, int end_offset) { - if ((seg == &_ds) && (cpu_cur_status & CPU_STATUS_FLATDS)) - return; - if ((seg == &_ss) && (cpu_cur_status & CPU_STATUS_FLATSS)) + if ((seg == &_ds && codegen_flat_ds) || (seg == &_ss && codegen_flat_ss)) return; if (IS_32_ADDR(&seg->base)) @@ -978,8 +972,7 @@ static inline void CHECK_SEG_LIMITS(x86seg *seg, int end_offset) static inline void MEM_LOAD_ADDR_EA_B(x86seg *seg) { - if (((seg == &_ds) && (cpu_cur_status & CPU_STATUS_FLATDS)) || - ((seg == &_ss) && (cpu_cur_status & CPU_STATUS_FLATSS))) + if ((seg == &_ds && codegen_flat_ds) || (seg == &_ss && codegen_flat_ss)) { addbyte(0x31); /*XOR ECX, ECX*/ addbyte(0xc9); @@ -1052,8 +1045,7 @@ static inline void MEM_LOAD_ADDR_EA_B(x86seg *seg) } static inline void MEM_LOAD_ADDR_EA_W(x86seg *seg) { - if (((seg == &_ds) && (cpu_cur_status & CPU_STATUS_FLATDS)) || - ((seg == &_ss) && (cpu_cur_status & CPU_STATUS_FLATSS))) + if ((seg == &_ds && codegen_flat_ds) || (seg == &_ss && codegen_flat_ss)) { addbyte(0x31); /*XOR ECX, ECX*/ addbyte(0xc9); @@ -1142,8 +1134,7 @@ static inline void MEM_LOAD_ADDR_EA_W_OFFSET(x86seg *seg, int offset) } static inline void MEM_LOAD_ADDR_EA_L(x86seg *seg) { - if (((seg == &_ds) && (cpu_cur_status & CPU_STATUS_FLATDS)) || - ((seg == &_ss) && (cpu_cur_status & CPU_STATUS_FLATSS))) + if ((seg == &_ds && codegen_flat_ds) || (seg == &_ss && codegen_flat_ss)) { addbyte(0x31); /*XOR ECX, ECX*/ addbyte(0xc9); @@ -1224,8 +1215,7 @@ static inline void MEM_LOAD_ADDR_EA_L(x86seg *seg) } static inline void MEM_LOAD_ADDR_EA_Q(x86seg *seg) { - if (((seg == &_ds) && (cpu_cur_status & CPU_STATUS_FLATDS)) || - ((seg == &_ss) && (cpu_cur_status & CPU_STATUS_FLATSS))) + if ((seg == &_ds && codegen_flat_ds) || (seg == &_ss && codegen_flat_ss)) { addbyte(0x31); /*XOR ECX, ECX*/ addbyte(0xc9); @@ -1349,8 +1339,7 @@ static inline void MEM_STORE_ADDR_EA_B(x86seg *seg, int host_reg) addbyte(8); host_reg = 8; } - if (((seg == &_ds) && (cpu_cur_status & CPU_STATUS_FLATDS)) || - ((seg == &_ss) && (cpu_cur_status & CPU_STATUS_FLATSS))) + if ((seg == &_ds && codegen_flat_ds) || (seg == &_ss && codegen_flat_ss)) { addbyte(0x31); /*XOR ECX, ECX*/ addbyte(0xc9); @@ -1434,8 +1423,7 @@ static inline void MEM_STORE_ADDR_EA_B(x86seg *seg, int host_reg) } static inline void MEM_STORE_ADDR_EA_W(x86seg *seg, int host_reg) { - if (((seg == &_ds) && (cpu_cur_status & CPU_STATUS_FLATDS)) || - ((seg == &_ss) && (cpu_cur_status & CPU_STATUS_FLATSS))) + if ((seg == &_ds && codegen_flat_ds) || (seg == &_ss && codegen_flat_ss)) { addbyte(0x31); /*XOR ECX, ECX*/ addbyte(0xc9); @@ -1530,8 +1518,7 @@ static inline void MEM_STORE_ADDR_EA_W(x86seg *seg, int host_reg) } static inline void MEM_STORE_ADDR_EA_L(x86seg *seg, int host_reg) { - if (((seg == &_ds) && (cpu_cur_status & CPU_STATUS_FLATDS)) || - ((seg == &_ss) && (cpu_cur_status & CPU_STATUS_FLATSS))) + if ((seg == &_ds && codegen_flat_ds) || (seg == &_ss && codegen_flat_ss)) { addbyte(0x31); /*XOR ECX, ECX*/ addbyte(0xc9); @@ -1624,8 +1611,7 @@ static inline void MEM_STORE_ADDR_EA_L(x86seg *seg, int host_reg) } static inline void MEM_STORE_ADDR_EA_Q(x86seg *seg, int host_reg, int host_reg2) { - if (((seg == &_ds) && (cpu_cur_status & CPU_STATUS_FLATDS)) || - ((seg == &_ss) && (cpu_cur_status & CPU_STATUS_FLATSS))) + if ((seg == &_ds && codegen_flat_ds) || (seg == &_ss && codegen_flat_ss)) { addbyte(0x31); /*XOR ECX, ECX*/ addbyte(0xc9); @@ -5318,8 +5304,7 @@ static inline void MEM_CHECK_WRITE(x86seg *seg) CHECK_SEG_WRITE(seg); - if (((seg == &_ds) && (cpu_cur_status & CPU_STATUS_FLATDS)) || - ((seg == &_ss) && (cpu_cur_status & CPU_STATUS_FLATSS))) + if ((seg == &_ds && codegen_flat_ds) || (seg == &_ss && codegen_flat_ss)) { addbyte(0x31); /*XOR ESI, ESI*/ addbyte(0xf6); @@ -5371,8 +5356,7 @@ static inline void MEM_CHECK_WRITE(x86seg *seg) addbyte(0xc1); /*SHR EDI, 12*/ addbyte(0xef); addbyte(12); - if (!((seg == &_ds) && (cpu_cur_status & CPU_STATUS_FLATDS)) && - !((seg == &_ss) && (cpu_cur_status & CPU_STATUS_FLATSS))) + if (!(seg == &_ds && codegen_flat_ds) && !(seg == &_ss && codegen_flat_ss)) { addbyte(0x83); /*CMP ESI, -1*/ addbyte(0xfe); @@ -5404,8 +5388,7 @@ static inline void MEM_CHECK_WRITE(x86seg *seg) addbyte(0); // addbyte(0xc3); /*RET*/ - if (!((seg == &_ds) && (cpu_cur_status & CPU_STATUS_FLATDS)) && - !((seg == &_ss) && (cpu_cur_status & CPU_STATUS_FLATSS))) + if (!(seg == &_ds && codegen_flat_ds) && !(seg == &_ss && codegen_flat_ss)) *jump3 = (uintptr_t)&codeblock[block_current].data[block_pos] - (uintptr_t)jump3 - 1; /*slowpath:*/ addbyte(0x67); /*LEA EDI, [EAX+ESI]*/ @@ -5451,8 +5434,7 @@ static inline void MEM_CHECK_WRITE_W(x86seg *seg) CHECK_SEG_WRITE(seg); - if (((seg == &_ds) && (cpu_cur_status & CPU_STATUS_FLATDS)) || - ((seg == &_ss) && (cpu_cur_status & CPU_STATUS_FLATSS))) + if ((seg == &_ds && codegen_flat_ds) || (seg == &_ss && codegen_flat_ss)) { addbyte(0x31); /*XOR ESI, ESI*/ addbyte(0xf6); @@ -5500,8 +5482,7 @@ static inline void MEM_CHECK_WRITE_W(x86seg *seg) addbyte(0x79); /*JNS +*/ jump1 = &codeblock[block_current].data[block_pos]; addbyte(0); - if (!((seg == &_ds) && (cpu_cur_status & CPU_STATUS_FLATDS)) && - !((seg == &_ss) && (cpu_cur_status & CPU_STATUS_FLATSS))) + if (!(seg == &_ds && codegen_flat_ds) && !(seg == &_ss && codegen_flat_ss)) { addbyte(0x83); /*CMP ESI, -1*/ addbyte(0xfe); @@ -5510,8 +5491,7 @@ static inline void MEM_CHECK_WRITE_W(x86seg *seg) addbyte(0x8d); /*LEA ESI, 1[EDI]*/ addbyte(0x77); addbyte(0x01); - if (!((seg == &_ds) && (cpu_cur_status & CPU_STATUS_FLATDS)) && - !((seg == &_ss) && (cpu_cur_status & CPU_STATUS_FLATSS))) + if (!(seg == &_ds && codegen_flat_ds) && !(seg == &_ss && codegen_flat_ss)) { addbyte(0x74); /*JE slowpath*/ jump4 = &codeblock[block_current].data[block_pos]; @@ -5567,8 +5547,7 @@ static inline void MEM_CHECK_WRITE_W(x86seg *seg) /*slowpath:*/ *jump2 = (uintptr_t)&codeblock[block_current].data[block_pos] - (uintptr_t)jump2 - 1; - if (!((seg == &_ds) && (cpu_cur_status & CPU_STATUS_FLATDS)) && - !((seg == &_ss) && (cpu_cur_status & CPU_STATUS_FLATSS))) + if (!(seg == &_ds && codegen_flat_ds) && !(seg == &_ss && codegen_flat_ss)) *jump4 = (uintptr_t)&codeblock[block_current].data[block_pos] - (uintptr_t)jump4 - 1; jump_pos = block_pos; load_param_1_reg_32(REG_EBX); @@ -5604,8 +5583,7 @@ static inline void MEM_CHECK_WRITE_L(x86seg *seg) CHECK_SEG_WRITE(seg); - if (((seg == &_ds) && (cpu_cur_status & CPU_STATUS_FLATDS)) || - ((seg == &_ss) && (cpu_cur_status & CPU_STATUS_FLATSS))) + if ((seg == &_ds && codegen_flat_ds) || (seg == &_ss && codegen_flat_ss)) { addbyte(0x31); /*XOR ESI, ESI*/ addbyte(0xf6); @@ -5653,8 +5631,7 @@ static inline void MEM_CHECK_WRITE_L(x86seg *seg) addbyte(0x79); /*JNS +*/ jump1 = &codeblock[block_current].data[block_pos]; addbyte(0); - if (!((seg == &_ds) && (cpu_cur_status & CPU_STATUS_FLATDS)) && - !((seg == &_ss) && (cpu_cur_status & CPU_STATUS_FLATSS))) + if (!(seg == &_ds && codegen_flat_ds) && !(seg == &_ss && codegen_flat_ss)) { addbyte(0x83); /*CMP ESI, -1*/ addbyte(0xfe); @@ -5663,8 +5640,7 @@ static inline void MEM_CHECK_WRITE_L(x86seg *seg) addbyte(0x8d); /*LEA ESI, 3[EDI]*/ addbyte(0x77); addbyte(0x03); - if (!((seg == &_ds) && (cpu_cur_status & CPU_STATUS_FLATDS)) && - !((seg == &_ss) && (cpu_cur_status & CPU_STATUS_FLATSS))) + if (!(seg == &_ds && codegen_flat_ds) && !(seg == &_ss && codegen_flat_ss)) { addbyte(0x74); /*JE slowpath*/ jump4 = &codeblock[block_current].data[block_pos]; @@ -5720,8 +5696,7 @@ static inline void MEM_CHECK_WRITE_L(x86seg *seg) /*slowpath:*/ *jump2 = (uintptr_t)&codeblock[block_current].data[block_pos] - (uintptr_t)jump2 - 1; - if (!((seg == &_ds) && (cpu_cur_status & CPU_STATUS_FLATDS)) && - !((seg == &_ss) && (cpu_cur_status & CPU_STATUS_FLATSS))) + if (!(seg == &_ds && codegen_flat_ds) && !(seg == &_ss && codegen_flat_ss)) *jump4 = (uintptr_t)&codeblock[block_current].data[block_pos] - (uintptr_t)jump4 - 1; jump_pos = block_pos; load_param_1_reg_32(REG_EBX); @@ -5752,8 +5727,7 @@ static inline void MEM_CHECK_WRITE_L(x86seg *seg) static inline int MEM_LOAD_ADDR_EA_B_NO_ABRT(x86seg *seg) { - if (((seg == &_ds) && (cpu_cur_status & CPU_STATUS_FLATDS)) || - ((seg == &_ss) && (cpu_cur_status & CPU_STATUS_FLATSS))) + if ((seg == &_ds && codegen_flat_ds) || (seg == &_ss && codegen_flat_ss)) { addbyte(0x31); /*XOR ECX, ECX*/ addbyte(0xc9); @@ -5825,8 +5799,7 @@ static inline int MEM_LOAD_ADDR_EA_B_NO_ABRT(x86seg *seg) } static inline int MEM_LOAD_ADDR_EA_W_NO_ABRT(x86seg *seg) { - if (((seg == &_ds) && (cpu_cur_status & CPU_STATUS_FLATDS)) || - ((seg == &_ss) && (cpu_cur_status & CPU_STATUS_FLATSS))) + if ((seg == &_ds && codegen_flat_ds) || (seg == &_ss && codegen_flat_ss)) { addbyte(0x31); /*XOR ECX, ECX*/ addbyte(0xc9); @@ -5907,8 +5880,7 @@ static inline int MEM_LOAD_ADDR_EA_W_NO_ABRT(x86seg *seg) } static inline int MEM_LOAD_ADDR_EA_L_NO_ABRT(x86seg *seg) { - if (((seg == &_ds) && (cpu_cur_status & CPU_STATUS_FLATDS)) || - ((seg == &_ss) && (cpu_cur_status & CPU_STATUS_FLATSS))) + if ((seg == &_ds && codegen_flat_ds) || (seg == &_ss && codegen_flat_ss)) { addbyte(0x31); /*XOR ECX, ECX*/ addbyte(0xc9); @@ -6011,8 +5983,7 @@ static inline void MEM_STORE_ADDR_EA_B_NO_ABRT(x86seg *seg, int host_reg) addbyte(8); host_reg = 8; } - if (((seg == &_ds) && (cpu_cur_status & CPU_STATUS_FLATDS)) || - ((seg == &_ss) && (cpu_cur_status & CPU_STATUS_FLATSS))) + if ((seg == &_ds && codegen_flat_ds) || (seg == &_ss && codegen_flat_ss)) { addbyte(0x31); /*XOR EBX, EBX*/ addbyte(0xdb); @@ -6089,8 +6060,7 @@ static inline void MEM_STORE_ADDR_EA_B_NO_ABRT(x86seg *seg, int host_reg) } static inline void MEM_STORE_ADDR_EA_W_NO_ABRT(x86seg *seg, int host_reg) { - if (((seg == &_ds) && (cpu_cur_status & CPU_STATUS_FLATDS)) || - ((seg == &_ss) && (cpu_cur_status & CPU_STATUS_FLATSS))) + if ((seg == &_ds && codegen_flat_ds) || (seg == &_ss && codegen_flat_ss)) { addbyte(0x31); /*XOR EBX, EBX*/ addbyte(0xdb); @@ -6178,8 +6148,7 @@ static inline void MEM_STORE_ADDR_EA_W_NO_ABRT(x86seg *seg, int host_reg) } static inline void MEM_STORE_ADDR_EA_L_NO_ABRT(x86seg *seg, int host_reg) { - if (((seg == &_ds) && (cpu_cur_status & CPU_STATUS_FLATDS)) || - ((seg == &_ss) && (cpu_cur_status & CPU_STATUS_FLATSS))) + if ((seg == &_ds && codegen_flat_ds) || (seg == &_ss && codegen_flat_ss)) { addbyte(0x31); /*XOR EBX, EBX*/ addbyte(0xdb); diff --git a/src/codegen_ops_x86.h b/src/codegen_ops_x86.h index 34ace4d..77d284f 100644 --- a/src/codegen_ops_x86.h +++ b/src/codegen_ops_x86.h @@ -618,9 +618,7 @@ static inline void CHECK_SEG_READ(x86seg *seg) return; if (seg->checked) return; - if ((seg == &_ds) && (cpu_cur_status & CPU_STATUS_FLATDS)) - return; - if ((seg == &_ss) && (cpu_cur_status & CPU_STATUS_FLATSS)) + if (seg == &_ds && codegen_flat_ds) return; addbyte(0x83); /*CMP seg->base, -1*/ @@ -643,9 +641,7 @@ static inline void CHECK_SEG_WRITE(x86seg *seg) return; if (seg->checked) return; - if ((seg == &_ds) && (cpu_cur_status & CPU_STATUS_FLATDS)) - return; - if ((seg == &_ss) && (cpu_cur_status & CPU_STATUS_FLATSS)) + if (seg == &_ds && codegen_flat_ds) return; addbyte(0x83); /*CMP seg->base, -1*/ @@ -660,9 +656,7 @@ static inline void CHECK_SEG_WRITE(x86seg *seg) } static inline void CHECK_SEG_LIMITS(x86seg *seg, int end_offset) { - if ((seg == &_ds) && (cpu_cur_status & CPU_STATUS_FLATDS)) - return; - if ((seg == &_ss) && (cpu_cur_status & CPU_STATUS_FLATSS)) + if ((seg == &_ds && codegen_flat_ds) || (seg == &_ss && codegen_flat_ss)) return; addbyte(0x3b); /*CMP EAX, seg->limit_low*/ @@ -690,8 +684,7 @@ static inline void CHECK_SEG_LIMITS(x86seg *seg, int end_offset) static inline void MEM_LOAD_ADDR_EA_B(x86seg *seg) { - if (((seg == &_ds) && (cpu_cur_status & CPU_STATUS_FLATDS)) || - ((seg == &_ss) && (cpu_cur_status & CPU_STATUS_FLATSS))) + if ((seg == &_ds && codegen_flat_ds) || (seg == &_ss && codegen_flat_ss)) { addbyte(0x31); /*XOR EDX, EDX*/ addbyte(0xd2); @@ -709,8 +702,7 @@ static inline void MEM_LOAD_ADDR_EA_B(x86seg *seg) } static inline int MEM_LOAD_ADDR_EA_B_NO_ABRT(x86seg *seg) { - if (((seg == &_ds) && (cpu_cur_status & CPU_STATUS_FLATDS)) || - ((seg == &_ss) && (cpu_cur_status & CPU_STATUS_FLATSS))) + if ((seg == &_ds && codegen_flat_ds) || (seg == &_ss && codegen_flat_ss)) { addbyte(0x31); /*XOR EDX, EDX*/ addbyte(0xd2); @@ -730,8 +722,7 @@ static inline int MEM_LOAD_ADDR_EA_B_NO_ABRT(x86seg *seg) } static inline void MEM_LOAD_ADDR_EA_W(x86seg *seg) { - if (((seg == &_ds) && (cpu_cur_status & CPU_STATUS_FLATDS)) || - ((seg == &_ss) && (cpu_cur_status & CPU_STATUS_FLATSS))) + if ((seg == &_ds && codegen_flat_ds) || (seg == &_ss && codegen_flat_ss)) { addbyte(0x31); /*XOR EDX, EDX*/ addbyte(0xd2); @@ -749,8 +740,7 @@ static inline void MEM_LOAD_ADDR_EA_W(x86seg *seg) } static inline void MEM_LOAD_ADDR_EA_W_OFFSET(x86seg *seg, int offset) { - if (((seg == &_ds) && (cpu_cur_status & CPU_STATUS_FLATDS)) || - ((seg == &_ss) && (cpu_cur_status & CPU_STATUS_FLATSS))) + if ((seg == &_ds && codegen_flat_ds) || (seg == &_ss && codegen_flat_ss)) { addbyte(0x31); /*XOR EDX, EDX*/ addbyte(0xd2); @@ -771,8 +761,7 @@ static inline void MEM_LOAD_ADDR_EA_W_OFFSET(x86seg *seg, int offset) } static inline int MEM_LOAD_ADDR_EA_W_NO_ABRT(x86seg *seg) { - if (((seg == &_ds) && (cpu_cur_status & CPU_STATUS_FLATDS)) || - ((seg == &_ss) && (cpu_cur_status & CPU_STATUS_FLATSS))) + if ((seg == &_ds && codegen_flat_ds) || (seg == &_ss && codegen_flat_ss)) { addbyte(0x31); /*XOR EDX, EDX*/ addbyte(0xd2); @@ -792,8 +781,7 @@ static inline int MEM_LOAD_ADDR_EA_W_NO_ABRT(x86seg *seg) } static inline void MEM_LOAD_ADDR_EA_L(x86seg *seg) { - if (((seg == &_ds) && (cpu_cur_status & CPU_STATUS_FLATDS)) || - ((seg == &_ss) && (cpu_cur_status & CPU_STATUS_FLATSS))) + if ((seg == &_ds && codegen_flat_ds) || (seg == &_ss && codegen_flat_ss)) { addbyte(0x31); /*XOR EDX, EDX*/ addbyte(0xd2); @@ -812,8 +800,7 @@ static inline void MEM_LOAD_ADDR_EA_L(x86seg *seg) } static inline int MEM_LOAD_ADDR_EA_L_NO_ABRT(x86seg *seg) { - if (((seg == &_ds) && (cpu_cur_status & CPU_STATUS_FLATDS)) || - ((seg == &_ss) && (cpu_cur_status & CPU_STATUS_FLATSS))) + if ((seg == &_ds && codegen_flat_ds) || (seg == &_ss && codegen_flat_ss)) { addbyte(0x31); /*XOR EDX, EDX*/ addbyte(0xd2); @@ -834,8 +821,7 @@ static inline int MEM_LOAD_ADDR_EA_L_NO_ABRT(x86seg *seg) static inline void MEM_LOAD_ADDR_EA_Q(x86seg *seg) { - if (((seg == &_ds) && (cpu_cur_status & CPU_STATUS_FLATDS)) || - ((seg == &_ss) && (cpu_cur_status & CPU_STATUS_FLATSS))) + if ((seg == &_ds && codegen_flat_ds) || (seg == &_ss && codegen_flat_ss)) { addbyte(0x31); /*XOR EDX, EDX*/ addbyte(0xd2); @@ -873,8 +859,7 @@ static inline void MEM_LOAD_ADDR_IMM_L(x86seg *seg, uint32_t addr) static inline void MEM_STORE_ADDR_EA_B(x86seg *seg, int host_reg) { - if (((seg == &_ds) && (cpu_cur_status & CPU_STATUS_FLATDS)) || - ((seg == &_ss) && (cpu_cur_status & CPU_STATUS_FLATSS))) + if ((seg == &_ds && codegen_flat_ds) || (seg == &_ss && codegen_flat_ss)) { addbyte(0x31); /*XOR ESI, ESI*/ addbyte(0xf6); @@ -895,8 +880,7 @@ static inline void MEM_STORE_ADDR_EA_B(x86seg *seg, int host_reg) } static inline void MEM_STORE_ADDR_EA_B_NO_ABRT(x86seg *seg, int host_reg) { - if (((seg == &_ds) && (cpu_cur_status & CPU_STATUS_FLATDS)) || - ((seg == &_ss) && (cpu_cur_status & CPU_STATUS_FLATSS))) + if ((seg == &_ds && codegen_flat_ds) || (seg == &_ss && codegen_flat_ss)) { addbyte(0x31); /*XOR ESI, ESI*/ addbyte(0xf6); @@ -917,8 +901,7 @@ static inline void MEM_STORE_ADDR_EA_B_NO_ABRT(x86seg *seg, int host_reg) } static inline void MEM_STORE_ADDR_EA_W(x86seg *seg, int host_reg) { - if (((seg == &_ds) && (cpu_cur_status & CPU_STATUS_FLATDS)) || - ((seg == &_ss) && (cpu_cur_status & CPU_STATUS_FLATSS))) + if ((seg == &_ds && codegen_flat_ds) || (seg == &_ss && codegen_flat_ss)) { addbyte(0x31); /*XOR ESI, ESI*/ addbyte(0xf6); @@ -939,8 +922,7 @@ static inline void MEM_STORE_ADDR_EA_W(x86seg *seg, int host_reg) } static inline void MEM_STORE_ADDR_EA_W_NO_ABRT(x86seg *seg, int host_reg) { - if (((seg == &_ds) && (cpu_cur_status & CPU_STATUS_FLATDS)) || - ((seg == &_ss) && (cpu_cur_status & CPU_STATUS_FLATSS))) + if ((seg == &_ds && codegen_flat_ds) || (seg == &_ss && codegen_flat_ss)) { addbyte(0x31); /*XOR ESI, ESI*/ addbyte(0xf6); @@ -961,8 +943,7 @@ static inline void MEM_STORE_ADDR_EA_W_NO_ABRT(x86seg *seg, int host_reg) } static inline void MEM_STORE_ADDR_EA_L(x86seg *seg, int host_reg) { - if (((seg == &_ds) && (cpu_cur_status & CPU_STATUS_FLATDS)) || - ((seg == &_ss) && (cpu_cur_status & CPU_STATUS_FLATSS))) + if ((seg == &_ds && codegen_flat_ds) || (seg == &_ss && codegen_flat_ss)) { addbyte(0x31); /*XOR ESI, ESI*/ addbyte(0xf6); @@ -983,8 +964,7 @@ static inline void MEM_STORE_ADDR_EA_L(x86seg *seg, int host_reg) } static inline void MEM_STORE_ADDR_EA_L_NO_ABRT(x86seg *seg, int host_reg) { - if (((seg == &_ds) && (cpu_cur_status & CPU_STATUS_FLATDS)) || - ((seg == &_ss) && (cpu_cur_status & CPU_STATUS_FLATSS))) + if ((seg == &_ds && codegen_flat_ds) || (seg == &_ss && codegen_flat_ss)) { addbyte(0x31); /*XOR ESI, ESI*/ addbyte(0xf6); @@ -1015,8 +995,7 @@ static inline void MEM_STORE_ADDR_EA_Q(x86seg *seg, int host_reg, int host_reg2) addbyte(0x89); /*MOV ECX, host_reg2*/ addbyte(0xc0 | REG_ECX | (host_reg2 << 3)); } - if (((seg == &_ds) && (cpu_cur_status & CPU_STATUS_FLATDS)) || - ((seg == &_ss) && (cpu_cur_status & CPU_STATUS_FLATSS))) + if ((seg == &_ds && codegen_flat_ds) || (seg == &_ss && codegen_flat_ss)) { addbyte(0x31); /*XOR ESI, ESI*/ addbyte(0xf6); @@ -3943,8 +3922,7 @@ static inline void LOAD_EA() static inline void MEM_CHECK_WRITE(x86seg *seg) { CHECK_SEG_WRITE(seg); - if (((seg == &_ds) && (cpu_cur_status & CPU_STATUS_FLATDS)) || - ((seg == &_ss) && (cpu_cur_status & CPU_STATUS_FLATSS))) + if ((seg == &_ds && codegen_flat_ds) || (seg == &_ss && codegen_flat_ss)) { addbyte(0x31); /*XOR ESI, ESI*/ addbyte(0xf6); @@ -3962,8 +3940,7 @@ static inline void MEM_CHECK_WRITE(x86seg *seg) static inline void MEM_CHECK_WRITE_W(x86seg *seg) { CHECK_SEG_WRITE(seg); - if (((seg == &_ds) && (cpu_cur_status & CPU_STATUS_FLATDS)) || - ((seg == &_ss) && (cpu_cur_status & CPU_STATUS_FLATSS))) + if ((seg == &_ds && codegen_flat_ds) || (seg == &_ss && codegen_flat_ss)) { addbyte(0x31); /*XOR ESI, ESI*/ addbyte(0xf6); @@ -3981,8 +3958,7 @@ static inline void MEM_CHECK_WRITE_W(x86seg *seg) static inline void MEM_CHECK_WRITE_L(x86seg *seg) { CHECK_SEG_WRITE(seg); - if (((seg == &_ds) && (cpu_cur_status & CPU_STATUS_FLATDS)) || - ((seg == &_ss) && (cpu_cur_status & CPU_STATUS_FLATSS))) + if ((seg == &_ds && codegen_flat_ds) || (seg == &_ss && codegen_flat_ss)) { addbyte(0x31); /*XOR ESI, ESI*/ addbyte(0xf6); diff --git a/src/codegen_x86-64.c b/src/codegen_x86-64.c index e6e8b78..5a35102 100644 --- a/src/codegen_x86-64.c +++ b/src/codegen_x86-64.c @@ -23,7 +23,7 @@ #include #endif - +int codegen_flat_ds, codegen_flat_ss; int codegen_flags_changed = 0; int codegen_fpu_entered = 0; int codegen_fpu_loaded_iq[8]; @@ -384,6 +384,9 @@ void codegen_block_start_recompile(codeblock_t *block) codegen_reg_loaded[4] = codegen_reg_loaded[5] = codegen_reg_loaded[6] = codegen_reg_loaded[7] = 0; block->was_recompiled = 1; + + codegen_flat_ds = cpu_cur_status & CPU_STATUS_FLATDS; + codegen_flat_ss = cpu_cur_status & CPU_STATUS_FLATSS; } void codegen_block_remove() diff --git a/src/codegen_x86.c b/src/codegen_x86.c index 07f6857..841ef7e 100644 --- a/src/codegen_x86.c +++ b/src/codegen_x86.c @@ -23,6 +23,7 @@ #include #endif +int codegen_flat_ds, codegen_flat_ss; int mmx_ebx_ecx_loaded; int codegen_flags_changed = 0; int codegen_fpu_entered = 0; @@ -1478,6 +1479,9 @@ void codegen_block_start_recompile(codeblock_t *block) block->TOP = cpu_state.TOP; block->was_recompiled = 1; + + codegen_flat_ds = cpu_cur_status & CPU_STATUS_FLATDS; + codegen_flat_ss = cpu_cur_status & CPU_STATUS_FLATSS; } void codegen_block_remove() diff --git a/src/x86.h b/src/x86.h index dc60e05..1c15e1f 100644 --- a/src/x86.h +++ b/src/x86.h @@ -111,3 +111,6 @@ void dumpregs(); void execx86(int cycs); void exec386(int cycs); void exec386_dynarec(int cycs); + +extern int codegen_flat_ds; +extern int codegen_flat_ss; diff --git a/src/x86seg.c b/src/x86seg.c index c729670..364c616 100644 --- a/src/x86seg.c +++ b/src/x86seg.c @@ -434,6 +434,10 @@ void loadseg(uint16_t seg, x86seg *s) } #endif s->checked = 0; + if (s == &_ds) + codegen_flat_ds = 0; + if (s == &_ss) + codegen_flat_ss = 0; } else { @@ -443,6 +447,10 @@ void loadseg(uint16_t seg, x86seg *s) if (s == &_ss) stack32 = 0; s->checked = 1; + if (s == &_ds) + codegen_flat_ds = 0; + if (s == &_ss) + codegen_flat_ss = 0; } if (s == &_ds)