Search
lxdream.org :: lxdream/src/sh4/x86op.h :: diff
lxdream 0.9.1
released Jun 29
Download Now
filename src/sh4/x86op.h
changeset 926:68f3e0fe02f1
prev903:1337c7a7dd6b
next927:17b6b9e245d8
author nkeynes
date Sun Dec 14 07:50:48 2008 +0000 (11 years ago)
permissions -rw-r--r--
last change Setup a 'proper' stackframe in translated blocks. This doesn't affect performance noticeably,
but does ensure that
a) The stack is aligned correctly on OS X with no extra effort, and
b) We can't mess up the stack and crash that way anymore.
Replace all PUSH/POP instructions (outside of prologue/epilogue) with ESP-rel moves to stack
local variables.
Finally merge ia32mac and ia32abi together, since they're pretty much the same now anyway (and
thereby simplifying maintenance a good deal)
file annotate diff log raw
1.1 --- a/src/sh4/x86op.h Wed Oct 29 23:32:28 2008 +0000
1.2 +++ b/src/sh4/x86op.h Sun Dec 14 07:50:48 2008 +0000
1.3 @@ -54,31 +54,17 @@
1.4 #define AND_imm8s_rptr(imm, r1) REXW(); AND_imm8s_r32( imm, r1 )
1.5 #define LEA_sh4r_rptr(disp, r1) REXW(); LEA_sh4r_r32(disp,r1)
1.6 #define MOV_moffptr_EAX(offptr) REXW(); MOV_moff32_EAX( offptr )
1.7 -#define STACK_ALIGN 16
1.8 -#define POP_r32(r1) OP(0x58 + r1);
1.9 -#define POP_realigned_r32(r1) OP(0x58 + r1); REXW(); ADD_imm8s_r32(8,R_ESP)
1.10 -#define PUSH_r32(r1) OP(0x50 + r1);
1.11 -#define PUSH_realigned_r32(r1) REXW(); SUB_imm8s_r32(8, R_ESP); OP(0x50 + r1)
1.12 -#define PUSH_imm32(imm) OP(0x68); OP32(imm);
1.13 -#define PUSH_imm64(imm) REXW(); OP(0x68); OP64(imm);
1.14 #else /* 32-bit system */
1.15 #define OPPTR(x) OP32((uint32_t)(x))
1.16 #define AND_imm8s_rptr(imm, r1) AND_imm8s_r32( imm, r1 )
1.17 #define LEA_sh4r_rptr(disp, r1) LEA_sh4r_r32(disp,r1)
1.18 #define MOV_moffptr_EAX(offptr) MOV_moff32_EAX( offptr )
1.19 -#define POP_realigned_r32(r1) POP_r32(r1)
1.20 -#define PUSH_realigned_r32(r1) PUSH_r32(r1)
1.21 -#ifdef APPLE_BUILD
1.22 +#endif
1.23 #define STACK_ALIGN 16
1.24 -#define POP_r32(r1) OP(0x58 + r1); sh4_x86.stack_posn -= 4;
1.25 -#define PUSH_r32(r1) OP(0x50 + r1); sh4_x86.stack_posn += 4;
1.26 -#define PUSH_imm32(imm) OP(0x68); OP32(imm); sh4_x86.stack_posn += 4;
1.27 -#else
1.28 #define POP_r32(r1) OP(0x58 + r1)
1.29 #define PUSH_r32(r1) OP(0x50 + r1)
1.30 #define PUSH_imm32(imm) OP(0x68); OP32(imm)
1.31 -#endif
1.32 -#endif
1.33 +#define PUSH_imm64(imm) REXW(); OP(0x68); OP64(imm);
1.34
1.35 #ifdef STACK_ALIGN
1.36 #else
1.37 @@ -124,6 +110,9 @@
1.38 /* ebp+disp32 modrm form */
1.39 #define MODRM_r32_ebp32(r1,disp) OP(0x85 | (r1<<3)); OP32(disp)
1.40
1.41 +/* esp+disp32 modrm+sib form */
1.42 +#define MODRM_r32_esp8(r1,disp) OP(0x44 | (r1<<3)); OP(0x24); OP(disp)
1.43 +
1.44 #define MODRM_r32_sh4r(r1,disp) if(disp>127){ MODRM_r32_ebp32(r1,disp);}else{ MODRM_r32_ebp8(r1,(unsigned char)disp); }
1.45
1.46 #define REXW() OP(0x48)
1.47 @@ -134,6 +123,7 @@
1.48 #define ADD_r32_r32(r1,r2) OP(0x03); MODRM_rm32_r32(r1,r2)
1.49 #define ADD_imm8s_r32(imm,r1) OP(0x83); MODRM_rm32_r32(r1, 0); OP(imm)
1.50 #define ADD_imm8s_sh4r(imm,disp) OP(0x83); MODRM_r32_sh4r(0,disp); OP(imm)
1.51 +#define ADD_imm8s_esp8(imm,disp) OP(0x83); MODRM_r32_esp8(0,disp); OP(imm)
1.52 #define ADD_imm32_r32(imm32,r1) OP(0x81); MODRM_rm32_r32(r1,0); OP32(imm32)
1.53 #define ADC_r32_r32(r1,r2) OP(0x13); MODRM_rm32_r32(r1,r2)
1.54 #define ADC_sh4r_r32(disp,r1) OP(0x13); MODRM_r32_sh4r(r1,disp)
1.55 @@ -143,6 +133,7 @@
1.56 #define AND_imm8s_r32(imm8,r1) OP(0x83); MODRM_rm32_r32(r1,4); OP(imm8)
1.57 #define AND_imm32_r32(imm,r1) OP(0x81); MODRM_rm32_r32(r1,4); OP32(imm)
1.58 #define CALL_r32(r1) OP(0xFF); MODRM_rm32_r32(r1,2)
1.59 +#define CALL_ptr(ptr) OP(0xE8); OP32( (((char *)ptr) - (char *)xlat_output) - 4)
1.60 #define CLC() OP(0xF8)
1.61 #define CMC() OP(0xF5)
1.62 #define CMP_sh4r_r32(disp,r1) OP(0x3B); MODRM_r32_sh4r(r1,disp)
1.63 @@ -155,12 +146,15 @@
1.64 #define INC_r32(r1) OP(0x40+r1)
1.65 #define JMP_rel8(label) OP(0xEB); MARK_JMP8(label); OP(-1);
1.66 #define LEA_sh4r_r32(disp,r1) OP(0x8D); MODRM_r32_sh4r(r1,disp)
1.67 +#define LEA_r32disp8_r32(r1, disp, r2) OP(0x8D); OP( 0x40 + (r2<<3) + r1); OP(disp)
1.68 #define MOV_r32_r32(r1,r2) OP(0x89); MODRM_r32_rm32(r1,r2)
1.69 #define MOV_r32_sh4r(r1,disp) OP(0x89); MODRM_r32_sh4r(r1,disp)
1.70 #define MOV_moff32_EAX(off) OP(0xA1); OPPTR(off)
1.71 #define MOV_sh4r_r32(disp, r1) OP(0x8B); MODRM_r32_sh4r(r1,disp)
1.72 #define MOV_r32_r32ind(r2,r1) OP(0x89); OP(0 + (r2<<3) + r1 )
1.73 #define MOV_r32ind_r32(r1,r2) OP(0x8B); OP(0 + (r2<<3) + r1 )
1.74 +#define MOV_r32_esp8(r1,disp) OP(0x89); MODRM_r32_esp8(r1,disp)
1.75 +#define MOV_esp8_r32(disp,r1) OP(0x8B); MODRM_r32_esp8(r1,disp)
1.76 #define MOVSX_r8_r32(r1,r2) OP(0x0F); OP(0xBE); MODRM_rm32_r32(r1,r2)
1.77 #define MOVSX_r16_r32(r1,r2) OP(0x0F); OP(0xBF); MODRM_rm32_r32(r1,r2)
1.78 #define MOVZX_r8_r32(r1,r2) OP(0x0F); OP(0xB6); MODRM_rm32_r32(r1,r2)
.