1 #ifndef _TOKE_TICVOCAB_H 2 #define _TOKE_TICVOCAB_H 3 4 /* 5 * OpenBIOS - free your system! 6 * ( FCode tokenizer ) 7 * 8 * This program is part of a free implementation of the IEEE 1275-1994 9 * Standard for Boot (Initialization Configuration) Firmware. 10 * 11 * Copyright (C) 2001-2005 Stefan Reinauer, <stepan@openbios.org> 12 * 13 * This program is free software; you can redistribute it and/or modify 14 * it under the terms of the GNU General Public License as published by 15 * the Free Software Foundation; version 2 of the License. 16 * 17 * This program is distributed in the hope that it will be useful, 18 * but WITHOUT ANY WARRANTY; without even the implied warranty of 19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 20 * GNU General Public License for more details. 21 * 22 * You should have received a copy of the GNU General Public License 23 * along with this program; if not, write to the Free Software 24 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA, 02110-1301 USA 25 * 26 */ 27 28 /* ************************************************************************** 29 * 30 * General-purpose support structures and function prototypes for 31 * Threaded Interpretive Code (T. I. C.)-type vocabularies. 32 * See ticvocab.c 33 * 34 * (C) Copyright 2005 IBM Corporation. All Rights Reserved. 35 * Module Author: David L. Paktor dlpaktor@us.ibm.com 36 * 37 **************************************************************************** */ 38 39 /* ************************************************************************** 40 * 41 * Structures: 42 * 43 * The Threaded Interpretive Code Header data structure consists of: 44 * (1) A pointer to the function name as seen in the source 45 * (2) A link to the next (well, preceding) element 46 * (3) A Pointer to the routine to run as the function's behavior 47 * during active processing. It takes the "parameter field" 48 * item as its argument and has no return-value. 49 * (4) The "parameter field" item, which will be passed as an 50 * argument to the function. It may be an FCode- or FWord- 51 * -token, or an item of another type, or a pointer to data. 52 * The function may re-cast it as needed. 53 * (5) The "Definer" of the entry; a member of the subset of FWord- 54 * -tokens that may be Definers. 55 * (6) A flag indicating whether the item is one for which a 56 * single-token FCode number is assigned. 57 * (7) A Pointer to a routine to be run when the word is encountered 58 * in a Conditional Compilation section that is being ignored. 59 * Certain functions still need to be recognized in that state, 60 * and will require special behaviors; those that can be simply 61 * ignored will have a NULL pointer in this field. The function 62 * in this field, also, takes the "parameter field" item as its 63 * argument and has no return-value. 64 * (8) The size of the data pointed to by the "parameter field" item, 65 * if it is a pointer to allocated data; used to allocate space 66 * for a copy of the p.f. when making an alias, and to indicate 67 * whether the space needs to be freed. Automatic procedures 68 * are too often fooled, so we don't leave things to chance... 69 * (9) A flag, set TRUE if the word is on the Trace List, to indicate 70 * that an Invocation Message should be displayed when the word 71 * is invoked. 72 * 73 * To accommodate C's insistence on strong-typing, we might need 74 * to define different "parameter field" structure-types; see 75 * description of "Parameter Field as a union", below. 76 * 77 * It's not an exact name, but we'll still call it a T. I. C. Header 78 * 79 * We will use this structure for most of our vocabularies... 80 * 81 **************************************************************************** 82 * 83 * The "Parameter Field" is a union of several alternative types, 84 * for convenience, to avert excessive type-casting. It may 85 * either be the Parameter Data itself (if it is small enough) 86 * or a pointer to Parameter Data. 87 * In the case where the Parameter Field is the data itself, or is a 88 * pointer to hard-coded (non-allocated) data, the "size" field 89 * will be zero, to indicate that no space allocation is required. 90 * The types are (starting with the default for initialization) 91 * A long integer (including an FCode Token) 92 * An FWord Token 93 * A pointer to a boolean variable 94 * A pointer to a character or a character string 95 * If the parameter field value is intended to be a single character, 96 * it must be recast as a long integer, in order to preserve 97 * portability across big- and little- -endian platforms. 98 * 99 **************************************************************************** */ 100 101 /* ************************************************************************** * 102 * 103 * Macros: 104 * NO_PARAM_TIC Create an entry in the initial "Built-In" 105 * portion of a TIC-type vocabulary with 106 * an empty "param field". 107 * NO_PARAM_IGN Create an entry with an empty "param field" 108 * whose action- and "Ignore"- -functions 109 * are the same. 110 * VALPARAM_TIC " ... with a literal value for the "param field" 111 * DUALFUNC_TIC " ... with a literal "param" and both an action- 112 * and an "Ignore"- -function. 113 * DUFNC_FWT_PARM A tic_fwt_hdr_t -type entry with a literal 114 * "param" and both an action-function and an 115 * "Ignore"-function. 116 * FWORD_TKN_TIC " ... with an FWord Token for the "param field" 117 * DUALFUNC_FWT_TIC " " ... and both action- and "Ignore"- -function 118 * BUILTIN_MAC_TIC A tic_mac_hdr_t -type entry with a Macro- 119 * -Substitution-String "param" 120 * BUILTIN_BOOL_TIC A tic_bool_hdr_t -type entry with a boolean- 121 * -variable-pointer "param" 122 * 123 **************************************************************************** */ 124 125 #include "types.h" 126 #include "dictionary.h" 127 128 /* ************************************************************************** 129 * 130 * In order to work around C's limitations regarding data-typing 131 * during initialization, we need to create some alternative 132 * data-structures that exactly match the layout of tic_hdr_t 133 * as defined above, but have a different default-type for 134 * the parameter field. 135 * I apologize in advance for any maintenance awkwardnesses this 136 * might engender; I would have come up with a more convenient 137 * way to do this if I could. At least, the pieces that need 138 * to be co-ordinated are in close proximity to each other... 139 * 140 **************************************************************************** */ 141 142 /* ************************************************************************** 143 * 144 * The differences are all centered in the "parameter field" of 145 * the TIC header structure. In order to make sure all the 146 * alternative types map smoothly into each other, we will 147 * create a series of "union" types, differing only in what 148 * their default type is. We will keep the "parameter field" 149 * item the size of a Long Integer. 150 * 151 **************************************************************************** */ 152 153 /* ************************************************************************** 154 * 155 * This form is the default type. 156 * 157 **************************************************************************** */ 158 159 #define TIC_P_DEFLT_TYPE long 160 typedef union tic_param 161 { 162 TIC_P_DEFLT_TYPE deflt_elem ; /* The "default element" aspect. */ 163 long long_val ; /* Explicitly specifying "long" */ 164 fwtoken fw_token ; /* FWord Token */ 165 bool *bool_ptr ; /* Pointer to a boolean variable */ 166 char *chr_ptr ; /* Pointer to a character string */ 167 168 /* The "character value" aspect behaves differently on big- 169 * versus little- -endian platforms (for initialization, 170 * anyway), so we cannot actually use it. 171 * Keep this commented-out, as a reminder. 172 */ 173 /* char char_val ; */ 174 /* We will recast "character value" as an integer. */ 175 176 } tic_param_t ; 177 178 typedef struct tic_hdr 179 { 180 char *name; 181 struct tic_hdr *next; 182 void (*funct)(); /* Function for active processing */ 183 tic_param_t pfield; 184 fwtoken fword_defr; /* FWord Token of entry's Definer */ 185 bool is_token; /* Is entry a single-token FCode? */ 186 void (*ign_func)(); /* Function in "Ignored" segment */ 187 int pfld_size; 188 bool tracing; /* TRUE if Invoc'n Msg required */ 189 } tic_hdr_t ; 190 191 /* ************************************************************************** 192 * 193 * This form is for initialization of an FWord Token list. 194 * 195 **************************************************************************** */ 196 197 #define TIC_FWT_P_DEFLT_TYPE fwtoken 198 typedef union tic_fwt_param 199 { 200 TIC_FWT_P_DEFLT_TYPE deflt_elem ; /* "Default element" aspect. */ 201 long long_val ; /* Long integer */ 202 fwtoken fw_token ; /* Explicit FWord Token */ 203 bool *bool_ptr ; /* Pointer to a boolean variable */ 204 char *chr_ptr ; /* Pointer to a character string */ 205 } tic_fwt_param_t ; 206 207 typedef struct tic_fwt_hdr 208 { 209 char *name; 210 struct tic_fwt_hdr *next; 211 void (*funct)(); /* Function for active processing */ 212 tic_fwt_param_t pfield; 213 fwtoken fword_defr; /* FWord Token of entry's Definer */ 214 bool is_token; /* Is entry a single-token FCode? */ 215 void (*ign_func)(); /* Function in "Ignored" segment */ 216 int pfld_size; 217 bool tracing; /* TRUE if Invoc'n Msg required */ 218 } tic_fwt_hdr_t ; 219 220 221 /* ************************************************************************** 222 * 223 * The third form is for initialization of Built-in Macros. Its 224 * default parameter field type is a pointer to a compiled-in 225 * (i.e., constant) character string. Its pfld_size can be 226 * left as zero, because no allocated-memory copies of the 227 * string will be needed, even for aliases. (User-created 228 * macros, however, will need to allocate strings; we will 229 * deal with that elsewhere...) 230 * 231 **************************************************************************** */ 232 233 #define TIC_MAC_P_DEFLT_TYPE char * 234 typedef union tic_mac_param 235 { 236 TIC_MAC_P_DEFLT_TYPE deflt_elem ; /* "Default element" aspect. */ 237 long long_val ; /* Long integer */ 238 fwtoken fw_token ; /* FWord Token */ 239 bool *bool_ptr ; /* Pointer to a boolean variable */ 240 char *chr_ptr ; /* Explicit Pointer to char str. */ 241 } tic_mac_param_t ; 242 243 typedef struct tic_mac_hdr 244 { 245 char *name; 246 struct tic_mac_hdr *next; 247 void (*funct)(); 248 tic_mac_param_t pfield; 249 fwtoken fword_defr; 250 bool is_token; /* Is entry a single-token FCode? */ 251 void (*ign_func)(); 252 int pfld_size; 253 bool tracing; /* TRUE if Invoc'n Msg required */ 254 } tic_mac_hdr_t ; 255 256 /* ************************************************************************** 257 * 258 * The next form is for initialization of Condtionals. Its default 259 * parameter field type is a pointer to a boolean variable. 260 * 261 **************************************************************************** */ 262 263 #define TIC_BOOL_P_DEFLT_TYPE bool * 264 typedef union tic_bool_param 265 { 266 TIC_BOOL_P_DEFLT_TYPE deflt_elem ; /* "Default element" aspect. */ 267 long long_val ; /* Long integer */ 268 fwtoken fw_token ; /* FWord Token */ 269 bool *bool_ptr ; /* Explicit Ptr to boolean v'ble */ 270 char *chr_ptr ; /* Pointer to a character string */ 271 } tic_bool_param_t ; 272 273 typedef struct tic_bool_hdr 274 { 275 char *name; 276 struct tic_bool_hdr *next; 277 void (*funct)(); 278 tic_bool_param_t pfield; 279 fwtoken fword_defr; 280 bool is_token; /* Is entry a single-token FCode? */ 281 void (*ign_func)(); 282 int pfld_size; 283 bool tracing; /* TRUE if Invoc'n Msg required */ 284 } tic_bool_hdr_t ; 285 286 287 288 /* ************************************************************************** 289 * 290 * Various macros to create an entry in the initial "Built-In" portion 291 * of a vocabulary-list, specified as an array of one of the 292 * matching forms of a T. I. C. Header; each macro adjusts type 293 * casting as needed. 294 * In all cases, the "size" field will be set to zero, indicating that 295 * the "param field" item is either the complete data or a pointer 296 * to a hard-coded (non-allocated) data item. 297 * 298 **************************************************************************** */ 299 300 /* ************************************************************************** 301 * Macro Name: NO_PARAM_TIC 302 * Create an entry in the initial "Built-In" portion 303 * of a TIC_HDR -type vocabulary with an empty 304 * "param field" 305 * 306 * Arguments: 307 * nam (string) Name of the entry as seen in the source 308 * func (routine-name) Name of internal function to call 309 * The item is not one for which single-token FCode number is assigned. 310 * 311 **************************************************************************** */ 312 #define NO_PARAM_TIC(nam, func ) \ 313 { nam , (tic_hdr_t *)NULL , func , \ 314 { 0 }, UNSPECIFIED , FALSE , NULL , 0 , FALSE } 315 316 317 /* ************************************************************************** 318 * Macro Name: NO_PARAM_IGN 319 * Create an entry with an empty "param field" 320 * whose action-function and "Ignore"-function 321 * are the same. 322 * 323 * Arguments: 324 * nam (string) Name of the entry as seen in the source 325 * func (routine-name) Name of internal function to call for both 326 * The item is not one for which single-token FCode number is assigned. 327 * 328 **************************************************************************** */ 329 #define NO_PARAM_IGN(nam, func ) \ 330 { nam , (tic_hdr_t *)NULL , func , \ 331 { 0 }, UNSPECIFIED , FALSE , func , 0 , FALSE } 332 333 334 /* ************************************************************************** 335 * 336 * Variations on the above, to compensate for Type-Casting complications 337 * 338 **************************************************************************** */ 339 340 /* ************************************************************************** 341 * Macro Name: VALPARAM_TIC 342 * Create an entry in the initial "Built-In" portion 343 * of a TIC_HDR -type vocabulary with a literal 344 * value for the "param field" and a specifiable 345 * "definer". 346 * Arguments: 347 * nam (string) Name of the entry as seen in the source 348 * func (routine-name) Name of internal function to call 349 * pval (integer) The "param field" item 350 * definr (fword_token) "Definer" of the entry 351 * is_tok (bool) Is the "param" item a single-token FCode? 352 * 353 * The "param field" item will be recast to the required default type. 354 * 355 **************************************************************************** */ 356 357 #define VALPARAM_TIC(nam, func, pval, definr, is_tok ) \ 358 { nam , (tic_hdr_t *)NULL , func , \ 359 { (TIC_P_DEFLT_TYPE)(pval) }, definr , is_tok , NULL , 0 , FALSE } 360 361 362 /* ************************************************************************** 363 * Macro Name: DUALFUNC_TIC 364 * Create an entry in the initial "Built-In" portion 365 * of a TIC_HDR -type vocabulary with both an 366 * "active" and an "ignoring" function, a literal 367 * value for the "param field" and a specifiable 368 * "definer". 369 * 370 * Arguments: 371 * nam (string) Name of the entry as seen in the source 372 * afunc (routine-name) Name of internal "active" function 373 * pval (integer) The "param field" item 374 * ifunc (routine-name) Name of "ignoring" function 375 * definr (fword_token) "Definer" of the entry 376 * 377 * The "param field" item will be recast to the required default type. 378 * The item is not one for which single-token FCode number is assigned. 379 * 380 **************************************************************************** */ 381 #define DUALFUNC_TIC(nam, afunc, pval, ifunc, definr ) \ 382 { nam , (tic_hdr_t *)NULL , afunc , \ 383 { (TIC_P_DEFLT_TYPE)(pval) }, definr , FALSE , ifunc , 0 , FALSE } 384 385 /* Similar but a tic_fwt_hdr_t type structure */ 386 #define DUFNC_FWT_PARM(nam, afunc, pval, ifunc, definr ) \ 387 { nam , (tic_fwt_hdr_t *)NULL , afunc , \ 388 { (TIC_FWT_P_DEFLT_TYPE)(pval) }, definr , FALSE , ifunc , 0 , FALSE } 389 390 391 /* ************************************************************************** 392 * Macro Name: FWORD_TKN_TIC 393 * Create an entry in the initial "Built-In" portion 394 * of an FWord Token list of tic_fwt_hdr_t type. 395 * 396 * Arguments: 397 * nam (string) Name of the entry as seen in the source 398 * func (routine-name) Name of internal function to call 399 * fw_tokval (fword_token) Value of the FWord Token 400 * definr (fword_token) "Definer" of the entry 401 * 402 * The "param field" item should not need be recast. 403 * The item is not one for which single-token FCode number is assigned. 404 * 405 **************************************************************************** */ 406 407 #define FWORD_TKN_TIC(nam, func, fw_tokval, definr ) \ 408 { nam , (tic_fwt_hdr_t *)NULL , func , { fw_tokval }, \ 409 definr , FALSE , NULL , 0 , FALSE } 410 411 /* ************************************************************************** 412 * Macro Name: DUALFUNC_FWT_TIC 413 * Create an entry in the initial "Built-In" portion 414 * of an FWord Token list of tic_fwt_hdr_t type 415 * with both an action- and an "Ignore"- -function. 416 * 417 * Arguments: 418 * nam (string) Name of the entry as seen in the source 419 * afunc (routine-name) Name of internal "Action" function 420 * fw_tokval (fword_token) Value of the FWord Token 421 * ifunc (routine-name) Name of "ignoring" function 422 * definr (fword_token) "Definer" of the entry 423 * 424 * The "param field" item should not need be recast. 425 * The item is not one for which single-token FCode number is assigned. 426 * 427 **************************************************************************** */ 428 #define DUALFUNC_FWT_TIC(nam, afunc, fw_tokval, ifunc, definr ) \ 429 { nam , (tic_fwt_hdr_t *)NULL , afunc , { fw_tokval }, \ 430 definr , FALSE , ifunc , 0 , FALSE } 431 432 /* ************************************************************************** 433 * Macro Name: BUILTIN_MAC_TIC 434 * Create an entry in the initial "Built-In" portion 435 * of a Macros vocabulary of tic_mac_hdr_t type. 436 * 437 * Arguments: 438 * nam (string) Name of the entry as seen in the source 439 * func (routine-name) Name of internal function to call 440 * alias (string) Macro-Substitution string 441 * 442 * The "param field" item should not need be recast. 443 * The "definer" will be MACRO_DEF 444 * Builtin Macros do not need to be expanded while Ignoring, so 445 * the ign_func will be NULL 446 * The item is not one for which single-token FCode number is assigned. 447 * 448 **************************************************************************** */ 449 450 #define BUILTIN_MAC_TIC(nam, func, alias ) \ 451 { nam , (tic_mac_hdr_t *)NULL , func , { alias }, \ 452 MACRO_DEF , FALSE , NULL , 0 , FALSE } 453 454 455 /* ************************************************************************** 456 * Macro Name: BUILTIN_BOOL_TIC 457 * Create an entry in the initial "Built-In" portion 458 * of a Condtionals list of tic_bool_hdr_t type. 459 * 460 * Arguments: 461 * nam (string) Name of the entry as seen in the source 462 * func (routine-name) Name of internal function to call 463 * bool_vbl (boolean v'ble) Name of the boolean variable. 464 * 465 * The "param field" item should not need be recast. 466 * For all of the Condtionals, the "Ignoring" function is the same 467 * as the "Active" function. 468 * The "definer" will be COMMON_FWORD 469 * The item is not one for which single-token FCode number is assigned. 470 * 471 **************************************************************************** */ 472 473 #define BUILTIN_BOOL_TIC(nam, func, bool_vbl ) \ 474 { nam , (tic_bool_hdr_t *)NULL , func , { &bool_vbl }, \ 475 COMMON_FWORD , FALSE , func , 0 , FALSE } 476 477 478 /* ************************************************************************** 479 * 480 * Exported Variables and Function Prototypes the rest of the way... 481 * 482 **************************************************************************** */ 483 484 extern tic_hdr_t *tic_found; 485 486 void init_tic_vocab( tic_hdr_t *tic_vocab_tbl, 487 int max_indx, 488 tic_hdr_t **tic_vocab_ptr); 489 void add_tic_entry( char *tname, 490 void (*tfunct)(), 491 TIC_P_DEFLT_TYPE tparam, 492 fwtoken fw_defr, 493 int pfldsiz, 494 bool is_single, 495 void (*ign_fnc)(), 496 tic_hdr_t **tic_vocab ); 497 tic_hdr_t *lookup_tic_entry( char *tname, tic_hdr_t *tic_vocab ); 498 bool exists_in_tic_vocab( char *tname, tic_hdr_t *tic_vocab ); 499 bool handle_tic_vocab( char *tname, tic_hdr_t *tic_vocab ); 500 bool create_split_alias( char *new_name, char *old_name, 501 tic_hdr_t **src_vocab, tic_hdr_t **dest_vocab ); 502 bool create_tic_alias( char *new_name, char *old_name, tic_hdr_t **tic_vocab ); 503 void reset_tic_vocab( tic_hdr_t **tic_vocab, tic_hdr_t *reset_position ); 504 505 #endif /* _TOKE_TICVOCAB_H */ 506