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