decode.h 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197
  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 "udint.h"
  30. #include "itab.h"
  31. #define MAX_INSN_LENGTH 15
  32. /* itab prefix bits */
  33. #define P_none ( 0 )
  34. #define P_inv64 ( 1 << 0 )
  35. #define P_INV64(n) ( ( n >> 0 ) & 1 )
  36. #define P_def64 ( 1 << 1 )
  37. #define P_DEF64(n) ( ( n >> 1 ) & 1 )
  38. #define P_oso ( 1 << 2 )
  39. #define P_OSO(n) ( ( n >> 2 ) & 1 )
  40. #define P_aso ( 1 << 3 )
  41. #define P_ASO(n) ( ( n >> 3 ) & 1 )
  42. #define P_rexb ( 1 << 4 )
  43. #define P_REXB(n) ( ( n >> 4 ) & 1 )
  44. #define P_rexw ( 1 << 5 )
  45. #define P_REXW(n) ( ( n >> 5 ) & 1 )
  46. #define P_rexr ( 1 << 6 )
  47. #define P_REXR(n) ( ( n >> 6 ) & 1 )
  48. #define P_rexx ( 1 << 7 )
  49. #define P_REXX(n) ( ( n >> 7 ) & 1 )
  50. #define P_seg ( 1 << 8 )
  51. #define P_SEG(n) ( ( n >> 8 ) & 1 )
  52. #define P_vexl ( 1 << 9 )
  53. #define P_VEXL(n) ( ( n >> 9 ) & 1 )
  54. #define P_vexw ( 1 << 10 )
  55. #define P_VEXW(n) ( ( n >> 10 ) & 1 )
  56. #define P_str ( 1 << 11 )
  57. #define P_STR(n) ( ( n >> 11 ) & 1 )
  58. #define P_strz ( 1 << 12 )
  59. #define P_STR_ZF(n) ( ( n >> 12 ) & 1 )
  60. /* operand type constants -- order is important! */
  61. enum ud_operand_code {
  62. OP_NONE,
  63. OP_A, OP_E, OP_M, OP_G,
  64. OP_I, OP_F,
  65. OP_R0, OP_R1, OP_R2, OP_R3,
  66. OP_R4, OP_R5, OP_R6, OP_R7,
  67. OP_AL, OP_CL, OP_DL,
  68. OP_AX, OP_CX, OP_DX,
  69. OP_eAX, OP_eCX, OP_eDX,
  70. OP_rAX, OP_rCX, OP_rDX,
  71. OP_ES, OP_CS, OP_SS, OP_DS,
  72. OP_FS, OP_GS,
  73. OP_ST0, OP_ST1, OP_ST2, OP_ST3,
  74. OP_ST4, OP_ST5, OP_ST6, OP_ST7,
  75. OP_J, OP_S, OP_O,
  76. OP_I1, OP_I3, OP_sI,
  77. OP_V, OP_W, OP_Q, OP_P,
  78. OP_U, OP_N, OP_MU, OP_H,
  79. OP_L,
  80. OP_R, OP_C, OP_D,
  81. OP_MR
  82. } UD_ATTR_PACKED;
  83. /*
  84. * Operand size constants
  85. *
  86. * Symbolic constants for various operand sizes. Some of these constants
  87. * are given a value equal to the width of the data (SZ_B == 8), such
  88. * that they maybe used interchangeably in the internals. Modifying them
  89. * will most certainly break things!
  90. */
  91. typedef uint16_t ud_operand_size_t;
  92. #define SZ_NA 0
  93. #define SZ_Z 1
  94. #define SZ_V 2
  95. #define SZ_Y 3
  96. #define SZ_X 4
  97. #define SZ_RDQ 7
  98. #define SZ_B 8
  99. #define SZ_W 16
  100. #define SZ_D 32
  101. #define SZ_Q 64
  102. #define SZ_T 80
  103. #define SZ_O 12
  104. #define SZ_DQ 128 /* double quad */
  105. #define SZ_QQ 256 /* quad quad */
  106. /*
  107. * Complex size types; that encode sizes for operands of type MR (memory or
  108. * register); for internal use only. Id space above 256.
  109. */
  110. #define SZ_BD ((SZ_B << 8) | SZ_D)
  111. #define SZ_BV ((SZ_B << 8) | SZ_V)
  112. #define SZ_WD ((SZ_W << 8) | SZ_D)
  113. #define SZ_WV ((SZ_W << 8) | SZ_V)
  114. #define SZ_WY ((SZ_W << 8) | SZ_Y)
  115. #define SZ_DY ((SZ_D << 8) | SZ_Y)
  116. #define SZ_WO ((SZ_W << 8) | SZ_O)
  117. #define SZ_DO ((SZ_D << 8) | SZ_O)
  118. #define SZ_QO ((SZ_Q << 8) | SZ_O)
  119. /* resolve complex size type.
  120. */
  121. static UD_INLINE ud_operand_size_t
  122. Mx_mem_size(ud_operand_size_t size)
  123. {
  124. return (size >> 8) & 0xff;
  125. }
  126. static UD_INLINE ud_operand_size_t
  127. Mx_reg_size(ud_operand_size_t size)
  128. {
  129. return size & 0xff;
  130. }
  131. /* A single operand of an entry in the instruction table.
  132. * (internal use only)
  133. */
  134. struct ud_itab_entry_operand
  135. {
  136. enum ud_operand_code type;
  137. ud_operand_size_t size;
  138. };
  139. /* A single entry in an instruction table.
  140. *(internal use only)
  141. */
  142. struct ud_itab_entry
  143. {
  144. enum ud_mnemonic_code mnemonic;
  145. struct ud_itab_entry_operand operand1;
  146. struct ud_itab_entry_operand operand2;
  147. struct ud_itab_entry_operand operand3;
  148. struct ud_itab_entry_operand operand4;
  149. uint32_t prefix;
  150. };
  151. struct ud_lookup_table_list_entry {
  152. const uint16_t *table;
  153. enum ud_table_type type;
  154. const char *meta;
  155. };
  156. extern struct ud_itab_entry ud_itab[];
  157. extern struct ud_lookup_table_list_entry ud_lookup_table_list[];
  158. #endif /* UD_DECODE_H */
  159. /* vim:cindent
  160. * vim:expandtab
  161. * vim:ts=4
  162. * vim:sw=4
  163. */