Skip to content

Commit 970b84b

Browse files
author
Stefan Reinauer
committed
detok 1.0.2 merge part 3
git-svn-id: svn://coreboot.org/openbios/fcode-utils@105 f158a5a8-5612-0410-a976-696ce0be7e32
1 parent bf55ca7 commit 970b84b

2 files changed

Lines changed: 110 additions & 21 deletions

File tree

detok/addfcodes.c

Lines changed: 78 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,10 @@
4646
* Identified this need when working with in-house code,
4747
* which uses some custom functions. This solution
4848
* is (hoped to be) general enough to cover all cases.
49+
* Mon, 16 Oct 2006 by David L. Paktor
50+
* Add "special function" words. So far, only one added:
51+
* double-literal Infrastructure will support
52+
* adding others as needed.
4953
*
5054
**************************************************************************** */
5155

@@ -58,6 +62,21 @@
5862
*
5963
**************************************************************************** */
6064

65+
66+
/* **************************************************************************
67+
*
68+
* Global Variables Exported :
69+
*
70+
* For "special function" identification, we will need to
71+
* export Global Variables, each of which is a pointer
72+
* to the address of the FCode field of the entry in
73+
* the Special Functions List for that function.
74+
*
75+
* Variable Associated Name
76+
* double_lit_code double-literal
77+
*
78+
**************************************************************************** */
79+
6180
#include <stdio.h>
6281
#include <stdlib.h>
6382
#include <string.h>
@@ -73,6 +92,8 @@
7392
* vfc_remainder Remainder of Vendor-FCodes buffer to be scanned
7493
* vfc_line_no Number of current line in Vendor-FCodes buffer
7594
* vfc_buf_end Pointer to end of Vendor-FCodes buffer
95+
* spcl_func_list List of reserved Special Function names
96+
* spcl_func_count Number of reserved Special Function names
7697
*
7798
**************************************************************************** */
7899

@@ -81,6 +102,22 @@ static char *vfc_remainder;
81102
static int vfc_line_no = 0;
82103
static char *vfc_buf_end;
83104

105+
/* Special Functions List */
106+
/* Initial fcode-field value of -1 guarantees they won't be used */
107+
token_t spcl_func_list[] = {
108+
TOKEN_ENTRY( -1, "double(lit)" ), /* Entry [0] */
109+
};
110+
111+
static const int spcl_func_count = (sizeof(spcl_func_list)/sizeof(token_t)) ;
112+
113+
/* Global Variables for "special function" identification */
114+
/* Each is a pointer to the FCode field of the entry in
115+
* the Special Functions List for that function.
116+
*/
117+
118+
u16 *double_lit_code = &spcl_func_list[0].fcode;
119+
120+
84121
/* **************************************************************************
85122
*
86123
* Function name: skip_whitespace
@@ -231,11 +268,19 @@ static void vfc_splash(char *vf_file_name)
231268
* after the name will be ignored, so an extra "comment"
232269
* is permitted. The FCode number must be in hex, with
233270
* an optional leading 0x or 0X For example: 0X407
234-
* The valid range is 0x010 to 0x7ff. Numbers above 0x800
235-
* infringe upon the are reserved for FCodes generated
236-
* by the tokenization process.
271+
* The valid range for the FCode numbers is 0x010 to 0x7ff.
272+
* Numbers above 0x800 infringe upon the area reserved
273+
* for FCodes generated by the tokenization process.
237274
* Numbers already in use will be ignored. A Message will be
238275
* printed even if the name matches the one on the line.
276+
* Names may not be longer than 31 characters.
277+
* Certain names will be reserved for special functions.
278+
* Those names will be entered in the detok_table
279+
* with a value of -1 and again in the static
280+
* table associated with this function, below, to
281+
* supply the variable that will be used to match
282+
* the name with the special function.
283+
*
239284
*
240285
**************************************************************************** */
241286

@@ -267,6 +312,13 @@ bool add_fcodes_from_list(char *vf_file_name)
267312
char *lookup_result;
268313
char *fc_name_cpy;
269314

315+
/* For each line of input, we need to check that we have
316+
* two strings, one of which is the number and the
317+
* second of which is the name. We will check for
318+
* the various formats allowed for the number
319+
*/
320+
321+
/* Start with a lower-case 0x */
270322
scan_result = sscanf(current_vfc_line, "0x%x %32s",
271323
&vs_fc_number, vs_fc_name);
272324

@@ -315,6 +367,28 @@ bool add_fcodes_from_list(char *vf_file_name)
315367
continue;
316368
}
317369

