aicasm.c (23925) | aicasm.c (23991) |
---|---|
1/* 2 * Aic7xxx SCSI host adapter firmware asssembler 3 * 4 * Copyright (c) 1997 Justin T. Gibbs. 5 * All rights reserved. 6 * 7 * Redistribution and use in source and binary forms, with or without 8 * modification, are permitted provided that the following conditions --- 14 unchanged lines hidden (view full) --- 23 * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 24 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 25 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 26 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 27 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 28 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 29 * SUCH DAMAGE. 30 * | 1/* 2 * Aic7xxx SCSI host adapter firmware asssembler 3 * 4 * Copyright (c) 1997 Justin T. Gibbs. 5 * All rights reserved. 6 * 7 * Redistribution and use in source and binary forms, with or without 8 * modification, are permitted provided that the following conditions --- 14 unchanged lines hidden (view full) --- 23 * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 24 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 25 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 26 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 27 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 28 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 29 * SUCH DAMAGE. 30 * |
31 * $Id$ | 31 * $Id: aic7xxx_asm.c,v 1.15 1997/03/16 07:08:15 gibbs Exp $ |
32 */ 33#include <sys/types.h> 34#include <sys/mman.h> 35 36#include <stdio.h> 37#include <stdlib.h> 38#include <string.h> 39#include <sysexits.h> 40#include <unistd.h> 41 42#include "aic7xxx_asm.h" 43#include "symbol.h" 44#include "sequencer.h" 45 46static void usage __P((void)); 47static void back_patch __P((void)); 48static void output_code __P((FILE *ofile)); | 32 */ 33#include <sys/types.h> 34#include <sys/mman.h> 35 36#include <stdio.h> 37#include <stdlib.h> 38#include <string.h> 39#include <sysexits.h> 40#include <unistd.h> 41 42#include "aic7xxx_asm.h" 43#include "symbol.h" 44#include "sequencer.h" 45 46static void usage __P((void)); 47static void back_patch __P((void)); 48static void output_code __P((FILE *ofile)); |
49static void output_listing __P((FILE *listfile, char *ifilename)); | 49static void output_listing __P((FILE *listfile, char *ifilename, 50 char *options)); 51static struct patch *next_patch __P((struct patch *cur_patch, int options, 52 int instrptr)); |
50 51struct path_list search_path; 52int includes_search_curdir; 53char *appname; 54FILE *ofile; 55char *ofilename; 56 57static STAILQ_HEAD(,instruction) seq_program; --- 16 unchanged lines hidden (view full) --- 74 extern int optind; 75 int ch; 76 int retval; 77 char *inputfilename; 78 char *regfilename; 79 FILE *regfile; 80 char *listfilename; 81 FILE *listfile; | 53 54struct path_list search_path; 55int includes_search_curdir; 56char *appname; 57FILE *ofile; 58char *ofilename; 59 60static STAILQ_HEAD(,instruction) seq_program; --- 16 unchanged lines hidden (view full) --- 77 extern int optind; 78 int ch; 79 int retval; 80 char *inputfilename; 81 char *regfilename; 82 FILE *regfile; 83 char *listfilename; 84 FILE *listfile; |
85 char *options; |
|
82 83 SLIST_INIT(&search_path); 84 STAILQ_INIT(&seq_program); 85 STAILQ_INIT(&patch_list); 86 SLIST_INIT(&patch_options); 87 includes_search_curdir = 1; 88 appname = *argv; 89 regfile = NULL; 90 listfile = NULL; | 86 87 SLIST_INIT(&search_path); 88 STAILQ_INIT(&seq_program); 89 STAILQ_INIT(&patch_list); 90 SLIST_INIT(&patch_options); 91 includes_search_curdir = 1; 92 appname = *argv; 93 regfile = NULL; 94 listfile = NULL; |
95 options = NULL; |
|
91#if DEBUG 92 yy_flex_debug = 0; 93#endif | 96#if DEBUG 97 yy_flex_debug = 0; 98#endif |
94 while ((ch = getopt(argc, argv, "d:l:n:o:r:I:")) != EOF) { | 99 while ((ch = getopt(argc, argv, "d:l:n:o:r:I:O:")) != EOF) { |
95 switch(ch) { 96 case 'd': 97#if DEBUG 98 if (strcmp(optarg, "s") == 0) 99 yy_flex_debug = 1; 100 else if (strcmp(optarg, "p") == 0) 101 yydebug = 1; 102#else --- 20 unchanged lines hidden (view full) --- 123 break; 124 case 'o': 125 if ((ofile = fopen(optarg, "w")) == NULL) { 126 perror(optarg); 127 stop(NULL, EX_CANTCREAT); 128 } 129 ofilename = optarg; 130 break; | 100 switch(ch) { 101 case 'd': 102#if DEBUG 103 if (strcmp(optarg, "s") == 0) 104 yy_flex_debug = 1; 105 else if (strcmp(optarg, "p") == 0) 106 yydebug = 1; 107#else --- 20 unchanged lines hidden (view full) --- 128 break; 129 case 'o': 130 if ((ofile = fopen(optarg, "w")) == NULL) { 131 perror(optarg); 132 stop(NULL, EX_CANTCREAT); 133 } 134 ofilename = optarg; 135 break; |
136 case 'O': 137 /* Patches to include in the listing */ 138 options = optarg; 139 break; |
|
131 case 'r': 132 if ((regfile = fopen(optarg, "w")) == NULL) { 133 perror(optarg); 134 stop(NULL, EX_CANTCREAT); 135 } 136 regfilename = optarg; 137 break; 138 case 'I': --- 55 unchanged lines hidden (view full) --- 194 retval = yyparse(); 195 if (retval == 0) { 196 back_patch(); 197 if (ofile != NULL) 198 output_code(ofile); 199 if (regfile != NULL) 200 symtable_dump(regfile); 201 if (listfile != NULL) | 140 case 'r': 141 if ((regfile = fopen(optarg, "w")) == NULL) { 142 perror(optarg); 143 stop(NULL, EX_CANTCREAT); 144 } 145 regfilename = optarg; 146 break; 147 case 'I': --- 55 unchanged lines hidden (view full) --- 203 retval = yyparse(); 204 if (retval == 0) { 205 back_patch(); 206 if (ofile != NULL) 207 output_code(ofile); 208 if (regfile != NULL) 209 symtable_dump(regfile); 210 if (listfile != NULL) |
202 output_listing(listfile, inputfilename); | 211 output_listing(listfile, inputfilename, options); |
203 } 204 205 stop(NULL, 0); 206 /* NOTREACHED */ 207 return (0); 208} 209 210static void 211usage() 212{ 213 | 212 } 213 214 stop(NULL, 0); 215 /* NOTREACHED */ 216 return (0); 217} 218 219static void 220usage() 221{ 222 |
214 (void)fprintf(stderr, "usage: %s [-I directory] [-o output_file] " 215 "input_file\n", appname); | 223 (void)fprintf(stderr, 224"usage: %-16s [-nostdinc] [-I-] [-I directory] [-o output_file] 225 [-r register_output_file] [-l program_list_file] 226 [-O option_name[|options_name2]] input_file\n", 227 appname); |
216 exit(EX_USAGE); 217} 218 219static void 220back_patch() 221{ 222 struct instruction *cur_instr; 223 --- 56 unchanged lines hidden (view full) --- 280 * Output the patch list, option definitions first. 281 */ 282 for(cur_node = patch_options.slh_first; 283 cur_node != NULL; 284 cur_node = cur_node->links.sle_next) { 285 fprintf(ofile, "#define\t%-16s\t0x%x\n", cur_node->symbol->name, 286 cur_node->symbol->info.condinfo->value); 287 } | 228 exit(EX_USAGE); 229} 230 231static void 232back_patch() 233{ 234 struct instruction *cur_instr; 235 --- 56 unchanged lines hidden (view full) --- 292 * Output the patch list, option definitions first. 293 */ 294 for(cur_node = patch_options.slh_first; 295 cur_node != NULL; 296 cur_node = cur_node->links.sle_next) { 297 fprintf(ofile, "#define\t%-16s\t0x%x\n", cur_node->symbol->name, 298 cur_node->symbol->info.condinfo->value); 299 } |
288 symlist_free(&patch_options); | |
289 290 fprintf(ofile, 291"struct patch { 292 int options; 293 int negative; 294 int begin; 295 int end; 296} patches[] = {\n"); --- 8 unchanged lines hidden (view full) --- 305 306 fprintf(ofile, "\t{ 0x%08x, %d, 0x%03x, 0x%03x }\n};\n", 307 0, 0, 0, 0); 308 309 fprintf(stderr, "%s: %d instructions used\n", appname, instrcount); 310} 311 312void | 300 301 fprintf(ofile, 302"struct patch { 303 int options; 304 int negative; 305 int begin; 306 int end; 307} patches[] = {\n"); --- 8 unchanged lines hidden (view full) --- 316 317 fprintf(ofile, "\t{ 0x%08x, %d, 0x%03x, 0x%03x }\n};\n", 318 0, 0, 0, 0); 319 320 fprintf(stderr, "%s: %d instructions used\n", appname, instrcount); 321} 322 323void |
313output_listing(listfile, ifilename) | 324output_listing(listfile, ifilename, patches) |
314 FILE *listfile; 315 char *ifilename; | 325 FILE *listfile; 326 char *ifilename; |
327 char *patches; |
|
316{ 317 FILE *ifile; 318 int line; 319 struct instruction *cur_instr; 320 int instrcount; | 328{ 329 FILE *ifile; 330 int line; 331 struct instruction *cur_instr; 332 int instrcount; |
333 int instrptr; |
|
321 char buf[1024]; | 334 char buf[1024]; |
335 patch_t *cur_patch; 336 char *option_spec; 337 int options; |
|
322 323 instrcount = 0; | 338 339 instrcount = 0; |
340 instrptr = 0; |
|
324 line = 1; | 341 line = 1; |
342 options = 1; /* All code outside of patch blocks */ |
|
325 if ((ifile = fopen(ifilename, "r")) == NULL) { 326 perror(ifilename); 327 stop(NULL, EX_DATAERR); 328 } | 343 if ((ifile = fopen(ifilename, "r")) == NULL) { 344 perror(ifilename); 345 stop(NULL, EX_DATAERR); 346 } |
347 348 /* 349 * Determine which options to apply to this listing. 350 */ 351 while ((option_spec = strsep(&patches, "|")) != NULL) { 352 symbol_t *symbol; 353 354 symbol = symtable_get(option_spec); 355 if (symbol->type != CONDITIONAL) { 356 stop("Invalid option specified in patch list for " 357 "program listing", EX_USAGE); 358 /* NOTREACHED */ 359 } 360 options |= symbol->info.condinfo->value; 361 } 362 363 cur_patch = patch_list.stqh_first; |
|
329 for(cur_instr = seq_program.stqh_first; 330 cur_instr != NULL; | 364 for(cur_instr = seq_program.stqh_first; 365 cur_instr != NULL; |
331 cur_instr = cur_instr->links.stqe_next) { | 366 cur_instr = cur_instr->links.stqe_next,instrcount++) { 367 368 cur_patch = next_patch(cur_patch, options, instrcount); 369 if (cur_patch 370 && cur_patch->begin <= instrcount 371 && cur_patch->end > instrcount) 372 /* Don't count this instruction as it is in a patch 373 * that was removed. 374 */ 375 continue; 376 |
332 while (line < cur_instr->srcline) { 333 fgets(buf, sizeof(buf), ifile); 334 fprintf(listfile, "\t\t%s", buf); 335 line++; 336 } | 377 while (line < cur_instr->srcline) { 378 fgets(buf, sizeof(buf), ifile); 379 fprintf(listfile, "\t\t%s", buf); 380 line++; 381 } |
337 fprintf(listfile, "%03x %02x%02x%02x%02x", instrcount, | 382 fprintf(listfile, "%03x %02x%02x%02x%02x", instrptr, |
338 cur_instr->format.bytes[0], 339 cur_instr->format.bytes[1], 340 cur_instr->format.bytes[2], 341 cur_instr->format.bytes[3]); 342 fgets(buf, sizeof(buf), ifile); | 383 cur_instr->format.bytes[0], 384 cur_instr->format.bytes[1], 385 cur_instr->format.bytes[2], 386 cur_instr->format.bytes[3]); 387 fgets(buf, sizeof(buf), ifile); |
343 fprintf(listfile, "%s", buf); | 388 fprintf(listfile, "\t%s", buf); |
344 line++; | 389 line++; |
345 instrcount++; | 390 instrptr++; |
346 } | 391 } |
392 /* Dump the remainder of the file */ 393 while(fgets(buf, sizeof(buf), ifile) != NULL) 394 fprintf(listfile, "\t\t%s", buf); 395 |
|
347 fclose(ifile); 348} 349 | 396 fclose(ifile); 397} 398 |
399static struct patch * 400next_patch(cur_patch, options, instrptr) 401 struct patch *cur_patch; 402 int options; 403 int instrptr; 404{ 405 while(cur_patch != NULL) { 406 if (((cur_patch->options & options) != 0 407 && cur_patch->negative == FALSE) 408 || ((cur_patch->options & options) == 0 409 && cur_patch->negative == TRUE) 410 || (instrptr >= cur_patch->end)) { 411 /* 412 * Either we want to keep this section of code, 413 * or we have consumed this patch. Skip to the 414 * next patch. 415 */ 416 cur_patch = cur_patch->links.stqe_next; 417 } else 418 /* Found an okay patch */ 419 break; 420 } 421 return (cur_patch); 422} 423 |
|
350/* 351 * Print out error information if appropriate, and clean up before 352 * terminating the program. 353 */ 354void 355stop(string, err_code) 356 const char *string; 357 int err_code; --- 11 unchanged lines hidden (view full) --- 369 fclose(ofile); 370 if (err_code != 0) { 371 fprintf(stderr, "%s: Removing %s due to error\n", 372 appname, ofilename); 373 unlink(ofilename); 374 } 375 } 376 | 424/* 425 * Print out error information if appropriate, and clean up before 426 * terminating the program. 427 */ 428void 429stop(string, err_code) 430 const char *string; 431 int err_code; --- 11 unchanged lines hidden (view full) --- 443 fclose(ofile); 444 if (err_code != 0) { 445 fprintf(stderr, "%s: Removing %s due to error\n", 446 appname, ofilename); 447 unlink(ofilename); 448 } 449 } 450 |
451 symlist_free(&patch_options); |
|
377 symtable_close(); 378 379 exit(err_code); 380} 381 382struct instruction * 383seq_alloc() 384{ --- 23 unchanged lines hidden --- | 452 symtable_close(); 453 454 exit(err_code); 455} 456 457struct instruction * 458seq_alloc() 459{ --- 23 unchanged lines hidden --- |