source: trunk/minix/commands/i386/asmconv/asm86.h@ 9

Last change on this file since 9 was 9, checked in by Mattia Monga, 14 years ago

Minix 3.1.2a

File size: 4.6 KB
Line 
1/* asm86.h - 80X86 assembly intermediate Author: Kees J. Bot
2 * 27 Jun 1993
3 */
4
5typedef enum opcode { /* 80486 opcodes, from the i486 reference manual.
6 * Synonyms left out, some new words invented.
7 */
8 DOT_ALIGN,
9 DOT_ASCII, DOT_ASCIZ,
10 DOT_ASSERT, /* Pseudo's invented */
11 DOT_BASE,
12 DOT_COMM, DOT_LCOMM,
13 DOT_DATA1,
14 DOT_DATA2,
15 DOT_DATA4,
16 DOT_DEFINE, DOT_EXTERN,
17 DOT_EQU,
18 DOT_FILE, DOT_LINE,
19 DOT_LABEL,
20 DOT_LIST, DOT_NOLIST,
21 DOT_SPACE,
22 DOT_SYMB,
23 DOT_TEXT, DOT_ROM, DOT_DATA, DOT_BSS, DOT_END,
24 DOT_USE16, DOT_USE32,
25 AAA,
26 AAD,
27 AAM,
28 AAS,
29 ADC,
30 ADD,
31 AND,
32 ARPL,
33 BOUND,
34 BSF,
35 BSR,
36 BSWAP,
37 BT,
38 BTC,
39 BTR,
40 BTS,
41 CALL, CALLF, /* CALLF added */
42 CBW,
43 CLC,
44 CLD,
45 CLI,
46 CLTS,
47 CMC,
48 CMP,
49 CMPS,
50 CMPXCHG,
51 CWD,
52 DAA,
53 DAS,
54 DEC,
55 DIV,
56 ENTER,
57 F2XM1,
58 FABS,
59 FADD, FADDD, FADDS, FADDP, FIADDL, FIADDS,
60 FBLD,
61 FBSTP,
62 FCHS,
63 FCLEX,
64 FCOMD, FCOMS, FCOMPD, FCOMPS, FCOMPP,
65 FCOS,
66 FDECSTP,
67 FDIVD, FDIVS, FDIVP, FIDIVL, FIDIVS,
68 FDIVRD, FDIVRS, FDIVRP, FIDIVRL, FIDIVRS,
69 FFREE,
70 FICOM, FICOMP,
71 FILDQ, FILDL, FILDS,
72 FINCSTP,
73 FINIT,
74 FISTL, FISTS, FISTP,
75 FLDX, FLDD, FLDS,
76 FLD1, FLDL2T, FLDL2E, FLDPI, FLDLG2, FLDLN2, FLDZ,
77 FLDCW,
78 FLDENV,
79 FMULD, FMULS, FMULP, FIMULL, FIMULS,
80 FNOP,
81 FPATAN,
82 FPREM,
83 FPREM1,
84 FPTAN,
85 FRNDINT,
86 FRSTOR,
87 FSAVE,
88 FSCALE,
89 FSIN,
90 FSINCOS,
91 FSQRT,
92 FSTD, FSTS, FSTPX, FSTPD, FSTPS,
93 FSTCW,
94 FSTENV,
95 FSTSW,
96 FSUBD, FSUBS, FSUBP, FISUBL, FISUBS,
97 FSUBRD, FSUBRS, FSUBPR, FISUBRL, FISUBRS,
98 FTST,
99 FUCOM, FUCOMP, FUCOMPP,
100 FXAM,
101 FXCH,
102 FXTRACT,
103 FYL2X,
104 FYL2XP1,
105 HLT,
106 IDIV,
107 IMUL,
108 IN,
109 INC,
110 INS,
111 INT, INTO,
112 INVD,
113 INVLPG,
114 IRET, IRETD,
115 JA, JAE, JB, JBE, JCXZ, JE, JG, JGE, JL,
116 JLE, JNE, JNO, JNP, JNS, JO, JP, JS,
117 JMP, JMPF, /* JMPF added */
118 LAHF,
119 LAR,
120 LEA,
121 LEAVE,
122 LGDT, LIDT,
123 LGS, LSS, LDS, LES, LFS,
124 LLDT,
125 LMSW,
126 LOCK,
127 LODS,
128 LOOP, LOOPE, LOOPNE,
129 LSL,
130 LTR,
131 MOV,
132 MOVS,
133 MOVSX,
134 MOVSXB,
135 MOVZX,
136 MOVZXB,
137 MUL,
138 NEG,
139 NOP,
140 NOT,
141 OR,
142 OUT,
143 OUTS,
144 POP,
145 POPA,
146 POPF,
147 PUSH,
148 PUSHA,
149 PUSHF,
150 RCL, RCR, ROL, ROR,
151 RET, RETF, /* RETF added */
152 SAHF,
153 SAL, SAR, SHL, SHR,
154 SBB,
155 SCAS,
156 SETA, SETAE, SETB, SETBE, SETE, SETG, SETGE, SETL,
157 SETLE, SETNE, SETNO, SETNP, SETNS, SETO, SETP, SETS,
158 SGDT, SIDT,
159 SHLD,
160 SHRD,
161 SLDT,
162 SMSW,
163 STC,
164 STD,
165 STI,
166 STOS,
167 STR,
168 SUB,
169 TEST,
170 VERR, VERW,
171 WAIT,
172 WBINVD,
173 XADD,
174 XCHG,
175 XLAT,
176 XOR
177} opcode_t;
178
179#define is_pseudo(o) ((o) <= DOT_USE32)
180#define N_OPCODES ((int) XOR + 1)
181
182#define OPZ 0x01 /* Operand size prefix. */
183#define ADZ 0x02 /* Address size prefix. */
184
185typedef enum optype {
186 PSEUDO, JUMP, BYTE, WORD, OWORD /* Ordered list! */
187} optype_t;
188
189typedef enum repeat {
190 ONCE, REP, REPE, REPNE
191} repeat_t;
192
193typedef enum segment {
194 DEFSEG, CSEG, DSEG, ESEG, FSEG, GSEG, SSEG
195} segment_t;
196
197typedef struct expression {
198 int operator;
199 struct expression *left, *middle, *right;
200 char *name;
201 size_t len;
202 unsigned magic;
203} expression_t;
204
205typedef struct asm86 {
206 opcode_t opcode; /* DOT_TEXT, MOV, ... */
207 char *file; /* Name of the file it is found in. */
208 long line; /* Line number. */
209 optype_t optype; /* Type of operands: byte, word... */
210 int oaz; /* Operand/address size prefix? */
211 repeat_t rep; /* Repeat prefix used on this instr. */
212 segment_t seg; /* Segment override. */
213 expression_t *args; /* Arguments in ACK order. */
214 unsigned magic;
215} asm86_t;
216
217expression_t *new_expr(void);
218void del_expr(expression_t *a);
219asm86_t *new_asm86(void);
220void del_asm86(asm86_t *a);
221int isregister(const char *name);
222
223/*
224 * Format of the arguments of the asm86_t structure:
225 *
226 *
227 * ACK assembly operands expression_t cell:
228 * or part of operand: {operator, left, middle, right, name, len}
229 *
230 * [expr] {'[', nil, expr, nil}
231 * word {'W', nil, nil, nil, word}
232 * "string" {'S', nil, nil, nil, "string", strlen("string")}
233 * label = expr {'=', nil, expr, nil, label}
234 * expr * expr {'*', expr, nil, expr}
235 * - expr {'-', nil, expr, nil}
236 * (memory) {'(', nil, memory, nil}
237 * offset(base)(index*n) {'O', offset, base, index*n}
238 * base {'B', nil, nil, nil, base}
239 * index*4 {'4', nil, nil, nil, index}
240 * operand, oplist {',', operand, nil, oplist}
241 * label : {':', nil, nil, nil, label}
242 *
243 * The precedence of operators is ignored. The expression is simply copied
244 * as is, including parentheses. Problems like missing operators in the
245 * target language will have to be handled by rewriting the source language.
246 * 16-bit or 32-bit registers must be used where they are required by the
247 * target assembler even though ACK makes no difference between 'ax' and
248 * 'eax'. Asmconv is smart enough to transform compiler output. Human made
249 * assembly can be fixed up to be transformable.
250 */
Note: See TracBrowser for help on using the repository browser.