Search
lxdream.org :: lxdream/src/sh4/x86op.h :: diff
lxdream 0.9.1
released Jun 29
Download Now
filename src/sh4/x86op.h
changeset 368:36fac4c42322
prev361:be3de4ecd954
next374:8f80a795513e
author nkeynes
date Tue Sep 04 08:40:23 2007 +0000 (13 years ago)
permissions -rw-r--r--
last change More translator WIP - blocks are approaching something sane
file annotate diff log raw
1.1 --- a/src/sh4/x86op.h Tue Aug 28 08:46:14 2007 +0000
1.2 +++ b/src/sh4/x86op.h Tue Sep 04 08:40:23 2007 +0000
1.3 @@ -1,5 +1,5 @@
1.4 /**
1.5 - * $Id: x86op.h,v 1.2 2007-08-28 08:46:14 nkeynes Exp $
1.6 + * $Id: x86op.h,v 1.3 2007-09-04 08:40:23 nkeynes Exp $
1.7 *
1.8 * Definitions of x86 opcodes for use by the translator.
1.9 *
1.10 @@ -49,6 +49,7 @@
1.11 #define R_Q REG_OFFSET(q)
1.12 #define R_S REG_OFFSET(s)
1.13 #define R_M REG_OFFSET(m)
1.14 +#define R_SR REG_OFFSET(sr)
1.15 #define R_GBR REG_OFFSET(gbr)
1.16 #define R_SSR REG_OFFSET(ssr)
1.17 #define R_SPC REG_OFFSET(spc)
1.18 @@ -76,29 +77,45 @@
1.19 /* ebp+disp32 modrm form */
1.20 #define MODRM_r32_ebp32(r1,disp) OP(0x85 | (r1<<3)); OP32(disp)
1.21
1.22 +#define MODRM_r32_ebp(r1,disp) if(disp>127){ MODRM_r32_ebp32(r1,disp);}else{ MODRM_r32_ebp8(r1,(unsigned char)disp); }
1.23 +
1.24 /* Major opcodes */
1.25 #define ADD_r32_r32(r1,r2) OP(0x03); MODRM_rm32_r32(r1,r2)
1.26 #define ADD_imm8s_r32(imm,r1) OP(0x83); MODRM_rm32_r32(r1, 0); OP(imm)
1.27 +#define ADD_imm32_r32(imm32,r1) OP(0x81); MODRM_rm32_r32(r1,0); OP32(imm32)
1.28 #define ADC_r32_r32(r1,r2) OP(0x13); MODRM_rm32_r32(r1,r2)
1.29 #define AND_r32_r32(r1,r2) OP(0x23); MODRM_rm32_r32(r1,r2)
1.30 +#define AND_imm8_r8(imm8, r1) OP(0x80); MODRM_rm32_r32(r1,4); OP(imm8)
1.31 #define AND_imm32_r32(imm,r1) OP(0x81); MODRM_rm32_r32(r1,4); OP32(imm)
1.32 +#define CALL_r32(r1) OP(0xFF); MODRM_rm32_r32(r1,2)
1.33 #define CMC() OP(0xF5)
1.34 #define CMP_r32_r32(r1,r2) OP(0x3B); MODRM_rm32_r32(r1,r2)
1.35 +#define CMP_imm32_r32(imm32, r1) OP(0x81); MODRM_rm32_r32(r1,7); OP32(imm32)
1.36 #define CMP_imm8s_r32(imm,r1) OP(0x83); MODRM_rm32_r32(r1,7); OP(imm)
1.37 +#define CMP_imm8s_ebp(imm,disp) OP(0x83); MODRM_r32_ebp(7,disp) OP(imm)
1.38 +#define DEC_r32(r1) OP(0x48+r1)
1.39 +#define IMUL_r32(r1) OP(0xF7); MODRM_rm32_r32(r1,5)
1.40 +#define INC_r32(r1) OP(0x40+r1)
1.41 #define JMP_rel8(rel) OP(0xEB); OP(rel)
1.42 -#define MOV_r32_ebp8(r1,disp) OP(0x89); MODRM_r32_ebp8(r1,disp)
1.43 +#define MOV_r32_r32(r1,r2) OP(0x89); MODRM_r32_rm32(r1,r2)
1.44 +#define MOV_r32_ebp(r1,disp) OP(0x89); MODRM_r32_ebp(r1,disp)
1.45 #define MOV_r32_ebp32(r1,disp) OP(0x89); MODRM_r32_ebp32(r1,disp)
1.46 -#define MOV_ebp8_r32(r1,disp) OP(0x8B); MODRM_r32_ebp8(r1,disp)
1.47 -#define MOV_ebp32_r32(r1,disp) OP(0x8B); MODRM_r32_ebp32(r1,disp)
1.48 +#define MOV_moff32_EAX(off) OP(0xA1); OP32(off)
1.49 +#define MOV_ebp_r32(disp, r1) OP(0x8B); MODRM_r32_ebp(r1,disp)
1.50 #define MOVSX_r8_r32(r1,r2) OP(0x0F); OP(0xBE); MODRM_rm32_r32(r1,r2)
1.51 #define MOVSX_r16_r32(r1,r2) OP(0x0F); OP(0xBF); MODRM_rm32_r32(r1,r2)
1.52 #define MOVZX_r8_r32(r1,r2) OP(0x0F); OP(0xB6); MODRM_rm32_r32(r1,r2)
1.53 #define MOVZX_r16_r32(r1,r2) OP(0x0F); OP(0xB7); MODRM_rm32_r32(r1,r2)
1.54 +#define MUL_r32(r1) OP(0xF7); MODRM_rm32_r32(r1,4)
1.55 #define NEG_r32(r1) OP(0xF7); MODRM_rm32_r32(r1,3)
1.56 #define NOT_r32(r1) OP(0xF7); MODRM_rm32_r32(r1,2)
1.57 #define OR_r32_r32(r1,r2) OP(0x0B); MODRM_rm32_r32(r1,r2)
1.58 +#define OR_imm8_r8(imm,r1) OP(0x80); MODRM_rm32_r32(r1,1)
1.59 #define OR_imm32_r32(imm,r1) OP(0x81); MODRM_rm32_r32(r1,1); OP32(imm)
1.60 +#define OR_ebp_r32(disp,r1) OP(0x0B); MODRM_r32_ebp(r1,disp)
1.61 +#define POP_r32(r1) OP(0x58 + r1)
1.62 #define PUSH_r32(r1) OP(0x50 + r1)
1.63 +#define PUSH_imm32(imm) OP(0x68); OP32(imm)
1.64 #define RCL1_r32(r1) OP(0xD1); MODRM_rm32_r32(r1,2)
1.65 #define RCR1_r32(r1) OP(0xD1); MODRM_rm32_r32(r1,3)
1.66 #define RET() OP(0xC3)
1.67 @@ -106,29 +123,23 @@
1.68 #define ROR1_r32(r1) OP(0xD1); MODRM_rm32_r32(r1,1)
1.69 #define SAR1_r32(r1) OP(0xD1); MODRM_rm32_r32(r1,7)
1.70 #define SAR_imm8_r32(imm,r1) OP(0xC1); MODRM_rm32_r32(r1,7); OP(imm)
1.71 +#define SAR_r32_CL(r1) OP(0xD3); MODRM_rm32_r32(r1,7)
1.72 #define SBB_r32_r32(r1,r2) OP(0x1B); MODRM_rm32_r32(r1,r2)
1.73 #define SHL1_r32(r1) OP(0xD1); MODRM_rm32_r32(r1,4)
1.74 +#define SHL_r32_CL(r1) OP(0xD3); MODRM_rm32_r32(r1,4)
1.75 #define SHL_imm8_r32(imm,r1) OP(0xC1); MODRM_rm32_r32(r1,4); OP(imm)
1.76 #define SHR1_r32(r1) OP(0xD1); MODRM_rm32_r32(r1,5)
1.77 +#define SHR_r32_CL(r1) OP(0xD3); MODRM_rm32_r32(r1,5)
1.78 #define SHR_imm8_r32(imm,r1) OP(0xC1); MODRM_rm32_r32(r1,5); OP(imm)
1.79 #define SUB_r32_r32(r1,r2) OP(0x2B); MODRM_rm32_r32(r1,r2)
1.80 +#define TEST_r8_r8(r1,r2) OP(0x84); MODRM_r32_rm32(r1,r2)
1.81 #define TEST_r32_r32(r1,r2) OP(0x85); MODRM_rm32_r32(r1,r2)
1.82 +#define TEST_imm8_r8(imm8,r1) OP(0xF6); MODRM_rm32_r32(r1,0); OP(imm8)
1.83 #define TEST_imm32_r32(imm,r1) OP(0xF7); MODRM_rm32_r32(r1,0); OP32(imm)
1.84 +#define XCHG_r8_r8(r1,r2) OP(0x86); MODRM_rm32_r32(r1,r2)
1.85 #define XOR_r32_r32(r1,r2) OP(0x33); MODRM_rm32_r32(r1,r2)
1.86 #define XOR_imm32_r32(imm,r1) OP(0x81); MODRM_rm32_r32(r1,6); OP32(imm)
1.87
1.88 -#define ADD_imm32_r32(imm32,r1) OP(0x81); MODRM_rm32_r32(r1,0); OP32(imm32)
1.89 -#define AND_imm8_r8(imm8, r1) OP(0x80); MODRM_rm32_r32(r1,4); OP(imm8)
1.90 -#define CMP_imm32_r32(imm32, r1) OP(0x81); MODRM_rm32_r32(r1,7); OP32(imm32)
1.91 -#define MOV_r32_r32(r1,r2) OP(0x89); MODRM_r32_rm32(r1,r2)
1.92 -#define MUL_r32(r1) OP(0xF7); MODRM_rm32_r32(r1,4)
1.93 -#define IMUL_r32(r1) OP(0xF7); MODRM_rm32_r32(r1,5)
1.94 -#define OR_imm8_r8(imm,r1) OP(0x80); MODRM_rm32_r32(r1,1)
1.95 -#define TEST_r8_r8(r1,r2) OP(0x84); MODRM_r32_rm32(r1,r2)
1.96 -#define SAR_r32_CL(r1) OP(0xD3); MODRM_rm32_r32(r1,7)
1.97 -#define SHR_r32_CL(r1) OP(0xD3); MODRM_rm32_r32(r1,5)
1.98 -#define SHL_r32_CL(r1) OP(0xD3); MODRM_rm32_r32(r1,4)
1.99 -#define XCHG_r8_r8(r1,r2) OP(0x86); MODRM_rm32_r32(r1,r2)
1.100
1.101 /* Conditional branches */
1.102 #define JE_rel8(rel) OP(0x74); OP(rel)
1.103 @@ -138,8 +149,6 @@
1.104 #define JGE_rel8(rel) OP(0x7D); OP(rel)
1.105 #define JC_rel8(rel) OP(0x72); OP(rel)
1.106 #define JO_rel8(rel) OP(0x70); OP(rel)
1.107 -
1.108 -/* Negated forms */
1.109 #define JNE_rel8(rel) OP(0x75); OP(rel)
1.110 #define JNA_rel8(rel) OP(0x76); OP(rel)
1.111 #define JNAE_rel8(rel) OP(0x72); OP(rel)
1.112 @@ -148,24 +157,59 @@
1.113 #define JNC_rel8(rel) OP(0x73); OP(rel)
1.114 #define JNO_rel8(rel) OP(0x71); OP(rel)
1.115
1.116 +/* 32-bit long forms w/ backpatching to an exit routine */
1.117 +#define JE_exit(rel) OP(0x0F); OP(0x84); sh4_x86_add_backpatch(xlat_output); OP32(rel)
1.118 +#define JA_exit(rel) OP(0x0F); OP(0x87); sh4_x86_add_backpatch(xlat_output); OP32(rel)
1.119 +#define JAE_exit(rel) OP(0x0F); OP(0x83); sh4_x86_add_backpatch(xlat_output); OP32(rel)
1.120 +#define JG_exit(rel) OP(0x0F); OP(0x8F); sh4_x86_add_backpatch(xlat_output); OP32(rel)
1.121 +#define JGE_exit(rel) OP(0x0F); OP(0x8D); sh4_x86_add_backpatch(xlat_output); OP32(rel)
1.122 +#define JC_exit(rel) OP(0x0F); OP(0x82); sh4_x86_add_backpatch(xlat_output); OP32(rel)
1.123 +#define JO_exit(rel) OP(0x0F); OP(0x80); sh4_x86_add_backpatch(xlat_output); OP32(rel)
1.124 +#define JNE_exit(rel) OP(0x0F); OP(0x85); sh4_x86_add_backpatch(xlat_output); OP32(rel)
1.125 +#define JNA_exit(rel) OP(0x0F); OP(0x86); sh4_x86_add_backpatch(xlat_output); OP32(rel)
1.126 +#define JNAE_exit(rel) OP(0x0F);OP(0x82); sh4_x86_add_backpatch(xlat_output); OP32(rel)
1.127 +#define JNG_exit(rel) OP(0x0F); OP(0x8E); sh4_x86_add_backpatch(xlat_output); OP32(rel)
1.128 +#define JNGE_exit(rel) OP(0x0F);OP(0x8C); sh4_x86_add_backpatch(xlat_output); OP32(rel)
1.129 +#define JNC_exit(rel) OP(0x0F); OP(0x83); sh4_x86_add_backpatch(xlat_output); OP32(rel)
1.130 +#define JNO_exit(rel) OP(0x0F); OP(0x81); sh4_x86_add_backpatch(xlat_output); OP32(rel)
1.131 +
1.132 +
1.133 +/* Conditional moves ebp-rel */
1.134 +#define CMOVE_r32_r32(r1,r2) OP(0x0F); OP(0x44); MODRM_rm32_r32(r1,r2)
1.135 +#define CMOVA_r32_r32(r1,r2) OP(0x0F); OP(0x47); MODRM_rm32_r32(r1,r2)
1.136 +#define CMOVAE_r32_r32(r1,r2) OP(0x0F); OP(0x43); MODRM_rm32_r32(r1,r2)
1.137 +#define CMOVG_r32_r32(r1,r2) OP(0x0F); OP(0x4F); MODRM_rm32_r32(r1,r2)
1.138 +#define CMOVGE_r32_r32(r1,r2) OP(0x0F); OP(0x4D); MODRM_rm32_r32(r1,r2)
1.139 +#define CMOVC_r32_r32(r1,r2) OP(0x0F); OP(0x42); MODRM_rm32_r32(r1,r2)
1.140 +#define CMOVO_r32_r32(r1,r2) OP(0x0F); OP(0x40); MODRM_rm32_r32(r1,r2)
1.141 +
1.142 +
1.143 /* Conditional setcc - writeback to sh4r.t */
1.144 -#define SETE_t() OP(0x0F); OP(0x94); MODRM_r32_ebp8(0, R_T);
1.145 -#define SETA_t() OP(0x0F); OP(0x97); MODRM_r32_ebp8(0, R_T);
1.146 -#define SETAE_t() OP(0x0F); OP(0x93); MODRM_r32_ebp8(0, R_T);
1.147 -#define SETG_t() OP(0x0F); OP(0x9F); MODRM_r32_ebp8(0, R_T);
1.148 -#define SETGE_t() OP(0x0F); OP(0x9D); MODRM_r32_ebp8(0, R_T);
1.149 -#define SETC_t() OP(0x0F); OP(0x92); MODRM_r32_ebp8(0, R_T);
1.150 -#define SETO_t() OP(0x0F); OP(0x90); MODRM_r32_ebp8(0, R_T);
1.151 +#define SETE_ebp(disp) OP(0x0F); OP(0x94); MODRM_r32_ebp(0, disp);
1.152 +#define SETA_ebp(disp) OP(0x0F); OP(0x97); MODRM_r32_ebp(0, disp);
1.153 +#define SETAE_ebp(disp) OP(0x0F); OP(0x93); MODRM_r32_ebp(0, disp);
1.154 +#define SETG_ebp(disp) OP(0x0F); OP(0x9F); MODRM_r32_ebp(0, disp);
1.155 +#define SETGE_ebp(disp) OP(0x0F); OP(0x9D); MODRM_r32_ebp(0, disp);
1.156 +#define SETC_ebp(disp) OP(0x0F); OP(0x92); MODRM_r32_ebp(0, disp);
1.157 +#define SETO_ebp(disp) OP(0x0F); OP(0x90); MODRM_r32_ebp(0, disp);
1.158
1.159 -#define SETNE_t() OP(0x0F); OP(0x95); MODRM_r32_ebp8(0, R_T);
1.160 -#define SETNA_t() OP(0x0F); OP(0x96); MODRM_r32_ebp8(0, R_T);
1.161 -#define SETNAE_t() OP(0x0F); OP(0x92); MODRM_r32_ebp8(0, R_T);
1.162 -#define SETNG_t() OP(0x0F); OP(0x9E); MODRM_r32_ebp8(0, R_T);
1.163 -#define SETNGE_t() OP(0x0F); OP(0x9C); MODRM_r32_ebp8(0, R_T);
1.164 -#define SETNC_t() OP(0x0F); OP(0x93); MODRM_r32_ebp8(0, R_T);
1.165 -#define SETNO_t() OP(0x0F); OP(0x91); MODRM_r32_ebp8(0, R_T);
1.166 +#define SETNE_ebp(disp) OP(0x0F); OP(0x95); MODRM_r32_ebp(0, disp);
1.167 +#define SETNA_ebp(disp) OP(0x0F); OP(0x96); MODRM_r32_ebp(0, disp);
1.168 +#define SETNAE_ebp(disp) OP(0x0F); OP(0x92); MODRM_r32_ebp(0, disp);
1.169 +#define SETNG_ebp(disp) OP(0x0F); OP(0x9E); MODRM_r32_ebp(0, disp);
1.170 +#define SETNGE_ebp(disp) OP(0x0F); OP(0x9C); MODRM_r32_ebp(0, disp);
1.171 +#define SETNC_ebp(disp) OP(0x0F); OP(0x93); MODRM_r32_ebp(0, disp);
1.172 +#define SETNO_ebp(disp) OP(0x0F); OP(0x91); MODRM_r32_ebp(0, disp);
1.173 +
1.174 +#define SETE_t() SETE_ebp(R_T)
1.175 +#define SETA_t() SETA_ebp(R_T)
1.176 +#define SETAE_t() SETAE_ebp(R_T)
1.177 +#define SETG_t() SETG_ebp(R_T)
1.178 +#define SETGE_t() SETGE_ebp(R_T)
1.179 +#define SETC_t() SETC_ebp(R_T)
1.180 +#define SETO_t() SETO_ebp(R_T)
1.181
1.182 /* Pseudo-op Load carry from T: CMP [EBP+t], #01 ; CMC */
1.183 -#define LDC_t() OP(0x83); MODRM_r32_ebp8(7,R_T); OP(0x01); CMC()
1.184 +#define LDC_t() OP(0x83); MODRM_r32_ebp(7,R_T); OP(0x01); CMC()
1.185
1.186 #endif /* !__lxdream_x86op_H */
.