%{_arch} doesn't work with newer RPMs; use %{_target_cpu} instead
[nasm.git] / nasm.c
blobe8bc680f814cf497e48203bba887623edbbfa77f
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 optimizing = opt; /* Multiple passes */
407 } else {
408 if (*param == 'v' || *param == '+') {
409 ++param;
410 opt_verbose_info = TRUE;
411 opt = 0;
412 } else { /* garbage */
413 opt = -99;
414 break;
417 } /* while (*param) */
418 if (opt == -99) report_error(ERR_FATAL,
419 "command line optimization level must be 'v', 0..3 or <nn>");
420 } else if (p[1]=='P' || p[1]=='p') { /* pre-include */
421 pp_pre_include (param);
422 } else if (p[1]=='D' || p[1]=='d') { /* pre-define */
423 pp_pre_define (param);
424 } else if (p[1]=='U' || p[1]=='u') { /* un-define */
425 pp_pre_undefine (param);
426 } else if (p[1]=='I' || p[1]=='i') { /* include search path */
427 pp_include_path (param);
428 } else if (p[1]=='l') { /* listing file */
429 strcpy (listname, param);
430 } else if (p[1]=='E') { /* error messages file */
431 error_file = fopen(param, "w");
432 if ( !error_file ) {
433 error_file = stderr; /* Revert to default! */
434 report_error (ERR_FATAL | ERR_NOFILE | ERR_USAGE,
435 "cannot open file `%s' for error messages",
436 param);
438 } else if (p[1] == 'F') { /* specify debug format */
439 ofmt->current_dfmt = dfmt_find(ofmt, param);
440 if (!ofmt->current_dfmt) {
441 report_error (ERR_FATAL | ERR_NOFILE | ERR_USAGE,
442 "unrecognized debug format `%s' for"
443 " output format `%s'",
444 param, ofmt->shortname);
446 } else if (p[1] == 'X') { /* specify error reporting format */
447 if (nasm_stricmp("vc", param) == 0)
448 report_error = report_error_vc;
449 else if (nasm_stricmp("gnu", param) == 0)
450 report_error = report_error_gnu;
451 else
452 report_error (ERR_FATAL | ERR_NOFILE | ERR_USAGE,
453 "unrecognized error reporting format `%s'",
454 param);
456 break;
457 case 'g':
458 using_debug_info = TRUE;
459 break;
460 case 'h':
461 printf("usage: nasm [-@ response file] [-o outfile] [-f format] "
462 "[-l listfile]\n"
463 " [options...] [--] filename\n"
464 " or nasm -r for version info (obsolete)\n"
465 " or nasm -v for version info (preferred)\n\n"
466 " -t Assemble in SciTech TASM compatible mode\n"
467 " -g Generate debug information in selected format.\n");
468 printf(" -e preprocess only (writes output to stdout by default)\n"
469 " -a don't preprocess (assemble only)\n"
470 " -M generate Makefile dependencies on stdout\n\n"
471 " -E<file> redirect error messages to file\n"
472 " -s redirect error messages to stdout\n\n"
473 " -F format select a debugging format\n\n"
474 " -I<path> adds a pathname to the include file path\n");
475 printf(" -O<digit> optimize branch offsets (-O0 disables, default)\n"
476 " -P<file> pre-includes a file\n"
477 " -D<macro>[=<value>] pre-defines a macro\n"
478 " -U<macro> undefines a macro\n"
479 " -X<format> specifies error reporting format (gnu or vc)\n"
480 " -w+foo enables warnings about foo; -w-foo disables them\n"
481 "where foo can be:\n");
482 for (i=1; i<=ERR_WARN_MAX; i++)
483 printf(" %-23s %s (default %s)\n",
484 suppressed_names[i], suppressed_what[i],
485 suppressed[i] ? "off" : "on");
486 printf ("\nresponse files should contain command line parameters"
487 ", one per line.\n");
488 if (p[2] == 'f') {
489 printf("\nvalid output formats for -f are"
490 " (`*' denotes default):\n");
491 ofmt_list(ofmt, stdout);
493 else {
494 printf ("\nFor a list of valid output formats, use -hf.\n");
495 printf ("For a list of debug formats, use -f <form> -y.\n");
497 exit (0); /* never need usage message here */
498 break;
499 case 'y':
500 printf("\nvalid debug formats for '%s' output format are"
501 " ('*' denotes default):\n",
502 ofmt->shortname);
503 dfmt_list(ofmt, stdout);
504 exit(0);
505 break;
506 case 't':
507 tasm_compatible_mode = TRUE;
508 break;
509 case 'r':
510 case 'v':
512 const char *nasm_version_string =
513 "NASM version " NASM_VER " compiled on " __DATE__
514 #ifdef DEBUG
515 " with -DDEBUG"
516 #endif
518 puts(nasm_version_string);
519 exit (0); /* never need usage message here */
521 break;
522 case 'e': /* preprocess only */
523 operating_mode = op_preprocess;
524 break;
525 case 'a': /* assemble only - don't preprocess */
526 preproc = &no_pp;
527 break;
528 case 'w':
529 if (p[2] != '+' && p[2] != '-') {
530 report_error (ERR_NONFATAL | ERR_NOFILE | ERR_USAGE,
531 "invalid option to `-w'");
532 } else {
533 for (i=1; i<=ERR_WARN_MAX; i++)
534 if (!nasm_stricmp(p+3, suppressed_names[i]))
535 break;
536 if (i <= ERR_WARN_MAX)
537 suppressed[i] = (p[2] == '-');
538 else
539 report_error (ERR_NONFATAL | ERR_NOFILE | ERR_USAGE,
540 "invalid option to `-w'");
542 break;
543 case 'M':
544 operating_mode = op_depend;
545 break;
547 case '-':
549 int s;
551 if (p[2]==0) { /* -- => stop processing options */
552 stopoptions = 1;
553 break;
555 for(s=0; textopts[s].label; s++)
557 if(!nasm_stricmp(p+2, textopts[s].label))
559 break;
563 switch(s)
566 case OPT_PREFIX:
567 case OPT_POSTFIX:
569 if (!q)
571 report_error (ERR_NONFATAL | ERR_NOFILE | ERR_USAGE,
572 "option `--%s' requires an argument",
573 p+2);
574 break;
576 else
578 advance = 1, param = q;
581 if(s == OPT_PREFIX)
583 strncpy(lprefix,param,PREFIX_MAX-1);
584 lprefix[PREFIX_MAX-1]=0;
585 break;
587 if(s == OPT_POSTFIX)
589 strncpy(lpostfix,param,POSTFIX_MAX-1);
590 lpostfix[POSTFIX_MAX-1]=0;
591 break;
593 break;
595 default:
597 report_error (ERR_NONFATAL | ERR_NOFILE | ERR_USAGE,
598 "unrecognised option `--%s'",
599 p+2);
600 break;
603 break;
606 default:
607 if (!ofmt->setinfo(GI_SWITCH,&p))
608 report_error (ERR_NONFATAL | ERR_NOFILE | ERR_USAGE,
609 "unrecognised option `-%c'",
610 p[1]);
611 break;
614 else
616 if (*inname) {
617 report_error (ERR_NONFATAL | ERR_NOFILE | ERR_USAGE,
618 "more than one input file specified");
619 } else
620 strcpy(inname, p);
623 return advance;
626 #define ARG_BUF_DELTA 128
628 static void process_respfile (FILE *rfile)
630 char *buffer, *p, *q, *prevarg;
631 int bufsize, prevargsize;
633 bufsize = prevargsize = ARG_BUF_DELTA;
634 buffer = nasm_malloc(ARG_BUF_DELTA);
635 prevarg = nasm_malloc(ARG_BUF_DELTA);
636 prevarg[0] = '\0';
638 while (1) { /* Loop to handle all lines in file */
640 p = buffer;
641 while (1) { /* Loop to handle long lines */
642 q = fgets(p, bufsize-(p-buffer), rfile);
643 if (!q)
644 break;
645 p += strlen(p);
646 if (p > buffer && p[-1] == '\n')
647 break;
648 if (p-buffer > bufsize-10) {
649 int offset;
650 offset = p - buffer;
651 bufsize += ARG_BUF_DELTA;
652 buffer = nasm_realloc(buffer, bufsize);
653 p = buffer + offset;
657 if (!q && p == buffer) {
658 if (prevarg[0])
659 process_arg (prevarg, NULL);
660 nasm_free (buffer);
661 nasm_free (prevarg);
662 return;
666 * Play safe: remove CRs, LFs and any spurious ^Zs, if any of
667 * them are present at the end of the line.
669 *(p = &buffer[strcspn(buffer, "\r\n\032")]) = '\0';
671 while (p > buffer && isspace(p[-1]))
672 *--p = '\0';
674 p = buffer;
675 while (isspace(*p))
676 p++;
678 if (process_arg (prevarg, p))
679 *p = '\0';
681 if (strlen(p) > prevargsize-10) {
682 prevargsize += ARG_BUF_DELTA;
683 prevarg = nasm_realloc(prevarg, prevargsize);
685 strcpy (prevarg, p);
689 /* Function to process args from a string of args, rather than the
690 * argv array. Used by the environment variable and response file
691 * processing.
693 static void process_args (char *args) {
694 char *p, *q, *arg, *prevarg;
695 char separator = ' ';
697 p = args;
698 if (*p && *p != '-')
699 separator = *p++;
700 arg = NULL;
701 while (*p) {
702 q = p;
703 while (*p && *p != separator) p++;
704 while (*p == separator) *p++ = '\0';
705 prevarg = arg;
706 arg = q;
707 if (process_arg (prevarg, arg))
708 arg = NULL;
710 if (arg)
711 process_arg (arg, NULL);
714 static void parse_cmdline(int argc, char **argv)
716 FILE *rfile;
717 char *envreal, *envcopy=NULL, *p, *arg;
719 *inname = *outname = *listname = '\0';
722 * First, process the NASMENV environment variable.
724 envreal = getenv("NASMENV");
725 arg = NULL;
726 if (envreal) {
727 envcopy = nasm_strdup(envreal);
728 process_args(envcopy);
729 nasm_free (envcopy);
733 * Now process the actual command line.
735 while (--argc)
737 int i;
738 argv++;
739 if (argv[0][0] == '@') {
740 /* We have a response file, so process this as a set of
741 * arguments like the environment variable. This allows us
742 * to have multiple arguments on a single line, which is
743 * different to the -@resp file processing below for regular
744 * NASM.
746 char *str = malloc(2048);
747 FILE *f = fopen(&argv[0][1],"r");
748 if (!str) {
749 printf("out of memory");
750 exit(-1);
752 if (f) {
753 while (fgets(str,2048,f)) {
754 process_args(str);
756 fclose(f);
758 free(str);
759 argc--;
760 argv++;
762 if (!stopoptions && argv[0][0] == '-' && argv[0][1] == '@') {
763 if ((p = get_param (argv[0], argc > 1 ? argv[1] : NULL, &i))) {
764 if ((rfile = fopen(p, "r"))) {
765 process_respfile (rfile);
766 fclose(rfile);
767 } else
768 report_error (ERR_NONFATAL | ERR_NOFILE | ERR_USAGE,
769 "unable to open response file `%s'", p);
771 } else
772 i = process_arg (argv[0], argc > 1 ? argv[1] : NULL);
773 argv += i, argc -= i;
776 if (!*inname)
777 report_error (ERR_NONFATAL | ERR_NOFILE | ERR_USAGE,
778 "no input file specified");
782 static void assemble_file (char *fname)
784 char * directive, * value, * p, * q, * special, * line, debugid[80];
785 insn output_ins;
786 int i, rn_error, validid;
787 long seg, offs;
788 struct tokenval tokval;
789 expr * e;
790 int pass, pass_max;
791 int pass_cnt = 0; /* count actual passes */
793 if (cmd_sb == 32 && cmd_cpu < IF_386)
794 report_error(ERR_FATAL, "command line: "
795 "32-bit segment size requires a higher cpu");
797 pass_max = (optimizing>0 ? optimizing : 0) + 2; /* passes 1, optimizing, then 2 */
798 pass0 = !(optimizing>0); /* start at 1 if not optimizing */
799 for (pass = 1; pass <= pass_max && pass0 <= 2; pass++) {
800 int pass1, pass2;
801 ldfunc def_label;
803 pass1 = pass < pass_max ? 1 : 2; /* seq is 1, 1, 1,..., 1, 2 */
804 pass2 = pass > 1 ? 2 : 1; /* seq is 1, 2, 2,..., 2, 2 */
805 /* pass0 seq is 0, 0, 0,..., 1, 2 */
807 def_label = pass > 1 ? redefine_label : define_label;
810 sb = cmd_sb; /* set 'bits' to command line default */
811 cpu = cmd_cpu;
812 if (pass0 == 2) {
813 if (*listname)
814 nasmlist.init(listname, report_error);
816 in_abs_seg = FALSE;
817 global_offset_changed = FALSE; /* set by redefine_label */
818 location.segment = ofmt->section(NULL, pass2, &sb);
819 if (pass > 1) {
820 saa_rewind (forwrefs);
821 forwref = saa_rstruct (forwrefs);
822 raa_free (offsets);
823 offsets = raa_init();
825 preproc->reset(fname, pass1, report_error, evaluate, &nasmlist);
826 globallineno = 0;
827 if (pass == 1) location.known = TRUE;
828 location.offset = offs = GET_CURR_OFFS;
830 while ( (line = preproc->getline()) )
832 globallineno++;
834 /* here we parse our directives; this is not handled by the 'real'
835 * parser. */
836 directive = line;
837 if ( (i = getkw (&directive, &value)) )
839 switch (i) {
840 case 1: /* [SEGMENT n] */
841 seg = ofmt->section (value, pass2, &sb);
842 if (seg == NO_SEG) {
843 report_error (pass1==1 ? ERR_NONFATAL : ERR_PANIC,
844 "segment name `%s' not recognised",
845 value);
846 } else {
847 in_abs_seg = FALSE;
848 location.segment = seg;
850 break;
851 case 2: /* [EXTERN label:special] */
852 if (*value == '$') value++; /* skip initial $ if present */
853 if (pass0 == 2) {
854 q = value;
855 while (*q && *q != ':')
856 q++;
857 if (*q == ':') {
858 *q++ = '\0';
859 ofmt->symdef(value, 0L, 0L, 3, q);
861 } else if (pass == 1) { /* pass == 1 */
862 q = value;
863 validid = TRUE;
864 if (!isidstart(*q))
865 validid = FALSE;
866 while (*q && *q != ':') {
867 if (!isidchar(*q))
868 validid = FALSE;
869 q++;
871 if (!validid) {
872 report_error (ERR_NONFATAL,
873 "identifier expected after EXTERN");
874 break;
876 if (*q == ':') {
877 *q++ = '\0';
878 special = q;
879 } else
880 special = NULL;
881 if (!is_extern(value)) { /* allow re-EXTERN to be ignored */
882 int temp = pass0;
883 pass0 = 1; /* fake pass 1 in labels.c */
884 declare_as_global (value, special, report_error);
885 define_label (value, seg_alloc(), 0L, NULL, FALSE, TRUE,
886 ofmt, report_error);
887 pass0 = temp;
889 } /* else pass0 == 1 */
890 break;
891 case 3: /* [BITS bits] */
892 sb = get_bits(value);
893 break;
894 case 4: /* [GLOBAL symbol:special] */
895 if (*value == '$') value++; /* skip initial $ if present */
896 if (pass0 == 2) { /* pass 2 */
897 q = value;
898 while (*q && *q != ':')
899 q++;
900 if (*q == ':') {
901 *q++ = '\0';
902 ofmt->symdef(value, 0L, 0L, 3, q);
904 } else if (pass2 == 1) { /* pass == 1 */
905 q = value;
906 validid = TRUE;
907 if (!isidstart(*q))
908 validid = FALSE;
909 while (*q && *q != ':') {
910 if (!isidchar(*q))
911 validid = FALSE;
912 q++;
914 if (!validid) {
915 report_error (ERR_NONFATAL,
916 "identifier expected after GLOBAL");
917 break;
919 if (*q == ':') {
920 *q++ = '\0';
921 special = q;
922 } else
923 special = NULL;
924 declare_as_global (value, special, report_error);
925 } /* pass == 1 */
926 break;
927 case 5: /* [COMMON symbol size:special] */
928 if (*value == '$') value++; /* skip initial $ if present */
929 if (pass0 == 1) {
930 p = value;
931 validid = TRUE;
932 if (!isidstart(*p))
933 validid = FALSE;
934 while (*p && !isspace(*p)) {
935 if (!isidchar(*p))
936 validid = FALSE;
937 p++;
939 if (!validid) {
940 report_error (ERR_NONFATAL,
941 "identifier expected after COMMON");
942 break;
944 if (*p) {
945 long size;
947 while (*p && isspace(*p))
948 *p++ = '\0';
949 q = p;
950 while (*q && *q != ':')
951 q++;
952 if (*q == ':') {
953 *q++ = '\0';
954 special = q;
955 } else
956 special = NULL;
957 size = readnum (p, &rn_error);
958 if (rn_error)
959 report_error (ERR_NONFATAL, "invalid size specified"
960 " in COMMON declaration");
961 else
962 define_common (value, seg_alloc(), size,
963 special, ofmt, report_error);
964 } else
965 report_error (ERR_NONFATAL, "no size specified in"
966 " COMMON declaration");
967 } else if (pass0 == 2) { /* pass == 2 */
968 q = value;
969 while (*q && *q != ':') {
970 if (isspace(*q))
971 *q = '\0';
972 q++;
974 if (*q == ':') {
975 *q++ = '\0';
976 ofmt->symdef(value, 0L, 0L, 3, q);
979 break;
980 case 6: /* [ABSOLUTE address] */
981 stdscan_reset();
982 stdscan_bufptr = value;
983 tokval.t_type = TOKEN_INVALID;
984 e = evaluate(stdscan, NULL, &tokval, NULL, pass2, report_error,
985 NULL);
986 if (e) {
987 if (!is_reloc(e))
988 report_error (pass0==1 ? ERR_NONFATAL : ERR_PANIC,
989 "cannot use non-relocatable expression as "
990 "ABSOLUTE address");
991 else {
992 abs_seg = reloc_seg(e);
993 abs_offset = reloc_value(e);
995 } else
996 if (pass==1) abs_offset = 0x100;/* don't go near zero in case of / */
997 else report_error (ERR_PANIC, "invalid ABSOLUTE address "
998 "in pass two");
999 in_abs_seg = TRUE;
1000 location.segment = NO_SEG;
1001 break;
1002 case 7: /* DEBUG */
1003 p = value;
1004 q = debugid;
1005 validid = TRUE;
1006 if (!isidstart(*p))
1007 validid = FALSE;
1008 while (*p && !isspace(*p)) {
1009 if (!isidchar(*p))
1010 validid = FALSE;
1011 *q++ = *p++;
1013 *q++ = 0;
1014 if (!validid) {
1015 report_error (pass==1 ? ERR_NONFATAL : ERR_PANIC,
1016 "identifier expected after DEBUG");
1017 break;
1019 while (*p && isspace(*p)) p++;
1020 if (pass==pass_max) ofmt->current_dfmt->debug_directive (debugid, p);
1021 break;
1022 case 8: /* [WARNING {+|-}warn-name] */
1023 if (pass1 == 1) {
1024 while (*value && isspace(*value))
1025 value++;
1027 if (*value == '+' || *value == '-') {
1028 validid = (*value == '-') ? TRUE : FALSE;
1029 value++;
1030 } else
1031 validid = FALSE;
1033 for (i=1; i<=ERR_WARN_MAX; i++)
1034 if (!nasm_stricmp(value, suppressed_names[i]))
1035 break;
1036 if (i <= ERR_WARN_MAX)
1037 suppressed[i] = validid;
1038 else
1039 report_error (ERR_NONFATAL, "invalid warning id in WARNING directive");
1041 break;
1042 case 9: /* cpu */
1043 cpu = get_cpu (value);
1044 break;
1045 case 10: /* fbk 9/2/00 */ /* [LIST {+|-}] */
1046 while (*value && isspace(*value))
1047 value++;
1049 if (*value == '+') {
1050 user_nolist = 0;
1052 else {
1053 if (*value == '-') {
1054 user_nolist = 1;
1056 else {
1057 report_error (ERR_NONFATAL, "invalid parameter to \"list\" directive");
1060 break;
1061 default:
1062 if (!ofmt->directive (directive, value, pass2))
1063 report_error (pass1==1 ? ERR_NONFATAL : ERR_PANIC,
1064 "unrecognised directive [%s]",
1065 directive);
1068 else /* it isn't a directive */
1070 parse_line (pass1, line, &output_ins,
1071 report_error, evaluate,
1072 def_label);
1074 if (!(optimizing>0) && pass == 2) {
1075 if (forwref != NULL && globallineno == forwref->lineno) {
1076 output_ins.forw_ref = TRUE;
1077 do {
1078 output_ins.oprs[forwref->operand].opflags |= OPFLAG_FORWARD;
1079 forwref = saa_rstruct (forwrefs);
1080 } while (forwref != NULL && forwref->lineno == globallineno);
1081 } else
1082 output_ins.forw_ref = FALSE;
1086 if (!(optimizing>0) && output_ins.forw_ref)
1088 if (pass == 1) {
1089 for(i = 0; i < output_ins.operands; i++)
1091 if (output_ins.oprs[i].opflags & OPFLAG_FORWARD)
1093 struct forwrefinfo *fwinf =
1094 (struct forwrefinfo *)saa_wstruct(forwrefs);
1095 fwinf->lineno = globallineno;
1096 fwinf->operand = i;
1099 } else { /* pass == 2 */
1101 * Hack to prevent phase error in the code
1102 * rol ax,x
1103 * x equ 1
1105 * If the second operand is a forward reference,
1106 * the UNITY property of the number 1 in that
1107 * operand is cancelled. Otherwise the above
1108 * sequence will cause a phase error.
1110 * This hack means that the above code will
1111 * generate 286+ code.
1113 * The forward reference will mean that the
1114 * operand will not have the UNITY property on
1115 * the first pass, so the pass behaviours will
1116 * be consistent.
1119 if (output_ins.operands >= 2 &&
1120 (output_ins.oprs[1].opflags & OPFLAG_FORWARD))
1122 output_ins.oprs[1].type &= ~(ONENESS|BYTENESS);
1125 } /* pass == 2 */
1127 } /* forw_ref */
1130 if (output_ins.opcode == I_EQU) {
1131 if (pass1 == 1)
1134 * Special `..' EQUs get processed in pass two,
1135 * except `..@' macro-processor EQUs which are done
1136 * in the normal place.
1138 if (!output_ins.label)
1139 report_error (ERR_NONFATAL,
1140 "EQU not preceded by label");
1142 else if (output_ins.label[0] != '.' ||
1143 output_ins.label[1] != '.' ||
1144 output_ins.label[2] == '@')
1146 if (output_ins.operands == 1 &&
1147 (output_ins.oprs[0].type & IMMEDIATE) &&
1148 output_ins.oprs[0].wrt == NO_SEG)
1150 int isext = output_ins.oprs[0].opflags & OPFLAG_EXTERN;
1151 def_label (output_ins.label,
1152 output_ins.oprs[0].segment,
1153 output_ins.oprs[0].offset,
1154 NULL, FALSE, isext, ofmt, report_error);
1156 else if (output_ins.operands == 2 &&
1157 (output_ins.oprs[0].type & IMMEDIATE) &&
1158 (output_ins.oprs[0].type & COLON) &&
1159 output_ins.oprs[0].segment == NO_SEG &&
1160 output_ins.oprs[0].wrt == NO_SEG &&
1161 (output_ins.oprs[1].type & IMMEDIATE) &&
1162 output_ins.oprs[1].segment == NO_SEG &&
1163 output_ins.oprs[1].wrt == NO_SEG)
1165 def_label (output_ins.label,
1166 output_ins.oprs[0].offset | SEG_ABS,
1167 output_ins.oprs[1].offset,
1168 NULL, FALSE, FALSE, ofmt, report_error);
1170 else
1171 report_error(ERR_NONFATAL, "bad syntax for EQU");
1173 } else { /* pass == 2 */
1175 * Special `..' EQUs get processed here, except
1176 * `..@' macro processor EQUs which are done above.
1178 if (output_ins.label[0] == '.' &&
1179 output_ins.label[1] == '.' &&
1180 output_ins.label[2] != '@')
1182 if (output_ins.operands == 1 &&
1183 (output_ins.oprs[0].type & IMMEDIATE)) {
1184 define_label (output_ins.label,
1185 output_ins.oprs[0].segment,
1186 output_ins.oprs[0].offset,
1187 NULL, FALSE, FALSE, ofmt, report_error);
1189 else if (output_ins.operands == 2 &&
1190 (output_ins.oprs[0].type & IMMEDIATE) &&
1191 (output_ins.oprs[0].type & COLON) &&
1192 output_ins.oprs[0].segment == NO_SEG &&
1193 (output_ins.oprs[1].type & IMMEDIATE) &&
1194 output_ins.oprs[1].segment == NO_SEG)
1196 define_label (output_ins.label,
1197 output_ins.oprs[0].offset | SEG_ABS,
1198 output_ins.oprs[1].offset,
1199 NULL, FALSE, FALSE, ofmt, report_error);
1201 else
1202 report_error(ERR_NONFATAL, "bad syntax for EQU");
1204 } /* pass == 2 */
1205 } else { /* instruction isn't an EQU */
1207 if (pass1 == 1) {
1209 long l = insn_size (location.segment, offs, sb, cpu,
1210 &output_ins, report_error);
1212 /* if (using_debug_info) && output_ins.opcode != -1)*/
1213 if (using_debug_info) /* fbk 03/25/01 */
1216 /* this is done here so we can do debug type info */
1217 long typeinfo = TYS_ELEMENTS(output_ins.operands);
1218 switch (output_ins.opcode) {
1219 case I_RESB:
1220 typeinfo = TYS_ELEMENTS(output_ins.oprs[0].offset) | TY_BYTE;
1221 break;
1222 case I_RESW:
1223 typeinfo = TYS_ELEMENTS(output_ins.oprs[0].offset) | TY_WORD;
1224 break;
1225 case I_RESD:
1226 typeinfo = TYS_ELEMENTS(output_ins.oprs[0].offset) | TY_DWORD;
1227 break;
1228 case I_RESQ:
1229 typeinfo = TYS_ELEMENTS(output_ins.oprs[0].offset) | TY_QWORD;
1230 break;
1231 case I_REST:
1232 typeinfo = TYS_ELEMENTS(output_ins.oprs[0].offset) | TY_TBYTE;
1233 break;
1234 case I_DB:
1235 typeinfo |= TY_BYTE;
1236 break;
1237 case I_DW:
1238 typeinfo |= TY_WORD;
1239 break;
1240 case I_DD:
1241 if (output_ins.eops_float)
1242 typeinfo |= TY_FLOAT;
1243 else
1244 typeinfo |= TY_DWORD;
1245 break;
1246 case I_DQ:
1247 typeinfo |= TY_QWORD;
1248 break;
1249 case I_DT:
1250 typeinfo |= TY_TBYTE;
1251 break;
1252 default:
1253 typeinfo = TY_LABEL;
1257 ofmt->current_dfmt->debug_typevalue(typeinfo);
1260 if (l != -1) {
1261 offs += l;
1262 SET_CURR_OFFS (offs);
1265 * else l == -1 => invalid instruction, which will be
1266 * flagged as an error on pass 2
1269 } else { /* pass == 2 */
1270 offs += assemble (location.segment, offs, sb, cpu,
1271 &output_ins, ofmt, report_error, &nasmlist);
1272 SET_CURR_OFFS (offs);
1275 } /* not an EQU */
1276 cleanup_insn (&output_ins);
1278 nasm_free (line);
1279 location.offset = offs = GET_CURR_OFFS;
1280 } /* end while (line = preproc->getline... */
1282 if (pass1==2 && global_offset_changed)
1283 report_error(ERR_NONFATAL, "phase error detected at end of assembly.");
1285 if (pass1 == 1) preproc->cleanup(1);
1287 if (pass1==1 && terminate_after_phase) {
1288 fclose(ofile);
1289 remove(outname);
1290 if (want_usage)
1291 usage();
1292 exit (1);
1294 pass_cnt++;
1295 if (pass>1 && !global_offset_changed) {
1296 pass0++;
1297 if (pass0==2) pass = pass_max - 1;
1298 } else if (!(optimizing>0)) pass0++;
1300 } /* for (pass=1; pass<=2; pass++) */
1302 preproc->cleanup(0);
1303 nasmlist.cleanup();
1304 #if 1
1305 if (optimizing>0 && opt_verbose_info) /* -On and -Ov switches */
1306 fprintf(stdout,
1307 "info:: assembly required 1+%d+1 passes\n", pass_cnt-2);
1308 #endif
1309 } /* exit from assemble_file (...) */
1312 static int getkw (char **directive, char **value)
1314 char *p, *q, *buf;
1316 buf = *directive;
1318 /* allow leading spaces or tabs */
1319 while (*buf==' ' || *buf=='\t')
1320 buf++;
1322 if (*buf!='[')
1323 return 0;
1325 p = buf;
1327 while (*p && *p != ']') p++;
1329 if (!*p)
1330 return 0;
1332 q = p++;
1334 while (*p && *p != ';') {
1335 if (!isspace(*p))
1336 return 0;
1337 p++;
1339 q[1] = '\0';
1341 *directive = p = buf+1;
1342 while (*buf && *buf!=' ' && *buf!=']' && *buf!='\t')
1343 buf++;
1344 if (*buf==']') {
1345 *buf = '\0';
1346 *value = buf;
1347 } else {
1348 *buf++ = '\0';
1349 while (isspace(*buf)) buf++; /* beppu - skip leading whitespace */
1350 *value = buf;
1351 while (*buf!=']') buf++;
1352 *buf++ = '\0';
1354 #if 0
1355 for (q=p; *q; q++)
1356 *q = tolower(*q);
1357 #endif
1358 if (!nasm_stricmp(p, "segment") || !nasm_stricmp(p, "section"))
1359 return 1;
1360 if (!nasm_stricmp(p, "extern"))
1361 return 2;
1362 if (!nasm_stricmp(p, "bits"))
1363 return 3;
1364 if (!nasm_stricmp(p, "global"))
1365 return 4;
1366 if (!nasm_stricmp(p, "common"))
1367 return 5;
1368 if (!nasm_stricmp(p, "absolute"))
1369 return 6;
1370 if (!nasm_stricmp(p, "debug"))
1371 return 7;
1372 if (!nasm_stricmp(p, "warning"))
1373 return 8;
1374 if (!nasm_stricmp(p, "cpu"))
1375 return 9;
1376 if (!nasm_stricmp(p, "list")) /* fbk 9/2/00 */
1377 return 10;
1378 return -1;
1382 * gnu style error reporting
1383 * This function prints an error message to error_file in the
1384 * style used by GNU. An example would be:
1385 * file.asm:50: error: blah blah blah
1386 * where file.asm is the name of the file, 50 is the line number on
1387 * which the error occurs (or is detected) and "error:" is one of
1388 * the possible optional diagnostics -- it can be "error" or "warning"
1389 * or something else. Finally the line terminates with the actual
1390 * error message.
1392 * @param severity the severity of the warning or error
1393 * @param fmt the printf style format string
1395 static void report_error_gnu (int severity, const char *fmt, ...)
1397 va_list ap;
1399 if (is_suppressed_warning(severity))
1400 return;
1402 if (severity & ERR_NOFILE)
1403 fputs ("nasm: ", error_file);
1404 else {
1405 char * currentfile = NULL;
1406 long lineno = 0;
1407 src_get (&lineno, &currentfile);
1408 fprintf (error_file, "%s:%ld: ", currentfile, lineno);
1409 nasm_free (currentfile);
1411 va_start (ap, fmt);
1412 report_error_common (severity, fmt, ap);
1413 va_end (ap);
1417 * MS style error reporting
1418 * This function prints an error message to error_file in the
1419 * style used by Visual C and some other Microsoft tools. An example
1420 * would be:
1421 * file.asm(50) : error: blah blah blah
1422 * where file.asm is the name of the file, 50 is the line number on
1423 * which the error occurs (or is detected) and "error:" is one of
1424 * the possible optional diagnostics -- it can be "error" or "warning"
1425 * or something else. Finally the line terminates with the actual
1426 * error message.
1428 * @param severity the severity of the warning or error
1429 * @param fmt the printf style format string
1431 static void report_error_vc (int severity, const char *fmt, ...)
1433 va_list ap;
1435 if (is_suppressed_warning (severity))
1436 return;
1438 if (severity & ERR_NOFILE)
1439 fputs ("nasm: ", error_file);
1440 else {
1441 char * currentfile = NULL;
1442 long lineno = 0;
1443 src_get (&lineno, &currentfile);
1444 fprintf (error_file, "%s(%ld) : ", currentfile, lineno);
1445 nasm_free (currentfile);
1447 va_start (ap, fmt);
1448 report_error_common (severity, fmt, ap);
1449 va_end (ap);
1453 * check for supressed warning
1454 * checks for suppressed warning or pass one only warning and we're
1455 * not in pass 1
1457 * @param severity the severity of the warning or error
1458 * @return true if we should abort error/warning printing
1460 static int is_suppressed_warning (int severity)
1463 * See if it's a suppressed warning.
1465 return ((severity & ERR_MASK) == ERR_WARNING &&
1466 (severity & ERR_WARN_MASK) != 0 &&
1467 suppressed[ (severity & ERR_WARN_MASK) >> ERR_WARN_SHR ]) ||
1469 * See if it's a pass-one only warning and we're not in pass one.
1471 ((severity & ERR_PASS1) && pass0 == 2);
1475 * common error reporting
1476 * This is the common back end of the error reporting schemes currently
1477 * implemented. It prints the nature of the warning and then the
1478 * specific error message to error_file and may or may not return. It
1479 * doesn't return if the error severity is a "panic" or "debug" type.
1481 * @param severity the severity of the warning or error
1482 * @param fmt the printf style format string
1484 static void report_error_common (int severity, const char *fmt, va_list args)
1486 switch (severity & ERR_MASK) {
1487 case ERR_WARNING:
1488 fputs ("warning: ", error_file); break;
1489 case ERR_NONFATAL:
1490 fputs ("error: ", error_file); break;
1491 case ERR_FATAL:
1492 fputs ("fatal: ", error_file); break;
1493 case ERR_PANIC:
1494 fputs ("panic: ", error_file); break;
1495 case ERR_DEBUG:
1496 fputs("debug: ", error_file); break;
1499 vfprintf (error_file, fmt, args);
1500 fputc ('\n', error_file);
1502 if (severity & ERR_USAGE)
1503 want_usage = TRUE;
1505 switch (severity & ERR_MASK) {
1506 case ERR_WARNING: case ERR_DEBUG:
1507 /* no further action, by definition */
1508 break;
1509 case ERR_NONFATAL:
1510 /* hack enables listing(!) on errors */
1511 terminate_after_phase = TRUE;
1512 break;
1513 case ERR_FATAL:
1514 if (ofile) {
1515 fclose(ofile);
1516 remove(outname);
1518 if (want_usage)
1519 usage();
1520 exit(1); /* instantly die */
1521 break; /* placate silly compilers */
1522 case ERR_PANIC:
1523 fflush(NULL);
1524 /* abort(); */ /* halt, catch fire, and dump core */
1525 exit(3);
1526 break;
1530 static void usage(void)
1532 fputs("type `nasm -h' for help\n", error_file);
1535 static void register_output_formats(void)
1537 ofmt = ofmt_register (report_error);
1540 #define BUF_DELTA 512
1542 static FILE *no_pp_fp;
1543 static efunc no_pp_err;
1544 static ListGen *no_pp_list;
1545 static long no_pp_lineinc;
1547 static void no_pp_reset (char *file, int pass, efunc error, evalfunc eval,
1548 ListGen *listgen)
1550 src_set_fname(nasm_strdup(file));
1551 src_set_linnum(0);
1552 no_pp_lineinc = 1;
1553 no_pp_err = error;
1554 no_pp_fp = fopen(file, "r");
1555 if (!no_pp_fp)
1556 no_pp_err (ERR_FATAL | ERR_NOFILE,
1557 "unable to open input file `%s'", file);
1558 no_pp_list = listgen;
1559 (void) pass; /* placate compilers */
1560 (void) eval; /* placate compilers */
1563 static char *no_pp_getline (void)
1565 char *buffer, *p, *q;
1566 int bufsize;
1568 bufsize = BUF_DELTA;
1569 buffer = nasm_malloc(BUF_DELTA);
1570 src_set_linnum(src_get_linnum() + no_pp_lineinc);
1572 while (1) { /* Loop to handle %line */
1574 p = buffer;
1575 while (1) { /* Loop to handle long lines */
1576 q = fgets(p, bufsize-(p-buffer), no_pp_fp);
1577 if (!q)
1578 break;
1579 p += strlen(p);
1580 if (p > buffer && p[-1] == '\n')
1581 break;
1582 if (p-buffer > bufsize-10) {
1583 int offset;
1584 offset = p - buffer;
1585 bufsize += BUF_DELTA;
1586 buffer = nasm_realloc(buffer, bufsize);
1587 p = buffer + offset;
1591 if (!q && p == buffer) {
1592 nasm_free (buffer);
1593 return NULL;
1597 * Play safe: remove CRs, LFs and any spurious ^Zs, if any of
1598 * them are present at the end of the line.
1600 buffer[strcspn(buffer, "\r\n\032")] = '\0';
1602 if (!strncmp(buffer, "%line", 5)) {
1603 long ln;
1604 int li;
1605 char *nm = nasm_malloc(strlen(buffer));
1606 if (sscanf(buffer+5, "%ld+%d %s", &ln, &li, nm) == 3) {
1607 nasm_free( src_set_fname(nm) );
1608 src_set_linnum(ln);
1609 no_pp_lineinc = li;
1610 continue;
1612 nasm_free(nm);
1614 break;
1617 no_pp_list->line (LIST_READ, buffer);
1619 return buffer;
1622 static void no_pp_cleanup (int pass)
1624 fclose(no_pp_fp);
1627 static unsigned long get_cpu (char *value)
1630 if (!strcmp(value, "8086")) return IF_8086;
1631 if (!strcmp(value, "186")) return IF_186;
1632 if (!strcmp(value, "286")) return IF_286;
1633 if (!strcmp(value, "386")) return IF_386;
1634 if (!strcmp(value, "486")) return IF_486;
1635 if (!strcmp(value, "586") ||
1636 !nasm_stricmp(value, "pentium") ) return IF_PENT;
1637 if (!strcmp(value, "686") ||
1638 !nasm_stricmp(value, "ppro") ||
1639 !nasm_stricmp(value, "pentiumpro") ||
1640 !nasm_stricmp(value, "p2") ) return IF_P6;
1641 if (!nasm_stricmp(value, "p3") ||
1642 !nasm_stricmp(value, "katmai") ) return IF_KATMAI;
1643 if (!nasm_stricmp(value, "p4") || /* is this right? -- jrc */
1644 !nasm_stricmp(value, "willamette") ) return IF_WILLAMETTE;
1645 if (!nasm_stricmp(value, "prescott") ) return IF_PRESCOTT;
1646 if (!nasm_stricmp(value, "ia64") ||
1647 !nasm_stricmp(value, "ia-64") ||
1648 !nasm_stricmp(value, "itanium") ||
1649 !nasm_stricmp(value, "itanic") ||
1650 !nasm_stricmp(value, "merced") ) return IF_IA64;
1652 report_error (pass0<2 ? ERR_NONFATAL : ERR_FATAL, "unknown 'cpu' type");
1654 return IF_PLEVEL; /* the maximum level */
1658 static int get_bits (char *value)
1660 int i;
1662 if ((i = atoi(value)) == 16) return i; /* set for a 16-bit segment */
1663 else if (i == 32) {
1664 if (cpu < IF_386) {
1665 report_error(ERR_NONFATAL,
1666 "cannot specify 32-bit segment on processor below a 386");
1667 i = 16;
1669 } else {
1670 report_error(pass0<2 ? ERR_NONFATAL : ERR_FATAL,
1671 "`%s' is not a valid segment size; must be 16 or 32",
1672 value);
1673 i = 16;
1675 return i;
1678 /* end of nasm.c */