insns.h 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  1. /* insns.h header file for insns.c
  2. *
  3. * The Netwide Assembler is copyright (C) 1996 Simon Tatham and
  4. * Julian Hall. All rights reserved. The software is
  5. * redistributable under the license given in the file "LICENSE"
  6. * distributed in the NASM archive.
  7. */
  8. #ifndef NASM_INSNS_H
  9. #define NASM_INSNS_H
  10. #include "nasm.h"
  11. #include "tokens.h"
  12. #include "iflag.h"
  13. /* if changed, ITEMPLATE_END should be also changed accordingly */
  14. struct itemplate {
  15. enum opcode opcode; /* the token, passed from "parser.c" */
  16. int operands; /* number of operands */
  17. opflags_t opd[MAX_OPERANDS]; /* bit flags for operand types */
  18. decoflags_t deco[MAX_OPERANDS]; /* bit flags for operand decorators */
  19. const uint8_t *code; /* the code it assembles to */
  20. uint32_t iflag_idx; /* some flags referenced by index */
  21. };
  22. /* Use this helper to test instruction template flags */
  23. static inline bool itemp_has(const struct itemplate *itemp, unsigned int bit)
  24. {
  25. return iflag_test(&insns_flags[itemp->iflag_idx], bit);
  26. }
  27. /* Disassembler table structure */
  28. /*
  29. * If n == -1, then p points to another table of 256
  30. * struct disasm_index, otherwise p points to a list of n
  31. * struct itemplates to consider.
  32. */
  33. struct disasm_index {
  34. const void *p;
  35. int n;
  36. };
  37. /* Tables for the assembler and disassembler, respectively */
  38. extern const struct itemplate * const nasm_instructions[];
  39. extern const struct disasm_index itable[256];
  40. extern const struct disasm_index * const itable_vex[NASM_VEX_CLASSES][32][4];
  41. /* Common table for the byte codes */
  42. extern const uint8_t nasm_bytecodes[];
  43. /*
  44. * this define is used to signify the end of an itemplate
  45. */
  46. #define ITEMPLATE_END {I_none,0,{0,},{0,},NULL,0}
  47. /*
  48. * Pseudo-op tests
  49. */
  50. /* DB-type instruction (DB, DW, ...) */
  51. static inline bool const_func opcode_is_db(enum opcode opcode)
  52. {
  53. return opcode >= I_DB && opcode < I_RESB;
  54. }
  55. /* RESB-type instruction (RESB, RESW, ...) */
  56. static inline bool const_func opcode_is_resb(enum opcode opcode)
  57. {
  58. return opcode >= I_RESB && opcode < I_INCBIN;
  59. }
  60. /* Width of Dx and RESx instructions */
  61. /*
  62. * initialized data bytes length from opcode
  63. */
  64. static inline int const_func db_bytes(enum opcode opcode)
  65. {
  66. switch (opcode) {
  67. case I_DB:
  68. return 1;
  69. case I_DW:
  70. return 2;
  71. case I_DD:
  72. return 4;
  73. case I_DQ:
  74. return 8;
  75. case I_DT:
  76. return 10;
  77. case I_DO:
  78. return 16;
  79. case I_DY:
  80. return 32;
  81. case I_DZ:
  82. return 64;
  83. case I_none:
  84. return -1;
  85. default:
  86. return 0;
  87. }
  88. }
  89. /*
  90. * Uninitialized data bytes length from opcode
  91. */
  92. static inline int const_func resb_bytes(enum opcode opcode)
  93. {
  94. switch (opcode) {
  95. case I_RESB:
  96. return 1;
  97. case I_RESW:
  98. return 2;
  99. case I_RESD:
  100. return 4;
  101. case I_RESQ:
  102. return 8;
  103. case I_REST:
  104. return 10;
  105. case I_RESO:
  106. return 16;
  107. case I_RESY:
  108. return 32;
  109. case I_RESZ:
  110. return 64;
  111. case I_none:
  112. return -1;
  113. default:
  114. return 0;
  115. }
  116. }
  117. #endif /* NASM_INSNS_H */