Annotation of researchv9/cmd/sun/as/init.c, revision 1.1.1.1

1.1       root        1: #ifndef lint
                      2: static char sccsid[] = "@(#)init.c 1.1 86/02/03 Copyr 1985 Sun Micro";
                      3: #endif
                      4: 
                      5: /*
                      6:  * Copyright (c) 1985 by Sun Microsystems, Inc.
                      7:  */
                      8: 
                      9: #include "as.h"
                     10: 
                     11: char title[STR_MAX];
                     12: char o_outfile = 0;            /* 1 if .rel file name is specified by user */
                     13: int pass = 0;                  /* which pass we're on */
                     14: int implicit_cpid = INITIAL_CPID ; /* Default coprocessor id. */
                     15: int current_cpid ;             /* Coprocessor for current instruction. */
                     16: char rel_name[STR_MAX];                /* Name of .rel file */
                     17: FILE *rel_file;                        /* and ptr to it */
                     18: struct sym_bkt *dot_bkt ;      /* Ptr to location counter's symbol bucket */
                     19: long tsize = 0;                        /* sizes of three main csects */
                     20: long dsize = 0;
                     21: long d1size = 0;
                     22: long d2size = 0;
                     23: long bsize = 0;
                     24: struct ins_ptr *ins_hash_tab[HASH_MAX];
                     25: struct ins_ptr *inst;
                     26: char *source_name[FILES_MAX];
                     27: FILE *source_file[FILES_MAX];
                     28: int file_count= 0, current_file= 0;
                     29: char *asm_name;        /* set from argv[0] below: used in error.c */
                     30: int errors = 0;                /* Number of errors in this pass */
                     31: char file_name[STR_MAX];
                     32: char o_lflag = 0;
                     33: int  d2flag = 0;       /* all offsets are 16 bits */
                     34: int  rflag  = 0;       /* data goes at end of text segment (read-only) */
                     35: int  Oflag  = 0;        /* sdi optimization : over the whole file */
                     36: int  jsrflag = 0,      /* all "long" jumps use 16-bit displacements */
                     37:      Jflag   = 0,      /* all jumps are "long" */
                     38:      even_align_flag = 0, /* 0 = align on 4 byte boundaries; 1 = align on 2 bytes */
                     39:      hflag   = 0;      /* all calls use 4 byte displacement. other jumps are "long" */
                     40: #ifdef EBUG
                     41: int  debflag = 0;
                     42: #endif
                     43: 
                     44: extern int is68020();  /* undocumented hack from libc.a */
                     45: int ext_instruction_set; 
                     46: 
                     47: init(argc,argv)
                     48:        char *argv[];
                     49: {
                     50:        char *strncpy();
                     51:        char *cp1, *cp2, *end, *rindex();
                     52: 
                     53:        ext_instruction_set = is68020();
                     54:        asm_name = *(argv++);
                     55:        while (--argc) {
                     56:          if (argv[0][0] == '-') switch (argv[0][1]) {
                     57:            case 'o':   o_outfile++;
                     58:                        strcpy(rel_name, argv[1]);
                     59:                        argv++;                 
                     60:                        argc--;
                     61:                        break;
                     62: 
                     63:            case 'L':   
                     64:                        o_lflag++;
                     65:                        break;
                     66:            case 'R':
                     67:                        rflag++;
                     68:                        break;
                     69:            case 'h':
                     70:                        if (Oflag) goto Owarn;
                     71:                        if (Jflag && !hflag) goto Jwarn;
                     72:                        hflag++;
                     73:                        Jflag++;
                     74:                        break;
                     75:            case 'j':
                     76:                        jsrflag++;
                     77:                        Oflag++;
                     78:                        break;
                     79:            case 'J':
                     80:                        Jflag++;
                     81:                        if (Oflag) {
                     82:                                fprintf(stderr,"Warning: -J overrides -O\n");
                     83:                                Oflag = 0;
                     84:                        }
                     85:                        if (hflag) {
                     86:            Jwarn:              fprintf(stderr,"Warning: -J overrides -h\n");
                     87:                                hflag = 0;
                     88:                        }
                     89:                        break;
                     90:            case 'O':
                     91:                        if (Jflag) {
                     92:                                fprintf(stderr,"Warning: -J overrides -O\n");
                     93:                                Oflag = 0;
                     94:                                break;
                     95:                        }
                     96:                        if (hflag) {
                     97:            Owarn:              fprintf(stderr,"Warning: -h overrides -O\n");
                     98:                                Oflag = 0;
                     99:                                break;
                    100:                        }
                    101:                        Oflag++;
                    102:                        break;
                    103:            case '1':
                    104:                        if (argv[0][2] == '0'){
                    105:                                ext_instruction_set=0;
                    106:                                break;
                    107:                        }
                    108:                        goto oops;
                    109:            case '2':
                    110:                        if (argv[0][2] == '0'){
                    111:                                ext_instruction_set=1;
                    112:                                break;
                    113:                        }
                    114:                        goto oops;
                    115:            case 'm':
                    116:                        /*
                    117:                         * this is redundant but consistent with
                    118:                         * cc, f77, and pc
                    119:                         */
                    120:                        if (!strcmp(argv[0]+1,"m68010")) {
                    121:                                ext_instruction_set=0;
                    122:                                break;
                    123:                        }
                    124:                        if (!strcmp(argv[0]+1,"m68020")) {
                    125:                                ext_instruction_set=1;
                    126:                                break;
                    127:                        }
                    128:                        goto oops;
                    129:            case 'e':
                    130:                        even_align_flag = 1 ;
                    131:                        break ;
                    132: #ifdef EBUG
                    133:            case 'D':
                    134:                        debflag++;
                    135:                        break;
                    136: #endif
                    137:            case 'd':
                    138:                        if (argv[0][2] == '2'){
                    139:                                d2flag++;
                    140:                                Oflag++;
                    141:                                break;
                    142:                        }
                    143:                        /* else fall through */
                    144: 
                    145:            oops:
                    146:            default:    fprintf(stderr,"%s: Unknown option '%c' ignored.\n",
                    147:                                asm_name, argv[0][1]);
                    148:          } else {
                    149:                if (file_count >= FILES_MAX) {
                    150:                        fprintf(stderr, "Too many source files given (max=%d)\n", FILES_MAX); exit(99);};
                    151:                source_name[file_count] = argv[0];
                    152:                strcpy(file_name, argv[0]);
                    153:                if ((source_file[file_count]= fopen(file_name,"r")) == NULL) {
                    154:                    /* open source file */
                    155:                    if ((end = rindex(source_name[file_count], '.')) == 0 || strcmp(end, ".a68") != 0) {
                    156:                            fprintf(stderr,"%s: Can't open source file: %s\n", asm_name, file_name);
                    157:                            exit(1);
                    158:                    }
                    159:                         strncpy(file_name, argv[0], STR_MAX);
                    160:                         if ((source_file[file_count]= fopen(file_name,"r")) == NULL) {
                    161:                             fprintf(stderr,"Can't open source file: %s\n",file_name);
                    162:                             exit(1);
                    163:                         }}
                    164:                file_count++;
                    165:          }
                    166:          argv++;
                    167:        }
                    168: 
                    169:        if (file_count == 0){
                    170:                fprintf(stderr,"%s: No input file\n", asm_name);
                    171:                exit( 99 );
                    172:        }
                    173: 
                    174: 
                    175: /* Check to see if we can open output file */
                    176:        if(!o_outfile) {
                    177:                strcpy(rel_name, "a.out");
                    178:        }
                    179:        if ((rel_file = fopen(rel_name,"w")) == NULL){
                    180:                printf("%s: Can't create output file: %s\n",asm_name,rel_name);
                    181:                exit(1);
                    182:        }
                    183:        fclose(rel_file);       /* rel_header will open properly */
                    184: 
                    185:        sym_init();             /* Initialize symbols */
                    186:        dot_bkt = lookup(".");          /* make bucket for location counter */
                    187:        dot_bkt->csect_s = cur_csect_name;
                    188:        dot_bkt->attr_s = S_DEC | S_DEF | S_LABEL;      /* "S_LABEL" so it cant be redefined as a label */
                    189:        init_regs();                    /* define register names */
                    190:        d_ins();                        /* set up opcode hash table */
                    191:        perm();
                    192:        start_pass();
                    193: }
                    194: 

unix.superglobalmegacorp.com

This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.