Commit 970b84b895af956b20d2938c4945b02607cd3b03

Stefan Reinauer 2006-10-30T11:59:18

detok 1.0.2 merge part 3 git-svn-id: svn://coreboot.org/openbios/fcode-utils@105 f158a5a8-5612-0410-a976-696ce0be7e32

diff --git a/detok/addfcodes.c b/detok/addfcodes.c
index bf42447..b820ffb 100644
--- a/detok/addfcodes.c
+++ b/detok/addfcodes.c
@@ -46,6 +46,10 @@
  *              Identified this need when working with in-house code,
  *                  which uses some custom functions.  This solution
  *                  is (hoped to be) general enough to cover all cases.
+ *          Mon, 16 Oct 2006 by David L. Paktor
+ *              Add "special function" words.  So far, only one added:
+ *                   double-literal   Infrastructure will support
+ *                  adding others as needed.
  *
  **************************************************************************** */
 
@@ -58,6 +62,21 @@
  *
  **************************************************************************** */
 
+
+/* **************************************************************************
+ *
+ *          Global Variables Exported :
+ *
+ *          For "special function" identification, we will need to
+ *              export Global Variables, each of which is a pointer
+ *              to the address of the FCode field of the entry in
+ *              the Special Functions List for that function.
+ *              
+ *                Variable                 Associated Name
+ *              double_lit_code          double-literal
+ *
+ **************************************************************************** */
+
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
@@ -73,6 +92,8 @@
  *     vfc_remainder          Remainder of Vendor-FCodes buffer to be scanned
  *     vfc_line_no            Number of current line in Vendor-FCodes buffer
  *     vfc_buf_end            Pointer to end of Vendor-FCodes buffer
+ *     spcl_func_list         List of reserved Special Function names
+ *     spcl_func_count        Number of reserved Special Function names
  *
  **************************************************************************** */
 
@@ -81,6 +102,22 @@ static char *vfc_remainder;
 static int vfc_line_no = 0;
 static char *vfc_buf_end;
 
+/*  Special Functions List  */
+/*  Initial fcode-field value of  -1  guarantees they won't be used  */
+token_t spcl_func_list[]  =  {
+	TOKEN_ENTRY( -1, "double(lit)" ),  /*  Entry  [0]  */
+};
+
+static const int spcl_func_count = (sizeof(spcl_func_list)/sizeof(token_t)) ;
+
+/*  Global Variables for "special function" identification  */
+/*  Each is a pointer to the FCode field of the entry in
+ *              the Special Functions List for that function.
+ */
+
+u16 *double_lit_code = &spcl_func_list[0].fcode;
+
+
 /* **************************************************************************
  *
  *      Function name:  skip_whitespace
@@ -231,11 +268,19 @@ static void vfc_splash(char *vf_file_name)
  *              after the name will be ignored, so an extra "comment"
  *              is permitted.  The FCode number must be in hex, with
  *              an optional leading  0x  or  0X   For example:  0X407
- *          The valid range is 0x010 to 0x7ff.  Numbers above 0x800
- *              infringe upon the are reserved for FCodes generated
- *              by the tokenization process.
+ *          The valid range for the FCode numbers is 0x010 to 0x7ff.
+ *              Numbers above 0x800 infringe upon the area reserved
+ *              for FCodes generated by the tokenization process.
  *          Numbers already in use will be ignored.  A Message will be
  *              printed even if the name matches the one on the line.
+ *          Names may not be longer than 31 characters.
+ *          Certain names will be reserved for special functions.
+ *              Those names will be entered in the  detok_table 
+ *              with a value of  -1  and again in the static 
+ *              table associated with this function, below, to
+ *              supply the variable that will be used to match
+ *              the name with the special function.
+ *             
  *
  **************************************************************************** */
 
@@ -267,6 +312,13 @@ bool add_fcodes_from_list(char *vf_file_name)
 		char *lookup_result;
 		char *fc_name_cpy;
 
+		/*  For each line of input, we need to check that we have
+		 *      two strings, one of which is the number and the
+		 *      second of which is the name.  We will check for
+		 *      the various formats allowed for the number
+		 */
+
+		/*    Start with a lower-case  0x    */
 		scan_result = sscanf(current_vfc_line, "0x%x %32s",
 				     &vs_fc_number, vs_fc_name);
 
@@ -315,6 +367,28 @@ bool add_fcodes_from_list(char *vf_file_name)
 			continue;
 		}
 
