]> git.proxmox.com Git - mirror_edk2.git/blob - Tools/Source/TianoTools/VfrCompile/VfrCompile.g
db0ba955820901493afc3e98060901da4482955f
[mirror_edk2.git] / Tools / Source / TianoTools / VfrCompile / VfrCompile.g
1 /*++
2
3 Copyright (c) 2004 - 2005, Intel Corporation
4 All rights reserved. This program and the accompanying materials
5 are licensed and made available under the terms and conditions of the BSD License
6 which accompanies this distribution. The full text of the license may be found at
7 http://opensource.org/licenses/bsd-license.php
8
9 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
10 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
11
12 Module Name:
13
14 VfrCompile.g
15
16 Abstract:
17
18 PCCTS parser and lexer definitions for the EFI VFR forms compiler
19
20 --*/
21
22 #header<<
23
24 #include <Common/UefiBaseTypes.h>
25 #include <Common/MultiPhase.h>
26 #include <Common/InternalFormRepresentation.h>
27 #include <Protocol/UgaDraw.h>
28 #include <Protocol/Hii.h>
29
30 #include "CommonLib.h"
31 #include "EfiUtilityMsgs.h"
32 #include "EfiVfr.h"
33 #include "VfrServices.h"
34
35 #include <ctype.h>
36 #ifndef __GNUC__
37 #include <direct.h>
38 #include <process.h> // for spawn functions
39 #else
40 #include <unistd.h>
41 #endif
42
43 >>
44
45 <<
46
47 //
48 // Base info for DLG-generated scanner
49 //
50 #include "DLexerBase.h"
51
52 //
53 // Include the scanner file generated by DLG
54 //
55 #include "DLGLexer.h"
56
57 class DLGLexerVfr : public DLGLexer
58 {
59 public:
60 DLGLexerVfr (DLGFileInput *F) : DLGLexer (F) {};
61 INT32 errstd (char *Text)
62 {
63 printf ("unrecognized input '%s'\n", Text);
64 }
65 };
66
67 //
68 // Base token definitions for ANTLR
69 //
70 #include "AToken.h"
71
72 //
73 // This is how we invoke the C preprocessor on the VFR source file
74 // to resolve #defines, #includes, etc. To make C source files
75 // shareable between VFR and drivers, define VFRCOMPILE so that
76 // #ifdefs can be used in shared .h files.
77 //
78 #ifdef __GNUC__
79 #define PREPROCESSOR_COMMAND "gcc "
80 #define PREPROCESSOR_OPTIONS "-x c -E -P -DVFRCOMPILE "
81 #define FILE_SEP_CHAR '/'
82 #define FILE_SEP_STRING "/"
83 #else
84 #define PREPROCESSOR_COMMAND "cl.exe "
85 #define PREPROCESSOR_OPTIONS "/nologo /P /TC /DVFRCOMPILE "
86 #define FILE_SEP_CHAR '/'
87 #define FILE_SEP_STRING "/"
88 #endif
89
90 typedef ANTLRCommonToken ANTLRToken;
91
92 //
93 // Specify the filename extensions for the files we generate.
94 //
95 #define VFR_BINARY_FILENAME_EXTENSION ".c"
96 #define VFR_LIST_FILENAME_EXTENSION ".lst"
97
98 static
99 VOID
100 Usage ();
101
102 static
103 STATUS
104 ProcessArgs (
105 int Argc,
106 char *Argv[]
107 );
108
109 static
110 VOID
111 Cleanup ();
112
113 //
114 // Globals
115 //
116 OPTIONS gOptions;
117
118 int
119 main (
120 int argc,
121 char **argv
122 )
123 /*++
124
125 Routine Description:
126 Application entry point function. Parse command-line arguments,
127 invoke the parser, clean up, and return.
128
129 Arguments:
130 argc - standard argc passed to main() per C conventions
131 argv - standard argv passed to main() per C conventions
132
133 Returns:
134 STATUS_SUCCESS - program executed with no errors or warnings
135 STATUS_WARNING - program executed with warnings
136 STATUS_ERROR - non-recoverable errors encountered while processing
137
138 --*/
139 {
140 FILE *VfrFptr;
141 char *Cmd;
142 char *Cptr;
143 int Len;
144 STATUS Status;
145
146 //
147 // Set our program name for the error printing routines.
148 // Then set printing limits.
149 //
150 SetUtilityName (PROGRAM_NAME);
151 SetPrintLimits (20, 20, 30);
152 //
153 // Process the command-line arguments
154 //
155 if (ProcessArgs (argc, argv) != STATUS_SUCCESS) {
156 Usage ();
157 Cleanup();
158 return STATUS_ERROR;
159 }
160 VfrFptr = NULL;
161 //
162 // Verify the VFR script file exists
163 //
164 if ((VfrFptr = fopen (gOptions.VfrFileName, "r")) == NULL) {
165 Error (PROGRAM_NAME, 0, 0, gOptions.VfrFileName, "could not open input VFR file");
166 Cleanup();
167 return STATUS_ERROR;
168 }
169 //
170 // Now close the file and make a system call to run the preprocessor
171 // on it.
172 //
173 fclose (VfrFptr);
174 Len = strlen (PREPROCESSOR_OPTIONS) + strlen (gOptions.VfrFileName) + 10;
175 if (gOptions.CPreprocessorOptions != NULL) {
176 Len += strlen (gOptions.CPreprocessorOptions) + 1;
177 }
178 if (gOptions.IncludePaths != NULL) {
179 Len += strlen (gOptions.IncludePaths) + 1;
180 }
181 Cmd = (char *)malloc (Len);
182 if (Cmd == NULL) {
183 Error (PROGRAM_NAME, 0, 0, NULL, "could not allocate memory");
184 Cleanup();
185 return STATUS_ERROR;
186 }
187 strcpy (Cmd, PREPROCESSOR_OPTIONS);
188 if (gOptions.IncludePaths != NULL) {
189 strcat (Cmd, gOptions.IncludePaths);
190 strcat (Cmd, " ");
191 }
192 if (gOptions.CPreprocessorOptions != NULL) {
193 strcat (Cmd, gOptions.CPreprocessorOptions);
194 strcat (Cmd, " ");
195 }
196 strcat (Cmd, gOptions.VfrFileName);
197 #ifndef __GNUC__
198 Status = _spawnlp (_P_WAIT, PREPROCESSOR_COMMAND, Cmd, NULL);
199 #else
200 {
201 char CommandLine[1000];
202 char *p;
203
204 //
205 // Lean the slashes forward.
206 //
207 for (p = gOptions.PreprocessorOutputFileName; *p; p++) {
208 if (*p=='\\') {
209 *p=FILE_SEP_CHAR;
210 }
211 }
212
213 //
214 // Lean the slashes forward.
215 //
216 for (p = Cmd; *p; p++) {
217 if (*p=='\\') {
218 *p=FILE_SEP_CHAR;
219 }
220 }
221
222 sprintf(CommandLine, "%s %s > %s", PREPROCESSOR_COMMAND, Cmd, gOptions.PreprocessorOutputFileName);
223 Status = system (CommandLine);
224 }
225 #endif
226 if (Status != 0) {
227 Error (PROGRAM_NAME, 0, 0, gOptions.VfrFileName, "failed to spawn C preprocessor on VFR file");
228 printf ("Command: '%s %s'\n", PREPROCESSOR_COMMAND, Cmd);
229 Cleanup();
230 return STATUS_ERROR;
231 }
232 free (Cmd);
233 //
234 // Open the preprocessor output file
235 //
236 if ((VfrFptr = fopen (gOptions.PreprocessorOutputFileName, "r")) == NULL) {
237 Error (PROGRAM_NAME, 0, 0, "failed to open input VFR preprocessor output file",
238 gOptions.PreprocessorOutputFileName);
239 Cleanup();
240 return STATUS_ERROR;
241 }
242 //
243 // Define input VFR file
244 //
245 DLGFileInput InputFile (VfrFptr);
246 //
247 // Define an instance of the scanner
248 //
249 DLGLexerVfr Scanner (&InputFile);
250 //
251 // Define token buffer between scanner and parser
252 //
253 ANTLRTokenBuffer Pipe (&Scanner);
254 //
255 // Create a token to use as a model
256 //
257 ANTLRToken Tok;
258 //
259 // Tell the scanner what type the token is
260 //
261 Scanner.setToken (&Tok);
262 //
263 // Create an instance of our parser
264 //
265 EfiVfrParser Parser (&Pipe);
266 //
267 // Initialize the parser
268 //
269 Parser.init ();
270 Status = GetUtilityStatus ();
271 if (Status != STATUS_SUCCESS) {
272 Cleanup();
273 return Status;
274 }
275 //
276 // Start the first rule
277 //
278 Parser.program ();
279 //
280 // Close the input script file
281 //
282 fclose (VfrFptr);
283 Parser.WriteIfrBytes ();
284 //
285 // Call cleanup, which does some extra checking of the script
286 //
287 Parser.Cleanup ();
288 Cleanup();
289 //
290 // If we had an error somewhere, delete our output files so that
291 // a subsequent build will rebuild them.
292 //
293 Status = GetUtilityStatus ();
294 if (Status == STATUS_ERROR) {
295 remove (gOptions.IfrOutputFileName);
296 }
297 return Status;
298 }
299 static
300 VOID
301 Cleanup ()
302 /*++
303
304 Routine Description:
305 Free up memory allocated during parsing.
306
307 Arguments:
308 None
309
310 Returns:
311 None
312
313 --*/
314 {
315 //
316 // Free up our string we allocated to track the include paths
317 //
318 if (gOptions.IncludePaths != NULL) {
319 free (gOptions.IncludePaths);
320 gOptions.IncludePaths = NULL;
321 }
322 //
323 // Free up our string we allocated to track preprocessor options
324 //
325 if (gOptions.CPreprocessorOptions != NULL) {
326 free (gOptions.CPreprocessorOptions);
327 gOptions.CPreprocessorOptions = NULL;
328 }
329 }
330
331 static
332 STATUS
333 ProcessArgs (
334 int Argc,
335 char *Argv[]
336 )
337 /*++
338
339 Routine Description:
340 Process the command-line arguments.
341
342 Arguments:
343 Argc - standard argc passed to main()
344 Argv - standard argv passed to main()
345
346 Returns:
347 STATUS_SUCCESS - program should continue (all args ok)
348
349 --*/
350 {
351 char *IncludePaths;
352 char *CPreprocessorOptions;
353 int Len;
354 char CopyStr[MAX_PATH];
355 char *Cptr;
356
357 //
358 // Put options in known state.
359 //
360 memset ((char *)&gOptions, 0, sizeof (OPTIONS));
361 //
362 // Go through all the arguments that start with '-'
363 //
364 Argc--;
365 Argv++;
366 while ((Argc > 0) && (Argv[0][0] == '-')) {
367 //
368 // -? or -h help option -- return an error for printing usage
369 //
370 if ((stricmp (Argv[0], "-?") == 0) || (stricmp (Argv[0], "-h") == 0)) {
371 return STATUS_ERROR;
372 break;
373 //
374 // -l to create a listing output file
375 //
376 } else if (stricmp (Argv[0], "-l") == 0) {
377 gOptions.CreateListFile = 1;
378 //
379 // -I include_path option for finding include files. We'll pass this
380 // to the preprocessor. Turn them all into a single include string.
381 //
382 } else if (stricmp (Argv[0], "-i") == 0) {
383 if ((Argc < 2) || (Argv[1][0] == '-')) {
384 Error (PROGRAM_NAME, 0, 0, Argv[0], "missing path argument");
385 return STATUS_ERROR;
386 }
387 Argc--;
388 Argv++;
389 Len = strlen (" -I ");
390 Len += strlen (Argv[0]) + 2;
391 if (gOptions.IncludePaths != NULL) {
392 Len += strlen (gOptions.IncludePaths);
393 }
394 IncludePaths = (CHAR8 *)malloc (Len);
395 if (IncludePaths == NULL) {
396 Error (PROGRAM_NAME, 0, 0, NULL, "memory allocation failure");
397 return STATUS_ERROR;
398 }
399 IncludePaths[0] = 0;
400 if (gOptions.IncludePaths != NULL) {
401 strcpy (IncludePaths, gOptions.IncludePaths);
402 free (gOptions.IncludePaths);
403 }
404 strcat (IncludePaths, " -I ");
405 strcat (IncludePaths, Argv[0]);
406 gOptions.IncludePaths = IncludePaths;
407 //
408 // -od OutputDirectory to define a common directory for output files
409 //
410 } else if (stricmp (Argv[0], "-od") == 0) {
411 if ((Argc < 2) || (Argv[1][0] == '-')) {
412 Error (PROGRAM_NAME, 0, 0, Argv[0], "missing output directory name");
413 return STATUS_ERROR;
414 }
415 Argc--;
416 Argv++;
417 strcpy (gOptions.OutputDirectory, Argv[0]);
418 } else if (stricmp (Argv[0], "-ibin") == 0) {
419 gOptions.CreateIfrBinFile = 1;
420 } else if (stricmp (Argv[0], "-nostrings") == 0) {
421 // deprecated option
422 //
423 // -ppflag C-preprocessor-flag option for passing options to the C preprocessor.
424 // Turn them all into a single string.
425 //
426 } else if (stricmp (Argv[0], "-ppflag") == 0) {
427 if (Argc < 2) {
428 Error (PROGRAM_NAME, 0, 0, Argv[0], "missing C-preprocessor argument");
429 return STATUS_ERROR;
430 }
431 Argc--;
432 Argv++;
433 Len = strlen (Argv[0]) + 2;
434 if (gOptions.CPreprocessorOptions != NULL) {
435 Len += strlen (gOptions.CPreprocessorOptions);
436 }
437 CPreprocessorOptions = (CHAR8 *)malloc (Len);
438 if (CPreprocessorOptions == NULL) {
439 Error (PROGRAM_NAME, 0, 0, NULL, "memory allocation failure");
440 return STATUS_ERROR;
441 }
442 CPreprocessorOptions[0] = 0;
443 if (gOptions.CPreprocessorOptions != NULL) {
444 strcpy (CPreprocessorOptions, gOptions.CPreprocessorOptions);
445 free (gOptions.CPreprocessorOptions);
446 }
447 strcat (CPreprocessorOptions, " ");
448 strcat (CPreprocessorOptions, Argv[0]);
449 gOptions.CPreprocessorOptions = CPreprocessorOptions;
450 } else {
451 Error (PROGRAM_NAME, 0, 0, Argv[0], "unrecognized option");
452 return STATUS_ERROR;
453 }
454 Argc--;
455 Argv++;
456 }
457 //
458 // Must specify at least the vfr file name
459 //
460 if (Argc > 1) {
461 Error (PROGRAM_NAME, 0, 0, Argv[1], "unrecognized argument after VFR file name");
462 return STATUS_ERROR;
463 } else if (Argc < 1) {
464 Error (PROGRAM_NAME, 0, 0, NULL, "must specify VFR file name");
465 return STATUS_ERROR;
466 }
467 strcpy (gOptions.VfrFileName, Argv[0]);
468 //
469 // We run the preprocessor on the VFR file to manage #include statements.
470 // Unfortunately the preprocessor does not allow you to specify the
471 // output name or path of the resultant .i file, so we have to do
472 // some work. Here we'll extract the basename of the VFR file, then
473 // append .i on the end.
474 //
475 strcpy (CopyStr, gOptions.VfrFileName);
476 Cptr = CopyStr + strlen (CopyStr) - 1;
477 for (;(Cptr > CopyStr) && (*Cptr != '\\') && (*Cptr != ':') && (*Cptr != '/'); Cptr--);
478 if (Cptr == CopyStr) {
479 strcpy (gOptions.PreprocessorOutputFileName, Cptr);
480 strcpy (gOptions.VfrBaseFileName, Cptr);
481 } else {
482 strcpy (gOptions.PreprocessorOutputFileName, Cptr+1);
483 strcpy (gOptions.VfrBaseFileName, Cptr+1);
484 }
485 for (Cptr = gOptions.PreprocessorOutputFileName; *Cptr && (*Cptr != '.'); Cptr++);
486 strcpy (Cptr, ".i");
487 //
488 // Terminate the vfr file basename at the extension
489 //
490 for (Cptr = gOptions.VfrBaseFileName; *Cptr && (*Cptr != '.'); Cptr++) {
491 }
492 *Cptr = 0;
493 //
494 // If they defined an output directory, prepend all output files
495 // with the working directory. Output files of interest:
496 // VfrListFileName -- list file
497 // IfrOutputFileName -- IFR bytes
498 // StringOutputFileName -- string bytes
499 // StringListFileName -- not used
500 // StringDefineFileName -- #defines of string identifiers
501 //
502 // We have two cases:
503 // 1. Output directory (-od) not specified, in which case output files
504 // go to the current working directory.
505 // 2. Output directory specified, in which case the output files
506 // go directly to the specified directory.
507 //
508 if (gOptions.OutputDirectory[0] == 0) {
509 CopyStr[0] = 0;
510 #ifndef __GNUC__
511 _getcwd (CopyStr, sizeof (CopyStr));
512 #else
513 getcwd (CopyStr, sizeof (CopyStr));
514 #endif
515 strcpy (gOptions.OutputDirectory, CopyStr);
516 }
517 //
518 // Make sure output directory has a trailing backslash
519 //
520 if (gOptions.OutputDirectory[strlen (gOptions.OutputDirectory) - 1] != '\\' ||
521 gOptions.OutputDirectory[strlen (gOptions.OutputDirectory) - 1] != '/') {
522 strcat (gOptions.OutputDirectory, FILE_SEP_STRING);
523 }
524 //
525 // Create the base output file name as: path\base, copy it to all the output
526 // filenames, and then add the appropriate extension to each.
527 //
528 strcpy (gOptions.VfrListFileName, gOptions.OutputDirectory);
529 strcat (gOptions.VfrListFileName, gOptions.VfrBaseFileName);
530 strcpy (gOptions.IfrOutputFileName, gOptions.VfrListFileName);
531 strcat (gOptions.VfrListFileName, VFR_LIST_FILENAME_EXTENSION);
532 strcat (gOptions.IfrOutputFileName, VFR_BINARY_FILENAME_EXTENSION);
533 //
534 // We set a default list file name, so if they do not
535 // want a list file, null out the name now.
536 //
537 if (gOptions.CreateListFile == 0) {
538 gOptions.VfrListFileName[0] = 0;
539 }
540 return STATUS_SUCCESS;
541 }
542 static
543 VOID
544 Usage ()
545 /*++
546
547 Routine Description:
548 Print utility usage instructions
549
550 Arguments:
551 None
552
553 Returns:
554 None
555
556 --*/
557 {
558 int Index;
559 const char *Help[] = {
560 " ",
561 "VfrCompile version " VFR_COMPILER_VERSION,
562 " ",
563 " Usage: VfrCompile {options} [VfrFile]",
564 " ",
565 " where options include:",
566 " -? or -h prints this help",
567 " -l create an output IFR listing file",
568 " -i IncPath add IncPath to the search path for VFR included files",
569 " -od OutputDir deposit all output files to directory OutputDir (default=cwd)",
570 " -ibin create an IFR HII pack file",
571 " where parameters include:",
572 " VfrFile name of the input VFR script file",
573 " ",
574 NULL
575 };
576 for (Index = 0; Help[Index] != NULL; Index++) {
577 fprintf (stdout, "%s\n", Help[Index]);
578 }
579 }
580
581 >>
582
583
584 #lexaction
585 <<
586
587 #include "EfiVfr.h"
588
589 PARSER_LINE_DEFINITION *gLineDefinition = NULL;
590 PARSER_LINE_DEFINITION *gLastLineDefinition = NULL;
591
592 VOID
593 AddFileLine (
594 char *TokenString,
595 UINT32 TokenLine
596 )
597 /*++
598
599 Routine Description:
600 During the lexer phase, if we encounter a #line statement output by
601 the preprocessor, this function gets called. We'll save off the info
602 for error reporting purposes. The preprocessor line information has the
603 form:
604
605 #line 3 "FileName.c"
606
607 Arguments:
608 TokenString - the parsed string as shown above
609 TokenLine - the line number in the preprocessed output file
610
611 Returns:
612 NA
613
614 --*/
615 {
616 PARSER_LINE_DEFINITION *LineDef;
617 CHAR8 *Cptr;
618
619 //
620 // Allocate a structure in which we can keep track of this line information.
621 //
622 LineDef = (PARSER_LINE_DEFINITION *)malloc (sizeof (PARSER_LINE_DEFINITION));
623 memset ((char *)LineDef, 0, sizeof (PARSER_LINE_DEFINITION));
624 LineDef->TokenLineNum = TokenLine;
625 LineDef->HashLineNum = atoi (TokenString + 6);
626 //
627 // Find the quotes in the filename, then allocate space in the line
628 // def structure for a copy of the filename. Finally, copy it without
629 // quotes to the line def.
630 //
631 for (Cptr = TokenString + 7; *Cptr && (*Cptr != '"'); Cptr++);
632 if (*Cptr == '"') {
633 LineDef->FileName = (CHAR8 *)malloc (strlen (Cptr));
634 Cptr++;
635 strcpy (LineDef->FileName, Cptr);
636 for (Cptr = LineDef->FileName; *Cptr && (*Cptr != '"'); Cptr++);
637 *Cptr = 0;
638 //
639 // Now add this new one to the list
640 //
641 if (gLineDefinition == NULL) {
642 gLineDefinition = LineDef;
643 } else {
644 gLastLineDefinition->Next = LineDef;
645 }
646 gLastLineDefinition = LineDef;
647 } else {
648 Error (PROGRAM_NAME, 0, 0, "invalid line definition in preprocessor output file", TokenString);
649 free (LineDef);
650 return;
651 }
652 }
653 char *
654 ConvertLineNumber (
655 UINT32 *LineNum
656 )
657 /*++
658
659 Routine Description:
660 Given the line number in the preprocessor-output file, use the line number
661 information we've saved to determine the source file name and line number
662 where the code originally came from. This is required for error reporting.
663
664 Arguments:
665 LineNum - the line number in the preprocessor-output file.
666
667 Returns:
668 Returns a pointer to the source file name. Also returns the line number
669 in the provided LineNum argument
670
671 --*/
672 {
673 PARSER_LINE_DEFINITION *LineDef;
674 //
675 // Step through our linked list of #line information we saved off.
676 // For each one, look at its line number, and the line number of the
677 // next record, and see if the passed-in line number is in the range.
678 // If it is, then convert the line number to the appropriate line number
679 // of the original source file.
680 //
681 for (LineDef = gLineDefinition; LineDef != NULL; LineDef = LineDef->Next) {
682 //
683 // The given LineNum is the line number from the .i file.
684 // Find a line definition whose range includes this line number,
685 // convert the line number, and return the filename.
686 //
687 if (LineDef->TokenLineNum <= *LineNum) {
688 if (LineDef->Next != NULL) {
689 if (LineDef->Next->TokenLineNum > *LineNum) {
690 *LineNum = *LineNum - LineDef->TokenLineNum + LineDef->HashLineNum;
691 return LineDef->FileName;
692 }
693 } else {
694 //
695 // Last one in the list of line definitions, so has to be right
696 //
697 *LineNum = *LineNum - LineDef->TokenLineNum + LineDef->HashLineNum;
698 return LineDef->FileName;
699 }
700 }
701 }
702 return NULL;
703 }
704
705 >>
706
707 //
708 // Define a lexical class for parsing quoted strings. Basically
709 // starts with a double quote, and ends with a double quote that
710 // is not preceeded with a backslash.
711 //
712 #lexclass QUOTED_STRING
713 #token TheString "~[\"]*\"" << mode (START); >>
714
715 //
716 // Define a lexical class for parsing "#pragma pack" statements.
717 // We do this just for convenience (since we skip them here) so
718 // that users can include some minimal .h files.
719 //
720 #lexclass PRAGMA_PACK
721 #token "pack" << skip (); >>
722 #token "[\ \t]" << skip (); >>
723 #token "\(" << skip (); >>
724 #token "[0-9]*" << skip (); >>
725 #token "\)" << skip (); mode (START); >>
726
727 //
728 // Define a lexclass for skipping over C++ style comments
729 //
730 #lexclass CPP_COMMENT
731 #token "~[\n]*" << skip (); >>
732 #token "\n" << skip (); mode (START); newline (); >>
733
734 //
735 // Standard lexclass is START
736 //
737 #lexclass START
738
739 //
740 // Find start of C++ style comments
741 //
742 #token "//" << skip (); mode (CPP_COMMENT); >>
743
744 //
745 // Skip whitespace
746 //
747 #token "[\ \t]" << skip (); >>
748
749 //
750 // Skip over newlines, but count them
751 //
752 #token "\n" << skip (); newline (); >>
753
754 //
755 // Skip pragma pack statements
756 //
757 #token "\#pragma" << skip (); mode(PRAGMA_PACK); >>
758
759 //
760 // Skip over 'extern' in any included .H file
761 //
762 #token "extern" << skip (); >>
763
764 //
765 // Tokens for the different keywords. Syntax is:
766 // TokenName("ErrorMessageText") "TokenString"
767 // where:
768 // TokenName is the token name (must be capitalized) that is used in the rules
769 // ErrorMessageText is the string the compiler emits when it detects a syntax error
770 // TokenString is the actual matching string used in the user script
771 //
772 #token LineDefinition "#line\ [0-9]+\ \"~[\"]+\"[\ \t]*\n" << AddFileLine (begexpr (), line ()); skip (); >>
773 #token FormSet("formset") "formset"
774 #token EndFormSet("endformset") "endformset"
775 #token Title("title") "title"
776 #token FormId("formid") "formid"
777 #token OneOf("oneof") "oneof"
778 #token Prompt("prompt") "prompt"
779 #token OrderedList("orderedlist") "orderedlist"
780 #token EndList("endlist") "endlist"
781 #token EndForm("endform") "endform"
782 #token EndOneOf("endoneof") "endoneof"
783 #token Form("form") "form"
784 #token Subtitle("subtitle") "subtitle"
785 #token Help("help") "help"
786 #token VarId("varid") "varid"
787 #token Text("text") "text"
788 #token Option("option") "option"
789 #token Value("value") "value"
790 #token Flags("flags") "flags"
791 #token Date("date") "date"
792 #token EndDate("enddate") "enddate"
793 #token Year("year") "year"
794 #token Month("month") "month"
795 #token Day("day") "day"
796 #token Time("time") "time"
797 #token EndTime("endtime") "endtime"
798 #token Hour("hour") "hour"
799 #token Minute("minute") "minute"
800 #token Second("second") "second"
801 #token AND("AND") "AND"
802 #token OR("OR") "OR"
803 #token GrayOutIf("grayoutif") "grayoutif"
804 #token NOT("NOT") "NOT"
805 #token Label("label") "label"
806 #token Timeout("timeout") "timeout"
807 #token Inventory("inventory") "inventory"
808 #token StringToken("STRING_TOKEN") "STRING_TOKEN"
809 #token NonNvDataMap("_NON_NV_DATA_MAP") "_NON_NV_DATA_MAP"
810 #token Struct("struct") "struct"
811 #token Uint64("UINT64") "UINT64"
812 #token Uint32("UINT32") "UINT32"
813 #token Uint16("UINT16") "UINT16"
814 #token Char16("CHAR16") "CHAR16"
815 #token Uint8("UINT8") "UINT8"
816 #token Guid("guid") "guid"
817 #token CheckBox("checkbox") "checkbox"
818 #token EndCheckBox("endcheckbox") "endcheckbox"
819 #token Numeric("numeric") "numeric"
820 #token EndNumeric("endnumeric") "endnumeric"
821 #token Minimum("minimum") "minimum"
822 #token Maximum("maximum") "maximum"
823 #token Step("step") "step"
824 #token Default("default") "default"
825 #token Password("password") "password"
826 #token EndPassword("endpassword") "endpassword"
827 #token String("string") "string"
828 #token EndString("endstring") "endstring"
829 #token MinSize("minsize") "minsize"
830 #token MaxSize("maxsize") "maxsize"
831 #token Encoding("encoding") "encoding"
832 #token SuppressIf("suppressif") "suppressif"
833 #token Hidden("hidden") "hidden"
834 #token Goto("goto") "goto"
835 #token InconsistentIf "inconsistentif"
836 #token EndIf("endif") "endif"
837 #token IdEqId("ideqid") "ideqid"
838 #token IdEqVal("ideqval") "ideqval"
839 #token VarEqVal("vareqval") "vareqval"
840 #token Var("var") "var"
841 #token IdEqValList("ideqvallist") "ideqvallist"
842 #token Length("length") "length"
843 #token Values("values") "values"
844 #token Key("key") "key"
845 #token DefaultFlag("DEFAULT") "DEFAULT"
846 #token ManufacturingFlag("MANUFACTURING") "MANUFACTURING"
847 #token InteractiveFlag("INTERACTIVE") "INTERACTIVE"
848 #token NVAccessFlag("NV_ACCESS") "NV_ACCESS"
849 #token ResetRequiredFlag("RESET_REQUIRED") "RESET_REQUIRED"
850 #token LateCheckFlag("LATE_CHECK") "LATE_CHECK"
851 #token Class("class") "class"
852 #token Subclass("subclass") "subclass"
853 #token TypeDef("typedef") "typedef"
854 #token Restore("restore") "restore"
855 #token Save("save") "save"
856 #token Defaults("defaults") "defaults"
857 #token Banner("banner") "banner"
858 #token Align("align") "align"
859 #token Left("left") "left"
860 #token Right("right") "right"
861 #token Center("center") "center"
862 #token Line("line") "line"
863 #token VarStore("varstore") "varstore"
864 #token Name("name") "name"
865 #token Oem("oem") "oem"
866 #token True("TRUE") "TRUE"
867 #token False("FALSE") "FALSE"
868 #token GreaterThan(">") ">"
869 #token GreaterEqual(">=") ">="
870 #token LessThan("<") "<"
871 #token LessEqual("<=") "<="
872
873 //
874 // Define the class and subclass tokens
875 //
876 #token ClassNonDevice("NONDEVICE") "NON_DEVICE"
877 #token ClassDiskDevice("DISK_DEVICE") "DISK_DEVICE"
878 #token ClassVideoDevice("VIDEO_DEVICE") "VIDEO_DEVICE"
879 #token ClassNetworkDevice("NETWORK_DEVICE") "NETWORK_DEVICE"
880 #token ClassInputDevice("INPUT_DEVICE") "INPUT_DEVICE"
881 #token ClassOnBoardDevice("ONBOARD_DEVICE") "ONBOARD_DEVICE"
882 #token ClassOtherDevice("OTHER_DEVICE") "OTHER_DEVICE"
883
884 #token SubclassSetupApplication("SETUP_APPLICATION") "SETUP_APPLICATION"
885 #token SubclassGeneralApplication("GENERAL_APPLICATION") "GENERAL_APPLICATION"
886 #token SubclassFrontPage("FRONT_PAGE") "FRONT_PAGE"
887 #token SubclassSingleUse("SINGLE_USE") "SINGLE_USE"
888
889 #token LanguageIdentifier("language identifier") "[a-z][a-z][a-z]" // 3 lowercase characters
890 #token StringIdentifier("string identifier") "[A-Za-z_][A-Za-z_0-9]*"
891 #token Number("numeric value") "(0x[0-9A-Fa-f]+) | [0-9]+"
892 #token OpenBrace("{") "\{"
893 #token CloseBrace("}") "\}"
894 #token OpenParen("(") "\("
895 #token CloseParen(")") "\)"
896 #token OpenBracket("[") "\["
897 #token CloseBracket("]") "\]"
898
899 //
900 // Define all other invalid characters so that they get through the lexical phase
901 // and we can catch them during the parse phase. We get much better error
902 // messages then.
903 //
904 #token InvalidCharacters("invalid characters") "~[;:=,\.\|]"
905
906 //
907 // This is the overall definition of a VFR form definition script.
908 //
909 program :
910 ( dataStructDefinition )*
911 formSetStatement
912 ( vfrStatementVarStore )*
913 ( formDefinition )*
914 EFS:EndFormSet ";" << WriteOpByte (EFS->getLine(), EFI_IFR_END_FORM_SET_OP); >>
915 "@" // end of file
916 ;
917
918 formSetStatement :
919 FS:FormSet << WriteOpByte (FS->getLine(), EFI_IFR_FORM_SET_OP); >>
920 Guid "="
921 OpenBrace
922 G1:Number ","
923 G2:Number ","
924 G3:Number ","
925 OpenBrace
926 G4:Number ","
927 G5:Number ","
928 G6:Number ","
929 G7:Number ","
930 G8:Number ","
931 G9:Number ","
932 G10:Number ","
933 G11:Number
934 CloseBrace
935 CloseBrace << WriteGuidValue (G1->getLine (), G1->getText (), G2->getText (), G3->getText (),
936 G4->getText (), G5->getText (), G6->getText (), G7->getText (),
937 G8->getText (), G9->getText (), G10->getText (), G11->getText ()
938 );
939 >>
940 ","
941 Title "=" getStringId ","
942 Help "=" getStringId ","
943 //
944 // insert padding for an EFI_PHYSICAL_ADDRESS (UINT64)
945 //
946 << WriteDWord (0, 0); WriteDWord (0, 0); >>
947 Class "=" CVAL:classDefinition "," << WriteClass (); >>
948 Subclass "=" SVAL:subclassDefinition "," << WriteSubclass (); >>
949 << WriteWord (mNvDataStructSize); >>
950 ;
951
952 //
953 // A form can be of multiple classes, thus allow CLASS_A | CLASS_B | CLASS_C
954 //
955 classDefinition :
956 validClassNames ( "\|" validClassNames )*
957 ;
958
959 validClassNames :
960 CND:ClassNonDevice << SetClass (CND->getLine(), EFI_NON_DEVICE_CLASS); >>
961 | CDD:ClassDiskDevice << SetClass (CDD->getLine(), EFI_DISK_DEVICE_CLASS); >>
962 | CVD:ClassVideoDevice << SetClass (CVD->getLine(), EFI_VIDEO_DEVICE_CLASS); >>
963 | CNW:ClassNetworkDevice << SetClass (CNW->getLine(), EFI_NETWORK_DEVICE_CLASS); >>
964 | CID:ClassInputDevice << SetClass (CID->getLine(), EFI_INPUT_DEVICE_CLASS); >>
965 | COB:ClassOnBoardDevice << SetClass (COB->getLine(), EFI_ON_BOARD_DEVICE_CLASS); >>
966 | COD:ClassOtherDevice << SetClass (COD->getLine(), EFI_OTHER_DEVICE_CLASS); >>
967 | CNUM:Number << SetClass (CNUM->getLine(), GetNumber (CNUM->getText(), CNUM->getLine(), 4)); >>
968 ; << PrintErrorMessage (LT(1)->getLine(), LT(1)->getText(), "invalid class"); >>
969
970 //
971 // A form can only be of one subclass type.
972 //
973 subclassDefinition :
974 SSA:SubclassSetupApplication << SetSubclass (SSA->getLine(), EFI_SETUP_APPLICATION_SUBCLASS); >>
975 | SGA:SubclassGeneralApplication << SetSubclass (SGA->getLine(), EFI_GENERAL_APPLICATION_SUBCLASS); >>
976 | SFP:SubclassFrontPage << SetSubclass (SFP->getLine(), EFI_FRONT_PAGE_SUBCLASS); >>
977 | SSU:SubclassSingleUse << SetSubclass (SSU->getLine(), EFI_SINGLE_USE_SUBCLASS); >>
978 | SNUM:Number << SetSubclass (SNUM->getLine(), GetNumber (SNUM->getText(), SNUM->getLine(), 4)); >>
979 ; << PrintErrorMessage (LT(1)->getLine(), LT(1)->getText(), "invalid subclass"); >>
980
981 //
982 // Parse a C type data structure for storing VFR setup data. Allow:
983 // typedef struct _XXX_ {
984 // (fields)
985 // } MY_NV_DATA;
986 //
987 dataStructDefinition :
988 << int IsNonNV = 0; >>
989 { TypeDef }
990 S:Struct
991 (
992 NonNvDataMap << IsNonNV = 1; >>
993 |
994 { StringIdentifier }
995 ) << StartStructDefinition (IsNonNV, S->getLine()); >>
996 OpenBrace
997 dataStructFields
998 CloseBrace NAME:StringIdentifier << EndStructDefinition (NAME->getText(), NAME->getLine()); >>
999 ";"
1000 ;
1001
1002 //
1003 // Parse a C type data structure for defining data that is not stored in NV.
1004 // typedef struct _NON_NV_DATA_MAP {
1005 // (fields)
1006 // } NON_NV_DATA_MAP;
1007 //
1008 nonNvDataStructDefinition :
1009 { TypeDef }
1010 Struct NonNvDataMap
1011 { StringIdentifier }
1012 OpenBrace
1013 dataStructFields
1014 CloseBrace NAME:StringIdentifier << AddStructField (NAME->getText(), NAME->getLine(), 0, 0, 0); >>
1015 ";"
1016 ;
1017
1018 dataStructFields :
1019 ( dataStructField64 | dataStructField32 | dataStructField16 | dataStructField8 ) *
1020 ;
1021
1022 //*****************************************************************************
1023 //
1024 // PARSE:
1025 // UINT64 Name[4];
1026 // UINT64 Name;
1027 //
1028 // Used while parsing the NV data map structures.
1029 //
1030 dataStructField64 :
1031 << int ArrayLength = 1; char IsArray = 0; >>
1032 "UINT64"
1033 NAME:StringIdentifier
1034 ( ";" | OpenBracket IVal:Number CloseBracket ";" << ArrayLength = GetNumber (IVal->getText(), IVal->getLine(), 4); IsArray = 1; >> )
1035 << AddStructField (NAME->getText(), NAME->getLine(), 8, ArrayLength, IsArray); >>
1036 ;
1037
1038 //*****************************************************************************
1039 //
1040 // PARSE:
1041 // UINT32 Name[4];
1042 // UINT32 Name;
1043 //
1044 // Used while parsing the NV data map structures.
1045 //
1046 dataStructField32 :
1047 << int ArrayLength = 1; char IsArray = 0; >>
1048 "UINT32"
1049 NAME:StringIdentifier
1050 ( ";" | OpenBracket IVal:Number CloseBracket ";" << ArrayLength = GetNumber (IVal->getText(), IVal->getLine(), 4); IsArray = 1; >> )
1051 << AddStructField (NAME->getText(), NAME->getLine(), 4, ArrayLength, IsArray); >>
1052 ;
1053
1054 //*****************************************************************************
1055 //
1056 // PARSE:
1057 // UINT16 Name[4];
1058 // UINT16 Name;
1059 //
1060 // Used while parsing the NV data map structures.
1061 //
1062 dataStructField16 :
1063 << int ArrayLength = 1; char IsArray = 0; >>
1064 ( "UINT16" | "CHAR16" )
1065 NAME:StringIdentifier
1066 ( ";" | OpenBracket IVal:Number CloseBracket ";" << ArrayLength = GetNumber (IVal->getText(), IVal->getLine(), 4); IsArray = 1; >> )
1067 << AddStructField (NAME->getText(), NAME->getLine(), 2, ArrayLength, IsArray); >>
1068 ;
1069
1070 //*****************************************************************************
1071 //
1072 // PARSE:
1073 // UINT8 Name[4];
1074 // UINT8 Name;
1075 //
1076 // Used while parsing the NV data map structures.
1077 //
1078 dataStructField8 :
1079 << int ArrayLength = 1; char IsArray = 0; >>
1080 "UINT8"
1081 NAME:StringIdentifier
1082 ( ";" | OpenBracket IVal:Number CloseBracket ";" << ArrayLength = GetNumber (IVal->getText(), IVal->getLine(), 4); IsArray = 1; >> )
1083 << AddStructField (NAME->getText(), NAME->getLine(), 1, ArrayLength, IsArray); >>
1084 ;
1085
1086 //*****************************************************************************
1087 //
1088 // PARSE:
1089 // form formid = 1,
1090 // title = STRING_TOKEN(STR_FORM_TITLE);
1091 // -- form statements --
1092 // endform;
1093 //
1094 // The Form ID cannot be 0
1095 //
1096 formDefinition :
1097 FRM:Form FormId << WriteOpByte (FRM->getLine(), EFI_IFR_FORM_OP); >>
1098 "="
1099 VAL:Number << WriteWord (GetNumber (VAL->getText(), VAL->getLine(), 2)); AddFormId (GetNumber (VAL->getText(), VAL->getLine(), 2), VAL->getLine()); >>
1100 ","
1101 Title "=" getStringId ";" // writes string identifier
1102 ( vfrStatements )*
1103 ENDF:EndForm ";" << WriteOpByte (ENDF->getLine(), EFI_IFR_END_FORM_OP); >>
1104 ;
1105
1106 //
1107 // VFR statements in a formset
1108 //
1109 vfrStatements :
1110 vfrStatementSubTitle |
1111 vfrStatementOneOf |
1112 vfrStatementTextText |
1113 vfrStatementCheckBox |
1114 vfrStatementNumeric |
1115 vfrStatementDate |
1116 vfrStatementTime |
1117 vfrStatementPassword |
1118 vfrStatementString |
1119 vfrStatementSuppressIf |
1120 vfrStatementHidden |
1121 vfrStatementGoto |
1122 vfrStatementGrayOutIf |
1123 vfrStatementInconsistentIf |
1124 vfrStatementLabel |
1125 vfrStatementBanner |
1126 vfrStatementInventory |
1127 vfrStatementOrderedList |
1128 vfrStatementOem |
1129 vfrStatementSaveRestoreDefaults
1130 ;
1131
1132 //*****************************************************************************
1133 //
1134 // PARSE:
1135 // label 100;
1136 //
1137 vfrStatementLabel :
1138 OPID:Label << WriteOpByte (OPID->getLine(), EFI_IFR_LABEL_OP); >>
1139 VAL:Number <<
1140 WriteWord (GetNumber (VAL->getText(), VAL->getLine(), 2));
1141 AddLabel (GetNumber (VAL->getText(), VAL->getLine(), 2), VAL->getLine());
1142 >>
1143 ";"
1144 ;
1145
1146 //*****************************************************************************
1147 //
1148 // PARSE:
1149 // oem 0x12, 0x34, 0x56;
1150 //
1151 vfrStatementOem :
1152 OPID:Oem << WriteOpByte (OPID->getLine(), EFI_IFR_OEM_DEFINED_OP); >>
1153 ( VAL1:Number << WriteByte (GetNumber (VAL1->getText(), VAL1->getLine(), 1), 0); >> )
1154 ( "," VAL2:Number << WriteByte (GetNumber (VAL2->getText(), VAL2->getLine(), 1), 0); >> )*
1155 ";"
1156 ;
1157
1158 //*****************************************************************************
1159 //
1160 // PARSE:
1161 // inconsistentif NOT .... AND NOT .... OR ... endif;
1162 //
1163 vfrStatementInconsistentIf :
1164 << ResetFlags (); >>
1165 IIFOP:InconsistentIf << WriteOpByte (IIFOP->getLine(), EFI_IFR_INCONSISTENT_IF_OP); >>
1166 Prompt "=" getStringId ","
1167 {
1168 FF:Flags "=" flagsField ( "\|" flagsField )* ","
1169 }
1170 << WriteFlags (); >> // write the flags field
1171 vfrBooleanExpression
1172 EOP:EndIf ";" << WriteOpByte (EOP->getLine(), EFI_IFR_END_IF_OP); >>
1173 ;
1174
1175 //*****************************************************************************
1176 //
1177 // PARSE:
1178 // TRUE AND (ideqval SomeStruct.SomeMember >= 0x10 OR
1179 // ideqid SomeStruct.SomeMember < SomeStruct.SomeOtherMember) AND
1180 // (ideqlist SomeStruct.SomeOtherMember == 0x10, 0x20, 0x30 OR
1181 // vareqval var(VAR_EQ_TEST_NAME) == 0x1)
1182 //
1183 // For supporting complex express, divide the vfrBooleanExpression to two parts
1184 // so that pred-LL(k) parser can parse incrementally.
1185 //
1186 vfrBooleanExpression :
1187 leftPartVfrBooleanExp { rightPartVfrBooleanExp }
1188 ;
1189
1190 leftPartVfrBooleanExp :
1191 OpenParen vfrBooleanExpression CloseParen |
1192 (ideqval | ideqid | ideqvallist | vareqval | truefalse) |
1193 NOPID:NOT leftPartVfrBooleanExp << WriteOpByte (NOPID->getLine(), EFI_IFR_NOT_OP); >>
1194 ;
1195
1196 rightPartVfrBooleanExp :
1197 AOPID:AND vfrBooleanExpression << WriteOpByte (AOPID->getLine(), EFI_IFR_AND_OP); >> |
1198 OOPID:OR vfrBooleanExpression << WriteOpByte (OOPID->getLine(), EFI_IFR_OR_OP); >>
1199 ;
1200
1201 //*****************************************************************************
1202 //
1203 // PARSE:
1204 // TRUE
1205 //
1206 truefalse :
1207 TOPID:True << WriteOpByte (TOPID->getLine(), EFI_IFR_TRUE_OP); >> |
1208 FOPID:False << WriteOpByte (FOPID->getLine(), EFI_IFR_FALSE_OP); >>
1209 ;
1210
1211 //*****************************************************************************
1212 //
1213 // PARSE:
1214 // varstore MY_STRUCT_NAME, key = 0x1234, name = "MyVariableName", guid = {...};
1215 //
1216 vfrStatementVarStore :
1217 OP:VarStore << WriteOpByte (OP->getLine(), EFI_IFR_VARSTORE_OP); >>
1218 STRUCT_NAME:StringIdentifier ","
1219 Key "=" KNUM:Number ","
1220 Name "=" VAR_NAME:StringIdentifier ","
1221 Guid "="
1222 OpenBrace
1223 G1:Number ","
1224 G2:Number ","
1225 G3:Number ","
1226 OpenBrace
1227 G4:Number ","
1228 G5:Number ","
1229 G6:Number ","
1230 G7:Number ","
1231 G8:Number ","
1232 G9:Number ","
1233 G10:Number ","
1234 G11:Number
1235 CloseBrace
1236 CloseBrace << WriteGuidValue (G1->getLine (), G1->getText (), G2->getText (), G3->getText (),
1237 G4->getText (), G5->getText (), G6->getText (), G7->getText (),
1238 G8->getText (), G9->getText (), G10->getText (), G11->getText ()
1239 );
1240 WriteWord (GetNumber (KNUM->getText(), KNUM->getLine(), 2));
1241 AddVarStore (STRUCT_NAME->getText(), VAR_NAME->getText(), GetNumber (KNUM->getText(), KNUM->getLine(), 2), STRUCT_NAME->getLine());
1242 >>
1243
1244 ";"
1245 ;
1246
1247 //*****************************************************************************
1248 //
1249 // PARSE:
1250 // vareqval var(0x100) == 0x20
1251 //
1252 vareqval :
1253 OPID:VarEqVal << WriteOpByte (OPID->getLine(), EFI_IFR_EQ_VAR_VAL_OP); >>
1254 Var OpenParen
1255 VAR:Number << WriteWord (GetNumber (VAR->getText(), VAR->getLine(), 2)); >>
1256 CloseParen
1257 compareNumber
1258 ;
1259
1260 ideqval :
1261 OPID:IdEqVal << WriteOpByte (OPID->getLine(), EFI_IFR_EQ_ID_VAL_OP); >>
1262 vfrStructFieldName[0]
1263 compareNumber
1264 ;
1265
1266 //*****************************************************************************
1267 //
1268 // PARSE:
1269 // ideqid MyNVData3.Field16A == MyNVData3.Field16B
1270 //
1271 // NOTE: Before processing the second variable store in the ideqid statement, set a global flag
1272 // so that when we parse the second variable we set the secondary variable store id.
1273 //
1274 ideqid :
1275 OPID:IdEqId << WriteOpByte (OPID->getLine(), EFI_IFR_EQ_ID_ID_OP); >>
1276 vfrStructFieldName[0]
1277 compareVfrStructFieldNameNL0
1278 ;
1279
1280 //*****************************************************************************
1281 //
1282 // compareNumber is the combination of compare operation and Number
1283 //
1284 compareNumber :
1285 (
1286 "=="
1287 VAL1:Number << WriteWord (GetNumber (VAL1->getText(), VAL1->getLine(), 2)); >>
1288 ) |
1289 (
1290 GTOPID:GreaterThan
1291 VAL2:Number << WriteWord (GetNumber (VAL2->getText(), VAL2->getLine(), 2));
1292 WriteOpByte (GTOPID->getLine(), EFI_IFR_GT_OP); >>
1293 ) |
1294 (
1295 GEOPID:GreaterEqual
1296 VAL3:Number << WriteWord (GetNumber (VAL3->getText(), VAL3->getLine(), 2));
1297 WriteOpByte (GEOPID->getLine(), EFI_IFR_GE_OP); >>
1298 ) |
1299 (
1300 LTOPID:LessThan
1301 VAL4:Number << WriteWord (GetNumber (VAL4->getText(), VAL4->getLine(), 2));
1302 WriteOpByte (LTOPID->getLine(), EFI_IFR_GE_OP);
1303 WriteOpByte (LTOPID->getLine(), EFI_IFR_NOT_OP); >>
1304 ) |
1305 (
1306 LEOPID:LessEqual
1307 VAL5:Number << WriteWord (GetNumber (VAL5->getText(), VAL5->getLine(), 2));
1308 WriteOpByte (LEOPID->getLine(), EFI_IFR_GT_OP);
1309 WriteOpByte (LEOPID->getLine(), EFI_IFR_NOT_OP); >>
1310 )
1311 ;
1312
1313 //*****************************************************************************
1314 //
1315 // compareVfrStructFieldNameNL0 is the combination of compare operation and vfrStructFieldNameNL[0]
1316 //
1317 compareVfrStructFieldNameNL0 :
1318 (
1319 "==" << mIdEqIdStmt = 1; >>
1320 vfrStructFieldNameNL[0] << mIdEqIdStmt = 0; >>
1321 ) |
1322 (
1323 GTOPID:GreaterThan << mIdEqIdStmt = 1; >>
1324 vfrStructFieldNameNL[0] << mIdEqIdStmt = 0;
1325 WriteOpByte (GTOPID->getLine(), EFI_IFR_GT_OP); >>
1326 ) |
1327 (
1328 GEOPID:GreaterEqual << mIdEqIdStmt = 1; >>
1329 vfrStructFieldNameNL[0] << mIdEqIdStmt = 0;
1330 WriteOpByte (GEOPID->getLine(), EFI_IFR_GE_OP); >>
1331 ) |
1332 (
1333 LTOPID:LessThan << mIdEqIdStmt = 1; >>
1334 vfrStructFieldNameNL[0] << mIdEqIdStmt = 0;
1335 WriteOpByte (LTOPID->getLine(), EFI_IFR_GE_OP);
1336 WriteOpByte (LTOPID->getLine(), EFI_IFR_NOT_OP); >>
1337 ) |
1338 (
1339 LEOPID:LessEqual << mIdEqIdStmt = 1; >>
1340 vfrStructFieldNameNL[0] << mIdEqIdStmt = 0;
1341 WriteOpByte (LEOPID->getLine(), EFI_IFR_GT_OP);
1342 WriteOpByte (LEOPID->getLine(), EFI_IFR_NOT_OP); >>
1343 )
1344 ;
1345
1346
1347 ideqvallist :
1348 OPID:IdEqValList << WriteOpByte (OPID->getLine(), EFI_IFR_EQ_ID_LIST_OP); >>
1349 vfrStructFieldName[0]
1350 "=="
1351 ( VAL:Number << QueueIdEqValList (GetNumber (VAL->getText(), VAL->getLine(), 2)); >> ) +
1352 << FlushQueueIdEqValList(); >>
1353 ;
1354
1355 vfrStatementGoto :
1356 << UINT32 LineNum, KeyValue = 0; ResetFlags (); >>
1357 IDG:Goto << WriteOpByte (IDG->getLine(), EFI_IFR_REF_OP); >>
1358 VAL:Number "," << WriteWord (GetNumber (VAL->getText(), VAL->getLine(), 2));
1359 AddGotoReference (GetNumber (VAL->getText(), VAL->getLine(), 2), VAL->getLine());
1360 >>
1361 KP:Prompt "=" getStringId "," << LineNum = KP->getLine(); >>
1362 Help "=" getStringId
1363 {
1364 ","
1365 FF:Flags "=" flagsField ( "\|" flagsField )* << LineNum = FF->getLine(); >>
1366 }
1367 {
1368 "," Key "=" KNUM:Number << LineNum = KNUM->getLine(); KeyValue = GetNumber(KNUM->getText(), LineNum, 2); >>
1369 }
1370 << WriteFlagsKey (KeyValue, LineNum); >>
1371 ";"
1372 ;
1373
1374 vfrStatementHidden :
1375 IDH:Hidden << WriteOpByte (IDH->getLine(), EFI_IFR_HIDDEN_OP); >>
1376 Value "="
1377 VAL:Number "," << WriteWord (GetNumber (VAL->getText(), VAL->getLine(), 2)); >>
1378 Key "="
1379 KVAL:Number << WriteWord (GetNumber (KVAL->getText(), KVAL->getLine(), 2)); >>
1380 ";"
1381 ;
1382
1383 //*****************************************************************************
1384 //
1385 // PARSE:
1386 // suppressif <boolean_expression> { grayoutif } <statements>+ endif;
1387 // Note:
1388 // You can have: suppressif:grayoutif:statements:endif
1389 // suppressif:grayoutif:endif -- serves no purpose
1390 // suppressif:statements:endif
1391 // suppressif:endif -- serves no purpose
1392 //
1393 vfrStatementSuppressIf :
1394 << ResetFlags (); >>
1395 OPID:SuppressIf << WriteOpByte (OPID->getLine(), EFI_IFR_SUPPRESS_IF_OP); SetIfStart (OPID->getLine()); >>
1396 {
1397 FF:Flags "=" flagsField ( "\|" flagsField )* ","
1398 }
1399 << WriteFlags (); >> // write the flags field
1400 vfrBooleanExpression
1401 ";"
1402 { suppressIfGrayOutIf } ( suppressIfAndGrayoutIfSubstatements )+
1403 ENDOP:EndIf ";" << WriteOpByte (ENDOP->getLine(), EFI_IFR_END_IF_OP); SetIfStart (0); >>
1404 ;
1405
1406 //
1407 // This is the form for a grayoutif nested in a suppressif statement
1408 //
1409 suppressIfGrayOutIf :
1410 << ResetFlags (); >>
1411 OPID:GrayOutIf << WriteOpByte (OPID->getLine(), EFI_IFR_GRAYOUT_IF_OP); >>
1412 {
1413 FF:Flags "=" flagsField ( "\|" flagsField )* ","
1414 }
1415 << WriteFlags (); >> // write the flags field
1416 vfrBooleanExpression
1417 ";"
1418 ;
1419
1420 //*****************************************************************************
1421 //
1422 // PARSE:
1423 // grayoutif { flags = n, } <boolean_expression> endif;
1424 // Note:
1425 // You can have: grayoutif:suppressif:statements:endif
1426 // grayoutif:statements:endif
1427 //
1428 //
1429 vfrStatementGrayOutIf :
1430 << ResetFlags (); >>
1431 OPID:GrayOutIf << WriteOpByte (OPID->getLine(), EFI_IFR_GRAYOUT_IF_OP); SetIfStart (OPID->getLine()); >>
1432 {
1433 FF:Flags "=" flagsField ( "\|" flagsField )* ","
1434 }
1435 << WriteFlags (); >> // write the flags field
1436 vfrBooleanExpression
1437 ";"
1438 { grayoutIfSuppressIf } ( suppressIfAndGrayoutIfSubstatements )+
1439 ENDOP:EndIf ";" << WriteOpByte (ENDOP->getLine(), EFI_IFR_END_IF_OP); SetIfStart (0); >>
1440 ;
1441
1442 //
1443 // This is the format for a suppressif nested in a grayoutif
1444 //
1445 grayoutIfSuppressIf :
1446 << ResetFlags (); >>
1447 OPID:SuppressIf << WriteOpByte (OPID->getLine(), EFI_IFR_SUPPRESS_IF_OP); >>
1448 {
1449 FF:Flags "=" flagsField ( "\|" flagsField )* ","
1450 }
1451 << WriteFlags (); >> // write the flags field
1452 vfrBooleanExpression
1453 ";"
1454 ;
1455
1456 //
1457 // These are the VFR statements that are valid inside a suppressif or grayoutif statement.
1458 //
1459 suppressIfAndGrayoutIfSubstatements :
1460 vfrStatementOneOf |
1461 vfrStatementTextText |
1462 vfrStatementCheckBox |
1463 vfrStatementNumeric |
1464 vfrStatementDate |
1465 vfrStatementTime |
1466 vfrStatementPassword |
1467 vfrStatementString |
1468 vfrStatementHidden |
1469 vfrStatementGoto |
1470 vfrStatementLabel |
1471 vfrStatementInventory |
1472 vfrStatementOrderedList |
1473 vfrStatementSaveRestoreDefaults
1474 ;
1475
1476 //*****************************************************************************
1477 //
1478 // PARSE:
1479 //
1480 // password varid = MyNvData.Password,
1481 // prompt = STRING_TOKEN(STR_PASSWORD_PROMPT),
1482 // help = STRING_TOKEN(STR_PASSWORD_HELP),
1483 // minsize = 6,
1484 // maxsize = 20,
1485 // encoding = 1,
1486 // endpassword;
1487
1488 vfrStatementPassword :
1489 << UINT32 KeyValue = 0; UINT32 LineNum; ResetFlags (); >>
1490 IDPW:Password << WriteOpByte (IDPW->getLine(), EFI_IFR_PASSWORD_OP); >>
1491 VarId "=" vfrStructFieldNameArray[0] ","
1492 Prompt "=" getStringId ","
1493 KH:Help "=" getStringId "," << LineNum = KH->getLine(); >>
1494 {
1495 FF:Flags "=" flagsField ( "\|" flagsField )* "," << LineNum = FF->getLine(); >>
1496 }
1497 {
1498 Key "=" KNUM:Number "," << LineNum = KNUM->getLine(); KeyValue = GetNumber(KNUM->getText(), LineNum, 2); >>
1499 }
1500 << WriteFlagsKey (KeyValue, LineNum); >>
1501 MinSize "=" MIN:Number "," << WriteByte (GetNumber (MIN->getText(), MIN->getLine(), 1), 0); >>
1502 MaxSize "=" MAX:Number "," << WriteByte (GetNumber (MAX->getText(), MAX->getLine(), 1), 0); >>
1503 Encoding "=" ENC:Number "," << WriteWord (GetNumber (ENC->getText(), ENC->getLine(), 2)); >>
1504 EndPassword ";"
1505 ;
1506
1507 //*****************************************************************************
1508 //
1509 // PARSE:
1510 //
1511 // string varid = MyNv.String,
1512 // prompt = STRING_TOKEN(STR_STRING_PROMPT),
1513 // help = STRING_TOKEN(STR_STRING_HELP),
1514 // flags = INTERACTIVE,
1515 // key = 0x1234,
1516 // minsize = 6,
1517 // maxsize = 0x14,
1518 // endstring;
1519 //
1520 // Since flags and key are optional, we can't use Flags->getLine(). Therefore for error
1521 // reporting we save the line number of the "help" keyword.
1522 //
1523 vfrStatementString :
1524 << unsigned int KeyValue = 0; UINT32 LineNum; ResetFlags (); >>
1525 IDS:String << WriteOpByte (IDS->getLine(), EFI_IFR_STRING_OP); >>
1526 VarId "=" vfrStructFieldNameArray[0] ","
1527 Prompt "=" getStringId ","
1528 KH:Help "=" getStringId "," << LineNum = KH->getLine(); >>
1529 {
1530 FF:Flags "="
1531 flagsField ( "\|" flagsField )* << LineNum = FF->getLine(); >>
1532 ","
1533 }
1534 {
1535 Key "=" KNUM:Number "," << LineNum = KNUM->getLine(); KeyValue = GetNumber(KNUM->getText(), LineNum, 2); >>
1536 }
1537 << WriteFlagsKey (KeyValue, LineNum); >>
1538 MinSize "=" MIN:Number "," << WriteByte (GetNumber (MIN->getText(), MIN->getLine(), 1), 0); >>
1539 MaxSize "=" MAX:Number "," << WriteByte (GetNumber (MAX->getText(), MAX->getLine(), 1), 0); >>
1540 EndString ";"
1541 ;
1542
1543 //*****************************************************************************
1544 //
1545 // PARSE:
1546 // numeric varid = MyIfrNVData.HowOldAreYouInYears,
1547 // prompt = STRING_TOKEN(STR_NUMERIC_PROMPT),
1548 // help = STRING_TOKEN(STR_NUMERIC_HELP),
1549 // flags = INTERACTIVE, // flags is optional
1550 // key = 0x1234, // key is optional if (flags & INTERACTIVE = 0)
1551 // minimum = 0x0,
1552 // maximum = 0xf0,
1553 // step = 1, // step is option, and step=1 if not specified
1554 // default = 0; // default is optional, and default=minimum if not specified
1555 // endnumeric;
1556 //
1557 // Make flags and key optional. However if flags includes INTERACTIVE, then a key is required.
1558 // That check is done in WriteFlagsKey() function.
1559 //
1560 vfrStatementNumeric :
1561 << UINT32 LineNum, KeyValue = 0; ResetFlags (); >>
1562 IDN:Numeric << WriteOpByte (IDN->getLine(), EFI_IFR_NUMERIC_OP); >>
1563 VarId "=" vfrStructFieldName[2] ","
1564 Prompt "=" getStringId ","
1565 KH:Help "=" getStringId "," << LineNum = KH->getLine(); >>
1566 {
1567 FF:Flags "=" flagsField ( "\|" flagsField )* "," << LineNum = FF->getLine (); >>
1568 }
1569 {
1570 Key "=" KNUM:Number "," << LineNum = KNUM->getLine(); KeyValue = GetNumber(KNUM->getText(), LineNum, 2); >>
1571 }
1572 << WriteFlagsKey (KeyValue, LineNum); >>
1573 minMaxStepDefault
1574 EndNumeric ";" << WriteMinMaxStepDefault (); >>
1575 ;
1576
1577 //
1578 // Parse minimum/maximum/step/default statements. Special cases:
1579 // - if step not specified, then the value is 1
1580 // - if default not specified, then the value is the min value specified
1581 // - if max < min, print a warning and swap the values (changes default too)
1582 //
1583 minMaxStepDefault :
1584 << InitMinMaxStepDefault (); >>
1585 Minimum "=" MIN:Number "," << SetMinMaxStepDefault (GetNumber (MIN->getText(), MIN->getLine(), 2), 0, MIN->getLine()); >>
1586 Maximum "=" MAX:Number "," << SetMinMaxStepDefault (GetNumber (MAX->getText(), MAX->getLine(), 2), 1, MAX->getLine()); >>
1587 { Step "=" STEP:Number "," << SetMinMaxStepDefault (GetNumber (STEP->getText(), STEP->getLine(), 2), 2, STEP->getLine()); >> }
1588 { Default "=" DEF:Number "," << SetMinMaxStepDefault (GetNumber (DEF->getText(), DEF->getLine(), 2), 3, DEF->getLine()); >> }
1589 ;
1590
1591
1592 //*****************************************************************************
1593 //
1594 // PARSE:
1595 //
1596 // date year varid = Date.Year, // "Date.Year" is a special case we recognize
1597 // prompt = STRING_TOKEN(STR_DATE_PROMPT),
1598 // help = STRING_TOKEN(STR_DATE_YEAR_HELP),
1599 // minimum = 1939,
1600 // maximum = 2101,
1601 // step = 1,
1602 // default = 1964,
1603 //
1604 // month varid = Date.Month,
1605 // prompt = STRING_TOKEN(STR_DATE_PROMPT),
1606 // help = STRING_TOKEN(STR_DATE_MONTH_HELP),
1607 // minimum = 1,
1608 // maximum = 12,
1609 // step = 1,
1610 // default = 1,
1611 //
1612 // day varid = Date.Day,
1613 // prompt = STRING_TOKEN(STR_DATE_PROMPT),
1614 // help = STRING_TOKEN(STR_DATE_DAY_HELP),
1615 // minimum = 1,
1616 // maximum = 31,
1617 // step = 0x1,
1618 // default = 1,
1619 //
1620 // enddate;
1621 //
1622 vfrStatementDate :
1623 Date
1624 IDY:Year VarId "=" << WriteOpByte (IDY->getLine(), EFI_IFR_DATE_OP); >>
1625 vfrStructFieldName[2] ","
1626 dateTimeSubStatement
1627 IDM:Month VarId "=" << WriteOpByte (IDM->getLine(), EFI_IFR_DATE_OP); >>
1628 vfrStructFieldName[2] ","
1629 dateTimeSubStatement
1630 IDD:Day VarId "=" << WriteOpByte (IDD->getLine(), EFI_IFR_DATE_OP); >>
1631 vfrStructFieldName[2] ","
1632 dateTimeSubStatement
1633 EndDate ";"
1634 ;
1635
1636 vfrStatementTime :
1637 Time
1638 IDH:Hour VarId "=" << WriteOpByte (IDH->getLine(), EFI_IFR_TIME_OP); >>
1639 vfrStructFieldName[2] ","
1640 dateTimeSubStatement
1641 IDM:Minute VarId "=" << WriteOpByte (IDM->getLine(), EFI_IFR_TIME_OP); >>
1642 vfrStructFieldName[2] ","
1643 dateTimeSubStatement
1644 IDS:Second VarId "=" << WriteOpByte (IDS->getLine(), EFI_IFR_TIME_OP); >>
1645 vfrStructFieldName[2] ","
1646 dateTimeSubStatement
1647 EndTime ";"
1648 ;
1649
1650 //*****************************************************************************
1651 //
1652 // PARSE:
1653 //
1654 // text text = STRING_ID;
1655 // text text = STRING_ID, text = STRING_ID;
1656 // text text = STRING_ID, text = STRING_ID, flags = x, key = y;
1657 //
1658 vfrStatementTextText :
1659 << ResetFlags (); >>
1660 IDT:Text << WriteOpByte (IDT->getLine(), EFI_IFR_TEXT_OP); >>
1661 Help "=" getStringId ","
1662 Text "="
1663 getStringId // writes string identifier
1664 { "," Text "=" getStringId
1665 "," Flags "=" flagsField ( "\|" flagsField )* << WriteFlags (); >>
1666 ","
1667 Key "=" KNUM:Number << WriteWord (GetNumber(KNUM->getText(), KNUM->getLine(), 2)); >>
1668 }
1669 ";"
1670 ;
1671
1672 //*****************************************************************************
1673 //
1674 // PARSE:
1675 //
1676 // inventory help = ID, text = ID;
1677 // inventory help = ID, text = id, text = ID;
1678 //
1679 vfrStatementInventory :
1680 IDI:Inventory << WriteOpByte (IDI->getLine(), EFI_IFR_INVENTORY_OP); >>
1681 Help "=" getStringId ","
1682 Text "=" getStringId // writes string identifier
1683 { "," Text "=" getStringId
1684 }
1685 ";"
1686 ;
1687
1688 //*****************************************************************************
1689 //
1690 // PARSE:
1691 //
1692 // restore defaults,
1693 // formid = 4,
1694 // prompt = STRING_TOKEN(STR_RESTORE_DEFAULTS_PROMPT),
1695 // help = STRING_TOKEN(STR_RESTORE_DEFAULTS_HELP),
1696 // flags = 0,
1697 // key = 0;
1698 //
1699 // save defaults,
1700 // formid = 4,
1701 // prompt = STRING_TOKEN(STR_SAVE_DEFAULTS_PROMPT),
1702 // help = STRING_TOKEN(STR_SAVE_DEFAULTS_HELP),
1703 // flags = 0,
1704 // key = 0;
1705 //
1706 vfrStatementSaveRestoreDefaults :
1707 << unsigned int KeyValue = 0; UINT32 LineNum; ResetFlags (); >>
1708 ( IDS:Save << WriteOpByte (IDS->getLine(), EFI_IFR_SAVE_DEFAULTS_OP); >>
1709 | IDR:Restore << WriteOpByte (IDR->getLine(), EFI_IFR_RESTORE_DEFAULTS_OP); >>
1710 )
1711 Defaults ","
1712 FormId "=" FRMID:Number "," << WriteWord (GetNumber (FRMID->getText(), FRMID->getLine(), 2));
1713 AddGotoReference (GetNumber (FRMID->getText(), FRMID->getLine(), 2), FRMID->getLine());
1714 >>
1715 Prompt "=" getStringId ","
1716 KH:Help "=" getStringId << LineNum = KH->getLine(); >>
1717 {
1718 "," FF:Flags "=" flagsField ( "\|" flagsField )* << LineNum = FF->getLine(); >>
1719 }
1720 {
1721 "," Key "=" KNUM:Number << LineNum = KNUM->getLine(); KeyValue = GetNumber(KNUM->getText(), LineNum, 2); >>
1722 }
1723 << WriteFlagsKey (KeyValue, LineNum); >>
1724 ";"
1725 ;
1726
1727 //*****************************************************************************
1728 //
1729 // PARSE:
1730 //
1731 // flags = 0x10 | DEFAULT | MANUFACTURING | INTERACTIVE | NV_ACCESS | RESET_REQUIRED | LATE_CHECK
1732 //
1733 //
1734 flagsField :
1735 VAL:Number << SetFlags (GetNumber(VAL->getText(), VAL->getLine(), 4), VAL->getLine()); >>
1736 | IF:InteractiveFlag << SetFlags (EFI_IFR_FLAG_INTERACTIVE, IF->getLine()); >>
1737 | MF:ManufacturingFlag << SetFlags (EFI_IFR_FLAG_MANUFACTURING, MF->getLine()); >>
1738 | DF:DefaultFlag << SetFlags (EFI_IFR_FLAG_DEFAULT, DF->getLine()); >>
1739 | NV:NVAccessFlag << SetFlags (EFI_IFR_FLAG_NV_ACCESS, NV->getLine()); >>
1740 | RR:ResetRequiredFlag << SetFlags (EFI_IFR_FLAG_RESET_REQUIRED, RR->getLine()); >>
1741 | LC:LateCheckFlag << SetFlags (EFI_IFR_FLAG_LATE_CHECK, LC->getLine()); >>
1742 ;
1743
1744 dateTimeSubStatement :
1745 Prompt "=" getStringId ","
1746 Help "=" getStringId ","
1747 << WriteByte (0, 0); WriteWord (0); >> // bogus flags and key
1748 minMaxStepDefault << WriteMinMaxStepDefault (); >>
1749 ;
1750
1751 vfrStatementCheckBox :
1752 << UINT32 LineNum, KeyValue = 0; ResetFlags (); >>
1753 IDCB:CheckBox << WriteOpByte (IDCB->getLine(), EFI_IFR_CHECKBOX_OP); >>
1754 VarId "=" vfrStructFieldName[1] ","
1755 Prompt "=" getStringId ","
1756 Help "=" getStringId ","
1757 FF:Flags "=" flagsField ( "\|" flagsField )* "," << LineNum = FF->getLine(); >>
1758 {
1759 Key "=" KV:Number "," << LineNum = KV->getLine(); KeyValue = GetNumber(KV->getText(), LineNum, 2); >>
1760 }
1761 << WriteFlagsKey (KeyValue, LineNum); >>
1762 EndCheckBox ";"
1763 ;
1764
1765 vfrStatementSubTitle :
1766 IDS:Subtitle Text "=" << WriteOpByte (IDS->getLine(), EFI_IFR_SUBTITLE_OP); >>
1767 getStringId // writes string indentifier
1768 ";"
1769 ;
1770
1771 //*****************************************************************************
1772 //
1773 // PARSE:
1774 // banner
1775 // title = STRING_TOKEN(STR_BANNER_TITLE),
1776 // line 1,
1777 // align center; // or left or right
1778 //
1779 // banner,
1780 // title = STRING_TOKEN(STR_BANNER_TITLE), timeout = 100;
1781 //
1782 vfrStatementBanner :
1783 IDB:Banner { "," } << WriteOpByte (IDB->getLine(), EFI_IFR_BANNER_OP); >>
1784 Title "=" getStringId ","
1785 (
1786 Line VAL:Number "," << WriteWord (GetNumber(VAL->getText(), VAL->getLine(), 2)); >>
1787 Align
1788 ( Left << WriteByte (EFI_IFR_BANNER_ALIGN_LEFT, 0); >>
1789 | Center << WriteByte (EFI_IFR_BANNER_ALIGN_CENTER, 0); >>
1790 | Right << WriteByte (EFI_IFR_BANNER_ALIGN_RIGHT, 0); >>
1791 ) ";"
1792 |
1793 Timeout "=" TO:Number ";" << WriteWord (GetNumber(TO->getText(), TO->getLine(), 2)); >>
1794 << WriteByte (EFI_IFR_BANNER_TIMEOUT, 0); >>
1795 )
1796 ;
1797
1798 //*****************************************************************************
1799 //
1800 // PARSE:
1801 // oneof varid = MyNv.OneOfData,
1802 // prompt = STRING_TOKEN(STR_ONE_OF_PROMPT),
1803 // help = STRING_TOKEN(STR_ONE_OF_HELP),
1804 // option text = STRING_TOKEN(STR_ONE_OF_TEXT),
1805 // value = 0,
1806 // flags = DEFAULT | INTERACTIVE;
1807 //
1808 // supressif/grayoutif are supported inside oneof stmt.
1809 // We do not restrict the number of oneOfOptionText to >=2, but >=1.
1810 // The situation that all oneOfOptionText are suppressed is also possiable.
1811 //
1812 vfrStatementOneOf :
1813 << ResetFlags (); >>
1814 IDOO:OneOf << WriteOpByte (IDOO->getLine(), EFI_IFR_ONE_OF_OP); >>
1815 VarId "=" vfrStructFieldName[2] ","
1816 Prompt "=" getStringId "," // writes string identifier
1817 Help "=" getStringId "," // writes string identifier
1818 ( oneOfOptionText )+ // there must be at least 1 option to be choosed, not 2.
1819 IDEOO:EndOneOf ";" << TestOneOfFlags (IDEOO->getLine()); WriteOpByte (IDEOO->getLine(), EFI_IFR_END_ONE_OF_OP); >>
1820 ;
1821
1822 //*****************************************************************************
1823 //
1824 // PARSE:
1825 //
1826 // orderedlist varid = MyNv.OrderedListData,
1827 // prompt = STRING_TOKEN(STR_ORDERED_LIST_PROMPT),
1828 // help = STRING_TOKEN(STR_ORDERED_LIST_HELP),
1829 // option text = STRING_TOKEN(STR_ORDERED_LIST_TEXT), value = 0, flags = INTERACTIVE;
1830 // -- additional option text --
1831 // endlist;
1832 //
1833 vfrStatementOrderedList :
1834 << ResetFlags (); InitOrderedList(); >>
1835 IDOL:OrderedList << WriteOpByte (IDOL->getLine(), EFI_IFR_ORDERED_LIST_OP); >>
1836 VarId "=" vfrStructFieldNameArray[1] ","
1837 Prompt "=" getStringId "," // writes string identifier
1838 Help "=" getStringId "," // writes string identifier
1839 orderedListOptionText ( orderedListOptionText )+
1840 IDEOL:EndList ";" << WriteOpByte (IDEOL->getLine(), EFI_IFR_END_OP); EndOrderedList(IDEOL->getLine()); >>
1841 ;
1842
1843 //*****************************************************************************
1844 //
1845 // PARSE:
1846 //
1847 // option text = STRING_TOKEN(STRING_ID), value = 0 flags = 99;
1848 //
1849 // Differs from the oneOfOptionText in that we don't allow the DEFAULT flag to
1850 // be set, and value cannot be 0.
1851 //
1852 orderedListOptionText :
1853 << UINT32 KeyValue = 0; >>
1854 IDO:Option << WriteOpByte (IDO->getLine(), EFI_IFR_ONE_OF_OPTION_OP); >>
1855 Text "=" getStringId "," // writes string identifier
1856 Value "=" WVAL:Number "," <<
1857 if (GetNumber(WVAL->getText(), WVAL->getLine(), 2) == 0) {
1858 PrintErrorMessage (WVAL->getLine(), "value=0 is invalid for ordered lists", NULL);
1859 } else {
1860 WriteWord (GetNumber(WVAL->getText(), WVAL->getLine(), 2));
1861 }
1862 >>
1863 FF:Flags "=" orderedListFlagsField
1864 ("\|" orderedListFlagsField )*
1865 {
1866 "," Key "=" KV:Number << KeyValue = GetNumber (KV->getText(), KV->getLine(), 2); >>
1867 }
1868 << WriteFlagsKey (KeyValue, FF->getLine()); >>
1869 ";" << mOptionCount++; >>
1870 ;
1871
1872 //*****************************************************************************
1873 //
1874 // PARSE:
1875 //
1876 // flags = 0x10 | DEFAULT | MANUFACTURING | INTERACTIVE | NV_ACCESS | RESET_REQUIRED | LATE_CHECK
1877 //
1878 // The ordered list flags field cannot have a default.
1879 //
1880 orderedListFlagsField :
1881 VAL:Number << SetFlags (GetNumber(VAL->getText(), VAL->getLine(), 4), VAL->getLine()); >>
1882 | IF:InteractiveFlag << SetFlags (EFI_IFR_FLAG_INTERACTIVE, IF->getLine()); >>
1883 | MF:ManufacturingFlag << SetFlags (EFI_IFR_FLAG_MANUFACTURING, MF->getLine()); >>
1884 | NV:NVAccessFlag << SetFlags (EFI_IFR_FLAG_NV_ACCESS, NV->getLine()); >>
1885 | RR:ResetRequiredFlag << SetFlags (EFI_IFR_FLAG_RESET_REQUIRED, RR->getLine()); >>
1886 | LC:LateCheckFlag << SetFlags (EFI_IFR_FLAG_LATE_CHECK, LC->getLine()); >>
1887 | DF:DefaultFlag << PrintWarningMessage (DF->getLine(), "DEFAULT flag not valid for ordered lists", NULL); >>
1888 ;
1889
1890 //
1891 // Parse references to VFR structure field names of form "MyNvStructure.Field".
1892 // This implementation is specific to strings, passwords, and references in an
1893 // ordered list statement because we want to specify the size of the entire
1894 // field, rather than just one element. Then call a function to write out its
1895 // offset and length.
1896 //
1897 vfrStructFieldNameArray[int FieldWidth] :
1898 << int ArrayIndex = 1; char IsArrayIndex = 0; >>
1899 SName:StringIdentifier
1900 "."
1901 SFieldName:StringIdentifier
1902 { OpenBracket AIndex:Number CloseBracket << ArrayIndex = GetNumber(AIndex->getText(), AIndex->getLine(), 4); IsArrayIndex = 1; >> }
1903 <<
1904 WriteFieldOffset (1,
1905 SName->getText(),
1906 SName->getLine(),
1907 SFieldName->getText(),
1908 SFieldName->getLine(),
1909 ArrayIndex,
1910 IsArrayIndex,
1911 FieldWidth,
1912 1
1913 );
1914 >>
1915 ;
1916
1917 //
1918 // Parse references to VFR structure field names of form "MyNvStructure.Field",
1919 // then call a function to write out its offset and length.
1920 //
1921 vfrStructFieldName[int FieldWidth] :
1922 << int ArrayIndex = 1; char IsArrayIndex = 0; >>
1923 SName:StringIdentifier
1924 "."
1925 SFieldName:StringIdentifier
1926 { OpenBracket AIndex:Number CloseBracket << ArrayIndex = GetNumber(AIndex->getText(), AIndex->getLine(), 4); IsArrayIndex = 1; >> }
1927 <<
1928 WriteFieldOffset (1,
1929 SName->getText(),
1930 SName->getLine(),
1931 SFieldName->getText(),
1932 SFieldName->getLine(),
1933 ArrayIndex,
1934 IsArrayIndex,
1935 FieldWidth,
1936 0
1937 );
1938 >>
1939 ;
1940
1941 //*****************************************************************************
1942 //
1943 // PARSE:
1944 //
1945 // MyNvStructure.FieldName[4]
1946 //
1947 // Parse references to VFR structure field names of form "MyNvStructure.Field",
1948 // then call a function to write out the offset with no length.
1949 //
1950 vfrStructFieldNameNL[int FieldWidth] :
1951 << int ArrayIndex = 1; char IsArrayIndex = 0; >>
1952 SName:StringIdentifier
1953 "."
1954 SFieldName:StringIdentifier
1955 { OpenBracket AIndex:Number CloseBracket << ArrayIndex = GetNumber(AIndex->getText(), AIndex->getLine(), 4); IsArrayIndex = 1; >> }
1956 <<
1957 WriteFieldOffset (0,
1958 SName->getText(),
1959 SName->getLine(),
1960 SFieldName->getText(),
1961 SFieldName->getLine(),
1962 ArrayIndex,
1963 IsArrayIndex,
1964 FieldWidth,
1965 0
1966 );
1967 >>
1968 ;
1969
1970 //*****************************************************************************
1971 //
1972 // PARSE:
1973 // suppressif TRUE OR FALSE;
1974 // grayoutif FALSE OR TRUE;
1975 // option text = STRING_TOKEN(STRING_ID), value = 0 flags = 99;
1976 // option text = STRING_TOKEN(STRING_ID2), value = 1 flags = 98;
1977 // endif;
1978 //
1979 oneOfOptionText :
1980 suppressIfOptionText |
1981 grayOutIfOptionText |
1982 commonOptionText
1983 ;
1984
1985 suppressIfOptionText :
1986 << ResetFlags (); >>
1987 OPID:SuppressIf << WriteOpByte (OPID->getLine(), EFI_IFR_SUPPRESS_IF_OP); SetIfStart (OPID->getLine()); >>
1988 {
1989 FF:Flags "=" flagsField ( "\|" flagsField )* ","
1990 }
1991 << WriteFlags (); >> // write the flags field
1992 vfrBooleanExpression
1993 ";"
1994 { suppressIfGrayOutIf } ( commonOptionText )+
1995 ENDOP:EndIf ";" << WriteOpByte (ENDOP->getLine(), EFI_IFR_END_IF_OP); SetIfStart (0); >>
1996 ;
1997
1998 grayOutIfOptionText :
1999 << ResetFlags (); >>
2000 OPID:GrayOutIf << WriteOpByte (OPID->getLine(), EFI_IFR_GRAYOUT_IF_OP); SetIfStart (OPID->getLine()); >>
2001 {
2002 FF:Flags "=" flagsField ( "\|" flagsField )* ","
2003 }
2004 << WriteFlags (); >> // write the flags field
2005 vfrBooleanExpression
2006 ";"
2007 { grayoutIfSuppressIf } ( commonOptionText )+
2008 ENDOP:EndIf ";" << WriteOpByte (ENDOP->getLine(), EFI_IFR_END_IF_OP); SetIfStart (0); >>
2009 ;
2010
2011 commonOptionText :
2012 << UINT32 KeyValue = 0; >>
2013 IDO:Option << WriteOpByte (IDO->getLine(), EFI_IFR_ONE_OF_OPTION_OP); >>
2014 Text "=" getStringId "," // writes string identifier
2015 Value "=" WVal:Number "," << WriteWord (GetNumber(WVal->getText(), WVal->getLine(), 2)); >>
2016 FF:Flags "=" flagsField ("\|" flagsField )*
2017 {
2018 "," Key "=" KV:Number << KeyValue = GetNumber (KV->getText(), KV->getLine(), 2); >>
2019 }
2020 << WriteFlagsKey (KeyValue, FF->getLine()); >>
2021 ";" << mOptionCount++; >>
2022 ;
2023
2024 //
2025 // Gets a string identifier. It must be a numeric value of form:
2026 //
2027 // STRING_TOKEN(100)
2028 //
2029 getStringId :
2030 << unsigned short StrId; >>
2031 StringToken OpenParen
2032 IdVal:Number << StrId = GetNumber (IdVal->getText(), IdVal->getLine(), 2); WriteStringIdWord (StrId); >>
2033 CloseParen
2034 ;
2035
2036 //******************************************************************************
2037 //
2038 // Parser class definition.
2039 //
2040 class EfiVfrParser {
2041 <<
2042 //
2043 // Parser definitions go here
2044 //
2045 private:
2046 STRUCT_DEFINITION *mFirstStructDefinition;
2047 STRUCT_DEFINITION *mLastStructDefinition;
2048 INT32 mNvDataStructSize;
2049 INT32 mNonNvDataStructSize;
2050 //
2051 // Flag to indicate that we're processing a ideqid VFR statement so that
2052 // we can do late checks on the statement.
2053 //
2054 INT32 mIdEqIdStmt;
2055 INT32 mLastNVVariableDataSize;
2056 GOTO_REFERENCE *mGotoReferences;
2057 FORM_ID_VALUE *mFormIdValues;
2058 VfrOpcodeHandler mOpcodeHandler;
2059 UINT16_LIST *mUint16List;
2060 UINT16_LIST *mLastUint16;
2061 UINT16_LIST *mDefinedLabels;
2062 UINT16_LIST *mDefinedVarStoreId;
2063 UINT16_LIST *mLastDefinedVarStoreId;
2064 UINT32 mMinimumValue, mMaximumValue, mStepValue, mDefaultValue;
2065 UINT32 mStmtFlags;
2066 UINT32 mSubStmtFlags;
2067 UINT32 mSubStmtFlagsLineNum;
2068 EFI_GUID mFormSetGuid;
2069 UINT8 mNvDataStructDefined;
2070 UINT16 mClass, mSubclass;
2071 UINT32 mIfStart;
2072 UINT32 mOptionCount; // how many "option" fields in a given statement
2073 UINT32 mLastVarIdSize;
2074 UINT8 mOutput;
2075 public:
2076
2077 VOID
2078 EfiVfrParser::SetIfStart (
2079 UINT32 LineNum
2080 )
2081 /*++
2082
2083 Routine Description:
2084 Invoked during VFR parsing when an "if" is encountered. Save the
2085 source line number so we can point to it if we don't find a
2086 corresponding endif later.
2087
2088 Arguments:
2089 LineNum - source line number where the "if" was parsed.
2090
2091 Returns:
2092 None
2093
2094 --*/
2095 {
2096 mIfStart = LineNum;
2097 }
2098 VOID
2099 EfiVfrParser::SetClass (
2100 UINT32 LineNum,
2101 UINT32 Value
2102 )
2103 /*++
2104
2105 Routine Description:
2106 Invoked during VFR parsing when a "class" statement is found. Check the
2107 range on the class value and save it for later.
2108
2109 Arguments:
2110 LineNum - source line number where the class statement was parsed.
2111 Value - the class value
2112
2113 Returns:
2114 None
2115
2116 --*/
2117 {
2118 if (Value & 0xFFFF0000) {
2119 PrintWarningMessage (LineNum, NULL, "class value exceeds maximum allowed");
2120 }
2121 mClass |= (UINT16)Value;
2122 }
2123 VOID
2124 EfiVfrParser::SetSubclass (
2125 UINT32 LineNum,
2126 UINT32 Value
2127 )
2128 /*++
2129
2130 Routine Description:
2131 Invoked during VFR parsing when a subclass statement is found. Check the
2132 range on the value and save it for later.
2133
2134 Arguments:
2135 LineNum - source line number where the class statement was parsed.
2136 Value - the subclass value from the VFR statement
2137
2138 Returns:
2139 None
2140
2141 --*/
2142 {
2143 if (Value & 0xFFFF0000) {
2144 PrintWarningMessage (LineNum, NULL, "subclass value exceeds maximum allowed");
2145 }
2146 mSubclass |= (UINT16)Value;
2147 }
2148 VOID EfiVfrParser::WriteClass ()
2149 {
2150 WriteWord (mClass);
2151 mClass = 0;
2152 }
2153 VOID EfiVfrParser::WriteSubclass ()
2154 {
2155 WriteWord (mSubclass);
2156 mSubclass = 0;
2157 }
2158 VOID EfiVfrParser::WriteIfrBytes ()
2159 {
2160 mOpcodeHandler.WriteIfrBytes ();
2161 }
2162 VOID
2163 EfiVfrParser::WriteFlagsKey (
2164 UINT32 KeyValue,
2165 UINT32 LineNum
2166 )
2167 /*++
2168
2169 Routine Description:
2170 Write out the flags and key values from the previous VFR statement.
2171 Many statements take a flags/key pair. If not specified, then 0
2172 values are written out. However do not allow an interactive flags field
2173 to be specified if no key value is specified. Also, if NV_ACCESS flag
2174 is set but INTERACTIVE is not, then set interactive and issue a warning.
2175
2176 Arguments:
2177 KeyValue - the key value from the VFR statement
2178 LineNum - source line number where the statement was parsed
2179
2180 Returns:
2181 None
2182
2183 --*/
2184 {
2185 if ((mSubStmtFlags & EFI_IFR_FLAG_INTERACTIVE) && (KeyValue == 0)) {
2186 PrintErrorMessage (LineNum, NULL, "invalid or missing key value - required with INTERACTIVE");
2187 }
2188 if ((mSubStmtFlags & EFI_IFR_FLAG_NV_ACCESS) && !(mSubStmtFlags & EFI_IFR_FLAG_INTERACTIVE)) {
2189 PrintWarningMessage (LineNum, NULL, "NV_ACCESS without INTERACTIVE has no effect -- setting INTERACTIVE");
2190 mSubStmtFlags |= EFI_IFR_FLAG_INTERACTIVE;
2191 }
2192 WriteFlags ();
2193 WriteWord (KeyValue);
2194 }
2195 VOID
2196 EfiVfrParser::InitOrderedList ()
2197 {
2198 mOptionCount = 0;
2199 }
2200 VOID
2201 EfiVfrParser::EndOrderedList (
2202 UINT32 LineNum
2203 )
2204 {
2205 if (mLastVarIdSize < mOptionCount) {
2206 PrintErrorMessage (LineNum, NULL, "number of options exceeds the variable store size");
2207 }
2208 }
2209 VOID
2210 EfiVfrParser::ResetFlags ()
2211 /*++
2212
2213 Routine Description:
2214
2215 Flags are set for each substatement in a given one-of statement.
2216 To make sure there are no conflicts, for example setting DEFAULT on
2217 more than one substatement, we keep track of the flags at a statement
2218 level and a substatement level. This function resets the flags so
2219 we get a fresh start.
2220
2221 Arguments:
2222 None
2223
2224 Returns:
2225 None
2226
2227 --*/
2228 {
2229 mStmtFlags = 0;
2230 mSubStmtFlagsLineNum = 0;
2231 mSubStmtFlags = 0;
2232 }
2233 //
2234 // Test validity of flags value for a one-of statement.
2235 //
2236 VOID
2237 EfiVfrParser::TestOneOfFlags (
2238 UINT32 LineNum
2239 )
2240 {
2241 //
2242 // One of the fields must have had the default bit set
2243 //
2244 if ((mStmtFlags & EFI_IFR_FLAG_DEFAULT) == 0) {
2245 PrintWarningMessage (LineNum, "default value must be specified", NULL);
2246 }
2247 }
2248 VOID
2249 EfiVfrParser::SetFlags (
2250 UINT32 Flags,
2251 UINT32 LineNum
2252 )
2253 {
2254 //
2255 // Check for redefinitions and invalid combinations
2256 //
2257 if (mStmtFlags & Flags & EFI_IFR_FLAG_MANUFACTURING) {
2258 PrintErrorMessage (LineNum, "MANUFACTURING", "a field with this flag already defined");
2259 }
2260 if (mStmtFlags & Flags & EFI_IFR_FLAG_DEFAULT) {
2261 PrintErrorMessage (LineNum, "DEFAULT", "a field with this flag already defined");
2262 }
2263 mSubStmtFlags |= Flags;
2264 mSubStmtFlagsLineNum = LineNum;
2265 }
2266 VOID
2267 EfiVfrParser::WriteFlags ()
2268 {
2269 //
2270 // Check value for validity
2271 //
2272 if (mSubStmtFlags & ~(EFI_IFR_FLAG_DEFAULT |
2273 EFI_IFR_FLAG_MANUFACTURING |
2274 EFI_IFR_FLAG_INTERACTIVE |
2275 EFI_IFR_FLAG_NV_ACCESS |
2276 EFI_IFR_FLAG_RESET_REQUIRED |
2277 EFI_IFR_FLAG_LATE_CHECK )) {
2278 PrintWarningMessage (mSubStmtFlagsLineNum, "invalid bits defined in flag", NULL);
2279 }
2280 WriteByte ((UINT8)mSubStmtFlags, 'F');
2281 //
2282 // We can now clear the substatement flags
2283 //
2284 mStmtFlags |= mSubStmtFlags;
2285 mSubStmtFlags = 0;
2286 }
2287 //
2288 // When we parse a min/max/step/default sequence, save off the values for
2289 // later use. Call this first to init the values.
2290 //
2291 VOID
2292 EfiVfrParser::InitMinMaxStepDefault ()
2293 {
2294 mMinimumValue = 0;
2295 mMaximumValue = 0;
2296 mStepValue = 1;
2297 mDefaultValue = 0;
2298 }
2299 VOID
2300 EfiVfrParser::WriteMinMaxStepDefault ()
2301 {
2302 WriteWord (mMinimumValue);
2303 WriteWord (mMaximumValue);
2304 WriteWord (mStepValue);
2305 WriteWord (mDefaultValue);
2306 }
2307 VOID
2308 EfiVfrParser::SetMinMaxStepDefault (
2309 UINT16 Value,
2310 INT32 MMSD,
2311 INT32 LineNum
2312 )
2313 {
2314 UINT16 TempValue;
2315 //
2316 // Min specified
2317 //
2318 if (MMSD == 0) {
2319 mMinimumValue = Value;
2320 mDefaultValue = Value;
2321 //
2322 // Max specified
2323 //
2324 } else if (MMSD == 1) {
2325 mMaximumValue = Value;
2326 //
2327 // If min > max, then swap the values. That includes resetting the default
2328 // value as well.
2329 //
2330 if (mMinimumValue > mMaximumValue) {
2331 PrintWarningMessage (LineNum, NULL, "maximum < minimum");
2332 TempValue = Value;
2333 mMaximumValue = mMinimumValue;
2334 mMinimumValue = TempValue;
2335 mDefaultValue = mMinimumValue;
2336 }
2337 //
2338 // Step specified
2339 //
2340 } else if (MMSD == 2) {
2341 mStepValue = Value;
2342 //
2343 // Default specified. Make sure min <= default <= max.
2344 //
2345 } else if (MMSD == 3) {
2346 mDefaultValue = Value;
2347 if (mMinimumValue > Value) {
2348 PrintErrorMessage (LineNum, NULL, "default value < minimum value");
2349 } else if (Value > mMaximumValue) {
2350 PrintErrorMessage (LineNum, NULL, "default value > maximum value");
2351 }
2352 } else {
2353 PrintErrorMessage (LineNum, "application error", "internal MMSD error");
2354 }
2355 }
2356 VOID
2357 EfiVfrParser::AddLabel (
2358 UINT32 LabelNumber,
2359 UINT32 LineNum
2360 )
2361 {
2362 UINT16_LIST *Label;
2363
2364 //
2365 // Added a label from the user VFR script. Make sure they haven't already
2366 // defined the same label elsewhere
2367 //
2368 for (Label = mDefinedLabels; Label != NULL; Label = Label->Next) {
2369 if (Label->Value == LabelNumber) {
2370 PrintErrorMessage (LineNum, NULL, "label already defined");
2371 PrintErrorMessage (Label->LineNum, NULL, "previous definition of redefined label");
2372 break;
2373 }
2374 }
2375 Label = (UINT16_LIST *)malloc (sizeof (UINT16_LIST));
2376 if (Label == NULL) {
2377 PrintErrorMessage (0, NULL, "memory allocation error");
2378 return;
2379 }
2380 memset ((char *)Label, 0, sizeof (UINT16_LIST));
2381 Label->Value = LabelNumber;
2382 Label->LineNum = LineNum;
2383 Label->Next = mDefinedLabels;
2384 mDefinedLabels = Label;
2385 }
2386 VOID
2387 EfiVfrParser::QueueIdEqValList (
2388 UINT16 Value
2389 )
2390 {
2391 UINT16_LIST *U16;
2392
2393 U16 = (UINT16_LIST *)malloc (sizeof (UINT16_LIST));
2394 if (U16 == NULL) {
2395 Error (PROGRAM_NAME, 0, 0, NULL, "memory allocation failed");
2396 } else {
2397 memset ((char *)U16, 0, sizeof (UINT16_LIST));
2398 U16->Value = Value;
2399 if (mUint16List == NULL) {
2400 mUint16List = U16;
2401 } else {
2402 mLastUint16->Next = U16;
2403 }
2404 mLastUint16 = U16;
2405 }
2406 }
2407 VOID
2408 EfiVfrParser::FlushQueueIdEqValList ()
2409 {
2410 UINT32 Count;
2411
2412 //
2413 // We queued up a list of IdEqValList items. The IFR requires a count
2414 // followed by the actual values. Do it.
2415 //
2416 Count = 0;
2417 mLastUint16 = mUint16List;
2418 while (mLastUint16 != NULL) {
2419 Count++;
2420 mLastUint16 = mLastUint16->Next;
2421 }
2422 // BUGBUG -- check for more than 16K items?
2423 WriteWord (Count);
2424 //
2425 // Now write the values.
2426 //
2427 mLastUint16 = mUint16List;
2428 while (mLastUint16 != NULL) {
2429 WriteWord ((UINT32)mLastUint16->Value);
2430 mLastUint16 = mLastUint16->Next;
2431 }
2432 //
2433 // Free up the list
2434 //
2435 mLastUint16 = mUint16List;
2436 while (mUint16List != NULL) {
2437 mLastUint16 = mUint16List->Next;
2438 free (mUint16List);
2439 mUint16List = mLastUint16;
2440 }
2441 }
2442 VOID
2443 EfiVfrParser::PrintErrorMessage (
2444 UINT32 LineNum,
2445 CHAR8 *Msg1,
2446 CHAR8 *Msg2
2447 )
2448 {
2449 char *FileName;
2450
2451 if (LineNum != 0) {
2452 FileName = ConvertLineNumber ((UINT32 *)&LineNum);
2453 Error (FileName, LineNum, 0, Msg1, Msg2);
2454 } else {
2455 Error (PROGRAM_NAME, 0, 0, Msg1, Msg2);
2456 }
2457 }
2458 VOID
2459 EfiVfrParser::PrintWarningMessage (
2460 UINT32 LineNum,
2461 CHAR8 *Msg1,
2462 CHAR8 *Msg2
2463 )
2464 {
2465 char *FileName;
2466
2467 if (LineNum != 0) {
2468 FileName = ConvertLineNumber ((UINT32 *)&LineNum);
2469 Warning (FileName, LineNum, 0, Msg1, Msg2);
2470 } else {
2471 Warning (PROGRAM_NAME, 0, 0, Msg1, Msg2);
2472 }
2473 }
2474 VOID
2475 EfiVfrParser::syn (
2476 ANTLRAbstractToken *Tok,
2477 ANTLRChar *Egroup,
2478 SetWordType *Eset,
2479 ANTLRTokenType ETok,
2480 INT32 Huh
2481 )
2482 /*++
2483
2484 Routine Description:
2485 Called by the parser base class as a result of parse syntax errors.
2486
2487 Arguments:
2488 Tok - token that caused the error
2489 Egroup - not sure
2490 Eset - index in token table of the expected token
2491 Huh - not sure
2492
2493 Returns:
2494 NA
2495
2496 --*/
2497 {
2498 char *FileName;
2499 UINT32 LineNum;
2500
2501 LineNum = Tok->getLine ();
2502 FileName = ConvertLineNumber ((UINT32 *)&LineNum);
2503 //
2504 // Sometimes the token number is 0, in which case I don't know what to
2505 // print.
2506 //
2507 if (ETok == 0) {
2508 Error (FileName, LineNum, 0, Tok->getText (), "unexpected token");
2509 } else {
2510 //
2511 // If we were expecting an endif, then report the line where the corresponding
2512 // IF began.
2513 //
2514 if ((strcmp (_token_tbl[ETok], "endif") == 0) && (mIfStart != 0)) {
2515 LineNum = mIfStart;
2516 FileName = ConvertLineNumber (&LineNum);
2517 Error (FileName, LineNum, 0, "statement missing corresponding endif", NULL);
2518 } else {
2519 Error (FileName, LineNum, 0, Tok->getText (), "expected %s", _token_tbl[ETok]);
2520 }
2521 }
2522 }
2523
2524 VOID
2525 EfiVfrParser::init()
2526 /*++
2527
2528 Routine Description:
2529 Initializations function for our parser.
2530
2531 Arguments:
2532 None.
2533
2534 Returns:
2535 None.
2536
2537 --*/
2538 {
2539 ANTLRParser::init();
2540
2541 //
2542 // Used for queuing a variable list of UINT16's
2543 //
2544 mUint16List = NULL;
2545 mLastUint16 = NULL;
2546 mFirstStructDefinition = NULL;
2547 mLastStructDefinition = NULL;
2548 mNvDataStructSize = 0;
2549 mNonNvDataStructSize = 0;
2550 mNvDataStructDefined = 0;
2551 mGotoReferences = NULL;
2552 mFormIdValues = NULL;
2553 mDefinedLabels = NULL;
2554 mClass = 0;
2555 mSubclass = 0;
2556 mIfStart = 0;
2557 mDefinedVarStoreId = NULL;
2558 mLastDefinedVarStoreId = NULL;
2559 mIdEqIdStmt = 0;
2560 mLastNVVariableDataSize = 0;
2561
2562 memset ((char *)&mFormSetGuid, 0, sizeof (EFI_GUID));
2563 }
2564 //
2565 // Destructor for the parser.
2566 //
2567 EfiVfrParser::~EfiVfrParser(VOID)
2568 {
2569 Cleanup();
2570 }
2571 VOID
2572 EfiVfrParser::Cleanup (VOID)
2573 /*++
2574
2575 Routine Description:
2576 Free memory allocated during parsing
2577
2578 Arguments:
2579 None.
2580
2581 Returns:
2582 None.
2583
2584 --*/
2585 {
2586 STRUCT_DEFINITION *NextStruct;
2587 STRUCT_FIELD_DEFINITION *NextField;
2588 UINT8 Buff[6];
2589 UINT16_LIST *NextU16List;
2590
2591 //
2592 // Free up the structure definitions if any
2593 //
2594 while (mFirstStructDefinition != NULL) {
2595 //
2596 // Free up all the fields for this struct
2597 //
2598 while (mFirstStructDefinition->Field != NULL) {
2599 NextField = mFirstStructDefinition->Field->Next;
2600 free (mFirstStructDefinition->Field->Name);
2601 free (mFirstStructDefinition->Field);
2602 mFirstStructDefinition->Field = NextField;
2603 }
2604 NextStruct = mFirstStructDefinition->Next;
2605 free (mFirstStructDefinition->Name);
2606 free (mFirstStructDefinition);
2607 mFirstStructDefinition = NextStruct;
2608 }
2609 //
2610 // Free up the goto references and form id defines
2611 //
2612 FreeGotoReferences ();
2613 //
2614 // Free up label list
2615 //
2616 while (mDefinedLabels != NULL) {
2617 NextU16List = mDefinedLabels->Next;
2618 delete (mDefinedLabels);
2619 mDefinedLabels = NextU16List;
2620 }
2621 //
2622 // Free up the list of defined variable storage IDs
2623 //
2624 while (mDefinedVarStoreId != NULL) {
2625 NextU16List = mDefinedVarStoreId->Next;
2626 delete (mDefinedVarStoreId);
2627 mDefinedVarStoreId = NextU16List;
2628 }
2629 }
2630
2631 INT32
2632 EfiVfrParser::AtoX (
2633 CHAR8 *HexString,
2634 INT32 NumBytes,
2635 UINT32 *HexValue
2636 )
2637 /*++
2638
2639 Routine Description:
2640 Given a pointer to a ascii hex string, convert to a number with the given
2641 number of bytes.
2642
2643 Arguments:
2644 HexString - pointer to a string of format 30BCA
2645 Size - number of bytes to convert
2646 HexValue - return result
2647
2648 Returns:
2649 The number of bytes converted.
2650
2651 --*/
2652 {
2653 INT32 Count;
2654 INT32 Value;
2655
2656 *HexValue = 0;
2657 Count = 0;
2658 while (Count < NumBytes) {
2659 if ((*HexString >= '0') && (*HexString <= '9')) {
2660 Value = *HexString - '0';
2661 } else if ((*HexString >= 'a') && (*HexString <= 'f')) {
2662 Value = *HexString - 'a' + 10;
2663 } else if ((*HexString >= 'A') && (*HexString <= 'F')) {
2664 Value = *HexString - 'A' + 10;
2665 } else {
2666 return Count;
2667 }
2668 HexString++;
2669 *HexValue = (*HexValue << 4) | Value;
2670 if ((*HexString >= '0') && (*HexString <= '9')) {
2671 Value = *HexString - '0';
2672 } else if ((*HexString >= 'a') && (*HexString <= 'f')) {
2673 Value = *HexString - 'a' + 10;
2674 } else if ((*HexString >= 'A') && (*HexString <= 'F')) {
2675 Value = *HexString - 'A' + 10;
2676 } else {
2677 return Count;
2678 }
2679 *HexValue = (*HexValue << 4) | Value;
2680 HexString++;
2681 Count++;
2682 }
2683 return Count;
2684 }
2685 VOID
2686 EfiVfrParser::WriteGuidValue (
2687 UINT32 TokenLineNum,
2688 CHAR8 *G1,
2689 CHAR8 *G2,
2690 CHAR8 *G3,
2691 CHAR8 *G4,
2692 CHAR8 *G5,
2693 CHAR8 *G6,
2694 CHAR8 *G7,
2695 CHAR8 *G8,
2696 CHAR8 *G9,
2697 CHAR8 *G10,
2698 CHAR8 *G11
2699 )
2700 /*++
2701
2702 Routine Description:
2703 A Guid was parsed, likely of format:
2704 #define MY_GUID { 0x12345678, 0xAABB, 0xCCDD, 0xEE, 0xFF, 0x11, 0x22, 0x33, 0x44, 0x55, 0x66 }
2705
2706 Write out the value.
2707
2708 Arguments:
2709 TokenLineNum - line number where the guid was used
2710 G1-G11 - the 11 fields of the guid value
2711
2712 Returns:
2713 None.
2714
2715 --*/
2716 {
2717 UINT32 Value;
2718 INT32 Loop;
2719
2720 mFormSetGuid.Data1 = GetNumber (G1, TokenLineNum, 4);
2721 mFormSetGuid.Data2 = (UINT16)GetNumber (G2, TokenLineNum, 2);
2722 mFormSetGuid.Data3 = (UINT16)GetNumber (G3, TokenLineNum, 2);
2723 mFormSetGuid.Data4[0] = (UINT8)GetNumber (G4, TokenLineNum, 1);
2724 mFormSetGuid.Data4[1] = (UINT8)GetNumber (G5, TokenLineNum, 1);
2725 mFormSetGuid.Data4[2] = (UINT8)GetNumber (G6, TokenLineNum, 1);
2726 mFormSetGuid.Data4[3] = (UINT8)GetNumber (G7, TokenLineNum, 1);
2727 mFormSetGuid.Data4[4] = (UINT8)GetNumber (G8, TokenLineNum, 1);
2728 mFormSetGuid.Data4[5] = (UINT8)GetNumber (G9, TokenLineNum, 1);
2729 mFormSetGuid.Data4[6] = (UINT8)GetNumber (G10, TokenLineNum, 1);
2730 mFormSetGuid.Data4[7] = (UINT8)GetNumber (G11, TokenLineNum, 1);
2731
2732 WriteDWord (mFormSetGuid.Data1, 'G');
2733 WriteWord (mFormSetGuid.Data2);
2734 WriteWord (mFormSetGuid.Data3);
2735 WriteByte (mFormSetGuid.Data4[0], 0);
2736 WriteByte (mFormSetGuid.Data4[1], 0);
2737 WriteByte (mFormSetGuid.Data4[2], 0);
2738 WriteByte (mFormSetGuid.Data4[3], 0);
2739 WriteByte (mFormSetGuid.Data4[4], 0);
2740 WriteByte (mFormSetGuid.Data4[5], 0);
2741 WriteByte (mFormSetGuid.Data4[6], 0);
2742 WriteByte (mFormSetGuid.Data4[7], 0);
2743 }
2744 VOID
2745 EfiVfrParser::WriteFieldOffset (
2746 INT8 WriteLength,
2747 CHAR8 *StructName,
2748 INT32 LineNum1,
2749 CHAR8 *FieldName,
2750 INT32 LineNum2,
2751 INT32 ArrayIndex,
2752 INT8 IsArrayIndex,
2753 INT32 FieldWidth,
2754 INT8 WriteArraySize
2755 )
2756 /*++
2757
2758 Routine Description:
2759 A VFR script referenced the NV store structure. Given the structure's name
2760 and the field's name, write the offset of the field to the output file.
2761
2762 Arguments:
2763 WriteLength - write the field length byte out
2764 StructName - name of the NV store structure
2765 LineNum1 - line number in the VFR where we are (for error printing)
2766 FieldName - the name of the field within the NV store structure
2767 LineNum2 - line number in the VFR where FieldName is referenced
2768 ArrayIndex - the index specified, for example NV_DATA.Field[ArrayIndex]
2769 IsArrayIndex - non-zero if an array index was specified
2770 FieldWidth - expected size for the Field (1 byte? 2 bytes?)
2771 WriteArraySize - write the size of the entire field, not the size of a single element
2772
2773 Returns:
2774 None.
2775
2776 --*/
2777 {
2778 STRUCT_DEFINITION *StructDef;
2779 STRUCT_FIELD_DEFINITION *FieldDef;
2780 UINT32 Offset;
2781 UINT32 VarSize;
2782 CHAR8 Msg[100];
2783 //
2784 // If we're writing an array size, then they better have referenced the field without an
2785 // index.
2786 //
2787 if (WriteArraySize && IsArrayIndex) {
2788 sprintf (Msg, "array index specified where an array is required");
2789 PrintErrorMessage (LineNum2, FieldName, Msg);
2790 return;
2791 }
2792 //
2793 // Look through our list of known structures for a match
2794 //
2795 for (StructDef = mFirstStructDefinition; StructDef != NULL; StructDef = StructDef->Next) {
2796 //
2797 // Check for matching structure name
2798 //
2799 if (strcmp (StructDef->Name, StructName) == 0) {
2800 //
2801 // Mark it as referenced (for debug purposes only). Check the
2802 // flag that indicates that we have already found a varstore VFR
2803 // statement for it.
2804 //
2805 StructDef->Referenced++;
2806 if (StructDef->VarStoreIdValid == 0) {
2807 //
2808 // Set it valid so we don't flag it multiple times, then emit the error
2809 //
2810 StructDef->VarStoreIdValid = 1;
2811 PrintErrorMessage (LineNum1, StructName, "varstore statement missing for this variable store");
2812 }
2813 //
2814 // Let the opcode-handler know which variable storage we're now using
2815 //
2816 if (mIdEqIdStmt) {
2817 mOpcodeHandler.SetSecondaryVarStoreId (StructDef->VarStoreId);
2818 } else {
2819 mOpcodeHandler.SetVarStoreId (StructDef->VarStoreId);
2820 }
2821 //
2822 // Found matching structure name. Now find the matching field name
2823 //
2824 for (FieldDef = StructDef->Field; FieldDef != NULL; FieldDef = FieldDef->Next) {
2825 if (strcmp (FieldDef->Name, FieldName) == 0) {
2826 //
2827 // Make sure the variable size is valid
2828 //
2829 if ((FieldWidth != 0) && (FieldDef->DataSize > FieldWidth)) {
2830 sprintf (Msg, "field width exceeds %d byte%c", FieldWidth, FieldWidth == 1 ? ' ' : 's');
2831 PrintErrorMessage (LineNum2, FieldName, Msg);
2832 }
2833 //
2834 // If they specified an index (MyVfrData.FieldX[10]), then make sure that the
2835 // data structure was declared as an array, and that the index is in bounds.
2836 // If they did not specify an index, then we'll assume 0. This is required for
2837 // strings.
2838 //
2839 if (IsArrayIndex) {
2840 VarSize = FieldDef->DataSize;
2841 if (FieldDef->IsArray == 0) {
2842 PrintErrorMessage (LineNum2, FieldName, "field is not declared as an array");
2843 return;
2844 }
2845 if (FieldDef->ArrayLength < ArrayIndex) {
2846 PrintErrorMessage (LineNum2, FieldName, "array index exceeds declared size of field");
2847 return;
2848 }
2849 } else {
2850 if (FieldDef->IsArray) {
2851 VarSize = FieldDef->DataSize * FieldDef->ArrayLength;
2852 } else {
2853 VarSize = FieldDef->DataSize;
2854 }
2855 }
2856 //
2857 // If we're in the middle of a ideqid VFR statement, then this is the second
2858 // variable ID that we're now processing. Make sure that its size is the same
2859 // as the first variable.
2860 //
2861 if (mIdEqIdStmt) {
2862 if (mLastVarIdSize != VarSize) {
2863 PrintErrorMessage (LineNum2, FieldName, "variables must have the same size");
2864 return;
2865 }
2866 }
2867 mLastVarIdSize = VarSize;
2868 //
2869 // If we're supposed to write an array size, then require it to be an array
2870 //
2871 if (WriteArraySize && !FieldDef->IsArray) {
2872 PrintErrorMessage (LineNum2, FieldName, "array required");
2873 return;
2874 }
2875 //
2876 // Write the variable offset and size. If we're in the non-NV structure, then
2877 // set the offset beyond the NV data structure size.
2878 //
2879 Offset = FieldDef->Offset + FieldDef->DataSize * (ArrayIndex - 1);
2880 if (StructDef->IsNonNV) Offset += mNvDataStructSize;
2881 WriteWord (Offset);
2882 if (WriteLength) {
2883 if (WriteArraySize) {
2884 if (FieldDef->DataSize * FieldDef->ArrayLength > 255) {
2885 PrintErrorMessage (LineNum2, FieldName, "array size exceeds 255 maximum encoding limit");
2886 return;
2887 }
2888 WriteByte (FieldDef->DataSize * FieldDef->ArrayLength, 0);
2889 } else {
2890 WriteByte (FieldDef->DataSize, 0);
2891 }
2892 }
2893 return;
2894 }
2895 }
2896 sprintf (Msg, "structure %s does not have a field named '%s'", StructName, FieldName);
2897 PrintErrorMessage (LineNum2, Msg, NULL);
2898 PrintErrorMessage (StructDef->LineNum, "see structure definition", NULL);
2899 return;
2900 }
2901 }
2902 //
2903 // The structure was not found in the defined list. See if it's the "Date" structure
2904 //
2905 if (strcmp (StructName, "Date") == 0) {
2906 //
2907 // BUGBUG -- remove support for Date and Time as valid structure
2908 // names. They should use the NON_NV_DATA_MAP structure for this.
2909 //
2910 // Someone specified Date.Years|Months|Days
2911 // BUGBUG -- define some constants for the IDs used here
2912 // Length == 0 implies that this is not user NV data storage.
2913 //
2914 if (strcmp (FieldName, "Year") == 0) {
2915 //
2916 // Write ID (offset), ID, and size
2917 //
2918 WriteWord (mNvDataStructSize + mNonNvDataStructSize + 0);
2919 if (WriteLength) {
2920 WriteByte (0, 0);
2921 }
2922 } else if (strcmp (FieldName, "Month") == 0) {
2923 //
2924 // Write ID (offset), ID, and size
2925 //
2926 WriteWord (mNvDataStructSize + mNonNvDataStructSize + 2);
2927 if (WriteLength) {
2928 WriteByte (0, 0);
2929 }
2930 } else if (strcmp (FieldName, "Day") == 0) {
2931 //
2932 // Write ID (offset), ID, and size
2933 //
2934 WriteWord (mNvDataStructSize + mNonNvDataStructSize + 4);
2935 if (WriteLength) {
2936 WriteByte (0, 0);
2937 }
2938 } else {
2939 PrintErrorMessage (LineNum1, FieldName, "expected valid field name TheYear/TheMonth/TheDay");
2940 }
2941 return;
2942 } else if (strcmp (StructName, "Time") == 0) {
2943 //
2944 // Someone specified Time.Hours|Minutes|Seconds
2945 // BUGBUG -- define some constants for the IDs used here
2946 //
2947 if (strcmp (FieldName, "Hours") == 0) {
2948 //
2949 // Write ID (offset), ID, and size
2950 //
2951 WriteWord (mNvDataStructSize + mNonNvDataStructSize + 6);
2952 if (WriteLength) {
2953 WriteByte (0, 0);
2954 }
2955 } else if (strcmp (FieldName, "Minutes") == 0) {
2956 //
2957 // Write ID (offset), ID, and size
2958 //
2959 WriteWord (mNvDataStructSize + mNonNvDataStructSize + 8);
2960 if (WriteLength) {
2961 WriteByte (0, 0);
2962 }
2963 } else if (strcmp (FieldName, "Seconds") == 0) {
2964 //
2965 // Write ID (offset), ID, and size
2966 //
2967 WriteWord (mNvDataStructSize + mNonNvDataStructSize + 10);
2968 if (WriteLength) {
2969 WriteByte (0, 0);
2970 }
2971 } else {
2972 PrintErrorMessage (LineNum1, FieldName, "expected valid field name Hours/Minutes/Seconds");
2973 }
2974 return;
2975 } else {
2976 PrintErrorMessage (LineNum1, StructName, "undefined structure");
2977 return;
2978 }
2979 }
2980 VOID
2981 EfiVfrParser::StartStructDefinition (
2982 INT32 IsNonNV,
2983 INT32 LineNum
2984 )
2985 /*++
2986
2987 Routine Description:
2988 Called when we encounter a new "struct _MY_STRUCT..." statement while parsing.
2989 Initialize internal data and structures for parsing the fields of the structure.
2990
2991 Arguments:
2992 LineNum - line number in the source file (for error reporting purposes)
2993 IsNonNv - flag indicating (if nonzero) that the variable referred to is not in
2994 the standard NV store.
2995 Returns:
2996 None
2997
2998 --*/
2999 {
3000 STRUCT_DEFINITION *StructDef;
3001 //
3002 // Allocate memory for the structure record
3003 //
3004 StructDef = (STRUCT_DEFINITION *)malloc (sizeof (STRUCT_DEFINITION));
3005 memset (StructDef, 0, sizeof (STRUCT_DEFINITION));
3006 StructDef->LineNum = LineNum;
3007 //
3008 // Set flag indicating non-NV data structure or not
3009 //
3010 StructDef->IsNonNV = IsNonNV;
3011 //
3012 // Add it to the end of our linked list. If it's the first one
3013 // defined, then it's the default varstore ID, so set it valid.
3014 //
3015 if (mFirstStructDefinition == NULL) {
3016 mFirstStructDefinition = StructDef;
3017 StructDef->VarStoreIdValid = 1;
3018 } else {
3019 mLastStructDefinition->Next = StructDef;
3020 }
3021 mLastStructDefinition = StructDef;
3022 }
3023 VOID
3024 EfiVfrParser::EndStructDefinition (
3025 CHAR8 *StructName,
3026 INT32 LineNum
3027 )
3028 {
3029 STRUCT_DEFINITION *StructDef;
3030 STRUCT_FIELD_DEFINITION *FieldDef;
3031 UINT32 Offset;
3032 //
3033 // Make sure they have not already defined a structure with this name
3034 //
3035 for (StructDef = mFirstStructDefinition; StructDef != NULL; StructDef = StructDef->Next) {
3036 if ((StructDef->Name != NULL) && (strcmp (StructDef->Name, StructName) == 0)) {
3037 PrintErrorMessage (LineNum, StructName, "structure with this name already defined");
3038 //
3039 // Fall through and fill in the rest of the structure information. We do
3040 // this because the structure has already been added to our global list,
3041 // so will be used elsewhere, so we want it to contain valid fields.
3042 //
3043 }
3044 }
3045 //
3046 // Allocate memory for the structure name
3047 //
3048 mLastStructDefinition->Name = (char *)malloc (strlen (StructName) + 1);
3049 strcpy (mLastStructDefinition->Name, StructName);
3050 //
3051 // Compute the structure size, and the offsets to each field
3052 //
3053 Offset = 0;
3054 for (FieldDef = mLastStructDefinition->Field; FieldDef != NULL; FieldDef = FieldDef->Next) {
3055 FieldDef->Offset = Offset;
3056 Offset += FieldDef->ArrayLength * FieldDef->DataSize;
3057 }
3058 mLastStructDefinition->Size = Offset;
3059 //
3060 // Go through all the structure we have so far and figure out (if we can)
3061 // the size of the non-NV storage. We also assume that the first structure
3062 // definition is the primary/default storage for the VFR form.
3063 //
3064 if (mNonNvDataStructSize == 0) {
3065 for (StructDef = mFirstStructDefinition; StructDef != NULL; StructDef = StructDef->Next) {
3066 if (StructDef->IsNonNV) {
3067 mNonNvDataStructSize = StructDef->Size;
3068 break;
3069 }
3070 }
3071 }
3072 if (mNvDataStructSize == 0) {
3073 for (StructDef = mFirstStructDefinition; StructDef != NULL; StructDef = StructDef->Next) {
3074 if (StructDef->IsNonNV == 0) {
3075 mNvDataStructSize = StructDef->Size;
3076 break;
3077 }
3078 }
3079 }
3080 }
3081 VOID
3082 EfiVfrParser::AddStructField (
3083 CHAR8 *FieldName,
3084 INT32 LineNum,
3085 INT32 DataSize,
3086 INT32 ArrayLength,
3087 INT8 IsArray
3088 )
3089 /*++
3090
3091 Routine Description:
3092 We're parsing the VFR structure definition. Add another defined field to
3093 our definition.
3094
3095 Arguments:
3096 FieldName - name of the field in the structure.
3097 LineNum - the line number from the input (preprocessor output) file
3098 DataSize - the size of the field (1, 2, or 4 bytes)
3099 ArrayLength - the number of elements (for array)
3100 IsArray - non-zero if the field is an array
3101
3102 Returns:
3103 None.
3104
3105 --*/
3106 {
3107 STRUCT_FIELD_DEFINITION *FieldDef;
3108 STRUCT_FIELD_DEFINITION *Temp;
3109 //
3110 // Make sure we don't already have a field of this name in our structure
3111 //
3112 for (FieldDef = mLastStructDefinition->Field; FieldDef != NULL; FieldDef = FieldDef->Next) {
3113 if (strcmp (FieldDef->Name, FieldName) == 0) {
3114 PrintErrorMessage (LineNum, FieldName, "field with this name already defined");
3115 return;
3116 }
3117 }
3118 //
3119 // If it's an array, then they better not have a size of 0. For example:
3120 // UINT8 MyBytes[0];
3121 //
3122 if (IsArray && (ArrayLength <= 0)) {
3123 PrintErrorMessage (LineNum, FieldName, "invalid array size");
3124 return;
3125 }
3126 //
3127 // Allocate memory for a new structure field definition
3128 //
3129 FieldDef = (STRUCT_FIELD_DEFINITION *)malloc (sizeof (STRUCT_FIELD_DEFINITION));
3130 memset ((char *)FieldDef, 0, sizeof (STRUCT_FIELD_DEFINITION));
3131 FieldDef->ArrayLength = ArrayLength;
3132 FieldDef->DataSize = DataSize;
3133 FieldDef->IsArray = IsArray;
3134 FieldDef->Name = (char *)malloc (strlen (FieldName) + 1);
3135 strcpy (FieldDef->Name, FieldName);
3136 //
3137 // Add it to the end of the field list for the currently active structure
3138 //
3139 if (mLastStructDefinition->Field == NULL) {
3140 mLastStructDefinition->Field = FieldDef;
3141 } else {
3142 mLastStructDefinition->LastField->Next = FieldDef;
3143 }
3144 mLastStructDefinition->LastField = FieldDef;
3145 }
3146 VOID
3147 EfiVfrParser::AddVarStore (
3148 CHAR8 *StructName, // actual name of the structure
3149 CHAR8 *VarName, // actual NV variable name
3150 UINT16 VarStoreId, // key value
3151 INT32 LineNum // parse line number (for error reporting)
3152 )
3153 /*++
3154
3155 Routine Description:
3156 Called while parsing a varstore statement. Add the variable store
3157 to our linked list.
3158
3159 Arguments:
3160 StructName - the name of the typedef'ed structure to use
3161 VarName - the NV variable name as specified in the varstore statement
3162 VarStoreId - the variable store ID as specified in the varstore statememt
3163 LineNum - the line number from the input (preprocessor output) file
3164
3165 Returns:
3166 None.
3167
3168 --*/
3169 {
3170 STRUCT_DEFINITION *StructDef;
3171 UINT16_LIST *L16Ptr;
3172 //
3173 // Go through our list of previously-defined variable store IDs and
3174 // make sure this one is not a duplicate in name or key value.
3175 //
3176 for (L16Ptr = mDefinedVarStoreId; L16Ptr != NULL; L16Ptr = L16Ptr->Next) {
3177 if (L16Ptr->Value == VarStoreId) {
3178 PrintErrorMessage (LineNum, "variable storage key already used", NULL);
3179 PrintErrorMessage (L16Ptr->LineNum, "previous usage of storage key", NULL);
3180 }
3181 }
3182 //
3183 // Key value of 0 is invalid since that's assigned by default to the default
3184 // variable store (the first structure parsed).
3185 //
3186 if (VarStoreId == 0) {
3187 PrintErrorMessage (LineNum, "variable storage key of 0 is invalid", NULL);
3188 }
3189 //
3190 // Create a new element to add to the list
3191 //
3192 L16Ptr = (UINT16_LIST *)malloc(sizeof (UINT16_LIST));
3193 memset (L16Ptr, 0, sizeof (UINT16_LIST));
3194 L16Ptr->LineNum = LineNum;
3195 L16Ptr->Value = VarStoreId;
3196 if (mDefinedVarStoreId == NULL) {
3197 mDefinedVarStoreId = L16Ptr;
3198 } else {
3199 mLastDefinedVarStoreId->Next = L16Ptr;
3200 }
3201 mLastDefinedVarStoreId = L16Ptr;
3202 //
3203 // Find the structure definition with this name
3204 //
3205 for (StructDef = mFirstStructDefinition; StructDef != NULL; StructDef = StructDef->Next) {
3206 if (strcmp (StructDef->Name, StructName) == 0) {
3207 //
3208 // Make sure they did not already define a variable storage ID
3209 // for this structure.
3210 //
3211 if (StructDef->VarStoreId != 0) {
3212 PrintErrorMessage (LineNum, StructName, "variable storage already defined for this structure");
3213 PrintErrorMessage (StructDef->VarStoreLineNum, StructName, "previous definition for variable storage");
3214 }
3215 StructDef->VarStoreId = VarStoreId;
3216 StructDef->VarStoreIdValid = 1;
3217 StructDef->VarStoreLineNum = LineNum;
3218 WriteWord (StructDef->Size);
3219 while (*VarName) {
3220 WriteByte(*VarName, 0);
3221 VarName++;
3222 }
3223 WriteByte(0,0);
3224 return;
3225 }
3226 }
3227 PrintErrorMessage (LineNum, StructName, "structure with this name not defined");
3228 }
3229 VOID
3230 EfiVfrParser::WriteDWord (
3231 UINT32 Value,
3232 UINT8 KeyByte
3233 )
3234 /*++
3235
3236 Routine Description:
3237 During parsing, we came upon some code that requires a 32-bit value be
3238 written to the VFR binary file. Queue up the 4 bytes.
3239
3240 Arguments:
3241 Value - the 32-bit value to write
3242 KeyByte - a single character which gets written out beside the first byte.
3243 This is used to tag the data in the output file so that during
3244 debug you have an idea what the value is.
3245
3246 Returns:
3247 None.
3248
3249 --*/
3250 {
3251 //
3252 // Write 4 bytes, little endian. Specify a key byte only on the first one
3253 //
3254 mOpcodeHandler.AddByte ((UINT8)Value, KeyByte);
3255 Value \>>= 8;
3256 mOpcodeHandler.AddByte ((UINT8)Value, 0);
3257 Value \>>= 8;
3258 mOpcodeHandler.AddByte ((UINT8)Value, 0);
3259 Value \>>= 8;
3260 mOpcodeHandler.AddByte ((UINT8)Value, 0);
3261 }
3262 VOID
3263 EfiVfrParser::WriteOpByte (
3264 UINT32 LineNum,
3265 UINT8 ByteValue
3266 )
3267 /*++
3268
3269 Routine Description:
3270
3271 During parsing, we came upon a new VFR opcode. At this point we flush
3272 the output queue and then queue up this byte (with 'O' for opcode tag).
3273
3274 Arguments:
3275
3276 ByteValue - opcode value
3277
3278 Returns:
3279
3280 None.
3281
3282 --*/
3283 {
3284 mOpcodeHandler.AddOpcodeByte (ByteValue, LineNum);
3285 }
3286 VOID
3287 EfiVfrParser::WriteByte (
3288 UINT8 ByteValue,
3289 UINT8 Key
3290 )
3291 /*++
3292
3293 Routine Description:
3294
3295 During parsing of the VFR we spoonfeed this function with bytes to write to
3296 the output VFR binary file. This function simply queues up the bytes, and
3297 the queue gets flushed each time a new VFR opcode is encountered.
3298
3299 Arguments:
3300
3301 ByteValue - raw byte to write
3302 Key - character to tag the byte with when we write ByteValue to the
3303 output file.
3304
3305 Returns:
3306
3307 None.
3308
3309 --*/
3310 {
3311 mOpcodeHandler.AddByte (ByteValue, Key);
3312 }
3313 VOID
3314 EfiVfrParser::WriteWord (
3315 UINT32 Value
3316 )
3317 /*++
3318
3319 Routine Description:
3320 During VFR parsing we came upon a case where we need to write out a
3321 16-bit value. Queue it up.
3322
3323 Arguments:
3324 Value - value to write.
3325
3326 Returns:
3327 None.
3328
3329 --*/
3330 {
3331 mOpcodeHandler.AddByte ((UINT8)Value, 0);
3332 mOpcodeHandler.AddByte ((UINT8)((Value \>> 8) & 0xFF), 0);
3333 }
3334 VOID
3335 EfiVfrParser::WriteStringIdWord (
3336 UINT16 WordValue
3337 )
3338 {
3339 mOpcodeHandler.AddByte ((UINT8)WordValue, 'S');
3340 mOpcodeHandler.AddByte ((UINT8)((WordValue \>> 8) & 0xFF), 0);
3341 }
3342 VOID
3343 EfiVfrParser::FreeGotoReferences ()
3344 /*++
3345
3346 Routine Description:
3347 Called during cleanup to free up the memory we allocated when
3348 keeping track of VFR goto statements.
3349
3350 Arguments:
3351 None
3352
3353 Returns:
3354 None
3355
3356 --*/
3357 {
3358 GOTO_REFERENCE *CurrRef;
3359 GOTO_REFERENCE *NextRef;
3360 FORM_ID_VALUE *CurrFormId;
3361 FORM_ID_VALUE *NextFormId;
3362 UINT8 Found;
3363 CHAR8 Name[20];
3364
3365 //
3366 // Go through all the "goto" references and make sure there was a
3367 // form ID of that value defined.
3368 //
3369 for (CurrRef = mGotoReferences; CurrRef != NULL; CurrRef = CurrRef->Next) {
3370 Found = 0;
3371 for (CurrFormId = mFormIdValues; CurrFormId != NULL; CurrFormId = CurrFormId->Next) {
3372 if (CurrRef->Value == CurrFormId->Value) {
3373 Found = 1;
3374 break;
3375 }
3376 }
3377 if (!Found) {
3378 sprintf (Name, "%d", (UINT32)CurrRef->Value);
3379 PrintErrorMessage (CurrRef->RefLineNum, Name, "undefined form ID");
3380 }
3381 }
3382 //
3383 // Now free up the form id and goto references
3384 //
3385 CurrFormId = mFormIdValues;
3386 while (CurrFormId != NULL) {
3387 NextFormId = CurrFormId->Next;
3388 free (CurrFormId);
3389 CurrFormId = NextFormId;
3390 }
3391 mFormIdValues = NULL;
3392 CurrRef = mGotoReferences;
3393 while (CurrRef != NULL) {
3394 NextRef = CurrRef->Next;
3395 free (CurrRef);
3396 CurrRef = NextRef;
3397 }
3398 mGotoReferences = NULL;
3399 }
3400 VOID
3401 EfiVfrParser::AddGotoReference (
3402 UINT32 GotoNumber,
3403 UINT32 LineNum
3404 )
3405 /*++
3406
3407 Routine Description:
3408 During VFR parsing we came upon a goto statement. Since we support
3409 forward references, save the referenced label and at the end of parsing
3410 we'll check that the label was actually defined somewhere.
3411
3412 Arguments:
3413 GotoNumber - the label number referenced
3414 LineNum - the line number where the reference was made (used for
3415 error reporting)
3416
3417 Returns:
3418 None
3419
3420 --*/
3421 {
3422 GOTO_REFERENCE *NewRef;
3423
3424 NewRef = (GOTO_REFERENCE *)malloc (sizeof (GOTO_REFERENCE));
3425 if (NewRef == NULL) {
3426 Error (PROGRAM_NAME, 0, 0, NULL, "memory allocation failure");
3427 return;
3428 }
3429 memset ((char *)NewRef, 0, sizeof (GOTO_REFERENCE));
3430 NewRef->Value = (UINT16)GotoNumber;
3431 NewRef->RefLineNum = LineNum;
3432 NewRef->Next = mGotoReferences;
3433 mGotoReferences = NewRef;
3434 }
3435 VOID
3436 EfiVfrParser::AddFormId (
3437 INT32 FormIdValue,
3438 UINT32 LineNum
3439 )
3440 /*++
3441
3442 Routine Description:
3443 This function is called when we parse "form formid = 3" statements.
3444 We save the form ID valud so we can verify that duplicates are not
3445 defined. Also, these are the targets of goto statements, so when we're
3446 done parsing the script we also go through all the goto statements to
3447 check that there was a target FormId defined as referenced by each
3448 goto statement.
3449
3450 Note that formid = 0 is invalid.
3451
3452 Arguments:
3453 FormIdValue - the parsed value for the Form ID
3454 LineNum - line number of the source file we're parsing
3455
3456 Returns:
3457 NA
3458
3459 --*/
3460 {
3461 FORM_ID_VALUE *NewFormId;
3462 char *FileName;
3463 char *FileName2;
3464 UINT32 LineNum2;
3465 //
3466 // Verify that FormId != 0
3467 //
3468 if (FormIdValue == 0) {
3469 FileName = ConvertLineNumber (&LineNum);
3470 Error (FileName, LineNum, 0, "form ID cannot be 0", NULL);
3471 return;
3472 }
3473 //
3474 // First go through all previously defined form IDs and make sure they have not defined
3475 // duplicates.
3476 //
3477 for (NewFormId = mFormIdValues; NewFormId != NULL; NewFormId = NewFormId->Next) {
3478 if ((UINT16)FormIdValue == NewFormId->Value) {
3479 FileName = ConvertLineNumber (&LineNum);
3480 LineNum2 = NewFormId->LineNum;
3481 FileName2 = ConvertLineNumber (&LineNum2);
3482 Error (FileName, LineNum, 0, NULL, "form ID %d already defined", FormIdValue);
3483 Error (FileName2, LineNum2, 0, NULL, "form ID %d previous definition", FormIdValue);
3484 return;
3485 }
3486 }
3487 //
3488 // Allocate memory for a new one
3489 //
3490 NewFormId = (FORM_ID_VALUE *)malloc (sizeof (FORM_ID_VALUE));
3491 if (NewFormId == NULL) {
3492 Error (PROGRAM_NAME, 0, 0, NULL, "memory allocation failure");
3493 return;
3494 }
3495 memset ((char *)NewFormId, 0, sizeof (FORM_ID_VALUE));
3496 NewFormId->LineNum = LineNum;
3497 NewFormId->Next = mFormIdValues;
3498 NewFormId->Value = (UINT16)FormIdValue;
3499 mFormIdValues = NewFormId;
3500 }
3501 UINT32
3502 EfiVfrParser::GetNumber (
3503 CHAR8 *NumStr,
3504 UINT32 LineNum,
3505 UINT32 NumBytes
3506 )
3507 {
3508 UINT32 Value;
3509
3510 if ((NumStr[0] == '0') && (NumStr[1] == 'x')) {
3511 AtoX (NumStr + 2, 4, &Value);
3512 } else {
3513 Value = (UINT32)atoi (NumStr);
3514 }
3515 //
3516 // Check range
3517 //
3518 if ((NumBytes < 4) && (Value & ((UINT32)0xFFFFFFFF << (NumBytes * 8)))) {
3519 PrintErrorMessage (LineNum, NumStr, "value out of range");
3520 return 0;
3521 }
3522 return Value;
3523 }
3524
3525 >>
3526
3527 } // end grammar class
3528