1 /* ----------------------------------------------------------------------- *
3 * Copyright 1996-2009 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"
64 struct forwrefinfo
{ /* info held on forward refs. */
69 static int get_bits(char *value
);
70 static uint32_t get_cpu(char *cpu_str
);
71 static void parse_cmdline(int, char **);
72 static void assemble_file(char *, StrList
**);
73 static void nasm_verror_gnu(int severity
, const char *fmt
, va_list args
);
74 static void nasm_verror_vc(int severity
, const char *fmt
, va_list args
);
75 static void nasm_verror_common(int severity
, const char *fmt
, va_list args
);
76 static bool is_suppressed_warning(int severity
);
77 static void usage(void);
79 static int using_debug_info
, opt_verbose_info
;
80 bool tasm_compatible_mode
= false;
85 static time_t official_compile_time
;
87 static char inname
[FILENAME_MAX
];
88 static char outname
[FILENAME_MAX
];
89 static char listname
[FILENAME_MAX
];
90 static char errname
[FILENAME_MAX
];
91 static int globallineno
; /* for forward-reference tracking */
92 /* static int pass = 0; */
93 struct ofmt
*ofmt
= &OF_DEFAULT
;
94 const struct dfmt
*dfmt
;
96 static FILE *error_file
; /* Where to write error messages */
99 int optimizing
= -1; /* number of optimization passes to take */
100 static int sb
, cmd_sb
= 16; /* by default */
101 static uint32_t cmd_cpu
= IF_PLEVEL
; /* highest level by default */
102 static uint32_t cpu
= IF_PLEVEL
; /* passed to insn_size & assemble.c */
103 int64_t global_offset_changed
; /* referenced in labels.c */
104 int64_t prev_offset_changed
;
107 static struct location location
;
108 int in_abs_seg
; /* Flag we are in ABSOLUTE seg */
109 int32_t abs_seg
; /* ABSOLUTE segment basis */
110 int32_t abs_offset
; /* ABSOLUTE offset */
112 static struct RAA
*offsets
;
114 static struct SAA
*forwrefs
; /* keep track of forward references */
115 static const struct forwrefinfo
*forwref
;
117 static Preproc
*preproc
;
119 op_normal
, /* Preprocess and assemble */
120 op_preprocess
, /* Preprocess only */
121 op_depend
, /* Generate dependencies */
123 static enum op_type operating_mode
;
124 /* Dependency flags */
125 static bool depend_emit_phony
= false;
126 static bool depend_missing_ok
= false;
127 static const char *depend_target
= NULL
;
128 static const char *depend_file
= NULL
;
131 * Which of the suppressible warnings are suppressed. Entry zero
132 * isn't an actual warning, but it used for -w+error/-Werror.
135 static bool warning_on
[ERR_WARN_MAX
+1]; /* Current state */
136 static bool warning_on_global
[ERR_WARN_MAX
+1]; /* Command-line state */
138 static const struct warning
{
142 } warnings
[ERR_WARN_MAX
+1] = {
143 {"error", "treat warnings as errors", false},
144 {"macro-params", "macro calls with wrong parameter count", true},
145 {"macro-selfref", "cyclic macro references", false},
146 {"macro-defaults", "macros with more default than optional parameters", true},
147 {"orphan-labels", "labels alone on lines without trailing `:'", true},
148 {"number-overflow", "numeric constant does not fit", true},
149 {"gnu-elf-extensions", "using 8- or 16-bit relocation in ELF32, a GNU extension", false},
150 {"float-overflow", "floating point overflow", true},
151 {"float-denorm", "floating point denormal", false},
152 {"float-underflow", "floating point underflow", false},
153 {"float-toolong", "too many digits in floating-point number", true},
154 {"user", "%warning directives", true},
158 * This is a null preprocessor which just copies lines from input
159 * to output. It's used when someone explicitly requests that NASM
160 * not preprocess their source file.
163 static void no_pp_reset(char *, int, ListGen
*, StrList
**);
164 static char *no_pp_getline(void);
165 static void no_pp_cleanup(int);
166 static Preproc no_pp
= {
173 * get/set current offset...
175 #define GET_CURR_OFFS (in_abs_seg?abs_offset:\
176 raa_read(offsets,location.segment))
177 #define SET_CURR_OFFS(x) (in_abs_seg?(void)(abs_offset=(x)):\
178 (void)(offsets=raa_write(offsets,location.segment,(x))))
180 static bool want_usage
;
181 static bool terminate_after_phase
;
182 int user_nolist
= 0; /* fbk 9/2/00 */
184 static void nasm_fputs(const char *line
, FILE * outfile
)
187 fputs(line
, outfile
);
193 /* Convert a struct tm to a POSIX-style time constant */
194 static int64_t posix_mktime(struct tm
*tm
)
197 int64_t y
= tm
->tm_year
;
199 /* See IEEE 1003.1:2004, section 4.14 */
201 t
= (y
-70)*365 + (y
-69)/4 - (y
-1)/100 + (y
+299)/400;
213 static void define_macros_early(void)
216 struct tm lt
, *lt_p
, gm
, *gm_p
;
219 lt_p
= localtime(&official_compile_time
);
223 strftime(temp
, sizeof temp
, "__DATE__=\"%Y-%m-%d\"", <
);
225 strftime(temp
, sizeof temp
, "__DATE_NUM__=%Y%m%d", <
);
227 strftime(temp
, sizeof temp
, "__TIME__=\"%H:%M:%S\"", <
);
229 strftime(temp
, sizeof temp
, "__TIME_NUM__=%H%M%S", <
);
233 gm_p
= gmtime(&official_compile_time
);
237 strftime(temp
, sizeof temp
, "__UTC_DATE__=\"%Y-%m-%d\"", &gm
);
239 strftime(temp
, sizeof temp
, "__UTC_DATE_NUM__=%Y%m%d", &gm
);
241 strftime(temp
, sizeof temp
, "__UTC_TIME__=\"%H:%M:%S\"", &gm
);
243 strftime(temp
, sizeof temp
, "__UTC_TIME_NUM__=%H%M%S", &gm
);
248 posix_time
= posix_mktime(&gm
);
250 posix_time
= posix_mktime(<
);
255 snprintf(temp
, sizeof temp
, "__POSIX_TIME__=%"PRId64
, posix_time
);
260 static void define_macros_late(void)
264 snprintf(temp
, sizeof(temp
), "__OUTPUT_FORMAT__=%s\n",
269 static void emit_dependencies(StrList
*list
)
275 if (depend_file
&& strcmp(depend_file
, "-")) {
276 deps
= fopen(depend_file
, "w");
278 nasm_error(ERR_NONFATAL
|ERR_NOFILE
|ERR_USAGE
,
279 "unable to write dependency file `%s'", depend_file
);
286 linepos
= fprintf(deps
, "%s:", depend_target
);
287 list_for_each(l
, list
) {
288 len
= strlen(l
->str
);
289 if (linepos
+ len
> 62) {
290 fprintf(deps
, " \\\n ");
293 fprintf(deps
, " %s", l
->str
);
296 fprintf(deps
, "\n\n");
298 list_for_each_safe(l
, nl
, list
) {
299 if (depend_emit_phony
)
300 fprintf(deps
, "%s:\n\n", l
->str
);
308 int main(int argc
, char **argv
)
310 StrList
*depend_list
= NULL
, **depend_ptr
;
312 time(&official_compile_time
);
315 want_usage
= terminate_after_phase
= false;
316 nasm_set_verror(nasm_verror_gnu
);
322 nasm_init_malloc_error();
323 offsets
= raa_init();
324 forwrefs
= saa_init((int32_t)sizeof(struct forwrefinfo
));
327 operating_mode
= op_normal
;
331 /* Define some macros dependent on the runtime, but not
332 on the command line. */
333 define_macros_early();
335 parse_cmdline(argc
, argv
);
337 if (terminate_after_phase
) {
343 /* If debugging info is disabled, suppress any debug calls */
344 if (!using_debug_info
)
345 ofmt
->current_dfmt
= &null_debug_form
;
348 pp_extra_stdmac(ofmt
->stdmac
);
349 parser_global_info(&location
);
350 eval_global_info(ofmt
, lookup_label
, &location
);
352 /* define some macros dependent of command-line */
353 define_macros_late();
355 depend_ptr
= (depend_file
|| (operating_mode
== op_depend
))
356 ? &depend_list
: NULL
;
358 depend_target
= outname
;
360 switch (operating_mode
) {
365 if (depend_missing_ok
)
366 pp_include_path(NULL
); /* "assume generated" */
368 preproc
->reset(inname
, 0, &nasmlist
, depend_ptr
);
369 if (outname
[0] == '\0')
370 ofmt
->filename(inname
, outname
);
372 while ((line
= preproc
->getline()))
381 char *file_name
= NULL
;
382 int32_t prior_linnum
= 0;
386 ofile
= fopen(outname
, "w");
388 nasm_error(ERR_FATAL
| ERR_NOFILE
,
389 "unable to open output file `%s'",
394 location
.known
= false;
397 preproc
->reset(inname
, 3, &nasmlist
, depend_ptr
);
399 while ((line
= preproc
->getline())) {
401 * We generate %line directives if needed for later programs
403 int32_t linnum
= prior_linnum
+= lineinc
;
404 int altline
= src_get(&linnum
, &file_name
);
406 if (altline
== 1 && lineinc
== 1)
407 nasm_fputs("", ofile
);
409 lineinc
= (altline
!= -1 || lineinc
!= 1);
410 fprintf(ofile
? ofile
: stdout
,
411 "%%line %"PRId32
"+%d %s\n", linnum
, lineinc
,
414 prior_linnum
= linnum
;
416 nasm_fputs(line
, ofile
);
419 nasm_free(file_name
);
423 if (ofile
&& terminate_after_phase
)
432 * We must call ofmt->filename _anyway_, even if the user
433 * has specified their own output file, because some
434 * formats (eg OBJ and COFF) use ofmt->filename to find out
435 * the name of the input file and then put that inside the
438 ofmt
->filename(inname
, outname
);
440 ofile
= fopen(outname
, (ofmt
->flags
& OFMT_TEXT
) ? "w" : "wb");
442 nasm_error(ERR_FATAL
| ERR_NOFILE
,
443 "unable to open output file `%s'", outname
);
447 * We must call init_labels() before ofmt->init() since
448 * some object formats will want to define labels in their
449 * init routines. (eg OS/2 defines the FLAT group)
454 dfmt
= ofmt
->current_dfmt
;
457 assemble_file(inname
, depend_ptr
);
459 if (!terminate_after_phase
) {
460 ofmt
->cleanup(using_debug_info
);
464 nasm_error(ERR_NONFATAL
|ERR_NOFILE
,
465 "write error on output file `%s'", outname
);
471 if (terminate_after_phase
)
479 if (depend_list
&& !terminate_after_phase
)
480 emit_dependencies(depend_list
);
490 return terminate_after_phase
;
494 * Get a parameter for a command line option.
495 * First arg must be in the form of e.g. -f...
497 static char *get_param(char *p
, char *q
, bool *advance
)
500 if (p
[2]) /* the parameter's in the option */
501 return nasm_skip_spaces(p
+ 2);
506 nasm_error(ERR_NONFATAL
| ERR_NOFILE
| ERR_USAGE
,
507 "option `-%c' requires an argument", p
[1]);
514 static void copy_filename(char *dst
, const char *src
)
516 size_t len
= strlen(src
);
518 if (len
>= (size_t)FILENAME_MAX
) {
519 nasm_error(ERR_FATAL
| ERR_NOFILE
, "file name too long");
522 strncpy(dst
, src
, FILENAME_MAX
);
526 * Convert a string to Make-safe form
528 static char *quote_for_make(const char *str
)
533 size_t n
= 1; /* Terminating zero */
539 for (p
= str
; *p
; p
++) {
543 /* Convert N backslashes + ws -> 2N+1 backslashes + ws */
563 /* Convert N backslashes at the end of filename to 2N backslashes */
567 os
= q
= nasm_malloc(n
);
570 for (p
= str
; *p
; p
++) {
613 #define OPT_POSTFIX 1
614 struct textargs textopts
[] = {
615 {"prefix", OPT_PREFIX
},
616 {"postfix", OPT_POSTFIX
},
620 static bool stopoptions
= false;
621 static bool process_arg(char *p
, char *q
)
625 bool advance
= false;
631 if (p
[0] == '-' && !stopoptions
) {
632 if (strchr("oOfpPdDiIlFXuUZwW", p
[1])) {
633 /* These parameters take values */
634 if (!(param
= get_param(p
, q
, &advance
)))
643 case 'o': /* output file */
644 copy_filename(outname
, param
);
647 case 'f': /* output format */
648 ofmt
= ofmt_find(param
);
650 nasm_error(ERR_FATAL
| ERR_NOFILE
| ERR_USAGE
,
651 "unrecognised output format `%s' - "
652 "use -hf for a list", param
);
656 case 'O': /* Optimization level */
661 /* Naked -O == -Ox */
662 optimizing
= INT_MAX
>> 1; /* Almost unlimited */
666 case '0': case '1': case '2': case '3': case '4':
667 case '5': case '6': case '7': case '8': case '9':
668 opt
= strtoul(param
, ¶m
, 10);
670 /* -O0 -> optimizing == -1, 0.98 behaviour */
671 /* -O1 -> optimizing == 0, 0.98.09 behaviour */
673 optimizing
= opt
- 1;
681 opt_verbose_info
= true;
686 optimizing
= INT_MAX
>> 1; /* Almost unlimited */
690 nasm_error(ERR_FATAL
,
691 "unknown optimization option -O%c\n",
700 case 'p': /* pre-include */
702 pp_pre_include(param
);
705 case 'd': /* pre-define */
707 pp_pre_define(param
);
710 case 'u': /* un-define */
712 pp_pre_undefine(param
);
715 case 'i': /* include search path */
717 pp_include_path(param
);
720 case 'l': /* listing file */
721 copy_filename(listname
, param
);
724 case 'Z': /* error messages file */
725 copy_filename(errname
, param
);
728 case 'F': /* specify debug format */
729 ofmt
->current_dfmt
= dfmt_find(ofmt
, param
);
730 if (!ofmt
->current_dfmt
) {
731 nasm_error(ERR_FATAL
| ERR_NOFILE
| ERR_USAGE
,
732 "unrecognized debug format `%s' for"
733 " output format `%s'",
734 param
, ofmt
->shortname
);
736 using_debug_info
= true;
739 case 'X': /* specify error reporting format */
740 if (nasm_stricmp("vc", param
) == 0)
741 nasm_set_verror(nasm_verror_vc
);
742 else if (nasm_stricmp("gnu", param
) == 0)
743 nasm_set_verror(nasm_verror_gnu
);
745 nasm_error(ERR_FATAL
| ERR_NOFILE
| ERR_USAGE
,
746 "unrecognized error reporting format `%s'",
751 using_debug_info
= true;
756 ("usage: nasm [-@ response file] [-o outfile] [-f format] "
758 " [options...] [--] filename\n"
759 " or nasm -v for version info\n\n"
760 " -t assemble in SciTech TASM compatible mode\n"
761 " -g generate debug information in selected format\n");
763 (" -E (or -e) preprocess only (writes output to stdout by default)\n"
764 " -a don't preprocess (assemble only)\n"
765 " -M generate Makefile dependencies on stdout\n"
766 " -MG d:o, missing files assumed generated\n"
767 " -MF <file> set Makefile dependency file\n"
768 " -MD <file> assemble and generate dependencies\n"
769 " -MT <file> dependency target name\n"
770 " -MQ <file> dependency target name (quoted)\n"
771 " -MP emit phony target\n\n"
772 " -Z<file> redirect error messages to file\n"
773 " -s redirect error messages to stdout\n\n"
774 " -F format select a debugging format\n\n"
775 " -I<path> adds a pathname to the include file path\n");
777 (" -O<digit> optimize branch offsets\n"
778 " -O0: No optimization (default)\n"
779 " -O1: Minimal optimization\n"
780 " -Ox: Multipass optimization (recommended)\n\n"
781 " -P<file> pre-includes a file\n"
782 " -D<macro>[=<value>] pre-defines a macro\n"
783 " -U<macro> undefines a macro\n"
784 " -X<format> specifies error reporting format (gnu or vc)\n"
785 " -w+foo enables warning foo (equiv. -Wfoo)\n"
786 " -w-foo disable warning foo (equiv. -Wno-foo)\n\n"
787 "--prefix,--postfix\n"
788 " this options prepend or append the given argument to all\n"
789 " extern and global variables\n\n"
791 for (i
= 0; i
<= ERR_WARN_MAX
; i
++)
792 printf(" %-23s %s (default %s)\n",
793 warnings
[i
].name
, warnings
[i
].help
,
794 warnings
[i
].enabled
? "on" : "off");
796 ("\nresponse files should contain command line parameters"
797 ", one per line.\n");
799 printf("\nvalid output formats for -f are"
800 " (`*' denotes default):\n");
801 ofmt_list(ofmt
, stdout
);
803 printf("\nFor a list of valid output formats, use -hf.\n");
804 printf("For a list of debug formats, use -f <form> -y.\n");
806 exit(0); /* never need usage message here */
810 printf("\nvalid debug formats for '%s' output format are"
811 " ('*' denotes default):\n", ofmt
->shortname
);
812 dfmt_list(ofmt
, stdout
);
817 tasm_compatible_mode
= true;
821 printf("NASM version %s compiled on %s%s\n",
822 nasm_version
, nasm_date
, nasm_compile_options
);
823 exit(0); /* never need usage message here */
826 case 'e': /* preprocess only */
828 operating_mode
= op_preprocess
;
831 case 'a': /* assemble only - don't preprocess */
836 if (param
[0] == 'n' && param
[1] == 'o' && param
[2] == '-') {
845 if (param
[0] != '+' && param
[0] != '-') {
846 nasm_error(ERR_NONFATAL
| ERR_NOFILE
| ERR_USAGE
,
847 "invalid option to `-w'");
850 do_warn
= (param
[0] == '+');
854 for (i
= 0; i
<= ERR_WARN_MAX
; i
++)
855 if (!nasm_stricmp(param
, warnings
[i
].name
))
857 if (i
<= ERR_WARN_MAX
)
858 warning_on_global
[i
] = do_warn
;
859 else if (!nasm_stricmp(param
, "all"))
860 for (i
= 1; i
<= ERR_WARN_MAX
; i
++)
861 warning_on_global
[i
] = do_warn
;
862 else if (!nasm_stricmp(param
, "none"))
863 for (i
= 1; i
<= ERR_WARN_MAX
; i
++)
864 warning_on_global
[i
] = !do_warn
;
866 nasm_error(ERR_NONFATAL
| ERR_NOFILE
| ERR_USAGE
,
867 "invalid warning `%s'", param
);
873 operating_mode
= op_depend
;
876 operating_mode
= op_depend
;
877 depend_missing_ok
= true;
880 depend_emit_phony
= true;
891 depend_target
= quote_for_make(q
);
895 nasm_error(ERR_NONFATAL
|ERR_NOFILE
|ERR_USAGE
,
896 "unknown dependency option `-M%c'", p
[2]);
899 if (advance
&& (!q
|| !q
[0])) {
900 nasm_error(ERR_NONFATAL
|ERR_NOFILE
|ERR_USAGE
,
901 "option `-M%c' requires a parameter", p
[2]);
910 if (p
[2] == 0) { /* -- => stop processing options */
914 for (s
= 0; textopts
[s
].label
; s
++) {
915 if (!nasm_stricmp(p
+ 2, textopts
[s
].label
)) {
926 nasm_error(ERR_NONFATAL
| ERR_NOFILE
|
928 "option `--%s' requires an argument",
932 advance
= 1, param
= q
;
935 if (s
== OPT_PREFIX
) {
936 strncpy(lprefix
, param
, PREFIX_MAX
- 1);
937 lprefix
[PREFIX_MAX
- 1] = 0;
940 if (s
== OPT_POSTFIX
) {
941 strncpy(lpostfix
, param
, POSTFIX_MAX
- 1);
942 lpostfix
[POSTFIX_MAX
- 1] = 0;
949 nasm_error(ERR_NONFATAL
| ERR_NOFILE
| ERR_USAGE
,
950 "unrecognised option `--%s'", p
+ 2);
958 if (!ofmt
->setinfo(GI_SWITCH
, &p
))
959 nasm_error(ERR_NONFATAL
| ERR_NOFILE
| ERR_USAGE
,
960 "unrecognised option `-%c'", p
[1]);
965 nasm_error(ERR_NONFATAL
| ERR_NOFILE
| ERR_USAGE
,
966 "more than one input file specified");
968 copy_filename(inname
, p
);
975 #define ARG_BUF_DELTA 128
977 static void process_respfile(FILE * rfile
)
979 char *buffer
, *p
, *q
, *prevarg
;
980 int bufsize
, prevargsize
;
982 bufsize
= prevargsize
= ARG_BUF_DELTA
;
983 buffer
= nasm_malloc(ARG_BUF_DELTA
);
984 prevarg
= nasm_malloc(ARG_BUF_DELTA
);
987 while (1) { /* Loop to handle all lines in file */
989 while (1) { /* Loop to handle long lines */
990 q
= fgets(p
, bufsize
- (p
- buffer
), rfile
);
994 if (p
> buffer
&& p
[-1] == '\n')
996 if (p
- buffer
> bufsize
- 10) {
999 bufsize
+= ARG_BUF_DELTA
;
1000 buffer
= nasm_realloc(buffer
, bufsize
);
1001 p
= buffer
+ offset
;
1005 if (!q
&& p
== buffer
) {
1007 process_arg(prevarg
, NULL
);
1014 * Play safe: remove CRs, LFs and any spurious ^Zs, if any of
1015 * them are present at the end of the line.
1017 *(p
= &buffer
[strcspn(buffer
, "\r\n\032")]) = '\0';
1019 while (p
> buffer
&& nasm_isspace(p
[-1]))
1022 p
= nasm_skip_spaces(buffer
);
1024 if (process_arg(prevarg
, p
))
1027 if ((int) strlen(p
) > prevargsize
- 10) {
1028 prevargsize
+= ARG_BUF_DELTA
;
1029 prevarg
= nasm_realloc(prevarg
, prevargsize
);
1031 strncpy(prevarg
, p
, prevargsize
);
1035 /* Function to process args from a string of args, rather than the
1036 * argv array. Used by the environment variable and response file
1039 static void process_args(char *args
)
1041 char *p
, *q
, *arg
, *prevarg
;
1042 char separator
= ' ';
1045 if (*p
&& *p
!= '-')
1050 while (*p
&& *p
!= separator
)
1052 while (*p
== separator
)
1056 if (process_arg(prevarg
, arg
))
1060 process_arg(arg
, NULL
);
1063 static void process_response_file(const char *file
)
1066 FILE *f
= fopen(file
, "r");
1071 while (fgets(str
, sizeof str
, f
)) {
1077 static void parse_cmdline(int argc
, char **argv
)
1080 char *envreal
, *envcopy
= NULL
, *p
, *arg
;
1083 *inname
= *outname
= *listname
= *errname
= '\0';
1084 for (i
= 0; i
<= ERR_WARN_MAX
; i
++)
1085 warning_on_global
[i
] = warnings
[i
].enabled
;
1088 * First, process the NASMENV environment variable.
1090 envreal
= getenv("NASMENV");
1093 envcopy
= nasm_strdup(envreal
);
1094 process_args(envcopy
);
1099 * Now process the actual command line.
1104 if (argv
[0][0] == '@') {
1105 /* We have a response file, so process this as a set of
1106 * arguments like the environment variable. This allows us
1107 * to have multiple arguments on a single line, which is
1108 * different to the -@resp file processing below for regular
1111 process_response_file(argv
[0]+1);
1115 if (!stopoptions
&& argv
[0][0] == '-' && argv
[0][1] == '@') {
1116 p
= get_param(argv
[0], argc
> 1 ? argv
[1] : NULL
, &advance
);
1118 rfile
= fopen(p
, "r");
1120 process_respfile(rfile
);
1123 nasm_error(ERR_NONFATAL
| ERR_NOFILE
| ERR_USAGE
,
1124 "unable to open response file `%s'", p
);
1127 advance
= process_arg(argv
[0], argc
> 1 ? argv
[1] : NULL
);
1128 argv
+= advance
, argc
-= advance
;
1131 /* Look for basic command line typos. This definitely doesn't
1132 catch all errors, but it might help cases of fumbled fingers. */
1134 nasm_error(ERR_NONFATAL
| ERR_NOFILE
| ERR_USAGE
,
1135 "no input file specified");
1136 else if (!strcmp(inname
, errname
) ||
1137 !strcmp(inname
, outname
) ||
1138 !strcmp(inname
, listname
) ||
1139 (depend_file
&& !strcmp(inname
, depend_file
)))
1140 nasm_error(ERR_FATAL
| ERR_NOFILE
| ERR_USAGE
,
1141 "file `%s' is both input and output file",
1145 error_file
= fopen(errname
, "w");
1147 error_file
= stderr
; /* Revert to default! */
1148 nasm_error(ERR_FATAL
| ERR_NOFILE
| ERR_USAGE
,
1149 "cannot open file `%s' for error messages",
1155 static enum directives
getkw(char **directive
, char **value
);
1157 static void assemble_file(char *fname
, StrList
**depend_ptr
)
1159 char *directive
, *value
, *p
, *q
, *special
, *line
;
1165 struct tokenval tokval
;
1169 if (cmd_sb
== 32 && cmd_cpu
< IF_386
)
1170 nasm_error(ERR_FATAL
, "command line: "
1171 "32-bit segment size requires a higher cpu");
1173 pass_max
= prev_offset_changed
= (INT_MAX
>> 1) + 2; /* Almost unlimited */
1174 for (passn
= 1; pass0
<= 2; passn
++) {
1178 pass1
= pass0
== 2 ? 2 : 1; /* 1, 1, 1, ..., 1, 2 */
1179 pass2
= passn
> 1 ? 2 : 1; /* 1, 2, 2, ..., 2, 2 */
1180 /* pass0 0, 0, 0, ..., 1, 2 */
1182 def_label
= passn
> 1 ? redefine_label
: define_label
;
1184 globalbits
= sb
= cmd_sb
; /* set 'bits' to command line default */
1188 nasmlist
.init(listname
, nasm_error
);
1191 global_offset_changed
= 0; /* set by redefine_label */
1192 location
.segment
= ofmt
->section(NULL
, pass2
, &sb
);
1195 saa_rewind(forwrefs
);
1196 forwref
= saa_rstruct(forwrefs
);
1198 offsets
= raa_init();
1200 preproc
->reset(fname
, pass1
, &nasmlist
,
1201 pass1
== 2 ? depend_ptr
: NULL
);
1202 memcpy(warning_on
, warning_on_global
, (ERR_WARN_MAX
+1) * sizeof(bool));
1206 location
.known
= true;
1207 location
.offset
= offs
= GET_CURR_OFFS
;
1209 while ((line
= preproc
->getline())) {
1214 * Here we parse our directives; this is not handled by the
1215 * 'real' parser. This really should be a separate function.
1218 d
= getkw(&directive
, &value
);
1223 case D_SEGMENT
: /* [SEGMENT n] */
1225 seg
= ofmt
->section(value
, pass2
, &sb
);
1226 if (seg
== NO_SEG
) {
1227 nasm_error(pass1
== 1 ? ERR_NONFATAL
: ERR_PANIC
,
1228 "segment name `%s' not recognized",
1232 location
.segment
= seg
;
1235 case D_SECTALIGN
: /* [SECTALIGN n] */
1238 unsigned int align
= atoi(value
);
1239 if (!is_power2(align
)) {
1240 nasm_error(ERR_NONFATAL
,
1241 "segment alignment `%s' is not power of two",
1244 /* callee should be able to handle all details */
1245 ofmt
->sectalign(location
.segment
, align
);
1249 case D_EXTERN
: /* [EXTERN label:special] */
1251 value
++; /* skip initial $ if present */
1254 while (*q
&& *q
!= ':')
1258 ofmt
->symdef(value
, 0L, 0L, 3, q
);
1260 } else if (passn
== 1) {
1265 while (*q
&& *q
!= ':') {
1271 nasm_error(ERR_NONFATAL
,
1272 "identifier expected after EXTERN");
1280 if (!is_extern(value
)) { /* allow re-EXTERN to be ignored */
1282 pass0
= 1; /* fake pass 1 in labels.c */
1283 declare_as_global(value
, special
);
1284 define_label(value
, seg_alloc(), 0L, NULL
,
1288 } /* else pass0 == 1 */
1290 case D_BITS
: /* [BITS bits] */
1291 globalbits
= sb
= get_bits(value
);
1293 case D_GLOBAL
: /* [GLOBAL symbol:special] */
1295 value
++; /* skip initial $ if present */
1296 if (pass0
== 2) { /* pass 2 */
1298 while (*q
&& *q
!= ':')
1302 ofmt
->symdef(value
, 0L, 0L, 3, q
);
1304 } else if (pass2
== 1) { /* pass == 1 */
1309 while (*q
&& *q
!= ':') {
1315 nasm_error(ERR_NONFATAL
,
1316 "identifier expected after GLOBAL");
1324 declare_as_global(value
, special
);
1327 case D_COMMON
: /* [COMMON symbol size:special] */
1332 value
++; /* skip initial $ if present */
1337 while (*p
&& !nasm_isspace(*p
)) {
1343 nasm_error(ERR_NONFATAL
,
1344 "identifier expected after COMMON");
1348 p
= nasm_zap_spaces_fwd(p
);
1350 while (*q
&& *q
!= ':')
1358 size
= readnum(p
, &rn_error
);
1360 nasm_error(ERR_NONFATAL
,
1361 "invalid size specified"
1362 " in COMMON declaration");
1366 nasm_error(ERR_NONFATAL
,
1367 "no size specified in"
1368 " COMMON declaration");
1373 define_common(value
, seg_alloc(), size
, special
);
1374 } else if (pass0
== 2) {
1376 ofmt
->symdef(value
, 0L, 0L, 3, special
);
1380 case D_ABSOLUTE
: /* [ABSOLUTE address] */
1383 tokval
.t_type
= TOKEN_INVALID
;
1384 e
= evaluate(stdscan
, NULL
, &tokval
, NULL
, pass2
,
1389 1 ? ERR_NONFATAL
: ERR_PANIC
,
1390 "cannot use non-relocatable expression as "
1391 "ABSOLUTE address");
1393 abs_seg
= reloc_seg(e
);
1394 abs_offset
= reloc_value(e
);
1396 } else if (passn
== 1)
1397 abs_offset
= 0x100; /* don't go near zero in case of / */
1399 nasm_error(ERR_PANIC
, "invalid ABSOLUTE address "
1402 location
.segment
= NO_SEG
;
1404 case D_DEBUG
: /* [DEBUG] */
1407 bool badid
, overlong
;
1411 badid
= overlong
= false;
1412 if (!isidstart(*p
)) {
1415 while (*p
&& !nasm_isspace(*p
)) {
1416 if (q
>= debugid
+ sizeof debugid
- 1) {
1427 nasm_error(passn
== 1 ? ERR_NONFATAL
: ERR_PANIC
,
1428 "identifier expected after DEBUG");
1432 nasm_error(passn
== 1 ? ERR_NONFATAL
: ERR_PANIC
,
1433 "DEBUG identifier too long");
1436 p
= nasm_skip_spaces(p
);
1438 dfmt
->debug_directive(debugid
, p
);
1441 case D_WARNING
: /* [WARNING {+|-|*}warn-name] */
1442 value
= nasm_skip_spaces(value
);
1444 case '-': validid
= 0; value
++; break;
1445 case '+': validid
= 1; value
++; break;
1446 case '*': validid
= 2; value
++; break;
1447 default: validid
= 1; break;
1450 for (i
= 1; i
<= ERR_WARN_MAX
; i
++)
1451 if (!nasm_stricmp(value
, warnings
[i
].name
))
1453 if (i
<= ERR_WARN_MAX
) {
1456 warning_on
[i
] = false;
1459 warning_on
[i
] = true;
1462 warning_on
[i
] = warning_on_global
[i
];
1467 nasm_error(ERR_NONFATAL
,
1468 "invalid warning id in WARNING directive");
1470 case D_CPU
: /* [CPU] */
1471 cpu
= get_cpu(value
);
1473 case D_LIST
: /* [LIST {+|-}] */
1474 value
= nasm_skip_spaces(value
);
1475 if (*value
== '+') {
1478 if (*value
== '-') {
1485 case D_DEFAULT
: /* [DEFAULT] */
1488 tokval
.t_type
= TOKEN_INVALID
;
1489 if (stdscan(NULL
, &tokval
) == TOKEN_SPECIAL
) {
1490 switch ((int)tokval
.t_integer
) {
1506 if (float_option(value
)) {
1507 nasm_error(pass1
== 1 ? ERR_NONFATAL
: ERR_PANIC
,
1508 "unknown 'float' directive: %s",
1513 if (ofmt
->directive(d
, value
, pass2
))
1515 /* else fall through */
1517 nasm_error(pass1
== 1 ? ERR_NONFATAL
: ERR_PANIC
,
1518 "unrecognised directive [%s]",
1523 nasm_error(ERR_NONFATAL
,
1524 "invalid parameter to [%s] directive",
1527 } else { /* it isn't a directive */
1528 parse_line(pass1
, line
, &output_ins
, def_label
);
1530 if (optimizing
> 0) {
1531 if (forwref
!= NULL
&& globallineno
== forwref
->lineno
) {
1532 output_ins
.forw_ref
= true;
1534 output_ins
.oprs
[forwref
->operand
].opflags
|= OPFLAG_FORWARD
;
1535 forwref
= saa_rstruct(forwrefs
);
1536 } while (forwref
!= NULL
1537 && forwref
->lineno
== globallineno
);
1539 output_ins
.forw_ref
= false;
1541 if (output_ins
.forw_ref
) {
1543 for (i
= 0; i
< output_ins
.operands
; i
++) {
1544 if (output_ins
.oprs
[i
].opflags
& OPFLAG_FORWARD
) {
1545 struct forwrefinfo
*fwinf
=
1546 (struct forwrefinfo
*)
1547 saa_wstruct(forwrefs
);
1548 fwinf
->lineno
= globallineno
;
1557 if (output_ins
.opcode
== I_EQU
) {
1560 * Special `..' EQUs get processed in pass two,
1561 * except `..@' macro-processor EQUs which are done
1562 * in the normal place.
1564 if (!output_ins
.label
)
1565 nasm_error(ERR_NONFATAL
,
1566 "EQU not preceded by label");
1568 else if (output_ins
.label
[0] != '.' ||
1569 output_ins
.label
[1] != '.' ||
1570 output_ins
.label
[2] == '@') {
1571 if (output_ins
.operands
== 1 &&
1572 (output_ins
.oprs
[0].type
& IMMEDIATE
) &&
1573 output_ins
.oprs
[0].wrt
== NO_SEG
) {
1574 bool isext
= !!(output_ins
.oprs
[0].opflags
1576 def_label(output_ins
.label
,
1577 output_ins
.oprs
[0].segment
,
1578 output_ins
.oprs
[0].offset
, NULL
,
1580 } else if (output_ins
.operands
== 2
1581 && (output_ins
.oprs
[0].type
& IMMEDIATE
)
1582 && (output_ins
.oprs
[0].type
& COLON
)
1583 && output_ins
.oprs
[0].segment
== NO_SEG
1584 && output_ins
.oprs
[0].wrt
== NO_SEG
1585 && (output_ins
.oprs
[1].type
& IMMEDIATE
)
1586 && output_ins
.oprs
[1].segment
== NO_SEG
1587 && output_ins
.oprs
[1].wrt
== NO_SEG
) {
1588 def_label(output_ins
.label
,
1589 output_ins
.oprs
[0].offset
| SEG_ABS
,
1590 output_ins
.oprs
[1].offset
,
1591 NULL
, false, false);
1593 nasm_error(ERR_NONFATAL
,
1594 "bad syntax for EQU");
1598 * Special `..' EQUs get processed here, except
1599 * `..@' macro processor EQUs which are done above.
1601 if (output_ins
.label
[0] == '.' &&
1602 output_ins
.label
[1] == '.' &&
1603 output_ins
.label
[2] != '@') {
1604 if (output_ins
.operands
== 1 &&
1605 (output_ins
.oprs
[0].type
& IMMEDIATE
)) {
1606 define_label(output_ins
.label
,
1607 output_ins
.oprs
[0].segment
,
1608 output_ins
.oprs
[0].offset
,
1609 NULL
, false, false);
1610 } else if (output_ins
.operands
== 2
1611 && (output_ins
.oprs
[0].type
& IMMEDIATE
)
1612 && (output_ins
.oprs
[0].type
& COLON
)
1613 && output_ins
.oprs
[0].segment
== NO_SEG
1614 && (output_ins
.oprs
[1].type
& IMMEDIATE
)
1615 && output_ins
.oprs
[1].segment
== NO_SEG
) {
1616 define_label(output_ins
.label
,
1617 output_ins
.oprs
[0].offset
| SEG_ABS
,
1618 output_ins
.oprs
[1].offset
,
1619 NULL
, false, false);
1621 nasm_error(ERR_NONFATAL
,
1622 "bad syntax for EQU");
1625 } else { /* instruction isn't an EQU */
1629 int64_t l
= insn_size(location
.segment
, offs
, sb
, cpu
,
1630 &output_ins
, nasm_error
);
1632 /* if (using_debug_info) && output_ins.opcode != -1) */
1633 if (using_debug_info
)
1634 { /* fbk 03/25/01 */
1635 /* this is done here so we can do debug type info */
1637 TYS_ELEMENTS(output_ins
.operands
);
1638 switch (output_ins
.opcode
) {
1641 TYS_ELEMENTS(output_ins
.oprs
[0].offset
) | TY_BYTE
;
1645 TYS_ELEMENTS(output_ins
.oprs
[0].offset
) | TY_WORD
;
1649 TYS_ELEMENTS(output_ins
.oprs
[0].offset
) | TY_DWORD
;
1653 TYS_ELEMENTS(output_ins
.oprs
[0].offset
) | TY_QWORD
;
1657 TYS_ELEMENTS(output_ins
.oprs
[0].offset
) | TY_TBYTE
;
1661 TYS_ELEMENTS(output_ins
.oprs
[0].offset
) | TY_OWORD
;
1665 TYS_ELEMENTS(output_ins
.oprs
[0].offset
) | TY_YWORD
;
1668 typeinfo
|= TY_BYTE
;
1671 typeinfo
|= TY_WORD
;
1674 if (output_ins
.eops_float
)
1675 typeinfo
|= TY_FLOAT
;
1677 typeinfo
|= TY_DWORD
;
1680 typeinfo
|= TY_QWORD
;
1683 typeinfo
|= TY_TBYTE
;
1686 typeinfo
|= TY_OWORD
;
1689 typeinfo
|= TY_YWORD
;
1692 typeinfo
= TY_LABEL
;
1696 dfmt
->debug_typevalue(typeinfo
);
1700 SET_CURR_OFFS(offs
);
1703 * else l == -1 => invalid instruction, which will be
1704 * flagged as an error on pass 2
1708 offs
+= assemble(location
.segment
, offs
, sb
, cpu
,
1709 &output_ins
, ofmt
, nasm_error
,
1711 SET_CURR_OFFS(offs
);
1715 cleanup_insn(&output_ins
);
1718 location
.offset
= offs
= GET_CURR_OFFS
;
1719 } /* end while (line = preproc->getline... */
1721 if (pass0
== 2 && global_offset_changed
&& !terminate_after_phase
)
1722 nasm_error(ERR_NONFATAL
,
1723 "phase error detected at end of assembly.");
1726 preproc
->cleanup(1);
1728 if ((passn
> 1 && !global_offset_changed
) || pass0
== 2) {
1730 } else if (global_offset_changed
&&
1731 global_offset_changed
< prev_offset_changed
) {
1732 prev_offset_changed
= global_offset_changed
;
1738 if (terminate_after_phase
)
1741 if ((stall_count
> 997) || (passn
>= pass_max
)) {
1742 /* We get here if the labels don't converge
1743 * Example: FOO equ FOO + 1
1745 nasm_error(ERR_NONFATAL
,
1746 "Can't find valid values for all labels "
1747 "after %d passes, giving up.", passn
);
1748 nasm_error(ERR_NONFATAL
,
1749 "Possible causes: recursive EQUs, macro abuse.");
1754 preproc
->cleanup(0);
1756 if (!terminate_after_phase
&& opt_verbose_info
) {
1757 /* -On and -Ov switches */
1758 fprintf(stdout
, "info: assembly required 1+%d+1 passes\n", passn
-3);
1762 static enum directives
getkw(char **directive
, char **value
)
1766 buf
= nasm_skip_spaces(*directive
);
1768 /* it should be enclosed in [ ] */
1771 q
= strchr(buf
, ']');
1775 /* stip off the comments */
1776 p
= strchr(buf
, ';');
1778 if (p
< q
) /* ouch! somwhere inside */
1783 /* no brace, no trailing spaces */
1785 nasm_zap_spaces_rev(--q
);
1788 p
= nasm_skip_spaces(++buf
);
1789 q
= nasm_skip_word(p
);
1791 return D_none
; /* sigh... no value there */
1795 /* and value finally */
1796 p
= nasm_skip_spaces(++q
);
1799 return find_directive(*directive
);
1803 * gnu style error reporting
1804 * This function prints an error message to error_file in the
1805 * style used by GNU. An example would be:
1806 * file.asm:50: error: blah blah blah
1807 * where file.asm is the name of the file, 50 is the line number on
1808 * which the error occurs (or is detected) and "error:" is one of
1809 * the possible optional diagnostics -- it can be "error" or "warning"
1810 * or something else. Finally the line terminates with the actual
1813 * @param severity the severity of the warning or error
1814 * @param fmt the printf style format string
1816 static void nasm_verror_gnu(int severity
, const char *fmt
, va_list ap
)
1818 char *currentfile
= NULL
;
1821 if (is_suppressed_warning(severity
))
1824 if (!(severity
& ERR_NOFILE
))
1825 src_get(&lineno
, ¤tfile
);
1828 fprintf(error_file
, "%s:%"PRId32
": ", currentfile
, lineno
);
1829 nasm_free(currentfile
);
1831 fputs("nasm: ", error_file
);
1834 nasm_verror_common(severity
, fmt
, ap
);
1838 * MS style error reporting
1839 * This function prints an error message to error_file in the
1840 * style used by Visual C and some other Microsoft tools. An example
1842 * file.asm(50) : error: blah blah blah
1843 * where file.asm is the name of the file, 50 is the line number on
1844 * which the error occurs (or is detected) and "error:" is one of
1845 * the possible optional diagnostics -- it can be "error" or "warning"
1846 * or something else. Finally the line terminates with the actual
1849 * @param severity the severity of the warning or error
1850 * @param fmt the printf style format string
1852 static void nasm_verror_vc(int severity
, const char *fmt
, va_list ap
)
1854 char *currentfile
= NULL
;
1857 if (is_suppressed_warning(severity
))
1860 if (!(severity
& ERR_NOFILE
))
1861 src_get(&lineno
, ¤tfile
);
1864 fprintf(error_file
, "%s(%"PRId32
") : ", currentfile
, lineno
);
1865 nasm_free(currentfile
);
1867 fputs("nasm: ", error_file
);
1870 nasm_verror_common(severity
, fmt
, ap
);
1874 * check for supressed warning
1875 * checks for suppressed warning or pass one only warning and we're
1878 * @param severity the severity of the warning or error
1879 * @return true if we should abort error/warning printing
1881 static bool is_suppressed_warning(int severity
)
1884 * See if it's a suppressed warning.
1886 return (severity
& ERR_MASK
) == ERR_WARNING
&&
1887 (((severity
& ERR_WARN_MASK
) != 0 &&
1888 !warning_on
[(severity
& ERR_WARN_MASK
) >> ERR_WARN_SHR
]) ||
1889 /* See if it's a pass-one only warning and we're not in pass one. */
1890 ((severity
& ERR_PASS1
) && pass0
!= 1) ||
1891 ((severity
& ERR_PASS2
) && pass0
!= 2));
1895 * common error reporting
1896 * This is the common back end of the error reporting schemes currently
1897 * implemented. It prints the nature of the warning and then the
1898 * specific error message to error_file and may or may not return. It
1899 * doesn't return if the error severity is a "panic" or "debug" type.
1901 * @param severity the severity of the warning or error
1902 * @param fmt the printf style format string
1904 static void nasm_verror_common(int severity
, const char *fmt
, va_list args
)
1909 switch (severity
& (ERR_MASK
|ERR_NO_SEVERITY
)) {
1930 vsnprintf(msg
, sizeof msg
, fmt
, args
);
1932 fprintf(error_file
, "%s%s\n", pfx
, msg
);
1935 nasmlist
.error(severity
, pfx
, msg
);
1937 if (severity
& ERR_USAGE
)
1940 switch (severity
& ERR_MASK
) {
1942 /* no further action, by definition */
1945 if (warning_on
[0]) /* Treat warnings as errors */
1946 terminate_after_phase
= true;
1949 terminate_after_phase
= true;
1959 exit(1); /* instantly die */
1960 break; /* placate silly compilers */
1963 /* abort(); *//* halt, catch fire, and dump core */
1969 static void usage(void)
1971 fputs("type `nasm -h' for help\n", error_file
);
1974 #define BUF_DELTA 512
1976 static FILE *no_pp_fp
;
1977 static ListGen
*no_pp_list
;
1978 static int32_t no_pp_lineinc
;
1980 static void no_pp_reset(char *file
, int pass
, ListGen
* listgen
,
1983 src_set_fname(nasm_strdup(file
));
1986 no_pp_fp
= fopen(file
, "r");
1988 nasm_error(ERR_FATAL
| ERR_NOFILE
,
1989 "unable to open input file `%s'", file
);
1990 no_pp_list
= listgen
;
1991 (void)pass
; /* placate compilers */
1994 StrList
*sl
= nasm_malloc(strlen(file
)+1+sizeof sl
->next
);
1996 strcpy(sl
->str
, file
);
2001 static char *no_pp_getline(void)
2003 char *buffer
, *p
, *q
;
2006 bufsize
= BUF_DELTA
;
2007 buffer
= nasm_malloc(BUF_DELTA
);
2008 src_set_linnum(src_get_linnum() + no_pp_lineinc
);
2010 while (1) { /* Loop to handle %line */
2013 while (1) { /* Loop to handle long lines */
2014 q
= fgets(p
, bufsize
- (p
- buffer
), no_pp_fp
);
2018 if (p
> buffer
&& p
[-1] == '\n')
2020 if (p
- buffer
> bufsize
- 10) {
2022 offset
= p
- buffer
;
2023 bufsize
+= BUF_DELTA
;
2024 buffer
= nasm_realloc(buffer
, bufsize
);
2025 p
= buffer
+ offset
;
2029 if (!q
&& p
== buffer
) {
2035 * Play safe: remove CRs, LFs and any spurious ^Zs, if any of
2036 * them are present at the end of the line.
2038 buffer
[strcspn(buffer
, "\r\n\032")] = '\0';
2040 if (!nasm_strnicmp(buffer
, "%line", 5)) {
2043 char *nm
= nasm_malloc(strlen(buffer
));
2044 if (sscanf(buffer
+ 5, "%"PRId32
"+%d %s", &ln
, &li
, nm
) == 3) {
2045 nasm_free(src_set_fname(nm
));
2055 no_pp_list
->line(LIST_READ
, buffer
);
2060 static void no_pp_cleanup(int pass
)
2062 (void)pass
; /* placate GCC */
2066 static uint32_t get_cpu(char *value
)
2068 if (!strcmp(value
, "8086"))
2070 if (!strcmp(value
, "186"))
2072 if (!strcmp(value
, "286"))
2074 if (!strcmp(value
, "386"))
2076 if (!strcmp(value
, "486"))
2078 if (!strcmp(value
, "586") || !nasm_stricmp(value
, "pentium"))
2080 if (!strcmp(value
, "686") ||
2081 !nasm_stricmp(value
, "ppro") ||
2082 !nasm_stricmp(value
, "pentiumpro") || !nasm_stricmp(value
, "p2"))
2084 if (!nasm_stricmp(value
, "p3") || !nasm_stricmp(value
, "katmai"))
2086 if (!nasm_stricmp(value
, "p4") || /* is this right? -- jrc */
2087 !nasm_stricmp(value
, "willamette"))
2088 return IF_WILLAMETTE
;
2089 if (!nasm_stricmp(value
, "prescott"))
2091 if (!nasm_stricmp(value
, "x64") ||
2092 !nasm_stricmp(value
, "x86-64"))
2094 if (!nasm_stricmp(value
, "ia64") ||
2095 !nasm_stricmp(value
, "ia-64") ||
2096 !nasm_stricmp(value
, "itanium") ||
2097 !nasm_stricmp(value
, "itanic") || !nasm_stricmp(value
, "merced"))
2100 nasm_error(pass0
< 2 ? ERR_NONFATAL
: ERR_FATAL
,
2101 "unknown 'cpu' type");
2103 return IF_PLEVEL
; /* the maximum level */
2106 static int get_bits(char *value
)
2110 if ((i
= atoi(value
)) == 16)
2111 return i
; /* set for a 16-bit segment */
2114 nasm_error(ERR_NONFATAL
,
2115 "cannot specify 32-bit segment on processor below a 386");
2118 } else if (i
== 64) {
2119 if (cpu
< IF_X86_64
) {
2120 nasm_error(ERR_NONFATAL
,
2121 "cannot specify 64-bit segment on processor below an x86-64");
2125 nasm_error(ERR_NONFATAL
,
2126 "%s output format does not support 64-bit code",
2131 nasm_error(pass0
< 2 ? ERR_NONFATAL
: ERR_FATAL
,
2132 "`%s' is not a valid segment size; must be 16, 32 or 64",