Source code of Windows XP (NT5)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

459 lines
12 KiB

  1. /* x86 v1.0
  2. *
  3. * XGUEST.H
  4. * Guest processor definitions/conventions
  5. *
  6. * History
  7. * Created 20-Oct-90 by Jeff Parsons
  8. *
  9. * COPYRIGHT NOTICE
  10. * This source file may not be distributed, modified or incorporated into
  11. * another product without prior approval from the author, Jeff Parsons.
  12. * This file may be copied to designated servers and machines authorized to
  13. * access those servers, but that does not imply any form of approval.
  14. */
  15. #define GUESTMEM_SIZE (640*K)
  16. #define GUESTMEM_MIN (32*K) // smallest PC size ever
  17. #define GUESTMEM_MAX (960*K) // uses all but the last 64k ROM block
  18. #define GUESTVID_SIZE (4*K) // for MONO emulation
  19. #define GUESTVID_SEG (USHORT)0xB000
  20. #define GUESTROM_SIZE (64*K)
  21. #define GUESTROM_SEG (USHORT)0xF000
  22. #define FLATMEM_SIZE ((1024+64)*K)
  23. /* Processor-defined stuff
  24. */
  25. #define IVT_BEGIN 0x0000 // IVT table
  26. #define IVT_END 0x03FF
  27. #define RESET_SEG (USHORT)0xFFFF // processor reset address
  28. #define RESET_OFF 0x0000
  29. /* Useful macros
  30. */
  31. #define LINEAR(seg,off) (((((ULONG)(seg)<<4)+(off))) & ulWrapMask)
  32. #define LINEAR2(seg,off) (((ULONG)(seg)<<4)+(off))
  33. #define COMPOSITE(seg,off) (((ULONG)(seg)<<16)|(off))
  34. #define OFFCOMPOSITE(ul) WORDOF(ul,0)
  35. #define SEGCOMPOSITE(ul) WORDOF(ul,1)
  36. #define BYTESOFFSET(off) LOBYTE(off), HIBYTE(off)
  37. #define BYTESCOMPOSITE(seg,off) LOBYTE(off), HIBYTE(off), LOBYTE(seg), HIBYTE(seg)
  38. /* x86 opcodes (the really useful ones anyway)
  39. */
  40. #define OPX_ADDAXI 0x05
  41. #define OPX_PUSHDS 0x1E
  42. #define OPX_POPDS 0x1F
  43. #define OPX_ES 0x26
  44. #define OPX_CS 0x2E
  45. #define OPX_SS 0x36
  46. #define OPX_DS 0x3E
  47. #define OPX_PUSHAX 0x50
  48. #define OPX_POPAX 0x58
  49. #define OPX_JO 0x70
  50. #define OPX_JNO 0x71
  51. #define OPX_JB 0x72
  52. #define OPX_JNB 0x73
  53. #define OPX_JZ 0x74
  54. #define OPX_JNZ 0x75
  55. #define OPX_JBE 0x76
  56. #define OPX_JNBE 0x77
  57. #define OPX_JS 0x78
  58. #define OPX_JNS 0x79
  59. #define OPX_JP 0x7A
  60. #define OPX_JNP 0x7B
  61. #define OPX_JL 0x7C
  62. #define OPX_JGE 0x7D
  63. #define OPX_JLE 0x7E
  64. #define OPX_JG 0x7F
  65. #define OPX_MOVSEG2 0x8C
  66. #define OPX_LEA 0x8D
  67. #define OPX_MOV2SEG 0x8E
  68. #define OPX_CBW 0x98
  69. #define OPX_CWD 0x99
  70. #define OPX_MOVALOFF 0xA0
  71. #define OPX_MOVAXOFF 0xA1
  72. #define OPX_MOVSB 0xA4
  73. #define OPX_MOVSW 0xA5
  74. #define OPX_MOVAL 0xB0
  75. #define OPX_MOVCL 0xB1
  76. #define OPX_MOVDL 0xB2
  77. #define OPX_MOVBL 0xB3
  78. #define OPX_MOVAH 0xB4
  79. #define OPX_MOVCH 0xB5
  80. #define OPX_MOVDH 0xB6
  81. #define OPX_MOVBH 0xB7
  82. #define OPX_MOVAX 0xB8
  83. #define OPX_MOVCX 0xB9
  84. #define OPX_MOVDX 0xBA
  85. #define OPX_MOVBX 0xBB
  86. #define OPX_MOVSP 0xBC
  87. #define OPX_MOVBP 0xBD
  88. #define OPX_MOVSI 0xBE
  89. #define OPX_MOVDI 0xBF
  90. #define OPX_RETNV 0xC2
  91. #define OPX_RETN 0xC3
  92. #define OPX_LES 0xC4
  93. #define OPX_LDS 0xC5
  94. #define OPX_RETFV 0xCA
  95. #define OPX_RETF 0xCB
  96. #define OPX_INT3 0xCC
  97. #define OPX_INT 0xCD
  98. #define OPX_INTO 0xCE
  99. #define OPX_IRET 0xCF
  100. #define OPX_GBP 0xD6 // invalid opcode used for guest breakpoints
  101. #define OPX_XLAT 0xD7
  102. #define OPX_JCXZ 0xE3
  103. #define OPX_JMPR16 0xE9
  104. #define OPX_JMPF 0xEA
  105. #define OPX_JMPR8 0xEB
  106. #define OPX_LOCK 0xF0
  107. #define OPX_REPNZ 0xF2
  108. #define OPX_REPZ 0xF3
  109. #define OPX_CLC 0xF8
  110. #define OPX_STC 0xF9
  111. #define OPX_CLI 0xFA
  112. #define OPX_STI 0xFB
  113. #define OPX_GRP5 0xFF
  114. /* Mnemonic ordinals (indexes into apszMnemonic)
  115. */
  116. #define M_NONE 0
  117. #define M_AAA 1
  118. #define M_AAD 2
  119. #define M_AAM 3
  120. #define M_AAS 4
  121. #define M_ADC 5
  122. #define M_ADD 6
  123. #define M_AND 7
  124. #define M_ARPL 8
  125. #define M_ASIZE 9
  126. #define M_BOUND 10
  127. #define M_BSF 11
  128. #define M_BSR 12
  129. #define M_BT 13
  130. #define M_BTC 14
  131. #define M_BTR 15
  132. #define M_BTS 16
  133. #define M_CALL 17
  134. #define M_CBW 18
  135. #define M_CLC 19
  136. #define M_CLD 20
  137. #define M_CLI 21
  138. #define M_CLTS 22
  139. #define M_CMC 23
  140. #define M_CMP 24
  141. #define M_CMPSB 25
  142. #define M_CMPSW 26
  143. #define M_CS 27
  144. #define M_CWD 28
  145. #define M_DAA 29
  146. #define M_DAS 30
  147. #define M_DEC 31
  148. #define M_DIV 32
  149. #define M_DS 33
  150. #define M_ENTER 34
  151. #define M_ES 35
  152. #define M_ESC 36
  153. #define M_FADD 37
  154. #define M_FBLD 38
  155. #define M_FBSTP 39
  156. #define M_FCOM 40
  157. #define M_FCOMP 41
  158. #define M_FDIV 42
  159. #define M_FDIVR 43
  160. #define M_FIADD 44
  161. #define M_FICOM 45
  162. #define M_FICOMP 46
  163. #define M_FIDIV 47
  164. #define M_FIDIVR 48
  165. #define M_FILD 49
  166. #define M_FIMUL 50
  167. #define M_FIST 51
  168. #define M_FISTP 52
  169. #define M_FISUB 53
  170. #define M_FISUBR 54
  171. #define M_FLD 55
  172. #define M_FLDCW 56
  173. #define M_FLDENV 57
  174. #define M_FMUL 58
  175. #define M_FNSAVE 59
  176. #define M_FNSTCW 60
  177. #define M_FNSTENV 61
  178. #define M_FNSTSW 62
  179. #define M_FRSTOR 63
  180. #define M_FS 64
  181. #define M_FST 65
  182. #define M_FSTP 66
  183. #define M_FSUB 67
  184. #define M_FSUBR 68
  185. #define M_GBP 69
  186. #define M_GS 70
  187. #define M_HLT 71
  188. #define M_IDIV 72
  189. #define M_IMUL 73
  190. #define M_IN 74
  191. #define M_INC 75
  192. #define M_INS 76
  193. #define M_INT 77
  194. #define M_INT3 78
  195. #define M_INTO 79
  196. #define M_IRET 80
  197. #define M_JBE 81
  198. #define M_JB 82
  199. #define M_JCXZ 83
  200. #define M_JG 84
  201. #define M_JGE 85
  202. #define M_JL 86
  203. #define M_JLE 87
  204. #define M_JMP 88
  205. #define M_JNBE 89
  206. #define M_JNB 90
  207. #define M_JNO 91
  208. #define M_JNP 92
  209. #define M_JNS 93
  210. #define M_JNZ 94
  211. #define M_JO 95
  212. #define M_JP 96
  213. #define M_JS 97
  214. #define M_JZ 98
  215. #define M_LAHF 99
  216. #define M_LAR 100
  217. #define M_LDS 101
  218. #define M_LEA 102
  219. #define M_LEAVE 103
  220. #define M_LES 104
  221. #define M_LFS 105
  222. #define M_LGDT 106
  223. #define M_LGS 107
  224. #define M_LIDT 108
  225. #define M_LLDT 109
  226. #define M_LMSW 110
  227. #define M_LOCK 111
  228. #define M_LODSB 112
  229. #define M_LODSW 113
  230. #define M_LOOP 114
  231. #define M_LOOPNZ 115
  232. #define M_LOOPZ 116
  233. #define M_LSL 117
  234. #define M_LSS 118
  235. #define M_LTR 119
  236. #define M_MOV 120
  237. #define M_MOVSB 121
  238. #define M_MOVSW 122
  239. #define M_MOVSX 123
  240. #define M_MOVZX 124
  241. #define M_MUL 125
  242. #define M_NEG 126
  243. #define M_NOP 127
  244. #define M_NOT 128
  245. #define M_OR 129
  246. #define M_OSIZE 130
  247. #define M_OUT 131
  248. #define M_OUTS 132
  249. #define M_POP 133
  250. #define M_POPA 134
  251. #define M_POPF 135
  252. #define M_PUSH 136
  253. #define M_PUSHA 137
  254. #define M_PUSHF 138
  255. #define M_RCL 139
  256. #define M_RCR 140
  257. #define M_REPNZ 141
  258. #define M_REPZ 142
  259. #define M_RET 143
  260. #define M_RETF 144
  261. #define M_ROL 145
  262. #define M_ROR 146
  263. #define M_SAHF 147
  264. #define M_SAR 148
  265. #define M_SBB 149
  266. #define M_SCASB 150
  267. #define M_SCASW 151
  268. #define M_SETBE 152
  269. #define M_SETC 153
  270. #define M_SETG 154
  271. #define M_SETGE 155
  272. #define M_SETL 156
  273. #define M_SETLE 157
  274. #define M_SETNBE 158
  275. #define M_SETNC 159
  276. #define M_SETNO 160
  277. #define M_SETNP 161
  278. #define M_SETNS 162
  279. #define M_SETNZ 163
  280. #define M_SETO 164
  281. #define M_SETP 165
  282. #define M_SETS 166
  283. #define M_SETZ 167
  284. #define M_SGDT 156
  285. #define M_SHL 169
  286. #define M_SHLD 170
  287. #define M_SHR 171
  288. #define M_SHRD 172
  289. #define M_SIDT 173
  290. #define M_SLDT 174
  291. #define M_SMSW 175
  292. #define M_SS 176
  293. #define M_STC 177
  294. #define M_STD 178
  295. #define M_STI 179
  296. #define M_STOSB 180
  297. #define M_STOSW 181
  298. #define M_STR 182
  299. #define M_SUB 183
  300. #define M_TEST 184
  301. #define M_VERR 185
  302. #define M_VERW 186
  303. #define M_WAIT 187
  304. #define M_XCHG 188
  305. #define M_XLAT 189
  306. #define M_XOR 190
  307. #define MTOTAL 191
  308. /* ModRegRM masks and definitions
  309. */
  310. #define REG_AL 0x00 // bits 0-2 are standard Reg encodings
  311. #define REG_CL 0x01 //
  312. #define REG_DL 0x02 //
  313. #define REG_BL 0x03 //
  314. #define REG_AH 0x04 //
  315. #define REG_CH 0x05 //
  316. #define REG_DH 0x06 //
  317. #define REG_BH 0x07 //
  318. #define REG_AX 0x08 //
  319. #define REG_CX 0x09 //
  320. #define REG_DX 0x0A //
  321. #define REG_BX 0x0B //
  322. #define REG_SP 0x0C //
  323. #define REG_BP 0x0D //
  324. #define REG_SI 0x0E //
  325. #define REG_DI 0x0F //
  326. #define REG_ES 0x00 // bits 0-1 are standard SegReg encodings
  327. #define REG_CS 0x01 //
  328. #define REG_SS 0x02 //
  329. #define REG_DS 0x03 //
  330. #define REG_FS 0x04 //
  331. #define REG_GS 0x05 //
  332. #define MODMASK 0xC0 // mod/reg/rm definitions
  333. #define MODSHIFT 6 //
  334. #define MOD(m) (((m)&MODMASK)>>MODSHIFT)
  335. #define REGMASK 0x38 //
  336. #define REGSHIFT 3 //
  337. #define REG(r) (((r)&REGMASK)>>REGSHIFT)
  338. #define RMMASK 0x07 //
  339. #define RMSHIFT 0 //
  340. #define RM(b) (((b)&RMMASK)>>RMSHIFT)
  341. #define MODREGRM(m,r,b) ((BYTE)((((m)<<MODSHIFT)&MODMASK) | \
  342. (((r)<<REGSHIFT)&REGMASK) | \
  343. (((b)<<RMSHIFT )&RMMASK )))
  344. #define MOD_NODISP 0x00 // use RM below, no displacement
  345. #define MOD_DISP8 0x01 // use RM below + 8-bit displacement
  346. #define MOD_DISP16 0x02 // use RM below + 16-bit displacement
  347. #define MOD_REGISTER 0x03 // use REG above
  348. #define RM_BXSI 0x00 //
  349. #define RM_BXDI 0x01 //
  350. #define RM_BPSI 0x02 //
  351. #define RM_BPDI 0x03 //
  352. #define RM_SI 0x04 //
  353. #define RM_DI 0x05 //
  354. #define RM_BP 0x06 // note: if MOD_NODISP, this is IMMOFF
  355. #define RM_BX 0x07 //
  356. /* Operand type descriptor masks and definitions
  357. *
  358. * Note that the letters in () in the comments refer to Intel's
  359. * nomenclature used in Appendix A of the 80386 Prog. Reference Manual.
  360. */
  361. #define TYPE_SIZE 0x000F // size field
  362. #define TYPE_TYPE 0x00F0 // type field
  363. #define TYPE_IREG 0x0F00 // implied register field
  364. #define TYPE_OTHER 0xF000 // "other" field
  365. // TYPE_SIZE values. Note that some of the values (eg, TYPE_WORDIB
  366. // and TYPE_WORDIW) imply the presence of a third operand, for those
  367. // wierd cases....
  368. #define TYPE_NONE 0x0000 // (all other TYPE fields ignored)
  369. #define TYPE_BYTE 0x0001 // (b) byte, regardless of operand size
  370. #define TYPE_SBYTE 0x0002 // same as above, but sign-extended
  371. #define TYPE_WORD 0x0003 // (w) word, regardless...
  372. #define TYPE_WORDD 0x0004 // (v) word or double-word, depending...
  373. #define TYPE_DWORD 0x0005 // (d) double-word, regardless...
  374. #define TYPE_FARP 0x0006 // (p) 32-bit or 48-bit pointer, depending
  375. #define TYPE_2WORDD 0x0007 // (a) two memory operands (BOUND only)
  376. #define TYPE_DESC 0x0008 // (s) 6 byte pseudo-descriptor
  377. #define TYPE_WORDIB 0x0009 // two source operands (eg, IMUL)
  378. #define TYPE_WORDIW 0x000A // two source operands (eg, IMUL)
  379. // TYPE_TYPE values. Note that all values implying
  380. // the presence of a ModRegRM byte are >= TYPE_MODRM (clever, eh?)
  381. #define TYPE_IMM 0x0000 // (I) immediate data
  382. #define TYPE_ONE 0x0010 // implicit 1 (eg, shifts/rotates)
  383. #define TYPE_IMMOFF 0x0020 // (A) immediate offset
  384. #define TYPE_IMMREL 0x0030 // (J) immediate relative
  385. #define TYPE_DSSI 0x0040 // (X) memory addressed by DS:SI
  386. #define TYPE_ESDI 0x0050 // (Y) memory addressed by ES:DI
  387. #define TYPE_IMPREG 0x0060 // implicit register in TYPE_IREG
  388. #define TYPE_IMPSEG 0x0070 // implicit seg. register in TYPE_IREG
  389. #define TYPE_MODRM 0x0080 // (E) standard ModRM decoding
  390. #define TYPE_MEM 0x0090 // (M) ModRM refers to memory only
  391. #define TYPE_REG 0x00A0 // (G) standard Reg decoding
  392. #define TYPE_SEGREG 0x00B0 // (S) Reg selects segment register
  393. #define TYPE_MODREG 0x00C0 // (R) Mod refers to register only
  394. #define TYPE_CTLREG 0x00D0 // (C) Reg selects control register
  395. #define TYPE_DBGREG 0x00E0 // (D) Reg selects debug register
  396. #define TYPE_TSTREG 0x00F0 // (T) Reg selects test register
  397. // TYPE_IREG values, based on the REG_* constants.
  398. // For convenience, they include TYPE_IMPREG or TYPE_IMPSEG as appropriate.
  399. #define TYPE_AL (REG_AL<<8|TYPE_IMPREG|TYPE_BYTE)
  400. #define TYPE_CL (REG_CL<<8|TYPE_IMPREG|TYPE_BYTE)
  401. #define TYPE_DL (REG_DL<<8|TYPE_IMPREG|TYPE_BYTE)
  402. #define TYPE_BL (REG_BL<<8|TYPE_IMPREG|TYPE_BYTE)
  403. #define TYPE_AH (REG_AH<<8|TYPE_IMPREG|TYPE_BYTE)
  404. #define TYPE_CH (REG_CH<<8|TYPE_IMPREG|TYPE_BYTE)
  405. #define TYPE_DH (REG_DH<<8|TYPE_IMPREG|TYPE_BYTE)
  406. #define TYPE_BH (REG_BH<<8|TYPE_IMPREG|TYPE_BYTE)
  407. #define TYPE_AX (REG_AX<<8|TYPE_IMPREG|TYPE_WORD)
  408. #define TYPE_CX (REG_CX<<8|TYPE_IMPREG|TYPE_WORD)
  409. #define TYPE_DX (REG_DX<<8|TYPE_IMPREG|TYPE_WORD)
  410. #define TYPE_BX (REG_BX<<8|TYPE_IMPREG|TYPE_WORD)
  411. #define TYPE_SP (REG_SP<<8|TYPE_IMPREG|TYPE_WORD)
  412. #define TYPE_BP (REG_BP<<8|TYPE_IMPREG|TYPE_WORD)
  413. #define TYPE_SI (REG_SI<<8|TYPE_IMPREG|TYPE_WORD)
  414. #define TYPE_DI (REG_DI<<8|TYPE_IMPREG|TYPE_WORD)
  415. #define TYPE_ES (REG_ES<<8|TYPE_IMPSEG|TYPE_WORD)
  416. #define TYPE_CS (REG_CS<<8|TYPE_IMPSEG|TYPE_WORD)
  417. #define TYPE_SS (REG_SS<<8|TYPE_IMPSEG|TYPE_WORD)
  418. #define TYPE_DS (REG_DS<<8|TYPE_IMPSEG|TYPE_WORD)
  419. #define TYPE_FS (REG_FS<<8|TYPE_IMPSEG|TYPE_WORD)
  420. #define TYPE_GS (REG_GS<<8|TYPE_IMPSEG|TYPE_WORD)
  421. // TYPE_OTHER bit definitions
  422. #define TYPE_IN 0x1000 // operand is input
  423. #define TYPE_OUT 0x2000 // operand is output
  424. #define TYPE_BOTH (TYPE_IN|TYPE_OUT)
  425. #define TYPE_86 (CPU_86 << 14)
  426. #define TYPE_186 (CPU_186 << 14)
  427. #define TYPE_286 (CPU_286 << 14)
  428. #define TYPE_386 (CPU_386 << 14)