⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 aicasm_symbol.c

📁 linux-2.6.15.6
💻 C
📖 第 1 页 / 共 2 页
字号:
/* * Aic7xxx SCSI host adapter firmware asssembler 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$ */#include <sys/types.h>#ifdef __linux__#include "aicdb.h"#else#include <db.h>#endif#include <fcntl.h>#include <inttypes.h>#include <regex.h>#include <stdio.h>#include <stdlib.h>#include <string.h>#include <sysexits.h>#include "aicasm_symbol.h"#include "aicasm.h"static DB *symtable;symbol_t *symbol_create(char *name){	symbol_t *new_symbol;	new_symbol = (symbol_t *)malloc(sizeof(symbol_t));	if (new_symbol == NULL) {		perror("Unable to create new symbol");		exit(EX_SOFTWARE);	}	memset(new_symbol, 0, sizeof(*new_symbol));	new_symbol->name = strdup(name);	if (new_symbol->name == NULL)		 stop("Unable to strdup symbol name", EX_SOFTWARE);	new_symbol->type = UNINITIALIZED;	return (new_symbol);}voidsymbol_delete(symbol_t *symbol){	if (symtable != NULL) {		DBT	 key;		key.data = symbol->name;		key.size = strlen(symbol->name);		symtable->del(symtable, &key, /*flags*/0);	}	switch(symbol->type) {	case SCBLOC:	case SRAMLOC:	case REGISTER:		if (symbol->info.rinfo != NULL)			free(symbol->info.rinfo);		break;	case ALIAS:		if (symbol->info.ainfo != NULL)			free(symbol->info.ainfo);		break;	case MASK:	case FIELD:	case ENUM:	case ENUM_ENTRY:		if (symbol->info.finfo != NULL) {			symlist_free(&symbol->info.finfo->symrefs);			free(symbol->info.finfo);		}		break;	case DOWNLOAD_CONST:	case CONST:		if (symbol->info.cinfo != NULL)			free(symbol->info.cinfo);		break;	case LABEL:		if (symbol->info.linfo != NULL)			free(symbol->info.linfo);		break;	case UNINITIALIZED:	default:		break;	}	free(symbol->name);	free(symbol);}voidsymtable_open(){	symtable = dbopen(/*filename*/NULL,			  O_CREAT | O_NONBLOCK | O_RDWR, /*mode*/0, DB_HASH,			  /*openinfo*/NULL);	if (symtable == NULL) {		perror("Symbol table creation failed");		exit(EX_SOFTWARE);		/* NOTREACHED */	}}voidsymtable_close(){	if (symtable != NULL) {		DBT	 key;		DBT	 data;		while (symtable->seq(symtable, &key, &data, R_FIRST) == 0) {			symbol_t *stored_ptr;			memcpy(&stored_ptr, data.data, sizeof(stored_ptr));			symbol_delete(stored_ptr);		}		symtable->close(symtable);	}}/* * 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 */		} else if (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));	return (stored_ptr);}symbol_node_t *symlist_search(symlist_t *symlist, char *symname){	symbol_node_t *curnode;	curnode = SLIST_FIRST(symlist);	while(curnode != NULL) {		if (strcmp(symname, curnode->symbol->name) == 0)			break;		curnode = SLIST_NEXT(curnode, links);	}	return (curnode);}voidsymlist_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) {		case REGISTER:		case SCBLOC:		case SRAMLOC:			break;		case FIELD:		case MASK:		case ENUM:		case ENUM_ENTRY:			field = TRUE;			break;		default:			stop("symlist_add: Invalid symbol type for sorting",			     EX_SOFTWARE);			/* NOTREACHED */		}		curnode = SLIST_FIRST(symlist);		if (curnode == NULL		 || (field		  && (curnode->symbol->type > newnode->symbol->type		   || (curnode->symbol->type == newnode->symbol->type		    && (curnode->symbol->info.finfo->value >			newnode->symbol->info.finfo->value))))		 || (!field && (curnode->symbol->info.rinfo->address >		               newnode->symbol->info.rinfo->address))) {			SLIST_INSERT_HEAD(symlist, newnode, links);			return;		}		while (1) {			if (SLIST_NEXT(curnode, links) == NULL) {				SLIST_INSERT_AFTER(curnode, newnode,						   links);				break;			} else {				symbol_t *cursymbol;				cursymbol = SLIST_NEXT(curnode, links)->symbol;				if ((field		  		  && (cursymbol->type > symbol->type				   || (cursymbol->type == symbol->type				    && (cursymbol->info.finfo->value >					symbol->info.finfo->value))))				 || (!field				   && (cursymbol->info.rinfo->address >				       symbol->info.rinfo->address))) {					SLIST_INSERT_AFTER(curnode, newnode,							   links);					break;				}			}			curnode = SLIST_NEXT(curnode, links);		}	} else {		SLIST_INSERT_HEAD(symlist, newnode, links);	}}voidsymlist_free(symlist_t *symlist){	symbol_node_t *node1, *node2;	node1 = SLIST_FIRST(symlist);	while (node1 != NULL) {		node2 = SLIST_NEXT(node1, links);		free(node1);		node1 = node2;	}	SLIST_INIT(symlist);}voidsymlist_merge(symlist_t *symlist_dest, symlist_t *symlist_src1,	      symlist_t *symlist_src2){	symbol_node_t *node;	*symlist_dest = *symlist_src1;	while((node = SLIST_FIRST(symlist_src2)) != NULL) {		SLIST_REMOVE_HEAD(symlist_src2, links);		SLIST_INSERT_HEAD(symlist_dest, node, links);	}	/* These are now empty */	SLIST_INIT(symlist_src1);	SLIST_INIT(symlist_src2);}voidaic_print_file_prologue(FILE *ofile){	if (ofile == NULL)		return;	fprintf(ofile,"/*\n"" * DO NOT EDIT - This file is automatically generated\n"" *		 from the following source files:\n"" *\n""%s */\n",		versions);}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -