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.

204 lines
6.9 KiB

  1. #ifdef DEBUG
  2. #define dprintf printf
  3. #else
  4. #define dprintf //
  5. #endif
  6. // token classes and types
  7. #define ASM_CLASS_MASK 0xff00
  8. #define ASM_TYPE_MASK 0x00ff
  9. #define ASM_EOL_CLASS 0x000
  10. #define ASM_ADDOP_CLASS 0x100
  11. #define ASM_ADDOP_PLUS 0x101
  12. #define ASM_ADDOP_MINUS 0x102
  13. #define ASM_MULOP_CLASS 0x200
  14. #define ASM_MULOP_MULT 0x201
  15. #define ASM_MULOP_DIVIDE 0x202
  16. #define ASM_MULOP_MOD 0x203
  17. #define ASM_MULOP_SHL 0x204
  18. #define ASM_MULOP_SHR 0x205
  19. #define ASM_ANDOP_CLASS 0x300
  20. #define ASM_NOTOP_CLASS 0x400
  21. #define ASM_OROP_CLASS 0x500
  22. #define ASM_OROP_OR 0x501
  23. #define ASM_OROP_XOR 0x502
  24. #define ASM_RELOP_CLASS 0x600
  25. #define ASM_RELOP_EQ 0x601
  26. #define ASM_RELOP_NE 0x602
  27. #define ASM_RELOP_LE 0x603
  28. #define ASM_RELOP_LT 0x604
  29. #define ASM_RELOP_GE 0x605
  30. #define ASM_RELOP_GT 0x606
  31. #define ASM_UNOP_CLASS 0x700
  32. #define ASM_UNOP_BY 0x701 // UNDONE
  33. #define ASM_UNOP_WO 0x702 // UNDONE
  34. #define ASM_UNOP_DW 0x703 // UNDONE
  35. #define ASM_UNOP_POI 0x704 // UNDONE
  36. #define ASM_LOWOP_CLASS 0x800
  37. #define ASM_LOWOP_LOW 0x801
  38. #define ASM_LOWOP_HIGH 0x802
  39. #define ASM_PTROP_CLASS 0x900
  40. #define ASM_SIZE_CLASS 0xa00
  41. #define ASM_SIZE_BYTE (0xa00 + sizeB)
  42. #define ASM_SIZE_WORD (0xa00 + sizeW)
  43. #define ASM_SIZE_DWORD (0xa00 + sizeD)
  44. #define ASM_SIZE_FWORD (0xa00 + sizeF)
  45. #define ASM_SIZE_QWORD (0xa00 + sizeQ)
  46. #define ASM_SIZE_TBYTE (0xa00 + sizeT)
  47. #define ASM_SIZE_SWORD (0xa00 + sizeS)
  48. #define ASM_OFFOP_CLASS 0xb00
  49. #define ASM_COLNOP_CLASS 0xc00
  50. #define ASM_LPAREN_CLASS 0xd00
  51. #define ASM_RPAREN_CLASS 0xe00
  52. #define ASM_LBRACK_CLASS 0xf00
  53. #define ASM_RBRACK_CLASS 0x1000
  54. #define ASM_DOTOP_CLASS 0x1100
  55. #define ASM_SEGOVR_CLASS 0x1200
  56. #define ASM_SEGMENT_CLASS 0x1300 // value has 16-bit value
  57. #define ASM_COMMA_CLASS 0x1400
  58. #define ASM_REG_CLASS 0x1500
  59. #define ASM_REG_BYTE 0x1501
  60. #define ASM_REG_WORD 0x1502
  61. #define ASM_REG_DWORD 0x1503
  62. #define ASM_REG_SEGMENT 0x1504
  63. #define ASM_REG_CONTROL 0x1505
  64. #define ASM_REG_DEBUG 0x1506
  65. #define ASM_REG_TRACE 0x1507
  66. #define ASM_REG_FLOAT 0x1508
  67. #define ASM_REG_INDFLT 0x1509
  68. #define ASM_NUMBER_CLASS 0x1600
  69. #define ASM_SYMBOL_CLASS 0x1700
  70. #define ASM_ERROR_CLASS 0xff00 // only used for PeekToken
  71. #define tEnd 0x80
  72. #define eEnd 0x40
  73. // template flag and operand tokens
  74. enum {
  75. asNone, as0x0a, asOpRg, asSiz0, asSiz1, asWait, asSeg, asFSiz,
  76. asMpNx, asPrfx,
  77. asReg0, asReg1, asReg2, asReg3, asReg4, asReg5, asReg6, asReg7,
  78. opnAL, opnAX, opneAX, opnCL, opnDX, opnAp, opnEb, opnEw,
  79. opnEv, opnGb, opnGw, opnGv, opnGd, opnIm1, opnIm3, opnIb,
  80. opnIw, opnIv, opnJb, opnJv, opnM, opnMa, opnMb, opnMw,
  81. opnMd, opnMp, opnMs, opnMq, opnMt, opnMv, opnCd, opnDd,
  82. opnTd, opnRd, opnSt, opnSti, opnSeg, opnSw, opnXb, opnXv,
  83. opnYb, opnYv, opnOb, opnOv
  84. };
  85. #define asRegBase asReg0 // first of REG flags
  86. #define opnBase opnAL // first template operand type
  87. // if less, then flag, else operand
  88. enum {
  89. segX, segES, segCS, segSS, segDS, segFS, segGS
  90. };
  91. enum {
  92. typNULL, // no defined type
  93. typAX, // general register, value EAX
  94. typCL, // general register, value ECX
  95. typDX, // general register, value EDX
  96. typAbs, // absolute type (direct address)
  97. typExp, // expr (mod-r/m) general register or memory pointer
  98. typGen, // general register
  99. typReg, // general register (special reg MOV)
  100. typIm1, // immediate, value 1
  101. typIm3, // immediate, value 3
  102. typImm, // immediate
  103. typJmp, // jump relative offset
  104. typMem, // memory pointer
  105. typCtl, // control register
  106. typDbg, // debug register
  107. typTrc, // trace register
  108. typSt, // floating point top-of-stack
  109. typSti, // floating point index-on-stack
  110. typSeg, // segment register (PUSH/POP opcode)
  111. typSgr, // segment register (MOV opcode)
  112. typXsi, // string source address
  113. typYdi, // string destination address
  114. typOff // memory offset
  115. };
  116. enum {
  117. regG, // general register
  118. regS, // segment register
  119. regC, // control register
  120. regD, // debug register
  121. regT, // trace register
  122. regF, // float register (st)
  123. regI // float-index register (st(n))
  124. };
  125. enum {
  126. indAX, // index for EAX, AX, AL
  127. indCX, // index for ECX, CX, CL
  128. indDX, // index for EDX, DX, DL
  129. indBX, // index for EBX, BX, BL
  130. indSP, // index for ESP, SP, AH
  131. indBP, // index for EBP, BP, CH
  132. indSI, // index for ESI, SI, DH
  133. indDI // index for EDI, DI, BH
  134. };
  135. enum {
  136. sizeX, // no size
  137. sizeB, // byte size
  138. sizeW, // word size
  139. sizeV, // variable size (word or dword)
  140. sizeD, // dword size
  141. sizeP, // pointer size (dword or fword)
  142. sizeA, // dword or qword
  143. sizeF, // fword
  144. sizeQ, // qword
  145. sizeT, // ten-byte
  146. sizeS // sword
  147. };
  148. // mapping from operand token to operand type (class and opt. value)
  149. typedef struct tagOPNDTYPE {
  150. UCHAR type;
  151. UCHAR size;
  152. } OPNDTYPE, *POPNDTYPE;
  153. typedef struct tagASM_VALUE {
  154. ULONG value;
  155. USHORT segment;
  156. UCHAR reloc;
  157. UCHAR size;
  158. UCHAR flags;
  159. UCHAR segovr;
  160. UCHAR index;
  161. UCHAR base;
  162. UCHAR scale;
  163. } ASM_VALUE, *PASM_VALUE;
  164. // bit values of flags in ASM_VALUE
  165. // flags are mutually exclusive
  166. #define fREG 0x80 // set if register
  167. #define fIMM 0x40 // set if immediate
  168. #define fFPTR 0x20 // set if far ptr
  169. #define fPTR 0x10 // set if memory ptr (no reg index)
  170. #define fPTR16 0x08 // set if memory ptr with 16-bit reg index
  171. #define fPTR32 0x04 // set if memory ptr with 32-bit reg index