patch-2.4.22 linux-2.4.22/drivers/scsi/aic7xxx/aicasm/aicasm_symbol.c

Next file: linux-2.4.22/drivers/scsi/aic7xxx/aicasm/aicasm_symbol.h
Previous file: linux-2.4.22/drivers/scsi/aic7xxx/aicasm/aicasm_scan.l
Back to the patch index
Back to the overall index

diff -urN linux-2.4.21/drivers/scsi/aic7xxx/aicasm/aicasm_symbol.c linux-2.4.22/drivers/scsi/aic7xxx/aicasm/aicasm_symbol.c
@@ -2,6 +2,7 @@
  * 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
@@ -36,9 +37,9 @@
  * 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#14 $
+ * $Id: //depot/aic7xxx/aic7xxx/aicasm/aicasm_symbol.c#24 $
  *
- * $FreeBSD: src/sys/dev/aic7xxx/aicasm/aicasm_symbol.c,v 1.11.2.4 2002/04/29 19:36:36 gibbs Exp $
+ * $FreeBSD$
  */
 
 #include <sys/types.h>
@@ -49,6 +50,7 @@
 #include <db.h>
 #endif
 #include <fcntl.h>
+#include <inttypes.h>
 #include <regex.h>
 #include <stdio.h>
 #include <stdlib.h>
@@ -72,6 +74,8 @@
 	}
 	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);
 }
@@ -98,10 +102,12 @@
 			free(symbol->info.ainfo);
 		break;
 	case MASK:
