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
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.
18 PCCTS parser and lexer definitions for the EFI VFR forms compiler
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>
30 #include "CommonLib.h"
31 #include "EfiUtilityMsgs.h"
33 #include "VfrServices.h"
38 #include <process.h> // for spawn functions
48 // Base info for DLG-generated scanner
50 #include "DLexerBase.h"
53 // Include the scanner file generated by DLG
57 class DLGLexerVfr : public DLGLexer
60 DLGLexerVfr (DLGFileInput *F) : DLGLexer (F) {};
61 INT32 errstd (char *Text)
63 printf ("unrecognized input '%s'\n", Text);
69 // Base token definitions for ANTLR
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.
80 #define PREPROCESSOR_COMMAND "gcc "
81 #define PREPROCESSOR_OPTIONS "-x c -E -P -DVFRCOMPILE "
82 #define FILE_SEP_CHAR '/'
83 #define FILE_SEP_STRING "/"
85 #define PREPROCESSOR_COMMAND "cl.exe "
86 #define PREPROCESSOR_OPTIONS "/nologo /P /TC /DVFRCOMPILE "
87 #define FILE_SEP_CHAR '/'
88 #define FILE_SEP_STRING "/"
91 typedef ANTLRCommonToken ANTLRToken;
94 // Specify the filename extensions for the files we generate.
96 #define VFR_BINARY_FILENAME_EXTENSION ".c"
97 #define VFR_LIST_FILENAME_EXTENSION ".lst"
127 Application entry point function. Parse command-line arguments,
128 invoke the parser, clean up, and return.
131 argc - standard argc passed to main() per C conventions
132 argv - standard argv passed to main() per C conventions
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
148 // Set our program name for the error printing routines.
149 // Then set printing limits.
151 SetUtilityName (PROGRAM_NAME);
152 SetPrintLimits (20, 20, 30);
154 // Process the command-line arguments
156 if (ProcessArgs (argc, argv) != STATUS_SUCCESS) {
163 // Verify the VFR script file exists
165 if ((VfrFptr = fopen (gOptions.VfrFileName, "r")) == NULL) {
166 Error (PROGRAM_NAME, 0, 0, gOptions.VfrFileName, "could not open input VFR file");
171 // Now close the file and make a system call to run the preprocessor
175 // Len = strlen (PREPROCESSOR_OPTIONS) + strlen (gOptions.VfrFileName) + 10;
176 // if (gOptions.CPreprocessorOptions != NULL) {
177 // Len += strlen (gOptions.CPreprocessorOptions) + 1;
179 // if (gOptions.IncludePaths != NULL) {
180 // Len += strlen (gOptions.IncludePaths) + 1;
182 // Cmd = (char *)malloc (Len);
183 // if (Cmd == NULL) {
184 // Error (PROGRAM_NAME, 0, 0, NULL, "could not allocate memory");
186 // return STATUS_ERROR;
188 // strcpy (Cmd, PREPROCESSOR_OPTIONS);
189 // if (gOptions.IncludePaths != NULL) {
190 // strcat (Cmd, gOptions.IncludePaths);
191 // strcat (Cmd, " ");
193 // if (gOptions.CPreprocessorOptions != NULL) {
194 // strcat (Cmd, gOptions.CPreprocessorOptions);
195 // strcat (Cmd, " ");
197 // strcat (Cmd, gOptions.VfrFileName);
199 // Status = _spawnlp (_P_WAIT, PREPROCESSOR_COMMAND, Cmd, NULL);
202 // char CommandLine[1000];
206 // // Lean the slashes forward.
208 // for (p = gOptions.PreprocessorOutputFileName; *p; p++) {
215 // // Lean the slashes forward.
217 // for (p = Cmd; *p; p++) {
223 // sprintf(CommandLine, "%s %s > %s", PREPROCESSOR_COMMAND, Cmd, gOptions.PreprocessorOutputFileName);
224 // Status = system (CommandLine);
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);
231 // return STATUS_ERROR;
235 // Open the preprocessor output file
237 if ((VfrFptr = fopen (gOptions.VfrFileName, "r")) == NULL) {
238 Error (PROGRAM_NAME, 0, 0, "failed to open input VFR preprocessor output file",
239 gOptions.PreprocessorOutputFileName);
244 // Define input VFR file
246 DLGFileInput InputFile (VfrFptr);
248 // Define an instance of the scanner
250 DLGLexerVfr Scanner (&InputFile);
252 // Define token buffer between scanner and parser
254 ANTLRTokenBuffer Pipe (&Scanner);
256 // Create a token to use as a model
260 // Tell the scanner what type the token is
262 Scanner.setToken (&Tok);
264 // Create an instance of our parser
266 EfiVfrParser Parser (&Pipe);
268 // Initialize the parser
271 Status = GetUtilityStatus ();
272 if (Status != STATUS_SUCCESS) {
277 // Start the first rule
281 // Close the input script file
284 Parser.WriteIfrBytes ();
286 // Call cleanup, which does some extra checking of the script
291 // If we had an error somewhere, delete our output files so that
292 // a subsequent build will rebuild them.
294 Status = GetUtilityStatus ();
295 if (Status == STATUS_ERROR) {
296 remove (gOptions.IfrOutputFileName);
306 Free up memory allocated during parsing.
317 // Free up our string we allocated to track the include paths
319 if (gOptions.IncludePaths != NULL) {
320 free (gOptions.IncludePaths);
321 gOptions.IncludePaths = NULL;
324 // Free up our string we allocated to track preprocessor options
326 if (gOptions.CPreprocessorOptions != NULL) {
327 free (gOptions.CPreprocessorOptions);
328 gOptions.CPreprocessorOptions = NULL;
341 Process the command-line arguments.
344 Argc - standard argc passed to main()
345 Argv - standard argv passed to main()
348 STATUS_SUCCESS - program should continue (all args ok)
353 char *CPreprocessorOptions;
355 char CopyStr[MAX_PATH];
359 // Put options in known state.
361 memset ((char *)&gOptions, 0, sizeof (OPTIONS));
363 // Go through all the arguments that start with '-'
367 while ((Argc > 0) && (Argv[0][0] == '-')) {
369 // -? or -h help option -- return an error for printing usage
371 if ((stricmp (Argv[0], "-?") == 0) || (stricmp (Argv[0], "-h") == 0)) {
375 // -l to create a listing output file
377 } else if (stricmp (Argv[0], "-l") == 0) {
378 gOptions.CreateListFile = 1;
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.
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");
390 Len = strlen (" -I ");
391 Len += strlen (Argv[0]) + 2;
392 if (gOptions.IncludePaths != NULL) {
393 Len += strlen (gOptions.IncludePaths);
395 IncludePaths = (CHAR8 *)malloc (Len);
396 if (IncludePaths == NULL) {
397 Error (PROGRAM_NAME, 0, 0, NULL, "memory allocation failure");
401 if (gOptions.IncludePaths != NULL) {
402 strcpy (IncludePaths, gOptions.IncludePaths);
403 free (gOptions.IncludePaths);
405 strcat (IncludePaths, " -I ");
406 strcat (IncludePaths, Argv[0]);
407 gOptions.IncludePaths = IncludePaths;
409 // -od OutputDirectory to define a common directory for output files
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");
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) {
424 // -ppflag C-preprocessor-flag option for passing options to the C preprocessor.
425 // Turn them all into a single string.
427 } else if (stricmp (Argv[0], "-ppflag") == 0) {
429 Error (PROGRAM_NAME, 0, 0, Argv[0], "missing C-preprocessor argument");
434 Len = strlen (Argv[0]) + 2;
435 if (gOptions.CPreprocessorOptions != NULL) {
436 Len += strlen (gOptions.CPreprocessorOptions);
438 CPreprocessorOptions = (CHAR8 *)malloc (Len);
439 if (CPreprocessorOptions == NULL) {
440 Error (PROGRAM_NAME, 0, 0, NULL, "memory allocation failure");
443 CPreprocessorOptions[0] = 0;
444 if (gOptions.CPreprocessorOptions != NULL) {
445 strcpy (CPreprocessorOptions, gOptions.CPreprocessorOptions);
446 free (gOptions.CPreprocessorOptions);
448 strcat (CPreprocessorOptions, " ");
449 strcat (CPreprocessorOptions, Argv[0]);
450 gOptions.CPreprocessorOptions = CPreprocessorOptions;
452 Error (PROGRAM_NAME, 0, 0, Argv[0], "unrecognized option");
459 // Must specify at least the vfr file name
462 Error (PROGRAM_NAME, 0, 0, Argv[1], "unrecognized argument after VFR file name");
464 } else if (Argc < 1) {
465 Error (PROGRAM_NAME, 0, 0, NULL, "must specify VFR file name");
468 strcpy (gOptions.VfrFileName, Argv[0]);
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.
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);
483 strcpy (gOptions.PreprocessorOutputFileName, Cptr+1);
484 strcpy (gOptions.VfrBaseFileName, Cptr+1);
486 for (Cptr = gOptions.PreprocessorOutputFileName; *Cptr && (*Cptr != '.'); Cptr++);
489 // Terminate the vfr file basename at the extension
491 for (Cptr = gOptions.VfrBaseFileName; *Cptr && (*Cptr != '.'); Cptr++) {
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
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.
509 if (gOptions.OutputDirectory[0] == 0) {
512 _getcwd (CopyStr, sizeof (CopyStr));
514 getcwd (CopyStr, sizeof (CopyStr));
516 strcpy (gOptions.OutputDirectory, CopyStr);
519 // Make sure output directory has a trailing backslash
521 if (gOptions.OutputDirectory[strlen (gOptions.OutputDirectory) - 1] != '\\' ||
522 gOptions.OutputDirectory[strlen (gOptions.OutputDirectory) - 1] != '/') {
523 strcat (gOptions.OutputDirectory, FILE_SEP_STRING);
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.
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);
535 // We set a default list file name, so if they do not
536 // want a list file, null out the name now.
538 if (gOptions.CreateListFile == 0) {
539 gOptions.VfrListFileName[0] = 0;
541 return STATUS_SUCCESS;
549 Print utility usage instructions
560 const char *Help[] = {
562 "VfrCompile version " VFR_COMPILER_VERSION,
564 " Usage: VfrCompile {options} [VfrFile]",
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",
577 for (Index = 0; Help[Index] != NULL; Index++) {
578 fprintf (stdout, "%s\n", Help[Index]);
590 PARSER_LINE_DEFINITION *gLineDefinition = NULL;
591 PARSER_LINE_DEFINITION *gLastLineDefinition = NULL;
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
609 TokenString - the parsed string as shown above
610 TokenLine - the line number in the preprocessed output file
617 PARSER_LINE_DEFINITION *LineDef;
621 // Allocate a structure in which we can keep track of this line information.
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);
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.
632 for (Cptr = TokenString + 7; *Cptr && (*Cptr != '"'); Cptr++);
634 LineDef->FileName = (CHAR8 *)malloc (strlen (Cptr));
636 strcpy (LineDef->FileName, Cptr);
637 for (Cptr = LineDef->FileName; *Cptr && (*Cptr != '"'); Cptr++);
640 // Now add this new one to the list
642 if (gLineDefinition == NULL) {
643 gLineDefinition = LineDef;
645 gLastLineDefinition->Next = LineDef;
647 gLastLineDefinition = LineDef;
649 Error (PROGRAM_NAME, 0, 0, "invalid line definition in preprocessor output file", TokenString);
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.
666 LineNum - the line number in the preprocessor-output file.
669 Returns a pointer to the source file name. Also returns the line number
670 in the provided LineNum argument
674 PARSER_LINE_DEFINITION *LineDef;
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.
682 for (LineDef = gLineDefinition; LineDef != NULL; LineDef = LineDef->Next) {
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.
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;
696 // Last one in the list of line definitions, so has to be right
698 *LineNum = *LineNum - LineDef->TokenLineNum + LineDef->HashLineNum;
699 return LineDef->FileName;
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.
713 #lexclass QUOTED_STRING
714 #token TheString "~[\"]*\"" << mode (START); >>
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.
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); >>
729 // Define a lexclass for skipping over C++ style comments
731 #lexclass CPP_COMMENT
732 #token "~[\n]*" << skip (); >>
733 #token "\n" << skip (); mode (START); newline (); >>
736 // Standard lexclass is START
741 // Find start of C++ style comments
743 #token "//" << skip (); mode (CPP_COMMENT); >>
748 #token "[\ \t]" << skip (); >>
751 // Skip over newlines, but count them
753 #token "\n" << skip (); newline (); >>
756 // Skip pragma pack statements
758 #token "\#pragma" << skip (); mode(PRAGMA_PACK); >>
761 // Skip over 'extern' in any included .H file
763 #token "extern" << skip (); >>
766 // Tokens for the different keywords. Syntax is:
767 // TokenName("ErrorMessageText") "TokenString"
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
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"
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("<=") "<="
875 // Define the class and subclass tokens
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"
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"
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("]") "\]"
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
905 #token InvalidCharacters("invalid characters") "~[;:=,\.\|]"
908 // This is the overall definition of a VFR form definition script.
911 ( dataStructDefinition )*
913 ( vfrStatementVarStore )*
915 EFS:EndFormSet ";" << WriteOpByte (EFS->getLine(), EFI_IFR_END_FORM_SET_OP); >>
920 FS:FormSet << WriteOpByte (FS->getLine(), EFI_IFR_FORM_SET_OP); >>
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 ()
942 Title "=" getStringId ","
943 Help "=" getStringId ","
945 // insert padding for an EFI_PHYSICAL_ADDRESS (UINT64)
947 << WriteDWord (0, 0); WriteDWord (0, 0); >>
948 Class "=" CVAL:classDefinition "," << WriteClass (); >>
949 Subclass "=" SVAL:subclassDefinition "," << WriteSubclass (); >>
950 << WriteWord (mNvDataStructSize); >>
954 // A form can be of multiple classes, thus allow CLASS_A | CLASS_B | CLASS_C
957 validClassNames ( "\|" 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"); >>
972 // A form can only be of one subclass type.
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"); >>
983 // Parse a C type data structure for storing VFR setup data. Allow:
984 // typedef struct _XXX_ {
988 dataStructDefinition :
989 << int IsNonNV = 0; >>
993 NonNvDataMap << IsNonNV = 1; >>
996 ) << StartStructDefinition (IsNonNV, S->getLine()); >>
999 CloseBrace NAME:StringIdentifier << EndStructDefinition (NAME->getText(), NAME->getLine()); >>
1004 // Parse a C type data structure for defining data that is not stored in NV.
1005 // typedef struct _NON_NV_DATA_MAP {
1007 // } NON_NV_DATA_MAP;
1009 nonNvDataStructDefinition :
1012 { StringIdentifier }
1015 CloseBrace NAME:StringIdentifier << AddStructField (NAME->getText(), NAME->getLine(), 0, 0, 0); >>
1020 ( dataStructField64 | dataStructField32 | dataStructField16 | dataStructField8 ) *
1023 //*****************************************************************************
1029 // Used while parsing the NV data map structures.
1032 << int ArrayLength = 1; char IsArray = 0; >>
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); >>
1039 //*****************************************************************************
1045 // Used while parsing the NV data map structures.
1048 << int ArrayLength = 1; char IsArray = 0; >>
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); >>
1055 //*****************************************************************************
1061 // Used while parsing the NV data map structures.
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); >>
1071 //*****************************************************************************
1077 // Used while parsing the NV data map structures.
1080 << int ArrayLength = 1; char IsArray = 0; >>
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); >>
1087 //*****************************************************************************
1091 // title = STRING_TOKEN(STR_FORM_TITLE);
1092 // -- form statements --
1095 // The Form ID cannot be 0
1098 FRM:Form FormId << WriteOpByte (FRM->getLine(), EFI_IFR_FORM_OP); >>
1100 VAL:Number << WriteWord (GetNumber (VAL->getText(), VAL->getLine(), 2)); AddFormId (GetNumber (VAL->getText(), VAL->getLine(), 2), VAL->getLine()); >>
1102 Title "=" getStringId ";" // writes string identifier
1104 ENDF:EndForm ";" << WriteOpByte (ENDF->getLine(), EFI_IFR_END_FORM_OP); >>
1108 // VFR statements in a formset
1111 vfrStatementSubTitle |
1113 vfrStatementTextText |
1114 vfrStatementCheckBox |
1115 vfrStatementNumeric |
1118 vfrStatementPassword |
1119 vfrStatementString |
1120 vfrStatementSuppressIf |
1121 vfrStatementHidden |
1123 vfrStatementGrayOutIf |
1124 vfrStatementInconsistentIf |
1126 vfrStatementBanner |
1127 vfrStatementInventory |
1128 vfrStatementOrderedList |
1130 vfrStatementSaveRestoreDefaults
1133 //*****************************************************************************
1139 OPID:Label << WriteOpByte (OPID->getLine(), EFI_IFR_LABEL_OP); >>
1141 WriteWord (GetNumber (VAL->getText(), VAL->getLine(), 2));
1142 AddLabel (GetNumber (VAL->getText(), VAL->getLine(), 2), VAL->getLine());
1147 //*****************************************************************************
1150 // oem 0x12, 0x34, 0x56;
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); >> )*
1159 //*****************************************************************************
1162 // inconsistentif NOT .... AND NOT .... OR ... endif;
1164 vfrStatementInconsistentIf :
1165 << ResetFlags (); >>
1166 IIFOP:InconsistentIf << WriteOpByte (IIFOP->getLine(), EFI_IFR_INCONSISTENT_IF_OP); >>
1167 Prompt "=" getStringId ","
1169 FF:Flags "=" flagsField ( "\|" flagsField )* ","
1171 << WriteFlags (); >> // write the flags field
1172 vfrBooleanExpression
1173 EOP:EndIf ";" << WriteOpByte (EOP->getLine(), EFI_IFR_END_IF_OP); >>
1176 //*****************************************************************************
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)
1184 // For supporting complex express, divide the vfrBooleanExpression to two parts
1185 // so that pred-LL(k) parser can parse incrementally.
1187 vfrBooleanExpression :
1188 leftPartVfrBooleanExp { rightPartVfrBooleanExp }
1191 leftPartVfrBooleanExp :
1192 OpenParen vfrBooleanExpression CloseParen |
1193 (ideqval | ideqid | ideqvallist | vareqval | truefalse) |
1194 NOPID:NOT leftPartVfrBooleanExp << WriteOpByte (NOPID->getLine(), EFI_IFR_NOT_OP); >>
1197 rightPartVfrBooleanExp :
1198 AOPID:AND vfrBooleanExpression << WriteOpByte (AOPID->getLine(), EFI_IFR_AND_OP); >> |
1199 OOPID:OR vfrBooleanExpression << WriteOpByte (OOPID->getLine(), EFI_IFR_OR_OP); >>
1202 //*****************************************************************************
1208 TOPID:True << WriteOpByte (TOPID->getLine(), EFI_IFR_TRUE_OP); >> |
1209 FOPID:False << WriteOpByte (FOPID->getLine(), EFI_IFR_FALSE_OP); >>
1212 //*****************************************************************************
1215 // varstore MY_STRUCT_NAME, key = 0x1234, name = "MyVariableName", guid = {...};
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 ","
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 ()
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());
1248 //*****************************************************************************
1251 // vareqval var(0x100) == 0x20
1254 OPID:VarEqVal << WriteOpByte (OPID->getLine(), EFI_IFR_EQ_VAR_VAL_OP); >>
1256 VAR:Number << WriteWord (GetNumber (VAR->getText(), VAR->getLine(), 2)); >>
1262 OPID:IdEqVal << WriteOpByte (OPID->getLine(), EFI_IFR_EQ_ID_VAL_OP); >>
1263 vfrStructFieldName[0]
1267 //*****************************************************************************
1270 // ideqid MyNVData3.Field16A == MyNVData3.Field16B
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.
1276 OPID:IdEqId << WriteOpByte (OPID->getLine(), EFI_IFR_EQ_ID_ID_OP); >>
1277 vfrStructFieldName[0]
1278 compareVfrStructFieldNameNL0
1281 //*****************************************************************************
1283 // compareNumber is the combination of compare operation and Number
1288 VAL1:Number << WriteWord (GetNumber (VAL1->getText(), VAL1->getLine(), 2)); >>
1292 VAL2:Number << WriteWord (GetNumber (VAL2->getText(), VAL2->getLine(), 2));
1293 WriteOpByte (GTOPID->getLine(), EFI_IFR_GT_OP); >>
1297 VAL3:Number << WriteWord (GetNumber (VAL3->getText(), VAL3->getLine(), 2));
1298 WriteOpByte (GEOPID->getLine(), EFI_IFR_GE_OP); >>
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); >>
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); >>
1314 //*****************************************************************************
1316 // compareVfrStructFieldNameNL0 is the combination of compare operation and vfrStructFieldNameNL[0]
1318 compareVfrStructFieldNameNL0 :
1320 "==" << mIdEqIdStmt = 1; >>
1321 vfrStructFieldNameNL[0] << mIdEqIdStmt = 0; >>
1324 GTOPID:GreaterThan << mIdEqIdStmt = 1; >>
1325 vfrStructFieldNameNL[0] << mIdEqIdStmt = 0;
1326 WriteOpByte (GTOPID->getLine(), EFI_IFR_GT_OP); >>
1329 GEOPID:GreaterEqual << mIdEqIdStmt = 1; >>
1330 vfrStructFieldNameNL[0] << mIdEqIdStmt = 0;
1331 WriteOpByte (GEOPID->getLine(), EFI_IFR_GE_OP); >>
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); >>
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); >>
1349 OPID:IdEqValList << WriteOpByte (OPID->getLine(), EFI_IFR_EQ_ID_LIST_OP); >>
1350 vfrStructFieldName[0]
1352 ( VAL:Number << QueueIdEqValList (GetNumber (VAL->getText(), VAL->getLine(), 2)); >> ) +
1353 << FlushQueueIdEqValList(); >>
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());
1362 KP:Prompt "=" getStringId "," << LineNum = KP->getLine(); >>
1363 Help "=" getStringId
1366 FF:Flags "=" flagsField ( "\|" flagsField )* << LineNum = FF->getLine(); >>
1369 "," Key "=" KNUM:Number << LineNum = KNUM->getLine(); KeyValue = GetNumber(KNUM->getText(), LineNum, 2); >>
1371 << WriteFlagsKey (KeyValue, LineNum); >>
1375 vfrStatementHidden :
1376 IDH:Hidden << WriteOpByte (IDH->getLine(), EFI_IFR_HIDDEN_OP); >>
1378 VAL:Number "," << WriteWord (GetNumber (VAL->getText(), VAL->getLine(), 2)); >>
1380 KVAL:Number << WriteWord (GetNumber (KVAL->getText(), KVAL->getLine(), 2)); >>
1384 //*****************************************************************************
1387 // suppressif <boolean_expression> { grayoutif } <statements>+ endif;
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
1394 vfrStatementSuppressIf :
1395 << ResetFlags (); >>
1396 OPID:SuppressIf << WriteOpByte (OPID->getLine(), EFI_IFR_SUPPRESS_IF_OP); SetIfStart (OPID->getLine()); >>
1398 FF:Flags "=" flagsField ( "\|" flagsField )* ","
1400 << WriteFlags (); >> // write the flags field
1401 vfrBooleanExpression
1403 { suppressIfGrayOutIf } ( suppressIfAndGrayoutIfSubstatements )+
1404 ENDOP:EndIf ";" << WriteOpByte (ENDOP->getLine(), EFI_IFR_END_IF_OP); SetIfStart (0); >>
1408 // This is the form for a grayoutif nested in a suppressif statement
1410 suppressIfGrayOutIf :
1411 << ResetFlags (); >>
1412 OPID:GrayOutIf << WriteOpByte (OPID->getLine(), EFI_IFR_GRAYOUT_IF_OP); >>
1414 FF:Flags "=" flagsField ( "\|" flagsField )* ","
1416 << WriteFlags (); >> // write the flags field
1417 vfrBooleanExpression
1421 //*****************************************************************************
1424 // grayoutif { flags = n, } <boolean_expression> endif;
1426 // You can have: grayoutif:suppressif:statements:endif
1427 // grayoutif:statements:endif
1430 vfrStatementGrayOutIf :
1431 << ResetFlags (); >>
1432 OPID:GrayOutIf << WriteOpByte (OPID->getLine(), EFI_IFR_GRAYOUT_IF_OP); SetIfStart (OPID->getLine()); >>
1434 FF:Flags "=" flagsField ( "\|" flagsField )* ","
1436 << WriteFlags (); >> // write the flags field
1437 vfrBooleanExpression
1439 { grayoutIfSuppressIf } ( suppressIfAndGrayoutIfSubstatements )+
1440 ENDOP:EndIf ";" << WriteOpByte (ENDOP->getLine(), EFI_IFR_END_IF_OP); SetIfStart (0); >>
1444 // This is the format for a suppressif nested in a grayoutif
1446 grayoutIfSuppressIf :
1447 << ResetFlags (); >>
1448 OPID:SuppressIf << WriteOpByte (OPID->getLine(), EFI_IFR_SUPPRESS_IF_OP); >>
1450 FF:Flags "=" flagsField ( "\|" flagsField )* ","
1452 << WriteFlags (); >> // write the flags field
1453 vfrBooleanExpression
1458 // These are the VFR statements that are valid inside a suppressif or grayoutif statement.
1460 suppressIfAndGrayoutIfSubstatements :
1462 vfrStatementTextText |
1463 vfrStatementCheckBox |
1464 vfrStatementNumeric |
1467 vfrStatementPassword |
1468 vfrStatementString |
1469 vfrStatementHidden |
1472 vfrStatementInventory |
1473 vfrStatementOrderedList |
1474 vfrStatementSaveRestoreDefaults
1477 //*****************************************************************************
1481 // password varid = MyNvData.Password,
1482 // prompt = STRING_TOKEN(STR_PASSWORD_PROMPT),
1483 // help = STRING_TOKEN(STR_PASSWORD_HELP),
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(); >>
1496 FF:Flags "=" flagsField ( "\|" flagsField )* "," << LineNum = FF->getLine(); >>
1499 Key "=" KNUM:Number "," << LineNum = KNUM->getLine(); KeyValue = GetNumber(KNUM->getText(), LineNum, 2); >>
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)); >>
1508 //*****************************************************************************
1512 // string varid = MyNv.String,
1513 // prompt = STRING_TOKEN(STR_STRING_PROMPT),
1514 // help = STRING_TOKEN(STR_STRING_HELP),
1515 // flags = INTERACTIVE,
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.
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(); >>
1532 flagsField ( "\|" flagsField )* << LineNum = FF->getLine(); >>
1536 Key "=" KNUM:Number "," << LineNum = KNUM->getLine(); KeyValue = GetNumber(KNUM->getText(), LineNum, 2); >>
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); >>
1544 //*****************************************************************************
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)
1554 // step = 1, // step is option, and step=1 if not specified
1555 // default = 0; // default is optional, and default=minimum if not specified
1558 // Make flags and key optional. However if flags includes INTERACTIVE, then a key is required.
1559 // That check is done in WriteFlagsKey() function.
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(); >>
1568 FF:Flags "=" flagsField ( "\|" flagsField )* "," << LineNum = FF->getLine (); >>
1571 Key "=" KNUM:Number "," << LineNum = KNUM->getLine(); KeyValue = GetNumber(KNUM->getText(), LineNum, 2); >>
1573 << WriteFlagsKey (KeyValue, LineNum); >>
1575 EndNumeric ";" << WriteMinMaxStepDefault (); >>
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)
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()); >> }
1593 //*****************************************************************************
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),
1605 // month varid = Date.Month,
1606 // prompt = STRING_TOKEN(STR_DATE_PROMPT),
1607 // help = STRING_TOKEN(STR_DATE_MONTH_HELP),
1613 // day varid = Date.Day,
1614 // prompt = STRING_TOKEN(STR_DATE_PROMPT),
1615 // help = STRING_TOKEN(STR_DATE_DAY_HELP),
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
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
1651 //*****************************************************************************
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;
1659 vfrStatementTextText :
1660 << ResetFlags (); >>
1661 IDT:Text << WriteOpByte (IDT->getLine(), EFI_IFR_TEXT_OP); >>
1662 Help "=" getStringId ","
1664 getStringId // writes string identifier
1665 { "," Text "=" getStringId
1666 "," Flags "=" flagsField ( "\|" flagsField )* << WriteFlags (); >>
1668 Key "=" KNUM:Number << WriteWord (GetNumber(KNUM->getText(), KNUM->getLine(), 2)); >>
1673 //*****************************************************************************
1677 // inventory help = ID, text = ID;
1678 // inventory help = ID, text = id, text = ID;
1680 vfrStatementInventory :
1681 IDI:Inventory << WriteOpByte (IDI->getLine(), EFI_IFR_INVENTORY_OP); >>
1682 Help "=" getStringId ","
1683 Text "=" getStringId // writes string identifier
1684 { "," Text "=" getStringId
1689 //*****************************************************************************
1693 // restore defaults,
1695 // prompt = STRING_TOKEN(STR_RESTORE_DEFAULTS_PROMPT),
1696 // help = STRING_TOKEN(STR_RESTORE_DEFAULTS_HELP),
1702 // prompt = STRING_TOKEN(STR_SAVE_DEFAULTS_PROMPT),
1703 // help = STRING_TOKEN(STR_SAVE_DEFAULTS_HELP),
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); >>
1713 FormId "=" FRMID:Number "," << WriteWord (GetNumber (FRMID->getText(), FRMID->getLine(), 2));
1714 AddGotoReference (GetNumber (FRMID->getText(), FRMID->getLine(), 2), FRMID->getLine());
1716 Prompt "=" getStringId ","
1717 KH:Help "=" getStringId << LineNum = KH->getLine(); >>
1719 "," FF:Flags "=" flagsField ( "\|" flagsField )* << LineNum = FF->getLine(); >>
1722 "," Key "=" KNUM:Number << LineNum = KNUM->getLine(); KeyValue = GetNumber(KNUM->getText(), LineNum, 2); >>
1724 << WriteFlagsKey (KeyValue, LineNum); >>
1728 //*****************************************************************************
1732 // flags = 0x10 | DEFAULT | MANUFACTURING | INTERACTIVE | NV_ACCESS | RESET_REQUIRED | LATE_CHECK
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()); >>
1745 dateTimeSubStatement :
1746 Prompt "=" getStringId ","
1747 Help "=" getStringId ","
1748 << WriteByte (0, 0); WriteWord (0); >> // bogus flags and key
1749 minMaxStepDefault << WriteMinMaxStepDefault (); >>
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(); >>
1760 Key "=" KV:Number "," << LineNum = KV->getLine(); KeyValue = GetNumber(KV->getText(), LineNum, 2); >>
1762 << WriteFlagsKey (KeyValue, LineNum); >>
1766 vfrStatementSubTitle :
1767 IDS:Subtitle Text "=" << WriteOpByte (IDS->getLine(), EFI_IFR_SUBTITLE_OP); >>
1768 getStringId // writes string indentifier
1772 //*****************************************************************************
1776 // title = STRING_TOKEN(STR_BANNER_TITLE),
1778 // align center; // or left or right
1781 // title = STRING_TOKEN(STR_BANNER_TITLE), timeout = 100;
1783 vfrStatementBanner :
1784 IDB:Banner { "," } << WriteOpByte (IDB->getLine(), EFI_IFR_BANNER_OP); >>
1785 Title "=" getStringId ","
1787 Line VAL:Number "," << WriteWord (GetNumber(VAL->getText(), VAL->getLine(), 2)); >>
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); >>
1794 Timeout "=" TO:Number ";" << WriteWord (GetNumber(TO->getText(), TO->getLine(), 2)); >>
1795 << WriteByte (EFI_IFR_BANNER_TIMEOUT, 0); >>
1799 //*****************************************************************************
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),
1807 // flags = DEFAULT | INTERACTIVE;
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.
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); >>
1823 //*****************************************************************************
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 --
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()); >>
1844 //*****************************************************************************
1848 // option text = STRING_TOKEN(STRING_ID), value = 0 flags = 99;
1850 // Differs from the oneOfOptionText in that we don't allow the DEFAULT flag to
1851 // be set, and value cannot be 0.
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);
1861 WriteWord (GetNumber(WVAL->getText(), WVAL->getLine(), 2));
1864 FF:Flags "=" orderedListFlagsField
1865 ("\|" orderedListFlagsField )*
1867 "," Key "=" KV:Number << KeyValue = GetNumber (KV->getText(), KV->getLine(), 2); >>
1869 << WriteFlagsKey (KeyValue, FF->getLine()); >>
1870 ";" << mOptionCount++; >>
1873 //*****************************************************************************
1877 // flags = 0x10 | DEFAULT | MANUFACTURING | INTERACTIVE | NV_ACCESS | RESET_REQUIRED | LATE_CHECK
1879 // The ordered list flags field cannot have a default.
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); >>
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.
1898 vfrStructFieldNameArray[int FieldWidth] :
1899 << int ArrayIndex = 1; char IsArrayIndex = 0; >>
1900 SName:StringIdentifier
1902 SFieldName:StringIdentifier
1903 { OpenBracket AIndex:Number CloseBracket << ArrayIndex = GetNumber(AIndex->getText(), AIndex->getLine(), 4); IsArrayIndex = 1; >> }
1905 WriteFieldOffset (1,
1908 SFieldName->getText(),
1909 SFieldName->getLine(),
1919 // Parse references to VFR structure field names of form "MyNvStructure.Field",
1920 // then call a function to write out its offset and length.
1922 vfrStructFieldName[int FieldWidth] :
1923 << int ArrayIndex = 1; char IsArrayIndex = 0; >>
1924 SName:StringIdentifier
1926 SFieldName:StringIdentifier
1927 { OpenBracket AIndex:Number CloseBracket << ArrayIndex = GetNumber(AIndex->getText(), AIndex->getLine(), 4); IsArrayIndex = 1; >> }
1929 WriteFieldOffset (1,
1932 SFieldName->getText(),
1933 SFieldName->getLine(),
1942 //*****************************************************************************
1946 // MyNvStructure.FieldName[4]
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.
1951 vfrStructFieldNameNL[int FieldWidth] :
1952 << int ArrayIndex = 1; char IsArrayIndex = 0; >>
1953 SName:StringIdentifier
1955 SFieldName:StringIdentifier
1956 { OpenBracket AIndex:Number CloseBracket << ArrayIndex = GetNumber(AIndex->getText(), AIndex->getLine(), 4); IsArrayIndex = 1; >> }
1958 WriteFieldOffset (0,
1961 SFieldName->getText(),
1962 SFieldName->getLine(),
1971 //*****************************************************************************
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;
1981 suppressIfOptionText |
1982 grayOutIfOptionText |
1986 suppressIfOptionText :
1987 << ResetFlags (); >>
1988 OPID:SuppressIf << WriteOpByte (OPID->getLine(), EFI_IFR_SUPPRESS_IF_OP); SetIfStart (OPID->getLine()); >>
1990 FF:Flags "=" flagsField ( "\|" flagsField )* ","
1992 << WriteFlags (); >> // write the flags field
1993 vfrBooleanExpression
1995 { suppressIfGrayOutIf } ( commonOptionText )+
1996 ENDOP:EndIf ";" << WriteOpByte (ENDOP->getLine(), EFI_IFR_END_IF_OP); SetIfStart (0); >>
1999 grayOutIfOptionText :
2000 << ResetFlags (); >>
2001 OPID:GrayOutIf << WriteOpByte (OPID->getLine(), EFI_IFR_GRAYOUT_IF_OP); SetIfStart (OPID->getLine()); >>
2003 FF:Flags "=" flagsField ( "\|" flagsField )* ","
2005 << WriteFlags (); >> // write the flags field
2006 vfrBooleanExpression
2008 { grayoutIfSuppressIf } ( commonOptionText )+
2009 ENDOP:EndIf ";" << WriteOpByte (ENDOP->getLine(), EFI_IFR_END_IF_OP); SetIfStart (0); >>
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 )*
2019 "," Key "=" KV:Number << KeyValue = GetNumber (KV->getText(), KV->getLine(), 2); >>
2021 << WriteFlagsKey (KeyValue, FF->getLine()); >>
2022 ";" << mOptionCount++; >>
2026 // Gets a string identifier. It must be a numeric value of form:
2028 // STRING_TOKEN(100)
2031 << unsigned short StrId; >>
2032 StringToken OpenParen
2033 IdVal:Number << StrId = GetNumber (IdVal->getText(), IdVal->getLine(), 2); WriteStringIdWord (StrId); >>
2037 //******************************************************************************
2039 // Parser class definition.
2041 class EfiVfrParser {
2044 // Parser definitions go here
2047 STRUCT_DEFINITION *mFirstStructDefinition;
2048 STRUCT_DEFINITION *mLastStructDefinition;
2049 INT32 mNvDataStructSize;
2050 INT32 mNonNvDataStructSize;
2052 // Flag to indicate that we're processing a ideqid VFR statement so that
2053 // we can do late checks on the statement.
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;
2067 UINT32 mSubStmtFlags;
2068 UINT32 mSubStmtFlagsLineNum;
2069 EFI_GUID mFormSetGuid;
2070 UINT8 mNvDataStructDefined;
2071 UINT16 mClass, mSubclass;
2073 UINT32 mOptionCount; // how many "option" fields in a given statement
2074 UINT32 mLastVarIdSize;
2079 EfiVfrParser::SetIfStart (
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.
2090 LineNum - source line number where the "if" was parsed.
2100 EfiVfrParser::SetClass (
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.
2111 LineNum - source line number where the class statement was parsed.
2112 Value - the class value
2119 if (Value & 0xFFFF0000) {
2120 PrintWarningMessage (LineNum, NULL, "class value exceeds maximum allowed");
2122 mClass |= (UINT16)Value;
2125 EfiVfrParser::SetSubclass (
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.
2136 LineNum - source line number where the class statement was parsed.
2137 Value - the subclass value from the VFR statement
2144 if (Value & 0xFFFF0000) {
2145 PrintWarningMessage (LineNum, NULL, "subclass value exceeds maximum allowed");
2147 mSubclass |= (UINT16)Value;
2149 VOID EfiVfrParser::WriteClass ()
2154 VOID EfiVfrParser::WriteSubclass ()
2156 WriteWord (mSubclass);
2159 VOID EfiVfrParser::WriteIfrBytes ()
2161 mOpcodeHandler.WriteIfrBytes ();
2164 EfiVfrParser::WriteFlagsKey (
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.
2178 KeyValue - the key value from the VFR statement
2179 LineNum - source line number where the statement was parsed
2186 if ((mSubStmtFlags & EFI_IFR_FLAG_INTERACTIVE) && (KeyValue == 0)) {
2187 PrintErrorMessage (LineNum, NULL, "invalid or missing key value - required with INTERACTIVE");
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;
2194 WriteWord (KeyValue);
2197 EfiVfrParser::InitOrderedList ()
2202 EfiVfrParser::EndOrderedList (
2206 if (mLastVarIdSize < mOptionCount) {
2207 PrintErrorMessage (LineNum, NULL, "number of options exceeds the variable store size");
2211 EfiVfrParser::ResetFlags ()
2214 Routine Description:
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.
2231 mSubStmtFlagsLineNum = 0;
2235 // Test validity of flags value for a one-of statement.
2238 EfiVfrParser::TestOneOfFlags (
2243 // One of the fields must have had the default bit set
2245 if ((mStmtFlags & EFI_IFR_FLAG_DEFAULT) == 0) {
2246 PrintWarningMessage (LineNum, "default value must be specified", NULL);
2250 EfiVfrParser::SetFlags (
2256 // Check for redefinitions and invalid combinations
2258 if (mStmtFlags & Flags & EFI_IFR_FLAG_MANUFACTURING) {
2259 PrintErrorMessage (LineNum, "MANUFACTURING", "a field with this flag already defined");
2261 if (mStmtFlags & Flags & EFI_IFR_FLAG_DEFAULT) {
2262 PrintErrorMessage (LineNum, "DEFAULT", "a field with this flag already defined");
2264 mSubStmtFlags |= Flags;
2265 mSubStmtFlagsLineNum = LineNum;
2268 EfiVfrParser::WriteFlags ()
2271 // Check value for validity
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);
2281 WriteByte ((UINT8)mSubStmtFlags, 'F');
2283 // We can now clear the substatement flags
2285 mStmtFlags |= mSubStmtFlags;
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.
2293 EfiVfrParser::InitMinMaxStepDefault ()
2301 EfiVfrParser::WriteMinMaxStepDefault ()
2303 WriteWord (mMinimumValue);
2304 WriteWord (mMaximumValue);
2305 WriteWord (mStepValue);
2306 WriteWord (mDefaultValue);
2309 EfiVfrParser::SetMinMaxStepDefault (
2320 mMinimumValue = Value;
2321 mDefaultValue = Value;
2325 } else if (MMSD == 1) {
2326 mMaximumValue = Value;
2328 // If min > max, then swap the values. That includes resetting the default
2331 if (mMinimumValue > mMaximumValue) {
2332 PrintWarningMessage (LineNum, NULL, "maximum < minimum");
2334 mMaximumValue = mMinimumValue;
2335 mMinimumValue = TempValue;
2336 mDefaultValue = mMinimumValue;
2341 } else if (MMSD == 2) {
2344 // Default specified. Make sure min <= default <= max.
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");
2354 PrintErrorMessage (LineNum, "application error", "internal MMSD error");
2358 EfiVfrParser::AddLabel (
2366 // Added a label from the user VFR script. Make sure they haven't already
2367 // defined the same label elsewhere
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");
2376 Label = (UINT16_LIST *)malloc (sizeof (UINT16_LIST));
2377 if (Label == NULL) {
2378 PrintErrorMessage (0, NULL, "memory allocation error");
2381 memset ((char *)Label, 0, sizeof (UINT16_LIST));
2382 Label->Value = LabelNumber;
2383 Label->LineNum = LineNum;
2384 Label->Next = mDefinedLabels;
2385 mDefinedLabels = Label;
2388 EfiVfrParser::QueueIdEqValList (
2394 U16 = (UINT16_LIST *)malloc (sizeof (UINT16_LIST));
2396 Error (PROGRAM_NAME, 0, 0, NULL, "memory allocation failed");
2398 memset ((char *)U16, 0, sizeof (UINT16_LIST));
2400 if (mUint16List == NULL) {
2403 mLastUint16->Next = U16;
2409 EfiVfrParser::FlushQueueIdEqValList ()
2414 // We queued up a list of IdEqValList items. The IFR requires a count
2415 // followed by the actual values. Do it.
2418 mLastUint16 = mUint16List;
2419 while (mLastUint16 != NULL) {
2421 mLastUint16 = mLastUint16->Next;
2423 // BUGBUG -- check for more than 16K items?
2426 // Now write the values.
2428 mLastUint16 = mUint16List;
2429 while (mLastUint16 != NULL) {
2430 WriteWord ((UINT32)mLastUint16->Value);
2431 mLastUint16 = mLastUint16->Next;
2436 mLastUint16 = mUint16List;
2437 while (mUint16List != NULL) {
2438 mLastUint16 = mUint16List->Next;
2440 mUint16List = mLastUint16;
2444 EfiVfrParser::PrintErrorMessage (
2453 FileName = ConvertLineNumber ((UINT32 *)&LineNum);
2454 Error (FileName, LineNum, 0, Msg1, Msg2);
2456 Error (PROGRAM_NAME, 0, 0, Msg1, Msg2);
2460 EfiVfrParser::PrintWarningMessage (
2469 FileName = ConvertLineNumber ((UINT32 *)&LineNum);
2470 Warning (FileName, LineNum, 0, Msg1, Msg2);
2472 Warning (PROGRAM_NAME, 0, 0, Msg1, Msg2);
2477 ANTLRAbstractToken *Tok,
2480 ANTLRTokenType ETok,
2485 Routine Description:
2486 Called by the parser base class as a result of parse syntax errors.
2489 Tok - token that caused the error
2491 Eset - index in token table of the expected token
2502 LineNum = Tok->getLine ();
2503 FileName = ConvertLineNumber ((UINT32 *)&LineNum);
2505 // Sometimes the token number is 0, in which case I don't know what to
2509 Error (FileName, LineNum, 0, Tok->getText (), "unexpected token");
2512 // If we were expecting an endif, then report the line where the corresponding
2515 if ((strcmp (_token_tbl[ETok], "endif") == 0) && (mIfStart != 0)) {
2517 FileName = ConvertLineNumber (&LineNum);
2518 Error (FileName, LineNum, 0, "statement missing corresponding endif", NULL);
2520 Error (FileName, LineNum, 0, Tok->getText (), "expected %s", _token_tbl[ETok]);
2526 EfiVfrParser::init()
2529 Routine Description:
2530 Initializations function for our parser.
2540 ANTLRParser::init();
2543 // Used for queuing a variable list of UINT16's
2547 mFirstStructDefinition = NULL;
2548 mLastStructDefinition = NULL;
2549 mNvDataStructSize = 0;
2550 mNonNvDataStructSize = 0;
2551 mNvDataStructDefined = 0;
2552 mGotoReferences = NULL;
2553 mFormIdValues = NULL;
2554 mDefinedLabels = NULL;
2558 mDefinedVarStoreId = NULL;
2559 mLastDefinedVarStoreId = NULL;
2561 mLastNVVariableDataSize = 0;
2563 memset ((char *)&mFormSetGuid, 0, sizeof (EFI_GUID));
2566 // Destructor for the parser.
2568 EfiVfrParser::~EfiVfrParser(VOID)
2573 EfiVfrParser::Cleanup (VOID)
2576 Routine Description:
2577 Free memory allocated during parsing
2587 STRUCT_DEFINITION *NextStruct;
2588 STRUCT_FIELD_DEFINITION *NextField;
2590 UINT16_LIST *NextU16List;
2593 // Free up the structure definitions if any
2595 while (mFirstStructDefinition != NULL) {
2597 // Free up all the fields for this struct
2599 while (mFirstStructDefinition->Field != NULL) {
2600 NextField = mFirstStructDefinition->Field->Next;
2601 free (mFirstStructDefinition->Field->Name);
2602 free (mFirstStructDefinition->Field);
2603 mFirstStructDefinition->Field = NextField;
2605 NextStruct = mFirstStructDefinition->Next;
2606 free (mFirstStructDefinition->Name);
2607 free (mFirstStructDefinition);
2608 mFirstStructDefinition = NextStruct;
2611 // Free up the goto references and form id defines
2613 FreeGotoReferences ();
2615 // Free up label list
2617 while (mDefinedLabels != NULL) {
2618 NextU16List = mDefinedLabels->Next;
2619 delete (mDefinedLabels);
2620 mDefinedLabels = NextU16List;
2623 // Free up the list of defined variable storage IDs
2625 while (mDefinedVarStoreId != NULL) {
2626 NextU16List = mDefinedVarStoreId->Next;
2627 delete (mDefinedVarStoreId);
2628 mDefinedVarStoreId = NextU16List;
2633 EfiVfrParser::AtoX (
2640 Routine Description:
2641 Given a pointer to a ascii hex string, convert to a number with the given
2645 HexString - pointer to a string of format 30BCA
2646 Size - number of bytes to convert
2647 HexValue - return result
2650 The number of bytes converted.
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;
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;
2680 *HexValue = (*HexValue << 4) | Value;
2687 EfiVfrParser::WriteGuidValue (
2688 UINT32 TokenLineNum,
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 }
2707 Write out the value.
2710 TokenLineNum - line number where the guid was used
2711 G1-G11 - the 11 fields of the guid value
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);
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);
2746 EfiVfrParser::WriteFieldOffset (
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.
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
2779 STRUCT_DEFINITION *StructDef;
2780 STRUCT_FIELD_DEFINITION *FieldDef;
2785 // If we're writing an array size, then they better have referenced the field without an
2788 if (WriteArraySize && IsArrayIndex) {
2789 sprintf (Msg, "array index specified where an array is required");
2790 PrintErrorMessage (LineNum2, FieldName, Msg);
2794 // Look through our list of known structures for a match
2796 for (StructDef = mFirstStructDefinition; StructDef != NULL; StructDef = StructDef->Next) {
2798 // Check for matching structure name
2800 if (strcmp (StructDef->Name, StructName) == 0) {
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.
2806 StructDef->Referenced++;
2807 if (StructDef->VarStoreIdValid == 0) {
2809 // Set it valid so we don't flag it multiple times, then emit the error
2811 StructDef->VarStoreIdValid = 1;
2812 PrintErrorMessage (LineNum1, StructName, "varstore statement missing for this variable store");
2815 // Let the opcode-handler know which variable storage we're now using
2818 mOpcodeHandler.SetSecondaryVarStoreId (StructDef->VarStoreId);
2820 mOpcodeHandler.SetVarStoreId (StructDef->VarStoreId);
2823 // Found matching structure name. Now find the matching field name
2825 for (FieldDef = StructDef->Field; FieldDef != NULL; FieldDef = FieldDef->Next) {
2826 if (strcmp (FieldDef->Name, FieldName) == 0) {
2828 // Make sure the variable size is valid
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);
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
2841 VarSize = FieldDef->DataSize;
2842 if (FieldDef->IsArray == 0) {
2843 PrintErrorMessage (LineNum2, FieldName, "field is not declared as an array");
2846 if (FieldDef->ArrayLength < ArrayIndex) {
2847 PrintErrorMessage (LineNum2, FieldName, "array index exceeds declared size of field");
2851 if (FieldDef->IsArray) {
2852 VarSize = FieldDef->DataSize * FieldDef->ArrayLength;
2854 VarSize = FieldDef->DataSize;
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.
2863 if (mLastVarIdSize != VarSize) {
2864 PrintErrorMessage (LineNum2, FieldName, "variables must have the same size");
2868 mLastVarIdSize = VarSize;
2870 // If we're supposed to write an array size, then require it to be an array
2872 if (WriteArraySize && !FieldDef->IsArray) {
2873 PrintErrorMessage (LineNum2, FieldName, "array required");
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.
2880 Offset = FieldDef->Offset + FieldDef->DataSize * (ArrayIndex - 1);
2881 if (StructDef->IsNonNV) Offset += mNvDataStructSize;
2884 if (WriteArraySize) {
2885 if (FieldDef->DataSize * FieldDef->ArrayLength > 255) {
2886 PrintErrorMessage (LineNum2, FieldName, "array size exceeds 255 maximum encoding limit");
2889 WriteByte (FieldDef->DataSize * FieldDef->ArrayLength, 0);
2891 WriteByte (FieldDef->DataSize, 0);
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);
2904 // The structure was not found in the defined list. See if it's the "Date" structure
2906 if (strcmp (StructName, "Date") == 0) {
2908 // BUGBUG -- remove support for Date and Time as valid structure
2909 // names. They should use the NON_NV_DATA_MAP structure for this.
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.
2915 if (strcmp (FieldName, "Year") == 0) {
2917 // Write ID (offset), ID, and size
2919 WriteWord (mNvDataStructSize + mNonNvDataStructSize + 0);
2923 } else if (strcmp (FieldName, "Month") == 0) {
2925 // Write ID (offset), ID, and size
2927 WriteWord (mNvDataStructSize + mNonNvDataStructSize + 2);
2931 } else if (strcmp (FieldName, "Day") == 0) {
2933 // Write ID (offset), ID, and size
2935 WriteWord (mNvDataStructSize + mNonNvDataStructSize + 4);
2940 PrintErrorMessage (LineNum1, FieldName, "expected valid field name TheYear/TheMonth/TheDay");
2943 } else if (strcmp (StructName, "Time") == 0) {
2945 // Someone specified Time.Hours|Minutes|Seconds
2946 // BUGBUG -- define some constants for the IDs used here
2948 if (strcmp (FieldName, "Hours") == 0) {
2950 // Write ID (offset), ID, and size
2952 WriteWord (mNvDataStructSize + mNonNvDataStructSize + 6);
2956 } else if (strcmp (FieldName, "Minutes") == 0) {
2958 // Write ID (offset), ID, and size
2960 WriteWord (mNvDataStructSize + mNonNvDataStructSize + 8);
2964 } else if (strcmp (FieldName, "Seconds") == 0) {
2966 // Write ID (offset), ID, and size
2968 WriteWord (mNvDataStructSize + mNonNvDataStructSize + 10);
2973 PrintErrorMessage (LineNum1, FieldName, "expected valid field name Hours/Minutes/Seconds");
2977 PrintErrorMessage (LineNum1, StructName, "undefined structure");
2982 EfiVfrParser::StartStructDefinition (
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.
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.
3001 STRUCT_DEFINITION *StructDef;
3003 // Allocate memory for the structure record
3005 StructDef = (STRUCT_DEFINITION *)malloc (sizeof (STRUCT_DEFINITION));
3006 memset (StructDef, 0, sizeof (STRUCT_DEFINITION));
3007 StructDef->LineNum = LineNum;
3009 // Set flag indicating non-NV data structure or not
3011 StructDef->IsNonNV = IsNonNV;
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.
3016 if (mFirstStructDefinition == NULL) {
3017 mFirstStructDefinition = StructDef;
3018 StructDef->VarStoreIdValid = 1;
3020 mLastStructDefinition->Next = StructDef;
3022 mLastStructDefinition = StructDef;
3025 EfiVfrParser::EndStructDefinition (
3030 STRUCT_DEFINITION *StructDef;
3031 STRUCT_FIELD_DEFINITION *FieldDef;
3034 // Make sure they have not already defined a structure with this name
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");
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.
3047 // Allocate memory for the structure name
3049 mLastStructDefinition->Name = (char *)malloc (strlen (StructName) + 1);
3050 strcpy (mLastStructDefinition->Name, StructName);
3052 // Compute the structure size, and the offsets to each field
3055 for (FieldDef = mLastStructDefinition->Field; FieldDef != NULL; FieldDef = FieldDef->Next) {
3056 FieldDef->Offset = Offset;
3057 Offset += FieldDef->ArrayLength * FieldDef->DataSize;
3059 mLastStructDefinition->Size = Offset;
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.
3065 if (mNonNvDataStructSize == 0) {
3066 for (StructDef = mFirstStructDefinition; StructDef != NULL; StructDef = StructDef->Next) {
3067 if (StructDef->IsNonNV) {
3068 mNonNvDataStructSize = StructDef->Size;
3073 if (mNvDataStructSize == 0) {
3074 for (StructDef = mFirstStructDefinition; StructDef != NULL; StructDef = StructDef->Next) {
3075 if (StructDef->IsNonNV == 0) {
3076 mNvDataStructSize = StructDef->Size;
3083 EfiVfrParser::AddStructField (
3092 Routine Description:
3093 We're parsing the VFR structure definition. Add another defined field to
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
3108 STRUCT_FIELD_DEFINITION *FieldDef;
3109 STRUCT_FIELD_DEFINITION *Temp;
3111 // Make sure we don't already have a field of this name in our structure
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");
3120 // If it's an array, then they better not have a size of 0. For example:
3121 // UINT8 MyBytes[0];
3123 if (IsArray && (ArrayLength <= 0)) {
3124 PrintErrorMessage (LineNum, FieldName, "invalid array size");
3128 // Allocate memory for a new structure field definition
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);
3138 // Add it to the end of the field list for the currently active structure
3140 if (mLastStructDefinition->Field == NULL) {
3141 mLastStructDefinition->Field = FieldDef;
3143 mLastStructDefinition->LastField->Next = FieldDef;
3145 mLastStructDefinition->LastField = FieldDef;
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)
3156 Routine Description:
3157 Called while parsing a varstore statement. Add the variable store
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
3171 STRUCT_DEFINITION *StructDef;
3172 UINT16_LIST *L16Ptr;
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.
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);
3184 // Key value of 0 is invalid since that's assigned by default to the default
3185 // variable store (the first structure parsed).
3187 if (VarStoreId == 0) {
3188 PrintErrorMessage (LineNum, "variable storage key of 0 is invalid", NULL);
3191 // Create a new element to add to the list
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;
3200 mLastDefinedVarStoreId->Next = L16Ptr;
3202 mLastDefinedVarStoreId = L16Ptr;
3204 // Find the structure definition with this name
3206 for (StructDef = mFirstStructDefinition; StructDef != NULL; StructDef = StructDef->Next) {
3207 if (strcmp (StructDef->Name, StructName) == 0) {
3209 // Make sure they did not already define a variable storage ID
3210 // for this structure.
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");
3216 StructDef->VarStoreId = VarStoreId;
3217 StructDef->VarStoreIdValid = 1;
3218 StructDef->VarStoreLineNum = LineNum;
3219 WriteWord (StructDef->Size);
3221 WriteByte(*VarName, 0);
3228 PrintErrorMessage (LineNum, StructName, "structure with this name not defined");
3231 EfiVfrParser::WriteDWord (
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.
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.
3253 // Write 4 bytes, little endian. Specify a key byte only on the first one
3255 mOpcodeHandler.AddByte ((UINT8)Value, KeyByte);
3257 mOpcodeHandler.AddByte ((UINT8)Value, 0);
3259 mOpcodeHandler.AddByte ((UINT8)Value, 0);
3261 mOpcodeHandler.AddByte ((UINT8)Value, 0);
3264 EfiVfrParser::WriteOpByte (
3270 Routine Description:
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).
3277 ByteValue - opcode value
3285 mOpcodeHandler.AddOpcodeByte (ByteValue, LineNum);
3288 EfiVfrParser::WriteByte (
3294 Routine Description:
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.
3302 ByteValue - raw byte to write
3303 Key - character to tag the byte with when we write ByteValue to the
3312 mOpcodeHandler.AddByte (ByteValue, Key);
3315 EfiVfrParser::WriteWord (
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.
3325 Value - value to write.
3332 mOpcodeHandler.AddByte ((UINT8)Value, 0);
3333 mOpcodeHandler.AddByte ((UINT8)((Value \>> 8) & 0xFF), 0);
3336 EfiVfrParser::WriteStringIdWord (
3340 mOpcodeHandler.AddByte ((UINT8)WordValue, 'S');
3341 mOpcodeHandler.AddByte ((UINT8)((WordValue \>> 8) & 0xFF), 0);
3344 EfiVfrParser::FreeGotoReferences ()
3347 Routine Description:
3348 Called during cleanup to free up the memory we allocated when
3349 keeping track of VFR goto statements.
3359 GOTO_REFERENCE *CurrRef;
3360 GOTO_REFERENCE *NextRef;
3361 FORM_ID_VALUE *CurrFormId;
3362 FORM_ID_VALUE *NextFormId;
3367 // Go through all the "goto" references and make sure there was a
3368 // form ID of that value defined.
3370 for (CurrRef = mGotoReferences; CurrRef != NULL; CurrRef = CurrRef->Next) {
3372 for (CurrFormId = mFormIdValues; CurrFormId != NULL; CurrFormId = CurrFormId->Next) {
3373 if (CurrRef->Value == CurrFormId->Value) {
3379 sprintf (Name, "%d", (UINT32)CurrRef->Value);
3380 PrintErrorMessage (CurrRef->RefLineNum, Name, "undefined form ID");
3384 // Now free up the form id and goto references
3386 CurrFormId = mFormIdValues;
3387 while (CurrFormId != NULL) {
3388 NextFormId = CurrFormId->Next;
3390 CurrFormId = NextFormId;
3392 mFormIdValues = NULL;
3393 CurrRef = mGotoReferences;
3394 while (CurrRef != NULL) {
3395 NextRef = CurrRef->Next;
3399 mGotoReferences = NULL;
3402 EfiVfrParser::AddGotoReference (
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.
3414 GotoNumber - the label number referenced
3415 LineNum - the line number where the reference was made (used for
3423 GOTO_REFERENCE *NewRef;
3425 NewRef = (GOTO_REFERENCE *)malloc (sizeof (GOTO_REFERENCE));
3426 if (NewRef == NULL) {
3427 Error (PROGRAM_NAME, 0, 0, NULL, "memory allocation failure");
3430 memset ((char *)NewRef, 0, sizeof (GOTO_REFERENCE));
3431 NewRef->Value = (UINT16)GotoNumber;
3432 NewRef->RefLineNum = LineNum;
3433 NewRef->Next = mGotoReferences;
3434 mGotoReferences = NewRef;
3437 EfiVfrParser::AddFormId (
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
3451 Note that formid = 0 is invalid.
3454 FormIdValue - the parsed value for the Form ID
3455 LineNum - line number of the source file we're parsing
3462 FORM_ID_VALUE *NewFormId;
3467 // Verify that FormId != 0
3469 if (FormIdValue == 0) {
3470 FileName = ConvertLineNumber (&LineNum);
3471 Error (FileName, LineNum, 0, "form ID cannot be 0", NULL);
3475 // First go through all previously defined form IDs and make sure they have not defined
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);
3489 // Allocate memory for a new one
3491 NewFormId = (FORM_ID_VALUE *)malloc (sizeof (FORM_ID_VALUE));
3492 if (NewFormId == NULL) {
3493 Error (PROGRAM_NAME, 0, 0, NULL, "memory allocation failure");
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;
3503 EfiVfrParser::GetNumber (
3511 if ((NumStr[0] == '0') && (NumStr[1] == 'x')) {
3512 AtoX (NumStr + 2, 4, &Value);
3514 Value = (UINT32)atoi (NumStr);
3519 if ((NumBytes < 4) && (Value & ((UINT32)0xFFFFFFFF << (NumBytes * 8)))) {
3520 PrintErrorMessage (LineNum, NumStr, "value out of range");
3528 } // end grammar class