]>
Commit | Line | Data |
---|---|---|
14c7c974 A |
1 | /* |
2 | * Copyright (c) 1999 Apple Computer, Inc. All rights reserved. | |
3 | * | |
4 | * @APPLE_LICENSE_HEADER_START@ | |
5 | * | |
6 | * Portions Copyright (c) 1999 Apple Computer, Inc. All Rights | |
7 | * Reserved. This file contains Original Code and/or Modifications of | |
8 | * Original Code as defined in and that are subject to the Apple Public | |
9 | * Source License Version 1.1 (the "License"). You may not use this file | |
10 | * except in compliance with the License. Please obtain a copy of the | |
11 | * License at http://www.apple.com/publicsource and read it before using | |
12 | * this file. | |
13 | * | |
14 | * The Original Code and all software distributed under the License are | |
15 | * distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, EITHER | |
16 | * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, | |
17 | * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, | |
18 | * FITNESS FOR A PARTICULAR PURPOSE OR NON- INFRINGEMENT. Please see the | |
19 | * License for the specific language governing rights and limitations | |
20 | * under the License. | |
21 | * | |
22 | * @APPLE_LICENSE_HEADER_END@ | |
23 | */ | |
24 | /* nasm.h main header file for the Netwide Assembler: inter-module interface | |
25 | * | |
26 | * The Netwide Assembler is copyright (C) 1996 Simon Tatham and | |
27 | * Julian Hall. All rights reserved. The software is | |
28 | * redistributable under the licence given in the file "Licence" | |
29 | * distributed in the NASM archive. | |
30 | * | |
31 | * initial version: 27/iii/95 by Simon Tatham | |
32 | */ | |
33 | ||
34 | #ifndef NASM_NASM_H | |
35 | #define NASM_NASM_H | |
36 | ||
37 | #define NASM_MAJOR_VER 0 | |
38 | #define NASM_MINOR_VER 97 | |
39 | #define NASM_VER "0.97" | |
40 | ||
41 | #ifndef NULL | |
42 | #define NULL 0 | |
43 | #endif | |
44 | ||
45 | #ifndef FALSE | |
46 | #define FALSE 0 /* comes in handy */ | |
47 | #endif | |
48 | #ifndef TRUE | |
49 | #define TRUE 1 | |
50 | #endif | |
51 | ||
52 | #define NO_SEG -1L /* null segment value */ | |
53 | #define SEG_ABS 0x40000000L /* mask for far-absolute segments */ | |
54 | ||
55 | #ifndef FILENAME_MAX | |
56 | #define FILENAME_MAX 256 | |
57 | #endif | |
58 | ||
59 | /* | |
60 | * Name pollution problems: <time.h> on Digital UNIX pulls in some | |
61 | * strange hardware header file which sees fit to define R_SP. We | |
62 | * undefine it here so as not to break the enum below. | |
63 | */ | |
64 | #ifdef R_SP | |
65 | #undef R_SP | |
66 | #endif | |
67 | ||
68 | /* | |
69 | * We must declare the existence of this structure type up here, | |
70 | * since we have to reference it before we define it... | |
71 | */ | |
72 | struct ofmt; | |
73 | ||
74 | /* | |
75 | * ------------------------- | |
76 | * Error reporting functions | |
77 | * ------------------------- | |
78 | */ | |
79 | ||
80 | /* | |
81 | * An error reporting function should look like this. | |
82 | */ | |
83 | typedef void (*efunc) (int severity, char *fmt, ...); | |
84 | ||
85 | /* | |
86 | * These are the error severity codes which get passed as the first | |
87 | * argument to an efunc. | |
88 | */ | |
89 | ||
90 | #define ERR_WARNING 0 /* warn only: no further action */ | |
91 | #define ERR_NONFATAL 1 /* terminate assembly after phase */ | |
92 | #define ERR_FATAL 2 /* instantly fatal: exit with error */ | |
93 | #define ERR_PANIC 3 /* internal error: panic instantly | |
94 | * and dump core for reference */ | |
95 | #define ERR_MASK 0x0F /* mask off the above codes */ | |
96 | #define ERR_NOFILE 0x10 /* don't give source file name/line */ | |
97 | #define ERR_USAGE 0x20 /* print a usage message */ | |
98 | #define ERR_OFFBY1 0x40 /* report error as being on the line | |
99 | * we're just _about_ to read, not | |
100 | * the one we've just read */ | |
101 | #define ERR_PASS1 0x80 /* only print this error on pass one */ | |
102 | ||
103 | /* | |
104 | * These codes define specific types of suppressible warning. | |
105 | */ | |
106 | #define ERR_WARN_MNP 0x0100 /* macro-num-parameters warning */ | |
107 | #define ERR_WARN_OL 0x0200 /* orphan label (no colon, and | |
108 | * alone on line) */ | |
109 | #define ERR_WARN_NOV 0x0300 /* numeric overflow */ | |
110 | #define ERR_WARN_MASK 0xFF00 /* the mask for this feature */ | |
111 | #define ERR_WARN_SHR 8 /* how far to shift right */ | |
112 | #define ERR_WARN_MAX 3 /* the highest numbered one */ | |
113 | ||
114 | /* | |
115 | * ----------------------- | |
116 | * Other function typedefs | |
117 | * ----------------------- | |
118 | */ | |
119 | ||
120 | /* | |
121 | * A label-lookup function should look like this. | |
122 | */ | |
123 | typedef int (*lfunc) (char *label, long *segment, long *offset); | |
124 | ||
125 | /* | |
126 | * And a label-definition function like this. The boolean parameter | |
127 | * `is_norm' states whether the label is a `normal' label (which | |
128 | * should affect the local-label system), or something odder like | |
129 | * an EQU or a segment-base symbol, which shouldn't. | |
130 | */ | |
131 | typedef void (*ldfunc) (char *label, long segment, long offset, char *special, | |
132 | int is_norm, int isextrn, struct ofmt *ofmt, | |
133 | efunc error); | |
134 | ||
135 | /* | |
136 | * List-file generators should look like this: | |
137 | */ | |
138 | typedef struct { | |
139 | /* | |
140 | * Called to initialise the listing file generator. Before this | |
141 | * is called, the other routines will silently do nothing when | |
142 | * called. The `char *' parameter is the file name to write the | |
143 | * listing to. | |
144 | */ | |
145 | void (*init) (char *, efunc); | |
146 | ||
147 | /* | |
148 | * Called to clear stuff up and close the listing file. | |
149 | */ | |
150 | void (*cleanup) (void); | |
151 | ||
152 | /* | |
153 | * Called to output binary data. Parameters are: the offset; | |
154 | * the data; the data type. Data types are similar to the | |
155 | * output-format interface, only OUT_ADDRESS will _always_ be | |
156 | * displayed as if it's relocatable, so ensure that any non- | |
157 | * relocatable address has been converted to OUT_RAWDATA by | |
158 | * then. Note that OUT_RAWDATA+0 is a valid data type, and is a | |
159 | * dummy call used to give the listing generator an offset to | |
160 | * work with when doing things like uplevel(LIST_TIMES) or | |
161 | * uplevel(LIST_INCBIN). | |
162 | */ | |
163 | void (*output) (long, void *, unsigned long); | |
164 | ||
165 | /* | |
166 | * Called to send a text line to the listing generator. The | |
167 | * `int' parameter is LIST_READ or LIST_MACRO depending on | |
168 | * whether the line came directly from an input file or is the | |
169 | * result of a multi-line macro expansion. | |
170 | */ | |
171 | void (*line) (int, char *); | |
172 | ||
173 | /* | |
174 | * Called to change one of the various levelled mechanisms in | |
175 | * the listing generator. LIST_INCLUDE and LIST_MACRO can be | |
176 | * used to increase the nesting level of include files and | |
177 | * macro expansions; LIST_TIMES and LIST_INCBIN switch on the | |
178 | * two binary-output-suppression mechanisms for large-scale | |
179 | * pseudo-instructions. | |
180 | * | |
181 | * LIST_MACRO_NOLIST is synonymous with LIST_MACRO except that | |
182 | * it indicates the beginning of the expansion of a `nolist' | |
183 | * macro, so anything under that level won't be expanded unless | |
184 | * it includes another file. | |
185 | */ | |
186 | void (*uplevel) (int); | |
187 | ||
188 | /* | |
189 | * Reverse the effects of uplevel. | |
190 | */ | |
191 | void (*downlevel) (int); | |
192 | } ListGen; | |
193 | ||
194 | /* | |
195 | * The expression evaluator must be passed a scanner function; a | |
196 | * standard scanner is provided as part of nasmlib.c. The | |
197 | * preprocessor will use a different one. Scanners, and the | |
198 | * token-value structures they return, look like this. | |
199 | * | |
200 | * The return value from the scanner is always a copy of the | |
201 | * `t_type' field in the structure. | |
202 | */ | |
203 | struct tokenval { | |
204 | int t_type; | |
205 | long t_integer, t_inttwo; | |
206 | char *t_charptr; | |
207 | }; | |
208 | typedef int (*scanner) (void *private_data, struct tokenval *tv); | |
209 | ||
210 | /* | |
211 | * Token types returned by the scanner, in addition to ordinary | |
212 | * ASCII character values, and zero for end-of-string. | |
213 | */ | |
214 | enum { /* token types, other than chars */ | |
215 | TOKEN_INVALID = -1, /* a placeholder value */ | |
216 | TOKEN_EOS = 0, /* end of string */ | |
217 | TOKEN_EQ = '=', TOKEN_GT = '>', TOKEN_LT = '<', /* aliases */ | |
218 | TOKEN_ID = 256, TOKEN_NUM, TOKEN_REG, TOKEN_INSN, /* major token types */ | |
219 | TOKEN_ERRNUM, /* numeric constant with error in */ | |
220 | TOKEN_HERE, TOKEN_BASE, /* $ and $$ */ | |
221 | TOKEN_SPECIAL, /* BYTE, WORD, DWORD, FAR, NEAR, etc */ | |
222 | TOKEN_PREFIX, /* A32, O16, LOCK, REPNZ, TIMES, etc */ | |
223 | TOKEN_SHL, TOKEN_SHR, /* << and >> */ | |
224 | TOKEN_SDIV, TOKEN_SMOD, /* // and %% */ | |
225 | TOKEN_GE, TOKEN_LE, TOKEN_NE, /* >=, <= and <> (!= is same as <>) */ | |
226 | TOKEN_DBL_AND, TOKEN_DBL_OR, TOKEN_DBL_XOR, /* &&, || and ^^ */ | |
227 | TOKEN_SEG, TOKEN_WRT, /* SEG and WRT */ | |
228 | TOKEN_FLOAT /* floating-point constant */ | |
229 | }; | |
230 | ||
231 | /* | |
232 | * Expression-evaluator datatype. Expressions, within the | |
233 | * evaluator, are stored as an array of these beasts, terminated by | |
234 | * a record with type==0. Mostly, it's a vector type: each type | |
235 | * denotes some kind of a component, and the value denotes the | |
236 | * multiple of that component present in the expression. The | |
237 | * exception is the WRT type, whose `value' field denotes the | |
238 | * segment to which the expression is relative. These segments will | |
239 | * be segment-base types, i.e. either odd segment values or SEG_ABS | |
240 | * types. So it is still valid to assume that anything with a | |
241 | * `value' field of zero is insignificant. | |
242 | */ | |
243 | typedef struct { | |
244 | long type; /* a register, or EXPR_xxx */ | |
245 | long value; /* must be >= 32 bits */ | |
246 | } expr; | |
247 | ||
248 | /* | |
249 | * The evaluator can also return hints about which of two registers | |
250 | * used in an expression should be the base register. See also the | |
251 | * `operand' structure. | |
252 | */ | |
253 | struct eval_hints { | |
254 | int base; | |
255 | int type; | |
256 | }; | |
257 | ||
258 | /* | |
259 | * The actual expression evaluator function looks like this. When | |
260 | * called, it expects the first token of its expression to already | |
261 | * be in `*tv'; if it is not, set tv->t_type to TOKEN_INVALID and | |
262 | * it will start by calling the scanner. | |
263 | * | |
264 | * If a forward reference happens during evaluation, the evaluator | |
265 | * must set `*fwref' to TRUE if `fwref' is non-NULL. | |
266 | * | |
267 | * `critical' is non-zero if the expression may not contain forward | |
268 | * references. The evaluator will report its own error if this | |
269 | * occurs; if `critical' is 1, the error will be "symbol not | |
270 | * defined before use", whereas if `critical' is 2, the error will | |
271 | * be "symbol undefined". | |
272 | * | |
273 | * If `critical' has bit 4 set (in addition to its main value: 0x11 | |
274 | * and 0x12 correspond to 1 and 2) then an extended expression | |
275 | * syntax is recognised, in which relational operators such as =, < | |
276 | * and >= are accepted, as well as low-precedence logical operators | |
277 | * &&, ^^ and ||. | |
278 | * | |
279 | * If `hints' is non-NULL, it gets filled in with some hints as to | |
280 | * the base register in complex effective addresses. | |
281 | */ | |
282 | typedef expr *(*evalfunc) (scanner sc, void *scprivate, struct tokenval *tv, | |
283 | int *fwref, int critical, efunc error, | |
284 | struct eval_hints *hints); | |
285 | ||
286 | /* | |
287 | * There's also an auxiliary routine through which the evaluator | |
288 | * needs to hear about the value of $ and the label (if any) | |
289 | * defined on the current line. | |
290 | */ | |
291 | typedef void (*evalinfofunc) (char *labelname, long segment, long offset); | |
292 | ||
293 | /* | |
294 | * Special values for expr->type. ASSUMPTION MADE HERE: the number | |
295 | * of distinct register names (i.e. possible "type" fields for an | |
296 | * expr structure) does not exceed 124 (EXPR_REG_START through | |
297 | * EXPR_REG_END). | |
298 | */ | |
299 | #define EXPR_REG_START 1 | |
300 | #define EXPR_REG_END 124 | |
301 | #define EXPR_UNKNOWN 125L /* for forward references */ | |
302 | #define EXPR_SIMPLE 126L | |
303 | #define EXPR_WRT 127L | |
304 | #define EXPR_SEGBASE 128L | |
305 | ||
306 | /* | |
307 | * Preprocessors ought to look like this: | |
308 | */ | |
309 | typedef struct { | |
310 | /* | |
311 | * Called at the start of a pass; given a file name, the number | |
312 | * of the pass, an error reporting function, an evaluator | |
313 | * function, and a listing generator to talk to. | |
314 | */ | |
315 | void (*reset) (char *, int, efunc, evalfunc, ListGen *); | |
316 | ||
317 | /* | |
318 | * Called to fetch a line of preprocessed source. The line | |
319 | * returned has been malloc'ed, and so should be freed after | |
320 | * use. | |
321 | */ | |
322 | char *(*getline) (void); | |
323 | ||
324 | /* | |
325 | * Called at the end of a pass. | |
326 | */ | |
327 | void (*cleanup) (void); | |
328 | } Preproc; | |
329 | ||
330 | /* | |
331 | * ---------------------------------------------------------------- | |
332 | * Some lexical properties of the NASM source language, included | |
333 | * here because they are shared between the parser and preprocessor | |
334 | * ---------------------------------------------------------------- | |
335 | */ | |
336 | ||
337 | /* isidstart matches any character that may start an identifier, and isidchar | |
338 | * matches any character that may appear at places other than the start of an | |
339 | * identifier. E.g. a period may only appear at the start of an identifier | |
340 | * (for local labels), whereas a number may appear anywhere *but* at the | |
341 | * start. */ | |
342 | ||
343 | #define isidstart(c) ( isalpha(c) || (c)=='_' || (c)=='.' || (c)=='?' \ | |
344 | || (c)=='@' ) | |
345 | #define isidchar(c) ( isidstart(c) || isdigit(c) || (c)=='$' || (c)=='#' \ | |
346 | || (c)=='~' ) | |
347 | ||
348 | /* Ditto for numeric constants. */ | |
349 | ||
350 | #define isnumstart(c) ( isdigit(c) || (c)=='$' ) | |
351 | #define isnumchar(c) ( isalnum(c) ) | |
352 | ||
353 | /* This returns the numeric value of a given 'digit'. */ | |
354 | ||
355 | #define numvalue(c) ((c)>='a' ? (c)-'a'+10 : (c)>='A' ? (c)-'A'+10 : (c)-'0') | |
356 | ||
357 | /* | |
358 | * Data-type flags that get passed to listing-file routines. | |
359 | */ | |
360 | enum { | |
361 | LIST_READ, LIST_MACRO, LIST_MACRO_NOLIST, LIST_INCLUDE, | |
362 | LIST_INCBIN, LIST_TIMES | |
363 | }; | |
364 | ||
365 | /* | |
366 | * ----------------------------------------------------------- | |
367 | * Format of the `insn' structure returned from `parser.c' and | |
368 | * passed into `assemble.c' | |
369 | * ----------------------------------------------------------- | |
370 | */ | |
371 | ||
372 | /* | |
373 | * Here we define the operand types. These are implemented as bit | |
374 | * masks, since some are subsets of others; e.g. AX in a MOV | |
375 | * instruction is a special operand type, whereas AX in other | |
376 | * contexts is just another 16-bit register. (Also, consider CL in | |
377 | * shift instructions, DX in OUT, etc.) | |
378 | */ | |
379 | ||
380 | /* size, and other attributes, of the operand */ | |
381 | #define BITS8 0x00000001L | |
382 | #define BITS16 0x00000002L | |
383 | #define BITS32 0x00000004L | |
384 | #define BITS64 0x00000008L /* FPU only */ | |
385 | #define BITS80 0x00000010L /* FPU only */ | |
386 | #define FAR 0x00000020L /* grotty: this means 16:16 or */ | |
387 | /* 16:32, like in CALL/JMP */ | |
388 | #define NEAR 0x00000040L | |
389 | #define SHORT 0x00000080L /* and this means what it says :) */ | |
390 | ||
391 | #define SIZE_MASK 0x000000FFL /* all the size attributes */ | |
392 | #define NON_SIZE (~SIZE_MASK) | |
393 | ||
394 | #define TO 0x00000100L /* reverse effect in FADD, FSUB &c */ | |
395 | #define COLON 0x00000200L /* operand is followed by a colon */ | |
396 | ||
397 | /* type of operand: memory reference, register, etc. */ | |
398 | #define MEMORY 0x00204000L | |
399 | #define REGISTER 0x00001000L /* register number in 'basereg' */ | |
400 | #define IMMEDIATE 0x00002000L | |
401 | ||
402 | #define REGMEM 0x00200000L /* for r/m, ie EA, operands */ | |
403 | #define REGNORM 0x00201000L /* 'normal' reg, qualifies as EA */ | |
404 | #define REG8 0x00201001L | |
405 | #define REG16 0x00201002L | |
406 | #define REG32 0x00201004L | |
407 | #define MMXREG 0x00201008L /* MMX registers */ | |
408 | #define FPUREG 0x01000000L /* floating point stack registers */ | |
409 | #define FPU0 0x01000800L /* FPU stack register zero */ | |
410 | ||
411 | /* special register operands: these may be treated differently */ | |
412 | #define REG_SMASK 0x00070000L /* a mask for the following */ | |
413 | #define REG_ACCUM 0x00211000L /* accumulator: AL, AX or EAX */ | |
414 | #define REG_AL 0x00211001L /* REG_ACCUM | BITSxx */ | |
415 | #define REG_AX 0x00211002L /* ditto */ | |
416 | #define REG_EAX 0x00211004L /* and again */ | |
417 | #define REG_COUNT 0x00221000L /* counter: CL, CX or ECX */ | |
418 | #define REG_CL 0x00221001L /* REG_COUNT | BITSxx */ | |
419 | #define REG_CX 0x00221002L /* ditto */ | |
420 | #define REG_ECX 0x00221004L /* another one */ | |
421 | #define REG_DX 0x00241002L | |
422 | #define REG_SREG 0x00081002L /* any segment register */ | |
423 | #define REG_CS 0x01081002L /* CS */ | |
424 | #define REG_DESS 0x02081002L /* DS, ES, SS (non-CS 86 registers) */ | |
425 | #define REG_FSGS 0x04081002L /* FS, GS (386 extended registers) */ | |
426 | #define REG_CDT 0x00101004L /* CRn, DRn and TRn */ | |
427 | #define REG_CREG 0x08101004L /* CRn */ | |
428 | #define REG_CR4 0x08101404L /* CR4 (Pentium only) */ | |
429 | #define REG_DREG 0x10101004L /* DRn */ | |
430 | #define REG_TREG 0x20101004L /* TRn */ | |
431 | ||
432 | /* special type of EA */ | |
433 | #define MEM_OFFS 0x00604000L /* simple [address] offset */ | |
434 | ||
435 | /* special type of immediate operand */ | |
436 | #define ONENESS 0x00800000L /* so UNITY == IMMEDIATE | ONENESS */ | |
437 | #define UNITY 0x00802000L /* for shift/rotate instructions */ | |
438 | ||
439 | /* | |
440 | * Next, the codes returned from the parser, for registers and | |
441 | * instructions. | |
442 | */ | |
443 | ||
444 | enum { /* register names */ | |
445 | R_AH = EXPR_REG_START, R_AL, R_AX, R_BH, R_BL, R_BP, R_BX, R_CH, | |
446 | R_CL, R_CR0, R_CR2, R_CR3, R_CR4, R_CS, R_CX, R_DH, R_DI, R_DL, | |
447 | R_DR0, R_DR1, R_DR2, R_DR3, R_DR6, R_DR7, R_DS, R_DX, R_EAX, | |
448 | R_EBP, R_EBX, R_ECX, R_EDI, R_EDX, R_ES, R_ESI, R_ESP, R_FS, | |
449 | R_GS, R_MM0, R_MM1, R_MM2, R_MM3, R_MM4, R_MM5, R_MM6, R_MM7, | |
450 | R_SI, R_SP, R_SS, R_ST0, R_ST1, R_ST2, R_ST3, R_ST4, R_ST5, | |
451 | R_ST6, R_ST7, R_TR3, R_TR4, R_TR5, R_TR6, R_TR7, REG_ENUM_LIMIT | |
452 | }; | |
453 | ||
454 | enum { /* instruction names */ | |
455 | I_AAA, I_AAD, I_AAM, I_AAS, I_ADC, I_ADD, I_AND, I_ARPL, | |
456 | I_BOUND, I_BSF, I_BSR, I_BSWAP, I_BT, I_BTC, I_BTR, I_BTS, | |
457 | I_CALL, I_CBW, I_CDQ, I_CLC, I_CLD, I_CLI, I_CLTS, I_CMC, I_CMP, | |
458 | I_CMPSB, I_CMPSD, I_CMPSW, I_CMPXCHG, I_CMPXCHG486, I_CMPXCHG8B, | |
459 | I_CPUID, I_CWD, I_CWDE, I_DAA, I_DAS, I_DB, I_DD, I_DEC, I_DIV, | |
460 | I_DQ, I_DT, I_DW, I_EMMS, I_ENTER, I_EQU, I_F2XM1, I_FABS, | |
461 | I_FADD, I_FADDP, I_FBLD, I_FBSTP, I_FCHS, I_FCLEX, I_FCMOVB, | |
462 | I_FCMOVBE, I_FCMOVE, I_FCMOVNB, I_FCMOVNBE, I_FCMOVNE, | |
463 | I_FCMOVNU, I_FCMOVU, I_FCOM, I_FCOMI, I_FCOMIP, I_FCOMP, | |
464 | I_FCOMPP, I_FCOS, I_FDECSTP, I_FDISI, I_FDIV, I_FDIVP, I_FDIVR, | |
465 | I_FDIVRP, I_FENI, I_FFREE, I_FIADD, I_FICOM, I_FICOMP, I_FIDIV, | |
466 | I_FIDIVR, I_FILD, I_FIMUL, I_FINCSTP, I_FINIT, I_FIST, I_FISTP, | |
467 | I_FISUB, I_FISUBR, I_FLD, I_FLD1, I_FLDCW, I_FLDENV, I_FLDL2E, | |
468 | I_FLDL2T, I_FLDLG2, I_FLDLN2, I_FLDPI, I_FLDZ, I_FMUL, I_FMULP, | |
469 | I_FNCLEX, I_FNDISI, I_FNENI, I_FNINIT, I_FNOP, I_FNSAVE, | |
470 | I_FNSTCW, I_FNSTENV, I_FNSTSW, I_FPATAN, I_FPREM, I_FPREM1, | |
471 | I_FPTAN, I_FRNDINT, I_FRSTOR, I_FSAVE, I_FSCALE, I_FSETPM, | |
472 | I_FSIN, I_FSINCOS, I_FSQRT, I_FST, I_FSTCW, I_FSTENV, I_FSTP, | |
473 | I_FSTSW, I_FSUB, I_FSUBP, I_FSUBR, I_FSUBRP, I_FTST, I_FUCOM, | |
474 | I_FUCOMI, I_FUCOMIP, I_FUCOMP, I_FUCOMPP, I_FXAM, I_FXCH, | |
475 | I_FXTRACT, I_FYL2X, I_FYL2XP1, I_HLT, I_IBTS, I_ICEBP, I_IDIV, | |
476 | I_IMUL, I_IN, I_INC, I_INCBIN, I_INSB, I_INSD, I_INSW, I_INT, | |
477 | I_INT1, I_INT01, I_INT3, I_INTO, I_INVD, I_INVLPG, I_IRET, | |
478 | I_IRETD, I_IRETW, I_JCXZ, I_JECXZ, I_JMP, I_LAHF, I_LAR, I_LDS, | |
479 | I_LEA, I_LEAVE, I_LES, I_LFS, I_LGDT, I_LGS, I_LIDT, I_LLDT, | |
480 | I_LMSW, I_LOADALL, I_LOADALL286, I_LODSB, I_LODSD, I_LODSW, | |
481 | I_LOOP, I_LOOPE, I_LOOPNE, I_LOOPNZ, I_LOOPZ, I_LSL, I_LSS, | |
482 | I_LTR, I_MOV, I_MOVD, I_MOVQ, I_MOVSB, I_MOVSD, I_MOVSW, | |
483 | I_MOVSX, I_MOVZX, I_MUL, I_NEG, I_NOP, I_NOT, I_OR, I_OUT, | |
484 | I_OUTSB, I_OUTSD, I_OUTSW, I_PACKSSDW, I_PACKSSWB, I_PACKUSWB, | |
485 | I_PADDB, I_PADDD, I_PADDSB, I_PADDSIW, I_PADDSW, I_PADDUSB, | |
486 | I_PADDUSW, I_PADDW, I_PAND, I_PANDN, I_PAVEB, I_PCMPEQB, | |
487 | I_PCMPEQD, I_PCMPEQW, I_PCMPGTB, I_PCMPGTD, I_PCMPGTW, | |
488 | I_PDISTIB, I_PMACHRIW, I_PMADDWD, I_PMAGW, I_PMULHRW, | |
489 | I_PMULHRIW, I_PMULHW, I_PMULLW, I_PMVGEZB, I_PMVLZB, I_PMVNZB, | |
490 | I_PMVZB, I_POP, I_POPA, I_POPAD, I_POPAW, I_POPF, I_POPFD, | |
491 | I_POPFW, I_POR, I_PSLLD, I_PSLLQ, I_PSLLW, I_PSRAD, I_PSRAW, | |
492 | I_PSRLD, I_PSRLQ, I_PSRLW, I_PSUBB, I_PSUBD, I_PSUBSB, | |
493 | I_PSUBSIW, I_PSUBSW, I_PSUBUSB, I_PSUBUSW, I_PSUBW, I_PUNPCKHBW, | |
494 | I_PUNPCKHDQ, I_PUNPCKHWD, I_PUNPCKLBW, I_PUNPCKLDQ, I_PUNPCKLWD, | |
495 | I_PUSH, I_PUSHA, I_PUSHAD, I_PUSHAW, I_PUSHF, I_PUSHFD, | |
496 | I_PUSHFW, I_PXOR, I_RCL, I_RCR, I_RDMSR, I_RDPMC, I_RDTSC, | |
497 | I_RESB, I_RESD, I_RESQ, I_REST, I_RESW, I_RET, I_RETF, I_RETN, | |
498 | I_ROL, I_ROR, I_RSM, I_SAHF, I_SAL, I_SALC, I_SAR, I_SBB, | |
499 | I_SCASB, I_SCASD, I_SCASW, I_SGDT, I_SHL, I_SHLD, I_SHR, I_SHRD, | |
500 | I_SIDT, I_SLDT, I_SMI, I_SMSW, I_STC, I_STD, I_STI, I_STOSB, | |
501 | I_STOSD, I_STOSW, I_STR, I_SUB, I_TEST, I_UMOV, I_VERR, I_VERW, | |
502 | I_WAIT, I_WBINVD, I_WRMSR, I_XADD, I_XBTS, I_XCHG, I_XLATB, | |
503 | I_XOR, I_CMOVcc, I_Jcc, I_SETcc | |
504 | }; | |
505 | ||
506 | enum { /* condition code names */ | |
507 | C_A, C_AE, C_B, C_BE, C_C, C_E, C_G, C_GE, C_L, C_LE, C_NA, C_NAE, | |
508 | C_NB, C_NBE, C_NC, C_NE, C_NG, C_NGE, C_NL, C_NLE, C_NO, C_NP, | |
509 | C_NS, C_NZ, C_O, C_P, C_PE, C_PO, C_S, C_Z | |
510 | }; | |
511 | ||
512 | /* | |
513 | * Note that because segment registers may be used as instruction | |
514 | * prefixes, we must ensure the enumerations for prefixes and | |
515 | * register names do not overlap. | |
516 | */ | |
517 | enum { /* instruction prefixes */ | |
518 | PREFIX_ENUM_START = REG_ENUM_LIMIT, | |
519 | P_A16 = PREFIX_ENUM_START, P_A32, P_LOCK, P_O16, P_O32, P_REP, P_REPE, | |
520 | P_REPNE, P_REPNZ, P_REPZ, P_TIMES | |
521 | }; | |
522 | ||
523 | enum { /* extended operand types */ | |
524 | EOT_NOTHING, EOT_DB_STRING, EOT_DB_NUMBER | |
525 | }; | |
526 | ||
527 | enum { /* special EA flags */ | |
528 | EAF_BYTEOFFS = 1, /* force offset part to byte size */ | |
529 | EAF_WORDOFFS = 2, /* force offset part to [d]word size */ | |
530 | EAF_TIMESTWO = 4 /* really do EAX*2 not EAX+EAX */ | |
531 | }; | |
532 | ||
533 | enum { /* values for `hinttype' */ | |
534 | EAH_NOHINT = 0, /* no hint at all - our discretion */ | |
535 | EAH_MAKEBASE = 1, /* try to make given reg the base */ | |
536 | EAH_NOTBASE = 2 /* try _not_ to make reg the base */ | |
537 | }; | |
538 | ||
539 | typedef struct { /* operand to an instruction */ | |
540 | long type; /* type of operand */ | |
541 | int addr_size; /* 0 means default; 16; 32 */ | |
542 | int basereg, indexreg, scale; /* registers and scale involved */ | |
543 | int hintbase, hinttype; /* hint as to real base register */ | |
544 | long segment; /* immediate segment, if needed */ | |
545 | long offset; /* any immediate number */ | |
546 | long wrt; /* segment base it's relative to */ | |
547 | int eaflags; /* special EA flags */ | |
548 | } operand; | |
549 | ||
550 | typedef struct extop { /* extended operand */ | |
551 | struct extop *next; /* linked list */ | |
552 | long type; /* defined above */ | |
553 | char *stringval; /* if it's a string, then here it is */ | |
554 | int stringlen; /* ... and here's how long it is */ | |
555 | long segment; /* if it's a number/address, then... */ | |
556 | long offset; /* ... it's given here ... */ | |
557 | long wrt; /* ... and here */ | |
558 | } extop; | |
559 | ||
560 | #define MAXPREFIX 4 | |
561 | ||
562 | typedef struct { /* an instruction itself */ | |
563 | char *label; /* the label defined, or NULL */ | |
564 | int prefixes[MAXPREFIX]; /* instruction prefixes, if any */ | |
565 | int nprefix; /* number of entries in above */ | |
566 | int opcode; /* the opcode - not just the string */ | |
567 | int condition; /* the condition code, if Jcc/SETcc */ | |
568 | int operands; /* how many operands? 0-3 */ | |
569 | operand oprs[3]; /* the operands, defined as above */ | |
570 | extop *eops; /* extended operands */ | |
571 | long times; /* repeat count (TIMES prefix) */ | |
572 | int forw_ref; /* is there a forward reference? */ | |
573 | } insn; | |
574 | ||
575 | /* | |
576 | * ------------------------------------------------------------ | |
577 | * The data structure defining an output format driver, and the | |
578 | * interfaces to the functions therein. | |
579 | * ------------------------------------------------------------ | |
580 | */ | |
581 | ||
582 | struct ofmt { | |
583 | /* | |
584 | * This is a short (one-liner) description of the type of | |
585 | * output generated by the driver. | |
586 | */ | |
587 | char *fullname; | |
588 | ||
589 | /* | |
590 | * This is a single keyword used to select the driver. | |
591 | */ | |
592 | char *shortname; | |
593 | ||
594 | /* | |
595 | * This, if non-NULL, is a NULL-terminated list of `char *'s | |
596 | * pointing to extra standard macros supplied by the object | |
597 | * format (e.g. a sensible initial default value of __SECT__, | |
598 | * and user-level equivalents for any format-specific | |
599 | * directives). | |
600 | */ | |
601 | char **stdmac; | |
602 | ||
603 | /* | |
604 | * This procedure is called at the start of an output session. | |
605 | * It tells the output format what file it will be writing to, | |
606 | * what routine to report errors through, and how to interface | |
607 | * to the label manager and expression evaluator if necessary. | |
608 | * It also gives it a chance to do other initialisation. | |
609 | */ | |
610 | void (*init) (FILE *fp, efunc error, ldfunc ldef, evalfunc eval); | |
611 | ||
612 | /* | |
613 | * This procedure is called by assemble() to write actual | |
614 | * generated code or data to the object file. Typically it | |
615 | * doesn't have to actually _write_ it, just store it for | |
616 | * later. | |
617 | * | |
618 | * The `type' argument specifies the type of output data, and | |
619 | * usually the size as well: its contents are described below. | |
620 | */ | |
621 | void (*output) (long segto, void *data, unsigned long type, | |
622 | long segment, long wrt); | |
623 | ||
624 | /* | |
625 | * This procedure is called once for every symbol defined in | |
626 | * the module being assembled. It gives the name and value of | |
627 | * the symbol, in NASM's terms, and indicates whether it has | |
628 | * been declared to be global. Note that the parameter "name", | |
629 | * when passed, will point to a piece of static storage | |
630 | * allocated inside the label manager - it's safe to keep using | |
631 | * that pointer, because the label manager doesn't clean up | |
632 | * until after the output driver has. | |
633 | * | |
634 | * Values of `is_global' are: 0 means the symbol is local; 1 | |
635 | * means the symbol is global; 2 means the symbol is common (in | |
636 | * which case `offset' holds the _size_ of the variable). | |
637 | * Anything else is available for the output driver to use | |
638 | * internally. | |
639 | * | |
640 | * This routine explicitly _is_ allowed to call the label | |
641 | * manager to define further symbols, if it wants to, even | |
642 | * though it's been called _from_ the label manager. That much | |
643 | * re-entrancy is guaranteed in the label manager. However, the | |
644 | * label manager will in turn call this routine, so it should | |
645 | * be prepared to be re-entrant itself. | |
646 | * | |
647 | * The `special' parameter contains special information passed | |
648 | * through from the command that defined the label: it may have | |
649 | * been an EXTERN, a COMMON or a GLOBAL. The distinction should | |
650 | * be obvious to the output format from the other parameters. | |
651 | */ | |
652 | void (*symdef) (char *name, long segment, long offset, int is_global, | |
653 | char *special); | |
654 | ||
655 | /* | |
656 | * This procedure is called when the source code requests a | |
657 | * segment change. It should return the corresponding segment | |
658 | * _number_ for the name, or NO_SEG if the name is not a valid | |
659 | * segment name. | |
660 | * | |
661 | * It may also be called with NULL, in which case it is to | |
662 | * return the _default_ section number for starting assembly in. | |
663 | * | |
664 | * It is allowed to modify the string it is given a pointer to. | |
665 | * | |
666 | * It is also allowed to specify a default instruction size for | |
667 | * the segment, by setting `*bits' to 16 or 32. Or, if it | |
668 | * doesn't wish to define a default, it can leave `bits' alone. | |
669 | */ | |
670 | long (*section) (char *name, int pass, int *bits); | |
671 | ||
672 | /* | |
673 | * This procedure is called to modify the segment base values | |
674 | * returned from the SEG operator. It is given a segment base | |
675 | * value (i.e. a segment value with the low bit set), and is | |
676 | * required to produce in return a segment value which may be | |
677 | * different. It can map segment bases to absolute numbers by | |
678 | * means of returning SEG_ABS types. | |
679 | * | |
680 | * It should return NO_SEG if the segment base cannot be | |
681 | * determined; the evaluator (which calls this routine) is | |
682 | * responsible for throwing an error condition if that occurs | |
683 | * in pass two or in a critical expression. | |
684 | */ | |
685 | long (*segbase) (long segment); | |
686 | ||
687 | /* | |
688 | * This procedure is called to allow the output driver to | |
689 | * process its own specific directives. When called, it has the | |
690 | * directive word in `directive' and the parameter string in | |
691 | * `value'. It is called in both assembly passes, and `pass' | |
692 | * will be either 1 or 2. | |
693 | * | |
694 | * This procedure should return zero if it does not _recognise_ | |
695 | * the directive, so that the main program can report an error. | |
696 | * If it recognises the directive but then has its own errors, | |
697 | * it should report them itself and then return non-zero. It | |
698 | * should also return non-zero if it correctly processes the | |
699 | * directive. | |
700 | */ | |
701 | int (*directive) (char *directive, char *value, int pass); | |
702 | ||
703 | /* | |
704 | * This procedure is called before anything else - even before | |
705 | * the "init" routine - and is passed the name of the input | |
706 | * file from which this output file is being generated. It | |
707 | * should return its preferred name for the output file in | |
708 | * `outname', if outname[0] is not '\0', and do nothing to | |
709 | * `outname' otherwise. Since it is called before the driver is | |
710 | * properly initialised, it has to be passed its error handler | |
711 | * separately. | |
712 | * | |
713 | * This procedure may also take its own copy of the input file | |
714 | * name for use in writing the output file: it is _guaranteed_ | |
715 | * that it will be called before the "init" routine. | |
716 | * | |
717 | * The parameter `outname' points to an area of storage | |
718 | * guaranteed to be at least FILENAME_MAX in size. | |
719 | */ | |
720 | void (*filename) (char *inname, char *outname, efunc error); | |
721 | ||
722 | /* | |
723 | * This procedure is called after assembly finishes, to allow | |
724 | * the output driver to clean itself up and free its memory. | |
725 | * Typically, it will also be the point at which the object | |
726 | * file actually gets _written_. | |
727 | * | |
728 | * One thing the cleanup routine should always do is to close | |
729 | * the output file pointer. | |
730 | */ | |
731 | void (*cleanup) (void); | |
732 | }; | |
733 | ||
734 | /* | |
735 | * values for the `type' parameter to an output function. Each one | |
736 | * must have the actual number of _bytes_ added to it. | |
737 | * | |
738 | * Exceptions are OUT_RELxADR, which denote an x-byte relocation | |
739 | * which will be a relative jump. For this we need to know the | |
740 | * distance in bytes from the start of the relocated record until | |
741 | * the end of the containing instruction. _This_ is what is stored | |
742 | * in the size part of the parameter, in this case. | |
743 | * | |
744 | * Also OUT_RESERVE denotes reservation of N bytes of BSS space, | |
745 | * and the contents of the "data" parameter is irrelevant. | |
746 | * | |
747 | * The "data" parameter for the output function points to a "long", | |
748 | * containing the address in question, unless the type is | |
749 | * OUT_RAWDATA, in which case it points to an "unsigned char" | |
750 | * array. | |
751 | */ | |
752 | #define OUT_RAWDATA 0x00000000UL | |
753 | #define OUT_ADDRESS 0x10000000UL | |
754 | #define OUT_REL2ADR 0x20000000UL | |
755 | #define OUT_REL4ADR 0x30000000UL | |
756 | #define OUT_RESERVE 0x40000000UL | |
757 | #define OUT_TYPMASK 0xF0000000UL | |
758 | #define OUT_SIZMASK 0x0FFFFFFFUL | |
759 | ||
760 | /* | |
761 | * ----- | |
762 | * Other | |
763 | * ----- | |
764 | */ | |
765 | ||
766 | /* | |
767 | * This is a useful #define which I keep meaning to use more often: | |
768 | * the number of elements of a statically defined array. | |
769 | */ | |
770 | ||
771 | #define elements(x) ( sizeof(x) / sizeof(*(x)) ) | |
772 | ||
773 | #endif |