Changes to CHANGES, AUTHORS
[nasm.git] / nasm.c
blob5d37a34736b11553c74fade1c73832a391872848
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 *buf, 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 if ( !(param = get_param (p, q, &advance)) )
382 break;
383 if (p[1]=='o') { /* output file */
384 strcpy (outname, param);
385 } else if (p[1]=='f') { /* output format */
386 ofmt = ofmt_find(param);
387 if (!ofmt) {
388 report_error (ERR_FATAL | ERR_NOFILE | ERR_USAGE,
389 "unrecognised output format `%s' - "
390 "use -hf for a list",
391 param);
393 else
394 ofmt->current_dfmt = ofmt->debug_formats[0];
395 } else if (p[1]=='O') { /* Optimization level */
396 int opt;
397 opt = -99;
398 while (*param) {
399 if (isdigit(*param)) {
400 opt = atoi(param);
401 while(isdigit(*++param)) ;
402 if (opt<=0) optimizing = -1; /* 0.98 behaviour */
403 else if (opt==1) optimizing = 0; /* Two passes, 0.98.09 behavior */
404 else if (opt<=3) optimizing = opt*5; /* Multiple passes */
405 else optimizing = opt; /* Multiple passes */
406 } else {
407 if (*param == 'v' || *param == '+') {
408 ++param;
409 opt_verbose_info = TRUE;
410 opt = 0;
413 } /* while (*param) */
414 if (opt == -99) report_error(ERR_FATAL,
415 "command line optimization level must be 'v', 0..3 or <nn>");
416 } else if (p[1]=='P' || p[1]=='p') { /* pre-include */
417 pp_pre_include (param);
418 } else if (p[1]=='D' || p[1]=='d') { /* pre-define */
419 pp_pre_define (param);
420 } else if (p[1]=='U' || p[1]=='u') { /* un-define */
421 pp_pre_undefine (param);
422 } else if (p[1]=='I' || p[1]=='i') { /* include search path */
423 pp_include_path (param);
424 } else if (p[1]=='l') { /* listing file */
425 strcpy (listname, param);
426 } else if (p[1]=='E') { /* error messages file */
427 error_file = fopen(param, "w");
428 if ( !error_file ) {
429 error_file = stderr; /* Revert to default! */
430 report_error (ERR_FATAL | ERR_NOFILE | ERR_USAGE,
431 "cannot open file `%s' for error messages",
432 param);
434 } else if (p[1] == 'F') { /* specify debug format */
435 ofmt->current_dfmt = dfmt_find(ofmt, param);
436 if (!ofmt->current_dfmt) {
437 report_error (ERR_FATAL | ERR_NOFILE | ERR_USAGE,
438 "unrecognized debug format `%s' for"
439 " output format `%s'",
440 param, ofmt->shortname);
442 } else if (p[1] == 'X') { /* specify error reporting format */
443 if (nasm_stricmp("vc", param) == 0)
444 report_error = report_error_vc;
445 else if (nasm_stricmp("gnu", param) == 0)
446 report_error = report_error_gnu;
447 else
448 report_error (ERR_FATAL | ERR_NOFILE | ERR_USAGE,
449 "unrecognized error reporting format `%s'",
450 param);
452 break;
453 case 'g':
454 using_debug_info = TRUE;
455 break;
456 case 'h':
457 printf("usage: nasm [-@ response file] [-o outfile] [-f format] "
458 "[-l listfile]\n"
459 " [options...] [--] filename\n"
460 " or nasm -r for version info (obsolete)\n"
461 " or nasm -v for version info (preferred)\n\n"
462 " -t Assemble in SciTech TASM compatible mode\n"
463 " -g Generate debug information in selected format.\n");
464 printf(" -e preprocess only (writes output to stdout by default)\n"
465 " -a don't preprocess (assemble only)\n"
466 " -M generate Makefile dependencies on stdout\n\n"
467 " -E<file> redirect error messages to file\n"
468 " -s redirect error messages to stdout\n\n"
469 " -F format select a debugging format\n\n"
470 " -I<path> adds a pathname to the include file path\n");
471 printf(" -O<digit> optimize branch offsets (-O0 disables, default)\n"
472 " -P<file> pre-includes a file\n"
473 " -D<macro>[=<value>] pre-defines a macro\n"
474 " -U<macro> undefines a macro\n"
475 " -X<format> specifies error reporting format (gnu or vc)\n"
476 " -w+foo enables warnings about foo; -w-foo disables them\n"
477 "where foo can be:\n");
478 for (i=1; i<=ERR_WARN_MAX; i++)
479 printf(" %-23s %s (default %s)\n",
480 suppressed_names[i], suppressed_what[i],
481 suppressed[i] ? "off" : "on");
482 printf ("\nresponse files should contain command line parameters"
483 ", one per line.\n");
484 if (p[2] == 'f') {
485 printf("\nvalid output formats for -f are"
486 " (`*' denotes default):\n");
487 ofmt_list(ofmt, stdout);
489 else {
490 printf ("\nFor a list of valid output formats, use -hf.\n");
491 printf ("For a list of debug formats, use -f <form> -y.\n");
493 exit (0); /* never need usage message here */
494 break;
495 case 'y':
496 printf("\nvalid debug formats for '%s' output format are"
497 " ('*' denotes default):\n",
498 ofmt->shortname);
499 dfmt_list(ofmt, stdout);
500 exit(0);
501 break;
502 case 't':
503 tasm_compatible_mode = TRUE;
504 break;
505 case 'r':
506 case 'v':
508 const char *nasm_version_string =
509 "NASM version " NASM_VER " compiled on " __DATE__
510 #ifdef DEBUG
511 " with -DDEBUG"
512 #endif
514 puts(nasm_version_string);
515 exit (0); /* never need usage message here */
517 break;
518 case 'e': /* preprocess only */
519 operating_mode = op_preprocess;
520 break;
521 case 'a': /* assemble only - don't preprocess */
522 preproc = &no_pp;
523 break;
524 case 'w':
525 if (p[2] != '+' && p[2] != '-') {
526 report_error (ERR_NONFATAL | ERR_NOFILE | ERR_USAGE,
527 "invalid option to `-w'");
528 } else {
529 for (i=1; i<=ERR_WARN_MAX; i++)
530 if (!nasm_stricmp(p+3, suppressed_names[i]))
531 break;
532 if (i <= ERR_WARN_MAX)
533 suppressed[i] = (p[2] == '-');
534 else
535 report_error (ERR_NONFATAL | ERR_NOFILE | ERR_USAGE,
536 "invalid option to `-w'");
538 break;
539 case 'M':
540 operating_mode = op_depend;
541 break;
543 case '-':
545 int s;
547 if (p[2]==0) { /* -- => stop processing options */
548 stopoptions = 1;
549 break;
551 for(s=0; textopts[s].label; s++)
553 if(!nasm_stricmp(p+2, textopts[s].label))
555 break;
559 switch(s)
562 case OPT_PREFIX:
563 case OPT_POSTFIX:
565 if (!q)
567 report_error (ERR_NONFATAL | ERR_NOFILE | ERR_USAGE,
568 "option `--%s' requires an argument",
569 p+2);
570 break;
572 else
574 advance = 1, param = q;
577 if(s == OPT_PREFIX)
579 strncpy(lprefix,param,PREFIX_MAX-1);
580 lprefix[PREFIX_MAX-1]=0;
581 break;
583 if(s == OPT_POSTFIX)
585 strncpy(lpostfix,param,POSTFIX_MAX-1);
586 lpostfix[POSTFIX_MAX-1]=0;
587 break;
589 break;
591 default:
593 report_error (ERR_NONFATAL | ERR_NOFILE | ERR_USAGE,
594 "unrecognised option `--%s'",
595 p+2);
596 break;
599 break;
602 default:
603 if (!ofmt->setinfo(GI_SWITCH,&p))
604 report_error (ERR_NONFATAL | ERR_NOFILE | ERR_USAGE,
605 "unrecognised option `-%c'",
606 p[1]);
607 break;
610 else
612 if (*inname) {
613 report_error (ERR_NONFATAL | ERR_NOFILE | ERR_USAGE,
614 "more than one input file specified");
615 } else
616 strcpy(inname, p);
619 return advance;
622 #define ARG_BUF_DELTA 128
624 static void process_respfile (FILE *rfile)
626 char *buffer, *p, *q, *prevarg;
627 int bufsize, prevargsize;
629 bufsize = prevargsize = ARG_BUF_DELTA;
630 buffer = nasm_malloc(ARG_BUF_DELTA);
631 prevarg = nasm_malloc(ARG_BUF_DELTA);
632 prevarg[0] = '\0';
634 while (1) { /* Loop to handle all lines in file */
636 p = buffer;
637 while (1) { /* Loop to handle long lines */
638 q = fgets(p, bufsize-(p-buffer), rfile);
639 if (!q)
640 break;
641 p += strlen(p);
642 if (p > buffer && p[-1] == '\n')
643 break;
644 if (p-buffer > bufsize-10) {
645 int offset;
646 offset = p - buffer;
647 bufsize += ARG_BUF_DELTA;
648 buffer = nasm_realloc(buffer, bufsize);
649 p = buffer + offset;
653 if (!q && p == buffer) {
654 if (prevarg[0])
655 process_arg (prevarg, NULL);
656 nasm_free (buffer);
657 nasm_free (prevarg);
658 return;
662 * Play safe: remove CRs, LFs and any spurious ^Zs, if any of
663 * them are present at the end of the line.
665 *(p = &buffer[strcspn(buffer, "\r\n\032")]) = '\0';
667 while (p > buffer && isspace(p[-1]))
668 *--p = '\0';
670 p = buffer;
671 while (isspace(*p))
672 p++;
674 if (process_arg (prevarg, p))
675 *p = '\0';
677 if (strlen(p) > prevargsize-10) {
678 prevargsize += ARG_BUF_DELTA;
679 prevarg = nasm_realloc(prevarg, prevargsize);
681 strcpy (prevarg, p);
685 /* Function to process args from a string of args, rather than the
686 * argv array. Used by the environment variable and response file
687 * processing.
689 static void process_args (char *args) {
690 char *p, *q, *arg, *prevarg;
691 char separator = ' ';
693 p = args;
694 if (*p && *p != '-')
695 separator = *p++;
696 arg = NULL;
697 while (*p) {
698 q = p;
699 while (*p && *p != separator) p++;
700 while (*p == separator) *p++ = '\0';
701 prevarg = arg;
702 arg = q;
703 if (process_arg (prevarg, arg))
704 arg = NULL;
706 if (arg)
707 process_arg (arg, NULL);
710 static void parse_cmdline(int argc, char **argv)
712 FILE *rfile;
713 char *envreal, *envcopy=NULL, *p, *arg;
715 *inname = *outname = *listname = '\0';
718 * First, process the NASMENV environment variable.
720 envreal = getenv("NASMENV");
721 arg = NULL;
722 if (envreal) {
723 envcopy = nasm_strdup(envreal);
724 process_args(envcopy);
725 nasm_free (envcopy);
729 * Now process the actual command line.
731 while (--argc)
733 int i;
734 argv++;
735 if (argv[0][0] == '@') {
736 /* We have a response file, so process this as a set of
737 * arguments like the environment variable. This allows us
738 * to have multiple arguments on a single line, which is
739 * different to the -@resp file processing below for regular
740 * NASM.
742 char *str = malloc(2048);
743 FILE *f = fopen(&argv[0][1],"r");
744 if (!str) {
745 printf("out of memory");
746 exit(-1);
748 if (f) {
749 while (fgets(str,2048,f)) {
750 process_args(str);
752 fclose(f);
754 free(str);
755 argc--;
756 argv++;
758 if (!stopoptions && argv[0][0] == '-' && argv[0][1] == '@') {
759 if ((p = get_param (argv[0], argc > 1 ? argv[1] : NULL, &i))) {
760 if ((rfile = fopen(p, "r"))) {
761 process_respfile (rfile);
762 fclose(rfile);
763 } else
764 report_error (ERR_NONFATAL | ERR_NOFILE | ERR_USAGE,
765 "unable to open response file `%s'", p);
767 } else
768 i = process_arg (argv[0], argc > 1 ? argv[1] : NULL);
769 argv += i, argc -= i;
772 if (!*inname)
773 report_error (ERR_NONFATAL | ERR_NOFILE | ERR_USAGE,
774 "no input file specified");
778 static void assemble_file (char *fname)
780 char * value, * p, * q, * special, * line, debugid[80];
781 insn output_ins;
782 int i, rn_error, validid;
783 long seg, offs;
784 struct tokenval tokval;
785 expr * e;
786 int pass, pass_max;
787 int pass_cnt = 0; /* count actual passes */
789 if (cmd_sb == 32 && cmd_cpu < IF_386)
790 report_error(ERR_FATAL, "command line: "
791 "32-bit segment size requires a higher cpu");
793 pass_max = (optimizing>0 ? optimizing : 0) + 2; /* passes 1, optimizing, then 2 */
794 pass0 = !(optimizing>0); /* start at 1 if not optimizing */
795 for (pass = 1; pass <= pass_max && pass0 <= 2; pass++) {
796 int pass1, pass2;
797 ldfunc def_label;
799 pass1 = pass < pass_max ? 1 : 2; /* seq is 1, 1, 1,..., 1, 2 */
800 pass2 = pass > 1 ? 2 : 1; /* seq is 1, 2, 2,..., 2, 2 */
801 /* pass0 seq is 0, 0, 0,..., 1, 2 */
803 def_label = pass > 1 ? redefine_label : define_label;
806 sb = cmd_sb; /* set 'bits' to command line default */
807 cpu = cmd_cpu;
808 if (pass0 == 2) {
809 if (*listname)
810 nasmlist.init(listname, report_error);
812 in_abs_seg = FALSE;
813 global_offset_changed = FALSE; /* set by redefine_label */
814 location.segment = ofmt->section(NULL, pass2, &sb);
815 if (pass > 1) {
816 saa_rewind (forwrefs);
817 forwref = saa_rstruct (forwrefs);
818 raa_free (offsets);
819 offsets = raa_init();
821 preproc->reset(fname, pass1, report_error, evaluate, &nasmlist);
822 globallineno = 0;
823 if (pass == 1) location.known = TRUE;
824 location.offset = offs = GET_CURR_OFFS;
826 while ( (line = preproc->getline()) )
828 globallineno++;
830 /* here we parse our directives; this is not handled by the 'real'
831 * parser. */
832 if ( (i = getkw (line, &value)) )
834 switch (i) {
835 case 1: /* [SEGMENT n] */
836 seg = ofmt->section (value, pass2, &sb);
837 if (seg == NO_SEG) {
838 report_error (pass1==1 ? ERR_NONFATAL : ERR_PANIC,
839 "segment name `%s' not recognised",
840 value);
841 } else {
842 in_abs_seg = FALSE;
843 location.segment = seg;
845 break;
846 case 2: /* [EXTERN label:special] */
847 if (*value == '$') value++; /* skip initial $ if present */
848 if (pass0 == 2) {
849 q = value;
850 while (*q && *q != ':')
851 q++;
852 if (*q == ':') {
853 *q++ = '\0';
854 ofmt->symdef(value, 0L, 0L, 3, q);
856 } else if (pass == 1) { /* pass == 1 */
857 q = value;
858 validid = TRUE;
859 if (!isidstart(*q))
860 validid = FALSE;
861 while (*q && *q != ':') {
862 if (!isidchar(*q))
863 validid = FALSE;
864 q++;
866 if (!validid) {
867 report_error (ERR_NONFATAL,
868 "identifier expected after EXTERN");
869 break;
871 if (*q == ':') {
872 *q++ = '\0';
873 special = q;
874 } else
875 special = NULL;
876 if (!is_extern(value)) { /* allow re-EXTERN to be ignored */
877 int temp = pass0;
878 pass0 = 1; /* fake pass 1 in labels.c */
879 declare_as_global (value, special, report_error);
880 define_label (value, seg_alloc(), 0L, NULL, FALSE, TRUE,
881 ofmt, report_error);
882 pass0 = temp;
884 } /* else pass0 == 1 */
885 break;
886 case 3: /* [BITS bits] */
887 sb = get_bits(value);
888 break;
889 case 4: /* [GLOBAL symbol:special] */
890 if (*value == '$') value++; /* skip initial $ if present */
891 if (pass0 == 2) { /* pass 2 */
892 q = value;
893 while (*q && *q != ':')
894 q++;
895 if (*q == ':') {
896 *q++ = '\0';
897 ofmt->symdef(value, 0L, 0L, 3, q);
899 } else if (pass2 == 1) { /* pass == 1 */
900 q = value;
901 validid = TRUE;
902 if (!isidstart(*q))
903 validid = FALSE;
904 while (*q && *q != ':') {
905 if (!isidchar(*q))
906 validid = FALSE;
907 q++;
909 if (!validid) {
910 report_error (ERR_NONFATAL,
911 "identifier expected after GLOBAL");
912 break;
914 if (*q == ':') {
915 *q++ = '\0';
916 special = q;
917 } else
918 special = NULL;
919 declare_as_global (value, special, report_error);
920 } /* pass == 1 */
921 break;
922 case 5: /* [COMMON symbol size:special] */
923 if (*value == '$') value++; /* skip initial $ if present */
924 if (pass0 == 1) {
925 p = value;
926 validid = TRUE;
927 if (!isidstart(*p))
928 validid = FALSE;
929 while (*p && !isspace(*p)) {
930 if (!isidchar(*p))
931 validid = FALSE;
932 p++;
934 if (!validid) {
935 report_error (ERR_NONFATAL,
936 "identifier expected after COMMON");
937 break;
939 if (*p) {
940 long size;
942 while (*p && isspace(*p))
943 *p++ = '\0';
944 q = p;
945 while (*q && *q != ':')
946 q++;
947 if (*q == ':') {
948 *q++ = '\0';
949 special = q;
950 } else
951 special = NULL;
952 size = readnum (p, &rn_error);
953 if (rn_error)
954 report_error (ERR_NONFATAL, "invalid size specified"
955 " in COMMON declaration");
956 else
957 define_common (value, seg_alloc(), size,
958 special, ofmt, report_error);
959 } else
960 report_error (ERR_NONFATAL, "no size specified in"
961 " COMMON declaration");
962 } else if (pass0 == 2) { /* pass == 2 */
963 q = value;
964 while (*q && *q != ':') {
965 if (isspace(*q))
966 *q = '\0';
967 q++;
969 if (*q == ':') {
970 *q++ = '\0';
971 ofmt->symdef(value, 0L, 0L, 3, q);
974 break;
975 case 6: /* [ABSOLUTE address] */
976 stdscan_reset();
977 stdscan_bufptr = value;
978 tokval.t_type = TOKEN_INVALID;
979 e = evaluate(stdscan, NULL, &tokval, NULL, pass2, report_error,
980 NULL);
981 if (e) {
982 if (!is_reloc(e))
983 report_error (pass0==1 ? ERR_NONFATAL : ERR_PANIC,
984 "cannot use non-relocatable expression as "
985 "ABSOLUTE address");
986 else {
987 abs_seg = reloc_seg(e);
988 abs_offset = reloc_value(e);
990 } else
991 if (pass==1) abs_offset = 0x100;/* don't go near zero in case of / */
992 else report_error (ERR_PANIC, "invalid ABSOLUTE address "
993 "in pass two");
994 in_abs_seg = TRUE;
995 location.segment = NO_SEG;
996 break;
997 case 7: /* DEBUG */
998 p = value;
999 q = debugid;
1000 validid = TRUE;
1001 if (!isidstart(*p))
1002 validid = FALSE;
1003 while (*p && !isspace(*p)) {
1004 if (!isidchar(*p))
1005 validid = FALSE;
1006 *q++ = *p++;
1008 *q++ = 0;
1009 if (!validid) {
1010 report_error (pass==1 ? ERR_NONFATAL : ERR_PANIC,
1011 "identifier expected after DEBUG");
1012 break;
1014 while (*p && isspace(*p)) p++;
1015 if (pass==pass_max) ofmt->current_dfmt->debug_directive (debugid, p);
1016 break;
1017 case 8: /* [WARNING {+|-}warn-name] */
1018 if (pass1 == 1) {
1019 while (*value && isspace(*value))
1020 value++;
1022 if (*value == '+' || *value == '-') {
1023 validid = (*value == '-') ? TRUE : FALSE;
1024 value++;
1025 } else
1026 validid = FALSE;
1028 for (i=1; i<=ERR_WARN_MAX; i++)
1029 if (!nasm_stricmp(value, suppressed_names[i]))
1030 break;
1031 if (i <= ERR_WARN_MAX)
1032 suppressed[i] = validid;
1033 else
1034 report_error (ERR_NONFATAL, "invalid warning id in WARNING directive");
1036 break;
1037 case 9: /* cpu */
1038 cpu = get_cpu (value);
1039 break;
1040 case 10: /* fbk 9/2/00 */ /* [LIST {+|-}] */
1041 while (*value && isspace(*value))
1042 value++;
1044 if (*value == '+') {
1045 user_nolist = 0;
1047 else {
1048 if (*value == '-') {
1049 user_nolist = 1;
1051 else {
1052 report_error (ERR_NONFATAL, "invalid parameter to \"list\" directive");
1055 break;
1056 default:
1057 if (!ofmt->directive (line+1, value, pass2))
1058 report_error (pass1==1 ? ERR_NONFATAL : ERR_PANIC,
1059 "unrecognised directive [%s]",
1060 line+1);
1063 else /* it isn't a directive */
1065 parse_line (pass1, line, &output_ins,
1066 report_error, evaluate,
1067 def_label);
1069 if (!(optimizing>0) && pass == 2) {
1070 if (forwref != NULL && globallineno == forwref->lineno) {
1071 output_ins.forw_ref = TRUE;
1072 do {
1073 output_ins.oprs[forwref->operand].opflags |= OPFLAG_FORWARD;
1074 forwref = saa_rstruct (forwrefs);
1075 } while (forwref != NULL && forwref->lineno == globallineno);
1076 } else
1077 output_ins.forw_ref = FALSE;
1081 if (!(optimizing>0) && output_ins.forw_ref)
1083 if (pass == 1) {
1084 for(i = 0; i < output_ins.operands; i++)
1086 if (output_ins.oprs[i].opflags & OPFLAG_FORWARD)
1088 struct forwrefinfo *fwinf =
1089 (struct forwrefinfo *)saa_wstruct(forwrefs);
1090 fwinf->lineno = globallineno;
1091 fwinf->operand = i;
1094 } else { /* pass == 2 */
1096 * Hack to prevent phase error in the code
1097 * rol ax,x
1098 * x equ 1
1100 * If the second operand is a forward reference,
1101 * the UNITY property of the number 1 in that
1102 * operand is cancelled. Otherwise the above
1103 * sequence will cause a phase error.
1105 * This hack means that the above code will
1106 * generate 286+ code.
1108 * The forward reference will mean that the
1109 * operand will not have the UNITY property on
1110 * the first pass, so the pass behaviours will
1111 * be consistent.
1114 if (output_ins.operands >= 2 &&
1115 (output_ins.oprs[1].opflags & OPFLAG_FORWARD))
1117 output_ins.oprs[1].type &= ~(ONENESS|BYTENESS);
1120 } /* pass == 2 */
1122 } /* forw_ref */
1125 if (output_ins.opcode == I_EQU) {
1126 if (pass1 == 1)
1129 * Special `..' EQUs get processed in pass two,
1130 * except `..@' macro-processor EQUs which are done
1131 * in the normal place.
1133 if (!output_ins.label)
1134 report_error (ERR_NONFATAL,
1135 "EQU not preceded by label");
1137 else if (output_ins.label[0] != '.' ||
1138 output_ins.label[1] != '.' ||
1139 output_ins.label[2] == '@')
1141 if (output_ins.operands == 1 &&
1142 (output_ins.oprs[0].type & IMMEDIATE) &&
1143 output_ins.oprs[0].wrt == NO_SEG)
1145 int isext = output_ins.oprs[0].opflags & OPFLAG_EXTERN;
1146 def_label (output_ins.label,
1147 output_ins.oprs[0].segment,
1148 output_ins.oprs[0].offset,
1149 NULL, FALSE, isext, ofmt, report_error);
1151 else if (output_ins.operands == 2 &&
1152 (output_ins.oprs[0].type & IMMEDIATE) &&
1153 (output_ins.oprs[0].type & COLON) &&
1154 output_ins.oprs[0].segment == NO_SEG &&
1155 output_ins.oprs[0].wrt == NO_SEG &&
1156 (output_ins.oprs[1].type & IMMEDIATE) &&
1157 output_ins.oprs[1].segment == NO_SEG &&
1158 output_ins.oprs[1].wrt == NO_SEG)
1160 def_label (output_ins.label,
1161 output_ins.oprs[0].offset | SEG_ABS,
1162 output_ins.oprs[1].offset,
1163 NULL, FALSE, FALSE, ofmt, report_error);
1165 else
1166 report_error(ERR_NONFATAL, "bad syntax for EQU");
1168 } else { /* pass == 2 */
1170 * Special `..' EQUs get processed here, except
1171 * `..@' macro processor EQUs which are done above.
1173 if (output_ins.label[0] == '.' &&
1174 output_ins.label[1] == '.' &&
1175 output_ins.label[2] != '@')
1177 if (output_ins.operands == 1 &&
1178 (output_ins.oprs[0].type & IMMEDIATE)) {
1179 define_label (output_ins.label,
1180 output_ins.oprs[0].segment,
1181 output_ins.oprs[0].offset,
1182 NULL, FALSE, FALSE, ofmt, report_error);
1184 else if (output_ins.operands == 2 &&
1185 (output_ins.oprs[0].type & IMMEDIATE) &&
1186 (output_ins.oprs[0].type & COLON) &&
1187 output_ins.oprs[0].segment == NO_SEG &&
1188 (output_ins.oprs[1].type & IMMEDIATE) &&
1189 output_ins.oprs[1].segment == NO_SEG)
1191 define_label (output_ins.label,
1192 output_ins.oprs[0].offset | SEG_ABS,
1193 output_ins.oprs[1].offset,
1194 NULL, FALSE, FALSE, ofmt, report_error);
1196 else
1197 report_error(ERR_NONFATAL, "bad syntax for EQU");
1199 } /* pass == 2 */
1200 } else { /* instruction isn't an EQU */
1202 if (pass1 == 1) {
1204 long l = insn_size (location.segment, offs, sb, cpu,
1205 &output_ins, report_error);
1207 /* if (using_debug_info) && output_ins.opcode != -1)*/
1208 if (using_debug_info) /* fbk 03/25/01 */
1211 /* this is done here so we can do debug type info */
1212 long typeinfo = TYS_ELEMENTS(output_ins.operands);
1213 switch (output_ins.opcode) {
1214 case I_RESB:
1215 typeinfo = TYS_ELEMENTS(output_ins.oprs[0].offset) | TY_BYTE;
1216 break;
1217 case I_RESW:
1218 typeinfo = TYS_ELEMENTS(output_ins.oprs[0].offset) | TY_WORD;
1219 break;
1220 case I_RESD:
1221 typeinfo = TYS_ELEMENTS(output_ins.oprs[0].offset) | TY_DWORD;
1222 break;
1223 case I_RESQ:
1224 typeinfo = TYS_ELEMENTS(output_ins.oprs[0].offset) | TY_QWORD;
1225 break;
1226 case I_REST:
1227 typeinfo = TYS_ELEMENTS(output_ins.oprs[0].offset) | TY_TBYTE;
1228 break;
1229 case I_DB:
1230 typeinfo |= TY_BYTE;
1231 break;
1232 case I_DW:
1233 typeinfo |= TY_WORD;
1234 break;
1235 case I_DD:
1236 if (output_ins.eops_float)
1237 typeinfo |= TY_FLOAT;
1238 else
1239 typeinfo |= TY_DWORD;
1240 break;
1241 case I_DQ:
1242 typeinfo |= TY_QWORD;
1243 break;
1244 case I_DT:
1245 typeinfo |= TY_TBYTE;
1246 break;
1247 default:
1248 typeinfo = TY_LABEL;
1252 ofmt->current_dfmt->debug_typevalue(typeinfo);
1255 if (l != -1) {
1256 offs += l;
1257 SET_CURR_OFFS (offs);
1260 * else l == -1 => invalid instruction, which will be
1261 * flagged as an error on pass 2
1264 } else { /* pass == 2 */
1265 offs += assemble (location.segment, offs, sb, cpu,
1266 &output_ins, ofmt, report_error, &nasmlist);
1267 SET_CURR_OFFS (offs);
1270 } /* not an EQU */
1271 cleanup_insn (&output_ins);
1273 nasm_free (line);
1274 location.offset = offs = GET_CURR_OFFS;
1275 } /* end while (line = preproc->getline... */
1277 if (pass1==2 && global_offset_changed)
1278 report_error(ERR_NONFATAL, "phase error detected at end of assembly.");
1280 if (pass1 == 1) preproc->cleanup(1);
1282 if (pass1==1 && terminate_after_phase) {
1283 fclose(ofile);
1284 remove(outname);
1285 if (want_usage)
1286 usage();
1287 exit (1);
1289 pass_cnt++;
1290 if (pass>1 && !global_offset_changed) {
1291 pass0++;
1292 if (pass0==2) pass = pass_max - 1;
1293 } else if (!(optimizing>0)) pass0++;
1295 } /* for (pass=1; pass<=2; pass++) */
1297 preproc->cleanup(0);
1298 nasmlist.cleanup();
1299 #if 1
1300 if (optimizing>0 && opt_verbose_info) /* -On and -Ov switches */
1301 fprintf(stdout,
1302 "info:: assembly required 1+%d+1 passes\n", pass_cnt-2);
1303 #endif
1304 } /* exit from assemble_file (...) */
1307 static int getkw (char *buf, char **value)
1309 char *p, *q;
1311 /* allow leading spaces or tabs */
1312 while (*buf==' ' || *buf=='\t')
1313 buf++;
1315 if (*buf!='[')
1316 return 0;
1318 p = buf;
1320 while (*p && *p != ']') p++;
1322 if (!*p)
1323 return 0;
1325 q = p++;
1327 while (*p && *p != ';') {
1328 if (!isspace(*p))
1329 return 0;
1330 p++;
1332 q[1] = '\0';
1334 p = buf+1;
1335 while (*buf && *buf!=' ' && *buf!=']' && *buf!='\t')
1336 buf++;
1337 if (*buf==']') {
1338 *buf = '\0';
1339 *value = buf;
1340 } else {
1341 *buf++ = '\0';
1342 while (isspace(*buf)) buf++; /* beppu - skip leading whitespace */
1343 *value = buf;
1344 while (*buf!=']') buf++;
1345 *buf++ = '\0';
1347 #if 0
1348 for (q=p; *q; q++)
1349 *q = tolower(*q);
1350 #endif
1351 if (!nasm_stricmp(p, "segment") || !nasm_stricmp(p, "section"))
1352 return 1;
1353 if (!nasm_stricmp(p, "extern"))
1354 return 2;
1355 if (!nasm_stricmp(p, "bits"))
1356 return 3;
1357 if (!nasm_stricmp(p, "global"))
1358 return 4;
1359 if (!nasm_stricmp(p, "common"))
1360 return 5;
1361 if (!nasm_stricmp(p, "absolute"))
1362 return 6;
1363 if (!nasm_stricmp(p, "debug"))
1364 return 7;
1365 if (!nasm_stricmp(p, "warning"))
1366 return 8;
1367 if (!nasm_stricmp(p, "cpu"))
1368 return 9;
1369 if (!nasm_stricmp(p, "list")) /* fbk 9/2/00 */
1370 return 10;
1371 return -1;
1375 * gnu style error reporting
1376 * This function prints an error message to error_file in the
1377 * style used by GNU. An example would be:
1378 * file.asm:50: error: blah blah blah
1379 * where file.asm is the name of the file, 50 is the line number on
1380 * which the error occurs (or is detected) and "error:" is one of
1381 * the possible optional diagnostics -- it can be "error" or "warning"
1382 * or something else. Finally the line terminates with the actual
1383 * error message.
1385 * @param severity the severity of the warning or error
1386 * @param fmt the printf style format string
1388 static void report_error_gnu (int severity, const char *fmt, ...)
1390 va_list ap;
1392 if (is_suppressed_warning(severity))
1393 return;
1395 if (severity & ERR_NOFILE)
1396 fputs ("nasm: ", error_file);
1397 else {
1398 char * currentfile = NULL;
1399 long lineno = 0;
1400 src_get (&lineno, &currentfile);
1401 fprintf (error_file, "%s:%ld: ", currentfile, lineno);
1402 nasm_free (currentfile);
1404 va_start (ap, fmt);
1405 report_error_common (severity, fmt, ap);
1406 va_end (ap);
1410 * MS style error reporting
1411 * This function prints an error message to error_file in the
1412 * style used by Visual C and some other Microsoft tools. An example
1413 * would be:
1414 * file.asm(50) : error: blah blah blah
1415 * where file.asm is the name of the file, 50 is the line number on
1416 * which the error occurs (or is detected) and "error:" is one of
1417 * the possible optional diagnostics -- it can be "error" or "warning"
1418 * or something else. Finally the line terminates with the actual
1419 * error message.
1421 * @param severity the severity of the warning or error
1422 * @param fmt the printf style format string
1424 static void report_error_vc (int severity, const char *fmt, ...)
1426 va_list ap;
1428 if (is_suppressed_warning (severity))
1429 return;
1431 if (severity & ERR_NOFILE)
1432 fputs ("nasm: ", error_file);
1433 else {
1434 char * currentfile = NULL;
1435 long lineno = 0;
1436 src_get (&lineno, &currentfile);
1437 fprintf (error_file, "%s(%ld) : ", currentfile, lineno);
1438 nasm_free (currentfile);
1440 va_start (ap, fmt);
1441 report_error_common (severity, fmt, ap);
1442 va_end (ap);
1446 * check for supressed warning
1447 * checks for suppressed warning or pass one only warning and we're
1448 * not in pass 1
1450 * @param severity the severity of the warning or error
1451 * @return true if we should abort error/warning printing
1453 static int is_suppressed_warning (int severity)
1456 * See if it's a suppressed warning.
1458 return ((severity & ERR_MASK) == ERR_WARNING &&
1459 (severity & ERR_WARN_MASK) != 0 &&
1460 suppressed[ (severity & ERR_WARN_MASK) >> ERR_WARN_SHR ]) ||
1462 * See if it's a pass-one only warning and we're not in pass one.
1464 ((severity & ERR_PASS1) && pass0 == 2);
1468 * common error reporting
1469 * This is the common back end of the error reporting schemes currently
1470 * implemented. It prints the nature of the warning and then the
1471 * specific error message to error_file and may or may not return. It
1472 * doesn't return if the error severity is a "panic" or "debug" type.
1474 * @param severity the severity of the warning or error
1475 * @param fmt the printf style format string
1477 static void report_error_common (int severity, const char *fmt, va_list args)
1479 switch (severity & ERR_MASK) {
1480 case ERR_WARNING:
1481 fputs ("warning: ", error_file); break;
1482 case ERR_NONFATAL:
1483 fputs ("error: ", error_file); break;
1484 case ERR_FATAL:
1485 fputs ("fatal: ", error_file); break;
1486 case ERR_PANIC:
1487 fputs ("panic: ", error_file); break;
1488 case ERR_DEBUG:
1489 fputs("debug: ", error_file); break;
1492 vfprintf (error_file, fmt, args);
1493 fputc ('\n', error_file);
1495 if (severity & ERR_USAGE)
1496 want_usage = TRUE;
1498 switch (severity & ERR_MASK) {
1499 case ERR_WARNING: case ERR_DEBUG:
1500 /* no further action, by definition */
1501 break;
1502 case ERR_NONFATAL:
1503 /* hack enables listing(!) on errors */
1504 terminate_after_phase = TRUE;
1505 break;
1506 case ERR_FATAL:
1507 if (ofile) {
1508 fclose(ofile);
1509 remove(outname);
1511 if (want_usage)
1512 usage();
1513 exit(1); /* instantly die */
1514 break; /* placate silly compilers */
1515 case ERR_PANIC:
1516 fflush(NULL);
1517 /* abort(); */ /* halt, catch fire, and dump core */
1518 exit(3);
1519 break;
1523 static void usage(void)
1525 fputs("type `nasm -h' for help\n", error_file);
1528 static void register_output_formats(void)
1530 ofmt = ofmt_register (report_error);
1533 #define BUF_DELTA 512
1535 static FILE *no_pp_fp;
1536 static efunc no_pp_err;
1537 static ListGen *no_pp_list;
1538 static long no_pp_lineinc;
1540 static void no_pp_reset (char *file, int pass, efunc error, evalfunc eval,
1541 ListGen *listgen)
1543 src_set_fname(nasm_strdup(file));
1544 src_set_linnum(0);
1545 no_pp_lineinc = 1;
1546 no_pp_err = error;
1547 no_pp_fp = fopen(file, "r");
1548 if (!no_pp_fp)
1549 no_pp_err (ERR_FATAL | ERR_NOFILE,
1550 "unable to open input file `%s'", file);
1551 no_pp_list = listgen;
1552 (void) pass; /* placate compilers */
1553 (void) eval; /* placate compilers */
1556 static char *no_pp_getline (void)
1558 char *buffer, *p, *q;
1559 int bufsize;
1561 bufsize = BUF_DELTA;
1562 buffer = nasm_malloc(BUF_DELTA);
1563 src_set_linnum(src_get_linnum() + no_pp_lineinc);
1565 while (1) { /* Loop to handle %line */
1567 p = buffer;
1568 while (1) { /* Loop to handle long lines */
1569 q = fgets(p, bufsize-(p-buffer), no_pp_fp);
1570 if (!q)
1571 break;
1572 p += strlen(p);
1573 if (p > buffer && p[-1] == '\n')
1574 break;
1575 if (p-buffer > bufsize-10) {
1576 int offset;
1577 offset = p - buffer;
1578 bufsize += BUF_DELTA;
1579 buffer = nasm_realloc(buffer, bufsize);
1580 p = buffer + offset;
1584 if (!q && p == buffer) {
1585 nasm_free (buffer);
1586 return NULL;
1590 * Play safe: remove CRs, LFs and any spurious ^Zs, if any of
1591 * them are present at the end of the line.
1593 buffer[strcspn(buffer, "\r\n\032")] = '\0';
1595 if (!strncmp(buffer, "%line", 5)) {
1596 long ln;
1597 int li;
1598 char *nm = nasm_malloc(strlen(buffer));
1599 if (sscanf(buffer+5, "%ld+%d %s", &ln, &li, nm) == 3) {
1600 nasm_free( src_set_fname(nm) );
1601 src_set_linnum(ln);
1602 no_pp_lineinc = li;
1603 continue;
1605 nasm_free(nm);
1607 break;
1610 no_pp_list->line (LIST_READ, buffer);
1612 return buffer;
1615 static void no_pp_cleanup (int pass)
1617 fclose(no_pp_fp);
1620 static unsigned long get_cpu (char *value)
1623 if (!strcmp(value, "8086")) return IF_8086;
1624 if (!strcmp(value, "186")) return IF_186;
1625 if (!strcmp(value, "286")) return IF_286;
1626 if (!strcmp(value, "386")) return IF_386;
1627 if (!strcmp(value, "486")) return IF_486;
1628 if (!strcmp(value, "586") ||
1629 !nasm_stricmp(value, "pentium") ) return IF_PENT;
1630 if (!strcmp(value, "686") ||
1631 !nasm_stricmp(value, "ppro") ||
1632 !nasm_stricmp(value, "pentiumpro") ||
1633 !nasm_stricmp(value, "p2") ) return IF_P6;
1634 if (!nasm_stricmp(value, "p3") ||
1635 !nasm_stricmp(value, "katmai") ) return IF_KATMAI;
1636 if (!nasm_stricmp(value, "p4") || /* is this right? -- jrc */
1637 !nasm_stricmp(value, "willamette") ) return IF_WILLAMETTE;
1638 if (!nasm_stricmp(value, "ia64") ||
1639 !nasm_stricmp(value, "ia-64") ||
1640 !nasm_stricmp(value, "itanium") ||
1641 !nasm_stricmp(value, "itanic") ||
1642 !nasm_stricmp(value, "merced") ) return IF_IA64;
1644 report_error (pass0<2 ? ERR_NONFATAL : ERR_FATAL, "unknown 'cpu' type");
1646 return IF_PLEVEL; /* the maximum level */
1650 static int get_bits (char *value)
1652 int i;
1654 if ((i = atoi(value)) == 16) return i; /* set for a 16-bit segment */
1655 else if (i == 32) {
1656 if (cpu < IF_386) {
1657 report_error(ERR_NONFATAL,
1658 "cannot specify 32-bit segment on processor below a 386");
1659 i = 16;
1661 } else {
1662 report_error(pass0<2 ? ERR_NONFATAL : ERR_FATAL,
1663 "`%s' is not a valid segment size; must be 16 or 32",
1664 value);
1665 i = 16;
1667 return i;
1670 /* end of nasm.c */