1 /* ----------------------------------------------------------------------- *
3 * Copyright 1996-2012 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"
65 * This is the maximum number of optimization passes to do. If we ever
66 * find a case where the optimizer doesn't naturally converge, we might
67 * have to drop this value so the assembler doesn't appear to just hang.
69 #define MAX_OPTIMIZE (INT_MAX >> 1)
71 struct forwrefinfo
{ /* info held on forward refs. */
76 static int get_bits(char *value
);
77 static uint32_t get_cpu(char *cpu_str
);
78 static void parse_cmdline(int, char **);
79 static void assemble_file(char *, StrList
**);
80 static void nasm_verror_gnu(int severity
, const char *fmt
, va_list args
);
81 static void nasm_verror_vc(int severity
, const char *fmt
, va_list args
);
82 static void nasm_verror_common(int severity
, const char *fmt
, va_list args
);
83 static bool is_suppressed_warning(int severity
);
84 static void usage(void);
86 static int using_debug_info
, opt_verbose_info
;
87 bool tasm_compatible_mode
= false;
92 static time_t official_compile_time
;
94 static char inname
[FILENAME_MAX
];
95 static char outname
[FILENAME_MAX
];
96 static char listname
[FILENAME_MAX
];
97 static char errname
[FILENAME_MAX
];
98 static int globallineno
; /* for forward-reference tracking */
99 /* static int pass = 0; */
100 struct ofmt
*ofmt
= &OF_DEFAULT
;
101 struct ofmt_alias
*ofmt_alias
= NULL
;
102 const struct dfmt
*dfmt
;
104 static FILE *error_file
; /* Where to write error messages */
107 int optimizing
= MAX_OPTIMIZE
; /* number of optimization passes to take */
108 static int sb
, cmd_sb
= 16; /* by default */
109 static uint32_t cmd_cpu
= IF_PLEVEL
; /* highest level by default */
110 static uint32_t cpu
= IF_PLEVEL
; /* passed to insn_size & assemble.c */
111 int64_t global_offset_changed
; /* referenced in labels.c */
112 int64_t prev_offset_changed
;
115 static struct location location
;
116 int in_abs_seg
; /* Flag we are in ABSOLUTE seg */
117 int32_t abs_seg
; /* ABSOLUTE segment basis */
118 int32_t abs_offset
; /* ABSOLUTE offset */
120 static struct RAA
*offsets
;
122 static struct SAA
*forwrefs
; /* keep track of forward references */
123 static const struct forwrefinfo
*forwref
;
125 static struct preproc_ops
*preproc
;
128 op_normal
, /* Preprocess and assemble */
129 op_preprocess
, /* Preprocess only */
130 op_depend
, /* Generate dependencies */
132 static enum op_type operating_mode
;
133 /* Dependency flags */
134 static bool depend_emit_phony
= false;
135 static bool depend_missing_ok
= false;
136 static const char *depend_target
= NULL
;
137 static const char *depend_file
= NULL
;
140 * Which of the suppressible warnings are suppressed. Entry zero
141 * isn't an actual warning, but it used for -w+error/-Werror.
144 static bool warning_on
[ERR_WARN_MAX
+1]; /* Current state */
145 static bool warning_on_global
[ERR_WARN_MAX
+1]; /* Command-line state */
147 static const struct warning
{
151 } warnings
[ERR_WARN_MAX
+1] = {
152 {"error", "treat warnings as errors", false},
153 {"macro-params", "macro calls with wrong parameter count", true},
154 {"macro-selfref", "cyclic macro references", false},
155 {"macro-defaults", "macros with more default than optional parameters", true},
156 {"orphan-labels", "labels alone on lines without trailing `:'", true},
157 {"number-overflow", "numeric constant does not fit", true},
158 {"gnu-elf-extensions", "using 8- or 16-bit relocation in ELF32, a GNU extension", false},
159 {"float-overflow", "floating point overflow", true},
160 {"float-denorm", "floating point denormal", false},
161 {"float-underflow", "floating point underflow", false},
162 {"float-toolong", "too many digits in floating-point number", true},
163 {"user", "%warning directives", true},
164 {"lock", "lock prefix on unlockable instructions", true},
165 {"hle", "invalid hle prefixes", true},
169 * get/set current offset...
171 #define GET_CURR_OFFS (in_abs_seg?abs_offset:\
172 raa_read(offsets,location.segment))
173 #define SET_CURR_OFFS(x) (in_abs_seg?(void)(abs_offset=(x)):\
174 (void)(offsets=raa_write(offsets,location.segment,(x))))
176 static bool want_usage
;
177 static bool terminate_after_phase
;
178 int user_nolist
= 0; /* fbk 9/2/00 */
180 static void nasm_fputs(const char *line
, FILE * outfile
)
183 fputs(line
, outfile
);
189 /* Convert a struct tm to a POSIX-style time constant */
190 static int64_t posix_mktime(struct tm
*tm
)
193 int64_t y
= tm
->tm_year
;
195 /* See IEEE 1003.1:2004, section 4.14 */
197 t
= (y
-70)*365 + (y
-69)/4 - (y
-1)/100 + (y
+299)/400;
209 static void define_macros_early(void)
212 struct tm lt
, *lt_p
, gm
, *gm_p
;
215 lt_p
= localtime(&official_compile_time
);
219 strftime(temp
, sizeof temp
, "__DATE__=\"%Y-%m-%d\"", <
);
220 preproc
->pre_define(temp
);
221 strftime(temp
, sizeof temp
, "__DATE_NUM__=%Y%m%d", <
);
222 preproc
->pre_define(temp
);
223 strftime(temp
, sizeof temp
, "__TIME__=\"%H:%M:%S\"", <
);
224 preproc
->pre_define(temp
);
225 strftime(temp
, sizeof temp
, "__TIME_NUM__=%H%M%S", <
);
226 preproc
->pre_define(temp
);
229 gm_p
= gmtime(&official_compile_time
);
233 strftime(temp
, sizeof temp
, "__UTC_DATE__=\"%Y-%m-%d\"", &gm
);
234 preproc
->pre_define(temp
);
235 strftime(temp
, sizeof temp
, "__UTC_DATE_NUM__=%Y%m%d", &gm
);
236 preproc
->pre_define(temp
);
237 strftime(temp
, sizeof temp
, "__UTC_TIME__=\"%H:%M:%S\"", &gm
);
238 preproc
->pre_define(temp
);
239 strftime(temp
, sizeof temp
, "__UTC_TIME_NUM__=%H%M%S", &gm
);
240 preproc
->pre_define(temp
);
244 posix_time
= posix_mktime(&gm
);
246 posix_time
= posix_mktime(<
);
251 snprintf(temp
, sizeof temp
, "__POSIX_TIME__=%"PRId64
, posix_time
);
252 preproc
->pre_define(temp
);
256 static void define_macros_late(void)
261 * In case if output format is defined by alias
262 * we have to put shortname of the alias itself here
263 * otherwise ABI backward compatibility gets broken.
265 snprintf(temp
, sizeof(temp
), "__OUTPUT_FORMAT__=%s",
266 ofmt_alias
? ofmt_alias
->shortname
: ofmt
->shortname
);
267 preproc
->pre_define(temp
);
270 static void emit_dependencies(StrList
*list
)
276 if (depend_file
&& strcmp(depend_file
, "-")) {
277 deps
= fopen(depend_file
, "w");
279 nasm_error(ERR_NONFATAL
|ERR_NOFILE
|ERR_USAGE
,
280 "unable to write dependency file `%s'", depend_file
);
287 linepos
= fprintf(deps
, "%s:", depend_target
);
288 list_for_each(l
, list
) {
289 len
= strlen(l
->str
);
290 if (linepos
+ len
> 62) {
291 fprintf(deps
, " \\\n ");
294 fprintf(deps
, " %s", l
->str
);
297 fprintf(deps
, "\n\n");
299 list_for_each_safe(l
, nl
, list
) {
300 if (depend_emit_phony
)
301 fprintf(deps
, "%s:\n\n", l
->str
);
309 int main(int argc
, char **argv
)
311 StrList
*depend_list
= NULL
, **depend_ptr
;
313 time(&official_compile_time
);
316 want_usage
= terminate_after_phase
= false;
317 nasm_set_verror(nasm_verror_gnu
);
323 nasm_init_malloc_error();
324 offsets
= raa_init();
325 forwrefs
= saa_init((int32_t)sizeof(struct forwrefinfo
));
328 operating_mode
= op_normal
;
332 /* Define some macros dependent on the runtime, but not
333 on the command line. */
334 define_macros_early();
336 parse_cmdline(argc
, argv
);
338 if (terminate_after_phase
) {
344 /* If debugging info is disabled, suppress any debug calls */
345 if (!using_debug_info
)
346 ofmt
->current_dfmt
= &null_debug_form
;
349 preproc
->extra_stdmac(ofmt
->stdmac
);
350 parser_global_info(&location
);
351 eval_global_info(ofmt
, lookup_label
, &location
);
353 /* define some macros dependent of command-line */
354 define_macros_late();
356 depend_ptr
= (depend_file
|| (operating_mode
== op_depend
))
357 ? &depend_list
: NULL
;
359 depend_target
= outname
;
361 switch (operating_mode
) {
366 if (depend_missing_ok
)
367 preproc
->include_path(NULL
); /* "assume generated" */
369 preproc
->reset(inname
, 0, &nasmlist
, depend_ptr
);
370 if (outname
[0] == '\0')
371 ofmt
->filename(inname
, outname
);
373 while ((line
= preproc
->getline()))
382 char *file_name
= NULL
;
383 int32_t prior_linnum
= 0;
387 ofile
= fopen(outname
, "w");
389 nasm_error(ERR_FATAL
| ERR_NOFILE
,
390 "unable to open output file `%s'",
395 location
.known
= false;
398 preproc
->reset(inname
, 3, &nasmlist
, depend_ptr
);
399 memcpy(warning_on
, warning_on_global
, (ERR_WARN_MAX
+1) * sizeof(bool));
401 while ((line
= preproc
->getline())) {
403 * We generate %line directives if needed for later programs
405 int32_t linnum
= prior_linnum
+= lineinc
;
406 int altline
= src_get(&linnum
, &file_name
);
408 if (altline
== 1 && lineinc
== 1)
409 nasm_fputs("", ofile
);
411 lineinc
= (altline
!= -1 || lineinc
!= 1);
412 fprintf(ofile
? ofile
: stdout
,
413 "%%line %"PRId32
"+%d %s\n", linnum
, lineinc
,
416 prior_linnum
= linnum
;
418 nasm_fputs(line
, ofile
);
421 nasm_free(file_name
);
425 if (ofile
&& terminate_after_phase
)
434 * We must call ofmt->filename _anyway_, even if the user
435 * has specified their own output file, because some
436 * formats (eg OBJ and COFF) use ofmt->filename to find out
437 * the name of the input file and then put that inside the
440 ofmt
->filename(inname
, outname
);
442 ofile
= fopen(outname
, (ofmt
->flags
& OFMT_TEXT
) ? "w" : "wb");
444 nasm_error(ERR_FATAL
| ERR_NOFILE
,
445 "unable to open output file `%s'", outname
);
449 * We must call init_labels() before ofmt->init() since
450 * some object formats will want to define labels in their
451 * init routines. (eg OS/2 defines the FLAT group)
456 dfmt
= ofmt
->current_dfmt
;
459 assemble_file(inname
, depend_ptr
);
461 if (!terminate_after_phase
) {
462 ofmt
->cleanup(using_debug_info
);
466 nasm_error(ERR_NONFATAL
|ERR_NOFILE
,
467 "write error on output file `%s'", outname
);
473 if (terminate_after_phase
)
481 if (depend_list
&& !terminate_after_phase
)
482 emit_dependencies(depend_list
);
492 return terminate_after_phase
;
496 * Get a parameter for a command line option.
497 * First arg must be in the form of e.g. -f...
499 static char *get_param(char *p
, char *q
, bool *advance
)
502 if (p
[2]) /* the parameter's in the option */
503 return nasm_skip_spaces(p
+ 2);
508 nasm_error(ERR_NONFATAL
| ERR_NOFILE
| ERR_USAGE
,
509 "option `-%c' requires an argument", p
[1]);
516 static void copy_filename(char *dst
, const char *src
)
518 size_t len
= strlen(src
);
520 if (len
>= (size_t)FILENAME_MAX
) {
521 nasm_error(ERR_FATAL
| ERR_NOFILE
, "file name too long");
524 strncpy(dst
, src
, FILENAME_MAX
);
528 * Convert a string to Make-safe form
530 static char *quote_for_make(const char *str
)
535 size_t n
= 1; /* Terminating zero */
541 for (p
= str
; *p
; p
++) {
545 /* Convert N backslashes + ws -> 2N+1 backslashes + ws */
565 /* Convert N backslashes at the end of filename to 2N backslashes */
569 os
= q
= nasm_malloc(n
);
572 for (p
= str
; *p
; p
++) {
615 #define OPT_POSTFIX 1
616 struct textargs textopts
[] = {
617 {"prefix", OPT_PREFIX
},
618 {"postfix", OPT_POSTFIX
},
622 static bool stopoptions
= false;
623 static bool process_arg(char *p
, char *q
)
627 bool advance
= false;
633 if (p
[0] == '-' && !stopoptions
) {
634 if (strchr("oOfpPdDiIlFXuUZwW", p
[1])) {
635 /* These parameters take values */
636 if (!(param
= get_param(p
, q
, &advance
)))
645 case 'o': /* output file */
646 copy_filename(outname
, param
);
649 case 'f': /* output format */
650 ofmt
= ofmt_find(param
, &ofmt_alias
);
652 nasm_error(ERR_FATAL
| ERR_NOFILE
| ERR_USAGE
,
653 "unrecognised output format `%s' - "
654 "use -hf for a list", param
);
658 case 'O': /* Optimization level */
663 /* Naked -O == -Ox */
664 optimizing
= MAX_OPTIMIZE
;
668 case '0': case '1': case '2': case '3': case '4':
669 case '5': case '6': case '7': case '8': case '9':
670 opt
= strtoul(param
, ¶m
, 10);
672 /* -O0 -> optimizing == -1, 0.98 behaviour */
673 /* -O1 -> optimizing == 0, 0.98.09 behaviour */
675 optimizing
= opt
- 1;
683 opt_verbose_info
= true;
688 optimizing
= MAX_OPTIMIZE
;
692 nasm_error(ERR_FATAL
,
693 "unknown optimization option -O%c\n",
698 if (optimizing
> MAX_OPTIMIZE
)
699 optimizing
= MAX_OPTIMIZE
;
704 case 'p': /* pre-include */
706 preproc
->pre_include(param
);
709 case 'd': /* pre-define */
711 preproc
->pre_define(param
);
714 case 'u': /* un-define */
716 preproc
->pre_undefine(param
);
719 case 'i': /* include search path */
721 preproc
->include_path(param
);
724 case 'l': /* listing file */
725 copy_filename(listname
, param
);
728 case 'Z': /* error messages file */
729 copy_filename(errname
, param
);
732 case 'F': /* specify debug format */
733 ofmt
->current_dfmt
= dfmt_find(ofmt
, param
);
734 if (!ofmt
->current_dfmt
) {
735 nasm_error(ERR_FATAL
| ERR_NOFILE
| ERR_USAGE
,
736 "unrecognized debug format `%s' for"
737 " output format `%s'",
738 param
, ofmt
->shortname
);
740 using_debug_info
= true;
743 case 'X': /* specify error reporting format */
744 if (nasm_stricmp("vc", param
) == 0)
745 nasm_set_verror(nasm_verror_vc
);
746 else if (nasm_stricmp("gnu", param
) == 0)
747 nasm_set_verror(nasm_verror_gnu
);
749 nasm_error(ERR_FATAL
| ERR_NOFILE
| ERR_USAGE
,
750 "unrecognized error reporting format `%s'",
755 using_debug_info
= true;
760 ("usage: nasm [-@ response file] [-o outfile] [-f format] "
762 " [options...] [--] filename\n"
763 " or nasm -v for version info\n\n"
764 " -t assemble in SciTech TASM compatible mode\n"
765 " -g generate debug information in selected format\n");
767 (" -E (or -e) preprocess only (writes output to stdout by default)\n"
768 " -a don't preprocess (assemble only)\n"
769 " -M generate Makefile dependencies on stdout\n"
770 " -MG d:o, missing files assumed generated\n"
771 " -MF <file> set Makefile dependency file\n"
772 " -MD <file> assemble and generate dependencies\n"
773 " -MT <file> dependency target name\n"
774 " -MQ <file> dependency target name (quoted)\n"
775 " -MP emit phony target\n\n"
776 " -Z<file> redirect error messages to file\n"
777 " -s redirect error messages to stdout\n\n"
778 " -F format select a debugging format\n\n"
779 " -I<path> adds a pathname to the include file path\n");
781 (" -O<digit> optimize branch offsets\n"
782 " -O0: No optimization\n"
783 " -O1: Minimal optimization\n"
784 " -Ox: Multipass optimization (default)\n\n"
785 " -P<file> pre-includes a file\n"
786 " -D<macro>[=<value>] pre-defines a macro\n"
787 " -U<macro> undefines a macro\n"
788 " -X<format> specifies error reporting format (gnu or vc)\n"
789 " -w+foo enables warning foo (equiv. -Wfoo)\n"
790 " -w-foo disable warning foo (equiv. -Wno-foo)\n\n"
791 "--prefix,--postfix\n"
792 " this options prepend or append the given argument to all\n"
793 " extern and global variables\n\n"
795 for (i
= 0; i
<= ERR_WARN_MAX
; i
++)
796 printf(" %-23s %s (default %s)\n",
797 warnings
[i
].name
, warnings
[i
].help
,
798 warnings
[i
].enabled
? "on" : "off");
800 ("\nresponse files should contain command line parameters"
801 ", one per line.\n");
803 printf("\nvalid output formats for -f are"
804 " (`*' denotes default):\n");
805 ofmt_list(ofmt
, stdout
);
807 printf("\nFor a list of valid output formats, use -hf.\n");
808 printf("For a list of debug formats, use -f <form> -y.\n");
810 exit(0); /* never need usage message here */
814 printf("\nvalid debug formats for '%s' output format are"
815 " ('*' denotes default):\n", ofmt
->shortname
);
816 dfmt_list(ofmt
, stdout
);
821 tasm_compatible_mode
= true;
825 printf("NASM version %s compiled on %s%s\n",
826 nasm_version
, nasm_date
, nasm_compile_options
);
827 exit(0); /* never need usage message here */
830 case 'e': /* preprocess only */
832 operating_mode
= op_preprocess
;
835 case 'a': /* assemble only - don't preprocess */
836 preproc
= &preproc_nop
;
840 if (param
[0] == 'n' && param
[1] == 'o' && param
[2] == '-') {
849 if (param
[0] != '+' && param
[0] != '-') {
850 nasm_error(ERR_NONFATAL
| ERR_NOFILE
| ERR_USAGE
,
851 "invalid option to `-w'");
854 do_warn
= (param
[0] == '+');
858 for (i
= 0; i
<= ERR_WARN_MAX
; i
++) {
859 if (!nasm_stricmp(param
, warnings
[i
].name
))
862 if (i
<= ERR_WARN_MAX
) {
863 warning_on_global
[i
] = do_warn
;
864 } else if (!nasm_stricmp(param
, "all")) {
865 for (i
= 1; i
<= ERR_WARN_MAX
; i
++)
866 warning_on_global
[i
] = do_warn
;
867 } else if (!nasm_stricmp(param
, "none")) {
868 for (i
= 1; i
<= ERR_WARN_MAX
; i
++)
869 warning_on_global
[i
] = !do_warn
;
871 nasm_error(ERR_NONFATAL
| ERR_NOFILE
| ERR_USAGE
,
872 "invalid warning `%s'", param
);
879 operating_mode
= op_depend
;
882 operating_mode
= op_depend
;
883 depend_missing_ok
= true;
886 depend_emit_phony
= true;
897 depend_target
= quote_for_make(q
);
901 nasm_error(ERR_NONFATAL
|ERR_NOFILE
|ERR_USAGE
,
902 "unknown dependency option `-M%c'", p
[2]);
905 if (advance
&& (!q
|| !q
[0])) {
906 nasm_error(ERR_NONFATAL
|ERR_NOFILE
|ERR_USAGE
,
907 "option `-M%c' requires a parameter", p
[2]);
916 if (p
[2] == 0) { /* -- => stop processing options */
920 for (s
= 0; textopts
[s
].label
; s
++) {
921 if (!nasm_stricmp(p
+ 2, textopts
[s
].label
)) {
932 nasm_error(ERR_NONFATAL
| ERR_NOFILE
|
934 "option `--%s' requires an argument",
938 advance
= 1, param
= q
;
941 if (s
== OPT_PREFIX
) {
942 strncpy(lprefix
, param
, PREFIX_MAX
- 1);
943 lprefix
[PREFIX_MAX
- 1] = 0;
946 if (s
== OPT_POSTFIX
) {
947 strncpy(lpostfix
, param
, POSTFIX_MAX
- 1);
948 lpostfix
[POSTFIX_MAX
- 1] = 0;
955 nasm_error(ERR_NONFATAL
| ERR_NOFILE
| ERR_USAGE
,
956 "unrecognised option `--%s'", p
+ 2);
964 if (!ofmt
->setinfo(GI_SWITCH
, &p
))
965 nasm_error(ERR_NONFATAL
| ERR_NOFILE
| ERR_USAGE
,
966 "unrecognised option `-%c'", p
[1]);
971 nasm_error(ERR_NONFATAL
| ERR_NOFILE
| ERR_USAGE
,
972 "more than one input file specified");
974 copy_filename(inname
, p
);
981 #define ARG_BUF_DELTA 128
983 static void process_respfile(FILE * rfile
)
985 char *buffer
, *p
, *q
, *prevarg
;
986 int bufsize
, prevargsize
;
988 bufsize
= prevargsize
= ARG_BUF_DELTA
;
989 buffer
= nasm_malloc(ARG_BUF_DELTA
);
990 prevarg
= nasm_malloc(ARG_BUF_DELTA
);
993 while (1) { /* Loop to handle all lines in file */
995 while (1) { /* Loop to handle long lines */
996 q
= fgets(p
, bufsize
- (p
- buffer
), rfile
);
1000 if (p
> buffer
&& p
[-1] == '\n')
1002 if (p
- buffer
> bufsize
- 10) {
1004 offset
= p
- buffer
;
1005 bufsize
+= ARG_BUF_DELTA
;
1006 buffer
= nasm_realloc(buffer
, bufsize
);
1007 p
= buffer
+ offset
;
1011 if (!q
&& p
== buffer
) {
1013 process_arg(prevarg
, NULL
);
1020 * Play safe: remove CRs, LFs and any spurious ^Zs, if any of
1021 * them are present at the end of the line.
1023 *(p
= &buffer
[strcspn(buffer
, "\r\n\032")]) = '\0';
1025 while (p
> buffer
&& nasm_isspace(p
[-1]))
1028 p
= nasm_skip_spaces(buffer
);
1030 if (process_arg(prevarg
, p
))
1033 if ((int) strlen(p
) > prevargsize
- 10) {
1034 prevargsize
+= ARG_BUF_DELTA
;
1035 prevarg
= nasm_realloc(prevarg
, prevargsize
);
1037 strncpy(prevarg
, p
, prevargsize
);
1041 /* Function to process args from a string of args, rather than the
1042 * argv array. Used by the environment variable and response file
1045 static void process_args(char *args
)
1047 char *p
, *q
, *arg
, *prevarg
;
1048 char separator
= ' ';
1051 if (*p
&& *p
!= '-')
1056 while (*p
&& *p
!= separator
)
1058 while (*p
== separator
)
1062 if (process_arg(prevarg
, arg
))
1066 process_arg(arg
, NULL
);
1069 static void process_response_file(const char *file
)
1072 FILE *f
= fopen(file
, "r");
1077 while (fgets(str
, sizeof str
, f
)) {
1083 static void parse_cmdline(int argc
, char **argv
)
1086 char *envreal
, *envcopy
= NULL
, *p
;
1089 *inname
= *outname
= *listname
= *errname
= '\0';
1091 for (i
= 0; i
<= ERR_WARN_MAX
; i
++)
1092 warning_on_global
[i
] = warnings
[i
].enabled
;
1095 * First, process the NASMENV environment variable.
1097 envreal
= getenv("NASMENV");
1099 envcopy
= nasm_strdup(envreal
);
1100 process_args(envcopy
);
1105 * Now process the actual command line.
1110 if (argv
[0][0] == '@') {
1112 * We have a response file, so process this as a set of
1113 * arguments like the environment variable. This allows us
1114 * to have multiple arguments on a single line, which is
1115 * different to the -@resp file processing below for regular
1118 process_response_file(argv
[0]+1);
1122 if (!stopoptions
&& argv
[0][0] == '-' && argv
[0][1] == '@') {
1123 p
= get_param(argv
[0], argc
> 1 ? argv
[1] : NULL
, &advance
);
1125 rfile
= fopen(p
, "r");
1127 process_respfile(rfile
);
1130 nasm_error(ERR_NONFATAL
| ERR_NOFILE
| ERR_USAGE
,
1131 "unable to open response file `%s'", p
);
1134 advance
= process_arg(argv
[0], argc
> 1 ? argv
[1] : NULL
);
1135 argv
+= advance
, argc
-= advance
;
1139 * Look for basic command line typos. This definitely doesn't
1140 * catch all errors, but it might help cases of fumbled fingers.
1143 nasm_error(ERR_NONFATAL
| ERR_NOFILE
| ERR_USAGE
,
1144 "no input file specified");
1145 else if (!strcmp(inname
, errname
) ||
1146 !strcmp(inname
, outname
) ||
1147 !strcmp(inname
, listname
) ||
1148 (depend_file
&& !strcmp(inname
, depend_file
)))
1149 nasm_error(ERR_FATAL
| ERR_NOFILE
| ERR_USAGE
,
1150 "file `%s' is both input and output file",
1154 error_file
= fopen(errname
, "w");
1156 error_file
= stderr
; /* Revert to default! */
1157 nasm_error(ERR_FATAL
| ERR_NOFILE
| ERR_USAGE
,
1158 "cannot open file `%s' for error messages",
1164 static enum directives
getkw(char **directive
, char **value
);
1166 static void assemble_file(char *fname
, StrList
**depend_ptr
)
1168 char *directive
, *value
, *p
, *q
, *special
, *line
;
1174 struct tokenval tokval
;
1178 if (cmd_sb
== 32 && cmd_cpu
< IF_386
)
1179 nasm_error(ERR_FATAL
, "command line: "
1180 "32-bit segment size requires a higher cpu");
1182 pass_max
= prev_offset_changed
= (INT_MAX
>> 1) + 2; /* Almost unlimited */
1183 for (passn
= 1; pass0
<= 2; passn
++) {
1187 pass1
= pass0
== 2 ? 2 : 1; /* 1, 1, 1, ..., 1, 2 */
1188 pass2
= passn
> 1 ? 2 : 1; /* 1, 2, 2, ..., 2, 2 */
1189 /* pass0 0, 0, 0, ..., 1, 2 */
1191 def_label
= passn
> 1 ? redefine_label
: define_label
;
1193 globalbits
= sb
= cmd_sb
; /* set 'bits' to command line default */
1197 nasmlist
.init(listname
, nasm_error
);
1200 global_offset_changed
= 0; /* set by redefine_label */
1201 location
.segment
= ofmt
->section(NULL
, pass2
, &sb
);
1204 saa_rewind(forwrefs
);
1205 forwref
= saa_rstruct(forwrefs
);
1207 offsets
= raa_init();
1209 preproc
->reset(fname
, pass1
, &nasmlist
,
1210 pass1
== 2 ? depend_ptr
: NULL
);
1211 memcpy(warning_on
, warning_on_global
, (ERR_WARN_MAX
+1) * sizeof(bool));
1215 location
.known
= true;
1216 location
.offset
= offs
= GET_CURR_OFFS
;
1218 while ((line
= preproc
->getline())) {
1223 * Here we parse our directives; this is not handled by the
1224 * 'real' parser. This really should be a separate function.
1227 d
= getkw(&directive
, &value
);
1232 case D_SEGMENT
: /* [SEGMENT n] */
1234 seg
= ofmt
->section(value
, pass2
, &sb
);
1235 if (seg
== NO_SEG
) {
1236 nasm_error(pass1
== 1 ? ERR_NONFATAL
: ERR_PANIC
,
1237 "segment name `%s' not recognized",
1241 location
.segment
= seg
;
1244 case D_SECTALIGN
: /* [SECTALIGN n] */
1248 tokval
.t_type
= TOKEN_INVALID
;
1249 e
= evaluate(stdscan
, NULL
, &tokval
, NULL
, pass2
, nasm_error
, NULL
);
1251 unsigned int align
= (unsigned int)e
->value
;
1252 if ((uint64_t)e
->value
> 0x7fffffff) {
1254 * FIXME: Please make some sane message here
1255 * ofmt should have some 'check' method which
1256 * would report segment alignment bounds.
1258 nasm_error(ERR_FATAL
,
1259 "incorrect segment alignment `%s'", value
);
1260 } else if (!is_power2(align
)) {
1261 nasm_error(ERR_NONFATAL
,
1262 "segment alignment `%s' is not power of two",
1265 /* callee should be able to handle all details */
1266 ofmt
->sectalign(location
.segment
, align
);
1270 case D_EXTERN
: /* [EXTERN label:special] */
1272 value
++; /* skip initial $ if present */
1275 while (*q
&& *q
!= ':')
1279 ofmt
->symdef(value
, 0L, 0L, 3, q
);
1281 } else if (passn
== 1) {
1286 while (*q
&& *q
!= ':') {
1292 nasm_error(ERR_NONFATAL
,
1293 "identifier expected after EXTERN");
1301 if (!is_extern(value
)) { /* allow re-EXTERN to be ignored */
1303 pass0
= 1; /* fake pass 1 in labels.c */
1304 declare_as_global(value
, special
);
1305 define_label(value
, seg_alloc(), 0L, NULL
,
1309 } /* else pass0 == 1 */
1311 case D_BITS
: /* [BITS bits] */
1312 globalbits
= sb
= get_bits(value
);
1314 case D_GLOBAL
: /* [GLOBAL symbol:special] */
1316 value
++; /* skip initial $ if present */
1317 if (pass0
== 2) { /* pass 2 */
1319 while (*q
&& *q
!= ':')
1323 ofmt
->symdef(value
, 0L, 0L, 3, q
);
1325 } else if (pass2
== 1) { /* pass == 1 */
1330 while (*q
&& *q
!= ':') {
1336 nasm_error(ERR_NONFATAL
,
1337 "identifier expected after GLOBAL");
1345 declare_as_global(value
, special
);
1348 case D_COMMON
: /* [COMMON symbol size:special] */
1353 value
++; /* skip initial $ if present */
1358 while (*p
&& !nasm_isspace(*p
)) {
1364 nasm_error(ERR_NONFATAL
,
1365 "identifier expected after COMMON");
1369 p
= nasm_zap_spaces_fwd(p
);
1371 while (*q
&& *q
!= ':')
1379 size
= readnum(p
, &rn_error
);
1381 nasm_error(ERR_NONFATAL
,
1382 "invalid size specified"
1383 " in COMMON declaration");
1387 nasm_error(ERR_NONFATAL
,
1388 "no size specified in"
1389 " COMMON declaration");
1394 define_common(value
, seg_alloc(), size
, special
);
1395 } else if (pass0
== 2) {
1397 ofmt
->symdef(value
, 0L, 0L, 3, special
);
1401 case D_ABSOLUTE
: /* [ABSOLUTE address] */
1404 tokval
.t_type
= TOKEN_INVALID
;
1405 e
= evaluate(stdscan
, NULL
, &tokval
, NULL
, pass2
,
1410 1 ? ERR_NONFATAL
: ERR_PANIC
,
1411 "cannot use non-relocatable expression as "
1412 "ABSOLUTE address");
1414 abs_seg
= reloc_seg(e
);
1415 abs_offset
= reloc_value(e
);
1417 } else if (passn
== 1)
1418 abs_offset
= 0x100; /* don't go near zero in case of / */
1420 nasm_error(ERR_PANIC
, "invalid ABSOLUTE address "
1423 location
.segment
= NO_SEG
;
1425 case D_DEBUG
: /* [DEBUG] */
1428 bool badid
, overlong
;
1432 badid
= overlong
= false;
1433 if (!isidstart(*p
)) {
1436 while (*p
&& !nasm_isspace(*p
)) {
1437 if (q
>= debugid
+ sizeof debugid
- 1) {
1448 nasm_error(passn
== 1 ? ERR_NONFATAL
: ERR_PANIC
,
1449 "identifier expected after DEBUG");
1453 nasm_error(passn
== 1 ? ERR_NONFATAL
: ERR_PANIC
,
1454 "DEBUG identifier too long");
1457 p
= nasm_skip_spaces(p
);
1459 dfmt
->debug_directive(debugid
, p
);
1462 case D_WARNING
: /* [WARNING {+|-|*}warn-name] */
1463 value
= nasm_skip_spaces(value
);
1465 case '-': validid
= 0; value
++; break;
1466 case '+': validid
= 1; value
++; break;
1467 case '*': validid
= 2; value
++; break;
1468 default: validid
= 1; break;
1471 for (i
= 1; i
<= ERR_WARN_MAX
; i
++)
1472 if (!nasm_stricmp(value
, warnings
[i
].name
))
1474 if (i
<= ERR_WARN_MAX
) {
1477 warning_on
[i
] = false;
1480 warning_on
[i
] = true;
1483 warning_on
[i
] = warning_on_global
[i
];
1488 nasm_error(ERR_NONFATAL
,
1489 "invalid warning id in WARNING directive");
1491 case D_CPU
: /* [CPU] */
1492 cpu
= get_cpu(value
);
1494 case D_LIST
: /* [LIST {+|-}] */
1495 value
= nasm_skip_spaces(value
);
1496 if (*value
== '+') {
1499 if (*value
== '-') {
1506 case D_DEFAULT
: /* [DEFAULT] */
1509 tokval
.t_type
= TOKEN_INVALID
;
1510 if (stdscan(NULL
, &tokval
) == TOKEN_SPECIAL
) {
1511 switch ((int)tokval
.t_integer
) {
1527 if (float_option(value
)) {
1528 nasm_error(pass1
== 1 ? ERR_NONFATAL
: ERR_PANIC
,
1529 "unknown 'float' directive: %s",
1534 if (ofmt
->directive(d
, value
, pass2
))
1536 /* else fall through */
1538 nasm_error(pass1
== 1 ? ERR_NONFATAL
: ERR_PANIC
,
1539 "unrecognised directive [%s]",
1544 nasm_error(ERR_NONFATAL
,
1545 "invalid parameter to [%s] directive",
1548 } else { /* it isn't a directive */
1549 parse_line(pass1
, line
, &output_ins
, def_label
);
1551 if (optimizing
> 0) {
1552 if (forwref
!= NULL
&& globallineno
== forwref
->lineno
) {
1553 output_ins
.forw_ref
= true;
1555 output_ins
.oprs
[forwref
->operand
].opflags
|= OPFLAG_FORWARD
;
1556 forwref
= saa_rstruct(forwrefs
);
1557 } while (forwref
!= NULL
1558 && forwref
->lineno
== globallineno
);
1560 output_ins
.forw_ref
= false;
1562 if (output_ins
.forw_ref
) {
1564 for (i
= 0; i
< output_ins
.operands
; i
++) {
1565 if (output_ins
.oprs
[i
].opflags
& OPFLAG_FORWARD
) {
1566 struct forwrefinfo
*fwinf
=
1567 (struct forwrefinfo
*)
1568 saa_wstruct(forwrefs
);
1569 fwinf
->lineno
= globallineno
;
1578 if (output_ins
.opcode
== I_EQU
) {
1581 * Special `..' EQUs get processed in pass two,
1582 * except `..@' macro-processor EQUs which are done
1583 * in the normal place.
1585 if (!output_ins
.label
)
1586 nasm_error(ERR_NONFATAL
,
1587 "EQU not preceded by label");
1589 else if (output_ins
.label
[0] != '.' ||
1590 output_ins
.label
[1] != '.' ||
1591 output_ins
.label
[2] == '@') {
1592 if (output_ins
.operands
== 1 &&
1593 (output_ins
.oprs
[0].type
& IMMEDIATE
) &&
1594 output_ins
.oprs
[0].wrt
== NO_SEG
) {
1595 bool isext
= !!(output_ins
.oprs
[0].opflags
1597 def_label(output_ins
.label
,
1598 output_ins
.oprs
[0].segment
,
1599 output_ins
.oprs
[0].offset
, NULL
,
1601 } else if (output_ins
.operands
== 2
1602 && (output_ins
.oprs
[0].type
& IMMEDIATE
)
1603 && (output_ins
.oprs
[0].type
& COLON
)
1604 && output_ins
.oprs
[0].segment
== NO_SEG
1605 && output_ins
.oprs
[0].wrt
== NO_SEG
1606 && (output_ins
.oprs
[1].type
& IMMEDIATE
)
1607 && output_ins
.oprs
[1].segment
== NO_SEG
1608 && output_ins
.oprs
[1].wrt
== NO_SEG
) {
1609 def_label(output_ins
.label
,
1610 output_ins
.oprs
[0].offset
| SEG_ABS
,
1611 output_ins
.oprs
[1].offset
,
1612 NULL
, false, false);
1614 nasm_error(ERR_NONFATAL
,
1615 "bad syntax for EQU");
1619 * Special `..' EQUs get processed here, except
1620 * `..@' macro processor EQUs which are done above.
1622 if (output_ins
.label
[0] == '.' &&
1623 output_ins
.label
[1] == '.' &&
1624 output_ins
.label
[2] != '@') {
1625 if (output_ins
.operands
== 1 &&
1626 (output_ins
.oprs
[0].type
& IMMEDIATE
)) {
1627 define_label(output_ins
.label
,
1628 output_ins
.oprs
[0].segment
,
1629 output_ins
.oprs
[0].offset
,
1630 NULL
, false, false);
1631 } else if (output_ins
.operands
== 2
1632 && (output_ins
.oprs
[0].type
& IMMEDIATE
)
1633 && (output_ins
.oprs
[0].type
& COLON
)
1634 && output_ins
.oprs
[0].segment
== NO_SEG
1635 && (output_ins
.oprs
[1].type
& IMMEDIATE
)
1636 && output_ins
.oprs
[1].segment
== NO_SEG
) {
1637 define_label(output_ins
.label
,
1638 output_ins
.oprs
[0].offset
| SEG_ABS
,
1639 output_ins
.oprs
[1].offset
,
1640 NULL
, false, false);
1642 nasm_error(ERR_NONFATAL
,
1643 "bad syntax for EQU");
1646 } else { /* instruction isn't an EQU */
1650 int64_t l
= insn_size(location
.segment
, offs
, sb
, cpu
,
1651 &output_ins
, nasm_error
);
1653 /* if (using_debug_info) && output_ins.opcode != -1) */
1654 if (using_debug_info
)
1655 { /* fbk 03/25/01 */
1656 /* this is done here so we can do debug type info */
1658 TYS_ELEMENTS(output_ins
.operands
);
1659 switch (output_ins
.opcode
) {
1662 TYS_ELEMENTS(output_ins
.oprs
[0].offset
) | TY_BYTE
;
1666 TYS_ELEMENTS(output_ins
.oprs
[0].offset
) | TY_WORD
;
1670 TYS_ELEMENTS(output_ins
.oprs
[0].offset
) | TY_DWORD
;
1674 TYS_ELEMENTS(output_ins
.oprs
[0].offset
) | TY_QWORD
;
1678 TYS_ELEMENTS(output_ins
.oprs
[0].offset
) | TY_TBYTE
;
1682 TYS_ELEMENTS(output_ins
.oprs
[0].offset
) | TY_OWORD
;
1686 TYS_ELEMENTS(output_ins
.oprs
[0].offset
) | TY_YWORD
;
1689 typeinfo
|= TY_BYTE
;
1692 typeinfo
|= TY_WORD
;
1695 if (output_ins
.eops_float
)
1696 typeinfo
|= TY_FLOAT
;
1698 typeinfo
|= TY_DWORD
;
1701 typeinfo
|= TY_QWORD
;
1704 typeinfo
|= TY_TBYTE
;
1707 typeinfo
|= TY_OWORD
;
1710 typeinfo
|= TY_YWORD
;
1713 typeinfo
= TY_LABEL
;
1717 dfmt
->debug_typevalue(typeinfo
);
1721 SET_CURR_OFFS(offs
);
1724 * else l == -1 => invalid instruction, which will be
1725 * flagged as an error on pass 2
1729 offs
+= assemble(location
.segment
, offs
, sb
, cpu
,
1730 &output_ins
, ofmt
, nasm_error
,
1732 SET_CURR_OFFS(offs
);
1736 cleanup_insn(&output_ins
);
1739 location
.offset
= offs
= GET_CURR_OFFS
;
1740 } /* end while (line = preproc->getline... */
1742 if (pass0
== 2 && global_offset_changed
&& !terminate_after_phase
)
1743 nasm_error(ERR_NONFATAL
,
1744 "phase error detected at end of assembly.");
1747 preproc
->cleanup(1);
1749 if ((passn
> 1 && !global_offset_changed
) || pass0
== 2) {
1751 } else if (global_offset_changed
&&
1752 global_offset_changed
< prev_offset_changed
) {
1753 prev_offset_changed
= global_offset_changed
;
1759 if (terminate_after_phase
)
1762 if ((stall_count
> 997) || (passn
>= pass_max
)) {
1763 /* We get here if the labels don't converge
1764 * Example: FOO equ FOO + 1
1766 nasm_error(ERR_NONFATAL
,
1767 "Can't find valid values for all labels "
1768 "after %d passes, giving up.", passn
);
1769 nasm_error(ERR_NONFATAL
,
1770 "Possible causes: recursive EQUs, macro abuse.");
1775 preproc
->cleanup(0);
1777 if (!terminate_after_phase
&& opt_verbose_info
) {
1778 /* -On and -Ov switches */
1779 fprintf(stdout
, "info: assembly required 1+%d+1 passes\n", passn
-3);
1783 static enum directives
getkw(char **directive
, char **value
)
1787 buf
= nasm_skip_spaces(*directive
);
1789 /* it should be enclosed in [ ] */
1792 q
= strchr(buf
, ']');
1796 /* stip off the comments */
1797 p
= strchr(buf
, ';');
1799 if (p
< q
) /* ouch! somwhere inside */
1804 /* no brace, no trailing spaces */
1806 nasm_zap_spaces_rev(--q
);
1809 p
= nasm_skip_spaces(++buf
);
1810 q
= nasm_skip_word(p
);
1812 return D_none
; /* sigh... no value there */
1816 /* and value finally */
1817 p
= nasm_skip_spaces(++q
);
1820 return find_directive(*directive
);
1824 * gnu style error reporting
1825 * This function prints an error message to error_file in the
1826 * style used by GNU. An example would be:
1827 * file.asm:50: error: blah blah blah
1828 * where file.asm is the name of the file, 50 is the line number on
1829 * which the error occurs (or is detected) and "error:" is one of
1830 * the possible optional diagnostics -- it can be "error" or "warning"
1831 * or something else. Finally the line terminates with the actual
1834 * @param severity the severity of the warning or error
1835 * @param fmt the printf style format string
1837 static void nasm_verror_gnu(int severity
, const char *fmt
, va_list ap
)
1839 char *currentfile
= NULL
;
1842 if (is_suppressed_warning(severity
))
1845 if (!(severity
& ERR_NOFILE
))
1846 src_get(&lineno
, ¤tfile
);
1849 fprintf(error_file
, "%s:%"PRId32
": ", currentfile
, lineno
);
1850 nasm_free(currentfile
);
1852 fputs("nasm: ", error_file
);
1855 nasm_verror_common(severity
, fmt
, ap
);
1859 * MS style error reporting
1860 * This function prints an error message to error_file in the
1861 * style used by Visual C and some other Microsoft tools. An example
1863 * file.asm(50) : error: blah blah blah
1864 * where file.asm is the name of the file, 50 is the line number on
1865 * which the error occurs (or is detected) and "error:" is one of
1866 * the possible optional diagnostics -- it can be "error" or "warning"
1867 * or something else. Finally the line terminates with the actual
1870 * @param severity the severity of the warning or error
1871 * @param fmt the printf style format string
1873 static void nasm_verror_vc(int severity
, const char *fmt
, va_list ap
)
1875 char *currentfile
= NULL
;
1878 if (is_suppressed_warning(severity
))
1881 if (!(severity
& ERR_NOFILE
))
1882 src_get(&lineno
, ¤tfile
);
1885 fprintf(error_file
, "%s(%"PRId32
") : ", currentfile
, lineno
);
1886 nasm_free(currentfile
);
1888 fputs("nasm: ", error_file
);
1891 nasm_verror_common(severity
, fmt
, ap
);
1895 * check for supressed warning
1896 * checks for suppressed warning or pass one only warning and we're
1899 * @param severity the severity of the warning or error
1900 * @return true if we should abort error/warning printing
1902 static bool is_suppressed_warning(int severity
)
1904 /* Not a warning at all */
1905 if ((severity
& ERR_MASK
) != ERR_WARNING
)
1908 /* See if it's a pass-one only warning and we're not in pass one. */
1909 if (((severity
& ERR_PASS1
) && pass0
!= 1) ||
1910 ((severity
& ERR_PASS2
) && pass0
!= 2))
1913 /* Might be a warning but suppresed explicitly */
1914 if (severity
& ERR_WARN_MASK
)
1915 return !warning_on
[WARN_IDX(severity
)];
1921 * common error reporting
1922 * This is the common back end of the error reporting schemes currently
1923 * implemented. It prints the nature of the warning and then the
1924 * specific error message to error_file and may or may not return. It
1925 * doesn't return if the error severity is a "panic" or "debug" type.
1927 * @param severity the severity of the warning or error
1928 * @param fmt the printf style format string
1930 static void nasm_verror_common(int severity
, const char *fmt
, va_list args
)
1935 switch (severity
& (ERR_MASK
|ERR_NO_SEVERITY
)) {
1956 vsnprintf(msg
, sizeof msg
, fmt
, args
);
1958 fprintf(error_file
, "%s%s\n", pfx
, msg
);
1961 nasmlist
.error(severity
, pfx
, msg
);
1963 if (severity
& ERR_USAGE
)
1966 switch (severity
& ERR_MASK
) {
1968 /* no further action, by definition */
1971 /* Treat warnings as errors */
1972 if (warning_on
[WARN_IDX(ERR_WARN_TERM
)])
1973 terminate_after_phase
= true;
1976 terminate_after_phase
= true;
1986 exit(1); /* instantly die */
1987 break; /* placate silly compilers */
1990 /* abort(); *//* halt, catch fire, and dump core */
1996 static void usage(void)
1998 fputs("type `nasm -h' for help\n", error_file
);
2001 static uint32_t get_cpu(char *value
)
2003 if (!strcmp(value
, "8086"))
2005 if (!strcmp(value
, "186"))
2007 if (!strcmp(value
, "286"))
2009 if (!strcmp(value
, "386"))
2011 if (!strcmp(value
, "486"))
2013 if (!strcmp(value
, "586") || !nasm_stricmp(value
, "pentium"))
2015 if (!strcmp(value
, "686") ||
2016 !nasm_stricmp(value
, "ppro") ||
2017 !nasm_stricmp(value
, "pentiumpro") || !nasm_stricmp(value
, "p2"))
2019 if (!nasm_stricmp(value
, "p3") || !nasm_stricmp(value
, "katmai"))
2021 if (!nasm_stricmp(value
, "p4") || /* is this right? -- jrc */
2022 !nasm_stricmp(value
, "willamette"))
2023 return IF_WILLAMETTE
;
2024 if (!nasm_stricmp(value
, "prescott"))
2026 if (!nasm_stricmp(value
, "x64") ||
2027 !nasm_stricmp(value
, "x86-64"))
2029 if (!nasm_stricmp(value
, "ia64") ||
2030 !nasm_stricmp(value
, "ia-64") ||
2031 !nasm_stricmp(value
, "itanium") ||
2032 !nasm_stricmp(value
, "itanic") || !nasm_stricmp(value
, "merced"))
2035 nasm_error(pass0
< 2 ? ERR_NONFATAL
: ERR_FATAL
,
2036 "unknown 'cpu' type");
2038 return IF_PLEVEL
; /* the maximum level */
2041 static int get_bits(char *value
)
2045 if ((i
= atoi(value
)) == 16)
2046 return i
; /* set for a 16-bit segment */
2049 nasm_error(ERR_NONFATAL
,
2050 "cannot specify 32-bit segment on processor below a 386");
2053 } else if (i
== 64) {
2054 if (cpu
< IF_X86_64
) {
2055 nasm_error(ERR_NONFATAL
,
2056 "cannot specify 64-bit segment on processor below an x86-64");
2060 nasm_error(ERR_NONFATAL
,
2061 "%s output format does not support 64-bit code",
2066 nasm_error(pass0
< 2 ? ERR_NONFATAL
: ERR_FATAL
,
2067 "`%s' is not a valid segment size; must be 16, 32 or 64",