Leaked source code of windows server 2003
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.

207 lines
7.2 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_SIGNED_NUMBER_CLASS 0x1601
  70. #define ASM_SYMBOL_CLASS 0x1700
  71. #define ASM_ERROR_CLASS 0xff00 // only used for PeekToken
  72. #define tEnd 0x80
  73. #define eEnd 0x40
  74. // template flag and operand tokens
  75. enum {
  76. asNone, as0x0a, asOpRg, asSiz0, asSiz1, asWait, asSeg, asFSiz,
  77. asMpNx, asPrfx,
  78. asReg0, asReg1, asReg2, asReg3, asReg4, asReg5, asReg6, asReg7,
  79. opnAL, opnAX, opneAX, opnCL, opnDX, opnAp, opnEb, opnEw,
  80. opnEv, opnGb, opnGw, opnGv, opnGd, opnIm1, opnIm3, opnIb,
  81. opnIw, opnIv, opnJb, opnJv, opnM, opnMa, opnMb, opnMw,
  82. opnMd, opnMp, opnMs, opnMq, opnMt, opnMv, opnCd, opnDd,
  83. opnTd, opnRd, opnSt, opnSti, opnSeg, opnSw, opnXb, opnXv,
  84. opnYb, opnYv, opnOb, opnOv, opnIbe,
  85. };
  86. #define asRegBase asReg0 // first of REG flags
  87. #define opnBase opnAL // first template operand type
  88. // if less, then flag, else operand
  89. enum {
  90. segX, segES, segCS, segSS, segDS, segFS, segGS
  91. };
  92. enum {
  93. typNULL, // no defined type
  94. typAX, // general register, value EAX
  95. typCL, // general register, value ECX
  96. typDX, // general register, value EDX
  97. typAbs, // absolute type (direct address)
  98. typExp, // expr (mod-r/m) general register or memory pointer
  99. typGen, // general register
  100. typReg, // general register (special reg MOV)
  101. typIm1, // immediate, value 1
  102. typIm3, // immediate, value 3
  103. typImm, // immediate
  104. typJmp, // jump relative offset
  105. typMem, // memory pointer
  106. typCtl, // control register
  107. typDbg, // debug register
  108. typTrc, // trace register
  109. typSt, // floating point top-of-stack
  110. typSti, // floating point index-on-stack
  111. typSeg, // segment register (PUSH/POP opcode)
  112. typSgr, // segment register (MOV opcode)
  113. typXsi, // string source address
  114. typYdi, // string destination address
  115. typOff, // memory offset
  116. typImmEx, // immediate, sign-extended
  117. };
  118. enum {
  119. regG, // general register
  120. regS, // segment register
  121. regC, // control register
  122. regD, // debug register
  123. regT, // trace register
  124. regF, // float register (st)
  125. regI // float-index register (st(n))
  126. };
  127. enum {
  128. indAX, // index for EAX, AX, AL
  129. indCX, // index for ECX, CX, CL
  130. indDX, // index for EDX, DX, DL
  131. indBX, // index for EBX, BX, BL
  132. indSP, // index for ESP, SP, AH
  133. indBP, // index for EBP, BP, CH
  134. indSI, // index for ESI, SI, DH
  135. indDI // index for EDI, DI, BH
  136. };
  137. enum {
  138. sizeX, // no size
  139. sizeB, // byte size
  140. sizeW, // word size
  141. sizeV, // variable size (word or dword)
  142. sizeD, // dword size
  143. sizeP, // pointer size (dword or fword)
  144. sizeA, // dword or qword
  145. sizeF, // fword
  146. sizeQ, // qword
  147. sizeT, // ten-byte
  148. sizeS // sword
  149. };
  150. // mapping from operand token to operand type (class and opt. value)
  151. typedef struct tagOPNDTYPE {
  152. UCHAR type;
  153. UCHAR size;
  154. } OPNDTYPE, *POPNDTYPE;
  155. typedef struct tagASM_VALUE {
  156. ULONG value;
  157. USHORT segment;
  158. UCHAR reloc;
  159. UCHAR size;
  160. UCHAR flags;
  161. UCHAR segovr;
  162. UCHAR index;
  163. UCHAR base;
  164. UCHAR scale;
  165. } ASM_VALUE, *PASM_VALUE;
  166. // bit values of flags in ASM_VALUE
  167. // flags are mutually exclusive
  168. #define fREG 0x80 // set if register
  169. #define fIMM 0x40 // set if immediate
  170. #define fFPTR 0x20 // set if far ptr
  171. #define fPTR 0x10 // set if memory ptr (no reg index)
  172. #define fPTR16 0x08 // set if memory ptr with 16-bit reg index
  173. #define fPTR32 0x04 // set if memory ptr with 32-bit reg index
  174. #define fSIGNED 0x02 // combine with fIMM for signed immediate