00001 /* 00002 * HT Editor 00003 * x86opc.h 00004 * 00005 * Copyright (C) 1999-2002 Stefan Weyergraf (stefan@weyergraf.de) 00006 * 00007 * This program is free software; you can redistribute it and/or modify 00008 * it under the terms of the GNU General Public License version 2 as 00009 * published by the Free Software Foundation. 00010 * 00011 * This program is distributed in the hope that it will be useful, 00012 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00013 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00014 * GNU General Public License for more details. 00015 * 00016 * You should have received a copy of the GNU General Public License 00017 * along with this program; if not, write to the Free Software 00018 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 00019 */ 00020 00021 #ifndef __X86OPC_H__ 00022 #define __X86OPC_H__ 00023 00024 #include "common.h" 00025 00026 #define X86_PREFIX_NO -1 00027 00028 #define X86_PREFIX_LOCK 0 /* f0 */ 00029 00030 #define X86_PREFIX_ES 0 /* 26 */ 00031 #define X86_PREFIX_CS 1 /* 2e */ 00032 #define X86_PREFIX_SS 2 /* 36 */ 00033 #define X86_PREFIX_DS 3 /* 3e */ 00034 #define X86_PREFIX_FS 4 /* 64 */ 00035 #define X86_PREFIX_GS 5 /* 65 */ 00036 00037 #define X86_PREFIX_REPNZ 0 /* f2 */ 00038 #define X86_PREFIX_REPZ 1 /* f3 */ 00039 00040 #define X86_OPSIZEUNKNOWN -1 00041 #define X86_OPSIZE16 0 00042 #define X86_OPSIZE32 1 00043 00044 #define X86_ADDRSIZEUNKNOWN -1 00045 #define X86_ADDRSIZE16 0 00046 #define X86_ADDRSIZE32 1 00047 00048 #define X86_OPTYPE_EMPTY 0 00049 #define X86_OPTYPE_IMM 1 00050 #define X86_OPTYPE_REG 2 00051 #define X86_OPTYPE_SEG 3 00052 #define X86_OPTYPE_MEM 4 00053 #define X86_OPTYPE_CRX 5 00054 #define X86_OPTYPE_DRX 6 00055 #define X86_OPTYPE_TRX 7 00056 #define X86_OPTYPE_STX 8 00057 #define X86_OPTYPE_MMX 9 00058 #define X86_OPTYPE_FARPTR 10 00059 00060 // user defined types start here 00061 #define X86_OPTYPE_USER 32 00062 00063 union int_or_ptr { 00064 int i; 00065 void *p; 00066 }; 00067 00068 struct x86_insn_op { 00069 int type; 00070 int size; 00071 union { 00072 struct { 00073 dword seg; 00074 dword offset; 00075 } farptr; 00076 dword imm; 00077 int reg; 00078 int seg; 00079 struct { 00080 int floatptr; 00081 int hasdisp; 00082 dword disp; 00083 int base; 00084 int index; 00085 int scale; 00086 int addrsize; 00087 } mem; 00088 int crx; 00089 int drx; 00090 int trx; 00091 int stx; 00092 int mmx; 00093 int_or_ptr user[4]; 00094 }; 00095 }; 00096 00097 #define TYPE_0 0 00098 #define TYPE_A 1 /* direct address without ModR/M (generally 00099 like imm, but can be 16:32 = 48 bit) */ 00100 #define TYPE_C 2 /* reg of ModR/M picks control register */ 00101 #define TYPE_D 3 /* reg of ModR/M picks debug register */ 00102 #define TYPE_E 4 /* ModR/M (general reg or memory) */ 00103 #define TYPE_G 5 /* reg of ModR/M picks general register */ 00104 #define TYPE_Is 6 /* signed immediate */ 00105 #define TYPE_I 7 /* unsigned immediate */ 00106 #define TYPE_Ix 8 /* fixed immediate */ 00107 #define TYPE_J 9 /* relative branch offset */ 00108 #define TYPE_M 10 /* ModR/M (memory only) */ 00109 #define TYPE_O 11 /* direct memory without ModR/M */ 00110 #define TYPE_P 12 /* reg of ModR/M picks MMX register */ 00111 #define TYPE_Q 13 /* ModR/M (MMX reg or memory) */ 00112 #define TYPE_R 14 /* rm of ModR/M picks general register */ 00113 #define TYPE_Rx 15 /* extra picks register */ 00114 #define TYPE_S 16 /* reg of ModR/M picks segment register */ 00115 #define TYPE_Sx 17 /* extra picks segment register */ 00116 #define TYPE_T 18 /* reg of ModR/M picks test register */ 00117 #define TYPE_F 19 /* r/m of ModR/M picks a fpu register */ 00118 #define TYPE_Fx 20 /* extra picks a fpu register */ 00119 00120 /* when name is == 0, the first op has a special meaning (layout see x86_insn_op_special) */ 00121 #define SPECIAL_TYPE_INVALID 0 00122 #define SPECIAL_TYPE_PREFIX 1 00123 #define SPECIAL_TYPE_GROUP 2 00124 #define SPECIAL_TYPE_FGROUP 3 00125 00126 #define SIZE_0 '0' /* size unimportant */ 00127 #define SIZE_B 'b' /* byte */ 00128 #define SIZE_W 'w' /* word */ 00129 #define SIZE_D 'd' /* dword */ 00130 #define SIZE_Q 'q' /* qword */ 00131 #define SIZE_C 'c' /* byte OR word */ 00132 #define SIZE_V 'v' /* word OR dword */ 00133 #define SIZE_P 'p' /* word:word OR word:dword, memory only ! */ 00134 #define SIZE_S 's' /* short/single real (32-bit) */ 00135 #define SIZE_L 'l' /* long/double real (64-bit) */ 00136 #define SIZE_T 't' /* temp/extended real (80-bit) */ 00137 #define SIZE_A 'a' /* packed decimal (80-bit BCD) */ 00138 00139 struct x86opc_insn_op { 00140 char type; 00141 char extra; 00142 char size; 00143 char extendedsize; 00144 }; 00145 00146 struct x86opc_insn_op_special { 00147 char type; 00148 char data; 00149 char res1; 00150 char res2; 00151 }; 00152 00153 struct x86opc_insn { 00154 char *name; 00155 x86opc_insn_op op[3]; 00156 }; 00157 00158 /* this can be a group (group!=0), an insn (group==0) && (insn.name!=0) or 00159 (otherwise) a reserved instruction. */ 00160 struct x86opc_finsn { 00161 x86opc_insn *group; 00162 x86opc_insn insn; 00163 }; 00164 00165 #define X86_REG_INVALID -2 00166 #define X86_REG_NO -1 00167 #define X86_REG_AX 0 00168 #define X86_REG_CX 1 00169 #define X86_REG_DX 2 00170 #define X86_REG_BX 3 00171 #define X86_REG_SP 4 00172 #define X86_REG_BP 5 00173 #define X86_REG_SI 6 00174 #define X86_REG_DI 7 00175 00176 #define X86_GROUPS 20 00177 00178 extern char *x86_regs[3][8]; 00179 extern char *x86_segs[8]; 00180 extern x86opc_insn x86_insns[256]; 00181 extern x86opc_insn x86_insns_ext[256]; 00182 extern x86opc_insn x86_group_insns[X86_GROUPS][8]; 00183 00184 extern x86opc_insn x86_modfloat_group_insns[8][8]; 00185 extern x86opc_finsn x86_float_group_insns[8][8]; 00186 00187 #endif /* __X86OPC_H__ */