/drivers/scsi/aic7xxx/aicasm/aicasm.c
C | 844 lines | 623 code | 103 blank | 118 comment | 147 complexity | b41125191872345514148bd8d14f2a39 MD5 | raw file
Possible License(s): GPL-2.0, LGPL-2.0, AGPL-1.0
- /*
- * Aic7xxx SCSI host adapter firmware asssembler
- *
- * Copyright (c) 1997, 1998, 2000, 2001 Justin T. Gibbs.
- * Copyright (c) 2001, 2002 Adaptec Inc.
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions, and the following disclaimer,
- * without modification.
- * 2. Redistributions in binary form must reproduce at minimum a disclaimer
- * substantially similar to the "NO WARRANTY" disclaimer below
- * ("Disclaimer") and any redistribution must be conditioned upon
- * including a substantially similar Disclaimer requirement for further
- * binary redistribution.
- * 3. Neither the names of the above-listed copyright holders nor the names
- * of any contributors may be used to endorse or promote products derived
- * from this software without specific prior written permission.
- *
- * Alternatively, this software may be distributed under the terms of the
- * GNU General Public License ("GPL") version 2 as published by the Free
- * Software Foundation.
- *
- * NO WARRANTY
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
- * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
- * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR
- * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
- * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
- * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
- * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
- * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
- * POSSIBILITY OF SUCH DAMAGES.
- *
- * $Id: //depot/aic7xxx/aic7xxx/aicasm/aicasm.c#23 $
- *
- * $FreeBSD$
- */
- #include <sys/types.h>
- #include <sys/mman.h>
- #include <ctype.h>
- #include <inttypes.h>
- #include <regex.h>
- #include <stdio.h>
- #include <stdlib.h>
- #include <string.h>
- #include <sysexits.h>
- #include <unistd.h>
- #if linux
- #include <endian.h>
- #else
- #include <machine/endian.h>
- #endif
- #include "aicasm.h"
- #include "aicasm_symbol.h"
- #include "aicasm_insformat.h"
- typedef struct patch {
- STAILQ_ENTRY(patch) links;
- int patch_func;
- u_int begin;
- u_int skip_instr;
- u_int skip_patch;
- } patch_t;
- STAILQ_HEAD(patch_list, patch) patches;
- static void usage(void);
- static void back_patch(void);
- static void output_code(void);
- static void output_listing(char *ifilename);
- static void dump_scope(scope_t *scope);
- static void emit_patch(scope_t *scope, int patch);
- static int check_patch(patch_t **start_patch, int start_instr,
- int *skip_addr, int *func_vals);
- struct path_list search_path;
- int includes_search_curdir;
- char *appname;
- char *stock_include_file;
- FILE *ofile;
- char *ofilename;
- char *regfilename;
- FILE *regfile;
- char *listfilename;
- FILE *listfile;
- char *regdiagfilename;
- FILE *regdiagfile;
- int src_mode;
- int dst_mode;
- static STAILQ_HEAD(,instruction) seq_program;
- struct cs_tailq cs_tailq;
- struct scope_list scope_stack;
- symlist_t patch_functions;
- #if DEBUG
- extern int yy_flex_debug;
- extern int mm_flex_debug;
- extern int yydebug;
- extern int mmdebug;
- #endif
- extern FILE *yyin;
- extern int yyparse(void);
- int main(int argc, char *argv[]);
- int
- main(int argc, char *argv[])
- {
- extern char *optarg;
- extern int optind;
- int ch;
- int retval;
- char *inputfilename;
- scope_t *sentinal;
- STAILQ_INIT(&patches);
- SLIST_INIT(&search_path);
- STAILQ_INIT(&seq_program);
- TAILQ_INIT(&cs_tailq);
- SLIST_INIT(&scope_stack);
- /* Set Sentinal scope node */
- sentinal = scope_alloc();
- sentinal->type = SCOPE_ROOT;
-
- includes_search_curdir = 1;
- appname = *argv;
- regfile = NULL;
- listfile = NULL;
- #if DEBUG
- yy_flex_debug = 0;
- mm_flex_debug = 0;
- yydebug = 0;
- mmdebug = 0;
- #endif
- while ((ch = getopt(argc, argv, "d:i:l:n:o:p:r:I:")) != -1) {
- switch(ch) {
- case 'd':
- #if DEBUG
- if (strcmp(optarg, "s") == 0) {
- yy_flex_debug = 1;
- mm_flex_debug = 1;
- } else if (strcmp(optarg, "p") == 0) {
- yydebug = 1;
- mmdebug = 1;
- } else {
- fprintf(stderr, "%s: -d Requires either an "
- "'s' or 'p' argument\n", appname);
- usage();
- }
- #else
- stop("-d: Assembler not built with debugging "
- "information", EX_SOFTWARE);
- #endif
- break;
- case 'i':
- stock_include_file = optarg;
- break;
- case 'l':
- /* Create a program listing */
- if ((listfile = fopen(optarg, "w")) == NULL) {
- perror(optarg);
- stop(NULL, EX_CANTCREAT);
- }
- listfilename = optarg;
- break;
- case 'n':
- /* Don't complain about the -nostdinc directrive */
- if (strcmp(optarg, "ostdinc")) {
- fprintf(stderr, "%s: Unknown option -%c%s\n",
- appname, ch, optarg);
- usage();
- /* NOTREACHED */
- }
- break;
- case 'o':
- if ((ofile = fopen(optarg, "w")) == NULL) {
- perror(optarg);
- stop(NULL, EX_CANTCREAT);
- }
- ofilename = optarg;
- break;
- case 'p':
- /* Create Register Diagnostic "printing" Functions */
- if ((regdiagfile = fopen(optarg, "w")) == NULL) {
- perror(optarg);
- stop(NULL, EX_CANTCREAT);
- }
- regdiagfilename = optarg;
- break;
- case 'r':
- if ((regfile = fopen(optarg, "w")) == NULL) {
- perror(optarg);
- stop(NULL, EX_CANTCREAT);
- }
- regfilename = optarg;
- break;
- case 'I':
- {
- path_entry_t include_dir;
- if (strcmp(optarg, "-") == 0) {
- if (includes_search_curdir == 0) {
- fprintf(stderr, "%s: Warning - '-I-' "
- "specified multiple "
- "times\n", appname);
- }
- includes_search_curdir = 0;
- for (include_dir = SLIST_FIRST(&search_path);
- include_dir != NULL;
- include_dir = SLIST_NEXT(include_dir,
- links))
- /*
- * All entries before a '-I-' only
- * apply to includes specified with
- * quotes instead of "<>".
- */
- include_dir->quoted_includes_only = 1;
- } else {
- include_dir =
- (path_entry_t)malloc(sizeof(*include_dir));
- if (include_dir == NULL) {
- perror(optarg);
- stop(NULL, EX_OSERR);
- }
- include_dir->directory = strdup(optarg);
- if (include_dir->directory == NULL) {
- perror(optarg);
- stop(NULL, EX_OSERR);
- }
- include_dir->quoted_includes_only = 0;
- SLIST_INSERT_HEAD(&search_path, include_dir,
- links);
- }
- break;
- }
- case '?':
-