DOSBox-X
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Defines
src/cpu/core_full/support.h
00001 /*
00002  *  Copyright (C) 2002-2020  The DOSBox Team
00003  *
00004  *  This program is free software; you can redistribute it and/or modify
00005  *  it under the terms of the GNU General Public License as published by
00006  *  the Free Software Foundation; either version 2 of the License, or
00007  *  (at your option) any later version.
00008  *
00009  *  This program is distributed in the hope that it will be useful,
00010  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
00011  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00012  *  GNU General Public License for more details.
00013  *
00014  *  You should have received a copy of the GNU General Public License along
00015  *  with this program; if not, write to the Free Software Foundation, Inc.,
00016  *  51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
00017  */
00018 
00019 enum {
00020         L_N=0,
00021         L_SKIP,
00022         /* Grouped ones using MOD/RM */
00023         L_MODRM,L_MODRM_NVM,L_POPwRM,L_POPdRM,
00024         
00025         L_Ib,L_Iw,L_Id,
00026         L_Ibx,L_Iwx,L_Idx,                              //Sign extend
00027         L_Ifw,L_Ifd,
00028         L_OP,
00029 
00030         L_REGb,L_REGw,L_REGd,
00031         L_REGbIb,L_REGwIw,L_REGdId,
00032         L_POPw,L_POPd,
00033         L_POPfw,L_POPfd,
00034         L_SEG,
00035 
00036         L_INTO,
00037 
00038         L_VAL,
00039         L_PRESEG,
00040         L_DOUBLE,
00041         L_PREOP,L_PREADD,L_PREREP,L_PREREPNE,
00042         L_STRING,
00043 
00044 /* Direct ones */
00045         D_IRETw,D_IRETd,
00046         D_PUSHAw,D_PUSHAd,
00047         D_POPAw,D_POPAd,
00048         D_POPSEGw,D_POPSEGd,
00049         D_DAA,D_DAS,
00050         D_AAA,D_AAS,
00051         D_CBW,D_CWDE,
00052         D_CWD,D_CDQ,
00053         D_SETALC,
00054         D_XLAT,
00055         D_CLI,D_STI,D_STC,D_CLC,D_CMC,D_CLD,D_STD,
00056         D_NOP,D_WAIT,
00057         D_ENTERw,D_ENTERd,
00058         D_LEAVEw,D_LEAVEd,
00059         
00060         D_RETFw,D_RETFd,
00061         D_RETFwIw,D_RETFdIw,
00062         D_POPF,D_PUSHF,
00063         D_SAHF,D_LAHF,
00064         D_CPUID,
00065         D_HLT,D_CLTS,
00066         D_LOCK,D_ICEBP,
00067         D_RDTSC,
00068         L_ERROR
00069 };
00070 
00071 
00072 enum {
00073         O_N=t_LASTFLAG,
00074         O_COND,
00075         O_XCHG_AX,O_XCHG_EAX,
00076         O_IMULRw,O_IMULRd,
00077         O_BOUNDw,O_BOUNDd,
00078         O_CALLNw,O_CALLNd,
00079         O_CALLFw,O_CALLFd,
00080         O_JMPFw,O_JMPFd,
00081 
00082         O_OPAL,O_ALOP,
00083         O_OPAX,O_AXOP,
00084         O_OPEAX,O_EAXOP,
00085         O_INT,
00086         O_SEGDS,O_SEGES,O_SEGFS,O_SEGGS,O_SEGSS,
00087         O_LOOP,O_LOOPZ,O_LOOPNZ,O_JCXZ,
00088         O_INb,O_INw,O_INd,
00089         O_OUTb,O_OUTw,O_OUTd,
00090 
00091         O_NOT,O_AAM,O_AAD,
00092         O_MULb,O_MULw,O_MULd,
00093         O_IMULb,O_IMULw,O_IMULd,
00094         O_DIVb,O_DIVw,O_DIVd,
00095         O_IDIVb,O_IDIVw,O_IDIVd,
00096         O_CBACK,
00097 
00098 
00099         O_DSHLw,O_DSHLd,
00100         O_DSHRw,O_DSHRd,
00101         O_C_O   ,O_C_NO ,O_C_B  ,O_C_NB ,O_C_Z  ,O_C_NZ ,O_C_BE ,O_C_NBE,
00102         O_C_S   ,O_C_NS ,O_C_P  ,O_C_NP ,O_C_L  ,O_C_NL ,O_C_LE ,O_C_NLE,
00103 
00104         O_GRP6w,O_GRP6d,
00105         O_GRP7w,O_GRP7d,
00106         O_M_CRx_Rd,O_M_Rd_CRx,
00107         O_M_DRx_Rd,O_M_Rd_DRx,
00108         O_M_TRx_Rd,O_M_Rd_TRx,
00109         O_LAR,O_LSL,
00110         O_ARPL,
00111         
00112         O_BTw,O_BTSw,O_BTRw,O_BTCw,
00113         O_BTd,O_BTSd,O_BTRd,O_BTCd,
00114         O_BSFw,O_BSRw,O_BSFd,O_BSRd,
00115 
00116         O_BSWAPw, O_BSWAPd,
00117         O_CMPXCHG,
00118         O_FPU
00119 
00120 
00121 };
00122 
00123 enum {
00124         S_N=0,
00125         S_C_Eb,
00126         S_Eb,S_Gb,S_EbGb,
00127         S_Ew,S_Gw,S_EwGw,
00128         S_Ed,S_Gd,S_EdGd,S_EdMw,
00129 
00130         
00131         S_REGb,S_REGw,S_REGd,
00132         S_PUSHw,S_PUSHd,
00133         S_SEGm,
00134         S_SEGGw,S_SEGGd,
00135 
00136         
00137         S_AIPw,S_C_AIPw,
00138         S_AIPd,S_C_AIPd,
00139 
00140         S_IP,S_IPIw
00141 };
00142 
00143 enum {
00144         R_OUTSB,R_OUTSW,R_OUTSD,
00145         R_INSB,R_INSW,R_INSD,
00146         R_MOVSB,R_MOVSW,R_MOVSD,
00147         R_LODSB,R_LODSW,R_LODSD,
00148         R_STOSB,R_STOSW,R_STOSD,
00149         R_SCASB,R_SCASW,R_SCASD,
00150         R_CMPSB,R_CMPSW,R_CMPSD
00151 };
00152 
00153 enum {
00154         M_None=0,
00155         M_Ebx,M_Eb,M_Gb,M_EbGb,M_GbEb,
00156         M_Ewx,M_Ew,M_Gw,M_EwGw,M_GwEw,M_EwxGwx,M_EwGwt,
00157         M_Edx,M_Ed,M_Gd,M_EdGd,M_GdEd,M_EdxGdx,M_EdGdt,
00158         
00159         M_EbIb,M_EwIb,M_EdIb,
00160         M_EwIw,M_EwIbx,M_EwxIbx,M_EwxIwx,M_EwGwIb,M_EwGwCL,
00161         M_EdId,M_EdIbx,M_EdGdIb,M_EdGdCL,
00162         
00163         M_Efw,M_Efd,
00164         
00165         M_Ib,M_Iw,M_Id,
00166 
00167 
00168         M_SEG,M_EA,
00169         M_GRP,
00170         //Special shift groups
00171         M_SHIFT_1, M_SHIFT_Ib, M_SHIFT_CL,
00172 
00173         M_POPw,M_POPd
00174 };
00175 
00176 struct OpCode {
00177         Bit8u load,op,save,extra;
00178 };
00179 
00180 struct FullData {
00181         Bitu entry;
00182         Bitu rm;
00183         EAPoint rm_eaa;
00184         Bit32u rm_off;
00185         Bitu rm_eai;
00186         Bitu rm_index;
00187         Bitu rm_mod;
00188         OpCode code;
00189         EAPoint cseip;
00190 #ifdef WORDS_BIGENDIAN
00191         union {
00192                 Bit32u dword[1];
00193                 Bit32s dwords[1];
00194                 Bit16u word[2];
00195                 Bit16s words[2];
00196                 Bit8u byte[4];
00197                 Bit8s bytes[4];
00198                 } blah1,blah2,blah_imm;
00199 #else
00200         union { 
00201                 Bit8u b;Bit8s bs;
00202                 Bit16u w;Bit16s ws;
00203                 Bit32u d;Bit32s ds;
00204         } op1,op2,imm;
00205 #endif
00206         Bitu new_flags;
00207         struct {
00208                 EAPoint base;
00209         } seg;
00210         Bitu cond;
00211         bool repz;
00212         Bitu prefix;
00213 };
00214 
00215 /* Some defines to get the names correct. */
00216 #ifdef WORDS_BIGENDIAN
00217 
00218 #define inst_op1_b  inst.blah1.byte[3]
00219 #define inst_op1_bs inst.blah1.bytes[3]
00220 #define inst_op1_w  inst.blah1.word[1]
00221 #define inst_op1_ws inst.blah1.words[1]
00222 #define inst_op1_d  inst.blah1.dword[0]
00223 #define inst_op1_ds inst.blah1.dwords[0]
00224 
00225 #define inst_op2_b  inst.blah2.byte[3]
00226 #define inst_op2_bs inst.blah2.bytes[3]
00227 #define inst_op2_w  inst.blah2.word[1]
00228 #define inst_op2_ws inst.blah2.words[1]
00229 #define inst_op2_d  inst.blah2.dword[0]
00230 #define inst_op2_ds inst.blah2.dwords[0]
00231 
00232 #define inst_imm_b  inst.blah_imm.byte[3]
00233 #define inst_imm_bs inst.blah_imm.bytes[3]
00234 #define inst_imm_w  inst.blah_imm.word[1]
00235 #define inst_imm_ws inst.blah_imm.words[1]
00236 #define inst_imm_d  inst.blah_imm.dword[0]
00237 #define inst_imm_ds inst.blah_imm.dwords[0]
00238 
00239 #else
00240 
00241 #define inst_op1_b  inst.op1.b
00242 #define inst_op1_bs inst.op1.bs
00243 #define inst_op1_w  inst.op1.w
00244 #define inst_op1_ws inst.op1.ws
00245 #define inst_op1_d  inst.op1.d
00246 #define inst_op1_ds inst.op1.ds
00247 
00248 #define inst_op2_b  inst.op2.b
00249 #define inst_op2_bs inst.op2.bs
00250 #define inst_op2_w  inst.op2.w
00251 #define inst_op2_ws inst.op2.ws
00252 #define inst_op2_d  inst.op2.d
00253 #define inst_op2_ds inst.op2.ds
00254 
00255 #define inst_imm_b  inst.imm.b
00256 #define inst_imm_bs inst.imm.bs
00257 #define inst_imm_w  inst.imm.w
00258 #define inst_imm_ws inst.imm.ws
00259 #define inst_imm_d  inst.imm.d
00260 #define inst_imm_ds inst.imm.ds
00261 
00262 #endif
00263 
00264 
00265 #define PREFIX_NONE             0x0
00266 #define PREFIX_ADDR             0x1
00267 #define PREFIX_SEG              0x2
00268 #define PREFIX_REP              0x4
00269