1 /* ----------------------------------------------------------------------- *
3 * Copyright 1996-2016 The NASM Authors - All Rights Reserved
4 * See the file AUTHORS included with the NASM distribution for
5 * the specific copyright holders.
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following
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.
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.
32 * ----------------------------------------------------------------------- */
35 * The Netwide Assembler main program module
61 #include "output/outform.h"
66 * This is the maximum number of optimization passes to do. If we ever
67 * find a case where the optimizer doesn't naturally converge, we might
68 * have to drop this value so the assembler doesn't appear to just hang.
70 #define MAX_OPTIMIZE (INT_MAX >> 1)
72 struct forwrefinfo
{ /* info held on forward refs. */
77 static int get_bits(char *value
);
78 static iflag_t
get_cpu(char *cpu_str
);
79 static void parse_cmdline(int, char **);
80 static void assemble_file(char *, StrList
**);
81 static bool is_suppressed_warning(int severity
);
82 static bool skip_this_pass(int severity
);
83 static void nasm_verror_gnu(int severity
, const char *fmt
, va_list args
);
84 static void nasm_verror_vc(int severity
, const char *fmt
, va_list args
);
85 static void nasm_verror_common(int severity
, const char *fmt
, va_list args
);
86 static void usage(void);
88 static bool using_debug_info
, opt_verbose_info
;
89 static const char *debug_format
;
91 bool tasm_compatible_mode
= false;
96 static time_t official_compile_time
;
98 static char inname
[FILENAME_MAX
];
99 static char outname
[FILENAME_MAX
];
100 static char listname
[FILENAME_MAX
];
101 static char errname
[FILENAME_MAX
];
102 static int globallineno
; /* for forward-reference tracking */
103 /* static int pass = 0; */
104 struct ofmt
*ofmt
= &OF_DEFAULT
;
105 struct ofmt_alias
*ofmt_alias
= NULL
;
106 const struct dfmt
*dfmt
;
108 static FILE *error_file
; /* Where to write error messages */
111 int optimizing
= MAX_OPTIMIZE
; /* number of optimization passes to take */
112 static int sb
, cmd_sb
= 16; /* by default */
115 static iflag_t cmd_cpu
;
117 int64_t global_offset_changed
; /* referenced in labels.c */
118 int64_t prev_offset_changed
;
121 static struct location location
;
122 int in_abs_seg
; /* Flag we are in ABSOLUTE seg */
123 int32_t abs_seg
; /* ABSOLUTE segment basis */
124 int32_t abs_offset
; /* ABSOLUTE offset */
126 static struct RAA
*offsets
;
128 static struct SAA
*forwrefs
; /* keep track of forward references */
129 static const struct forwrefinfo
*forwref
;
131 static struct preproc_ops
*preproc
;
133 #define OP_NORMAL (1u << 0)
134 #define OP_PREPROCESS (1u << 1)
135 #define OP_DEPEND (1u << 2)
137 static unsigned int operating_mode
;
139 /* Dependency flags */
140 static bool depend_emit_phony
= false;
141 static bool depend_missing_ok
= false;
142 static const char *depend_target
= NULL
;
143 static const char *depend_file
= NULL
;
146 * Which of the suppressible warnings are suppressed. Entry zero
147 * isn't an actual warning, but it used for -w+error/-Werror.
150 static bool warning_on
[ERR_WARN_MAX
+1]; /* Current state */
151 static bool warning_on_global
[ERR_WARN_MAX
+1]; /* Command-line state */
153 static const struct warning
{
157 } warnings
[ERR_WARN_MAX
+1] = {
158 {"error", "treat warnings as errors", false},
159 {"macro-params", "macro calls with wrong parameter count", true},
160 {"macro-selfref", "cyclic macro references", false},
161 {"macro-defaults", "macros with more default than optional parameters", true},
162 {"orphan-labels", "labels alone on lines without trailing `:'", true},
163 {"number-overflow", "numeric constant does not fit", true},
164 {"gnu-elf-extensions", "using 8- or 16-bit relocation in ELF32, a GNU extension", false},
165 {"float-overflow", "floating point overflow", true},
166 {"float-denorm", "floating point denormal", false},
167 {"float-underflow", "floating point underflow", false},
168 {"float-toolong", "too many digits in floating-point number", true},
169 {"user", "%warning directives", true},
170 {"lock", "lock prefix on unlockable instructions", true},
171 {"hle", "invalid hle prefixes", true},
172 {"bnd", "invalid bnd prefixes", true},
173 {"zext-reloc", "relocation zero-extended to match output format", true},
176 static bool want_usage
;
177 static bool terminate_after_phase
;
178 bool user_nolist
= false;
180 static char *quote_for_make(const char *str
);
182 static int64_t get_curr_offs(void)
184 return in_abs_seg
? abs_offset
: raa_read(offsets
, location
.segment
);
187 static void set_curr_offs(int64_t l_off
)
192 offsets
= raa_write(offsets
, location
.segment
, l_off
);
195 static void nasm_fputs(const char *line
, FILE * outfile
)
198 fputs(line
, outfile
);
204 /* Convert a struct tm to a POSIX-style time constant */
205 static int64_t make_posix_time(struct tm
*tm
)
208 int64_t y
= tm
->tm_year
;
210 /* See IEEE 1003.1:2004, section 4.14 */
212 t
= (y
-70)*365 + (y
-69)/4 - (y
-1)/100 + (y
+299)/400;
224 static void define_macros_early(void)
227 struct tm lt
, *lt_p
, gm
, *gm_p
;
230 lt_p
= localtime(&official_compile_time
);
234 strftime(temp
, sizeof temp
, "__DATE__=\"%Y-%m-%d\"", <
);
235 preproc
->pre_define(temp
);
236 strftime(temp
, sizeof temp
, "__DATE_NUM__=%Y%m%d", <
);
237 preproc
->pre_define(temp
);
238 strftime(temp
, sizeof temp
, "__TIME__=\"%H:%M:%S\"", <
);
239 preproc
->pre_define(temp
);
240 strftime(temp
, sizeof temp
, "__TIME_NUM__=%H%M%S", <
);
241 preproc
->pre_define(temp
);
244 gm_p
= gmtime(&official_compile_time
);
248 strftime(temp
, sizeof temp
, "__UTC_DATE__=\"%Y-%m-%d\"", &gm
);
249 preproc
->pre_define(temp
);
250 strftime(temp
, sizeof temp
, "__UTC_DATE_NUM__=%Y%m%d", &gm
);
251 preproc
->pre_define(temp
);
252 strftime(temp
, sizeof temp
, "__UTC_TIME__=\"%H:%M:%S\"", &gm
);
253 preproc
->pre_define(temp
);
254 strftime(temp
, sizeof temp
, "__UTC_TIME_NUM__=%H%M%S", &gm
);
255 preproc
->pre_define(temp
);
259 posix_time
= make_posix_time(&gm
);
261 posix_time
= make_posix_time(<
);
266 snprintf(temp
, sizeof temp
, "__POSIX_TIME__=%"PRId64
, posix_time
);
267 preproc
->pre_define(temp
);
271 static void define_macros_late(void)
276 * In case if output format is defined by alias
277 * we have to put shortname of the alias itself here
278 * otherwise ABI backward compatibility gets broken.
280 snprintf(temp
, sizeof(temp
), "__OUTPUT_FORMAT__=%s",
281 ofmt_alias
? ofmt_alias
->shortname
: ofmt
->shortname
);
282 preproc
->pre_define(temp
);
285 static void emit_dependencies(StrList
*list
)
291 if (depend_file
&& strcmp(depend_file
, "-")) {
292 deps
= fopen(depend_file
, "w");
294 nasm_error(ERR_NONFATAL
|ERR_NOFILE
|ERR_USAGE
,
295 "unable to write dependency file `%s'", depend_file
);
302 linepos
= fprintf(deps
, "%s:", depend_target
);
303 list_for_each(l
, list
) {
304 char *file
= quote_for_make(l
->str
);
306 if (linepos
+ len
> 62 && linepos
> 1) {
307 fprintf(deps
, " \\\n ");
310 fprintf(deps
, " %s", file
);
314 fprintf(deps
, "\n\n");
316 list_for_each_safe(l
, nl
, list
) {
317 if (depend_emit_phony
)
318 fprintf(deps
, "%s:\n\n", l
->str
);
326 int main(int argc
, char **argv
)
328 StrList
*depend_list
= NULL
, **depend_ptr
;
330 time(&official_compile_time
);
332 iflag_set(&cpu
, IF_PLEVEL
);
333 iflag_set(&cmd_cpu
, IF_PLEVEL
);
336 want_usage
= terminate_after_phase
= false;
337 nasm_set_verror(nasm_verror_gnu
);
343 offsets
= raa_init();
344 forwrefs
= saa_init((int32_t)sizeof(struct forwrefinfo
));
347 operating_mode
= OP_NORMAL
;
349 /* Define some macros dependent on the runtime, but not
350 on the command line. */
351 define_macros_early();
353 parse_cmdline(argc
, argv
);
355 if (terminate_after_phase
) {
361 if (!using_debug_info
) {
362 /* No debug info, redirect to the null backend (empty stubs) */
363 dfmt
= &null_debug_form
;
364 } else if (!debug_format
) {
365 /* Default debug format for this backend */
366 dfmt
= ofmt
->default_dfmt
;
368 dfmt
= dfmt_find(ofmt
, debug_format
);
370 nasm_fatal(ERR_NOFILE
| ERR_USAGE
,
371 "unrecognized debug format `%s' for"
372 " output format `%s'",
373 debug_format
, ofmt
->shortname
);
378 preproc
->extra_stdmac(ofmt
->stdmac
);
379 parser_global_info(&location
);
380 eval_global_info(ofmt
, lookup_label
, &location
);
382 /* define some macros dependent of command-line */
383 define_macros_late();
385 depend_ptr
= (depend_file
|| (operating_mode
& OP_DEPEND
)) ? &depend_list
: NULL
;
387 depend_target
= quote_for_make(outname
);
389 if (operating_mode
& OP_DEPEND
) {
392 if (depend_missing_ok
)
393 preproc
->include_path(NULL
); /* "assume generated" */
395 preproc
->reset(inname
, 0, depend_ptr
);
396 if (outname
[0] == '\0')
397 ofmt
->filename(inname
, outname
);
399 while ((line
= preproc
->getline()))
402 } else if (operating_mode
& OP_PREPROCESS
) {
404 char *file_name
= NULL
;
405 int32_t prior_linnum
= 0;
409 ofile
= fopen(outname
, "w");
411 nasm_fatal(ERR_NOFILE
,
412 "unable to open output file `%s'",
417 location
.known
= false;
420 preproc
->reset(inname
, 3, depend_ptr
);
421 memcpy(warning_on
, warning_on_global
,
422 (ERR_WARN_MAX
+1) * sizeof(bool));
424 while ((line
= preproc
->getline())) {
426 * We generate %line directives if needed for later programs
428 int32_t linnum
= prior_linnum
+= lineinc
;
429 int altline
= src_get(&linnum
, &file_name
);
431 if (altline
== 1 && lineinc
== 1)
432 nasm_fputs("", ofile
);
434 lineinc
= (altline
!= -1 || lineinc
!= 1);
435 fprintf(ofile
? ofile
: stdout
,
436 "%%line %"PRId32
"+%d %s\n", linnum
, lineinc
,
439 prior_linnum
= linnum
;
441 nasm_fputs(line
, ofile
);
444 nasm_free(file_name
);
448 if (ofile
&& terminate_after_phase
)
453 if (operating_mode
& OP_NORMAL
) {
455 * We must call ofmt->filename _anyway_, even if the user
456 * has specified their own output file, because some
457 * formats (eg OBJ and COFF) use ofmt->filename to find out
458 * the name of the input file and then put that inside the
461 ofmt
->filename(inname
, outname
);
463 ofile
= fopen(outname
, (ofmt
->flags
& OFMT_TEXT
) ? "w" : "wb");
465 nasm_fatal(ERR_NOFILE
,
466 "unable to open output file `%s'", outname
);
469 * We must call init_labels() before ofmt->init() since
470 * some object formats will want to define labels in their
471 * init routines. (eg OS/2 defines the FLAT group)
478 assemble_file(inname
, depend_ptr
);
480 if (!terminate_after_phase
) {
485 nasm_error(ERR_NONFATAL
|ERR_NOFILE
,
486 "write error on output file `%s'", outname
);
491 if (terminate_after_phase
)
497 if (depend_list
&& !terminate_after_phase
)
498 emit_dependencies(depend_list
);
508 return terminate_after_phase
;
512 * Get a parameter for a command line option.
513 * First arg must be in the form of e.g. -f...
515 static char *get_param(char *p
, char *q
, bool *advance
)
518 if (p
[2]) /* the parameter's in the option */
519 return nasm_skip_spaces(p
+ 2);
524 nasm_error(ERR_NONFATAL
| ERR_NOFILE
| ERR_USAGE
,
525 "option `-%c' requires an argument", p
[1]);
532 static void copy_filename(char *dst
, const char *src
)
534 size_t len
= strlen(src
);
536 if (len
>= (size_t)FILENAME_MAX
) {
537 nasm_fatal(ERR_NOFILE
, "file name too long");
540 strncpy(dst
, src
, FILENAME_MAX
);
544 * Convert a string to Make-safe form
546 static char *quote_for_make(const char *str
)
551 size_t n
= 1; /* Terminating zero */
557 for (p
= str
; *p
; p
++) {
561 /* Convert N backslashes + ws -> 2N+1 backslashes + ws */
581 /* Convert N backslashes at the end of filename to 2N backslashes */
585 os
= q
= nasm_malloc(n
);
588 for (p
= str
; *p
; p
++) {
634 struct textargs textopts
[] = {
635 {"prefix", OPT_PREFIX
},
636 {"postfix", OPT_POSTFIX
},
640 static void show_version(void)
642 printf("NASM version %s compiled on %s%s\n",
643 nasm_version
, nasm_date
, nasm_compile_options
);
647 static bool stopoptions
= false;
648 static bool process_arg(char *p
, char *q
)
652 bool advance
= false;
658 if (p
[0] == '-' && !stopoptions
) {
659 if (strchr("oOfpPdDiIlFXuUZwW", p
[1])) {
660 /* These parameters take values */
661 if (!(param
= get_param(p
, q
, &advance
)))
670 case 'o': /* output file */
671 copy_filename(outname
, param
);
674 case 'f': /* output format */
675 ofmt
= ofmt_find(param
, &ofmt_alias
);
677 nasm_fatal(ERR_NOFILE
| ERR_USAGE
,
678 "unrecognised output format `%s' - "
679 "use -hf for a list", param
);
683 case 'O': /* Optimization level */
688 /* Naked -O == -Ox */
689 optimizing
= MAX_OPTIMIZE
;
693 case '0': case '1': case '2': case '3': case '4':
694 case '5': case '6': case '7': case '8': case '9':
695 opt
= strtoul(param
, ¶m
, 10);
697 /* -O0 -> optimizing == -1, 0.98 behaviour */
698 /* -O1 -> optimizing == 0, 0.98.09 behaviour */
700 optimizing
= opt
- 1;
708 opt_verbose_info
= true;
713 optimizing
= MAX_OPTIMIZE
;
718 "unknown optimization option -O%c\n",
723 if (optimizing
> MAX_OPTIMIZE
)
724 optimizing
= MAX_OPTIMIZE
;
729 case 'p': /* pre-include */
731 preproc
->pre_include(param
);
734 case 'd': /* pre-define */
736 preproc
->pre_define(param
);
739 case 'u': /* un-define */
741 preproc
->pre_undefine(param
);
744 case 'i': /* include search path */
746 preproc
->include_path(param
);
749 case 'l': /* listing file */
750 copy_filename(listname
, param
);
753 case 'Z': /* error messages file */
754 copy_filename(errname
, param
);
757 case 'F': /* specify debug format */
758 using_debug_info
= true;
759 debug_format
= param
;
762 case 'X': /* specify error reporting format */
763 if (nasm_stricmp("vc", param
) == 0)
764 nasm_set_verror(nasm_verror_vc
);
765 else if (nasm_stricmp("gnu", param
) == 0)
766 nasm_set_verror(nasm_verror_gnu
);
768 nasm_fatal(ERR_NOFILE
| ERR_USAGE
,
769 "unrecognized error reporting format `%s'",
774 using_debug_info
= true;
776 debug_format
= nasm_skip_spaces(p
+ 2);
781 ("usage: nasm [-@ response file] [-o outfile] [-f format] "
783 " [options...] [--] filename\n"
784 " or nasm -v (or --v) for version info\n\n"
785 " -t assemble in SciTech TASM compatible mode\n");
787 (" -E (or -e) preprocess only (writes output to stdout by default)\n"
788 " -a don't preprocess (assemble only)\n"
789 " -M generate Makefile dependencies on stdout\n"
790 " -MG d:o, missing files assumed generated\n"
791 " -MF <file> set Makefile dependency file\n"
792 " -MD <file> assemble and generate dependencies\n"
793 " -MT <file> dependency target name\n"
794 " -MQ <file> dependency target name (quoted)\n"
795 " -MP emit phony target\n\n"
796 " -Z<file> redirect error messages to file\n"
797 " -s redirect error messages to stdout\n\n"
798 " -g generate debugging information\n\n"
799 " -F format select a debugging format\n\n"
800 " -gformat same as -g -F format\n\n"
801 " -o outfile write output to an outfile\n\n"
802 " -f format select an output format\n\n"
803 " -l listfile write listing to a listfile\n\n"
804 " -I<path> adds a pathname to the include file path\n");
806 (" -O<digit> optimize branch offsets\n"
807 " -O0: No optimization\n"
808 " -O1: Minimal optimization\n"
809 " -Ox: Multipass optimization (default)\n\n"
810 " -P<file> pre-includes a file\n"
811 " -D<macro>[=<value>] pre-defines a macro\n"
812 " -U<macro> undefines a macro\n"
813 " -X<format> specifies error reporting format (gnu or vc)\n"
814 " -w+foo enables warning foo (equiv. -Wfoo)\n"
815 " -w-foo disable warning foo (equiv. -Wno-foo)\n\n"
816 " -h show invocation summary and exit\n\n"
817 "--prefix,--postfix\n"
818 " this options prepend or append the given argument to all\n"
819 " extern and global variables\n"
821 for (i
= 0; i
<= ERR_WARN_MAX
; i
++)
822 printf(" %-23s %s (default %s)\n",
823 warnings
[i
].name
, warnings
[i
].help
,
824 warnings
[i
].enabled
? "on" : "off");
826 ("\nresponse files should contain command line parameters"
827 ", one per line.\n");
829 printf("\nvalid output formats for -f are"
830 " (`*' denotes default):\n");
831 ofmt_list(ofmt
, stdout
);
833 printf("\nFor a list of valid output formats, use -hf.\n");
834 printf("For a list of debug formats, use -f <form> -y.\n");
836 exit(0); /* never need usage message here */
840 printf("\nvalid debug formats for '%s' output format are"
841 " ('*' denotes default):\n", ofmt
->shortname
);
842 dfmt_list(ofmt
, stdout
);
847 tasm_compatible_mode
= true;
854 case 'e': /* preprocess only */
856 operating_mode
= OP_PREPROCESS
;
859 case 'a': /* assemble only - don't preprocess */
860 preproc
= &preproc_nop
;
864 if (param
[0] == 'n' && param
[1] == 'o' && param
[2] == '-') {
873 if (param
[0] != '+' && param
[0] != '-') {
874 nasm_error(ERR_NONFATAL
| ERR_NOFILE
| ERR_USAGE
,
875 "invalid option to `-w'");
878 do_warn
= (param
[0] == '+');
882 for (i
= 0; i
<= ERR_WARN_MAX
; i
++) {
883 if (!nasm_stricmp(param
, warnings
[i
].name
))
886 if (i
<= ERR_WARN_MAX
) {
887 warning_on_global
[i
] = do_warn
;
888 } else if (!nasm_stricmp(param
, "all")) {
889 for (i
= 1; i
<= ERR_WARN_MAX
; i
++)
890 warning_on_global
[i
] = do_warn
;
891 } else if (!nasm_stricmp(param
, "none")) {
892 for (i
= 1; i
<= ERR_WARN_MAX
; i
++)
893 warning_on_global
[i
] = !do_warn
;
895 nasm_error(ERR_NONFATAL
| ERR_NOFILE
| ERR_USAGE
,
896 "invalid warning `%s'", param
);
903 operating_mode
= OP_DEPEND
;
906 operating_mode
= OP_DEPEND
;
907 depend_missing_ok
= true;
910 depend_emit_phony
= true;
913 operating_mode
= OP_NORMAL
;
926 depend_target
= quote_for_make(q
);
930 nasm_error(ERR_NONFATAL
|ERR_NOFILE
|ERR_USAGE
,
931 "unknown dependency option `-M%c'", p
[2]);
934 if (advance
&& (!q
|| !q
[0])) {
935 nasm_error(ERR_NONFATAL
|ERR_NOFILE
|ERR_USAGE
,
936 "option `-M%c' requires a parameter", p
[2]);
945 if (p
[2] == 0) { /* -- => stop processing options */
950 if (!nasm_stricmp(p
, "--v"))
953 for (s
= 0; textopts
[s
].label
; s
++) {
954 if (!nasm_stricmp(p
+ 2, textopts
[s
].label
)) {
965 nasm_error(ERR_NONFATAL
| ERR_NOFILE
|
967 "option `--%s' requires an argument",
971 advance
= 1, param
= q
;
976 strlcpy(lprefix
, param
, PREFIX_MAX
);
979 strlcpy(lpostfix
, param
, POSTFIX_MAX
);
982 nasm_panic(ERR_NOFILE
,
991 nasm_error(ERR_NONFATAL
| ERR_NOFILE
| ERR_USAGE
,
992 "unrecognised option `--%s'", p
+ 2);
1000 if (!ofmt
->setinfo(GI_SWITCH
, &p
))
1001 nasm_error(ERR_NONFATAL
| ERR_NOFILE
| ERR_USAGE
,
1002 "unrecognised option `-%c'", p
[1]);
1007 nasm_error(ERR_NONFATAL
| ERR_NOFILE
| ERR_USAGE
,
1008 "more than one input file specified");
1010 copy_filename(inname
, p
);
1017 #define ARG_BUF_DELTA 128
1019 static void process_respfile(FILE * rfile
)
1021 char *buffer
, *p
, *q
, *prevarg
;
1022 int bufsize
, prevargsize
;
1024 bufsize
= prevargsize
= ARG_BUF_DELTA
;
1025 buffer
= nasm_malloc(ARG_BUF_DELTA
);
1026 prevarg
= nasm_malloc(ARG_BUF_DELTA
);
1029 while (1) { /* Loop to handle all lines in file */
1031 while (1) { /* Loop to handle long lines */
1032 q
= fgets(p
, bufsize
- (p
- buffer
), rfile
);
1036 if (p
> buffer
&& p
[-1] == '\n')
1038 if (p
- buffer
> bufsize
- 10) {
1040 offset
= p
- buffer
;
1041 bufsize
+= ARG_BUF_DELTA
;
1042 buffer
= nasm_realloc(buffer
, bufsize
);
1043 p
= buffer
+ offset
;
1047 if (!q
&& p
== buffer
) {
1049 process_arg(prevarg
, NULL
);
1056 * Play safe: remove CRs, LFs and any spurious ^Zs, if any of
1057 * them are present at the end of the line.
1059 *(p
= &buffer
[strcspn(buffer
, "\r\n\032")]) = '\0';
1061 while (p
> buffer
&& nasm_isspace(p
[-1]))
1064 p
= nasm_skip_spaces(buffer
);
1066 if (process_arg(prevarg
, p
))
1069 if ((int) strlen(p
) > prevargsize
- 10) {
1070 prevargsize
+= ARG_BUF_DELTA
;
1071 prevarg
= nasm_realloc(prevarg
, prevargsize
);
1073 strncpy(prevarg
, p
, prevargsize
);
1077 /* Function to process args from a string of args, rather than the
1078 * argv array. Used by the environment variable and response file
1081 static void process_args(char *args
)
1083 char *p
, *q
, *arg
, *prevarg
;
1084 char separator
= ' ';
1087 if (*p
&& *p
!= '-')
1092 while (*p
&& *p
!= separator
)
1094 while (*p
== separator
)
1098 if (process_arg(prevarg
, arg
))
1102 process_arg(arg
, NULL
);
1105 static void process_response_file(const char *file
)
1108 FILE *f
= fopen(file
, "r");
1113 while (fgets(str
, sizeof str
, f
)) {
1119 static void parse_cmdline(int argc
, char **argv
)
1122 char *envreal
, *envcopy
= NULL
, *p
;
1125 *inname
= *outname
= *listname
= *errname
= '\0';
1127 for (i
= 0; i
<= ERR_WARN_MAX
; i
++)
1128 warning_on_global
[i
] = warnings
[i
].enabled
;
1131 * First, process the NASMENV environment variable.
1133 envreal
= getenv("NASMENV");
1135 envcopy
= nasm_strdup(envreal
);
1136 process_args(envcopy
);
1141 * Now process the actual command line.
1146 if (argv
[0][0] == '@') {
1148 * We have a response file, so process this as a set of
1149 * arguments like the environment variable. This allows us
1150 * to have multiple arguments on a single line, which is
1151 * different to the -@resp file processing below for regular
1154 process_response_file(argv
[0]+1);
1158 if (!stopoptions
&& argv
[0][0] == '-' && argv
[0][1] == '@') {
1159 p
= get_param(argv
[0], argc
> 1 ? argv
[1] : NULL
, &advance
);
1161 rfile
= fopen(p
, "r");
1163 process_respfile(rfile
);
1166 nasm_error(ERR_NONFATAL
| ERR_NOFILE
| ERR_USAGE
,
1167 "unable to open response file `%s'", p
);
1170 advance
= process_arg(argv
[0], argc
> 1 ? argv
[1] : NULL
);
1171 argv
+= advance
, argc
-= advance
;
1175 * Look for basic command line typos. This definitely doesn't
1176 * catch all errors, but it might help cases of fumbled fingers.
1179 nasm_error(ERR_NONFATAL
| ERR_NOFILE
| ERR_USAGE
,
1180 "no input file specified");
1181 else if (!strcmp(inname
, errname
) ||
1182 !strcmp(inname
, outname
) ||
1183 !strcmp(inname
, listname
) ||
1184 (depend_file
&& !strcmp(inname
, depend_file
)))
1185 nasm_fatal(ERR_NOFILE
| ERR_USAGE
,
1186 "file `%s' is both input and output file",
1190 error_file
= fopen(errname
, "w");
1192 error_file
= stderr
; /* Revert to default! */
1193 nasm_fatal(ERR_NOFILE
| ERR_USAGE
,
1194 "cannot open file `%s' for error messages",
1200 static enum directives
getkw(char **directive
, char **value
);
1202 static void assemble_file(char *fname
, StrList
**depend_ptr
)
1204 char *directive
, *value
, *p
, *q
, *special
, *line
;
1210 struct tokenval tokval
;
1214 if (cmd_sb
== 32 && iflag_ffs(&cmd_cpu
) < IF_386
)
1215 nasm_fatal(0, "command line: 32-bit segment size requires a higher cpu");
1217 pass_max
= prev_offset_changed
= (INT_MAX
>> 1) + 2; /* Almost unlimited */
1218 for (passn
= 1; pass0
<= 2; passn
++) {
1222 pass1
= pass0
== 2 ? 2 : 1; /* 1, 1, 1, ..., 1, 2 */
1223 pass2
= passn
> 1 ? 2 : 1; /* 1, 2, 2, ..., 2, 2 */
1224 /* pass0 0, 0, 0, ..., 1, 2 */
1226 def_label
= passn
> 1 ? redefine_label
: define_label
;
1228 globalbits
= sb
= cmd_sb
; /* set 'bits' to command line default */
1231 lfmt
->init(listname
);
1234 global_offset_changed
= 0; /* set by redefine_label */
1235 location
.segment
= ofmt
->section(NULL
, pass2
, &sb
);
1238 saa_rewind(forwrefs
);
1239 forwref
= saa_rstruct(forwrefs
);
1241 offsets
= raa_init();
1243 preproc
->reset(fname
, pass1
, pass1
== 2 ? depend_ptr
: NULL
);
1244 memcpy(warning_on
, warning_on_global
, (ERR_WARN_MAX
+1) * sizeof(bool));
1248 location
.known
= true;
1249 location
.offset
= offs
= get_curr_offs();
1251 while ((line
= preproc
->getline())) {
1256 * Here we parse our directives; this is not handled by the
1257 * 'real' parser. This really should be a separate function.
1260 d
= getkw(&directive
, &value
);
1265 case D_SEGMENT
: /* [SEGMENT n] */
1267 seg
= ofmt
->section(value
, pass2
, &sb
);
1268 if (seg
== NO_SEG
) {
1269 nasm_error(pass1
== 1 ? ERR_NONFATAL
: ERR_PANIC
,
1270 "segment name `%s' not recognized",
1274 location
.segment
= seg
;
1277 case D_SECTALIGN
: /* [SECTALIGN n] */
1281 tokval
.t_type
= TOKEN_INVALID
;
1282 e
= evaluate(stdscan
, NULL
, &tokval
, NULL
, pass2
, NULL
);
1284 unsigned int align
= (unsigned int)e
->value
;
1285 if ((uint64_t)e
->value
> 0x7fffffff) {
1287 * FIXME: Please make some sane message here
1288 * ofmt should have some 'check' method which
1289 * would report segment alignment bounds.
1292 "incorrect segment alignment `%s'", value
);
1293 } else if (!is_power2(align
)) {
1294 nasm_error(ERR_NONFATAL
,
1295 "segment alignment `%s' is not power of two",
1299 /* callee should be able to handle all details */
1300 if (location
.segment
!= NO_SEG
)
1301 ofmt
->sectalign(location
.segment
, align
);
1305 case D_EXTERN
: /* [EXTERN label:special] */
1307 value
++; /* skip initial $ if present */
1310 while (*q
&& *q
!= ':')
1314 ofmt
->symdef(value
, 0L, 0L, 3, q
);
1316 } else if (passn
== 1) {
1321 while (*q
&& *q
!= ':') {
1327 nasm_error(ERR_NONFATAL
,
1328 "identifier expected after EXTERN");
1336 if (!is_extern(value
)) { /* allow re-EXTERN to be ignored */
1338 pass0
= 1; /* fake pass 1 in labels.c */
1339 declare_as_global(value
, special
);
1340 define_label(value
, seg_alloc(), 0L, NULL
,
1344 } /* else pass0 == 1 */
1346 case D_BITS
: /* [BITS bits] */
1347 globalbits
= sb
= get_bits(value
);
1349 case D_GLOBAL
: /* [GLOBAL symbol:special] */
1351 value
++; /* skip initial $ if present */
1352 if (pass0
== 2) { /* pass 2 */
1354 while (*q
&& *q
!= ':')
1358 ofmt
->symdef(value
, 0L, 0L, 3, q
);
1360 } else if (pass2
== 1) { /* pass == 1 */
1365 while (*q
&& *q
!= ':') {
1371 nasm_error(ERR_NONFATAL
,
1372 "identifier expected after GLOBAL");
1380 declare_as_global(value
, special
);
1383 case D_COMMON
: /* [COMMON symbol size:special] */
1388 value
++; /* skip initial $ if present */
1393 while (*p
&& !nasm_isspace(*p
)) {
1399 nasm_error(ERR_NONFATAL
,
1400 "identifier expected after COMMON");
1404 p
= nasm_zap_spaces_fwd(p
);
1406 while (*q
&& *q
!= ':')
1414 size
= readnum(p
, &rn_error
);
1416 nasm_error(ERR_NONFATAL
,
1417 "invalid size specified"
1418 " in COMMON declaration");
1422 nasm_error(ERR_NONFATAL
,
1423 "no size specified in"
1424 " COMMON declaration");
1429 define_common(value
, seg_alloc(), size
, special
);
1430 } else if (pass0
== 2) {
1432 ofmt
->symdef(value
, 0L, 0L, 3, special
);
1436 case D_ABSOLUTE
: /* [ABSOLUTE address] */
1439 tokval
.t_type
= TOKEN_INVALID
;
1440 e
= evaluate(stdscan
, NULL
, &tokval
, NULL
, pass2
, NULL
);
1444 1 ? ERR_NONFATAL
: ERR_PANIC
,
1445 "cannot use non-relocatable expression as "
1446 "ABSOLUTE address");
1448 abs_seg
= reloc_seg(e
);
1449 abs_offset
= reloc_value(e
);
1451 } else if (passn
== 1)
1452 abs_offset
= 0x100; /* don't go near zero in case of / */
1454 nasm_panic(0, "invalid ABSOLUTE address "
1457 location
.segment
= NO_SEG
;
1459 case D_DEBUG
: /* [DEBUG] */
1462 bool badid
, overlong
;
1466 badid
= overlong
= false;
1467 if (!isidstart(*p
)) {
1470 while (*p
&& !nasm_isspace(*p
)) {
1471 if (q
>= debugid
+ sizeof debugid
- 1) {
1482 nasm_error(passn
== 1 ? ERR_NONFATAL
: ERR_PANIC
,
1483 "identifier expected after DEBUG");
1487 nasm_error(passn
== 1 ? ERR_NONFATAL
: ERR_PANIC
,
1488 "DEBUG identifier too long");
1491 p
= nasm_skip_spaces(p
);
1493 dfmt
->debug_directive(debugid
, p
);
1496 case D_WARNING
: /* [WARNING {+|-|*}warn-name] */
1497 value
= nasm_skip_spaces(value
);
1499 case '-': validid
= 0; value
++; break;
1500 case '+': validid
= 1; value
++; break;
1501 case '*': validid
= 2; value
++; break;
1502 default: validid
= 1; break;
1505 for (i
= 1; i
<= ERR_WARN_MAX
; i
++)
1506 if (!nasm_stricmp(value
, warnings
[i
].name
))
1508 if (i
<= ERR_WARN_MAX
) {
1511 warning_on
[i
] = false;
1514 warning_on
[i
] = true;
1517 warning_on
[i
] = warning_on_global
[i
];
1521 nasm_error(ERR_NONFATAL
,
1522 "invalid warning id in WARNING directive");
1524 case D_CPU
: /* [CPU] */
1525 cpu
= get_cpu(value
);
1527 case D_LIST
: /* [LIST {+|-}] */
1528 value
= nasm_skip_spaces(value
);
1529 if (*value
== '+') {
1532 if (*value
== '-') {
1539 case D_DEFAULT
: /* [DEFAULT] */
1542 tokval
.t_type
= TOKEN_INVALID
;
1543 if (stdscan(NULL
, &tokval
) != TOKEN_INVALID
) {
1544 switch ((int)tokval
.t_integer
) {
1566 if (float_option(value
)) {
1567 nasm_error(pass1
== 1 ? ERR_NONFATAL
: ERR_PANIC
,
1568 "unknown 'float' directive: %s",
1573 if (ofmt
->directive(d
, value
, pass2
))
1575 /* else fall through */
1577 nasm_error(pass1
== 1 ? ERR_NONFATAL
: ERR_PANIC
,
1578 "unrecognised directive [%s]",
1583 nasm_error(ERR_NONFATAL
,
1584 "invalid parameter to [%s] directive",
1587 } else { /* it isn't a directive */
1588 parse_line(pass1
, line
, &output_ins
, def_label
);
1590 if (optimizing
> 0) {
1591 if (forwref
!= NULL
&& globallineno
== forwref
->lineno
) {
1592 output_ins
.forw_ref
= true;
1594 output_ins
.oprs
[forwref
->operand
].opflags
|= OPFLAG_FORWARD
;
1595 forwref
= saa_rstruct(forwrefs
);
1596 } while (forwref
!= NULL
1597 && forwref
->lineno
== globallineno
);
1599 output_ins
.forw_ref
= false;
1601 if (output_ins
.forw_ref
) {
1603 for (i
= 0; i
< output_ins
.operands
; i
++) {
1604 if (output_ins
.oprs
[i
].opflags
& OPFLAG_FORWARD
) {
1605 struct forwrefinfo
*fwinf
= (struct forwrefinfo
*)saa_wstruct(forwrefs
);
1606 fwinf
->lineno
= globallineno
;
1615 if (output_ins
.opcode
== I_EQU
) {
1618 * Special `..' EQUs get processed in pass two,
1619 * except `..@' macro-processor EQUs which are done
1620 * in the normal place.
1622 if (!output_ins
.label
)
1623 nasm_error(ERR_NONFATAL
,
1624 "EQU not preceded by label");
1626 else if (output_ins
.label
[0] != '.' ||
1627 output_ins
.label
[1] != '.' ||
1628 output_ins
.label
[2] == '@') {
1629 if (output_ins
.operands
== 1 &&
1630 (output_ins
.oprs
[0].type
& IMMEDIATE
) &&
1631 output_ins
.oprs
[0].wrt
== NO_SEG
) {
1632 bool isext
= !!(output_ins
.oprs
[0].opflags
& OPFLAG_EXTERN
);
1633 def_label(output_ins
.label
,
1634 output_ins
.oprs
[0].segment
,
1635 output_ins
.oprs
[0].offset
, NULL
,
1637 } else if (output_ins
.operands
== 2
1638 && (output_ins
.oprs
[0].type
& IMMEDIATE
)
1639 && (output_ins
.oprs
[0].type
& COLON
)
1640 && output_ins
.oprs
[0].segment
== NO_SEG
1641 && output_ins
.oprs
[0].wrt
== NO_SEG
1642 && (output_ins
.oprs
[1].type
& IMMEDIATE
)
1643 && output_ins
.oprs
[1].segment
== NO_SEG
1644 && output_ins
.oprs
[1].wrt
== NO_SEG
) {
1645 def_label(output_ins
.label
,
1646 output_ins
.oprs
[0].offset
| SEG_ABS
,
1647 output_ins
.oprs
[1].offset
,
1648 NULL
, false, false);
1650 nasm_error(ERR_NONFATAL
,
1651 "bad syntax for EQU");
1655 * Special `..' EQUs get processed here, except
1656 * `..@' macro processor EQUs which are done above.
1658 if (output_ins
.label
[0] == '.' &&
1659 output_ins
.label
[1] == '.' &&
1660 output_ins
.label
[2] != '@') {
1661 if (output_ins
.operands
== 1 &&
1662 (output_ins
.oprs
[0].type
& IMMEDIATE
)) {
1663 define_label(output_ins
.label
,
1664 output_ins
.oprs
[0].segment
,
1665 output_ins
.oprs
[0].offset
,
1666 NULL
, false, false);
1667 } else if (output_ins
.operands
== 2
1668 && (output_ins
.oprs
[0].type
& IMMEDIATE
)
1669 && (output_ins
.oprs
[0].type
& COLON
)
1670 && output_ins
.oprs
[0].segment
== NO_SEG
1671 && (output_ins
.oprs
[1].type
& IMMEDIATE
)
1672 && output_ins
.oprs
[1].segment
== NO_SEG
) {
1673 define_label(output_ins
.label
,
1674 output_ins
.oprs
[0].offset
| SEG_ABS
,
1675 output_ins
.oprs
[1].offset
,
1676 NULL
, false, false);
1678 nasm_error(ERR_NONFATAL
,
1679 "bad syntax for EQU");
1682 } else { /* instruction isn't an EQU */
1686 int64_t l
= insn_size(location
.segment
, offs
, sb
, cpu
,
1689 /* if (using_debug_info) && output_ins.opcode != -1) */
1690 if (using_debug_info
)
1691 { /* fbk 03/25/01 */
1692 /* this is done here so we can do debug type info */
1694 TYS_ELEMENTS(output_ins
.operands
);
1695 switch (output_ins
.opcode
) {
1698 TYS_ELEMENTS(output_ins
.oprs
[0].offset
) | TY_BYTE
;
1702 TYS_ELEMENTS(output_ins
.oprs
[0].offset
) | TY_WORD
;
1706 TYS_ELEMENTS(output_ins
.oprs
[0].offset
) | TY_DWORD
;
1710 TYS_ELEMENTS(output_ins
.oprs
[0].offset
) | TY_QWORD
;
1714 TYS_ELEMENTS(output_ins
.oprs
[0].offset
) | TY_TBYTE
;
1718 TYS_ELEMENTS(output_ins
.oprs
[0].offset
) | TY_OWORD
;
1722 TYS_ELEMENTS(output_ins
.oprs
[0].offset
) | TY_YWORD
;
1725 typeinfo
|= TY_BYTE
;
1728 typeinfo
|= TY_WORD
;
1731 if (output_ins
.eops_float
)
1732 typeinfo
|= TY_FLOAT
;
1734 typeinfo
|= TY_DWORD
;
1737 typeinfo
|= TY_QWORD
;
1740 typeinfo
|= TY_TBYTE
;
1743 typeinfo
|= TY_OWORD
;
1746 typeinfo
|= TY_YWORD
;
1749 typeinfo
= TY_LABEL
;
1753 dfmt
->debug_typevalue(typeinfo
);
1757 set_curr_offs(offs
);
1760 * else l == -1 => invalid instruction, which will be
1761 * flagged as an error on pass 2
1765 offs
+= assemble(location
.segment
, offs
, sb
, cpu
,
1767 set_curr_offs(offs
);
1771 cleanup_insn(&output_ins
);
1774 location
.offset
= offs
= get_curr_offs();
1775 } /* end while (line = preproc->getline... */
1777 if (pass0
== 2 && global_offset_changed
&& !terminate_after_phase
)
1778 nasm_error(ERR_NONFATAL
,
1779 "phase error detected at end of assembly.");
1782 preproc
->cleanup(1);
1784 if ((passn
> 1 && !global_offset_changed
) || pass0
== 2) {
1786 } else if (global_offset_changed
&&
1787 global_offset_changed
< prev_offset_changed
) {
1788 prev_offset_changed
= global_offset_changed
;
1794 if (terminate_after_phase
)
1797 if ((stall_count
> 997) || (passn
>= pass_max
)) {
1798 /* We get here if the labels don't converge
1799 * Example: FOO equ FOO + 1
1801 nasm_error(ERR_NONFATAL
,
1802 "Can't find valid values for all labels "
1803 "after %d passes, giving up.", passn
);
1804 nasm_error(ERR_NONFATAL
,
1805 "Possible causes: recursive EQUs, macro abuse.");
1810 preproc
->cleanup(0);
1812 if (!terminate_after_phase
&& opt_verbose_info
) {
1813 /* -On and -Ov switches */
1814 fprintf(stdout
, "info: assembly required 1+%d+1 passes\n", passn
-3);
1818 static enum directives
getkw(char **directive
, char **value
)
1822 buf
= nasm_skip_spaces(*directive
);
1824 /* it should be enclosed in [ ] */
1827 q
= strchr(buf
, ']');
1831 /* stip off the comments */
1832 p
= strchr(buf
, ';');
1834 if (p
< q
) /* ouch! somwhere inside */
1839 /* no brace, no trailing spaces */
1841 nasm_zap_spaces_rev(--q
);
1844 p
= nasm_skip_spaces(++buf
);
1845 q
= nasm_skip_word(p
);
1847 return D_none
; /* sigh... no value there */
1851 /* and value finally */
1852 p
= nasm_skip_spaces(++q
);
1855 return find_directive(*directive
);
1859 * gnu style error reporting
1860 * This function prints an error message to error_file in the
1861 * style used by GNU. An example would be:
1862 * file.asm:50: error: blah blah blah
1863 * where file.asm is the name of the file, 50 is the line number on
1864 * which the error occurs (or is detected) and "error:" is one of
1865 * the possible optional diagnostics -- it can be "error" or "warning"
1866 * or something else. Finally the line terminates with the actual
1869 * @param severity the severity of the warning or error
1870 * @param fmt the printf style format string
1872 static void nasm_verror_gnu(int severity
, const char *fmt
, va_list ap
)
1874 char *currentfile
= NULL
;
1877 if (is_suppressed_warning(severity
))
1880 if (!(severity
& ERR_NOFILE
))
1881 src_get(&lineno
, ¤tfile
);
1883 if (!skip_this_pass(severity
)) {
1885 fprintf(error_file
, "%s:%"PRId32
": ", currentfile
, lineno
);
1886 nasm_free(currentfile
);
1888 fputs("nasm: ", error_file
);
1892 nasm_verror_common(severity
, fmt
, ap
);
1896 * MS style error reporting
1897 * This function prints an error message to error_file in the
1898 * style used by Visual C and some other Microsoft tools. An example
1900 * file.asm(50) : error: blah blah blah
1901 * where file.asm is the name of the file, 50 is the line number on
1902 * which the error occurs (or is detected) and "error:" is one of
1903 * the possible optional diagnostics -- it can be "error" or "warning"
1904 * or something else. Finally the line terminates with the actual
1907 * @param severity the severity of the warning or error
1908 * @param fmt the printf style format string
1910 static void nasm_verror_vc(int severity
, const char *fmt
, va_list ap
)
1912 char *currentfile
= NULL
;
1915 if (is_suppressed_warning(severity
))
1918 if (!(severity
& ERR_NOFILE
))
1919 src_get(&lineno
, ¤tfile
);
1921 if (!skip_this_pass(severity
)) {
1923 fprintf(error_file
, "%s(%"PRId32
") : ", currentfile
, lineno
);
1924 nasm_free(currentfile
);
1926 fputs("nasm: ", error_file
);
1930 nasm_verror_common(severity
, fmt
, ap
);
1934 * check for supressed warning
1935 * checks for suppressed warning or pass one only warning and we're
1938 * @param severity the severity of the warning or error
1939 * @return true if we should abort error/warning printing
1941 static bool is_suppressed_warning(int severity
)
1943 /* Not a warning at all */
1944 if ((severity
& ERR_MASK
) != ERR_WARNING
)
1947 /* Might be a warning but suppresed explicitly */
1948 if (severity
& ERR_WARN_MASK
)
1949 return !warning_on
[WARN_IDX(severity
)];
1954 static bool skip_this_pass(int severity
)
1956 /* See if it's a pass-one only warning and we're not in pass one. */
1957 if ((severity
& ERR_MASK
) > ERR_WARNING
)
1960 if (((severity
& ERR_PASS1
) && pass0
!= 1) ||
1961 ((severity
& ERR_PASS2
) && pass0
!= 2))
1968 * common error reporting
1969 * This is the common back end of the error reporting schemes currently
1970 * implemented. It prints the nature of the warning and then the
1971 * specific error message to error_file and may or may not return. It
1972 * doesn't return if the error severity is a "panic" or "debug" type.
1974 * @param severity the severity of the warning or error
1975 * @param fmt the printf style format string
1977 static void nasm_verror_common(int severity
, const char *fmt
, va_list args
)
1982 switch (severity
& (ERR_MASK
|ERR_NO_SEVERITY
)) {
2003 vsnprintf(msg
, sizeof msg
, fmt
, args
);
2005 if (!skip_this_pass(severity
))
2006 fprintf(error_file
, "%s%s\n", pfx
, msg
);
2009 * Don't suppress this with skip_this_pass(), or we don't get
2010 * preprocessor warnings in the list file
2012 if ((severity
& ERR_MASK
) >= ERR_WARNING
)
2013 lfmt
->error(severity
, pfx
, msg
);
2015 if (severity
& ERR_USAGE
)
2018 switch (severity
& ERR_MASK
) {
2020 /* no further action, by definition */
2023 /* Treat warnings as errors */
2024 if (warning_on
[WARN_IDX(ERR_WARN_TERM
)])
2025 terminate_after_phase
= true;
2028 terminate_after_phase
= true;
2038 exit(1); /* instantly die */
2039 break; /* placate silly compilers */
2042 /* abort(); */ /* halt, catch fire, and dump core */
2053 static void usage(void)
2055 fputs("type `nasm -h' for help\n", error_file
);
2058 static iflag_t
get_cpu(char *value
)
2062 iflag_clear_all(&r
);
2064 if (!strcmp(value
, "8086"))
2065 iflag_set(&r
, IF_8086
);
2066 else if (!strcmp(value
, "186"))
2067 iflag_set(&r
, IF_186
);
2068 else if (!strcmp(value
, "286"))
2069 iflag_set(&r
, IF_286
);
2070 else if (!strcmp(value
, "386"))
2071 iflag_set(&r
, IF_386
);
2072 else if (!strcmp(value
, "486"))
2073 iflag_set(&r
, IF_486
);
2074 else if (!strcmp(value
, "586") ||
2075 !nasm_stricmp(value
, "pentium"))
2076 iflag_set(&r
, IF_PENT
);
2077 else if (!strcmp(value
, "686") ||
2078 !nasm_stricmp(value
, "ppro") ||
2079 !nasm_stricmp(value
, "pentiumpro") ||
2080 !nasm_stricmp(value
, "p2"))
2081 iflag_set(&r
, IF_P6
);
2082 else if (!nasm_stricmp(value
, "p3") ||
2083 !nasm_stricmp(value
, "katmai"))
2084 iflag_set(&r
, IF_KATMAI
);
2085 else if (!nasm_stricmp(value
, "p4") || /* is this right? -- jrc */
2086 !nasm_stricmp(value
, "willamette"))
2087 iflag_set(&r
, IF_WILLAMETTE
);
2088 else if (!nasm_stricmp(value
, "prescott"))
2089 iflag_set(&r
, IF_PRESCOTT
);
2090 else if (!nasm_stricmp(value
, "x64") ||
2091 !nasm_stricmp(value
, "x86-64"))
2092 iflag_set(&r
, IF_X86_64
);
2093 else if (!nasm_stricmp(value
, "ia64") ||
2094 !nasm_stricmp(value
, "ia-64") ||
2095 !nasm_stricmp(value
, "itanium")||
2096 !nasm_stricmp(value
, "itanic") ||
2097 !nasm_stricmp(value
, "merced"))
2098 iflag_set(&r
, IF_IA64
);
2100 iflag_set(&r
, IF_PLEVEL
);
2101 nasm_error(pass0
< 2 ? ERR_NONFATAL
: ERR_FATAL
,
2102 "unknown 'cpu' type");
2107 static int get_bits(char *value
)
2111 if ((i
= atoi(value
)) == 16)
2112 return i
; /* set for a 16-bit segment */
2114 if (iflag_ffs(&cpu
) < IF_386
) {
2115 nasm_error(ERR_NONFATAL
,
2116 "cannot specify 32-bit segment on processor below a 386");
2119 } else if (i
== 64) {
2120 if (iflag_ffs(&cpu
) < IF_X86_64
) {
2121 nasm_error(ERR_NONFATAL
,
2122 "cannot specify 64-bit segment on processor below an x86-64");
2126 nasm_error(pass0
< 2 ? ERR_NONFATAL
: ERR_FATAL
,
2127 "`%s' is not a valid segment size; must be 16, 32 or 64",