-	case BIT:
-		if (symbol->info.minfo != NULL) {
-			symlist_free(&symbol->info.minfo->symrefs);
-			free(symbol->info.minfo);
+	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:
@@ -222,17 +228,19 @@
 	newnode->symbol = symbol;
 	if (how == SYMLIST_SORT) {
 		symbol_node_t *curnode;
-		int mask;
+		int field;
 
-		mask = FALSE;
+		field = FALSE;
 		switch(symbol->type) {
 		case REGISTER:
 		case SCBLOC:
 		case SRAMLOC:
 			break;
-		case BIT:
+		case FIELD:
 		case MASK:
-			mask = TRUE;
+		case ENUM:
+		case ENUM_ENTRY:
+			field = TRUE;
 			break;
 		default:
 			stop("symlist_add: Invalid symbol type for sorting",
@@ -242,9 +250,12 @@
 
 		curnode = SLIST_FIRST(symlist);
 		if (curnode == NULL
-		 || (mask && (curnode->symbol->info.minfo->mask >
-		              newnode->symbol->info.minfo->mask))
-		 || (!mask && (curnode->symbol->info.rinfo->address >
+		 || (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;
@@ -259,10 +270,14 @@
 				symbol_t *cursymbol;
 
 				cursymbol = SLIST_NEXT(curnode, links)->symbol;
-				if ((mask && (cursymbol->info.minfo->mask >
-				              symbol->info.minfo->mask))
-				 || (!mask &&(cursymbol->info.rinfo->address >
-				              symbol->info.rinfo->address))){
+				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;
@@ -307,20 +322,160 @@
 }
 
 void
-symtable_dump(FILE *ofile)
+aic_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);
+}
+
+void
+aic_print_include(FILE *dfile, char *include_file)
+{
+
+	if (dfile == NULL)
+		return;
+	fprintf(dfile, "\n#include \"%s\"\n\n", include_file);
+}
+
+void
+aic_print_reg_dump_types(FILE *ofile)
+{
+	if (ofile == NULL)
+		return;
+		
+	fprintf(ofile,
+"typedef int (%sreg_print_t)(u_int, u_int *, u_int);\n"
+"typedef struct %sreg_parse_entry {\n"
+"	char	*name;\n"
+"	uint8_t	 value;\n"
+"	uint8_t	 mask;\n"
+"} %sreg_parse_entry_t;\n"
+"\n",
+		prefix, prefix, prefix);
+}
+
+static void
+aic_print_reg_dump_start(FILE *dfile, symbol_node_t *regnode)
+{
+	if (dfile == NULL)
+		return;
+
+	fprintf(dfile,
+"static %sreg_parse_entry_t %s_parse_table[] = {\n",
+		prefix,
+		regnode->symbol->name);
+}
+
+static void
+aic_print_reg_dump_end(FILE *ofile, FILE *dfile,
+		       symbol_node_t *regnode, u_int num_entries)
+{
+	char *lower_name;
+	char *letter;
+
+	lower_name = strdup(regnode->symbol->name);
+	if (lower_name == NULL)
+		 stop("Unable to strdup symbol name", EX_SOFTWARE);
+	
+	for (letter = lower_name; *letter != '\0'; letter++)
+		*letter = tolower(*letter);
+
+	if (dfile != NULL) {
+		if (num_entries != 0)
+			fprintf(dfile,
+"\n"
+"};\n"
+"\n");
+
+		fprintf(dfile,
+"int\n"
+"%s%s_print(u_int regvalue, u_int *cur_col, u_int wrap)\n"
+"{\n"
+"	return (%sprint_register(%s%s, %d, \"%s\",\n"
+"	    0x%02x, regvalue, cur_col, wrap));\n"
+"}\n"
+"\n",
+			prefix,
+			lower_name,
+			prefix,
+			num_entries != 0 ? regnode->symbol->name : "NULL",
+			num_entries != 0 ? "_parse_table" : "",
+			num_entries,
+			regnode->symbol->name,
+			regnode->symbol->info.rinfo->address);
+	}
+
+	fprintf(ofile,
+"#if AIC_DEBUG_REGISTERS\n"
+"%sreg_print_t %s%s_print;\n"
+"#else\n"
+"#define %s%s_print(regvalue, cur_col, wrap) \\\n"
+"    %sprint_register(NULL, 0, \"%s\", 0x%02x, regvalue, cur_col, wrap)\n"
+"#endif\n"
+"\n",
+		prefix,
+		prefix,
+		lower_name,
+		prefix,
+		lower_name,
+		prefix,
+		regnode->symbol->name,
+		regnode->symbol->info.rinfo->address);
+}
+
+static void
+aic_print_reg_dump_entry(FILE *dfile, symbol_node_t *curnode)
+{
+	int num_tabs;
+
+	if (dfile == NULL)
+		return;
+
+	fprintf(dfile,
+"	{ \"%s\",",
+		curnode->symbol->name);
+
+	num_tabs = 3 - (strlen(curnode->symbol->name) + 5) / 8;
+
+	while (num_tabs-- > 0)
+		fputc('\t', dfile);
+	fprintf(dfile, "0x%02x, 0x%02x }",
+		curnode->symbol->info.finfo->value,
+		curnode->symbol->info.finfo->mask);
+}
+
+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;
-	u_int	  i;
+	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;
+	u_int		 i;
+
+	if (symtable == NULL)
+		return;
 
 	SLIST_INIT(&registers);
 	SLIST_INIT(&masks);
@@ -328,173 +483,195 @@
 	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;
 
-	if (symtable != NULL) {
-		DBT	 key;
-		DBT	 data;
-		int	 flag = R_FIRST;
+		memcpy(&cursym, data.data, sizeof(cursym));
+		switch(cursym->type) {
+		case REGISTER:
+		case SCBLOC:
+		case SRAMLOC:
+			symlist_add(&registers, cursym, SYMLIST_SORT);
+			break;
+		case MASK:
+		case FIELD:
+		case ENUM:
+		case ENUM_ENTRY:
+			symlist_add(&masks, cursym, SYMLIST_SORT);
+			break;
+		case CONST:
+			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;
+	}
 
-		while (symtable->seq(symtable, &key, &data, flag) == 0) {
-			symbol_t *cursym;
+	/* Register dianostic functions/declarations first. */
+	aic_print_file_prologue(ofile);
+	aic_print_reg_dump_types(ofile);
+	aic_print_file_prologue(dfile);
+	aic_print_include(dfile, stock_include_file);
+	SLIST_FOREACH(curnode, &registers, links) {
 
-			memcpy(&cursym, data.data, sizeof(cursym));
-			switch(cursym->type) {
-			case REGISTER:
-			case SCBLOC:
-			case SRAMLOC:
-				symlist_add(&registers, cursym, SYMLIST_SORT);
-				break;
-			case MASK:
-			case BIT:
-				symlist_add(&masks, cursym, SYMLIST_SORT);
-				break;
-			case CONST:
-				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;
+		switch(curnode->symbol->type) {
+		case REGISTER:
+		case SCBLOC:
+		case SRAMLOC:
+		{
+			symlist_t	*fields;
+			symbol_node_t	*fieldnode;
+			int		 num_entries;
+
+			num_entries = 0;
+			fields = &curnode->symbol->info.rinfo->fields;
+			SLIST_FOREACH(fieldnode, fields, links) {
+				if (num_entries == 0)
+					aic_print_reg_dump_start(dfile,
+								 curnode);
+				else if (dfile != NULL)
+					fputs(",\n", dfile);
+				num_entries++;
+				aic_print_reg_dump_entry(dfile, fieldnode);
 			}
-			flag = R_NEXT;
+			aic_print_reg_dump_end(ofile, dfile,
+					       curnode, num_entries);
+		}
+		default:
+			break;
 		}
+	}
 
-		/* Put in the masks and bits */
-		while (SLIST_FIRST(&masks) != NULL) {
-			symbol_node_t *curnode;
-			symbol_node_t *regnode;
-			char *regname;
+	/* Fold in the masks and bits */
+	while (SLIST_FIRST(&masks) != NULL) {
+		char *regname;
 
-			curnode = SLIST_FIRST(&masks);
-			SLIST_REMOVE_HEAD(&masks, links);
+		curnode = SLIST_FIRST(&masks);
+		SLIST_REMOVE_HEAD(&masks, links);
 
-			regnode =
-			    SLIST_FIRST(&curnode->symbol->info.minfo->symrefs);
-			regname = regnode->symbol->name;
-			regnode = symlist_search(&registers, regname);
-			SLIST_INSERT_AFTER(regnode, curnode, links);
-		}
+		regnode = SLIST_FIRST(&curnode->symbol->info.finfo->symrefs);
+		regname = regnode->symbol->name;
+		regnode = symlist_search(&registers, regname);
+		SLIST_INSERT_AFTER(regnode, curnode, links);
+	}
 
-		/* Add the aliases */
-		while (SLIST_FIRST(&aliases) != NULL) {
-			symbol_node_t *curnode;
-			symbol_node_t *regnode;
-			char *regname;
+	/* Add the aliases */
+	while (SLIST_FIRST(&aliases) != NULL) {
+		char *regname;
 
-			curnode = SLIST_FIRST(&aliases);
-			SLIST_REMOVE_HEAD(&aliases, links);
+		curnode = SLIST_FIRST(&aliases);
+		SLIST_REMOVE_HEAD(&aliases, links);
 
-			regname = curnode->symbol->info.ainfo->parent->name;
-			regnode = symlist_search(&registers, regname);
-			SLIST_INSERT_AFTER(regnode, curnode, links);
-		}
+		regname = curnode->symbol->info.ainfo->parent->name;
+		regnode = symlist_search(&registers, regname);
+		SLIST_INSERT_AFTER(regnode, curnode, links);
+	}
 
-		/* Output what we have */
-		fprintf(ofile,
-"/*
- * DO NOT EDIT - This file is automatically generated
- *		 from the following source files:
- *
-%s */\n", versions);
-		while (SLIST_FIRST(&registers) != NULL) {
-			symbol_node_t *curnode;
-			u_int value;
-			char *tab_str;
-			char *tab_str2;
-
-			curnode = SLIST_FIRST(&registers);
-			SLIST_REMOVE_HEAD(&registers, links);
-			switch(curnode->symbol->type) {
-			case REGISTER:
-			case SCBLOC:
-			case SRAMLOC:
-				fprintf(ofile, "\n");
-				value = curnode->symbol->info.rinfo->address;
-				tab_str = "\t";
-				tab_str2 = "\t\t";
-				break;
-			case ALIAS:
-			{
-				symbol_t *parent;
-
-				parent = curnode->symbol->info.ainfo->parent;
-				value = parent->info.rinfo->address;
-				tab_str = "\t";
-				tab_str2 = "\t\t";
-				break;
-			}
-			case MASK:
-			case BIT:
-				value = curnode->symbol->info.minfo->mask;
-				tab_str = "\t\t";
-				tab_str2 = "\t";
-				break;
-			default:
-				value = 0; /* Quiet compiler */
-				tab_str = NULL;
-				tab_str2 = NULL;
-				stop("symtable_dump: Invalid symbol type "
-				     "encountered", EX_SOFTWARE);
-				break;
-			}
-			fprintf(ofile, "#define%s%-16s%s0x%02x\n",
-				tab_str, curnode->symbol->name, tab_str2,
-				value);
-			free(curnode);
-		}
-		fprintf(ofile, "\n\n");
-
-		while (SLIST_FIRST(&constants) != NULL) {
-			symbol_node_t *curnode;
-
-			curnode = SLIST_FIRST(&constants);
-			SLIST_REMOVE_HEAD(&constants, links);
-			fprintf(ofile, "#define\t%-8s\t0x%02x\n",
-				curnode->symbol->name,
-				curnode->symbol->info.cinfo->value);
-			free(curnode);
+	/* Output generated #defines. */
+	while (SLIST_FIRST(&registers) != NULL) {
+		symbol_node_t *curnode;
+		u_int value;
+		char *tab_str;
+		char *tab_str2;
+
+		curnode = SLIST_FIRST(&registers);
+		SLIST_REMOVE_HEAD(&registers, links);
+		switch(curnode->symbol->type) {
+		case REGISTER:
+		case SCBLOC:
+		case SRAMLOC:
+			fprintf(ofile, "\n");
+			value = curnode->symbol->info.rinfo->address;
+			tab_str = "\t";
+			tab_str2 = "\t\t";
+			break;
+		case ALIAS:
+		{
+			symbol_t *parent;
+
+			parent = curnode->symbol->info.ainfo->parent;
+			value = parent->info.rinfo->address;
+			tab_str = "\t";
+			tab_str2 = "\t\t";
+			break;
 		}
+		case MASK:
+		case FIELD:
+		case ENUM:
+		case ENUM_ENTRY:
+			value = curnode->symbol->info.finfo->value;
+			tab_str = "\t\t";
+			tab_str2 = "\t";
+			break;
+		default:
+			value = 0; /* Quiet compiler */
+			tab_str = NULL;
+			tab_str2 = NULL;
+			stop("symtable_dump: Invalid symbol type "
+			     "encountered", EX_SOFTWARE);
+			break;
+		}
+		fprintf(ofile, "#define%s%-16s%s0x%02x\n",
+			tab_str, curnode->symbol->name, tab_str2,
+			value);
+		free(curnode);
+	}
+	fprintf(ofile, "\n\n");
 
-		
-		fprintf(ofile, "\n\n/* Downloaded Constant Definitions */\n");
+	while (SLIST_FIRST(&constants) != NULL) {
+		symbol_node_t *curnode;
+
+		curnode = SLIST_FIRST(&constants);
+		SLIST_REMOVE_HEAD(&constants, links);
+		fprintf(ofile, "#define\t%-8s\t0x%02x\n",
+			curnode->symbol->name,
+			curnode->symbol->info.cinfo->value);
+		free(curnode);
+	}
 
-		for (i = 0; SLIST_FIRST(&download_constants) != NULL; i++) {
-			symbol_node_t *curnode;
+	
+	fprintf(ofile, "\n\n/* Downloaded Constant Definitions */\n");
 
-			curnode = SLIST_FIRST(&download_constants);
-			SLIST_REMOVE_HEAD(&download_constants, links);
-			fprintf(ofile, "#define\t%-8s\t0x%02x\n",
-				curnode->symbol->name,
-				curnode->symbol->info.cinfo->value);
-			free(curnode);
-		}
-		fprintf(ofile, "#define\tDOWNLOAD_CONST_COUNT\t0x%02x\n", i);
-
-		fprintf(ofile, "\n\n/* Exported Labels */\n");
-
-		while (SLIST_FIRST(&exported_labels) != NULL) {
-			symbol_node_t *curnode;
-
-			curnode = SLIST_FIRST(&exported_labels);
-			SLIST_REMOVE_HEAD(&exported_labels, links);
-			fprintf(ofile, "#define\tLABEL_%-8s\t0x%02x\n",
-				curnode->symbol->name,
-				curnode->symbol->info.linfo->address);
-			free(curnode);
-		}
+	for (i = 0; SLIST_FIRST(&download_constants) != NULL; i++) {
+		symbol_node_t *curnode;
+
+		curnode = SLIST_FIRST(&download_constants);
+		SLIST_REMOVE_HEAD(&download_constants, links);
+		fprintf(ofile, "#define\t%-8s\t0x%02x\n",
+			curnode->symbol->name,
+			curnode->symbol->info.cinfo->value);
+		free(curnode);
+	}
+	fprintf(ofile, "#define\tDOWNLOAD_CONST_COUNT\t0x%02x\n", i);
+
+	fprintf(ofile, "\n\n/* Exported Labels */\n");
+
+	while (SLIST_FIRST(&exported_labels) != NULL) {
+		symbol_node_t *curnode;
+
+		curnode = SLIST_FIRST(&exported_labels);
+		SLIST_REMOVE_HEAD(&exported_labels, links);
+		fprintf(ofile, "#define\tLABEL_%-8s\t0x%02x\n",
+			curnode->symbol->name,
+			curnode->symbol->info.linfo->address);
+		free(curnode);
 	}
 }
 

FUNET's LINUX-ADM group, linux-adm@nic.funet.fi
TCL-scripts by Sam Shen (who was at: slshen@lbl.gov)