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 */
502 while (nasm_isspace(*p
))
510 nasm_error(ERR_NONFATAL
| ERR_NOFILE
| ERR_USAGE
,
511 "option `-%c' requires an argument", p
[1]);
518 static void copy_filename(char *dst
, const char *src
)
520 size_t len
= strlen(src
);
522 if (len
>= (size_t)FILENAME_MAX
) {
523 nasm_error(ERR_FATAL
| ERR_NOFILE
, "file name too long");
526 strncpy(dst
, src
, FILENAME_MAX
);
530 * Convert a string to Make-safe form
532 static char *quote_for_make(const char *str
)
537 size_t n
= 1; /* Terminating zero */
543 for (p
= str
; *p
; p
++) {
547 /* Convert N backslashes + ws -> 2N+1 backslashes + ws */
567 /* Convert N backslashes at the end of filename to 2N backslashes */
571 os
= q
= nasm_malloc(n
);
574 for (p
= str
; *p
; p
++) {
617 #define OPT_POSTFIX 1
618 struct textargs textopts
[] = {
619 {"prefix", OPT_PREFIX
},
620 {"postfix", OPT_POSTFIX
},
624 static bool stopoptions
= false;
625 static bool process_arg(char *p
, char *q
)
629 bool advance
= false;
635 if (p
[0] == '-' && !stopoptions
) {
636 if (strchr("oOfpPdDiIlFXuUZwW", p
[1])) {
637 /* These parameters take values */
638 if (!(param
= get_param(p
, q
, &advance
)))
647 case 'o': /* output file */
648 copy_filename(outname
, param
);
651 case 'f': /* output format */
652 ofmt
= ofmt_find(param
);
654 nasm_error(ERR_FATAL
| ERR_NOFILE
| ERR_USAGE
,
655 "unrecognised output format `%s' - "
656 "use -hf for a list", param
);
660 case 'O': /* Optimization level */
665 /* Naked -O == -Ox */
666 optimizing
= INT_MAX
>> 1; /* Almost unlimited */
670 case '0': case '1': case '2': case '3': case '4':
671 case '5': case '6': case '7': case '8': case '9':
672 opt
= strtoul(param
, ¶m
, 10);
674 /* -O0 -> optimizing == -1, 0.98 behaviour */
675 /* -O1 -> optimizing == 0, 0.98.09 behaviour */
677 optimizing
= opt
- 1;
685 opt_verbose_info
= true;
690 optimizing
= INT_MAX
>> 1; /* Almost unlimited */
694 nasm_error(ERR_FATAL
,
695 "unknown optimization option -O%c\n",
704 case 'p': /* pre-include */
706 pp_pre_include(param
);
709 case 'd': /* pre-define */
711 pp_pre_define(param
);
714 case 'u': /* un-define */
716 pp_pre_undefine(param
);
719 case 'i': /* include search path */
721 pp_include_path(param
);
724 case 'l': /* listing file */
725 copy_filename(listname
, param
);
728 case 'Z': /* error messages file */
729 strcpy(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 (-O0 disables, default)\n"
782 " -P<file> pre-includes a file\n"
783 " -D<macro>[=<value>] pre-defines a macro\n"
784 " -U<macro> undefines a macro\n"
785 " -X<format> specifies error reporting format (gnu or vc)\n"
786 " -w+foo enables warning foo (equiv. -Wfoo)\n"
787 " -w-foo disable warning foo (equiv. -Wno-foo)\n\n"
788 "--prefix,--postfix\n"
789 " this options prepend or append the given argument to all\n"
790 " extern and global variables\n\n"
792 for (i
= 0; i
<= ERR_WARN_MAX
; i
++)
793 printf(" %-23s %s (default %s)\n",
794 warnings
[i
].name
, warnings
[i
].help
,
795 warnings
[i
].enabled
? "on" : "off");
797 ("\nresponse files should contain command line parameters"
798 ", one per line.\n");
800 printf("\nvalid output formats for -f are"
801 " (`*' denotes default):\n");
802 ofmt_list(ofmt
, stdout
);
804 printf("\nFor a list of valid output formats, use -hf.\n");
805 printf("For a list of debug formats, use -f <form> -y.\n");
807 exit(0); /* never need usage message here */
811 printf("\nvalid debug formats for '%s' output format are"
812 " ('*' denotes default):\n", ofmt
->shortname
);
813 dfmt_list(ofmt
, stdout
);
818 tasm_compatible_mode
= true;
822 printf("NASM version %s compiled on %s%s\n",
823 nasm_version
, nasm_date
, nasm_compile_options
);
824 exit(0); /* never need usage message here */
827 case 'e': /* preprocess only */
829 operating_mode
= op_preprocess
;
832 case 'a': /* assemble only - don't preprocess */
837 if (param
[0] == 'n' && param
[1] == 'o' && param
[2] == '-') {
846 if (param
[0] != '+' && param
[0] != '-') {
847 nasm_error(ERR_NONFATAL
| ERR_NOFILE
| ERR_USAGE
,
848 "invalid option to `-w'");
851 do_warn
= (param
[0] == '+');
855 for (i
= 0; i
<= ERR_WARN_MAX
; i
++)
856 if (!nasm_stricmp(param
, warnings
[i
].name
))
858 if (i
<= ERR_WARN_MAX
)
859 warning_on_global
[i
] = do_warn
;
860 else if (!nasm_stricmp(param
, "all"))
861 for (i
= 1; i
<= ERR_WARN_MAX
; i
++)
862 warning_on_global
[i
] = do_warn
;
863 else if (!nasm_stricmp(param
, "none"))
864 for (i
= 1; i
<= ERR_WARN_MAX
; i
++)
865 warning_on_global
[i
] = !do_warn
;
867 nasm_error(ERR_NONFATAL
| ERR_NOFILE
| ERR_USAGE
,
868 "invalid warning `%s'", param
);
874 operating_mode
= op_depend
;
877 operating_mode
= op_depend
;
878 depend_missing_ok
= true;
881 depend_emit_phony
= true;
892 depend_target
= quote_for_make(q
);
896 nasm_error(ERR_NONFATAL
|ERR_NOFILE
|ERR_USAGE
,
897 "unknown dependency option `-M%c'", p
[2]);
900 if (advance
&& (!q
|| !q
[0])) {
901 nasm_error(ERR_NONFATAL
|ERR_NOFILE
|ERR_USAGE
,
902 "option `-M%c' requires a parameter", p
[2]);
911 if (p
[2] == 0) { /* -- => stop processing options */
915 for (s
= 0; textopts
[s
].label
; s
++) {
916 if (!nasm_stricmp(p
+ 2, textopts
[s
].label
)) {
927 nasm_error(ERR_NONFATAL
| ERR_NOFILE
|
929 "option `--%s' requires an argument",
933 advance
= 1, param
= q
;
936 if (s
== OPT_PREFIX
) {
937 strncpy(lprefix
, param
, PREFIX_MAX
- 1);
938 lprefix
[PREFIX_MAX
- 1] = 0;
941 if (s
== OPT_POSTFIX
) {
942 strncpy(lpostfix
, param
, POSTFIX_MAX
- 1);
943 lpostfix
[POSTFIX_MAX
- 1] = 0;
950 nasm_error(ERR_NONFATAL
| ERR_NOFILE
| ERR_USAGE
,
951 "unrecognised option `--%s'", p
+ 2);
959 if (!ofmt
->setinfo(GI_SWITCH
, &p
))
960 nasm_error(ERR_NONFATAL
| ERR_NOFILE
| ERR_USAGE
,
961 "unrecognised option `-%c'", p
[1]);
966 nasm_error(ERR_NONFATAL
| ERR_NOFILE
| ERR_USAGE
,
967 "more than one input file specified");
969 copy_filename(inname
, p
);
976 #define ARG_BUF_DELTA 128
978 static void process_respfile(FILE * rfile
)
980 char *buffer
, *p
, *q
, *prevarg
;
981 int bufsize
, prevargsize
;
983 bufsize
= prevargsize
= ARG_BUF_DELTA
;
984 buffer
= nasm_malloc(ARG_BUF_DELTA
);
985 prevarg
= nasm_malloc(ARG_BUF_DELTA
);
988 while (1) { /* Loop to handle all lines in file */
990 while (1) { /* Loop to handle long lines */
991 q
= fgets(p
, bufsize
- (p
- buffer
), rfile
);
995 if (p
> buffer
&& p
[-1] == '\n')
997 if (p
- buffer
> bufsize
- 10) {
1000 bufsize
+= ARG_BUF_DELTA
;
1001 buffer
= nasm_realloc(buffer
, bufsize
);
1002 p
= buffer
+ offset
;
1006 if (!q
&& p
== buffer
) {
1008 process_arg(prevarg
, NULL
);
1015 * Play safe: remove CRs, LFs and any spurious ^Zs, if any of
1016 * them are present at the end of the line.
1018 *(p
= &buffer
[strcspn(buffer
, "\r\n\032")]) = '\0';
1020 while (p
> buffer
&& nasm_isspace(p
[-1]))
1024 while (nasm_isspace(*p
))
1027 if (process_arg(prevarg
, p
))
1030 if ((int) strlen(p
) > prevargsize
- 10) {
1031 prevargsize
+= ARG_BUF_DELTA
;
1032 prevarg
= nasm_realloc(prevarg
, prevargsize
);
1034 strncpy(prevarg
, p
, prevargsize
);
1038 /* Function to process args from a string of args, rather than the
1039 * argv array. Used by the environment variable and response file
1042 static void process_args(char *args
)
1044 char *p
, *q
, *arg
, *prevarg
;
1045 char separator
= ' ';
1048 if (*p
&& *p
!= '-')
1053 while (*p
&& *p
!= separator
)
1055 while (*p
== separator
)
1059 if (process_arg(prevarg
, arg
))
1063 process_arg(arg
, NULL
);
1066 static void process_response_file(const char *file
)
1069 FILE *f
= fopen(file
, "r");
1074 while (fgets(str
, sizeof str
, f
)) {
1080 static void parse_cmdline(int argc
, char **argv
)
1083 char *envreal
, *envcopy
= NULL
, *p
, *arg
;
1086 *inname
= *outname
= *listname
= *errname
= '\0';
1087 for (i
= 0; i
<= ERR_WARN_MAX
; i
++)
1088 warning_on_global
[i
] = warnings
[i
].enabled
;
1091 * First, process the NASMENV environment variable.
1093 envreal
= getenv("NASMENV");
1096 envcopy
= nasm_strdup(envreal
);
1097 process_args(envcopy
);
1102 * Now process the actual command line.
1107 if (argv
[0][0] == '@') {
1108 /* We have a response file, so process this as a set of
1109 * arguments like the environment variable. This allows us
1110 * to have multiple arguments on a single line, which is
1111 * different to the -@resp file processing below for regular
1114 process_response_file(argv
[0]+1);
1118 if (!stopoptions
&& argv
[0][0] == '-' && argv
[0][1] == '@') {
1119 p
= get_param(argv
[0], argc
> 1 ? argv
[1] : NULL
, &advance
);
1121 rfile
= fopen(p
, "r");
1123 process_respfile(rfile
);
1126 nasm_error(ERR_NONFATAL
| ERR_NOFILE
| ERR_USAGE
,
1127 "unable to open response file `%s'", p
);
1130 advance
= process_arg(argv
[0], argc
> 1 ? argv
[1] : NULL
);
1131 argv
+= advance
, argc
-= advance
;
1134 /* Look for basic command line typos. This definitely doesn't
1135 catch all errors, but it might help cases of fumbled fingers. */
1137 nasm_error(ERR_NONFATAL
| ERR_NOFILE
| ERR_USAGE
,
1138 "no input file specified");
1139 else if (!strcmp(inname
, errname
) ||
1140 !strcmp(inname
, outname
) ||
1141 !strcmp(inname
, listname
) ||
1142 (depend_file
&& !strcmp(inname
, depend_file
)))
1143 nasm_error(ERR_FATAL
| ERR_NOFILE
| ERR_USAGE
,
1144 "file `%s' is both input and output file",
1148 error_file
= fopen(errname
, "w");
1150 error_file
= stderr
; /* Revert to default! */
1151 nasm_error(ERR_FATAL
| ERR_NOFILE
| ERR_USAGE
,
1152 "cannot open file `%s' for error messages",
1158 static enum directives
getkw(char **directive
, char **value
);
1160 static void assemble_file(char *fname
, StrList
**depend_ptr
)
1162 char *directive
, *value
, *p
, *q
, *special
, *line
, debugid
[80];
1168 struct tokenval tokval
;
1172 if (cmd_sb
== 32 && cmd_cpu
< IF_386
)
1173 nasm_error(ERR_FATAL
, "command line: "
1174 "32-bit segment size requires a higher cpu");
1176 pass_max
= prev_offset_changed
= (INT_MAX
>> 1) + 2; /* Almost unlimited */
1177 for (passn
= 1; pass0
<= 2; passn
++) {
1181 pass1
= pass0
== 2 ? 2 : 1; /* 1, 1, 1, ..., 1, 2 */
1182 pass2
= passn
> 1 ? 2 : 1; /* 1, 2, 2, ..., 2, 2 */
1183 /* pass0 0, 0, 0, ..., 1, 2 */
1185 def_label
= passn
> 1 ? redefine_label
: define_label
;
1187 globalbits
= sb
= cmd_sb
; /* set 'bits' to command line default */
1191 nasmlist
.init(listname
, nasm_error
);
1194 global_offset_changed
= 0; /* set by redefine_label */
1195 location
.segment
= ofmt
->section(NULL
, pass2
, &sb
);
1198 saa_rewind(forwrefs
);
1199 forwref
= saa_rstruct(forwrefs
);
1201 offsets
= raa_init();
1203 preproc
->reset(fname
, pass1
, &nasmlist
,
1204 pass1
== 2 ? depend_ptr
: NULL
);
1205 memcpy(warning_on
, warning_on_global
, (ERR_WARN_MAX
+1) * sizeof(bool));
1209 location
.known
= true;
1210 location
.offset
= offs
= GET_CURR_OFFS
;
1212 while ((line
= preproc
->getline())) {
1217 * Here we parse our directives; this is not handled by the
1218 * 'real' parser. This really should be a separate function.
1221 d
= getkw(&directive
, &value
);
1226 case D_SEGMENT
: /* [SEGMENT n] */
1228 seg
= ofmt
->section(value
, pass2
, &sb
);
1229 if (seg
== NO_SEG
) {
1230 nasm_error(pass1
== 1 ? ERR_NONFATAL
: ERR_PANIC
,
1231 "segment name `%s' not recognized",
1235 location
.segment
= seg
;
1238 case D_EXTERN
: /* [EXTERN label:special] */
1240 value
++; /* skip initial $ if present */
1243 while (*q
&& *q
!= ':')
1247 ofmt
->symdef(value
, 0L, 0L, 3, q
);
1249 } else if (passn
== 1) {
1254 while (*q
&& *q
!= ':') {
1260 nasm_error(ERR_NONFATAL
,
1261 "identifier expected after EXTERN");
1269 if (!is_extern(value
)) { /* allow re-EXTERN to be ignored */
1271 pass0
= 1; /* fake pass 1 in labels.c */
1272 declare_as_global(value
, special
);
1273 define_label(value
, seg_alloc(), 0L, NULL
,
1277 } /* else pass0 == 1 */
1279 case D_BITS
: /* [BITS bits] */
1280 globalbits
= sb
= get_bits(value
);
1282 case D_GLOBAL
: /* [GLOBAL symbol:special] */
1284 value
++; /* skip initial $ if present */
1285 if (pass0
== 2) { /* pass 2 */
1287 while (*q
&& *q
!= ':')
1291 ofmt
->symdef(value
, 0L, 0L, 3, q
);
1293 } else if (pass2
== 1) { /* pass == 1 */
1298 while (*q
&& *q
!= ':') {
1304 nasm_error(ERR_NONFATAL
,
1305 "identifier expected after GLOBAL");
1313 declare_as_global(value
, special
);
1316 case D_COMMON
: /* [COMMON symbol size:special] */
1321 value
++; /* skip initial $ if present */
1326 while (*p
&& !nasm_isspace(*p
)) {
1332 nasm_error(ERR_NONFATAL
,
1333 "identifier expected after COMMON");
1337 while (*p
&& nasm_isspace(*p
))
1340 while (*q
&& *q
!= ':')
1348 size
= readnum(p
, &rn_error
);
1350 nasm_error(ERR_NONFATAL
,
1351 "invalid size specified"
1352 " in COMMON declaration");
1356 nasm_error(ERR_NONFATAL
,
1357 "no size specified in"
1358 " COMMON declaration");
1363 define_common(value
, seg_alloc(), size
, special
);
1364 } else if (pass0
== 2) {
1366 ofmt
->symdef(value
, 0L, 0L, 3, special
);
1370 case D_ABSOLUTE
: /* [ABSOLUTE address] */
1372 stdscan_bufptr
= value
;
1373 tokval
.t_type
= TOKEN_INVALID
;
1374 e
= evaluate(stdscan
, NULL
, &tokval
, NULL
, pass2
,
1379 1 ? ERR_NONFATAL
: ERR_PANIC
,
1380 "cannot use non-relocatable expression as "
1381 "ABSOLUTE address");
1383 abs_seg
= reloc_seg(e
);
1384 abs_offset
= reloc_value(e
);
1386 } else if (passn
== 1)
1387 abs_offset
= 0x100; /* don't go near zero in case of / */
1389 nasm_error(ERR_PANIC
, "invalid ABSOLUTE address "
1392 location
.segment
= NO_SEG
;
1394 case D_DEBUG
: /* [DEBUG] */
1400 while (*p
&& !nasm_isspace(*p
)) {
1407 nasm_error(passn
== 1 ? ERR_NONFATAL
: ERR_PANIC
,
1408 "identifier expected after DEBUG");
1411 while (*p
&& nasm_isspace(*p
))
1414 dfmt
->debug_directive(debugid
, p
);
1416 case D_WARNING
: /* [WARNING {+|-|*}warn-name] */
1417 while (*value
&& nasm_isspace(*value
))
1421 case '-': validid
= 0; value
++; break;
1422 case '+': validid
= 1; value
++; break;
1423 case '*': validid
= 2; value
++; break;
1424 default: validid
= 1; break;
1427 for (i
= 1; i
<= ERR_WARN_MAX
; i
++)
1428 if (!nasm_stricmp(value
, warnings
[i
].name
))
1430 if (i
<= ERR_WARN_MAX
) {
1433 warning_on
[i
] = false;
1436 warning_on
[i
] = true;
1439 warning_on
[i
] = warning_on_global
[i
];
1444 nasm_error(ERR_NONFATAL
,
1445 "invalid warning id in WARNING directive");
1447 case D_CPU
: /* [CPU] */
1448 cpu
= get_cpu(value
);
1450 case D_LIST
: /* [LIST {+|-}] */
1451 while (*value
&& nasm_isspace(*value
))
1454 if (*value
== '+') {
1457 if (*value
== '-') {
1464 case D_DEFAULT
: /* [DEFAULT] */
1466 stdscan_bufptr
= value
;
1467 tokval
.t_type
= TOKEN_INVALID
;
1468 if (stdscan(NULL
, &tokval
) == TOKEN_SPECIAL
) {
1469 switch ((int)tokval
.t_integer
) {
1485 if (float_option(value
)) {
1486 nasm_error(pass1
== 1 ? ERR_NONFATAL
: ERR_PANIC
,
1487 "unknown 'float' directive: %s",
1492 if (!d
|| !ofmt
->directive(d
, value
, pass2
))
1493 nasm_error(pass1
== 1 ? ERR_NONFATAL
: ERR_PANIC
,
1494 "unrecognised directive [%s]",
1499 nasm_error(ERR_NONFATAL
,
1500 "invalid parameter to [%s] directive",
1503 } else { /* it isn't a directive */
1504 parse_line(pass1
, line
, &output_ins
, def_label
);
1506 if (optimizing
> 0) {
1507 if (forwref
!= NULL
&& globallineno
== forwref
->lineno
) {
1508 output_ins
.forw_ref
= true;
1510 output_ins
.oprs
[forwref
->operand
].opflags
|=
1512 forwref
= saa_rstruct(forwrefs
);
1513 } while (forwref
!= NULL
1514 && forwref
->lineno
== globallineno
);
1516 output_ins
.forw_ref
= false;
1518 if (output_ins
.forw_ref
) {
1520 for (i
= 0; i
< output_ins
.operands
; i
++) {
1521 if (output_ins
.oprs
[i
].
1522 opflags
& OPFLAG_FORWARD
) {
1523 struct forwrefinfo
*fwinf
=
1524 (struct forwrefinfo
*)
1525 saa_wstruct(forwrefs
);
1526 fwinf
->lineno
= globallineno
;
1535 if (output_ins
.opcode
== I_EQU
) {
1538 * Special `..' EQUs get processed in pass two,
1539 * except `..@' macro-processor EQUs which are done
1540 * in the normal place.
1542 if (!output_ins
.label
)
1543 nasm_error(ERR_NONFATAL
,
1544 "EQU not preceded by label");
1546 else if (output_ins
.label
[0] != '.' ||
1547 output_ins
.label
[1] != '.' ||
1548 output_ins
.label
[2] == '@') {
1549 if (output_ins
.operands
== 1 &&
1550 (output_ins
.oprs
[0].type
& IMMEDIATE
) &&
1551 output_ins
.oprs
[0].wrt
== NO_SEG
) {
1552 bool isext
= !!(output_ins
.oprs
[0].opflags
1554 def_label(output_ins
.label
,
1555 output_ins
.oprs
[0].segment
,
1556 output_ins
.oprs
[0].offset
, NULL
,
1558 } else if (output_ins
.operands
== 2
1559 && (output_ins
.oprs
[0].type
& IMMEDIATE
)
1560 && (output_ins
.oprs
[0].type
& COLON
)
1561 && output_ins
.oprs
[0].segment
== NO_SEG
1562 && output_ins
.oprs
[0].wrt
== NO_SEG
1563 && (output_ins
.oprs
[1].type
& IMMEDIATE
)
1564 && output_ins
.oprs
[1].segment
== NO_SEG
1565 && output_ins
.oprs
[1].wrt
== NO_SEG
) {
1566 def_label(output_ins
.label
,
1567 output_ins
.oprs
[0].offset
| SEG_ABS
,
1568 output_ins
.oprs
[1].offset
,
1569 NULL
, false, false);
1571 nasm_error(ERR_NONFATAL
,
1572 "bad syntax for EQU");
1576 * Special `..' EQUs get processed here, except
1577 * `..@' macro processor EQUs which are done above.
1579 if (output_ins
.label
[0] == '.' &&
1580 output_ins
.label
[1] == '.' &&
1581 output_ins
.label
[2] != '@') {
1582 if (output_ins
.operands
== 1 &&
1583 (output_ins
.oprs
[0].type
& IMMEDIATE
)) {
1584 define_label(output_ins
.label
,
1585 output_ins
.oprs
[0].segment
,
1586 output_ins
.oprs
[0].offset
,
1587 NULL
, false, false);
1588 } else if (output_ins
.operands
== 2
1589 && (output_ins
.oprs
[0].
1591 && (output_ins
.oprs
[0].type
& COLON
)
1592 && output_ins
.oprs
[0].segment
==
1594 && (output_ins
.oprs
[1].
1596 && output_ins
.oprs
[1].segment
==
1598 define_label(output_ins
.label
,
1601 output_ins
.oprs
[1].offset
,
1602 NULL
, false, false);
1604 nasm_error(ERR_NONFATAL
,
1605 "bad syntax for EQU");
1608 } else { /* instruction isn't an EQU */
1612 int64_t l
= insn_size(location
.segment
, offs
, sb
, cpu
,
1613 &output_ins
, nasm_error
);
1615 /* if (using_debug_info) && output_ins.opcode != -1) */
1616 if (using_debug_info
)
1617 { /* fbk 03/25/01 */
1618 /* this is done here so we can do debug type info */
1620 TYS_ELEMENTS(output_ins
.operands
);
1621 switch (output_ins
.opcode
) {
1624 TYS_ELEMENTS(output_ins
.oprs
[0].
1629 TYS_ELEMENTS(output_ins
.oprs
[0].
1634 TYS_ELEMENTS(output_ins
.oprs
[0].
1639 TYS_ELEMENTS(output_ins
.oprs
[0].
1644 TYS_ELEMENTS(output_ins
.oprs
[0].
1649 TYS_ELEMENTS(output_ins
.oprs
[0].
1654 TYS_ELEMENTS(output_ins
.oprs
[0].
1658 typeinfo
|= TY_BYTE
;
1661 typeinfo
|= TY_WORD
;
1664 if (output_ins
.eops_float
)
1665 typeinfo
|= TY_FLOAT
;
1667 typeinfo
|= TY_DWORD
;
1670 typeinfo
|= TY_QWORD
;
1673 typeinfo
|= TY_TBYTE
;
1676 typeinfo
|= TY_OWORD
;
1679 typeinfo
|= TY_YWORD
;
1682 typeinfo
= TY_LABEL
;
1686 dfmt
->debug_typevalue(typeinfo
);
1690 SET_CURR_OFFS(offs
);
1693 * else l == -1 => invalid instruction, which will be
1694 * flagged as an error on pass 2
1698 offs
+= assemble(location
.segment
, offs
, sb
, cpu
,
1699 &output_ins
, ofmt
, nasm_error
,
1701 SET_CURR_OFFS(offs
);
1705 cleanup_insn(&output_ins
);
1708 location
.offset
= offs
= GET_CURR_OFFS
;
1709 } /* end while (line = preproc->getline... */
1711 if (pass0
== 2 && global_offset_changed
&& !terminate_after_phase
)
1712 nasm_error(ERR_NONFATAL
,
1713 "phase error detected at end of assembly.");
1716 preproc
->cleanup(1);
1718 if ((passn
> 1 && !global_offset_changed
) || pass0
== 2) {
1720 } else if (global_offset_changed
&&
1721 global_offset_changed
< prev_offset_changed
) {
1722 prev_offset_changed
= global_offset_changed
;
1728 if (terminate_after_phase
)
1731 if ((stall_count
> 997) || (passn
>= pass_max
)) {
1732 /* We get here if the labels don't converge
1733 * Example: FOO equ FOO + 1
1735 nasm_error(ERR_NONFATAL
,
1736 "Can't find valid values for all labels "
1737 "after %d passes, giving up.", passn
);
1738 nasm_error(ERR_NONFATAL
,
1739 "Possible causes: recursive EQUs, macro abuse.");
1744 preproc
->cleanup(0);
1746 if (!terminate_after_phase
&& opt_verbose_info
) {
1747 /* -On and -Ov switches */
1748 fprintf(stdout
, "info: assembly required 1+%d+1 passes\n", passn
-3);
1752 static enum directives
getkw(char **directive
, char **value
)
1758 /* allow leading spaces or tabs */
1759 while (*buf
== ' ' || *buf
== '\t')
1767 while (*p
&& *p
!= ']')
1775 while (*p
&& *p
!= ';') {
1776 if (!nasm_isspace(*p
))
1782 *directive
= p
= buf
+ 1;
1783 while (*buf
&& *buf
!= ' ' && *buf
!= ']' && *buf
!= '\t')
1790 while (nasm_isspace(*buf
))
1791 buf
++; /* beppu - skip leading whitespace */
1798 return find_directive(*directive
);
1802 * gnu style error reporting
1803 * This function prints an error message to error_file in the
1804 * style used by GNU. An example would be:
1805 * file.asm:50: error: blah blah blah
1806 * where file.asm is the name of the file, 50 is the line number on
1807 * which the error occurs (or is detected) and "error:" is one of
1808 * the possible optional diagnostics -- it can be "error" or "warning"
1809 * or something else. Finally the line terminates with the actual
1812 * @param severity the severity of the warning or error
1813 * @param fmt the printf style format string
1815 static void nasm_verror_gnu(int severity
, const char *fmt
, va_list ap
)
1817 char *currentfile
= NULL
;
1820 if (is_suppressed_warning(severity
))
1823 if (!(severity
& ERR_NOFILE
))
1824 src_get(&lineno
, ¤tfile
);
1827 fprintf(error_file
, "%s:%"PRId32
": ", currentfile
, lineno
);
1828 nasm_free(currentfile
);
1830 fputs("nasm: ", error_file
);
1833 nasm_verror_common(severity
, fmt
, ap
);
1837 * MS style error reporting
1838 * This function prints an error message to error_file in the
1839 * style used by Visual C and some other Microsoft tools. An example
1841 * file.asm(50) : error: blah blah blah
1842 * where file.asm is the name of the file, 50 is the line number on
1843 * which the error occurs (or is detected) and "error:" is one of
1844 * the possible optional diagnostics -- it can be "error" or "warning"
1845 * or something else. Finally the line terminates with the actual
1848 * @param severity the severity of the warning or error
1849 * @param fmt the printf style format string
1851 static void nasm_verror_vc(int severity
, const char *fmt
, va_list ap
)
1853 char *currentfile
= NULL
;
1856 if (is_suppressed_warning(severity
))
1859 if (!(severity
& ERR_NOFILE
))
1860 src_get(&lineno
, ¤tfile
);
1863 fprintf(error_file
, "%s(%"PRId32
") : ", currentfile
, lineno
);
1864 nasm_free(currentfile
);
1866 fputs("nasm: ", error_file
);
1869 nasm_verror_common(severity
, fmt
, ap
);
1873 * check for supressed warning
1874 * checks for suppressed warning or pass one only warning and we're
1877 * @param severity the severity of the warning or error
1878 * @return true if we should abort error/warning printing
1880 static bool is_suppressed_warning(int severity
)
1883 * See if it's a suppressed warning.
1885 return (severity
& ERR_MASK
) == ERR_WARNING
&&
1886 (((severity
& ERR_WARN_MASK
) != 0 &&
1887 !warning_on
[(severity
& ERR_WARN_MASK
) >> ERR_WARN_SHR
]) ||
1888 /* See if it's a pass-one only warning and we're not in pass one. */
1889 ((severity
& ERR_PASS1
) && pass0
!= 1) ||
1890 ((severity
& ERR_PASS2
) && pass0
!= 2));
1894 * common error reporting
1895 * This is the common back end of the error reporting schemes currently
1896 * implemented. It prints the nature of the warning and then the
1897 * specific error message to error_file and may or may not return. It
1898 * doesn't return if the error severity is a "panic" or "debug" type.
1900 * @param severity the severity of the warning or error
1901 * @param fmt the printf style format string
1903 static void nasm_verror_common(int severity
, const char *fmt
, va_list args
)
1908 switch (severity
& (ERR_MASK
|ERR_NO_SEVERITY
)) {
1929 vsnprintf(msg
, sizeof msg
, fmt
, args
);
1931 fprintf(error_file
, "%s%s\n", pfx
, msg
);
1934 nasmlist
.error(severity
, pfx
, msg
);
1936 if (severity
& ERR_USAGE
)
1939 switch (severity
& ERR_MASK
) {
1941 /* no further action, by definition */
1944 if (warning_on
[0]) /* Treat warnings as errors */
1945 terminate_after_phase
= true;
1948 terminate_after_phase
= true;
1958 exit(1); /* instantly die */
1959 break; /* placate silly compilers */
1962 /* abort(); *//* halt, catch fire, and dump core */
1968 static void usage(void)
1970 fputs("type `nasm -h' for help\n", error_file
);
1973 #define BUF_DELTA 512
1975 static FILE *no_pp_fp
;
1976 static ListGen
*no_pp_list
;
1977 static int32_t no_pp_lineinc
;
1979 static void no_pp_reset(char *file
, int pass
, ListGen
* listgen
,
1982 src_set_fname(nasm_strdup(file
));
1985 no_pp_fp
= fopen(file
, "r");
1987 nasm_error(ERR_FATAL
| ERR_NOFILE
,
1988 "unable to open input file `%s'", file
);
1989 no_pp_list
= listgen
;
1990 (void)pass
; /* placate compilers */
1993 StrList
*sl
= nasm_malloc(strlen(file
)+1+sizeof sl
->next
);
1995 strcpy(sl
->str
, file
);
2000 static char *no_pp_getline(void)
2002 char *buffer
, *p
, *q
;
2005 bufsize
= BUF_DELTA
;
2006 buffer
= nasm_malloc(BUF_DELTA
);
2007 src_set_linnum(src_get_linnum() + no_pp_lineinc
);
2009 while (1) { /* Loop to handle %line */
2012 while (1) { /* Loop to handle long lines */
2013 q
= fgets(p
, bufsize
- (p
- buffer
), no_pp_fp
);
2017 if (p
> buffer
&& p
[-1] == '\n')
2019 if (p
- buffer
> bufsize
- 10) {
2021 offset
= p
- buffer
;
2022 bufsize
+= BUF_DELTA
;
2023 buffer
= nasm_realloc(buffer
, bufsize
);
2024 p
= buffer
+ offset
;
2028 if (!q
&& p
== buffer
) {
2034 * Play safe: remove CRs, LFs and any spurious ^Zs, if any of
2035 * them are present at the end of the line.
2037 buffer
[strcspn(buffer
, "\r\n\032")] = '\0';
2039 if (!nasm_strnicmp(buffer
, "%line", 5)) {
2042 char *nm
= nasm_malloc(strlen(buffer
));
2043 if (sscanf(buffer
+ 5, "%"PRId32
"+%d %s", &ln
, &li
, nm
) == 3) {
2044 nasm_free(src_set_fname(nm
));
2054 no_pp_list
->line(LIST_READ
, buffer
);
2059 static void no_pp_cleanup(int pass
)
2061 (void)pass
; /* placate GCC */
2065 static uint32_t get_cpu(char *value
)
2067 if (!strcmp(value
, "8086"))
2069 if (!strcmp(value
, "186"))
2071 if (!strcmp(value
, "286"))
2073 if (!strcmp(value
, "386"))
2075 if (!strcmp(value
, "486"))
2077 if (!strcmp(value
, "586") || !nasm_stricmp(value
, "pentium"))
2079 if (!strcmp(value
, "686") ||
2080 !nasm_stricmp(value
, "ppro") ||
2081 !nasm_stricmp(value
, "pentiumpro") || !nasm_stricmp(value
, "p2"))
2083 if (!nasm_stricmp(value
, "p3") || !nasm_stricmp(value
, "katmai"))
2085 if (!nasm_stricmp(value
, "p4") || /* is this right? -- jrc */
2086 !nasm_stricmp(value
, "willamette"))
2087 return IF_WILLAMETTE
;
2088 if (!nasm_stricmp(value
, "prescott"))
2090 if (!nasm_stricmp(value
, "x64") ||
2091 !nasm_stricmp(value
, "x86-64"))
2093 if (!nasm_stricmp(value
, "ia64") ||
2094 !nasm_stricmp(value
, "ia-64") ||
2095 !nasm_stricmp(value
, "itanium") ||
2096 !nasm_stricmp(value
, "itanic") || !nasm_stricmp(value
, "merced"))
2099 nasm_error(pass0
< 2 ? ERR_NONFATAL
: ERR_FATAL
,
2100 "unknown 'cpu' type");
2102 return IF_PLEVEL
; /* the maximum level */
2105 static int get_bits(char *value
)
2109 if ((i
= atoi(value
)) == 16)
2110 return i
; /* set for a 16-bit segment */
2113 nasm_error(ERR_NONFATAL
,
2114 "cannot specify 32-bit segment on processor below a 386");
2117 } else if (i
== 64) {
2118 if (cpu
< IF_X86_64
) {
2119 nasm_error(ERR_NONFATAL
,
2120 "cannot specify 64-bit segment on processor below an x86-64");
2124 nasm_error(ERR_NONFATAL
,
2125 "%s output format does not support 64-bit code",
2130 nasm_error(pass0
< 2 ? ERR_NONFATAL
: ERR_FATAL
,
2131 "`%s' is not a valid segment size; must be 16, 32 or 64",