/* * Aic7xxx SCSI host adapter firmware assembler symbol table implementation * * Copyright (c) 1997 Justin T. Gibbs. * Copyright (c) 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_symbol.c#24 $ * * $FreeBSD$
*/
/* * The semantics of get is to return an uninitialized symbol entry * if a lookup fails.
*/
symbol_t *
symtable_get(char *name)
{
symbol_t *stored_ptr;
DBT key;
DBT data; int retval;
key.data = (void *)name;
key.size = strlen(name);
if ((retval = symtable->get(symtable, &key, &data, /*flags*/0)) != 0) { if (retval == -1) {
perror("Symbol table get operation failed"); exit(EX_SOFTWARE); /* NOTREACHED */
} elseif (retval == 1) { /* Symbol wasn't found, so create a new one */
symbol_t *new_symbol;
new_symbol = symbol_create(name);
data.data = &new_symbol;
data.size = sizeof(new_symbol); if (symtable->put(symtable, &key, &data, /*flags*/0) !=0) {
perror("Symtable put failed"); exit(EX_SOFTWARE);
} return (new_symbol);
} else {
perror("Unexpected return value from db get routine"); exit(EX_SOFTWARE); /* NOTREACHED */
}
}
memcpy(&stored_ptr, data.data, sizeof(stored_ptr));
stored_ptr->count++;
data.data = &stored_ptr; if (symtable->put(symtable, &key, &data, /*flags*/0) !=0) {
perror("Symtable put failed"); exit(EX_SOFTWARE);
} return (stored_ptr);
}
void
symlist_add(symlist_t *symlist, symbol_t *symbol, int how)
{
symbol_node_t *newnode;
newnode = (symbol_node_t *)malloc(sizeof(symbol_node_t)); if (newnode == NULL) {
stop("symlist_add: Unable to malloc symbol_node", EX_SOFTWARE); /* NOTREACHED */
}
newnode->symbol = symbol; if (how == SYMLIST_SORT) {
symbol_node_t *curnode; int field;
field = FALSE; switch(symbol->type) { caseREGISTER: case SCBLOC: case SRAMLOC: break; case FIELD: case MASK: caseENUM: case ENUM_ENTRY:
field = TRUE; break; default:
stop("symlist_add: Invalid symbol type for sorting",
EX_SOFTWARE); /* NOTREACHED */
}
void
symtable_dump(FILE *ofile, FILE *dfile)
{ /* * Sort the registers by address with a simple insertion sort. * Put bitmasks next to the first register that defines them. * Put constants at the end.
*/
symlist_t registers;
symlist_t masks;
symlist_t constants;
symlist_t download_constants;
symlist_t aliases;
symlist_t exported_labels;
symbol_node_t *curnode;
symbol_node_t *regnode;
DBT key;
DBT data; int flag; int reg_count = 0, reg_used = 0;
u_int i;
if (symtable == NULL) return;
SLIST_INIT(®isters);
SLIST_INIT(&masks);
SLIST_INIT(&constants);
SLIST_INIT(&download_constants);
SLIST_INIT(&aliases);
SLIST_INIT(&exported_labels);
flag = R_FIRST; while (symtable->seq(symtable, &key, &data, flag) == 0) {
symbol_t *cursym;
memcpy(&cursym, data.data, sizeof(cursym)); switch(cursym->type) { caseREGISTER: case SCBLOC: case SRAMLOC:
symlist_add(®isters, cursym, SYMLIST_SORT); break; case MASK: case FIELD: caseENUM: case ENUM_ENTRY:
symlist_add(&masks, cursym, SYMLIST_SORT); break; caseCONST:
symlist_add(&constants, cursym,
SYMLIST_INSERT_HEAD); break; case DOWNLOAD_CONST:
symlist_add(&download_constants, cursym,
SYMLIST_INSERT_HEAD); break; case ALIAS:
symlist_add(&aliases, cursym,
SYMLIST_INSERT_HEAD); break; case LABEL: if (cursym->info.linfo->exported == 0) break;
symlist_add(&exported_labels, cursym,
SYMLIST_INSERT_HEAD); break; default: break;
}
flag = R_NEXT;
}
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.