nasm.h 42 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283
  1. /* ----------------------------------------------------------------------- *
  2. *
  3. * Copyright 1996-2018 The NASM Authors - All Rights Reserved
  4. * See the file AUTHORS included with the NASM distribution for
  5. * the specific copyright holders.
  6. *
  7. * Redistribution and use in source and binary forms, with or without
  8. * modification, are permitted provided that the following
  9. * conditions are met:
  10. *
  11. * * Redistributions of source code must retain the above copyright
  12. * notice, this list of conditions and the following disclaimer.
  13. * * Redistributions in binary form must reproduce the above
  14. * copyright notice, this list of conditions and the following
  15. * disclaimer in the documentation and/or other materials provided
  16. * with the distribution.
  17. *
  18. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
  19. * CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
  20. * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
  21. * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  22. * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
  23. * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  24. * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
  25. * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
  26. * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
  27. * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
  28. * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
  29. * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
  30. * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  31. *
  32. * ----------------------------------------------------------------------- */
  33. /*
  34. * nasm.h main header file for the Netwide Assembler: inter-module interface
  35. */
  36. #ifndef NASM_NASM_H
  37. #define NASM_NASM_H
  38. #include "compiler.h"
  39. #include <stdio.h>
  40. #include <time.h>
  41. #include "nasmlib.h"
  42. #include "strlist.h"
  43. #include "preproc.h"
  44. #include "insnsi.h" /* For enum opcode */
  45. #include "directiv.h" /* For enum directive */
  46. #include "labels.h" /* For enum mangle_index, enum label_type */
  47. #include "opflags.h"
  48. #include "regs.h"
  49. /* Time stamp for the official start of compilation */
  50. struct compile_time {
  51. time_t t;
  52. bool have_local, have_gm, have_posix;
  53. int64_t posix;
  54. struct tm local;
  55. struct tm gm;
  56. };
  57. extern struct compile_time official_compile_time;
  58. #define NO_SEG INT32_C(-1) /* null segment value */
  59. #define SEG_ABS 0x40000000L /* mask for far-absolute segments */
  60. #define IDLEN_MAX 4096
  61. #define DECOLEN_MAX 32
  62. /*
  63. * Name pollution problems: <time.h> on Digital UNIX pulls in some
  64. * strange hardware header file which sees fit to define R_SP. We
  65. * undefine it here so as not to break the enum below.
  66. */
  67. #ifdef R_SP
  68. #undef R_SP
  69. #endif
  70. /*
  71. * We must declare the existence of this structure type up here,
  72. * since we have to reference it before we define it...
  73. */
  74. struct ofmt;
  75. /*
  76. * Values for the `type' parameter to an output function.
  77. */
  78. enum out_type {
  79. OUT_RAWDATA, /* Plain bytes */
  80. OUT_RESERVE, /* Reserved bytes (RESB et al) */
  81. OUT_ZERODATA, /* Initialized data, but all zero */
  82. OUT_ADDRESS, /* An address (symbol value) */
  83. OUT_RELADDR, /* A relative address */
  84. OUT_SEGMENT, /* A segment number */
  85. /*
  86. * These values are used by the legacy backend interface only;
  87. * see output/legacy.c for more information. These should never
  88. * be used otherwise. Once all backends have been migrated to the
  89. * new interface they should be removed.
  90. */
  91. OUT_REL1ADR,
  92. OUT_REL2ADR,
  93. OUT_REL4ADR,
  94. OUT_REL8ADR
  95. };
  96. enum out_sign {
  97. OUT_WRAP, /* Undefined signedness (wraps) */
  98. OUT_SIGNED, /* Value is signed */
  99. OUT_UNSIGNED /* Value is unsigned */
  100. };
  101. /*
  102. * The data we send down to the backend.
  103. * XXX: We still want to push down the base address symbol if
  104. * available, and replace the segment numbers with a structure.
  105. */
  106. struct out_data {
  107. int64_t offset; /* Offset within segment */
  108. int32_t segment; /* Segment written to */
  109. enum out_type type; /* See above */
  110. enum out_sign sign; /* See above */
  111. int inslen; /* Length of instruction */
  112. int insoffs; /* Offset inside instruction */
  113. int bits; /* Bits mode of compilation */
  114. uint64_t size; /* Size of output */
  115. const struct itemplate *itemp; /* Instruction template */
  116. const void *data; /* Data for OUT_RAWDATA */
  117. uint64_t toffset; /* Target address offset for relocation */
  118. int32_t tsegment; /* Target segment for relocation */
  119. int32_t twrt; /* Relocation with respect to */
  120. int64_t relbase; /* Relative base for OUT_RELADDR */
  121. };
  122. /*
  123. * And a label-definition function. The boolean parameter
  124. * `is_norm' states whether the label is a `normal' label (which
  125. * should affect the local-label system), or something odder like
  126. * an EQU or a segment-base symbol, which shouldn't.
  127. */
  128. typedef void (*ldfunc)(char *label, int32_t segment, int64_t offset,
  129. char *special, bool is_norm);
  130. /*
  131. * Token types returned by the scanner, in addition to ordinary
  132. * ASCII character values, and zero for end-of-string.
  133. */
  134. enum token_type { /* token types, other than chars */
  135. TOKEN_INVALID = -1, /* a placeholder value */
  136. TOKEN_EOS = 0, /* end of string */
  137. TOKEN_EQ = '=',
  138. TOKEN_GT = '>',
  139. TOKEN_LT = '<', /* aliases */
  140. TOKEN_ID = 256, /* identifier */
  141. TOKEN_NUM, /* numeric constant */
  142. TOKEN_ERRNUM, /* malformed numeric constant */
  143. TOKEN_STR, /* string constant */
  144. TOKEN_ERRSTR, /* unterminated string constant */
  145. TOKEN_FLOAT, /* floating-point constant */
  146. TOKEN_REG, /* register name */
  147. TOKEN_INSN, /* instruction name */
  148. TOKEN_HERE, /* $ */
  149. TOKEN_BASE, /* $$ */
  150. TOKEN_SPECIAL, /* BYTE, WORD, DWORD, QWORD, FAR, NEAR, etc */
  151. TOKEN_PREFIX, /* A32, O16, LOCK, REPNZ, TIMES, etc */
  152. TOKEN_SHL, /* << or <<< */
  153. TOKEN_SHR, /* >> */
  154. TOKEN_SAR, /* >>> */
  155. TOKEN_SDIV, /* // */
  156. TOKEN_SMOD, /* %% */
  157. TOKEN_GE, /* >= */
  158. TOKEN_LE, /* <= */
  159. TOKEN_NE, /* <> (!= is same as <>) */
  160. TOKEN_DBL_AND, /* && */
  161. TOKEN_DBL_OR, /* || */
  162. TOKEN_DBL_XOR, /* ^^ */
  163. TOKEN_SEG, /* SEG */
  164. TOKEN_WRT, /* WRT */
  165. TOKEN_FLOATIZE, /* __floatX__ */
  166. TOKEN_STRFUNC, /* __utf16*__, __utf32*__ */
  167. TOKEN_IFUNC, /* __ilog2*__ */
  168. TOKEN_DECORATOR, /* decorators such as {...} */
  169. TOKEN_OPMASK /* translated token for opmask registers */
  170. };
  171. enum floatize {
  172. FLOAT_8,
  173. FLOAT_16,
  174. FLOAT_32,
  175. FLOAT_64,
  176. FLOAT_80M,
  177. FLOAT_80E,
  178. FLOAT_128L,
  179. FLOAT_128H
  180. };
  181. /* Must match the list in string_transform(), in strfunc.c */
  182. enum strfunc {
  183. STRFUNC_UTF16,
  184. STRFUNC_UTF16LE,
  185. STRFUNC_UTF16BE,
  186. STRFUNC_UTF32,
  187. STRFUNC_UTF32LE,
  188. STRFUNC_UTF32BE
  189. };
  190. enum ifunc {
  191. IFUNC_ILOG2E,
  192. IFUNC_ILOG2W,
  193. IFUNC_ILOG2F,
  194. IFUNC_ILOG2C
  195. };
  196. size_t string_transform(char *, size_t, char **, enum strfunc);
  197. /*
  198. * The expression evaluator must be passed a scanner function; a
  199. * standard scanner is provided as part of nasmlib.c. The
  200. * preprocessor will use a different one. Scanners, and the
  201. * token-value structures they return, look like this.
  202. *
  203. * The return value from the scanner is always a copy of the
  204. * `t_type' field in the structure.
  205. */
  206. struct tokenval {
  207. char *t_charptr;
  208. int64_t t_integer;
  209. int64_t t_inttwo;
  210. enum token_type t_type;
  211. int8_t t_flag;
  212. };
  213. typedef int (*scanner)(void *private_data, struct tokenval *tv);
  214. struct location {
  215. int64_t offset;
  216. int32_t segment;
  217. int known;
  218. };
  219. extern struct location location;
  220. /*
  221. * Expression-evaluator datatype. Expressions, within the
  222. * evaluator, are stored as an array of these beasts, terminated by
  223. * a record with type==0. Mostly, it's a vector type: each type
  224. * denotes some kind of a component, and the value denotes the
  225. * multiple of that component present in the expression. The
  226. * exception is the WRT type, whose `value' field denotes the
  227. * segment to which the expression is relative. These segments will
  228. * be segment-base types, i.e. either odd segment values or SEG_ABS
  229. * types. So it is still valid to assume that anything with a
  230. * `value' field of zero is insignificant.
  231. */
  232. typedef struct {
  233. int32_t type; /* a register, or EXPR_xxx */
  234. int64_t value; /* must be >= 32 bits */
  235. } expr;
  236. /*
  237. * Library routines to manipulate expression data types.
  238. */
  239. bool is_reloc(const expr *vect);
  240. bool is_simple(const expr *vect);
  241. bool is_really_simple(const expr *vect);
  242. bool is_unknown(const expr *vect);
  243. bool is_just_unknown(const expr *vect);
  244. int64_t reloc_value(const expr *vect);
  245. int32_t reloc_seg(const expr *vect);
  246. int32_t reloc_wrt(const expr *vect);
  247. bool is_self_relative(const expr *vect);
  248. void dump_expr(const expr *vect);
  249. /*
  250. * The evaluator can also return hints about which of two registers
  251. * used in an expression should be the base register. See also the
  252. * `operand' structure.
  253. */
  254. struct eval_hints {
  255. int64_t base;
  256. int type;
  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 8 set (in addition to its main value: 0x101
  274. * and 0x102 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. #define CRITICAL 0x100
  283. typedef expr *(*evalfunc)(scanner sc, void *scprivate,
  284. struct tokenval *tv, int *fwref, int critical,
  285. struct eval_hints *hints);
  286. /*
  287. * Special values for expr->type.
  288. * These come after EXPR_REG_END as defined in regs.h.
  289. * Expr types : 0 ~ EXPR_REG_END, EXPR_UNKNOWN, EXPR_...., EXPR_RDSAE,
  290. * EXPR_SEGBASE ~ EXPR_SEGBASE + SEG_ABS, ...
  291. */
  292. #define EXPR_UNKNOWN (EXPR_REG_END+1) /* forward references */
  293. #define EXPR_SIMPLE (EXPR_REG_END+2)
  294. #define EXPR_WRT (EXPR_REG_END+3)
  295. #define EXPR_RDSAE (EXPR_REG_END+4)
  296. #define EXPR_SEGBASE (EXPR_REG_END+5)
  297. /*
  298. * preprocessors ought to look like this:
  299. */
  300. struct preproc_ops {
  301. /*
  302. * Called once at the very start of assembly.
  303. */
  304. void (*init)(void);
  305. /*
  306. * Called at the start of a pass; given a file name, the number
  307. * of the pass, an error reporting function, an evaluator
  308. * function, and a listing generator to talk to.
  309. */
  310. void (*reset)(const char *file, int pass, StrList *deplist);
  311. /*
  312. * Called to fetch a line of preprocessed source. The line
  313. * returned has been malloc'ed, and so should be freed after
  314. * use.
  315. */
  316. char *(*getline)(void);
  317. /* Called at the end of a pass */
  318. void (*cleanup)(int pass);
  319. /* Additional macros specific to output format */
  320. void (*extra_stdmac)(macros_t *macros);
  321. /* Early definitions and undefinitions for macros */
  322. void (*pre_define)(char *definition);
  323. void (*pre_undefine)(char *definition);
  324. /* Include file from command line */
  325. void (*pre_include)(char *fname);
  326. /* Add a command from the command line */
  327. void (*pre_command)(const char *what, char *str);
  328. /* Include path from command line */
  329. void (*include_path)(const char *path);
  330. /* Unwind the macro stack when printing an error message */
  331. void (*error_list_macros)(int severity);
  332. };
  333. extern const struct preproc_ops nasmpp;
  334. extern const struct preproc_ops preproc_nop;
  335. /* List of dependency files */
  336. extern StrList *depend_list;
  337. /*
  338. * Some lexical properties of the NASM source language, included
  339. * here because they are shared between the parser and preprocessor.
  340. */
  341. /*
  342. * isidstart matches any character that may start an identifier, and isidchar
  343. * matches any character that may appear at places other than the start of an
  344. * identifier. E.g. a period may only appear at the start of an identifier
  345. * (for local labels), whereas a number may appear anywhere *but* at the
  346. * start.
  347. * isbrcchar matches any character that may placed inside curly braces as a
  348. * decorator. E.g. {rn-sae}, {1to8}, {k1}{z}
  349. */
  350. #define isidstart(c) (nasm_isalpha(c) || \
  351. (c) == '_' || \
  352. (c) == '.' || \
  353. (c) == '?' || \
  354. (c) == '@')
  355. #define isidchar(c) (isidstart(c) || \
  356. nasm_isdigit(c) || \
  357. (c) == '$' || \
  358. (c) == '#' || \
  359. (c) == '~')
  360. #define isbrcchar(c) (isidchar(c) || \
  361. (c) == '-')
  362. /* Ditto for numeric constants. */
  363. #define isnumstart(c) (nasm_isdigit(c) || (c) == '$')
  364. #define isnumchar(c) (nasm_isalnum(c) || (c) == '_')
  365. /*
  366. * inline function to skip past an identifier; returns the first character past
  367. * the identifier if valid, otherwise NULL.
  368. */
  369. static inline char *nasm_skip_identifier(const char *str)
  370. {
  371. const char *p = str;
  372. if (!isidstart(*p++)) {
  373. p = NULL;
  374. } else {
  375. while (isidchar(*p++))
  376. ;
  377. }
  378. return (char *)p;
  379. }
  380. /*
  381. * Data-type flags that get passed to listing-file routines.
  382. */
  383. enum {
  384. LIST_READ,
  385. LIST_MACRO,
  386. LIST_MACRO_NOLIST,
  387. LIST_INCLUDE,
  388. LIST_INCBIN,
  389. LIST_TIMES
  390. };
  391. /*
  392. * -----------------------------------------------------------
  393. * Format of the `insn' structure returned from `parser.c' and
  394. * passed into `assemble.c'
  395. * -----------------------------------------------------------
  396. */
  397. /* Verify value to be a valid register */
  398. static inline bool is_register(int reg)
  399. {
  400. return reg >= EXPR_REG_START && reg < REG_ENUM_LIMIT;
  401. }
  402. enum ccode { /* condition code names */
  403. C_A, C_AE, C_B, C_BE, C_C, C_E, C_G, C_GE, C_L, C_LE, C_NA, C_NAE,
  404. C_NB, C_NBE, C_NC, C_NE, C_NG, C_NGE, C_NL, C_NLE, C_NO, C_NP,
  405. C_NS, C_NZ, C_O, C_P, C_PE, C_PO, C_S, C_Z,
  406. C_none = -1
  407. };
  408. /*
  409. * token flags
  410. */
  411. #define TFLAG_BRC (1 << 0) /* valid only with braces. {1to8}, {rd-sae}, ...*/
  412. #define TFLAG_BRC_OPT (1 << 1) /* may or may not have braces. opmasks {k1} */
  413. #define TFLAG_BRC_ANY (TFLAG_BRC | TFLAG_BRC_OPT)
  414. #define TFLAG_BRDCAST (1 << 2) /* broadcasting decorator */
  415. #define TFLAG_WARN (1 << 3) /* warning only, treat as ID */
  416. static inline uint8_t get_cond_opcode(enum ccode c)
  417. {
  418. static const uint8_t ccode_opcodes[] = {
  419. 0x7, 0x3, 0x2, 0x6, 0x2, 0x4, 0xf, 0xd, 0xc, 0xe, 0x6, 0x2,
  420. 0x3, 0x7, 0x3, 0x5, 0xe, 0xc, 0xd, 0xf, 0x1, 0xb, 0x9, 0x5,
  421. 0x0, 0xa, 0xa, 0xb, 0x8, 0x4
  422. };
  423. return ccode_opcodes[(int)c];
  424. }
  425. /*
  426. * REX flags
  427. */
  428. #define REX_MASK 0x4f /* Actual REX prefix bits */
  429. #define REX_B 0x01 /* ModRM r/m extension */
  430. #define REX_X 0x02 /* SIB index extension */
  431. #define REX_R 0x04 /* ModRM reg extension */
  432. #define REX_W 0x08 /* 64-bit operand size */
  433. #define REX_L 0x20 /* Use LOCK prefix instead of REX.R */
  434. #define REX_P 0x40 /* REX prefix present/required */
  435. #define REX_H 0x80 /* High register present, REX forbidden */
  436. #define REX_V 0x0100 /* Instruction uses VEX/XOP instead of REX */
  437. #define REX_NH 0x0200 /* Instruction which doesn't use high regs */
  438. #define REX_EV 0x0400 /* Instruction uses EVEX instead of REX */
  439. /*
  440. * EVEX bit field
  441. */
  442. #define EVEX_P0MM 0x0f /* EVEX P[3:0] : Opcode map */
  443. #define EVEX_P0RP 0x10 /* EVEX P[4] : High-16 reg */
  444. #define EVEX_P0X 0x40 /* EVEX P[6] : High-16 rm */
  445. #define EVEX_P1PP 0x03 /* EVEX P[9:8] : Legacy prefix */
  446. #define EVEX_P1VVVV 0x78 /* EVEX P[14:11] : NDS register */
  447. #define EVEX_P1W 0x80 /* EVEX P[15] : Osize extension */
  448. #define EVEX_P2AAA 0x07 /* EVEX P[18:16] : Embedded opmask */
  449. #define EVEX_P2VP 0x08 /* EVEX P[19] : High-16 NDS reg */
  450. #define EVEX_P2B 0x10 /* EVEX P[20] : Broadcast / RC / SAE */
  451. #define EVEX_P2LL 0x60 /* EVEX P[22:21] : Vector length */
  452. #define EVEX_P2RC EVEX_P2LL /* EVEX P[22:21] : Rounding control */
  453. #define EVEX_P2Z 0x80 /* EVEX P[23] : Zeroing/Merging */
  454. /*
  455. * REX_V "classes" (prefixes which behave like VEX)
  456. */
  457. enum vex_class {
  458. RV_VEX = 0, /* C4/C5 */
  459. RV_XOP = 1, /* 8F */
  460. RV_EVEX = 2 /* 62 */
  461. };
  462. /*
  463. * Note that because segment registers may be used as instruction
  464. * prefixes, we must ensure the enumerations for prefixes and
  465. * register names do not overlap.
  466. */
  467. enum prefixes { /* instruction prefixes */
  468. P_none = 0,
  469. PREFIX_ENUM_START = REG_ENUM_LIMIT,
  470. P_A16 = PREFIX_ENUM_START,
  471. P_A32,
  472. P_A64,
  473. P_ASP,
  474. P_LOCK,
  475. P_O16,
  476. P_O32,
  477. P_O64,
  478. P_OSP,
  479. P_REP,
  480. P_REPE,
  481. P_REPNE,
  482. P_REPNZ,
  483. P_REPZ,
  484. P_TIMES,
  485. P_WAIT,
  486. P_XACQUIRE,
  487. P_XRELEASE,
  488. P_BND,
  489. P_NOBND,
  490. P_EVEX,
  491. P_VEX3,
  492. P_VEX2,
  493. PREFIX_ENUM_LIMIT
  494. };
  495. enum extop_type { /* extended operand types */
  496. EOT_NOTHING,
  497. EOT_DB_STRING, /* Byte string */
  498. EOT_DB_STRING_FREE, /* Byte string which should be nasm_free'd*/
  499. EOT_DB_NUMBER /* Integer */
  500. };
  501. enum ea_flags { /* special EA flags */
  502. EAF_BYTEOFFS = 1, /* force offset part to byte size */
  503. EAF_WORDOFFS = 2, /* force offset part to [d]word size */
  504. EAF_TIMESTWO = 4, /* really do EAX*2 not EAX+EAX */
  505. EAF_REL = 8, /* IP-relative addressing */
  506. EAF_ABS = 16, /* non-IP-relative addressing */
  507. EAF_FSGS = 32, /* fs/gs segment override present */
  508. EAF_MIB = 64 /* mib operand */
  509. };
  510. enum eval_hint { /* values for `hinttype' */
  511. EAH_NOHINT = 0, /* no hint at all - our discretion */
  512. EAH_MAKEBASE = 1, /* try to make given reg the base */
  513. EAH_NOTBASE = 2, /* try _not_ to make reg the base */
  514. EAH_SUMMED = 3 /* base and index are summed into index */
  515. };
  516. typedef struct operand { /* operand to an instruction */
  517. opflags_t type; /* type of operand */
  518. int disp_size; /* 0 means default; 16; 32; 64 */
  519. enum reg_enum basereg;
  520. enum reg_enum indexreg; /* address registers */
  521. int scale; /* index scale */
  522. int hintbase;
  523. enum eval_hint hinttype; /* hint as to real base register */
  524. int32_t segment; /* immediate segment, if needed */
  525. int64_t offset; /* any immediate number */
  526. int32_t wrt; /* segment base it's relative to */
  527. int eaflags; /* special EA flags */
  528. int opflags; /* see OPFLAG_* defines below */
  529. decoflags_t decoflags; /* decorator flags such as {...} */
  530. } operand;
  531. #define OPFLAG_FORWARD 1 /* operand is a forward reference */
  532. #define OPFLAG_EXTERN 2 /* operand is an external reference */
  533. #define OPFLAG_UNKNOWN 4 /* operand is an unknown reference
  534. (always a forward reference also) */
  535. #define OPFLAG_RELATIVE 8 /* operand is self-relative, e.g. [foo - $]
  536. where foo is not in the current segment */
  537. typedef struct extop { /* extended operand */
  538. struct extop *next; /* linked list */
  539. char *stringval; /* if it's a string, then here it is */
  540. size_t stringlen; /* ... and here's how long it is */
  541. int64_t offset; /* ... it's given here ... */
  542. int32_t segment; /* if it's a number/address, then... */
  543. int32_t wrt; /* ... and here */
  544. bool relative; /* self-relative expression */
  545. enum extop_type type; /* defined above */
  546. } extop;
  547. enum ea_type {
  548. EA_INVALID, /* Not a valid EA at all */
  549. EA_SCALAR, /* Scalar EA */
  550. EA_XMMVSIB, /* XMM vector EA */
  551. EA_YMMVSIB, /* YMM vector EA */
  552. EA_ZMMVSIB /* ZMM vector EA */
  553. };
  554. /*
  555. * Prefix positions: each type of prefix goes in a specific slot.
  556. * This affects the final ordering of the assembled output, which
  557. * shouldn't matter to the processor, but if you have stylistic
  558. * preferences, you can change this. REX prefixes are handled
  559. * differently for the time being.
  560. *
  561. * LOCK and REP used to be one slot; this is no longer the case since
  562. * the introduction of HLE.
  563. */
  564. enum prefix_pos {
  565. PPS_WAIT, /* WAIT (technically not a prefix!) */
  566. PPS_REP, /* REP/HLE prefix */
  567. PPS_LOCK, /* LOCK prefix */
  568. PPS_SEG, /* Segment override prefix */
  569. PPS_OSIZE, /* Operand size prefix */
  570. PPS_ASIZE, /* Address size prefix */
  571. PPS_VEX, /* VEX type */
  572. MAXPREFIX /* Total number of prefix slots */
  573. };
  574. /*
  575. * Tuple types that are used when determining Disp8*N eligibility
  576. * The order must match with a hash %tuple_codes in insns.pl
  577. */
  578. enum ttypes {
  579. FV = 001,
  580. HV = 002,
  581. FVM = 003,
  582. T1S8 = 004,
  583. T1S16 = 005,
  584. T1S = 006,
  585. T1F32 = 007,
  586. T1F64 = 010,
  587. T2 = 011,
  588. T4 = 012,
  589. T8 = 013,
  590. HVM = 014,
  591. QVM = 015,
  592. OVM = 016,
  593. M128 = 017,
  594. DUP = 020
  595. };
  596. /* EVEX.L'L : Vector length on vector insns */
  597. enum vectlens {
  598. VL128 = 0,
  599. VL256 = 1,
  600. VL512 = 2,
  601. VLMAX = 3
  602. };
  603. /* If you need to change this, also change it in insns.pl */
  604. #define MAX_OPERANDS 5
  605. typedef struct insn { /* an instruction itself */
  606. char *label; /* the label defined, or NULL */
  607. int prefixes[MAXPREFIX]; /* instruction prefixes, if any */
  608. enum opcode opcode; /* the opcode - not just the string */
  609. enum ccode condition; /* the condition code, if Jcc/SETcc */
  610. int operands; /* how many operands? 0-3 (more if db et al) */
  611. int addr_size; /* address size */
  612. operand oprs[MAX_OPERANDS]; /* the operands, defined as above */
  613. extop *eops; /* extended operands */
  614. int eops_float; /* true if DD and floating */
  615. int32_t times; /* repeat count (TIMES prefix) */
  616. bool forw_ref; /* is there a forward reference? */
  617. bool rex_done; /* REX prefix emitted? */
  618. int rex; /* Special REX Prefix */
  619. int vexreg; /* Register encoded in VEX prefix */
  620. int vex_cm; /* Class and M field for VEX prefix */
  621. int vex_wlp; /* W, P and L information for VEX prefix */
  622. uint8_t evex_p[3]; /* EVEX.P0: [RXB,R',00,mm], P1: [W,vvvv,1,pp] */
  623. /* EVEX.P2: [z,L'L,b,V',aaa] */
  624. enum ttypes evex_tuple; /* Tuple type for compressed Disp8*N */
  625. int evex_rm; /* static rounding mode for AVX512 (EVEX) */
  626. int8_t evex_brerop; /* BR/ER/SAE operand position */
  627. } insn;
  628. /* Instruction flags type: IF_* flags are defined in insns.h */
  629. typedef uint64_t iflags_t;
  630. /*
  631. * What to return from a directive- or pragma-handling function.
  632. * Currently DIRR_OK and DIRR_ERROR are treated the same way;
  633. * in both cases the backend is expected to produce the appropriate
  634. * error message on its own.
  635. *
  636. * DIRR_BADPARAM causes a generic error message to be printed. Note
  637. * that it is an error, not a warning, even in the case of pragmas;
  638. * don't use it where forward compatiblity would be compromised
  639. * (instead consider adding a DIRR_WARNPARAM.)
  640. */
  641. enum directive_result {
  642. DIRR_UNKNOWN, /* Directive not handled by backend */
  643. DIRR_OK, /* Directive processed */
  644. DIRR_ERROR, /* Directive processed unsuccessfully */
  645. DIRR_BADPARAM /* Print bad argument error message */
  646. };
  647. /*
  648. * A pragma facility: this structure is used to request passing a
  649. * parsed pragma directive for a specific facility. If the handler is
  650. * NULL then this pragma facility is recognized but ignored; pragma
  651. * processing stops at that point.
  652. *
  653. * Note that the handler is passed a pointer to the facility structure
  654. * as part of the struct pragma.
  655. */
  656. struct pragma;
  657. typedef enum directive_result (*pragma_handler)(const struct pragma *);
  658. struct pragma_facility {
  659. const char *name;
  660. pragma_handler handler;
  661. };
  662. /*
  663. * This structure defines how a pragma directive is passed to a
  664. * facility. This structure may be augmented in the future.
  665. *
  666. * Any facility MAY, but is not required to, add its operations
  667. * keywords or a subset thereof into asm/directiv.dat, in which case
  668. * the "opcode" field will be set to the corresponding D_ constant
  669. * from directiv.h; otherwise it will be D_unknown.
  670. */
  671. struct pragma {
  672. const struct pragma_facility *facility;
  673. const char *facility_name; /* Facility name exactly as entered by user */
  674. const char *opname; /* First word after the facility name */
  675. const char *tail; /* Anything after the operation */
  676. enum directive opcode; /* Operation as a D_ directives constant */
  677. };
  678. /*
  679. * These are semi-arbitrary limits to keep the assembler from going
  680. * into a black hole on certain kinds of bugs. They can be overridden
  681. * by command-line options or %pragma.
  682. */
  683. enum nasm_limit {
  684. LIMIT_PASSES,
  685. LIMIT_STALLED,
  686. LIMIT_MACROS,
  687. LIMIT_REP,
  688. LIMIT_EVAL,
  689. LIMIT_LINES
  690. };
  691. #define LIMIT_MAX LIMIT_LINES
  692. extern int64_t nasm_limit[LIMIT_MAX+1];
  693. extern enum directive_result nasm_set_limit(const char *, const char *);
  694. /*
  695. * The data structure defining an output format driver, and the
  696. * interfaces to the functions therein.
  697. */
  698. struct ofmt {
  699. /*
  700. * This is a short (one-liner) description of the type of
  701. * output generated by the driver.
  702. */
  703. const char *fullname;
  704. /*
  705. * This is a single keyword used to select the driver.
  706. */
  707. const char *shortname;
  708. /*
  709. * Default output filename extension, or a null string
  710. */
  711. const char *extension;
  712. /*
  713. * Output format flags.
  714. */
  715. #define OFMT_TEXT 1 /* Text file format */
  716. #define OFMT_KEEP_ADDR 2 /* Keep addr; no conversion to data */
  717. unsigned int flags;
  718. int maxbits; /* Maximum segment bits supported */
  719. /*
  720. * this is a pointer to the first element of the debug information
  721. */
  722. const struct dfmt * const *debug_formats;
  723. /*
  724. * the default debugging format if -F is not specified
  725. */
  726. const struct dfmt *default_dfmt;
  727. /*
  728. * This, if non-NULL, is a NULL-terminated list of `char *'s
  729. * pointing to extra standard macros supplied by the object
  730. * format (e.g. a sensible initial default value of __SECT__,
  731. * and user-level equivalents for any format-specific
  732. * directives).
  733. */
  734. macros_t *stdmac;
  735. /*
  736. * This procedure is called at the start of an output session to set
  737. * up internal parameters.
  738. */
  739. void (*init)(void);
  740. /*
  741. * This procedure is called at the start of each pass.
  742. */
  743. void (*reset)(void);
  744. /*
  745. * This is the modern output function, which gets passed
  746. * a struct out_data with much more information. See the
  747. * definition of struct out_data.
  748. */
  749. void (*output)(const struct out_data *data);
  750. /*
  751. * This procedure is called by assemble() to write actual
  752. * generated code or data to the object file. Typically it
  753. * doesn't have to actually _write_ it, just store it for
  754. * later.
  755. *
  756. * The `type' argument specifies the type of output data, and
  757. * usually the size as well: its contents are described below.
  758. *
  759. * This is used for backends which have not yet been ported to
  760. * the new interface, and should be NULL on ported backends.
  761. * To use this entry point, set the output pointer to
  762. * nasm_do_legacy_output.
  763. */
  764. void (*legacy_output)(int32_t segto, const void *data,
  765. enum out_type type, uint64_t size,
  766. int32_t segment, int32_t wrt);
  767. /*
  768. * This procedure is called once for every symbol defined in
  769. * the module being assembled. It gives the name and value of
  770. * the symbol, in NASM's terms, and indicates whether it has
  771. * been declared to be global. Note that the parameter "name",
  772. * when passed, will point to a piece of static storage
  773. * allocated inside the label manager - it's safe to keep using
  774. * that pointer, because the label manager doesn't clean up
  775. * until after the output driver has.
  776. *
  777. * Values of `is_global' are: 0 means the symbol is local; 1
  778. * means the symbol is global; 2 means the symbol is common (in
  779. * which case `offset' holds the _size_ of the variable).
  780. * Anything else is available for the output driver to use
  781. * internally.
  782. *
  783. * This routine explicitly _is_ allowed to call the label
  784. * manager to define further symbols, if it wants to, even
  785. * though it's been called _from_ the label manager. That much
  786. * re-entrancy is guaranteed in the label manager. However, the
  787. * label manager will in turn call this routine, so it should
  788. * be prepared to be re-entrant itself.
  789. *
  790. * The `special' parameter contains special information passed
  791. * through from the command that defined the label: it may have
  792. * been an EXTERN, a COMMON or a GLOBAL. The distinction should
  793. * be obvious to the output format from the other parameters.
  794. */
  795. void (*symdef)(char *name, int32_t segment, int64_t offset,
  796. int is_global, char *special);
  797. /*
  798. * This procedure is called when the source code requests a
  799. * segment change. It should return the corresponding segment
  800. * _number_ for the name, or NO_SEG if the name is not a valid
  801. * segment name.
  802. *
  803. * It may also be called with NULL, in which case it is to
  804. * return the _default_ section number for starting assembly in.
  805. *
  806. * It is allowed to modify the string it is given a pointer to.
  807. *
  808. * It is also allowed to specify a default instruction size for
  809. * the segment, by setting `*bits' to 16 or 32. Or, if it
  810. * doesn't wish to define a default, it can leave `bits' alone.
  811. */
  812. int32_t (*section)(char *name, int pass, int *bits);
  813. /*
  814. * This function is called when a label is defined
  815. * in the source code. It is allowed to change the section
  816. * number as a result, but not the bits value.
  817. * This is *only* called if the symbol defined is at the
  818. * current offset, i.e. "foo:" or "foo equ $".
  819. * The offset isn't passed; and may not be stable at this point.
  820. * The subsection number is a field available for use by the
  821. * backend. It is initialized to NO_SEG.
  822. *
  823. * If "copyoffset" is set by the backend then the offset is
  824. * copied from the previous segment, otherwise the new segment
  825. * is treated as a new segment the normal way.
  826. */
  827. int32_t (*herelabel)(const char *name, enum label_type type,
  828. int32_t seg, int32_t *subsection,
  829. bool *copyoffset);
  830. /*
  831. * This procedure is called to modify section alignment,
  832. * note there is a trick, the alignment can only increase
  833. */
  834. void (*sectalign)(int32_t seg, unsigned int value);
  835. /*
  836. * This procedure is called to modify the segment base values
  837. * returned from the SEG operator. It is given a segment base
  838. * value (i.e. a segment value with the low bit set), and is
  839. * required to produce in return a segment value which may be
  840. * different. It can map segment bases to absolute numbers by
  841. * means of returning SEG_ABS types.
  842. *
  843. * It should return NO_SEG if the segment base cannot be
  844. * determined; the evaluator (which calls this routine) is
  845. * responsible for throwing an error condition if that occurs
  846. * in pass two or in a critical expression.
  847. */
  848. int32_t (*segbase)(int32_t segment);
  849. /*
  850. * This procedure is called to allow the output driver to
  851. * process its own specific directives. When called, it has the
  852. * directive word in `directive' and the parameter string in
  853. * `value'. It is called in both assembly passes, and `pass'
  854. * will be either 1 or 2.
  855. *
  856. * The following values are (currently) possible for
  857. * directive_result:
  858. *
  859. * 0 - DIRR_UNKNOWN - directive not recognized by backend
  860. * 1 - DIRR_OK - directive processed ok
  861. * 2 - DIRR_ERROR - backend printed its own error message
  862. * 3 - DIRR_BADPARAM - print the generic message
  863. * "invalid parameter to [*] directive"
  864. */
  865. enum directive_result
  866. (*directive)(enum directive directive, char *value, int pass);
  867. /*
  868. * This procedure is called after assembly finishes, to allow
  869. * the output driver to clean itself up and free its memory.
  870. * Typically, it will also be the point at which the object
  871. * file actually gets _written_.
  872. *
  873. * One thing the cleanup routine should always do is to close
  874. * the output file pointer.
  875. */
  876. void (*cleanup)(void);
  877. /*
  878. * List of pragma facility names that apply to this backend.
  879. */
  880. const struct pragma_facility *pragmas;
  881. };
  882. /*
  883. * Output format driver alias
  884. */
  885. struct ofmt_alias {
  886. const char *shortname;
  887. const char *fullname;
  888. const struct ofmt *ofmt;
  889. };
  890. extern const struct ofmt *ofmt;
  891. extern FILE *ofile;
  892. /*
  893. * ------------------------------------------------------------
  894. * The data structure defining a debug format driver, and the
  895. * interfaces to the functions therein.
  896. * ------------------------------------------------------------
  897. */
  898. struct dfmt {
  899. /*
  900. * This is a short (one-liner) description of the type of
  901. * output generated by the driver.
  902. */
  903. const char *fullname;
  904. /*
  905. * This is a single keyword used to select the driver.
  906. */
  907. const char *shortname;
  908. /*
  909. * init - called initially to set up local pointer to object format.
  910. */
  911. void (*init)(void);
  912. /*
  913. * linenum - called any time there is output with a change of
  914. * line number or file.
  915. */
  916. void (*linenum)(const char *filename, int32_t linenumber, int32_t segto);
  917. /*
  918. * debug_deflabel - called whenever a label is defined. Parameters
  919. * are the same as to 'symdef()' in the output format. This function
  920. * is called after the output format version.
  921. */
  922. void (*debug_deflabel)(char *name, int32_t segment, int64_t offset,
  923. int is_global, char *special);
  924. /*
  925. * debug_directive - called whenever a DEBUG directive other than 'LINE'
  926. * is encountered. 'directive' contains the first parameter to the
  927. * DEBUG directive, and params contains the rest. For example,
  928. * 'DEBUG VAR _somevar:int' would translate to a call to this
  929. * function with 'directive' equal to "VAR" and 'params' equal to
  930. * "_somevar:int".
  931. */
  932. void (*debug_directive)(const char *directive, const char *params);
  933. /*
  934. * typevalue - called whenever the assembler wishes to register a type
  935. * for the last defined label. This routine MUST detect if a type was
  936. * already registered and not re-register it.
  937. */
  938. void (*debug_typevalue)(int32_t type);
  939. /*
  940. * debug_output - called whenever output is required
  941. * 'type' is the type of info required, and this is format-specific
  942. */
  943. void (*debug_output)(int type, void *param);
  944. /*
  945. * cleanup - called after processing of file is complete
  946. */
  947. void (*cleanup)(void);
  948. /*
  949. * List of pragma facility names that apply to this backend.
  950. */
  951. const struct pragma_facility *pragmas;
  952. };
  953. extern const struct dfmt *dfmt;
  954. /*
  955. * The type definition macros
  956. * for debugging
  957. *
  958. * low 3 bits: reserved
  959. * next 5 bits: type
  960. * next 24 bits: number of elements for arrays (0 for labels)
  961. */
  962. #define TY_UNKNOWN 0x00
  963. #define TY_LABEL 0x08
  964. #define TY_BYTE 0x10
  965. #define TY_WORD 0x18
  966. #define TY_DWORD 0x20
  967. #define TY_FLOAT 0x28
  968. #define TY_QWORD 0x30
  969. #define TY_TBYTE 0x38
  970. #define TY_OWORD 0x40
  971. #define TY_YWORD 0x48
  972. #define TY_ZWORD 0x50
  973. #define TY_COMMON 0xE0
  974. #define TY_SEG 0xE8
  975. #define TY_EXTERN 0xF0
  976. #define TY_EQU 0xF8
  977. #define TYM_TYPE(x) ((x) & 0xF8)
  978. #define TYM_ELEMENTS(x) (((x) & 0xFFFFFF00) >> 8)
  979. #define TYS_ELEMENTS(x) ((x) << 8)
  980. enum special_tokens {
  981. SPECIAL_ENUM_START = PREFIX_ENUM_LIMIT,
  982. S_ABS = SPECIAL_ENUM_START,
  983. S_BYTE,
  984. S_DWORD,
  985. S_FAR,
  986. S_LONG,
  987. S_NEAR,
  988. S_NOSPLIT,
  989. S_OWORD,
  990. S_QWORD,
  991. S_REL,
  992. S_SHORT,
  993. S_STRICT,
  994. S_TO,
  995. S_TWORD,
  996. S_WORD,
  997. S_YWORD,
  998. S_ZWORD,
  999. SPECIAL_ENUM_LIMIT
  1000. };
  1001. enum decorator_tokens {
  1002. DECORATOR_ENUM_START = SPECIAL_ENUM_LIMIT,
  1003. BRC_1TO2 = DECORATOR_ENUM_START,
  1004. BRC_1TO4,
  1005. BRC_1TO8,
  1006. BRC_1TO16,
  1007. BRC_RN,
  1008. BRC_RD,
  1009. BRC_RU,
  1010. BRC_RZ,
  1011. BRC_SAE,
  1012. BRC_Z,
  1013. DECORATOR_ENUM_LIMIT
  1014. };
  1015. /*
  1016. * AVX512 Decorator (decoflags_t) bits distribution (counted from 0)
  1017. * 3 2 1
  1018. * 10987654321098765432109876543210
  1019. * |
  1020. * | word boundary
  1021. * ............................1111 opmask
  1022. * ...........................1.... zeroing / merging
  1023. * ..........................1..... broadcast
  1024. * .........................1...... static rounding
  1025. * ........................1....... SAE
  1026. * ......................11........ broadcast element size
  1027. * ....................11.......... number of broadcast elements
  1028. */
  1029. #define OP_GENVAL(val, bits, shift) (((val) & ((UINT64_C(1) << (bits)) - 1)) << (shift))
  1030. /*
  1031. * Opmask register number
  1032. * identical to EVEX.aaa
  1033. *
  1034. * Bits: 0 - 3
  1035. */
  1036. #define OPMASK_SHIFT (0)
  1037. #define OPMASK_BITS (4)
  1038. #define OPMASK_MASK OP_GENMASK(OPMASK_BITS, OPMASK_SHIFT)
  1039. #define GEN_OPMASK(bit) OP_GENBIT(bit, OPMASK_SHIFT)
  1040. #define VAL_OPMASK(val) OP_GENVAL(val, OPMASK_BITS, OPMASK_SHIFT)
  1041. /*
  1042. * zeroing / merging control available
  1043. * matching to EVEX.z
  1044. *
  1045. * Bits: 4
  1046. */
  1047. #define Z_SHIFT (4)
  1048. #define Z_BITS (1)
  1049. #define Z_MASK OP_GENMASK(Z_BITS, Z_SHIFT)
  1050. #define GEN_Z(bit) OP_GENBIT(bit, Z_SHIFT)
  1051. /*
  1052. * broadcast - Whether this operand can be broadcasted
  1053. *
  1054. * Bits: 5
  1055. */
  1056. #define BRDCAST_SHIFT (5)
  1057. #define BRDCAST_BITS (1)
  1058. #define BRDCAST_MASK OP_GENMASK(BRDCAST_BITS, BRDCAST_SHIFT)
  1059. #define GEN_BRDCAST(bit) OP_GENBIT(bit, BRDCAST_SHIFT)
  1060. /*
  1061. * Whether this instruction can have a static rounding mode.
  1062. * It goes with the last simd operand because the static rounding mode
  1063. * decorator is located between the last simd operand and imm8 (if any).
  1064. *
  1065. * Bits: 6
  1066. */
  1067. #define STATICRND_SHIFT (6)
  1068. #define STATICRND_BITS (1)
  1069. #define STATICRND_MASK OP_GENMASK(STATICRND_BITS, STATICRND_SHIFT)
  1070. #define GEN_STATICRND(bit) OP_GENBIT(bit, STATICRND_SHIFT)
  1071. /*
  1072. * SAE(Suppress all exception) available
  1073. *
  1074. * Bits: 7
  1075. */
  1076. #define SAE_SHIFT (7)
  1077. #define SAE_BITS (1)
  1078. #define SAE_MASK OP_GENMASK(SAE_BITS, SAE_SHIFT)
  1079. #define GEN_SAE(bit) OP_GENBIT(bit, SAE_SHIFT)
  1080. /*
  1081. * Broadcasting element size.
  1082. *
  1083. * Bits: 8 - 9
  1084. */
  1085. #define BRSIZE_SHIFT (8)
  1086. #define BRSIZE_BITS (2)
  1087. #define BRSIZE_MASK OP_GENMASK(BRSIZE_BITS, BRSIZE_SHIFT)
  1088. #define GEN_BRSIZE(bit) OP_GENBIT(bit, BRSIZE_SHIFT)
  1089. #define BR_BITS32 GEN_BRSIZE(0)
  1090. #define BR_BITS64 GEN_BRSIZE(1)
  1091. /*
  1092. * Number of broadcasting elements
  1093. *
  1094. * Bits: 10 - 11
  1095. */
  1096. #define BRNUM_SHIFT (10)
  1097. #define BRNUM_BITS (2)
  1098. #define BRNUM_MASK OP_GENMASK(BRNUM_BITS, BRNUM_SHIFT)
  1099. #define VAL_BRNUM(val) OP_GENVAL(val, BRNUM_BITS, BRNUM_SHIFT)
  1100. #define BR_1TO2 VAL_BRNUM(0)
  1101. #define BR_1TO4 VAL_BRNUM(1)
  1102. #define BR_1TO8 VAL_BRNUM(2)
  1103. #define BR_1TO16 VAL_BRNUM(3)
  1104. #define MASK OPMASK_MASK /* Opmask (k1 ~ 7) can be used */
  1105. #define Z Z_MASK
  1106. #define B32 (BRDCAST_MASK|BR_BITS32) /* {1to16} : broadcast 32b * 16 to zmm(512b) */
  1107. #define B64 (BRDCAST_MASK|BR_BITS64) /* {1to8} : broadcast 64b * 8 to zmm(512b) */
  1108. #define ER STATICRND_MASK /* ER(Embedded Rounding) == Static rounding mode */
  1109. #define SAE SAE_MASK /* SAE(Suppress All Exception) */
  1110. /*
  1111. * Global modes
  1112. */
  1113. /*
  1114. * This declaration passes the "pass" number to all other modules
  1115. * "pass0" assumes the values: 0, 0, ..., 0, 1, 2
  1116. * where 0 = optimizing pass
  1117. * 1 = pass 1
  1118. * 2 = pass 2
  1119. */
  1120. /*
  1121. * flag to disable optimizations selectively
  1122. * this is useful to turn-off certain optimizations
  1123. */
  1124. enum optimization_disable_flag {
  1125. OPTIM_ALL_ENABLED = 0,
  1126. OPTIM_DISABLE_JMP_MATCH = 1
  1127. };
  1128. struct optimization {
  1129. int level;
  1130. int flag;
  1131. };
  1132. extern int pass0;
  1133. extern int64_t passn; /* Actual pass number */
  1134. extern bool tasm_compatible_mode;
  1135. extern struct optimization optimizing;
  1136. extern int globalbits; /* 16, 32 or 64-bit mode */
  1137. extern int globalrel; /* default to relative addressing? */
  1138. extern int globalbnd; /* default to using bnd prefix? */
  1139. extern const char *inname; /* primary input filename */
  1140. extern const char *outname; /* output filename */
  1141. /*
  1142. * Switch to a different segment and return the current offset
  1143. */
  1144. int64_t switch_segment(int32_t segment);
  1145. #endif