+		/*    Check if the name is on the "Special Functions List"  */
+		{
+			bool found_spf = FALSE;
+			int indx;
+			for (indx = 0; indx < spcl_func_count; indx++) {
+				if ( strcmp( vs_fc_name, spcl_func_list[indx].name) == 0 ) {
+					char strbuf[64];
+					found_spf = TRUE;
+					spcl_func_list[indx].fcode = vs_fc_number;
+					link_token( &spcl_func_list[indx]);
+					added_fc_count++;
+					sprintf( strbuf,  "Added Special Function FCode "
+						 "number 0x%03x, name %s\n", vs_fc_number, vs_fc_name);
+					printremark( strbuf);
+					break;
+				}
+			}
+
+			if (found_spf) 
+				continue;
+		}
+
 		/*  We've passed all the tests!  */
 		fc_name_cpy = strdup(vs_fc_name);
 		add_token((u16) vs_fc_number, fc_name_cpy);
@@ -323,11 +397,10 @@ bool add_fcodes_from_list(char *vf_file_name)
 	}
 
 	if (verbose) {
-		char *strbfr = malloc(85);
+		char strbfr[32]; 
 		sprintf(strbfr,
 			"Added %d FCode numbers\n", added_fc_count);
 		printremark(strbfr);
-		free(strbfr);
 	}
 
 	close_stream();
diff --git a/detok/dictionary.c b/detok/dictionary.c
index 41dd873..b3d7abf 100644
--- a/detok/dictionary.c
+++ b/detok/dictionary.c
@@ -37,13 +37,6 @@
 #include "detok.h"
 
 bool check_tok_seq = TRUE;
-
-typedef struct token {
-	char *name;
-	u16 fcode;
-	struct token *next;
-} token_t;
-#define TOKEN_ENTRY(num, name)   { name, (u16)num, (token_t *)NULL }
 static token_t *dictionary;	/*  Initialize dynamically to accommodate AIX  */
 
 static char *fcerror = "ferror";
@@ -52,7 +45,7 @@ char *lookup_token(u16 number)
 {
 	token_t *curr;
 
-	for (curr = dictionary; curr != NULL; curr = curr->next)
+	for (curr = dictionary; curr != NULL; curr = curr->prev)
 		if (curr->fcode == number)
 			break;
 
@@ -64,6 +57,33 @@ char *lookup_token(u16 number)
 
 /* **************************************************************************
  *
+ *      Function name:  link_token
+ *      Synopsis:       Simply link a ready-made token-table entry to
+ *                          the dictionary, without side-effects.
+ *
+ *      Inputs:
+ *         Parameters:
+ *             curr_token                  The token-table entry to link
+ *         Local Static Variables:
+ *             dictionary                  Pointer to the "tail" of the
+ *                                             FCode-Tokens vocabulary.
+ *
+ *      Outputs:
+ *         Returned Value:                 NONE
+ *         Local Static Variables:
+ *             dictionary                  Updated to point to the new entry.
+ *
+ **************************************************************************** */
+
+void link_token( token_t *curr_token)
+{
+	curr_token->prev  = dictionary;
+
+	dictionary = curr_token;
+}
+
+/* **************************************************************************
+ *
  *      Function name:  add_token
  *      Synopsis:       Add an entry to the FCode-Tokens vocabulary.
  *
@@ -72,8 +92,6 @@ char *lookup_token(u16 number)
  *             number                      Numeric value of the FCode token
  *             name                        Name of the function to display
  *         Global/Static Variables:
- *             dictionary                  Pointer to the "tail" of the
- *                                             FCode-Tokens vocabulary.
  *             check_tok_seq               TRUE = "Check Token Sequence"
  *                                             A retro-fit to accommodate
  *                                             adding Vendor FCodes
@@ -81,7 +99,6 @@ char *lookup_token(u16 number)
  *      Outputs:
  *         Returned Value:                 NONE
  *         Global/Static Variables:
- *             dictionary                  Updated to point to the new entry.
  *             last_defined_token          Updated to the given FCode token
  *         Memory Allocated
  *             For the new entry.
@@ -116,11 +133,10 @@ void add_token(u16 number, char *name)
 		exit(-ENOMEM);
 	}
 
-	curr->next = dictionary;
-	curr->fcode = number;
 	curr->name = name;
+	curr->fcode=number;
 
-	dictionary = curr;
+	link_token( curr);
 
 	if (check_tok_seq) {
 		/*  Error-check, but not for first time.  */
@@ -543,7 +559,7 @@ void init_dictionary(void)
 	dictionary_reset_position = dictionary;
 
 	for (indx = 1; indx < dictionary_indx_max; indx++) {
-		detok_table[indx].next = &detok_table[indx - 1];
+		detok_table[indx].prev = &detok_table[indx - 1];
 	}
 }
 
@@ -553,7 +569,7 @@ void reset_dictionary(void)
 
 	next_t = dictionary;
 	while (next_t != dictionary_reset_position) {
-		next_t = dictionary->next;
+		next_t = dictionary->prev;
 		free(dictionary->name);
 		free(dictionary);
 		dictionary = next_t;