370+
/* Check if the name is on the "Special Functions List" */
371+
{
372+
bool found_spf = FALSE;
373+
int indx;
374+
for (indx = 0; indx < spcl_func_count; indx++) {
375+
if ( strcmp( vs_fc_name, spcl_func_list[indx].name) == 0 ) {
376+
char strbuf[64];
377+
found_spf = TRUE;
378+
spcl_func_list[indx].fcode = vs_fc_number;
379+
link_token( &spcl_func_list[indx]);
380+
added_fc_count++;
381+
sprintf( strbuf, "Added Special Function FCode "
382+
"number 0x%03x, name %s\n", vs_fc_number, vs_fc_name);
383+
printremark( strbuf);
384+
break;
385+
}
386+
}
387+
388+
if (found_spf)
389+
continue;
390+
}
391+
318392
/* We've passed all the tests! */
319393
fc_name_cpy = strdup(vs_fc_name);
320394
add_token((u16) vs_fc_number, fc_name_cpy);
@@ -323,11 +397,10 @@ bool add_fcodes_from_list(char *vf_file_name)
323397
}
324398

325399
if (verbose) {
326-
char *strbfr = malloc(85);
400+
char strbfr[32];
327401
sprintf(strbfr,
328402
"Added %d FCode numbers\n", added_fc_count);
329403
printremark(strbfr);
330-
free(strbfr);
331404
}
332405

333406
close_stream();

detok/dictionary.c

Lines changed: 32 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -37,13 +37,6 @@
3737
#include "detok.h"
3838

3939
bool check_tok_seq = TRUE;
40-
41-
typedef struct token {
42-
char *name;
43-
u16 fcode;
44-
struct token *next;
45-
} token_t;
46-
#define TOKEN_ENTRY(num, name) { name, (u16)num, (token_t *)NULL }
4740
static token_t *dictionary; /* Initialize dynamically to accommodate AIX */
4841

4942
static char *fcerror = "ferror";
@@ -52,7 +45,7 @@ char *lookup_token(u16 number)
5245
{
5346
token_t *curr;
5447

55-
for (curr = dictionary; curr != NULL; curr = curr->next)
48+
for (curr = dictionary; curr != NULL; curr = curr->prev)
5649
if (curr->fcode == number)
5750
break;
5851

@@ -62,6 +55,33 @@ char *lookup_token(u16 number)
6255
return fcerror;
6356
}
6457

58+
/* **************************************************************************
59+
*
60+
* Function name: link_token
61+
* Synopsis: Simply link a ready-made token-table entry to
62+
* the dictionary, without side-effects.
63+
*
64+
* Inputs:
65+
* Parameters:
66+
* curr_token The token-table entry to link
67+
* Local Static Variables:
68+
* dictionary Pointer to the "tail" of the
69+
* FCode-Tokens vocabulary.
70+
*
71+
* Outputs:
72+
* Returned Value: NONE
73+
* Local Static Variables:
74+
* dictionary Updated to point to the new entry.
75+
*
76+
**************************************************************************** */
77+
78+
void link_token( token_t *curr_token)
79+
{
80+
curr_token->prev = dictionary;
81+
82+
dictionary = curr_token;
83+
}
84+
6585
/* **************************************************************************
6686
*
6787
* Function name: add_token
@@ -72,16 +92,13 @@ char *lookup_token(u16 number)
7292
* number Numeric value of the FCode token
7393
* name Name of the function to display
7494
* Global/Static Variables:
75-
* dictionary Pointer to the "tail" of the
76-
* FCode-Tokens vocabulary.
7795
* check_tok_seq TRUE = "Check Token Sequence"
7896
* A retro-fit to accommodate
7997
* adding Vendor FCodes
8098
*
8199
* Outputs:
82100
* Returned Value: NONE
83101
* Global/Static Variables:
84-
* dictionary Updated to point to the new entry.
85102
* last_defined_token Updated to the given FCode token
86103
* Memory Allocated
87104
* For the new entry.
@@ -116,11 +133,10 @@ void add_token(u16 number, char *name)
116133
exit(-ENOMEM);
117134
}
118135

119-
curr->next = dictionary;
120-
curr->fcode = number;
121136
curr->name = name;
137+
curr->fcode=number;
122138

123-
dictionary = curr;
139+
link_token( curr);
124140

125141
if (check_tok_seq) {
126142
/* Error-check, but not for first time. */
@@ -543,7 +559,7 @@ void init_dictionary(void)
543559
dictionary_reset_position = dictionary;
544560

545561
for (indx = 1; indx < dictionary_indx_max; indx++) {
546-
detok_table[indx].next = &detok_table[indx - 1];
562+
detok_table[indx].prev = &detok_table[indx - 1];
547563
}
548564
}
549565

@@ -553,7 +569,7 @@ void reset_dictionary(void)
553569

554570
next_t = dictionary;
555571
while (next_t != dictionary_reset_position) {
556-
next_t = dictionary->next;
572+
next_t = dictionary->prev;
557573
free(dictionary->name);
558574
free(dictionary);
559575
dictionary = next_t;

0 commit comments

Comments
 (0)