Remove obsolete comment
[nasm.git] / nasm.c
blobcdc936b55cee7d91a8a12b5d2be11cb2aa5f1b61
1 /* The Netwide Assembler main program module
3 * The Netwide Assembler is copyright (C) 1996 Simon Tatham and
4 * Julian Hall. All rights reserved. The software is
5 * redistributable under the licence given in the file "Licence"
6 * distributed in the NASM archive.
7 */
9 #include <stdio.h>
10 #include <stdarg.h>
11 #include <stdlib.h>
12 #include <string.h>
13 #include <ctype.h>
15 #include "nasm.h"
16 #include "nasmlib.h"
17 #include "insns.h"
18 #include "preproc.h"
19 #include "parser.h"
20 #include "eval.h"
21 #include "assemble.h"
22 #include "labels.h"
23 #include "outform.h"
24 #include "listing.h"
26 struct forwrefinfo { /* info held on forward refs. */
27 int lineno;
28 int operand;
31 static int get_bits (char *value);
32 static unsigned long get_cpu (char *cpu_str);
33 static void parse_cmdline (int, char **);
34 static void assemble_file (char *);
35 static int getkw (char **directive, char **value);
36 static void register_output_formats(void);
37 static void report_error_gnu (int severity, const char *fmt, ...);
38 static void report_error_vc (int severity, const char *fmt, ...);
39 static void report_error_common (int severity, const char *fmt, va_list args);
40 static int is_suppressed_warning (int severity);
41 static void usage(void);
42 static efunc report_error;
44 static int using_debug_info, opt_verbose_info;
45 int tasm_compatible_mode = FALSE;
46 int pass0;
48 static char inname[FILENAME_MAX];
49 static char outname[FILENAME_MAX];
50 static char listname[FILENAME_MAX];
51 static int globallineno; /* for forward-reference tracking */
52 /* static int pass = 0; */
53 static struct ofmt *ofmt = NULL;
55 static FILE *error_file; /* Where to write error messages */
57 static FILE *ofile = NULL;
58 int optimizing = -1; /* number of optimization passes to take */
59 static int sb, cmd_sb = 16; /* by default */
60 static unsigned long cmd_cpu = IF_PLEVEL; /* highest level by default */
61 static unsigned long cpu = IF_PLEVEL; /* passed to insn_size & assemble.c */
62 int global_offset_changed; /* referenced in labels.c */
64 static loc_t location;
65 int in_abs_seg; /* Flag we are in ABSOLUTE seg */
66 long abs_seg; /* ABSOLUTE segment basis */
67 long abs_offset; /* ABSOLUTE offset */
69 static struct RAA *offsets;
71 static struct SAA *forwrefs; /* keep track of forward references */
72 static struct forwrefinfo *forwref;
74 static Preproc *preproc;
75 enum op_type {
76 op_normal, /* Preprocess and assemble */
77 op_preprocess, /* Preprocess only */
78 op_depend /* Generate dependencies */
80 static enum op_type operating_mode;
83 * Which of the suppressible warnings are suppressed. Entry zero
84 * doesn't do anything. Initial defaults are given here.
86 static char suppressed[1+ERR_WARN_MAX] = {
87 0, TRUE, TRUE, TRUE, FALSE, TRUE
91 * The option names for the suppressible warnings. As before, entry
92 * zero does nothing.
94 static const char *suppressed_names[1+ERR_WARN_MAX] = {
95 NULL, "macro-params", "macro-selfref", "orphan-labels", "number-overflow",
96 "gnu-elf-extensions"
100 * The explanations for the suppressible warnings. As before, entry
101 * zero does nothing.
103 static const char *suppressed_what[1+ERR_WARN_MAX] = {
104 NULL,
105 "macro calls with wrong no. of params",
106 "cyclic macro self-references",
107 "labels alone on lines without trailing `:'",
108 "numeric constants greater than 0xFFFFFFFF",
109 "using 8- or 16-bit relocation in ELF, a GNU extension"
113 * This is a null preprocessor which just copies lines from input
114 * to output. It's used when someone explicitly requests that NASM
115 * not preprocess their source file.
118 static void no_pp_reset (char *, int, efunc, evalfunc, ListGen *);
119 static char *no_pp_getline (void);
120 static void no_pp_cleanup (int);
121 static Preproc no_pp = {
122 no_pp_reset,
123 no_pp_getline,
124 no_pp_cleanup
128 * get/set current offset...
130 #define GET_CURR_OFFS (in_abs_seg?abs_offset:\
131 raa_read(offsets,location.segment))
132 #define SET_CURR_OFFS(x) (in_abs_seg?(void)(abs_offset=(x)):\
133 (void)(offsets=raa_write(offsets,location.segment,(x))))
135 static int want_usage;
136 static int terminate_after_phase;
137 int user_nolist = 0; /* fbk 9/2/00 */
139 static void nasm_fputs(const char *line, FILE *outfile)
141 if (outfile) {
142 fputs(line, outfile);
143 fputc('\n', outfile);
144 } else
145 puts(line);
148 int main(int argc, char **argv)
150 pass0 = 1;
151 want_usage = terminate_after_phase = FALSE;
152 report_error = report_error_gnu;
154 nasm_set_malloc_error (report_error);
155 offsets = raa_init();
156 forwrefs = saa_init ((long)sizeof(struct forwrefinfo));
158 preproc = &nasmpp;
159 operating_mode = op_normal;
161 error_file = stderr;
163 seg_init();
165 register_output_formats();
167 parse_cmdline(argc, argv);
169 if (terminate_after_phase)
171 if (want_usage)
172 usage();
173 return 1;
176 if (ofmt->stdmac)
177 pp_extra_stdmac (ofmt->stdmac);
178 parser_global_info (ofmt, &location);
179 eval_global_info (ofmt, lookup_label, &location);
181 /* define some macros dependent of command-line */
183 char temp [64];
184 sprintf (temp, "__OUTPUT_FORMAT__=%s\n", ofmt->shortname);
185 pp_pre_define (temp);
188 switch ( operating_mode ) {
189 case op_depend:
191 char *line;
192 preproc->reset (inname, 0, report_error, evaluate, &nasmlist);
193 if (outname[0] == '\0')
194 ofmt->filename (inname, outname, report_error);
195 ofile = NULL;
196 fprintf(stdout, "%s: %s", outname, inname);
197 while ( (line = preproc->getline()) )
198 nasm_free (line);
199 preproc->cleanup(0);
200 putc('\n', stdout);
202 break;
204 case op_preprocess:
206 char *line;
207 char *file_name = NULL;
208 long prior_linnum=0;
209 int lineinc=0;
211 if (*outname) {
212 ofile = fopen(outname, "w");
213 if (!ofile)
214 report_error (ERR_FATAL | ERR_NOFILE,
215 "unable to open output file `%s'", outname);
216 } else
217 ofile = NULL;
219 location.known = FALSE;
221 /* pass = 1; */
222 preproc->reset (inname, 2, report_error, evaluate, &nasmlist);
223 while ( (line = preproc->getline()) ) {
225 * We generate %line directives if needed for later programs
227 long linnum = prior_linnum += lineinc;
228 int altline = src_get(&linnum, &file_name);
229 if (altline) {
230 if (altline==1 && lineinc==1)
231 nasm_fputs("", ofile);
232 else {
233 lineinc = (altline != -1 || lineinc!=1);
234 fprintf(ofile ? ofile : stdout, "%%line %ld+%d %s\n",
235 linnum, lineinc, file_name);
237 prior_linnum = linnum;
239 nasm_fputs(line, ofile);
240 nasm_free (line);
242 nasm_free(file_name);
243 preproc->cleanup(0);
244 if (ofile)
245 fclose(ofile);
246 if (ofile && terminate_after_phase)
247 remove(outname);
249 break;
251 case op_normal:
254 * We must call ofmt->filename _anyway_, even if the user
255 * has specified their own output file, because some
256 * formats (eg OBJ and COFF) use ofmt->filename to find out
257 * the name of the input file and then put that inside the
258 * file.
260 ofmt->filename (inname, outname, report_error);
262 ofile = fopen(outname, "wb");
263 if (!ofile) {
264 report_error (ERR_FATAL | ERR_NOFILE,
265 "unable to open output file `%s'", outname);
269 * We must call init_labels() before ofmt->init() since
270 * some object formats will want to define labels in their
271 * init routines. (eg OS/2 defines the FLAT group)
273 init_labels ();
275 ofmt->init (ofile, report_error, define_label, evaluate);
277 assemble_file (inname);
279 if (!terminate_after_phase) {
280 ofmt->cleanup (using_debug_info);
281 cleanup_labels ();
282 } else {
284 * We had an fclose on the output file here, but we
285 * actually do that in all the object file drivers as well,
286 * so we're leaving out the one here.
287 * fclose (ofile);
289 remove(outname);
290 if (listname[0])
291 remove(listname);
294 break;
297 if (want_usage)
298 usage();
300 raa_free (offsets);
301 saa_free (forwrefs);
302 eval_cleanup ();
303 nasmlib_cleanup ();
305 if (terminate_after_phase)
306 return 1;
307 else
308 return 0;
313 * Get a parameter for a command line option.
314 * First arg must be in the form of e.g. -f...
316 static char *get_param (char *p, char *q, int *advance)
318 *advance = 0;
319 if (p[2]) /* the parameter's in the option */
321 p += 2;
322 while (isspace(*p))
323 p++;
324 return p;
326 if (q && q[0])
328 *advance = 1;
329 return q;
331 report_error (ERR_NONFATAL | ERR_NOFILE | ERR_USAGE,
332 "option `-%c' requires an argument",
333 p[1]);
334 return NULL;
337 struct textargs
339 const char *label;
340 int value;
343 #define OPT_PREFIX 0
344 #define OPT_POSTFIX 1
345 struct textargs textopts[] =
347 {"prefix",OPT_PREFIX},
348 {"postfix",OPT_POSTFIX},
349 {NULL,0}
353 int stopoptions = 0;
354 static int process_arg (char *p, char *q)
356 char *param;
357 int i, advance = 0;
359 if (!p || !p[0])
360 return 0;
362 if (p[0]=='-' && ! stopoptions)
364 switch (p[1]) {
365 case 's':
366 error_file = stdout;
367 break;
368 case 'o': /* these parameters take values */
369 case 'O':
370 case 'f':
371 case 'p':
372 case 'P':
373 case 'd':
374 case 'D':
375 case 'i':
376 case 'I':
377 case 'l':
378 case 'E':
379 case 'F':
380 case 'X':
381 case 'u':
382 case 'U':
383 if ( !(param = get_param (p, q, &advance)) )
384 break;
385 if (p[1]=='o') { /* output file */
386 strcpy (outname, param);
387 } else if (p[1]=='f') { /* output format */
388 ofmt = ofmt_find(param);
389 if (!ofmt) {
390 report_error (ERR_FATAL | ERR_NOFILE | ERR_USAGE,
391 "unrecognised output format `%s' - "
392 "use -hf for a list",
393 param);
395 else
396 ofmt->current_dfmt = ofmt->debug_formats[0];
397 } else if (p[1]=='O') { /* Optimization level */
398 int opt;
399 opt = -99;
400 while (*param) {
401 if (isdigit(*param)) {
402 opt = atoi(param);
403 while(isdigit(*++param)) ;
404 if (opt<=0) optimizing = -1; /* 0.98 behaviour */
405 else if (opt==1) optimizing = 0; /* Two passes, 0.98.09 behavior */
406 else if (opt<=3) optimizing = opt*5; /* Multiple passes */
407 else optimizing = opt; /* Multiple passes */
408 } else {
409 if (*param == 'v' || *param == '+') {
410 ++param;
411 opt_verbose_info = TRUE;
412 opt = 0;
413 } else { /* garbage */
414 opt = -99;
415 break;
418 } /* while (*param) */
419 if (opt == -99) report_error(ERR_FATAL,
420 "command line optimization level must be 'v', 0..3 or <nn>");
421 } else if (p[1]=='P' || p[1]=='p') { /* pre-include */
422 pp_pre_include (param);
423 } else if (p[1]=='D' || p[1]=='d') { /* pre-define */
424 pp_pre_define (param);
425 } else if (p[1]=='U' || p[1]=='u') { /* un-define */
426 pp_pre_undefine (param);
427 } else if (p[1]=='I' || p[1]=='i') { /* include search path */
428 pp_include_path (param);
429 } else if (p[1]=='l') { /* listing file */
430 strcpy (listname, param);
431 } else if (p[1]=='E') { /* error messages file */
432 error_file = fopen(param, "w");
433 if ( !error_file ) {
434 error_file = stderr; /* Revert to default! */
435 report_error (ERR_FATAL | ERR_NOFILE | ERR_USAGE,
436 "cannot open file `%s' for error messages",
437 param);
439 } else if (p[1] == 'F') { /* specify debug format */
440 ofmt->current_dfmt = dfmt_find(ofmt, param);
441 if (!ofmt->current_dfmt) {
442 report_error (ERR_FATAL | ERR_NOFILE | ERR_USAGE,
443 "unrecognized debug format `%s' for"
444 " output format `%s'",
445 param, ofmt->shortname);
447 } else if (p[1] == 'X') { /* specify error reporting format */
448 if (nasm_stricmp("vc", param) == 0)
449 report_error = report_error_vc;
450 else if (nasm_stricmp("gnu", param) == 0)
451 report_error = report_error_gnu;
452 else
453 report_error (ERR_FATAL | ERR_NOFILE | ERR_USAGE,
454 "unrecognized error reporting format `%s'",
455 param);
457 break;
458 case 'g':
459 using_debug_info = TRUE;
460 break;
461 case 'h':
462 printf("usage: nasm [-@ response file] [-o outfile] [-f format] "
463 "[-l listfile]\n"
464 " [options...] [--] filename\n"
465 " or nasm -r for version info (obsolete)\n"
466 " or nasm -v for version info (preferred)\n\n"
467 " -t Assemble in SciTech TASM compatible mode\n"
468 " -g Generate debug information in selected format.\n");
469 printf(" -e preprocess only (writes output to stdout by default)\n"
470 " -a don't preprocess (assemble only)\n"
471 " -M generate Makefile dependencies on stdout\n\n"
472 " -E<file> redirect error messages to file\n"
473 " -s redirect error messages to stdout\n\n"
474 " -F format select a debugging format\n\n"
475 " -I<path> adds a pathname to the include file path\n");
476 printf(" -O<digit> optimize branch offsets (-O0 disables, default)\n"
477 " -P<file> pre-includes a file\n"
478 " -D<macro>[=<value>] pre-defines a macro\n"
479 " -U<macro> undefines a macro\n"
480 " -X<format> specifies error reporting format (gnu or vc)\n"
481 " -w+foo enables warnings about foo; -w-foo disables them\n"
482 "where foo can be:\n");
483 for (i=1; i<=ERR_WARN_MAX; i++)
484 printf(" %-23s %s (default %s)\n",
485 suppressed_names[i], suppressed_what[i],
486 suppressed[i] ? "off" : "on");
487 printf ("\nresponse files should contain command line parameters"
488 ", one per line.\n");
489 if (p[2] == 'f') {
490 printf("\nvalid output formats for -f are"
491 " (`*' denotes default):\n");
492 ofmt_list(ofmt, stdout);
494 else {
495 printf ("\nFor a list of valid output formats, use -hf.\n");
496 printf ("For a list of debug formats, use -f <form> -y.\n");
498 exit (0); /* never need usage message here */
499 break;
500 case 'y':
501 printf("\nvalid debug formats for '%s' output format are"
502 " ('*' denotes default):\n",
503 ofmt->shortname);
504 dfmt_list(ofmt, stdout);
505 exit(0);
506 break;
507 case 't':
508 tasm_compatible_mode = TRUE;
509 break;
510 case 'r':
511 case 'v':
513 const char *nasm_version_string =
514 "NASM version " NASM_VER " compiled on " __DATE__
515 #ifdef DEBUG
516 " with -DDEBUG"
517 #endif
519 puts(nasm_version_string);
520 exit (0); /* never need usage message here */
522 break;
523 case 'e': /* preprocess only */
524 operating_mode = op_preprocess;
525 break;
526 case 'a': /* assemble only - don't preprocess */
527 preproc = &no_pp;
528 break;
529 case 'w':
530 if (p[2] != '+' && p[2] != '-') {
531 report_error (ERR_NONFATAL | ERR_NOFILE | ERR_USAGE,
532 "invalid option to `-w'");
533 } else {
534 for (i=1; i<=ERR_WARN_MAX; i++)
535 if (!nasm_stricmp(p+3, suppressed_names[i]))
536 break;
537 if (i <= ERR_WARN_MAX)
538 suppressed[i] = (p[2] == '-');
539 else
540 report_error (ERR_NONFATAL | ERR_NOFILE | ERR_USAGE,
541 "invalid option to `-w'");
543 break;
544 case 'M':
545 operating_mode = op_depend;
546 break;
548 case '-':
550 int s;
552 if (p[2]==0) { /* -- => stop processing options */
553 stopoptions = 1;
554 break;
556 for(s=0; textopts[s].label; s++)
558 if(!nasm_stricmp(p+2, textopts[s].label))
560 break;
564 switch(s)
567 case OPT_PREFIX:
568 case OPT_POSTFIX:
570 if (!q)
572 report_error (ERR_NONFATAL | ERR_NOFILE | ERR_USAGE,
573 "option `--%s' requires an argument",
574 p+2);
575 break;
577 else
579 advance = 1, param = q;
582 if(s == OPT_PREFIX)
584 strncpy(lprefix,param,PREFIX_MAX-1);
585 lprefix[PREFIX_MAX-1]=0;
586 break;
588 if(s == OPT_POSTFIX)
590 strncpy(lpostfix,param,POSTFIX_MAX-1);
591 lpostfix[POSTFIX_MAX-1]=0;
592 break;
594 break;
596 default:
598 report_error (ERR_NONFATAL | ERR_NOFILE | ERR_USAGE,
599 "unrecognised option `--%s'",
600 p+2);
601 break;
604 break;
607 default:
608 if (!ofmt->setinfo(GI_SWITCH,&p))
609 report_error (ERR_NONFATAL | ERR_NOFILE | ERR_USAGE,
610 "unrecognised option `-%c'",
611 p[1]);
612 break;
615 else
617 if (*inname) {
618 report_error (ERR_NONFATAL | ERR_NOFILE | ERR_USAGE,
619 "more than one input file specified");
620 } else
621 strcpy(inname, p);
624 return advance;
627 #define ARG_BUF_DELTA 128
629 static void process_respfile (FILE *rfile)
631 char *buffer, *p, *q, *prevarg;
632 int bufsize, prevargsize;
634 bufsize = prevargsize = ARG_BUF_DELTA;
635 buffer = nasm_malloc(ARG_BUF_DELTA);
636 prevarg = nasm_malloc(ARG_BUF_DELTA);
637 prevarg[0] = '\0';
639 while (1) { /* Loop to handle all lines in file */
641 p = buffer;
642 while (1) { /* Loop to handle long lines */
643 q = fgets(p, bufsize-(p-buffer), rfile);
644 if (!q)
645 break;
646 p += strlen(p);
647 if (p > buffer && p[-1] == '\n')
648 break;
649 if (p-buffer > bufsize-10) {
650 int offset;
651 offset = p - buffer;
652 bufsize += ARG_BUF_DELTA;
653 buffer = nasm_realloc(buffer, bufsize);
654 p = buffer + offset;
658 if (!q && p == buffer) {
659 if (prevarg[0])
660 process_arg (prevarg, NULL);
661 nasm_free (buffer);
662 nasm_free (prevarg);
663 return;
667 * Play safe: remove CRs, LFs and any spurious ^Zs, if any of
668 * them are present at the end of the line.
670 *(p = &buffer[strcspn(buffer, "\r\n\032")]) = '\0';
672 while (p > buffer && isspace(p[-1]))
673 *--p = '\0';
675 p = buffer;
676 while (isspace(*p))
677 p++;
679 if (process_arg (prevarg, p))
680 *p = '\0';
682 if (strlen(p) > prevargsize-10) {
683 prevargsize += ARG_BUF_DELTA;
684 prevarg = nasm_realloc(prevarg, prevargsize);
686 strcpy (prevarg, p);
690 /* Function to process args from a string of args, rather than the
691 * argv array. Used by the environment variable and response file
692 * processing.
694 static void process_args (char *args) {
695 char *p, *q, *arg, *prevarg;
696 char separator = ' ';
698 p = args;
699 if (*p && *p != '-')
700 separator = *p++;
701 arg = NULL;
702 while (*p) {
703 q = p;
704 while (*p && *p != separator) p++;
705 while (*p == separator) *p++ = '\0';
706 prevarg = arg;
707 arg = q;
708 if (process_arg (prevarg, arg))
709 arg = NULL;
711 if (arg)
712 process_arg (arg, NULL);
715 static void parse_cmdline(int argc, char **argv)
717 FILE *rfile;
718 char *envreal, *envcopy=NULL, *p, *arg;
720 *inname = *outname = *listname = '\0';
723 * First, process the NASMENV environment variable.
725 envreal = getenv("NASMENV");
726 arg = NULL;
727 if (envreal) {
728 envcopy = nasm_strdup(envreal);
729 process_args(envcopy);
730 nasm_free (envcopy);
734 * Now process the actual command line.
736 while (--argc)
738 int i;
739 argv++;
740 if (argv[0][0] == '@') {
741 /* We have a response file, so process this as a set of
742 * arguments like the environment variable. This allows us
743 * to have multiple arguments on a single line, which is
744 * different to the -@resp file processing below for regular
745 * NASM.
747 char *str = malloc(2048);
748 FILE *f = fopen(&argv[0][1],"r");
749 if (!str) {
750 printf("out of memory");
751 exit(-1);
753 if (f) {
754 while (fgets(str,2048,f)) {
755 process_args(str);
757 fclose(f);
759 free(str);
760 argc--;
761 argv++;
763 if (!stopoptions && argv[0][0] == '-' && argv[0][1] == '@') {
764 if ((p = get_param (argv[0], argc > 1 ? argv[1] : NULL, &i))) {
765 if ((rfile = fopen(p, "r"))) {
766 process_respfile (rfile);
767 fclose(rfile);
768 } else
769 report_error (ERR_NONFATAL | ERR_NOFILE | ERR_USAGE,
770 "unable to open response file `%s'", p);
772 } else
773 i = process_arg (argv[0], argc > 1 ? argv[1] : NULL);
774 argv += i, argc -= i;
777 if (!*inname)
778 report_error (ERR_NONFATAL | ERR_NOFILE | ERR_USAGE,
779 "no input file specified");
783 static void assemble_file (char *fname)
785 char * directive, * value, * p, * q, * special, * line, debugid[80];
786 insn output_ins;
787 int i, rn_error, validid;
788 long seg, offs;
789 struct tokenval tokval;
790 expr * e;
791 int pass, pass_max;
792 int pass_cnt = 0; /* count actual passes */
794 if (cmd_sb == 32 && cmd_cpu < IF_386)
795 report_error(ERR_FATAL, "command line: "
796 "32-bit segment size requires a higher cpu");
798 pass_max = (optimizing>0 ? optimizing : 0) + 2; /* passes 1, optimizing, then 2 */
799 pass0 = !(optimizing>0); /* start at 1 if not optimizing */
800 for (pass = 1; pass <= pass_max && pass0 <= 2; pass++) {
801 int pass1, pass2;
802 ldfunc def_label;
804 pass1 = pass < pass_max ? 1 : 2; /* seq is 1, 1, 1,..., 1, 2 */
805 pass2 = pass > 1 ? 2 : 1; /* seq is 1, 2, 2,..., 2, 2 */
806 /* pass0 seq is 0, 0, 0,..., 1, 2 */
808 def_label = pass > 1 ? redefine_label : define_label;
811 sb = cmd_sb; /* set 'bits' to command line default */
812 cpu = cmd_cpu;
813 if (pass0 == 2) {
814 if (*listname)
815 nasmlist.init(listname, report_error);
817 in_abs_seg = FALSE;
818 global_offset_changed = FALSE; /* set by redefine_label */
819 location.segment = ofmt->section(NULL, pass2, &sb);
820 if (pass > 1) {
821 saa_rewind (forwrefs);
822 forwref = saa_rstruct (forwrefs);
823 raa_free (offsets);
824 offsets = raa_init();
826 preproc->reset(fname, pass1, report_error, evaluate, &nasmlist);
827 globallineno = 0;
828 if (pass == 1) location.known = TRUE;
829 location.offset = offs = GET_CURR_OFFS;
831 while ( (line = preproc->getline()) )
833 globallineno++;
835 /* here we parse our directives; this is not handled by the 'real'
836 * parser. */
837 directive = line;
838 if ( (i = getkw (&directive, &value)) )
840 switch (i) {
841 case 1: /* [SEGMENT n] */
842 seg = ofmt->section (value, pass2, &sb);
843 if (seg == NO_SEG) {
844 report_error (pass1==1 ? ERR_NONFATAL : ERR_PANIC,
845 "segment name `%s' not recognised",
846 value);
847 } else {
848 in_abs_seg = FALSE;
849 location.segment = seg;
851 break;
852 case 2: /* [EXTERN label:special] */
853 if (*value == '$') value++; /* skip initial $ if present */
854 if (pass0 == 2) {
855 q = value;
856 while (*q && *q != ':')
857 q++;
858 if (*q == ':') {
859 *q++ = '\0';
860 ofmt->symdef(value, 0L, 0L, 3, q);
862 } else if (pass == 1) { /* pass == 1 */
863 q = value;
864 validid = TRUE;
865 if (!isidstart(*q))
866 validid = FALSE;
867 while (*q && *q != ':') {
868 if (!isidchar(*q))
869 validid = FALSE;
870 q++;
872 if (!validid) {
873 report_error (ERR_NONFATAL,
874 "identifier expected after EXTERN");
875 break;
877 if (*q == ':') {
878 *q++ = '\0';
879 special = q;
880 } else
881 special = NULL;
882 if (!is_extern(value)) { /* allow re-EXTERN to be ignored */
883 int temp = pass0;
884 pass0 = 1; /* fake pass 1 in labels.c */
885 declare_as_global (value, special, report_error);
886 define_label (value, seg_alloc(), 0L, NULL, FALSE, TRUE,
887 ofmt, report_error);
888 pass0 = temp;
890 } /* else pass0 == 1 */
891 break;
892 case 3: /* [BITS bits] */
893 sb = get_bits(value);
894 break;
895 case 4: /* [GLOBAL symbol:special] */
896 if (*value == '$') value++; /* skip initial $ if present */
897 if (pass0 == 2) { /* pass 2 */
898 q = value;
899 while (*q && *q != ':')
900 q++;
901 if (*q == ':') {
902 *q++ = '\0';
903 ofmt->symdef(value, 0L, 0L, 3, q);
905 } else if (pass2 == 1) { /* pass == 1 */
906 q = value;
907 validid = TRUE;
908 if (!isidstart(*q))
909 validid = FALSE;
910 while (*q && *q != ':') {
911 if (!isidchar(*q))
912 validid = FALSE;
913 q++;
915 if (!validid) {
916 report_error (ERR_NONFATAL,
917 "identifier expected after GLOBAL");
918 break;
920 if (*q == ':') {
921 *q++ = '\0';
922 special = q;
923 } else
924 special = NULL;
925 declare_as_global (value, special, report_error);
926 } /* pass == 1 */
927 break;
928 case 5: /* [COMMON symbol size:special] */
929 if (*value == '$') value++; /* skip initial $ if present */
930 if (pass0 == 1) {
931 p = value;
932 validid = TRUE;
933 if (!isidstart(*p))
934 validid = FALSE;
935 while (*p && !isspace(*p)) {
936 if (!isidchar(*p))
937 validid = FALSE;
938 p++;
940 if (!validid) {
941 report_error (ERR_NONFATAL,
942 "identifier expected after COMMON");
943 break;
945 if (*p) {
946 long size;
948 while (*p && isspace(*p))
949 *p++ = '\0';
950 q = p;
951 while (*q && *q != ':')
952 q++;
953 if (*q == ':') {
954 *q++ = '\0';
955 special = q;
956 } else
957 special = NULL;
958 size = readnum (p, &rn_error);
959 if (rn_error)
960 report_error (ERR_NONFATAL, "invalid size specified"
961 " in COMMON declaration");
962 else
963 define_common (value, seg_alloc(), size,
964 special, ofmt, report_error);
965 } else
966 report_error (ERR_NONFATAL, "no size specified in"
967 " COMMON declaration");
968 } else if (pass0 == 2) { /* pass == 2 */
969 q = value;
970 while (*q && *q != ':') {
971 if (isspace(*q))
972 *q = '\0';
973 q++;
975 if (*q == ':') {
976 *q++ = '\0';
977 ofmt->symdef(value, 0L, 0L, 3, q);
980 break;
981 case 6: /* [ABSOLUTE address] */
982 stdscan_reset();
983 stdscan_bufptr = value;
984 tokval.t_type = TOKEN_INVALID;
985 e = evaluate(stdscan, NULL, &tokval, NULL, pass2, report_error,
986 NULL);
987 if (e) {
988 if (!is_reloc(e))
989 report_error (pass0==1 ? ERR_NONFATAL : ERR_PANIC,
990 "cannot use non-relocatable expression as "
991 "ABSOLUTE address");
992 else {
993 abs_seg = reloc_seg(e);
994 abs_offset = reloc_value(e);
996 } else
997 if (pass==1) abs_offset = 0x100;/* don't go near zero in case of / */
998 else report_error (ERR_PANIC, "invalid ABSOLUTE address "
999 "in pass two");
1000 in_abs_seg = TRUE;
1001 location.segment = NO_SEG;
1002 break;
1003 case 7: /* DEBUG */
1004 p = value;
1005 q = debugid;
1006 validid = TRUE;
1007 if (!isidstart(*p))
1008 validid = FALSE;
1009 while (*p && !isspace(*p)) {
1010 if (!isidchar(*p))
1011 validid = FALSE;
1012 *q++ = *p++;
1014 *q++ = 0;
1015 if (!validid) {
1016 report_error (pass==1 ? ERR_NONFATAL : ERR_PANIC,
1017 "identifier expected after DEBUG");
1018 break;
1020 while (*p && isspace(*p)) p++;
1021 if (pass==pass_max) ofmt->current_dfmt->debug_directive (debugid, p);
1022 break;
1023 case 8: /* [WARNING {+|-}warn-name] */
1024 if (pass1 == 1) {
1025 while (*value && isspace(*value))
1026 value++;
1028 if (*value == '+' || *value == '-') {
1029 validid = (*value == '-') ? TRUE : FALSE;
1030 value++;
1031 } else
1032 validid = FALSE;
1034 for (i=1; i<=ERR_WARN_MAX; i++)
1035 if (!nasm_stricmp(value, suppressed_names[i]))
1036 break;
1037 if (i <= ERR_WARN_MAX)
1038 suppressed[i] = validid;
1039 else
1040 report_error (ERR_NONFATAL, "invalid warning id in WARNING directive");
1042 break;
1043 case 9: /* cpu */
1044 cpu = get_cpu (value);
1045 break;
1046 case 10: /* fbk 9/2/00 */ /* [LIST {+|-}] */
1047 while (*value && isspace(*value))
1048 value++;
1050 if (*value == '+') {
1051 user_nolist = 0;
1053 else {
1054 if (*value == '-') {
1055 user_nolist = 1;
1057 else {
1058 report_error (ERR_NONFATAL, "invalid parameter to \"list\" directive");
1061 break;
1062 default:
1063 if (!ofmt->directive (directive, value, pass2))
1064 report_error (pass1==1 ? ERR_NONFATAL : ERR_PANIC,
1065 "unrecognised directive [%s]",
1066 directive);
1069 else /* it isn't a directive */
1071 parse_line (pass1, line, &output_ins,
1072 report_error, evaluate,
1073 def_label);
1075 if (!(optimizing>0) && pass == 2) {
1076 if (forwref != NULL && globallineno == forwref->lineno) {
1077 output_ins.forw_ref = TRUE;
1078 do {
1079 output_ins.oprs[forwref->operand].opflags |= OPFLAG_FORWARD;
1080 forwref = saa_rstruct (forwrefs);
1081 } while (forwref != NULL && forwref->lineno == globallineno);
1082 } else
1083 output_ins.forw_ref = FALSE;
1087 if (!(optimizing>0) && output_ins.forw_ref)
1089 if (pass == 1) {
1090 for(i = 0; i < output_ins.operands; i++)
1092 if (output_ins.oprs[i].opflags & OPFLAG_FORWARD)
1094 struct forwrefinfo *fwinf =
1095 (struct forwrefinfo *)saa_wstruct(forwrefs);
1096 fwinf->lineno = globallineno;
1097 fwinf->operand = i;
1100 } else { /* pass == 2 */
1102 * Hack to prevent phase error in the code
1103 * rol ax,x
1104 * x equ 1
1106 * If the second operand is a forward reference,
1107 * the UNITY property of the number 1 in that
1108 * operand is cancelled. Otherwise the above
1109 * sequence will cause a phase error.
1111 * This hack means that the above code will
1112 * generate 286+ code.
1114 * The forward reference will mean that the
1115 * operand will not have the UNITY property on
1116 * the first pass, so the pass behaviours will
1117 * be consistent.
1120 if (output_ins.operands >= 2 &&
1121 (output_ins.oprs[1].opflags & OPFLAG_FORWARD))
1123 output_ins.oprs[1].type &= ~(ONENESS|BYTENESS);
1126 } /* pass == 2 */
1128 } /* forw_ref */
1131 if (output_ins.opcode == I_EQU) {
1132 if (pass1 == 1)
1135 * Special `..' EQUs get processed in pass two,
1136 * except `..@' macro-processor EQUs which are done
1137 * in the normal place.
1139 if (!output_ins.label)
1140 report_error (ERR_NONFATAL,
1141 "EQU not preceded by label");
1143 else if (output_ins.label[0] != '.' ||
1144 output_ins.label[1] != '.' ||
1145 output_ins.label[2] == '@')
1147 if (output_ins.operands == 1 &&
1148 (output_ins.oprs[0].type & IMMEDIATE) &&
1149 output_ins.oprs[0].wrt == NO_SEG)
1151 int isext = output_ins.oprs[0].opflags & OPFLAG_EXTERN;
1152 def_label (output_ins.label,
1153 output_ins.oprs[0].segment,
1154 output_ins.oprs[0].offset,
1155 NULL, FALSE, isext, ofmt, report_error);
1157 else if (output_ins.operands == 2 &&
1158 (output_ins.oprs[0].type & IMMEDIATE) &&
1159 (output_ins.oprs[0].type & COLON) &&
1160 output_ins.oprs[0].segment == NO_SEG &&
1161 output_ins.oprs[0].wrt == NO_SEG &&
1162 (output_ins.oprs[1].type & IMMEDIATE) &&
1163 output_ins.oprs[1].segment == NO_SEG &&
1164 output_ins.oprs[1].wrt == NO_SEG)
1166 def_label (output_ins.label,
1167 output_ins.oprs[0].offset | SEG_ABS,
1168 output_ins.oprs[1].offset,
1169 NULL, FALSE, FALSE, ofmt, report_error);
1171 else
1172 report_error(ERR_NONFATAL, "bad syntax for EQU");
1174 } else { /* pass == 2 */
1176 * Special `..' EQUs get processed here, except
1177 * `..@' macro processor EQUs which are done above.
1179 if (output_ins.label[0] == '.' &&
1180 output_ins.label[1] == '.' &&
1181 output_ins.label[2] != '@')
1183 if (output_ins.operands == 1 &&
1184 (output_ins.oprs[0].type & IMMEDIATE)) {
1185 define_label (output_ins.label,
1186 output_ins.oprs[0].segment,
1187 output_ins.oprs[0].offset,
1188 NULL, FALSE, FALSE, ofmt, report_error);
1190 else if (output_ins.operands == 2 &&
1191 (output_ins.oprs[0].type & IMMEDIATE) &&
1192 (output_ins.oprs[0].type & COLON) &&
1193 output_ins.oprs[0].segment == NO_SEG &&
1194 (output_ins.oprs[1].type & IMMEDIATE) &&
1195 output_ins.oprs[1].segment == NO_SEG)
1197 define_label (output_ins.label,
1198 output_ins.oprs[0].offset | SEG_ABS,
1199 output_ins.oprs[1].offset,
1200 NULL, FALSE, FALSE, ofmt, report_error);
1202 else
1203 report_error(ERR_NONFATAL, "bad syntax for EQU");
1205 } /* pass == 2 */
1206 } else { /* instruction isn't an EQU */
1208 if (pass1 == 1) {
1210 long l = insn_size (location.segment, offs, sb, cpu,
1211 &output_ins, report_error);
1213 /* if (using_debug_info) && output_ins.opcode != -1)*/
1214 if (using_debug_info) /* fbk 03/25/01 */
1217 /* this is done here so we can do debug type info */
1218 long typeinfo = TYS_ELEMENTS(output_ins.operands);
1219 switch (output_ins.opcode) {
1220 case I_RESB:
1221 typeinfo = TYS_ELEMENTS(output_ins.oprs[0].offset) | TY_BYTE;
1222 break;
1223 case I_RESW:
1224 typeinfo = TYS_ELEMENTS(output_ins.oprs[0].offset) | TY_WORD;
1225 break;
1226 case I_RESD:
1227 typeinfo = TYS_ELEMENTS(output_ins.oprs[0].offset) | TY_DWORD;
1228 break;
1229 case I_RESQ:
1230 typeinfo = TYS_ELEMENTS(output_ins.oprs[0].offset) | TY_QWORD;
1231 break;
1232 case I_REST:
1233 typeinfo = TYS_ELEMENTS(output_ins.oprs[0].offset) | TY_TBYTE;
1234 break;
1235 case I_DB:
1236 typeinfo |= TY_BYTE;
1237 break;
1238 case I_DW:
1239 typeinfo |= TY_WORD;
1240 break;
1241 case I_DD:
1242 if (output_ins.eops_float)
1243 typeinfo |= TY_FLOAT;
1244 else
1245 typeinfo |= TY_DWORD;
1246 break;
1247 case I_DQ:
1248 typeinfo |= TY_QWORD;
1249 break;
1250 case I_DT:
1251 typeinfo |= TY_TBYTE;
1252 break;
1253 default:
1254 typeinfo = TY_LABEL;
1258 ofmt->current_dfmt->debug_typevalue(typeinfo);
1261 if (l != -1) {
1262 offs += l;
1263 SET_CURR_OFFS (offs);
1266 * else l == -1 => invalid instruction, which will be
1267 * flagged as an error on pass 2
1270 } else { /* pass == 2 */
1271 offs += assemble (location.segment, offs, sb, cpu,
1272 &output_ins, ofmt, report_error, &nasmlist);
1273 SET_CURR_OFFS (offs);
1276 } /* not an EQU */
1277 cleanup_insn (&output_ins);
1279 nasm_free (line);
1280 location.offset = offs = GET_CURR_OFFS;
1281 } /* end while (line = preproc->getline... */
1283 if (pass1==2 && global_offset_changed)
1284 report_error(ERR_NONFATAL, "phase error detected at end of assembly.");
1286 if (pass1 == 1) preproc->cleanup(1);
1288 if (pass1==1 && terminate_after_phase) {
1289 fclose(ofile);
1290 remove(outname);
1291 if (want_usage)
1292 usage();
1293 exit (1);
1295 pass_cnt++;
1296 if (pass>1 && !global_offset_changed) {
1297 pass0++;
1298 if (pass0==2) pass = pass_max - 1;
1299 } else if (!(optimizing>0)) pass0++;
1301 } /* for (pass=1; pass<=2; pass++) */
1303 preproc->cleanup(0);
1304 nasmlist.cleanup();
1305 #if 1
1306 if (optimizing>0 && opt_verbose_info) /* -On and -Ov switches */
1307 fprintf(stdout,
1308 "info:: assembly required 1+%d+1 passes\n", pass_cnt-2);
1309 #endif
1310 } /* exit from assemble_file (...) */
1313 static int getkw (char **directive, char **value)
1315 char *p, *q, *buf;
1317 buf = *directive;
1319 /* allow leading spaces or tabs */
1320 while (*buf==' ' || *buf=='\t')
1321 buf++;
1323 if (*buf!='[')
1324 return 0;
1326 p = buf;
1328 while (*p && *p != ']') p++;
1330 if (!*p)
1331 return 0;
1333 q = p++;
1335 while (*p && *p != ';') {
1336 if (!isspace(*p))
1337 return 0;
1338 p++;
1340 q[1] = '\0';
1342 *directive = p = buf+1;
1343 while (*buf && *buf!=' ' && *buf!=']' && *buf!='\t')
1344 buf++;
1345 if (*buf==']') {
1346 *buf = '\0';
1347 *value = buf;
1348 } else {
1349 *buf++ = '\0';
1350 while (isspace(*buf)) buf++; /* beppu - skip leading whitespace */
1351 *value = buf;
1352 while (*buf!=']') buf++;
1353 *buf++ = '\0';
1355 #if 0
1356 for (q=p; *q; q++)
1357 *q = tolower(*q);
1358 #endif
1359 if (!nasm_stricmp(p, "segment") || !nasm_stricmp(p, "section"))
1360 return 1;
1361 if (!nasm_stricmp(p, "extern"))
1362 return 2;
1363 if (!nasm_stricmp(p, "bits"))
1364 return 3;
1365 if (!nasm_stricmp(p, "global"))
1366 return 4;
1367 if (!nasm_stricmp(p, "common"))
1368 return 5;
1369 if (!nasm_stricmp(p, "absolute"))
1370 return 6;
1371 if (!nasm_stricmp(p, "debug"))
1372 return 7;
1373 if (!nasm_stricmp(p, "warning"))
1374 return 8;
1375 if (!nasm_stricmp(p, "cpu"))
1376 return 9;
1377 if (!nasm_stricmp(p, "list")) /* fbk 9/2/00 */
1378 return 10;
1379 return -1;
1383 * gnu style error reporting
1384 * This function prints an error message to error_file in the
1385 * style used by GNU. An example would be:
1386 * file.asm:50: error: blah blah blah
1387 * where file.asm is the name of the file, 50 is the line number on
1388 * which the error occurs (or is detected) and "error:" is one of
1389 * the possible optional diagnostics -- it can be "error" or "warning"
1390 * or something else. Finally the line terminates with the actual
1391 * error message.
1393 * @param severity the severity of the warning or error
1394 * @param fmt the printf style format string
1396 static void report_error_gnu (int severity, const char *fmt, ...)
1398 va_list ap;
1400 if (is_suppressed_warning(severity))
1401 return;
1403 if (severity & ERR_NOFILE)
1404 fputs ("nasm: ", error_file);
1405 else {
1406 char * currentfile = NULL;
1407 long lineno = 0;
1408 src_get (&lineno, &currentfile);
1409 fprintf (error_file, "%s:%ld: ", currentfile, lineno);
1410 nasm_free (currentfile);
1412 va_start (ap, fmt);
1413 report_error_common (severity, fmt, ap);
1414 va_end (ap);
1418 * MS style error reporting
1419 * This function prints an error message to error_file in the
1420 * style used by Visual C and some other Microsoft tools. An example
1421 * would be:
1422 * file.asm(50) : error: blah blah blah
1423 * where file.asm is the name of the file, 50 is the line number on
1424 * which the error occurs (or is detected) and "error:" is one of
1425 * the possible optional diagnostics -- it can be "error" or "warning"
1426 * or something else. Finally the line terminates with the actual
1427 * error message.
1429 * @param severity the severity of the warning or error
1430 * @param fmt the printf style format string
1432 static void report_error_vc (int severity, const char *fmt, ...)
1434 va_list ap;
1436 if (is_suppressed_warning (severity))
1437 return;
1439 if (severity & ERR_NOFILE)
1440 fputs ("nasm: ", error_file);
1441 else {
1442 char * currentfile = NULL;
1443 long lineno = 0;
1444 src_get (&lineno, &currentfile);
1445 fprintf (error_file, "%s(%ld) : ", currentfile, lineno);
1446 nasm_free (currentfile);
1448 va_start (ap, fmt);
1449 report_error_common (severity, fmt, ap);
1450 va_end (ap);
1454 * check for supressed warning
1455 * checks for suppressed warning or pass one only warning and we're
1456 * not in pass 1
1458 * @param severity the severity of the warning or error
1459 * @return true if we should abort error/warning printing
1461 static int is_suppressed_warning (int severity)
1464 * See if it's a suppressed warning.
1466 return ((severity & ERR_MASK) == ERR_WARNING &&
1467 (severity & ERR_WARN_MASK) != 0 &&
1468 suppressed[ (severity & ERR_WARN_MASK) >> ERR_WARN_SHR ]) ||
1470 * See if it's a pass-one only warning and we're not in pass one.
1472 ((severity & ERR_PASS1) && pass0 == 2);
1476 * common error reporting
1477 * This is the common back end of the error reporting schemes currently
1478 * implemented. It prints the nature of the warning and then the
1479 * specific error message to error_file and may or may not return. It
1480 * doesn't return if the error severity is a "panic" or "debug" type.
1482 * @param severity the severity of the warning or error
1483 * @param fmt the printf style format string
1485 static void report_error_common (int severity, const char *fmt, va_list args)
1487 switch (severity & ERR_MASK) {
1488 case ERR_WARNING:
1489 fputs ("warning: ", error_file); break;
1490 case ERR_NONFATAL:
1491 fputs ("error: ", error_file); break;
1492 case ERR_FATAL:
1493 fputs ("fatal: ", error_file); break;
1494 case ERR_PANIC:
1495 fputs ("panic: ", error_file); break;
1496 case ERR_DEBUG:
1497 fputs("debug: ", error_file); break;
1500 vfprintf (error_file, fmt, args);
1501 fputc ('\n', error_file);
1503 if (severity & ERR_USAGE)
1504 want_usage = TRUE;
1506 switch (severity & ERR_MASK) {
1507 case ERR_WARNING: case ERR_DEBUG:
1508 /* no further action, by definition */
1509 break;
1510 case ERR_NONFATAL:
1511 /* hack enables listing(!) on errors */
1512 terminate_after_phase = TRUE;
1513 break;
1514 case ERR_FATAL:
1515 if (ofile) {
1516 fclose(ofile);
1517 remove(outname);
1519 if (want_usage)
1520 usage();
1521 exit(1); /* instantly die */
1522 break; /* placate silly compilers */
1523 case ERR_PANIC:
1524 fflush(NULL);
1525 /* abort(); */ /* halt, catch fire, and dump core */
1526 exit(3);
1527 break;
1531 static void usage(void)
1533 fputs("type `nasm -h' for help\n", error_file);
1536 static void register_output_formats(void)
1538 ofmt = ofmt_register (report_error);
1541 #define BUF_DELTA 512
1543 static FILE *no_pp_fp;
1544 static efunc no_pp_err;
1545 static ListGen *no_pp_list;
1546 static long no_pp_lineinc;
1548 static void no_pp_reset (char *file, int pass, efunc error, evalfunc eval,
1549 ListGen *listgen)
1551 src_set_fname(nasm_strdup(file));
1552 src_set_linnum(0);
1553 no_pp_lineinc = 1;
1554 no_pp_err = error;
1555 no_pp_fp = fopen(file, "r");
1556 if (!no_pp_fp)
1557 no_pp_err (ERR_FATAL | ERR_NOFILE,
1558 "unable to open input file `%s'", file);
1559 no_pp_list = listgen;
1560 (void) pass; /* placate compilers */
1561 (void) eval; /* placate compilers */
1564 static char *no_pp_getline (void)
1566 char *buffer, *p, *q;
1567 int bufsize;
1569 bufsize = BUF_DELTA;
1570 buffer = nasm_malloc(BUF_DELTA);
1571 src_set_linnum(src_get_linnum() + no_pp_lineinc);
1573 while (1) { /* Loop to handle %line */
1575 p = buffer;
1576 while (1) { /* Loop to handle long lines */
1577 q = fgets(p, bufsize-(p-buffer), no_pp_fp);
1578 if (!q)
1579 break;
1580 p += strlen(p);
1581 if (p > buffer && p[-1] == '\n')
1582 break;
1583 if (p-buffer > bufsize-10) {
1584 int offset;
1585 offset = p - buffer;
1586 bufsize += BUF_DELTA;
1587 buffer = nasm_realloc(buffer, bufsize);
1588 p = buffer + offset;
1592 if (!q && p == buffer) {
1593 nasm_free (buffer);
1594 return NULL;
1598 * Play safe: remove CRs, LFs and any spurious ^Zs, if any of
1599 * them are present at the end of the line.
1601 buffer[strcspn(buffer, "\r\n\032")] = '\0';
1603 if (!strncmp(buffer, "%line", 5)) {
1604 long ln;
1605 int li;
1606 char *nm = nasm_malloc(strlen(buffer));
1607 if (sscanf(buffer+5, "%ld+%d %s", &ln, &li, nm) == 3) {
1608 nasm_free( src_set_fname(nm) );
1609 src_set_linnum(ln);
1610 no_pp_lineinc = li;
1611 continue;
1613 nasm_free(nm);
1615 break;
1618 no_pp_list->line (LIST_READ, buffer);
1620 return buffer;
1623 static void no_pp_cleanup (int pass)
1625 fclose(no_pp_fp);
1628 static unsigned long get_cpu (char *value)
1631 if (!strcmp(value, "8086")) return IF_8086;
1632 if (!strcmp(value, "186")) return IF_186;
1633 if (!strcmp(value, "286")) return IF_286;
1634 if (!strcmp(value, "386")) return IF_386;
1635 if (!strcmp(value, "486")) return IF_486;
1636 if (!strcmp(value, "586") ||
1637 !nasm_stricmp(value, "pentium") ) return IF_PENT;
1638 if (!strcmp(value, "686") ||
1639 !nasm_stricmp(value, "ppro") ||
1640 !nasm_stricmp(value, "pentiumpro") ||
1641 !nasm_stricmp(value, "p2") ) return IF_P6;
1642 if (!nasm_stricmp(value, "p3") ||
1643 !nasm_stricmp(value, "katmai") ) return IF_KATMAI;
1644 if (!nasm_stricmp(value, "p4") || /* is this right? -- jrc */
1645 !nasm_stricmp(value, "willamette") ) return IF_WILLAMETTE;
1646 if (!nasm_stricmp(value, "prescott") ) return IF_PRESCOTT;
1647 if (!nasm_stricmp(value, "ia64") ||
1648 !nasm_stricmp(value, "ia-64") ||
1649 !nasm_stricmp(value, "itanium") ||
1650 !nasm_stricmp(value, "itanic") ||
1651 !nasm_stricmp(value, "merced") ) return IF_IA64;
1653 report_error (pass0<2 ? ERR_NONFATAL : ERR_FATAL, "unknown 'cpu' type");
1655 return IF_PLEVEL; /* the maximum level */
1659 static int get_bits (char *value)
1661 int i;
1663 if ((i = atoi(value)) == 16) return i; /* set for a 16-bit segment */
1664 else if (i == 32) {
1665 if (cpu < IF_386) {
1666 report_error(ERR_NONFATAL,
1667 "cannot specify 32-bit segment on processor below a 386");
1668 i = 16;
1670 } else {
1671 report_error(pass0<2 ? ERR_NONFATAL : ERR_FATAL,
1672 "`%s' is not a valid segment size; must be 16 or 32",
1673 value);
1674 i = 16;
1676 return i;
1679 /* end of nasm.c */