Du kannst nicht mehr als 25 Themen auswählen Themen müssen entweder mit einem Buchstaben oder einer Ziffer beginnen. Sie können Bindestriche („-“) enthalten und bis zu 35 Zeichen lang sein.

196 Zeilen
5.3KB

  1. /* udis86 - libudis86/decode.h
  2. *
  3. * Copyright (c) 2002-2009 Vivek Thampi
  4. * All rights reserved.
  5. *
  6. * Redistribution and use in source and binary forms, with or without modification,
  7. * are permitted provided that the following conditions are met:
  8. *
  9. * * Redistributions of source code must retain the above copyright notice,
  10. * this list of conditions and the following disclaimer.
  11. * * Redistributions in binary form must reproduce the above copyright notice,
  12. * this list of conditions and the following disclaimer in the documentation
  13. * and/or other materials provided with the distribution.
  14. *
  15. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
  16. * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
  17. * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  18. * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
  19. * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  20. * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
  21. * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
  22. * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  23. * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  24. * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  25. */
  26. #ifndef UD_DECODE_H
  27. #define UD_DECODE_H
  28. #include "types.h"
  29. #include "itab.h"
  30. #define MAX_INSN_LENGTH 15
  31. /* itab prefix bits */
  32. #define P_none ( 0 )
  33. #define P_cast ( 1 << 0 )
  34. #define P_CAST(n) ( ( n >> 0 ) & 1 )
  35. #define P_rexb ( 1 << 1 )
  36. #define P_REXB(n) ( ( n >> 1 ) & 1 )
  37. #define P_inv64 ( 1 << 4 )
  38. #define P_INV64(n) ( ( n >> 4 ) & 1 )
  39. #define P_rexw ( 1 << 5 )
  40. #define P_REXW(n) ( ( n >> 5 ) & 1 )
  41. #define P_def64 ( 1 << 7 )
  42. #define P_DEF64(n) ( ( n >> 7 ) & 1 )
  43. #define P_rexr ( 1 << 8 )
  44. #define P_REXR(n) ( ( n >> 8 ) & 1 )
  45. #define P_oso ( 1 << 9 )
  46. #define P_OSO(n) ( ( n >> 9 ) & 1 )
  47. #define P_aso ( 1 << 10 )
  48. #define P_ASO(n) ( ( n >> 10 ) & 1 )
  49. #define P_rexx ( 1 << 11 )
  50. #define P_REXX(n) ( ( n >> 11 ) & 1 )
  51. #define P_ImpAddr ( 1 << 12 )
  52. #define P_IMPADDR(n) ( ( n >> 12 ) & 1 )
  53. #define P_seg ( 1 << 13 )
  54. #define P_SEG(n) ( ( n >> 13 ) & 1 )
  55. #define P_str ( 1 << 14 )
  56. #define P_STR(n) ( ( n >> 14 ) & 1 )
  57. #define P_strz ( 1 << 15 )
  58. #define P_STR_ZF(n) ( ( n >> 15 ) & 1 )
  59. /* operand type constants -- order is important! */
  60. enum ud_operand_code {
  61. OP_NONE,
  62. OP_A, OP_E, OP_M, OP_G,
  63. OP_I, OP_F,
  64. OP_R0, OP_R1, OP_R2, OP_R3,
  65. OP_R4, OP_R5, OP_R6, OP_R7,
  66. OP_AL, OP_CL, OP_DL,
  67. OP_AX, OP_CX, OP_DX,
  68. OP_eAX, OP_eCX, OP_eDX,
  69. OP_rAX, OP_rCX, OP_rDX,
  70. OP_ES, OP_CS, OP_SS, OP_DS,
  71. OP_FS, OP_GS,
  72. OP_ST0, OP_ST1, OP_ST2, OP_ST3,
  73. OP_ST4, OP_ST5, OP_ST6, OP_ST7,
  74. OP_J, OP_S, OP_O,
  75. OP_I1, OP_I3, OP_sI,
  76. OP_V, OP_W, OP_Q, OP_P,
  77. OP_U, OP_N, OP_MU,
  78. OP_R, OP_C, OP_D,
  79. OP_MR
  80. } UD_ATTR_PACKED;
  81. /* operand size constants */
  82. enum ud_operand_size {
  83. SZ_NA = 0,
  84. SZ_Z = 1,
  85. SZ_V = 2,
  86. SZ_RDQ = 7,
  87. /* the following values are used as is,
  88. * and thus hard-coded. changing them
  89. * will break internals
  90. */
  91. SZ_B = 8,
  92. SZ_W = 16,
  93. SZ_D = 32,
  94. SZ_Q = 64,
  95. SZ_T = 80,
  96. SZ_O = 128,
  97. SZ_Y = 17,
  98. /*
  99. * complex size types, that encode sizes for operands
  100. * of type MR (memory or register), for internal use
  101. * only. Id space 256 and above.
  102. */
  103. SZ_BD = (SZ_B << 8) | SZ_D,
  104. SZ_BV = (SZ_B << 8) | SZ_V,
  105. SZ_WD = (SZ_W << 8) | SZ_D,
  106. SZ_WV = (SZ_W << 8) | SZ_V,
  107. SZ_WY = (SZ_W << 8) | SZ_Y,
  108. SZ_DY = (SZ_D << 8) | SZ_Y,
  109. SZ_WO = (SZ_W << 8) | SZ_O,
  110. SZ_DO = (SZ_D << 8) | SZ_O,
  111. SZ_QO = (SZ_Q << 8) | SZ_O,
  112. } UD_ATTR_PACKED;
  113. /* resolve complex size type.
  114. */
  115. static inline enum ud_operand_size
  116. Mx_mem_size(enum ud_operand_size size)
  117. {
  118. return (size >> 8) & 0xff;
  119. }
  120. static inline enum ud_operand_size
  121. Mx_reg_size(enum ud_operand_size size)
  122. {
  123. return size & 0xff;
  124. }
  125. /* A single operand of an entry in the instruction table.
  126. * (internal use only)
  127. */
  128. struct ud_itab_entry_operand
  129. {
  130. enum ud_operand_code type;
  131. enum ud_operand_size size;
  132. };
  133. /* A single entry in an instruction table.
  134. *(internal use only)
  135. */
  136. struct ud_itab_entry
  137. {
  138. enum ud_mnemonic_code mnemonic;
  139. struct ud_itab_entry_operand operand1;
  140. struct ud_itab_entry_operand operand2;
  141. struct ud_itab_entry_operand operand3;
  142. uint32_t prefix;
  143. };
  144. struct ud_lookup_table_list_entry {
  145. const uint16_t *table;
  146. enum ud_table_type type;
  147. const char *meta;
  148. };
  149. static inline int
  150. ud_opcode_field_sext(uint8_t primary_opcode)
  151. {
  152. return (primary_opcode & 0x02) != 0;
  153. }
  154. extern struct ud_itab_entry ud_itab[];
  155. extern struct ud_lookup_table_list_entry ud_lookup_table_list[];
  156. #endif /* UD_DECODE_H */
  157. /* vim:cindent
  158. * vim:expandtab
  159. * vim:ts=4
  160. * vim:sw=4
  161. */