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 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU Lesser General Public License as
9 * published by the Free Software Foundation, Inc.,
10 * 51 Franklin St, Fifth Floor, Boston MA 02110-1301, USA; version 2.1,
11 * or, at your option, any later version, incorporated herein by
14 * Patches submitted to this file are required to be dual licensed
15 * under the LGPL 2.1+ and the 2-clause BSD license:
17 * Copyright 1996-2009 the NASM Authors - All rights reserved.
19 * Redistribution and use in source and binary forms, with or without
20 * modification, are permitted provided that the following
23 * * Redistributions of source code must retain the above copyright
24 * notice, this list of conditions and the following disclaimer.
25 * * Redistributions in binary form must reproduce the above
26 * copyright notice, this list of conditions and the following
27 * disclaimer in the documentation and/or other materials provided
28 * with the distribution.
30 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
31 * CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
32 * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
33 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
34 * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
35 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
36 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
37 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
38 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
39 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
40 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
41 * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
42 * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
44 * ----------------------------------------------------------------------- */
47 * The Netwide Assembler main program module
73 #include "output/outform.h"
76 struct forwrefinfo
{ /* info held on forward refs. */
81 static int get_bits(char *value
);
82 static uint32_t get_cpu(char *cpu_str
);
83 static void parse_cmdline(int, char **);
84 static void assemble_file(char *, StrList
**);
85 static void register_output_formats(void);
86 static void report_error_gnu(int severity
, const char *fmt
, ...);
87 static void report_error_vc(int severity
, const char *fmt
, ...);
88 static void report_error_common(int severity
, const char *fmt
,
90 static bool is_suppressed_warning(int severity
);
91 static void usage(void);
92 static efunc report_error
;
94 static int using_debug_info
, opt_verbose_info
;
95 bool tasm_compatible_mode
= false;
100 time_t official_compile_time
;
102 static char inname
[FILENAME_MAX
];
103 static char outname
[FILENAME_MAX
];
104 static char listname
[FILENAME_MAX
];
105 static char errname
[FILENAME_MAX
];
106 static int globallineno
; /* for forward-reference tracking */
107 /* static int pass = 0; */
108 static struct ofmt
*ofmt
= NULL
;
110 static FILE *error_file
; /* Where to write error messages */
112 static FILE *ofile
= NULL
;
113 int optimizing
= -1; /* number of optimization passes to take */
114 static int sb
, cmd_sb
= 16; /* by default */
115 static uint32_t cmd_cpu
= IF_PLEVEL
; /* highest level by default */
116 static uint32_t cpu
= IF_PLEVEL
; /* passed to insn_size & assemble.c */
117 int64_t global_offset_changed
; /* referenced in labels.c */
118 int64_t prev_offset_changed
;
121 static struct location location
;
122 int in_abs_seg
; /* Flag we are in ABSOLUTE seg */
123 int32_t abs_seg
; /* ABSOLUTE segment basis */
124 int32_t abs_offset
; /* ABSOLUTE offset */
126 static struct RAA
*offsets
;
128 static struct SAA
*forwrefs
; /* keep track of forward references */
129 static const struct forwrefinfo
*forwref
;
131 static Preproc
*preproc
;
133 op_normal
, /* Preprocess and assemble */
134 op_preprocess
, /* Preprocess only */
135 op_depend
, /* Generate dependencies */
137 static enum op_type operating_mode
;
138 /* Dependency flags */
139 static bool depend_emit_phony
= false;
140 static bool depend_missing_ok
= false;
141 static const char *depend_target
= NULL
;
142 static const char *depend_file
= NULL
;
145 * Which of the suppressible warnings are suppressed. Entry zero
146 * isn't an actual warning, but it used for -w+error/-Werror.
149 static bool warning_on
[ERR_WARN_MAX
+1]; /* Current state */
150 static bool warning_on_global
[ERR_WARN_MAX
+1]; /* Command-line state */
152 static const struct warning
{
156 } warnings
[ERR_WARN_MAX
+1] = {
157 {"error", "treat warnings as errors", false},
158 {"macro-params", "macro calls with wrong parameter count", true},
159 {"macro-selfref", "cyclic macro references", false},
160 {"macro-defaults", "macros with more default than optional parameters", true},
161 {"orphan-labels", "labels alone on lines without trailing `:'", true},
162 {"number-overflow", "numeric constant does not fit", true},
163 {"gnu-elf-extensions", "using 8- or 16-bit relocation in ELF32, a GNU extension", false},
164 {"float-overflow", "floating point overflow", true},
165 {"float-denorm", "floating point denormal", false},
166 {"float-underflow", "floating point underflow", false},
167 {"float-toolong", "too many digits in floating-point number", true},
168 {"user", "%warning directives", true},
172 * This is a null preprocessor which just copies lines from input
173 * to output. It's used when someone explicitly requests that NASM
174 * not preprocess their source file.
177 static void no_pp_reset(char *, int, efunc
, evalfunc
, ListGen
*, StrList
**);
178 static char *no_pp_getline(void);
179 static void no_pp_cleanup(int);
180 static Preproc no_pp
= {
187 * get/set current offset...
189 #define GET_CURR_OFFS (in_abs_seg?abs_offset:\
190 raa_read(offsets,location.segment))
191 #define SET_CURR_OFFS(x) (in_abs_seg?(void)(abs_offset=(x)):\
192 (void)(offsets=raa_write(offsets,location.segment,(x))))
194 static bool want_usage
;
195 static bool terminate_after_phase
;
196 int user_nolist
= 0; /* fbk 9/2/00 */
198 static void nasm_fputs(const char *line
, FILE * outfile
)
201 fputs(line
, outfile
);
207 /* Convert a struct tm to a POSIX-style time constant */
208 static int64_t posix_mktime(struct tm
*tm
)
211 int64_t y
= tm
->tm_year
;
213 /* See IEEE 1003.1:2004, section 4.14 */
215 t
= (y
-70)*365 + (y
-69)/4 - (y
-1)/100 + (y
+299)/400;
227 static void define_macros_early(void)
230 struct tm lt
, *lt_p
, gm
, *gm_p
;
233 lt_p
= localtime(&official_compile_time
);
237 strftime(temp
, sizeof temp
, "__DATE__=\"%Y-%m-%d\"", <
);
239 strftime(temp
, sizeof temp
, "__DATE_NUM__=%Y%m%d", <
);
241 strftime(temp
, sizeof temp
, "__TIME__=\"%H:%M:%S\"", <
);
243 strftime(temp
, sizeof temp
, "__TIME_NUM__=%H%M%S", <
);
247 gm_p
= gmtime(&official_compile_time
);
251 strftime(temp
, sizeof temp
, "__UTC_DATE__=\"%Y-%m-%d\"", &gm
);
253 strftime(temp
, sizeof temp
, "__UTC_DATE_NUM__=%Y%m%d", &gm
);
255 strftime(temp
, sizeof temp
, "__UTC_TIME__=\"%H:%M:%S\"", &gm
);
257 strftime(temp
, sizeof temp
, "__UTC_TIME_NUM__=%H%M%S", &gm
);
262 posix_time
= posix_mktime(&gm
);
264 posix_time
= posix_mktime(<
);
269 snprintf(temp
, sizeof temp
, "__POSIX_TIME__=%"PRId64
, posix_time
);
274 static void define_macros_late(void)
278 snprintf(temp
, sizeof(temp
), "__OUTPUT_FORMAT__=%s\n",
283 static void emit_dependencies(StrList
*list
)
289 if (depend_file
&& strcmp(depend_file
, "-")) {
290 deps
= fopen(depend_file
, "w");
292 report_error(ERR_NONFATAL
|ERR_NOFILE
|ERR_USAGE
,
293 "unable to write dependency file `%s'", depend_file
);
300 linepos
= fprintf(deps
, "%s:", depend_target
);
301 for (l
= list
; l
; l
= l
->next
) {
302 len
= strlen(l
->str
);
303 if (linepos
+ len
> 62) {
304 fprintf(deps
, " \\\n ");
307 fprintf(deps
, " %s", l
->str
);
310 fprintf(deps
, "\n\n");
312 for (l
= list
; l
; l
= nl
) {
313 if (depend_emit_phony
)
314 fprintf(deps
, "%s:\n\n", l
->str
);
324 int main(int argc
, char **argv
)
326 StrList
*depend_list
= NULL
, **depend_ptr
;
328 time(&official_compile_time
);
331 want_usage
= terminate_after_phase
= false;
332 report_error
= report_error_gnu
;
338 nasm_set_malloc_error(report_error
);
339 offsets
= raa_init();
340 forwrefs
= saa_init((int32_t)sizeof(struct forwrefinfo
));
343 operating_mode
= op_normal
;
347 register_output_formats();
349 /* Define some macros dependent on the runtime, but not
350 on the command line. */
351 define_macros_early();
353 parse_cmdline(argc
, argv
);
355 if (terminate_after_phase
) {
361 /* If debugging info is disabled, suppress any debug calls */
362 if (!using_debug_info
)
363 ofmt
->current_dfmt
= &null_debug_form
;
366 pp_extra_stdmac(ofmt
->stdmac
);
367 parser_global_info(ofmt
, &location
);
368 eval_global_info(ofmt
, lookup_label
, &location
);
370 /* define some macros dependent of command-line */
371 define_macros_late();
373 depend_ptr
= (depend_file
|| (operating_mode
== op_depend
))
374 ? &depend_list
: NULL
;
376 depend_target
= outname
;
378 switch (operating_mode
) {
383 if (depend_missing_ok
)
384 pp_include_path(NULL
); /* "assume generated" */
386 preproc
->reset(inname
, 0, report_error
, evaluate
, &nasmlist
,
388 if (outname
[0] == '\0')
389 ofmt
->filename(inname
, outname
, report_error
);
391 while ((line
= preproc
->getline()))
400 char *file_name
= NULL
;
401 int32_t prior_linnum
= 0;
405 ofile
= fopen(outname
, "w");
407 report_error(ERR_FATAL
| ERR_NOFILE
,
408 "unable to open output file `%s'",
413 location
.known
= false;
416 preproc
->reset(inname
, 3, report_error
, evaluate
, &nasmlist
,
419 while ((line
= preproc
->getline())) {
421 * We generate %line directives if needed for later programs
423 int32_t linnum
= prior_linnum
+= lineinc
;
424 int altline
= src_get(&linnum
, &file_name
);
426 if (altline
== 1 && lineinc
== 1)
427 nasm_fputs("", ofile
);
429 lineinc
= (altline
!= -1 || lineinc
!= 1);
430 fprintf(ofile
? ofile
: stdout
,
431 "%%line %"PRId32
"+%d %s\n", linnum
, lineinc
,
434 prior_linnum
= linnum
;
436 nasm_fputs(line
, ofile
);
439 nasm_free(file_name
);
443 if (ofile
&& terminate_after_phase
)
451 * We must call ofmt->filename _anyway_, even if the user
452 * has specified their own output file, because some
453 * formats (eg OBJ and COFF) use ofmt->filename to find out
454 * the name of the input file and then put that inside the
457 ofmt
->filename(inname
, outname
, report_error
);
459 ofile
= fopen(outname
, "wb");
461 report_error(ERR_FATAL
| ERR_NOFILE
,
462 "unable to open output file `%s'", outname
);
466 * We must call init_labels() before ofmt->init() since
467 * some object formats will want to define labels in their
468 * init routines. (eg OS/2 defines the FLAT group)
472 ofmt
->init(ofile
, report_error
, define_label
, evaluate
);
473 ofmt
->current_dfmt
->init(ofmt
, NULL
, ofile
, report_error
);
475 assemble_file(inname
, depend_ptr
);
477 if (!terminate_after_phase
) {
478 ofmt
->cleanup(using_debug_info
);
482 * Despite earlier comments, we need this fclose.
483 * The object output drivers only fclose on cleanup,
484 * and we just skipped that.
496 if (depend_list
&& !terminate_after_phase
)
497 emit_dependencies(depend_list
);
507 return terminate_after_phase
;
511 * Get a parameter for a command line option.
512 * First arg must be in the form of e.g. -f...
514 static char *get_param(char *p
, char *q
, bool *advance
)
517 if (p
[2]) { /* the parameter's in the option */
519 while (nasm_isspace(*p
))
527 report_error(ERR_NONFATAL
| ERR_NOFILE
| ERR_USAGE
,
528 "option `-%c' requires an argument", p
[1]);
535 static void copy_filename(char *dst
, const char *src
)
537 size_t len
= strlen(src
);
539 if (len
>= (size_t)FILENAME_MAX
) {
540 report_error(ERR_FATAL
| ERR_NOFILE
, "file name too long");
543 strncpy(dst
, src
, FILENAME_MAX
);
547 * Convert a string to Make-safe form
549 static char *quote_for_make(const char *str
)
554 size_t n
= 1; /* Terminating zero */
560 for (p
= str
; *p
; p
++) {
564 /* Convert N backslashes + ws -> 2N+1 backslashes + ws */
584 /* Convert N backslashes at the end of filename to 2N backslashes */
588 os
= q
= nasm_malloc(n
);
591 for (p
= str
; *p
; p
++) {
634 #define OPT_POSTFIX 1
635 struct textargs textopts
[] = {
636 {"prefix", OPT_PREFIX
},
637 {"postfix", OPT_POSTFIX
},
641 static bool stopoptions
= false;
642 static bool process_arg(char *p
, char *q
)
646 bool advance
= false;
652 if (p
[0] == '-' && !stopoptions
) {
653 if (strchr("oOfpPdDiIlFXuUZwW", p
[1])) {
654 /* These parameters take values */
655 if (!(param
= get_param(p
, q
, &advance
)))
664 case 'o': /* output file */
665 copy_filename(outname
, param
);
668 case 'f': /* output format */
669 ofmt
= ofmt_find(param
);
671 report_error(ERR_FATAL
| ERR_NOFILE
| ERR_USAGE
,
672 "unrecognised output format `%s' - "
673 "use -hf for a list", param
);
677 case 'O': /* Optimization level */
682 /* Naked -O == -Ox */
683 optimizing
= INT_MAX
>> 1; /* Almost unlimited */
687 case '0': case '1': case '2': case '3': case '4':
688 case '5': case '6': case '7': case '8': case '9':
689 opt
= strtoul(param
, ¶m
, 10);
691 /* -O0 -> optimizing == -1, 0.98 behaviour */
692 /* -O1 -> optimizing == 0, 0.98.09 behaviour */
694 optimizing
= opt
- 1;
702 opt_verbose_info
= true;
707 optimizing
= INT_MAX
>> 1; /* Almost unlimited */
711 report_error(ERR_FATAL
,
712 "unknown optimization option -O%c\n",
721 case 'p': /* pre-include */
723 pp_pre_include(param
);
726 case 'd': /* pre-define */
728 pp_pre_define(param
);
731 case 'u': /* un-define */
733 pp_pre_undefine(param
);
736 case 'i': /* include search path */
738 pp_include_path(param
);
741 case 'l': /* listing file */
742 copy_filename(listname
, param
);
745 case 'Z': /* error messages file */
746 strcpy(errname
, param
);
749 case 'F': /* specify debug format */
750 ofmt
->current_dfmt
= dfmt_find(ofmt
, param
);
751 if (!ofmt
->current_dfmt
) {
752 report_error(ERR_FATAL
| ERR_NOFILE
| ERR_USAGE
,
753 "unrecognized debug format `%s' for"
754 " output format `%s'",
755 param
, ofmt
->shortname
);
757 using_debug_info
= true;
760 case 'X': /* specify error reporting format */
761 if (nasm_stricmp("vc", param
) == 0)
762 report_error
= report_error_vc
;
763 else if (nasm_stricmp("gnu", param
) == 0)
764 report_error
= report_error_gnu
;
766 report_error(ERR_FATAL
| ERR_NOFILE
| ERR_USAGE
,
767 "unrecognized error reporting format `%s'",
772 using_debug_info
= true;
777 ("usage: nasm [-@ response file] [-o outfile] [-f format] "
779 " [options...] [--] filename\n"
780 " or nasm -v for version info\n\n"
781 " -t assemble in SciTech TASM compatible mode\n"
782 " -g generate debug information in selected format.\n");
784 (" -E (or -e) preprocess only (writes output to stdout by default)\n"
785 " -a don't preprocess (assemble only)\n"
786 " -M generate Makefile dependencies on stdout\n"
787 " -MG d:o, missing files assumed generated\n\n"
788 " -Z<file> redirect error messages to file\n"
789 " -s redirect error messages to stdout\n\n"
790 " -F format select a debugging format\n\n"
791 " -I<path> adds a pathname to the include file path\n");
793 (" -O<digit> optimize branch offsets (-O0 disables, default)\n"
794 " -P<file> pre-includes a file\n"
795 " -D<macro>[=<value>] pre-defines a macro\n"
796 " -U<macro> undefines a macro\n"
797 " -X<format> specifies error reporting format (gnu or vc)\n"
798 " -w+foo enables warning foo (equiv. -Wfoo)\n"
799 " -w-foo disable warning foo (equiv. -Wno-foo)\n"
801 for (i
= 0; i
<= ERR_WARN_MAX
; i
++)
802 printf(" %-23s %s (default %s)\n",
803 warnings
[i
].name
, warnings
[i
].help
,
804 warnings
[i
].enabled
? "on" : "off");
806 ("\nresponse files should contain command line parameters"
807 ", one per line.\n");
809 printf("\nvalid output formats for -f are"
810 " (`*' denotes default):\n");
811 ofmt_list(ofmt
, stdout
);
813 printf("\nFor a list of valid output formats, use -hf.\n");
814 printf("For a list of debug formats, use -f <form> -y.\n");
816 exit(0); /* never need usage message here */
820 printf("\nvalid debug formats for '%s' output format are"
821 " ('*' denotes default):\n", ofmt
->shortname
);
822 dfmt_list(ofmt
, stdout
);
827 tasm_compatible_mode
= true;
831 printf("NASM version %s compiled on %s%s\n",
832 nasm_version
, nasm_date
, nasm_compile_options
);
833 exit(0); /* never need usage message here */
836 case 'e': /* preprocess only */
838 operating_mode
= op_preprocess
;
841 case 'a': /* assemble only - don't preprocess */
846 if (param
[0] == 'n' && param
[1] == 'o' && param
[2] == '-') {
855 if (param
[0] != '+' && param
[0] != '-') {
856 report_error(ERR_NONFATAL
| ERR_NOFILE
| ERR_USAGE
,
857 "invalid option to `-w'");
860 do_warn
= (param
[0] == '+');
864 for (i
= 0; i
<= ERR_WARN_MAX
; i
++)
865 if (!nasm_stricmp(param
, warnings
[i
].name
))
867 if (i
<= ERR_WARN_MAX
)
868 warning_on_global
[i
] = do_warn
;
869 else if (!nasm_stricmp(param
, "all"))
870 for (i
= 1; i
<= ERR_WARN_MAX
; i
++)
871 warning_on_global
[i
] = do_warn
;
872 else if (!nasm_stricmp(param
, "none"))
873 for (i
= 1; i
<= ERR_WARN_MAX
; i
++)
874 warning_on_global
[i
] = !do_warn
;
876 report_error(ERR_NONFATAL
| ERR_NOFILE
| ERR_USAGE
,
877 "invalid warning `%s'", param
);
883 operating_mode
= op_depend
;
886 operating_mode
= op_depend
;
887 depend_missing_ok
= true;
890 depend_emit_phony
= true;
901 depend_target
= quote_for_make(q
);
905 report_error(ERR_NONFATAL
|ERR_NOFILE
|ERR_USAGE
,
906 "unknown dependency option `-M%c'", p
[2]);
909 if (advance
&& (!q
|| !q
[0])) {
910 report_error(ERR_NONFATAL
|ERR_NOFILE
|ERR_USAGE
,
911 "option `-M%c' requires a parameter", p
[2]);
920 if (p
[2] == 0) { /* -- => stop processing options */
924 for (s
= 0; textopts
[s
].label
; s
++) {
925 if (!nasm_stricmp(p
+ 2, textopts
[s
].label
)) {
936 report_error(ERR_NONFATAL
| ERR_NOFILE
|
938 "option `--%s' requires an argument",
942 advance
= 1, param
= q
;
945 if (s
== OPT_PREFIX
) {
946 strncpy(lprefix
, param
, PREFIX_MAX
- 1);
947 lprefix
[PREFIX_MAX
- 1] = 0;
950 if (s
== OPT_POSTFIX
) {
951 strncpy(lpostfix
, param
, POSTFIX_MAX
- 1);
952 lpostfix
[POSTFIX_MAX
- 1] = 0;
959 report_error(ERR_NONFATAL
| ERR_NOFILE
| ERR_USAGE
,
960 "unrecognised option `--%s'", p
+ 2);
968 if (!ofmt
->setinfo(GI_SWITCH
, &p
))
969 report_error(ERR_NONFATAL
| ERR_NOFILE
| ERR_USAGE
,
970 "unrecognised option `-%c'", p
[1]);
975 report_error(ERR_NONFATAL
| ERR_NOFILE
| ERR_USAGE
,
976 "more than one input file specified");
978 copy_filename(inname
, p
);
985 #define ARG_BUF_DELTA 128
987 static void process_respfile(FILE * rfile
)
989 char *buffer
, *p
, *q
, *prevarg
;
990 int bufsize
, prevargsize
;
992 bufsize
= prevargsize
= ARG_BUF_DELTA
;
993 buffer
= nasm_malloc(ARG_BUF_DELTA
);
994 prevarg
= nasm_malloc(ARG_BUF_DELTA
);
997 while (1) { /* Loop to handle all lines in file */
999 while (1) { /* Loop to handle long lines */
1000 q
= fgets(p
, bufsize
- (p
- buffer
), rfile
);
1004 if (p
> buffer
&& p
[-1] == '\n')
1006 if (p
- buffer
> bufsize
- 10) {
1008 offset
= p
- buffer
;
1009 bufsize
+= ARG_BUF_DELTA
;
1010 buffer
= nasm_realloc(buffer
, bufsize
);
1011 p
= buffer
+ offset
;
1015 if (!q
&& p
== buffer
) {
1017 process_arg(prevarg
, NULL
);
1024 * Play safe: remove CRs, LFs and any spurious ^Zs, if any of
1025 * them are present at the end of the line.
1027 *(p
= &buffer
[strcspn(buffer
, "\r\n\032")]) = '\0';
1029 while (p
> buffer
&& nasm_isspace(p
[-1]))
1033 while (nasm_isspace(*p
))
1036 if (process_arg(prevarg
, p
))
1039 if ((int) strlen(p
) > prevargsize
- 10) {
1040 prevargsize
+= ARG_BUF_DELTA
;
1041 prevarg
= nasm_realloc(prevarg
, prevargsize
);
1043 strncpy(prevarg
, p
, prevargsize
);
1047 /* Function to process args from a string of args, rather than the
1048 * argv array. Used by the environment variable and response file
1051 static void process_args(char *args
)
1053 char *p
, *q
, *arg
, *prevarg
;
1054 char separator
= ' ';
1057 if (*p
&& *p
!= '-')
1062 while (*p
&& *p
!= separator
)
1064 while (*p
== separator
)
1068 if (process_arg(prevarg
, arg
))
1072 process_arg(arg
, NULL
);
1075 static void process_response_file(const char *file
)
1078 FILE *f
= fopen(file
, "r");
1083 while (fgets(str
, sizeof str
, f
)) {
1089 static void parse_cmdline(int argc
, char **argv
)
1092 char *envreal
, *envcopy
= NULL
, *p
, *arg
;
1095 *inname
= *outname
= *listname
= *errname
= '\0';
1096 for (i
= 0; i
<= ERR_WARN_MAX
; i
++)
1097 warning_on_global
[i
] = warnings
[i
].enabled
;
1100 * First, process the NASMENV environment variable.
1102 envreal
= getenv("NASMENV");
1105 envcopy
= nasm_strdup(envreal
);
1106 process_args(envcopy
);
1111 * Now process the actual command line.
1116 if (argv
[0][0] == '@') {
1117 /* We have a response file, so process this as a set of
1118 * arguments like the environment variable. This allows us
1119 * to have multiple arguments on a single line, which is
1120 * different to the -@resp file processing below for regular
1123 process_response_file(argv
[0]+1);
1127 if (!stopoptions
&& argv
[0][0] == '-' && argv
[0][1] == '@') {
1128 p
= get_param(argv
[0], argc
> 1 ? argv
[1] : NULL
, &advance
);
1130 rfile
= fopen(p
, "r");
1132 process_respfile(rfile
);
1135 report_error(ERR_NONFATAL
| ERR_NOFILE
| ERR_USAGE
,
1136 "unable to open response file `%s'", p
);
1139 advance
= process_arg(argv
[0], argc
> 1 ? argv
[1] : NULL
);
1140 argv
+= advance
, argc
-= advance
;
1143 /* Look for basic command line typos. This definitely doesn't
1144 catch all errors, but it might help cases of fumbled fingers. */
1146 report_error(ERR_NONFATAL
| ERR_NOFILE
| ERR_USAGE
,
1147 "no input file specified");
1148 else if (!strcmp(inname
, errname
) ||
1149 !strcmp(inname
, outname
) ||
1150 !strcmp(inname
, listname
) ||
1151 (depend_file
&& !strcmp(inname
, depend_file
)))
1152 report_error(ERR_FATAL
| ERR_NOFILE
| ERR_USAGE
,
1153 "file `%s' is both input and output file",
1157 error_file
= fopen(errname
, "w");
1159 error_file
= stderr
; /* Revert to default! */
1160 report_error(ERR_FATAL
| ERR_NOFILE
| ERR_USAGE
,
1161 "cannot open file `%s' for error messages",
1167 /* List of directives */
1169 D_NONE
, D_ABSOLUTE
, D_BITS
, D_COMMON
, D_CPU
, D_DEBUG
, D_DEFAULT
,
1170 D_EXTERN
, D_FLOAT
, D_GLOBAL
, D_LIST
, D_SECTION
, D_SEGMENT
, D_WARNING
1172 static const char *directives
[] = {
1173 "", "absolute", "bits", "common", "cpu", "debug", "default",
1174 "extern", "float", "global", "list", "section", "segment", "warning"
1176 static enum directives
getkw(char **directive
, char **value
);
1178 static void assemble_file(char *fname
, StrList
**depend_ptr
)
1180 char *directive
, *value
, *p
, *q
, *special
, *line
, debugid
[80];
1186 struct tokenval tokval
;
1190 if (cmd_sb
== 32 && cmd_cpu
< IF_386
)
1191 report_error(ERR_FATAL
, "command line: "
1192 "32-bit segment size requires a higher cpu");
1194 pass_max
= prev_offset_changed
= (INT_MAX
>> 1) + 2; /* Almost unlimited */
1195 for (passn
= 1; pass0
<= 2; passn
++) {
1199 pass1
= pass0
== 2 ? 2 : 1; /* 1, 1, 1, ..., 1, 2 */
1200 pass2
= passn
> 1 ? 2 : 1; /* 1, 2, 2, ..., 2, 2 */
1201 /* pass0 0, 0, 0, ..., 1, 2 */
1203 def_label
= passn
> 1 ? redefine_label
: define_label
;
1205 globalbits
= sb
= cmd_sb
; /* set 'bits' to command line default */
1209 nasmlist
.init(listname
, report_error
);
1212 global_offset_changed
= 0; /* set by redefine_label */
1213 location
.segment
= ofmt
->section(NULL
, pass2
, &sb
);
1216 saa_rewind(forwrefs
);
1217 forwref
= saa_rstruct(forwrefs
);
1219 offsets
= raa_init();
1221 preproc
->reset(fname
, pass1
, report_error
, evaluate
, &nasmlist
,
1222 pass1
== 2 ? depend_ptr
: NULL
);
1223 memcpy(warning_on
, warning_on_global
, (ERR_WARN_MAX
+1) * sizeof(bool));
1227 location
.known
= true;
1228 location
.offset
= offs
= GET_CURR_OFFS
;
1230 while ((line
= preproc
->getline())) {
1235 * Here we parse our directives; this is not handled by the
1236 * 'real' parser. This really should be a separate function.
1239 d
= getkw(&directive
, &value
);
1244 case D_SEGMENT
: /* [SEGMENT n] */
1246 seg
= ofmt
->section(value
, pass2
, &sb
);
1247 if (seg
== NO_SEG
) {
1248 report_error(pass1
== 1 ? ERR_NONFATAL
: ERR_PANIC
,
1249 "segment name `%s' not recognized",
1253 location
.segment
= seg
;
1256 case D_EXTERN
: /* [EXTERN label:special] */
1258 value
++; /* skip initial $ if present */
1261 while (*q
&& *q
!= ':')
1265 ofmt
->symdef(value
, 0L, 0L, 3, q
);
1267 } else if (passn
== 1) {
1272 while (*q
&& *q
!= ':') {
1278 report_error(ERR_NONFATAL
,
1279 "identifier expected after EXTERN");
1287 if (!is_extern(value
)) { /* allow re-EXTERN to be ignored */
1289 pass0
= 1; /* fake pass 1 in labels.c */
1290 declare_as_global(value
, special
,
1292 define_label(value
, seg_alloc(), 0L, NULL
,
1293 false, true, ofmt
, report_error
);
1296 } /* else pass0 == 1 */
1298 case D_BITS
: /* [BITS bits] */
1299 globalbits
= sb
= get_bits(value
);
1301 case D_GLOBAL
: /* [GLOBAL symbol:special] */
1303 value
++; /* skip initial $ if present */
1304 if (pass0
== 2) { /* pass 2 */
1306 while (*q
&& *q
!= ':')
1310 ofmt
->symdef(value
, 0L, 0L, 3, q
);
1312 } else if (pass2
== 1) { /* pass == 1 */
1317 while (*q
&& *q
!= ':') {
1323 report_error(ERR_NONFATAL
,
1324 "identifier expected after GLOBAL");
1332 declare_as_global(value
, special
, report_error
);
1335 case D_COMMON
: /* [COMMON symbol size:special] */
1340 value
++; /* skip initial $ if present */
1345 while (*p
&& !nasm_isspace(*p
)) {
1351 report_error(ERR_NONFATAL
,
1352 "identifier expected after COMMON");
1356 while (*p
&& nasm_isspace(*p
))
1359 while (*q
&& *q
!= ':')
1367 size
= readnum(p
, &rn_error
);
1369 report_error(ERR_NONFATAL
,
1370 "invalid size specified"
1371 " in COMMON declaration");
1375 report_error(ERR_NONFATAL
,
1376 "no size specified in"
1377 " COMMON declaration");
1382 define_common(value
, seg_alloc(), size
,
1383 special
, ofmt
, report_error
);
1384 } else if (pass0
== 2) {
1385 ofmt
->symdef(value
, 0L, 0L, 3, special
);
1389 case D_ABSOLUTE
: /* [ABSOLUTE address] */
1391 stdscan_bufptr
= value
;
1392 tokval
.t_type
= TOKEN_INVALID
;
1393 e
= evaluate(stdscan
, NULL
, &tokval
, NULL
, pass2
,
1394 report_error
, NULL
);
1397 report_error(pass0
==
1398 1 ? ERR_NONFATAL
: ERR_PANIC
,
1399 "cannot use non-relocatable expression as "
1400 "ABSOLUTE address");
1402 abs_seg
= reloc_seg(e
);
1403 abs_offset
= reloc_value(e
);
1405 } else if (passn
== 1)
1406 abs_offset
= 0x100; /* don't go near zero in case of / */
1408 report_error(ERR_PANIC
, "invalid ABSOLUTE address "
1411 location
.segment
= NO_SEG
;
1413 case D_DEBUG
: /* [DEBUG] */
1419 while (*p
&& !nasm_isspace(*p
)) {
1426 report_error(passn
== 1 ? ERR_NONFATAL
: ERR_PANIC
,
1427 "identifier expected after DEBUG");
1430 while (*p
&& nasm_isspace(*p
))
1433 ofmt
->current_dfmt
->debug_directive(debugid
, p
);
1435 case D_WARNING
: /* [WARNING {+|-|*}warn-name] */
1436 while (*value
&& nasm_isspace(*value
))
1440 case '-': validid
= 0; value
++; break;
1441 case '+': validid
= 1; value
++; break;
1442 case '*': validid
= 2; value
++; break;
1443 default: validid
= 1; break;
1446 for (i
= 1; i
<= ERR_WARN_MAX
; i
++)
1447 if (!nasm_stricmp(value
, warnings
[i
].name
))
1449 if (i
<= ERR_WARN_MAX
) {
1452 warning_on
[i
] = false;
1455 warning_on
[i
] = true;
1458 warning_on
[i
] = warning_on_global
[i
];
1463 report_error(ERR_NONFATAL
,
1464 "invalid warning id in WARNING directive");
1466 case D_CPU
: /* [CPU] */
1467 cpu
= get_cpu(value
);
1469 case D_LIST
: /* [LIST {+|-}] */
1470 while (*value
&& nasm_isspace(*value
))
1473 if (*value
== '+') {
1476 if (*value
== '-') {
1483 case D_DEFAULT
: /* [DEFAULT] */
1485 stdscan_bufptr
= value
;
1486 tokval
.t_type
= TOKEN_INVALID
;
1487 if (stdscan(NULL
, &tokval
) == TOKEN_SPECIAL
) {
1488 switch ((int)tokval
.t_integer
) {
1504 if (float_option(value
)) {
1505 report_error(pass1
== 1 ? ERR_NONFATAL
: ERR_PANIC
,
1506 "unknown 'float' directive: %s",
1511 if (!ofmt
->directive(directive
, value
, pass2
))
1512 report_error(pass1
== 1 ? ERR_NONFATAL
: ERR_PANIC
,
1513 "unrecognised directive [%s]",
1517 report_error(ERR_NONFATAL
,
1518 "invalid parameter to [%s] directive",
1521 } else { /* it isn't a directive */
1523 parse_line(pass1
, line
, &output_ins
,
1524 report_error
, evaluate
, def_label
);
1526 if (optimizing
> 0) {
1527 if (forwref
!= NULL
&& globallineno
== forwref
->lineno
) {
1528 output_ins
.forw_ref
= true;
1530 output_ins
.oprs
[forwref
->operand
].opflags
|=
1532 forwref
= saa_rstruct(forwrefs
);
1533 } while (forwref
!= NULL
1534 && forwref
->lineno
== globallineno
);
1536 output_ins
.forw_ref
= false;
1538 if (output_ins
.forw_ref
) {
1540 for (i
= 0; i
< output_ins
.operands
; i
++) {
1541 if (output_ins
.oprs
[i
].
1542 opflags
& OPFLAG_FORWARD
) {
1543 struct forwrefinfo
*fwinf
=
1544 (struct forwrefinfo
*)
1545 saa_wstruct(forwrefs
);
1546 fwinf
->lineno
= globallineno
;
1555 if (output_ins
.opcode
== I_EQU
) {
1558 * Special `..' EQUs get processed in pass two,
1559 * except `..@' macro-processor EQUs which are done
1560 * in the normal place.
1562 if (!output_ins
.label
)
1563 report_error(ERR_NONFATAL
,
1564 "EQU not preceded by label");
1566 else if (output_ins
.label
[0] != '.' ||
1567 output_ins
.label
[1] != '.' ||
1568 output_ins
.label
[2] == '@') {
1569 if (output_ins
.operands
== 1 &&
1570 (output_ins
.oprs
[0].type
& IMMEDIATE
) &&
1571 output_ins
.oprs
[0].wrt
== NO_SEG
) {
1572 bool isext
= !!(output_ins
.oprs
[0].opflags
1574 def_label(output_ins
.label
,
1575 output_ins
.oprs
[0].segment
,
1576 output_ins
.oprs
[0].offset
, NULL
,
1579 } else if (output_ins
.operands
== 2
1580 && (output_ins
.oprs
[0].type
& IMMEDIATE
)
1581 && (output_ins
.oprs
[0].type
& COLON
)
1582 && output_ins
.oprs
[0].segment
== NO_SEG
1583 && output_ins
.oprs
[0].wrt
== NO_SEG
1584 && (output_ins
.oprs
[1].type
& IMMEDIATE
)
1585 && output_ins
.oprs
[1].segment
== NO_SEG
1586 && output_ins
.oprs
[1].wrt
== NO_SEG
) {
1587 def_label(output_ins
.label
,
1588 output_ins
.oprs
[0].offset
| SEG_ABS
,
1589 output_ins
.oprs
[1].offset
,
1590 NULL
, false, false, ofmt
,
1593 report_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, ofmt
,
1611 } else if (output_ins
.operands
== 2
1612 && (output_ins
.oprs
[0].
1614 && (output_ins
.oprs
[0].type
& COLON
)
1615 && output_ins
.oprs
[0].segment
==
1617 && (output_ins
.oprs
[1].
1619 && output_ins
.oprs
[1].segment
==
1621 define_label(output_ins
.label
,
1624 output_ins
.oprs
[1].offset
,
1625 NULL
, false, false, ofmt
,
1628 report_error(ERR_NONFATAL
,
1629 "bad syntax for EQU");
1632 } else { /* instruction isn't an EQU */
1636 int64_t l
= insn_size(location
.segment
, offs
, sb
, cpu
,
1637 &output_ins
, report_error
);
1639 /* if (using_debug_info) && output_ins.opcode != -1) */
1640 if (using_debug_info
)
1641 { /* fbk 03/25/01 */
1642 /* this is done here so we can do debug type info */
1644 TYS_ELEMENTS(output_ins
.operands
);
1645 switch (output_ins
.opcode
) {
1648 TYS_ELEMENTS(output_ins
.oprs
[0].
1653 TYS_ELEMENTS(output_ins
.oprs
[0].
1658 TYS_ELEMENTS(output_ins
.oprs
[0].
1663 TYS_ELEMENTS(output_ins
.oprs
[0].
1668 TYS_ELEMENTS(output_ins
.oprs
[0].
1673 TYS_ELEMENTS(output_ins
.oprs
[0].
1678 TYS_ELEMENTS(output_ins
.oprs
[0].
1682 typeinfo
|= TY_BYTE
;
1685 typeinfo
|= TY_WORD
;
1688 if (output_ins
.eops_float
)
1689 typeinfo
|= TY_FLOAT
;
1691 typeinfo
|= TY_DWORD
;
1694 typeinfo
|= TY_QWORD
;
1697 typeinfo
|= TY_TBYTE
;
1700 typeinfo
|= TY_OWORD
;
1703 typeinfo
|= TY_YWORD
;
1706 typeinfo
= TY_LABEL
;
1710 ofmt
->current_dfmt
->debug_typevalue(typeinfo
);
1715 SET_CURR_OFFS(offs
);
1718 * else l == -1 => invalid instruction, which will be
1719 * flagged as an error on pass 2
1723 offs
+= assemble(location
.segment
, offs
, sb
, cpu
,
1724 &output_ins
, ofmt
, report_error
,
1726 SET_CURR_OFFS(offs
);
1730 cleanup_insn(&output_ins
);
1733 location
.offset
= offs
= GET_CURR_OFFS
;
1734 } /* end while (line = preproc->getline... */
1736 if (pass0
== 2 && global_offset_changed
&& !terminate_after_phase
)
1737 report_error(ERR_NONFATAL
,
1738 "phase error detected at end of assembly.");
1741 preproc
->cleanup(1);
1743 if ((passn
> 1 && !global_offset_changed
) || pass0
== 2) {
1745 } else if (global_offset_changed
&&
1746 global_offset_changed
< prev_offset_changed
) {
1747 prev_offset_changed
= global_offset_changed
;
1753 if (terminate_after_phase
)
1756 if ((stall_count
> 997) || (passn
>= pass_max
)) {
1757 /* We get here if the labels don't converge
1758 * Example: FOO equ FOO + 1
1760 report_error(ERR_NONFATAL
,
1761 "Can't find valid values for all labels "
1762 "after %d passes, giving up.", passn
);
1763 report_error(ERR_NONFATAL
,
1764 "Possible causes: recursive EQUs, macro abuse.");
1769 preproc
->cleanup(0);
1771 if (!terminate_after_phase
&& opt_verbose_info
) {
1772 /* -On and -Ov switches */
1773 fprintf(stdout
, "info: assembly required 1+%d+1 passes\n", passn
-3);
1777 static enum directives
getkw(char **directive
, char **value
)
1783 /* allow leading spaces or tabs */
1784 while (*buf
== ' ' || *buf
== '\t')
1792 while (*p
&& *p
!= ']')
1800 while (*p
&& *p
!= ';') {
1801 if (!nasm_isspace(*p
))
1807 *directive
= p
= buf
+ 1;
1808 while (*buf
&& *buf
!= ' ' && *buf
!= ']' && *buf
!= '\t')
1815 while (nasm_isspace(*buf
))
1816 buf
++; /* beppu - skip leading whitespace */
1823 return bsii(*directive
, directives
, elements(directives
));
1827 * gnu style error reporting
1828 * This function prints an error message to error_file in the
1829 * style used by GNU. An example would be:
1830 * file.asm:50: error: blah blah blah
1831 * where file.asm is the name of the file, 50 is the line number on
1832 * which the error occurs (or is detected) and "error:" is one of
1833 * the possible optional diagnostics -- it can be "error" or "warning"
1834 * or something else. Finally the line terminates with the actual
1837 * @param severity the severity of the warning or error
1838 * @param fmt the printf style format string
1840 static void report_error_gnu(int severity
, const char *fmt
, ...)
1843 char *currentfile
= NULL
;
1846 if (is_suppressed_warning(severity
))
1849 if (!(severity
& ERR_NOFILE
))
1850 src_get(&lineno
, ¤tfile
);
1853 fprintf(error_file
, "%s:%"PRId32
": ", currentfile
, lineno
);
1854 nasm_free(currentfile
);
1856 fputs("nasm: ", error_file
);
1860 report_error_common(severity
, fmt
, ap
);
1865 * MS style error reporting
1866 * This function prints an error message to error_file in the
1867 * style used by Visual C and some other Microsoft tools. An example
1869 * file.asm(50) : error: blah blah blah
1870 * where file.asm is the name of the file, 50 is the line number on
1871 * which the error occurs (or is detected) and "error:" is one of
1872 * the possible optional diagnostics -- it can be "error" or "warning"
1873 * or something else. Finally the line terminates with the actual
1876 * @param severity the severity of the warning or error
1877 * @param fmt the printf style format string
1879 static void report_error_vc(int severity
, const char *fmt
, ...)
1882 char *currentfile
= NULL
;
1885 if (is_suppressed_warning(severity
))
1888 if (!(severity
& ERR_NOFILE
))
1889 src_get(&lineno
, ¤tfile
);
1892 fprintf(error_file
, "%s(%"PRId32
") : ", currentfile
, lineno
);
1893 nasm_free(currentfile
);
1895 fputs("nasm: ", error_file
);
1899 report_error_common(severity
, fmt
, ap
);
1904 * check for supressed warning
1905 * checks for suppressed warning or pass one only warning and we're
1908 * @param severity the severity of the warning or error
1909 * @return true if we should abort error/warning printing
1911 static bool is_suppressed_warning(int severity
)
1914 * See if it's a suppressed warning.
1916 return (severity
& ERR_MASK
) == ERR_WARNING
&&
1917 (((severity
& ERR_WARN_MASK
) != 0 &&
1918 !warning_on
[(severity
& ERR_WARN_MASK
) >> ERR_WARN_SHR
]) ||
1919 /* See if it's a pass-one only warning and we're not in pass one. */
1920 ((severity
& ERR_PASS1
) && pass0
!= 1) ||
1921 ((severity
& ERR_PASS2
) && pass0
!= 2));
1925 * common error reporting
1926 * This is the common back end of the error reporting schemes currently
1927 * implemented. It prints the nature of the warning and then the
1928 * specific error message to error_file and may or may not return. It
1929 * doesn't return if the error severity is a "panic" or "debug" type.
1931 * @param severity the severity of the warning or error
1932 * @param fmt the printf style format string
1934 static void report_error_common(int severity
, const char *fmt
,
1937 switch (severity
& (ERR_MASK
|ERR_NO_SEVERITY
)) {
1939 fputs("warning: ", error_file
);
1942 fputs("error: ", error_file
);
1945 fputs("fatal: ", error_file
);
1948 fputs("panic: ", error_file
);
1951 fputs("debug: ", error_file
);
1957 vfprintf(error_file
, fmt
, args
);
1958 putc('\n', error_file
);
1960 if (severity
& ERR_USAGE
)
1963 switch (severity
& ERR_MASK
) {
1965 /* no further action, by definition */
1968 if (warning_on
[0]) /* Treat warnings as errors */
1969 terminate_after_phase
= true;
1972 terminate_after_phase
= true;
1981 exit(1); /* instantly die */
1982 break; /* placate silly compilers */
1985 /* abort(); *//* halt, catch fire, and dump core */
1991 static void usage(void)
1993 fputs("type `nasm -h' for help\n", error_file
);
1996 static void register_output_formats(void)
1998 ofmt
= ofmt_register(report_error
);
2001 #define BUF_DELTA 512
2003 static FILE *no_pp_fp
;
2004 static efunc no_pp_err
;
2005 static ListGen
*no_pp_list
;
2006 static int32_t no_pp_lineinc
;
2008 static void no_pp_reset(char *file
, int pass
, efunc error
, evalfunc eval
,
2009 ListGen
* listgen
, StrList
**deplist
)
2011 src_set_fname(nasm_strdup(file
));
2015 no_pp_fp
= fopen(file
, "r");
2017 no_pp_err(ERR_FATAL
| ERR_NOFILE
,
2018 "unable to open input file `%s'", file
);
2019 no_pp_list
= listgen
;
2020 (void)pass
; /* placate compilers */
2021 (void)eval
; /* placate compilers */
2024 StrList
*sl
= nasm_malloc(strlen(file
)+1+sizeof sl
->next
);
2026 strcpy(sl
->str
, file
);
2031 static char *no_pp_getline(void)
2033 char *buffer
, *p
, *q
;
2036 bufsize
= BUF_DELTA
;
2037 buffer
= nasm_malloc(BUF_DELTA
);
2038 src_set_linnum(src_get_linnum() + no_pp_lineinc
);
2040 while (1) { /* Loop to handle %line */
2043 while (1) { /* Loop to handle long lines */
2044 q
= fgets(p
, bufsize
- (p
- buffer
), no_pp_fp
);
2048 if (p
> buffer
&& p
[-1] == '\n')
2050 if (p
- buffer
> bufsize
- 10) {
2052 offset
= p
- buffer
;
2053 bufsize
+= BUF_DELTA
;
2054 buffer
= nasm_realloc(buffer
, bufsize
);
2055 p
= buffer
+ offset
;
2059 if (!q
&& p
== buffer
) {
2065 * Play safe: remove CRs, LFs and any spurious ^Zs, if any of
2066 * them are present at the end of the line.
2068 buffer
[strcspn(buffer
, "\r\n\032")] = '\0';
2070 if (!nasm_strnicmp(buffer
, "%line", 5)) {
2073 char *nm
= nasm_malloc(strlen(buffer
));
2074 if (sscanf(buffer
+ 5, "%"PRId32
"+%d %s", &ln
, &li
, nm
) == 3) {
2075 nasm_free(src_set_fname(nm
));
2085 no_pp_list
->line(LIST_READ
, buffer
);
2090 static void no_pp_cleanup(int pass
)
2092 (void)pass
; /* placate GCC */
2096 static uint32_t get_cpu(char *value
)
2098 if (!strcmp(value
, "8086"))
2100 if (!strcmp(value
, "186"))
2102 if (!strcmp(value
, "286"))
2104 if (!strcmp(value
, "386"))
2106 if (!strcmp(value
, "486"))
2108 if (!strcmp(value
, "586") || !nasm_stricmp(value
, "pentium"))
2110 if (!strcmp(value
, "686") ||
2111 !nasm_stricmp(value
, "ppro") ||
2112 !nasm_stricmp(value
, "pentiumpro") || !nasm_stricmp(value
, "p2"))
2114 if (!nasm_stricmp(value
, "p3") || !nasm_stricmp(value
, "katmai"))
2116 if (!nasm_stricmp(value
, "p4") || /* is this right? -- jrc */
2117 !nasm_stricmp(value
, "willamette"))
2118 return IF_WILLAMETTE
;
2119 if (!nasm_stricmp(value
, "prescott"))
2121 if (!nasm_stricmp(value
, "x64") ||
2122 !nasm_stricmp(value
, "x86-64"))
2124 if (!nasm_stricmp(value
, "ia64") ||
2125 !nasm_stricmp(value
, "ia-64") ||
2126 !nasm_stricmp(value
, "itanium") ||
2127 !nasm_stricmp(value
, "itanic") || !nasm_stricmp(value
, "merced"))
2130 report_error(pass0
< 2 ? ERR_NONFATAL
: ERR_FATAL
,
2131 "unknown 'cpu' type");
2133 return IF_PLEVEL
; /* the maximum level */
2136 static int get_bits(char *value
)
2140 if ((i
= atoi(value
)) == 16)
2141 return i
; /* set for a 16-bit segment */
2144 report_error(ERR_NONFATAL
,
2145 "cannot specify 32-bit segment on processor below a 386");
2148 } else if (i
== 64) {
2149 if (cpu
< IF_X86_64
) {
2150 report_error(ERR_NONFATAL
,
2151 "cannot specify 64-bit segment on processor below an x86-64");
2155 report_error(ERR_NONFATAL
,
2156 "%s output format does not support 64-bit code",
2161 report_error(pass0
< 2 ? ERR_NONFATAL
: ERR_FATAL
,
2162 "`%s' is not a valid segment size; must be 16, 32 or 64",