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