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);
68 // Base token definitions for ANTLR
73 // This is how we invoke the C preprocessor on the VFR source file
74 // to resolve #defines, #includes, etc. To make C source files
75 // shareable between VFR and drivers, define VFRCOMPILE so that
76 // #ifdefs can be used in shared .h files.
79 #define PREPROCESSOR_COMMAND "gcc "
80 #define PREPROCESSOR_OPTIONS "-x c -E -P -DVFRCOMPILE "
81 #define FILE_SEP_CHAR '/'
82 #define FILE_SEP_STRING "/"
84 #define PREPROCESSOR_COMMAND "cl.exe "
85 #define PREPROCESSOR_OPTIONS "/nologo /P /TC /DVFRCOMPILE "
86 #define FILE_SEP_CHAR '/'
87 #define FILE_SEP_STRING "/"
90 typedef ANTLRCommonToken ANTLRToken;
93 // Specify the filename extensions for the files we generate.
95 #define VFR_BINARY_FILENAME_EXTENSION ".c"
96 #define VFR_LIST_FILENAME_EXTENSION ".lst"
126 Application entry point function. Parse command-line arguments,
127 invoke the parser, clean up, and return.
130 argc - standard argc passed to main() per C conventions
131 argv - standard argv passed to main() per C conventions
134 STATUS_SUCCESS - program executed with no errors or warnings
135 STATUS_WARNING - program executed with warnings
136 STATUS_ERROR - non-recoverable errors encountered while processing
147 // Set our program name for the error printing routines.
148 // Then set printing limits.
150 SetUtilityName (PROGRAM_NAME);
151 SetPrintLimits (20, 20, 30);
153 // Process the command-line arguments
155 if (ProcessArgs (argc, argv) != STATUS_SUCCESS) {
162 // Verify the VFR script file exists
164 if ((VfrFptr = fopen (gOptions.VfrFileName, "r")) == NULL) {
165 Error (PROGRAM_NAME, 0, 0, gOptions.VfrFileName, "could not open input VFR file");
170 // Now close the file and make a system call to run the preprocessor
174 Len = strlen (PREPROCESSOR_OPTIONS) + strlen (gOptions.VfrFileName) + 10;
175 if (gOptions.CPreprocessorOptions != NULL) {
176 Len += strlen (gOptions.CPreprocessorOptions) + 1;
178 if (gOptions.IncludePaths != NULL) {
179 Len += strlen (gOptions.IncludePaths) + 1;
181 Cmd = (char *)malloc (Len);
183 Error (PROGRAM_NAME, 0, 0, NULL, "could not allocate memory");
187 strcpy (Cmd, PREPROCESSOR_OPTIONS);
188 if (gOptions.IncludePaths != NULL) {
189 strcat (Cmd, gOptions.IncludePaths);
192 if (gOptions.CPreprocessorOptions != NULL) {
193 strcat (Cmd, gOptions.CPreprocessorOptions);
196 strcat (Cmd, gOptions.VfrFileName);
198 Status = _spawnlp (_P_WAIT, PREPROCESSOR_COMMAND, Cmd, NULL);
201 char CommandLine[1000];
205 // Lean the slashes forward.
207 for (p = gOptions.PreprocessorOutputFileName; *p; p++) {
214 // Lean the slashes forward.
216 for (p = Cmd; *p; p++) {
222 sprintf(CommandLine, "%s %s > %s", PREPROCESSOR_COMMAND, Cmd, gOptions.PreprocessorOutputFileName);
223 Status = system (CommandLine);
227 Error (PROGRAM_NAME, 0, 0, gOptions.VfrFileName, "failed to spawn C preprocessor on VFR file");
228 printf ("Command: '%s %s'\n", PREPROCESSOR_COMMAND, Cmd);
234 // Open the preprocessor output file
236 if ((VfrFptr = fopen (gOptions.PreprocessorOutputFileName, "r")) == NULL) {
237 Error (PROGRAM_NAME, 0, 0, "failed to open input VFR preprocessor output file",
238 gOptions.PreprocessorOutputFileName);
243 // Define input VFR file
245 DLGFileInput InputFile (VfrFptr);
247 // Define an instance of the scanner
249 DLGLexerVfr Scanner (&InputFile);
251 // Define token buffer between scanner and parser
253 ANTLRTokenBuffer Pipe (&Scanner);
255 // Create a token to use as a model
259 // Tell the scanner what type the token is
261 Scanner.setToken (&Tok);
263 // Create an instance of our parser
265 EfiVfrParser Parser (&Pipe);
267 // Initialize the parser
270 Status = GetUtilityStatus ();
271 if (Status != STATUS_SUCCESS) {
276 // Start the first rule
280 // Close the input script file
283 Parser.WriteIfrBytes ();
285 // Call cleanup, which does some extra checking of the script
290 // If we had an error somewhere, delete our output files so that
291 // a subsequent build will rebuild them.
293 Status = GetUtilityStatus ();
294 if (Status == STATUS_ERROR) {
295 remove (gOptions.IfrOutputFileName);
305 Free up memory allocated during parsing.
316 // Free up our string we allocated to track the include paths
318 if (gOptions.IncludePaths != NULL) {
319 free (gOptions.IncludePaths);
320 gOptions.IncludePaths = NULL;
323 // Free up our string we allocated to track preprocessor options
325 if (gOptions.CPreprocessorOptions != NULL) {
326 free (gOptions.CPreprocessorOptions);
327 gOptions.CPreprocessorOptions = NULL;
340 Process the command-line arguments.
343 Argc - standard argc passed to main()
344 Argv - standard argv passed to main()
347 STATUS_SUCCESS - program should continue (all args ok)
352 char *CPreprocessorOptions;
354 char CopyStr[MAX_PATH];
358 // Put options in known state.
360 memset ((char *)&gOptions, 0, sizeof (OPTIONS));
362 // Go through all the arguments that start with '-'
366 while ((Argc > 0) && (Argv[0][0] == '-')) {
368 // -? or -h help option -- return an error for printing usage
370 if ((stricmp (Argv[0], "-?") == 0) || (stricmp (Argv[0], "-h") == 0)) {
374 // -l to create a listing output file
376 } else if (stricmp (Argv[0], "-l") == 0) {
377 gOptions.CreateListFile = 1;
379 // -I include_path option for finding include files. We'll pass this
380 // to the preprocessor. Turn them all into a single include string.
382 } else if (stricmp (Argv[0], "-i") == 0) {
383 if ((Argc < 2) || (Argv[1][0] == '-')) {
384 Error (PROGRAM_NAME, 0, 0, Argv[0], "missing path argument");
389 Len = strlen (" -I ");
390 Len += strlen (Argv[0]) + 2;
391 if (gOptions.IncludePaths != NULL) {
392 Len += strlen (gOptions.IncludePaths);
394 IncludePaths = (CHAR8 *)malloc (Len);
395 if (IncludePaths == NULL) {
396 Error (PROGRAM_NAME, 0, 0, NULL, "memory allocation failure");
400 if (gOptions.IncludePaths != NULL) {
401 strcpy (IncludePaths, gOptions.IncludePaths);
402 free (gOptions.IncludePaths);
404 strcat (IncludePaths, " -I ");
405 strcat (IncludePaths, Argv[0]);
406 gOptions.IncludePaths = IncludePaths;
408 // -od OutputDirectory to define a common directory for output files
410 } else if (stricmp (Argv[0], "-od") == 0) {
411 if ((Argc < 2) || (Argv[1][0] == '-')) {
412 Error (PROGRAM_NAME, 0, 0, Argv[0], "missing output directory name");
417 strcpy (gOptions.OutputDirectory, Argv[0]);
418 } else if (stricmp (Argv[0], "-ibin") == 0) {
419 gOptions.CreateIfrBinFile = 1;
420 } else if (stricmp (Argv[0], "-nostrings") == 0) {
423 // -ppflag C-preprocessor-flag option for passing options to the C preprocessor.
424 // Turn them all into a single string.
426 } else if (stricmp (Argv[0], "-ppflag") == 0) {
428 Error (PROGRAM_NAME, 0, 0, Argv[0], "missing C-preprocessor argument");
433 Len = strlen (Argv[0]) + 2;
434 if (gOptions.CPreprocessorOptions != NULL) {
435 Len += strlen (gOptions.CPreprocessorOptions);
437 CPreprocessorOptions = (CHAR8 *)malloc (Len);
438 if (CPreprocessorOptions == NULL) {
439 Error (PROGRAM_NAME, 0, 0, NULL, "memory allocation failure");
442 CPreprocessorOptions[0] = 0;
443 if (gOptions.CPreprocessorOptions != NULL) {
444 strcpy (CPreprocessorOptions, gOptions.CPreprocessorOptions);
445 free (gOptions.CPreprocessorOptions);
447 strcat (CPreprocessorOptions, " ");
448 strcat (CPreprocessorOptions, Argv[0]);
449 gOptions.CPreprocessorOptions = CPreprocessorOptions;
451 Error (PROGRAM_NAME, 0, 0, Argv[0], "unrecognized option");
458 // Must specify at least the vfr file name
461 Error (PROGRAM_NAME, 0, 0, Argv[1], "unrecognized argument after VFR file name");
463 } else if (Argc < 1) {
464 Error (PROGRAM_NAME, 0, 0, NULL, "must specify VFR file name");
467 strcpy (gOptions.VfrFileName, Argv[0]);
469 // We run the preprocessor on the VFR file to manage #include statements.
470 // Unfortunately the preprocessor does not allow you to specify the
471 // output name or path of the resultant .i file, so we have to do
472 // some work. Here we'll extract the basename of the VFR file, then
473 // append .i on the end.
475 strcpy (CopyStr, gOptions.VfrFileName);
476 Cptr = CopyStr + strlen (CopyStr) - 1;
477 for (;(Cptr > CopyStr) && (*Cptr != '\\') && (*Cptr != ':') && (*Cptr != '/'); Cptr--);
478 if (Cptr == CopyStr) {
479 strcpy (gOptions.PreprocessorOutputFileName, Cptr);
480 strcpy (gOptions.VfrBaseFileName, Cptr);
482 strcpy (gOptions.PreprocessorOutputFileName, Cptr+1);
483 strcpy (gOptions.VfrBaseFileName, Cptr+1);
485 for (Cptr = gOptions.PreprocessorOutputFileName; *Cptr && (*Cptr != '.'); Cptr++);
488 // Terminate the vfr file basename at the extension
490 for (Cptr = gOptions.VfrBaseFileName; *Cptr && (*Cptr != '.'); Cptr++) {
494 // If they defined an output directory, prepend all output files
495 // with the working directory. Output files of interest:
496 // VfrListFileName -- list file
497 // IfrOutputFileName -- IFR bytes
498 // StringOutputFileName -- string bytes
499 // StringListFileName -- not used
500 // StringDefineFileName -- #defines of string identifiers
502 // We have two cases:
503 // 1. Output directory (-od) not specified, in which case output files
504 // go to the current working directory.
505 // 2. Output directory specified, in which case the output files
506 // go directly to the specified directory.
508 if (gOptions.OutputDirectory[0] == 0) {
511 _getcwd (CopyStr, sizeof (CopyStr));
513 getcwd (CopyStr, sizeof (CopyStr));
515 strcpy (gOptions.OutputDirectory, CopyStr);
518 // Make sure output directory has a trailing backslash
520 if (gOptions.OutputDirectory[strlen (gOptions.OutputDirectory) - 1] != '\\' ||
521 gOptions.OutputDirectory[strlen (gOptions.OutputDirectory) - 1] != '/') {
522 strcat (gOptions.OutputDirectory, FILE_SEP_STRING);
525 // Create the base output file name as: path\base, copy it to all the output
526 // filenames, and then add the appropriate extension to each.
528 strcpy (gOptions.VfrListFileName, gOptions.OutputDirectory);
529 strcat (gOptions.VfrListFileName, gOptions.VfrBaseFileName);
530 strcpy (gOptions.IfrOutputFileName, gOptions.VfrListFileName);
531 strcat (gOptions.VfrListFileName, VFR_LIST_FILENAME_EXTENSION);
532 strcat (gOptions.IfrOutputFileName, VFR_BINARY_FILENAME_EXTENSION);
534 // We set a default list file name, so if they do not
535 // want a list file, null out the name now.
537 if (gOptions.CreateListFile == 0) {
538 gOptions.VfrListFileName[0] = 0;
540 return STATUS_SUCCESS;
548 Print utility usage instructions
559 const char *Help[] = {
561 "VfrCompile version " VFR_COMPILER_VERSION,
563 " Usage: VfrCompile {options} [VfrFile]",
565 " where options include:",
566 " -? or -h prints this help",
567 " -l create an output IFR listing file",
568 " -i IncPath add IncPath to the search path for VFR included files",
569 " -od OutputDir deposit all output files to directory OutputDir (default=cwd)",
570 " -ibin create an IFR HII pack file",
571 " where parameters include:",
572 " VfrFile name of the input VFR script file",
576 for (Index = 0; Help[Index] != NULL; Index++) {
577 fprintf (stdout, "%s\n", Help[Index]);
589 PARSER_LINE_DEFINITION *gLineDefinition = NULL;
590 PARSER_LINE_DEFINITION *gLastLineDefinition = NULL;
600 During the lexer phase, if we encounter a #line statement output by
601 the preprocessor, this function gets called. We'll save off the info
602 for error reporting purposes. The preprocessor line information has the
608 TokenString - the parsed string as shown above
609 TokenLine - the line number in the preprocessed output file
616 PARSER_LINE_DEFINITION *LineDef;
620 // Allocate a structure in which we can keep track of this line information.
622 LineDef = (PARSER_LINE_DEFINITION *)malloc (sizeof (PARSER_LINE_DEFINITION));
623 memset ((char *)LineDef, 0, sizeof (PARSER_LINE_DEFINITION));
624 LineDef->TokenLineNum = TokenLine;
625 LineDef->HashLineNum = atoi (TokenString + 6);
627 // Find the quotes in the filename, then allocate space in the line
628 // def structure for a copy of the filename. Finally, copy it without
629 // quotes to the line def.
631 for (Cptr = TokenString + 7; *Cptr && (*Cptr != '"'); Cptr++);
633 LineDef->FileName = (CHAR8 *)malloc (strlen (Cptr));
635 strcpy (LineDef->FileName, Cptr);
636 for (Cptr = LineDef->FileName; *Cptr && (*Cptr != '"'); Cptr++);
639 // Now add this new one to the list
641 if (gLineDefinition == NULL) {
642 gLineDefinition = LineDef;
644 gLastLineDefinition->Next = LineDef;
646 gLastLineDefinition = LineDef;
648 Error (PROGRAM_NAME, 0, 0, "invalid line definition in preprocessor output file", TokenString);
660 Given the line number in the preprocessor-output file, use the line number
661 information we've saved to determine the source file name and line number
662 where the code originally came from. This is required for error reporting.
665 LineNum - the line number in the preprocessor-output file.
668 Returns a pointer to the source file name. Also returns the line number
669 in the provided LineNum argument
673 PARSER_LINE_DEFINITION *LineDef;
675 // Step through our linked list of #line information we saved off.
676 // For each one, look at its line number, and the line number of the
677 // next record, and see if the passed-in line number is in the range.
678 // If it is, then convert the line number to the appropriate line number
679 // of the original source file.
681 for (LineDef = gLineDefinition; LineDef != NULL; LineDef = LineDef->Next) {
683 // The given LineNum is the line number from the .i file.
684 // Find a line definition whose range includes this line number,
685 // convert the line number, and return the filename.
687 if (LineDef->TokenLineNum <= *LineNum) {
688 if (LineDef->Next != NULL) {
689 if (LineDef->Next->TokenLineNum > *LineNum) {
690 *LineNum = *LineNum - LineDef->TokenLineNum + LineDef->HashLineNum;
691 return LineDef->FileName;
695 // Last one in the list of line definitions, so has to be right
697 *LineNum = *LineNum - LineDef->TokenLineNum + LineDef->HashLineNum;
698 return LineDef->FileName;
708 // Define a lexical class for parsing quoted strings. Basically
709 // starts with a double quote, and ends with a double quote that
710 // is not preceeded with a backslash.
712 #lexclass QUOTED_STRING
713 #token TheString "~[\"]*\"" << mode (START); >>
716 // Define a lexical class for parsing "#pragma pack" statements.
717 // We do this just for convenience (since we skip them here) so
718 // that users can include some minimal .h files.
720 #lexclass PRAGMA_PACK
721 #token "pack" << skip (); >>
722 #token "[\ \t]" << skip (); >>
723 #token "\(" << skip (); >>
724 #token "[0-9]*" << skip (); >>
725 #token "\)" << skip (); mode (START); >>
728 // Define a lexclass for skipping over C++ style comments
730 #lexclass CPP_COMMENT
731 #token "~[\n]*" << skip (); >>
732 #token "\n" << skip (); mode (START); newline (); >>
735 // Standard lexclass is START
740 // Find start of C++ style comments
742 #token "//" << skip (); mode (CPP_COMMENT); >>
747 #token "[\ \t]" << skip (); >>
750 // Skip over newlines, but count them
752 #token "\n" << skip (); newline (); >>
755 // Skip pragma pack statements
757 #token "\#pragma" << skip (); mode(PRAGMA_PACK); >>
760 // Skip over 'extern' in any included .H file
762 #token "extern" << skip (); >>
765 // Tokens for the different keywords. Syntax is:
766 // TokenName("ErrorMessageText") "TokenString"
768 // TokenName is the token name (must be capitalized) that is used in the rules
769 // ErrorMessageText is the string the compiler emits when it detects a syntax error
770 // TokenString is the actual matching string used in the user script
772 #token LineDefinition "#line\ [0-9]+\ \"~[\"]+\"[\ \t]*\n" << AddFileLine (begexpr (), line ()); skip (); >>
773 #token FormSet("formset") "formset"
774 #token EndFormSet("endformset") "endformset"
775 #token Title("title") "title"
776 #token FormId("formid") "formid"
777 #token OneOf("oneof") "oneof"
778 #token Prompt("prompt") "prompt"
779 #token OrderedList("orderedlist") "orderedlist"
780 #token EndList("endlist") "endlist"
781 #token EndForm("endform") "endform"
782 #token EndOneOf("endoneof") "endoneof"
783 #token Form("form") "form"
784 #token Subtitle("subtitle") "subtitle"
785 #token Help("help") "help"
786 #token VarId("varid") "varid"
787 #token Text("text") "text"
788 #token Option("option") "option"
789 #token Value("value") "value"
790 #token Flags("flags") "flags"
791 #token Date("date") "date"
792 #token EndDate("enddate") "enddate"
793 #token Year("year") "year"
794 #token Month("month") "month"
795 #token Day("day") "day"
796 #token Time("time") "time"
797 #token EndTime("endtime") "endtime"
798 #token Hour("hour") "hour"
799 #token Minute("minute") "minute"
800 #token Second("second") "second"
801 #token AND("AND") "AND"
803 #token GrayOutIf("grayoutif") "grayoutif"
804 #token NOT("NOT") "NOT"
805 #token Label("label") "label"
806 #token Timeout("timeout") "timeout"
807 #token Inventory("inventory") "inventory"
808 #token StringToken("STRING_TOKEN") "STRING_TOKEN"
809 #token NonNvDataMap("_NON_NV_DATA_MAP") "_NON_NV_DATA_MAP"
810 #token Struct("struct") "struct"
811 #token Uint64("UINT64") "UINT64"
812 #token Uint32("UINT32") "UINT32"
813 #token Uint16("UINT16") "UINT16"
814 #token Char16("CHAR16") "CHAR16"
815 #token Uint8("UINT8") "UINT8"
816 #token Guid("guid") "guid"
817 #token CheckBox("checkbox") "checkbox"
818 #token EndCheckBox("endcheckbox") "endcheckbox"
819 #token Numeric("numeric") "numeric"
820 #token EndNumeric("endnumeric") "endnumeric"
821 #token Minimum("minimum") "minimum"
822 #token Maximum("maximum") "maximum"
823 #token Step("step") "step"
824 #token Default("default") "default"
825 #token Password("password") "password"
826 #token EndPassword("endpassword") "endpassword"
827 #token String("string") "string"
828 #token EndString("endstring") "endstring"
829 #token MinSize("minsize") "minsize"
830 #token MaxSize("maxsize") "maxsize"
831 #token Encoding("encoding") "encoding"
832 #token SuppressIf("suppressif") "suppressif"
833 #token Hidden("hidden") "hidden"
834 #token Goto("goto") "goto"
835 #token InconsistentIf "inconsistentif"
836 #token EndIf("endif") "endif"
837 #token IdEqId("ideqid") "ideqid"
838 #token IdEqVal("ideqval") "ideqval"
839 #token VarEqVal("vareqval") "vareqval"
840 #token Var("var") "var"
841 #token IdEqValList("ideqvallist") "ideqvallist"
842 #token Length("length") "length"
843 #token Values("values") "values"
844 #token Key("key") "key"
845 #token DefaultFlag("DEFAULT") "DEFAULT"
846 #token ManufacturingFlag("MANUFACTURING") "MANUFACTURING"
847 #token InteractiveFlag("INTERACTIVE") "INTERACTIVE"
848 #token NVAccessFlag("NV_ACCESS") "NV_ACCESS"
849 #token ResetRequiredFlag("RESET_REQUIRED") "RESET_REQUIRED"
850 #token LateCheckFlag("LATE_CHECK") "LATE_CHECK"
851 #token Class("class") "class"
852 #token Subclass("subclass") "subclass"
853 #token TypeDef("typedef") "typedef"
854 #token Restore("restore") "restore"
855 #token Save("save") "save"
856 #token Defaults("defaults") "defaults"
857 #token Banner("banner") "banner"
858 #token Align("align") "align"
859 #token Left("left") "left"
860 #token Right("right") "right"
861 #token Center("center") "center"
862 #token Line("line") "line"
863 #token VarStore("varstore") "varstore"
864 #token Name("name") "name"
865 #token Oem("oem") "oem"
866 #token True("TRUE") "TRUE"
867 #token False("FALSE") "FALSE"
868 #token GreaterThan(">") ">"
869 #token GreaterEqual(">=") ">="
870 #token LessThan("<") "<"
871 #token LessEqual("<=") "<="
874 // Define the class and subclass tokens
876 #token ClassNonDevice("NONDEVICE") "NON_DEVICE"
877 #token ClassDiskDevice("DISK_DEVICE") "DISK_DEVICE"
878 #token ClassVideoDevice("VIDEO_DEVICE") "VIDEO_DEVICE"
879 #token ClassNetworkDevice("NETWORK_DEVICE") "NETWORK_DEVICE"
880 #token ClassInputDevice("INPUT_DEVICE") "INPUT_DEVICE"
881 #token ClassOnBoardDevice("ONBOARD_DEVICE") "ONBOARD_DEVICE"
882 #token ClassOtherDevice("OTHER_DEVICE") "OTHER_DEVICE"
884 #token SubclassSetupApplication("SETUP_APPLICATION") "SETUP_APPLICATION"
885 #token SubclassGeneralApplication("GENERAL_APPLICATION") "GENERAL_APPLICATION"
886 #token SubclassFrontPage("FRONT_PAGE") "FRONT_PAGE"
887 #token SubclassSingleUse("SINGLE_USE") "SINGLE_USE"
889 #token LanguageIdentifier("language identifier") "[a-z][a-z][a-z]" // 3 lowercase characters
890 #token StringIdentifier("string identifier") "[A-Za-z_][A-Za-z_0-9]*"
891 #token Number("numeric value") "(0x[0-9A-Fa-f]+) | [0-9]+"
892 #token OpenBrace("{") "\{"
893 #token CloseBrace("}") "\}"
894 #token OpenParen("(") "\("
895 #token CloseParen(")") "\)"
896 #token OpenBracket("[") "\["
897 #token CloseBracket("]") "\]"
900 // Define all other invalid characters so that they get through the lexical phase
901 // and we can catch them during the parse phase. We get much better error
904 #token InvalidCharacters("invalid characters") "~[;:=,\.\|]"
907 // This is the overall definition of a VFR form definition script.
910 ( dataStructDefinition )*
912 ( vfrStatementVarStore )*
914 EFS:EndFormSet ";" << WriteOpByte (EFS->getLine(), EFI_IFR_END_FORM_SET_OP); >>
919 FS:FormSet << WriteOpByte (FS->getLine(), EFI_IFR_FORM_SET_OP); >>
935 CloseBrace << WriteGuidValue (G1->getLine (), G1->getText (), G2->getText (), G3->getText (),
936 G4->getText (), G5->getText (), G6->getText (), G7->getText (),
937 G8->getText (), G9->getText (), G10->getText (), G11->getText ()
941 Title "=" getStringId ","
942 Help "=" getStringId ","
944 // insert padding for an EFI_PHYSICAL_ADDRESS (UINT64)
946 << WriteDWord (0, 0); WriteDWord (0, 0); >>
947 Class "=" CVAL:classDefinition "," << WriteClass (); >>
948 Subclass "=" SVAL:subclassDefinition "," << WriteSubclass (); >>
949 << WriteWord (mNvDataStructSize); >>
953 // A form can be of multiple classes, thus allow CLASS_A | CLASS_B | CLASS_C
956 validClassNames ( "\|" validClassNames )*
960 CND:ClassNonDevice << SetClass (CND->getLine(), EFI_NON_DEVICE_CLASS); >>
961 | CDD:ClassDiskDevice << SetClass (CDD->getLine(), EFI_DISK_DEVICE_CLASS); >>
962 | CVD:ClassVideoDevice << SetClass (CVD->getLine(), EFI_VIDEO_DEVICE_CLASS); >>
963 | CNW:ClassNetworkDevice << SetClass (CNW->getLine(), EFI_NETWORK_DEVICE_CLASS); >>
964 | CID:ClassInputDevice << SetClass (CID->getLine(), EFI_INPUT_DEVICE_CLASS); >>
965 | COB:ClassOnBoardDevice << SetClass (COB->getLine(), EFI_ON_BOARD_DEVICE_CLASS); >>
966 | COD:ClassOtherDevice << SetClass (COD->getLine(), EFI_OTHER_DEVICE_CLASS); >>
967 | CNUM:Number << SetClass (CNUM->getLine(), GetNumber (CNUM->getText(), CNUM->getLine(), 4)); >>
968 ; << PrintErrorMessage (LT(1)->getLine(), LT(1)->getText(), "invalid class"); >>
971 // A form can only be of one subclass type.
974 SSA:SubclassSetupApplication << SetSubclass (SSA->getLine(), EFI_SETUP_APPLICATION_SUBCLASS); >>
975 | SGA:SubclassGeneralApplication << SetSubclass (SGA->getLine(), EFI_GENERAL_APPLICATION_SUBCLASS); >>
976 | SFP:SubclassFrontPage << SetSubclass (SFP->getLine(), EFI_FRONT_PAGE_SUBCLASS); >>
977 | SSU:SubclassSingleUse << SetSubclass (SSU->getLine(), EFI_SINGLE_USE_SUBCLASS); >>
978 | SNUM:Number << SetSubclass (SNUM->getLine(), GetNumber (SNUM->getText(), SNUM->getLine(), 4)); >>
979 ; << PrintErrorMessage (LT(1)->getLine(), LT(1)->getText(), "invalid subclass"); >>
982 // Parse a C type data structure for storing VFR setup data. Allow:
983 // typedef struct _XXX_ {
987 dataStructDefinition :
988 << int IsNonNV = 0; >>
992 NonNvDataMap << IsNonNV = 1; >>
995 ) << StartStructDefinition (IsNonNV, S->getLine()); >>
998 CloseBrace NAME:StringIdentifier << EndStructDefinition (NAME->getText(), NAME->getLine()); >>
1003 // Parse a C type data structure for defining data that is not stored in NV.
1004 // typedef struct _NON_NV_DATA_MAP {
1006 // } NON_NV_DATA_MAP;
1008 nonNvDataStructDefinition :
1011 { StringIdentifier }
1014 CloseBrace NAME:StringIdentifier << AddStructField (NAME->getText(), NAME->getLine(), 0, 0, 0); >>
1019 ( dataStructField64 | dataStructField32 | dataStructField16 | dataStructField8 ) *
1022 //*****************************************************************************
1028 // Used while parsing the NV data map structures.
1031 << int ArrayLength = 1; char IsArray = 0; >>
1033 NAME:StringIdentifier
1034 ( ";" | OpenBracket IVal:Number CloseBracket ";" << ArrayLength = GetNumber (IVal->getText(), IVal->getLine(), 4); IsArray = 1; >> )
1035 << AddStructField (NAME->getText(), NAME->getLine(), 8, ArrayLength, IsArray); >>
1038 //*****************************************************************************
1044 // Used while parsing the NV data map structures.
1047 << int ArrayLength = 1; char IsArray = 0; >>
1049 NAME:StringIdentifier
1050 ( ";" | OpenBracket IVal:Number CloseBracket ";" << ArrayLength = GetNumber (IVal->getText(), IVal->getLine(), 4); IsArray = 1; >> )
1051 << AddStructField (NAME->getText(), NAME->getLine(), 4, ArrayLength, IsArray); >>
1054 //*****************************************************************************
1060 // Used while parsing the NV data map structures.
1063 << int ArrayLength = 1; char IsArray = 0; >>
1064 ( "UINT16" | "CHAR16" )
1065 NAME:StringIdentifier
1066 ( ";" | OpenBracket IVal:Number CloseBracket ";" << ArrayLength = GetNumber (IVal->getText(), IVal->getLine(), 4); IsArray = 1; >> )
1067 << AddStructField (NAME->getText(), NAME->getLine(), 2, ArrayLength, IsArray); >>
1070 //*****************************************************************************
1076 // Used while parsing the NV data map structures.
1079 << int ArrayLength = 1; char IsArray = 0; >>
1081 NAME:StringIdentifier
1082 ( ";" | OpenBracket IVal:Number CloseBracket ";" << ArrayLength = GetNumber (IVal->getText(), IVal->getLine(), 4); IsArray = 1; >> )
1083 << AddStructField (NAME->getText(), NAME->getLine(), 1, ArrayLength, IsArray); >>
1086 //*****************************************************************************
1090 // title = STRING_TOKEN(STR_FORM_TITLE);
1091 // -- form statements --
1094 // The Form ID cannot be 0
1097 FRM:Form FormId << WriteOpByte (FRM->getLine(), EFI_IFR_FORM_OP); >>
1099 VAL:Number << WriteWord (GetNumber (VAL->getText(), VAL->getLine(), 2)); AddFormId (GetNumber (VAL->getText(), VAL->getLine(), 2), VAL->getLine()); >>
1101 Title "=" getStringId ";" // writes string identifier
1103 ENDF:EndForm ";" << WriteOpByte (ENDF->getLine(), EFI_IFR_END_FORM_OP); >>
1107 // VFR statements in a formset
1110 vfrStatementSubTitle |
1112 vfrStatementTextText |
1113 vfrStatementCheckBox |
1114 vfrStatementNumeric |
1117 vfrStatementPassword |
1118 vfrStatementString |
1119 vfrStatementSuppressIf |
1120 vfrStatementHidden |
1122 vfrStatementGrayOutIf |
1123 vfrStatementInconsistentIf |
1125 vfrStatementBanner |
1126 vfrStatementInventory |
1127 vfrStatementOrderedList |
1129 vfrStatementSaveRestoreDefaults
1132 //*****************************************************************************
1138 OPID:Label << WriteOpByte (OPID->getLine(), EFI_IFR_LABEL_OP); >>
1140 WriteWord (GetNumber (VAL->getText(), VAL->getLine(), 2));
1141 AddLabel (GetNumber (VAL->getText(), VAL->getLine(), 2), VAL->getLine());
1146 //*****************************************************************************
1149 // oem 0x12, 0x34, 0x56;
1152 OPID:Oem << WriteOpByte (OPID->getLine(), EFI_IFR_OEM_DEFINED_OP); >>
1153 ( VAL1:Number << WriteByte (GetNumber (VAL1->getText(), VAL1->getLine(), 1), 0); >> )
1154 ( "," VAL2:Number << WriteByte (GetNumber (VAL2->getText(), VAL2->getLine(), 1), 0); >> )*
1158 //*****************************************************************************
1161 // inconsistentif NOT .... AND NOT .... OR ... endif;
1163 vfrStatementInconsistentIf :
1164 << ResetFlags (); >>
1165 IIFOP:InconsistentIf << WriteOpByte (IIFOP->getLine(), EFI_IFR_INCONSISTENT_IF_OP); >>
1166 Prompt "=" getStringId ","
1168 FF:Flags "=" flagsField ( "\|" flagsField )* ","
1170 << WriteFlags (); >> // write the flags field
1171 vfrBooleanExpression
1172 EOP:EndIf ";" << WriteOpByte (EOP->getLine(), EFI_IFR_END_IF_OP); >>
1175 //*****************************************************************************
1178 // TRUE AND (ideqval SomeStruct.SomeMember >= 0x10 OR
1179 // ideqid SomeStruct.SomeMember < SomeStruct.SomeOtherMember) AND
1180 // (ideqlist SomeStruct.SomeOtherMember == 0x10, 0x20, 0x30 OR
1181 // vareqval var(VAR_EQ_TEST_NAME) == 0x1)
1183 // For supporting complex express, divide the vfrBooleanExpression to two parts
1184 // so that pred-LL(k) parser can parse incrementally.
1186 vfrBooleanExpression :
1187 leftPartVfrBooleanExp { rightPartVfrBooleanExp }
1190 leftPartVfrBooleanExp :
1191 OpenParen vfrBooleanExpression CloseParen |
1192 (ideqval | ideqid | ideqvallist | vareqval | truefalse) |
1193 NOPID:NOT leftPartVfrBooleanExp << WriteOpByte (NOPID->getLine(), EFI_IFR_NOT_OP); >>
1196 rightPartVfrBooleanExp :
1197 AOPID:AND vfrBooleanExpression << WriteOpByte (AOPID->getLine(), EFI_IFR_AND_OP); >> |
1198 OOPID:OR vfrBooleanExpression << WriteOpByte (OOPID->getLine(), EFI_IFR_OR_OP); >>
1201 //*****************************************************************************
1207 TOPID:True << WriteOpByte (TOPID->getLine(), EFI_IFR_TRUE_OP); >> |
1208 FOPID:False << WriteOpByte (FOPID->getLine(), EFI_IFR_FALSE_OP); >>
1211 //*****************************************************************************
1214 // varstore MY_STRUCT_NAME, key = 0x1234, name = "MyVariableName", guid = {...};
1216 vfrStatementVarStore :
1217 OP:VarStore << WriteOpByte (OP->getLine(), EFI_IFR_VARSTORE_OP); >>
1218 STRUCT_NAME:StringIdentifier ","
1219 Key "=" KNUM:Number ","
1220 Name "=" VAR_NAME:StringIdentifier ","
1236 CloseBrace << WriteGuidValue (G1->getLine (), G1->getText (), G2->getText (), G3->getText (),
1237 G4->getText (), G5->getText (), G6->getText (), G7->getText (),
1238 G8->getText (), G9->getText (), G10->getText (), G11->getText ()
1240 WriteWord (GetNumber (KNUM->getText(), KNUM->getLine(), 2));
1241 AddVarStore (STRUCT_NAME->getText(), VAR_NAME->getText(), GetNumber (KNUM->getText(), KNUM->getLine(), 2), STRUCT_NAME->getLine());
1247 //*****************************************************************************
1250 // vareqval var(0x100) == 0x20
1253 OPID:VarEqVal << WriteOpByte (OPID->getLine(), EFI_IFR_EQ_VAR_VAL_OP); >>
1255 VAR:Number << WriteWord (GetNumber (VAR->getText(), VAR->getLine(), 2)); >>
1261 OPID:IdEqVal << WriteOpByte (OPID->getLine(), EFI_IFR_EQ_ID_VAL_OP); >>
1262 vfrStructFieldName[0]
1266 //*****************************************************************************
1269 // ideqid MyNVData3.Field16A == MyNVData3.Field16B
1271 // NOTE: Before processing the second variable store in the ideqid statement, set a global flag
1272 // so that when we parse the second variable we set the secondary variable store id.
1275 OPID:IdEqId << WriteOpByte (OPID->getLine(), EFI_IFR_EQ_ID_ID_OP); >>
1276 vfrStructFieldName[0]
1277 compareVfrStructFieldNameNL0
1280 //*****************************************************************************
1282 // compareNumber is the combination of compare operation and Number
1287 VAL1:Number << WriteWord (GetNumber (VAL1->getText(), VAL1->getLine(), 2)); >>
1291 VAL2:Number << WriteWord (GetNumber (VAL2->getText(), VAL2->getLine(), 2));
1292 WriteOpByte (GTOPID->getLine(), EFI_IFR_GT_OP); >>
1296 VAL3:Number << WriteWord (GetNumber (VAL3->getText(), VAL3->getLine(), 2));
1297 WriteOpByte (GEOPID->getLine(), EFI_IFR_GE_OP); >>
1301 VAL4:Number << WriteWord (GetNumber (VAL4->getText(), VAL4->getLine(), 2));
1302 WriteOpByte (LTOPID->getLine(), EFI_IFR_GE_OP);
1303 WriteOpByte (LTOPID->getLine(), EFI_IFR_NOT_OP); >>
1307 VAL5:Number << WriteWord (GetNumber (VAL5->getText(), VAL5->getLine(), 2));
1308 WriteOpByte (LEOPID->getLine(), EFI_IFR_GT_OP);
1309 WriteOpByte (LEOPID->getLine(), EFI_IFR_NOT_OP); >>
1313 //*****************************************************************************
1315 // compareVfrStructFieldNameNL0 is the combination of compare operation and vfrStructFieldNameNL[0]
1317 compareVfrStructFieldNameNL0 :
1319 "==" << mIdEqIdStmt = 1; >>
1320 vfrStructFieldNameNL[0] << mIdEqIdStmt = 0; >>
1323 GTOPID:GreaterThan << mIdEqIdStmt = 1; >>
1324 vfrStructFieldNameNL[0] << mIdEqIdStmt = 0;
1325 WriteOpByte (GTOPID->getLine(), EFI_IFR_GT_OP); >>
1328 GEOPID:GreaterEqual << mIdEqIdStmt = 1; >>
1329 vfrStructFieldNameNL[0] << mIdEqIdStmt = 0;
1330 WriteOpByte (GEOPID->getLine(), EFI_IFR_GE_OP); >>
1333 LTOPID:LessThan << mIdEqIdStmt = 1; >>
1334 vfrStructFieldNameNL[0] << mIdEqIdStmt = 0;
1335 WriteOpByte (LTOPID->getLine(), EFI_IFR_GE_OP);
1336 WriteOpByte (LTOPID->getLine(), EFI_IFR_NOT_OP); >>
1339 LEOPID:LessEqual << mIdEqIdStmt = 1; >>
1340 vfrStructFieldNameNL[0] << mIdEqIdStmt = 0;
1341 WriteOpByte (LEOPID->getLine(), EFI_IFR_GT_OP);
1342 WriteOpByte (LEOPID->getLine(), EFI_IFR_NOT_OP); >>
1348 OPID:IdEqValList << WriteOpByte (OPID->getLine(), EFI_IFR_EQ_ID_LIST_OP); >>
1349 vfrStructFieldName[0]
1351 ( VAL:Number << QueueIdEqValList (GetNumber (VAL->getText(), VAL->getLine(), 2)); >> ) +
1352 << FlushQueueIdEqValList(); >>
1356 << UINT32 LineNum, KeyValue = 0; ResetFlags (); >>
1357 IDG:Goto << WriteOpByte (IDG->getLine(), EFI_IFR_REF_OP); >>
1358 VAL:Number "," << WriteWord (GetNumber (VAL->getText(), VAL->getLine(), 2));
1359 AddGotoReference (GetNumber (VAL->getText(), VAL->getLine(), 2), VAL->getLine());
1361 KP:Prompt "=" getStringId "," << LineNum = KP->getLine(); >>
1362 Help "=" getStringId
1365 FF:Flags "=" flagsField ( "\|" flagsField )* << LineNum = FF->getLine(); >>
1368 "," Key "=" KNUM:Number << LineNum = KNUM->getLine(); KeyValue = GetNumber(KNUM->getText(), LineNum, 2); >>
1370 << WriteFlagsKey (KeyValue, LineNum); >>
1374 vfrStatementHidden :
1375 IDH:Hidden << WriteOpByte (IDH->getLine(), EFI_IFR_HIDDEN_OP); >>
1377 VAL:Number "," << WriteWord (GetNumber (VAL->getText(), VAL->getLine(), 2)); >>
1379 KVAL:Number << WriteWord (GetNumber (KVAL->getText(), KVAL->getLine(), 2)); >>
1383 //*****************************************************************************
1386 // suppressif <boolean_expression> { grayoutif } <statements>+ endif;
1388 // You can have: suppressif:grayoutif:statements:endif
1389 // suppressif:grayoutif:endif -- serves no purpose
1390 // suppressif:statements:endif
1391 // suppressif:endif -- serves no purpose
1393 vfrStatementSuppressIf :
1394 << ResetFlags (); >>
1395 OPID:SuppressIf << WriteOpByte (OPID->getLine(), EFI_IFR_SUPPRESS_IF_OP); SetIfStart (OPID->getLine()); >>
1397 FF:Flags "=" flagsField ( "\|" flagsField )* ","
1399 << WriteFlags (); >> // write the flags field
1400 vfrBooleanExpression
1402 { suppressIfGrayOutIf } ( suppressIfAndGrayoutIfSubstatements )+
1403 ENDOP:EndIf ";" << WriteOpByte (ENDOP->getLine(), EFI_IFR_END_IF_OP); SetIfStart (0); >>
1407 // This is the form for a grayoutif nested in a suppressif statement
1409 suppressIfGrayOutIf :
1410 << ResetFlags (); >>
1411 OPID:GrayOutIf << WriteOpByte (OPID->getLine(), EFI_IFR_GRAYOUT_IF_OP); >>
1413 FF:Flags "=" flagsField ( "\|" flagsField )* ","
1415 << WriteFlags (); >> // write the flags field
1416 vfrBooleanExpression
1420 //*****************************************************************************
1423 // grayoutif { flags = n, } <boolean_expression> endif;
1425 // You can have: grayoutif:suppressif:statements:endif
1426 // grayoutif:statements:endif
1429 vfrStatementGrayOutIf :
1430 << ResetFlags (); >>
1431 OPID:GrayOutIf << WriteOpByte (OPID->getLine(), EFI_IFR_GRAYOUT_IF_OP); SetIfStart (OPID->getLine()); >>
1433 FF:Flags "=" flagsField ( "\|" flagsField )* ","
1435 << WriteFlags (); >> // write the flags field
1436 vfrBooleanExpression
1438 { grayoutIfSuppressIf } ( suppressIfAndGrayoutIfSubstatements )+
1439 ENDOP:EndIf ";" << WriteOpByte (ENDOP->getLine(), EFI_IFR_END_IF_OP); SetIfStart (0); >>
1443 // This is the format for a suppressif nested in a grayoutif
1445 grayoutIfSuppressIf :
1446 << ResetFlags (); >>
1447 OPID:SuppressIf << WriteOpByte (OPID->getLine(), EFI_IFR_SUPPRESS_IF_OP); >>
1449 FF:Flags "=" flagsField ( "\|" flagsField )* ","
1451 << WriteFlags (); >> // write the flags field
1452 vfrBooleanExpression
1457 // These are the VFR statements that are valid inside a suppressif or grayoutif statement.
1459 suppressIfAndGrayoutIfSubstatements :
1461 vfrStatementTextText |
1462 vfrStatementCheckBox |
1463 vfrStatementNumeric |
1466 vfrStatementPassword |
1467 vfrStatementString |
1468 vfrStatementHidden |
1471 vfrStatementInventory |
1472 vfrStatementOrderedList |
1473 vfrStatementSaveRestoreDefaults
1476 //*****************************************************************************
1480 // password varid = MyNvData.Password,
1481 // prompt = STRING_TOKEN(STR_PASSWORD_PROMPT),
1482 // help = STRING_TOKEN(STR_PASSWORD_HELP),
1488 vfrStatementPassword :
1489 << UINT32 KeyValue = 0; UINT32 LineNum; ResetFlags (); >>
1490 IDPW:Password << WriteOpByte (IDPW->getLine(), EFI_IFR_PASSWORD_OP); >>
1491 VarId "=" vfrStructFieldNameArray[0] ","
1492 Prompt "=" getStringId ","
1493 KH:Help "=" getStringId "," << LineNum = KH->getLine(); >>
1495 FF:Flags "=" flagsField ( "\|" flagsField )* "," << LineNum = FF->getLine(); >>
1498 Key "=" KNUM:Number "," << LineNum = KNUM->getLine(); KeyValue = GetNumber(KNUM->getText(), LineNum, 2); >>
1500 << WriteFlagsKey (KeyValue, LineNum); >>
1501 MinSize "=" MIN:Number "," << WriteByte (GetNumber (MIN->getText(), MIN->getLine(), 1), 0); >>
1502 MaxSize "=" MAX:Number "," << WriteByte (GetNumber (MAX->getText(), MAX->getLine(), 1), 0); >>
1503 Encoding "=" ENC:Number "," << WriteWord (GetNumber (ENC->getText(), ENC->getLine(), 2)); >>
1507 //*****************************************************************************
1511 // string varid = MyNv.String,
1512 // prompt = STRING_TOKEN(STR_STRING_PROMPT),
1513 // help = STRING_TOKEN(STR_STRING_HELP),
1514 // flags = INTERACTIVE,
1520 // Since flags and key are optional, we can't use Flags->getLine(). Therefore for error
1521 // reporting we save the line number of the "help" keyword.
1523 vfrStatementString :
1524 << unsigned int KeyValue = 0; UINT32 LineNum; ResetFlags (); >>
1525 IDS:String << WriteOpByte (IDS->getLine(), EFI_IFR_STRING_OP); >>
1526 VarId "=" vfrStructFieldNameArray[0] ","
1527 Prompt "=" getStringId ","
1528 KH:Help "=" getStringId "," << LineNum = KH->getLine(); >>
1531 flagsField ( "\|" flagsField )* << LineNum = FF->getLine(); >>
1535 Key "=" KNUM:Number "," << LineNum = KNUM->getLine(); KeyValue = GetNumber(KNUM->getText(), LineNum, 2); >>
1537 << WriteFlagsKey (KeyValue, LineNum); >>
1538 MinSize "=" MIN:Number "," << WriteByte (GetNumber (MIN->getText(), MIN->getLine(), 1), 0); >>
1539 MaxSize "=" MAX:Number "," << WriteByte (GetNumber (MAX->getText(), MAX->getLine(), 1), 0); >>
1543 //*****************************************************************************
1546 // numeric varid = MyIfrNVData.HowOldAreYouInYears,
1547 // prompt = STRING_TOKEN(STR_NUMERIC_PROMPT),
1548 // help = STRING_TOKEN(STR_NUMERIC_HELP),
1549 // flags = INTERACTIVE, // flags is optional
1550 // key = 0x1234, // key is optional if (flags & INTERACTIVE = 0)
1553 // step = 1, // step is option, and step=1 if not specified
1554 // default = 0; // default is optional, and default=minimum if not specified
1557 // Make flags and key optional. However if flags includes INTERACTIVE, then a key is required.
1558 // That check is done in WriteFlagsKey() function.
1560 vfrStatementNumeric :
1561 << UINT32 LineNum, KeyValue = 0; ResetFlags (); >>
1562 IDN:Numeric << WriteOpByte (IDN->getLine(), EFI_IFR_NUMERIC_OP); >>
1563 VarId "=" vfrStructFieldName[2] ","
1564 Prompt "=" getStringId ","
1565 KH:Help "=" getStringId "," << LineNum = KH->getLine(); >>
1567 FF:Flags "=" flagsField ( "\|" flagsField )* "," << LineNum = FF->getLine (); >>
1570 Key "=" KNUM:Number "," << LineNum = KNUM->getLine(); KeyValue = GetNumber(KNUM->getText(), LineNum, 2); >>
1572 << WriteFlagsKey (KeyValue, LineNum); >>
1574 EndNumeric ";" << WriteMinMaxStepDefault (); >>
1578 // Parse minimum/maximum/step/default statements. Special cases:
1579 // - if step not specified, then the value is 1
1580 // - if default not specified, then the value is the min value specified
1581 // - if max < min, print a warning and swap the values (changes default too)
1584 << InitMinMaxStepDefault (); >>
1585 Minimum "=" MIN:Number "," << SetMinMaxStepDefault (GetNumber (MIN->getText(), MIN->getLine(), 2), 0, MIN->getLine()); >>
1586 Maximum "=" MAX:Number "," << SetMinMaxStepDefault (GetNumber (MAX->getText(), MAX->getLine(), 2), 1, MAX->getLine()); >>
1587 { Step "=" STEP:Number "," << SetMinMaxStepDefault (GetNumber (STEP->getText(), STEP->getLine(), 2), 2, STEP->getLine()); >> }
1588 { Default "=" DEF:Number "," << SetMinMaxStepDefault (GetNumber (DEF->getText(), DEF->getLine(), 2), 3, DEF->getLine()); >> }
1592 //*****************************************************************************
1596 // date year varid = Date.Year, // "Date.Year" is a special case we recognize
1597 // prompt = STRING_TOKEN(STR_DATE_PROMPT),
1598 // help = STRING_TOKEN(STR_DATE_YEAR_HELP),
1604 // month varid = Date.Month,
1605 // prompt = STRING_TOKEN(STR_DATE_PROMPT),
1606 // help = STRING_TOKEN(STR_DATE_MONTH_HELP),
1612 // day varid = Date.Day,
1613 // prompt = STRING_TOKEN(STR_DATE_PROMPT),
1614 // help = STRING_TOKEN(STR_DATE_DAY_HELP),
1624 IDY:Year VarId "=" << WriteOpByte (IDY->getLine(), EFI_IFR_DATE_OP); >>
1625 vfrStructFieldName[2] ","
1626 dateTimeSubStatement
1627 IDM:Month VarId "=" << WriteOpByte (IDM->getLine(), EFI_IFR_DATE_OP); >>
1628 vfrStructFieldName[2] ","
1629 dateTimeSubStatement
1630 IDD:Day VarId "=" << WriteOpByte (IDD->getLine(), EFI_IFR_DATE_OP); >>
1631 vfrStructFieldName[2] ","
1632 dateTimeSubStatement
1638 IDH:Hour VarId "=" << WriteOpByte (IDH->getLine(), EFI_IFR_TIME_OP); >>
1639 vfrStructFieldName[2] ","
1640 dateTimeSubStatement
1641 IDM:Minute VarId "=" << WriteOpByte (IDM->getLine(), EFI_IFR_TIME_OP); >>
1642 vfrStructFieldName[2] ","
1643 dateTimeSubStatement
1644 IDS:Second VarId "=" << WriteOpByte (IDS->getLine(), EFI_IFR_TIME_OP); >>
1645 vfrStructFieldName[2] ","
1646 dateTimeSubStatement
1650 //*****************************************************************************
1654 // text text = STRING_ID;
1655 // text text = STRING_ID, text = STRING_ID;
1656 // text text = STRING_ID, text = STRING_ID, flags = x, key = y;
1658 vfrStatementTextText :
1659 << ResetFlags (); >>
1660 IDT:Text << WriteOpByte (IDT->getLine(), EFI_IFR_TEXT_OP); >>
1661 Help "=" getStringId ","
1663 getStringId // writes string identifier
1664 { "," Text "=" getStringId
1665 "," Flags "=" flagsField ( "\|" flagsField )* << WriteFlags (); >>
1667 Key "=" KNUM:Number << WriteWord (GetNumber(KNUM->getText(), KNUM->getLine(), 2)); >>
1672 //*****************************************************************************
1676 // inventory help = ID, text = ID;
1677 // inventory help = ID, text = id, text = ID;
1679 vfrStatementInventory :
1680 IDI:Inventory << WriteOpByte (IDI->getLine(), EFI_IFR_INVENTORY_OP); >>
1681 Help "=" getStringId ","
1682 Text "=" getStringId // writes string identifier
1683 { "," Text "=" getStringId
1688 //*****************************************************************************
1692 // restore defaults,
1694 // prompt = STRING_TOKEN(STR_RESTORE_DEFAULTS_PROMPT),
1695 // help = STRING_TOKEN(STR_RESTORE_DEFAULTS_HELP),
1701 // prompt = STRING_TOKEN(STR_SAVE_DEFAULTS_PROMPT),
1702 // help = STRING_TOKEN(STR_SAVE_DEFAULTS_HELP),
1706 vfrStatementSaveRestoreDefaults :
1707 << unsigned int KeyValue = 0; UINT32 LineNum; ResetFlags (); >>
1708 ( IDS:Save << WriteOpByte (IDS->getLine(), EFI_IFR_SAVE_DEFAULTS_OP); >>
1709 | IDR:Restore << WriteOpByte (IDR->getLine(), EFI_IFR_RESTORE_DEFAULTS_OP); >>
1712 FormId "=" FRMID:Number "," << WriteWord (GetNumber (FRMID->getText(), FRMID->getLine(), 2));
1713 AddGotoReference (GetNumber (FRMID->getText(), FRMID->getLine(), 2), FRMID->getLine());
1715 Prompt "=" getStringId ","
1716 KH:Help "=" getStringId << LineNum = KH->getLine(); >>
1718 "," FF:Flags "=" flagsField ( "\|" flagsField )* << LineNum = FF->getLine(); >>
1721 "," Key "=" KNUM:Number << LineNum = KNUM->getLine(); KeyValue = GetNumber(KNUM->getText(), LineNum, 2); >>
1723 << WriteFlagsKey (KeyValue, LineNum); >>
1727 //*****************************************************************************
1731 // flags = 0x10 | DEFAULT | MANUFACTURING | INTERACTIVE | NV_ACCESS | RESET_REQUIRED | LATE_CHECK
1735 VAL:Number << SetFlags (GetNumber(VAL->getText(), VAL->getLine(), 4), VAL->getLine()); >>
1736 | IF:InteractiveFlag << SetFlags (EFI_IFR_FLAG_INTERACTIVE, IF->getLine()); >>
1737 | MF:ManufacturingFlag << SetFlags (EFI_IFR_FLAG_MANUFACTURING, MF->getLine()); >>
1738 | DF:DefaultFlag << SetFlags (EFI_IFR_FLAG_DEFAULT, DF->getLine()); >>
1739 | NV:NVAccessFlag << SetFlags (EFI_IFR_FLAG_NV_ACCESS, NV->getLine()); >>
1740 | RR:ResetRequiredFlag << SetFlags (EFI_IFR_FLAG_RESET_REQUIRED, RR->getLine()); >>
1741 | LC:LateCheckFlag << SetFlags (EFI_IFR_FLAG_LATE_CHECK, LC->getLine()); >>
1744 dateTimeSubStatement :
1745 Prompt "=" getStringId ","
1746 Help "=" getStringId ","
1747 << WriteByte (0, 0); WriteWord (0); >> // bogus flags and key
1748 minMaxStepDefault << WriteMinMaxStepDefault (); >>
1751 vfrStatementCheckBox :
1752 << UINT32 LineNum, KeyValue = 0; ResetFlags (); >>
1753 IDCB:CheckBox << WriteOpByte (IDCB->getLine(), EFI_IFR_CHECKBOX_OP); >>
1754 VarId "=" vfrStructFieldName[1] ","
1755 Prompt "=" getStringId ","
1756 Help "=" getStringId ","
1757 FF:Flags "=" flagsField ( "\|" flagsField )* "," << LineNum = FF->getLine(); >>
1759 Key "=" KV:Number "," << LineNum = KV->getLine(); KeyValue = GetNumber(KV->getText(), LineNum, 2); >>
1761 << WriteFlagsKey (KeyValue, LineNum); >>
1765 vfrStatementSubTitle :
1766 IDS:Subtitle Text "=" << WriteOpByte (IDS->getLine(), EFI_IFR_SUBTITLE_OP); >>
1767 getStringId // writes string indentifier
1771 //*****************************************************************************
1775 // title = STRING_TOKEN(STR_BANNER_TITLE),
1777 // align center; // or left or right
1780 // title = STRING_TOKEN(STR_BANNER_TITLE), timeout = 100;
1782 vfrStatementBanner :
1783 IDB:Banner { "," } << WriteOpByte (IDB->getLine(), EFI_IFR_BANNER_OP); >>
1784 Title "=" getStringId ","
1786 Line VAL:Number "," << WriteWord (GetNumber(VAL->getText(), VAL->getLine(), 2)); >>
1788 ( Left << WriteByte (EFI_IFR_BANNER_ALIGN_LEFT, 0); >>
1789 | Center << WriteByte (EFI_IFR_BANNER_ALIGN_CENTER, 0); >>
1790 | Right << WriteByte (EFI_IFR_BANNER_ALIGN_RIGHT, 0); >>
1793 Timeout "=" TO:Number ";" << WriteWord (GetNumber(TO->getText(), TO->getLine(), 2)); >>
1794 << WriteByte (EFI_IFR_BANNER_TIMEOUT, 0); >>
1798 //*****************************************************************************
1801 // oneof varid = MyNv.OneOfData,
1802 // prompt = STRING_TOKEN(STR_ONE_OF_PROMPT),
1803 // help = STRING_TOKEN(STR_ONE_OF_HELP),
1804 // option text = STRING_TOKEN(STR_ONE_OF_TEXT),
1806 // flags = DEFAULT | INTERACTIVE;
1808 // supressif/grayoutif are supported inside oneof stmt.
1809 // We do not restrict the number of oneOfOptionText to >=2, but >=1.
1810 // The situation that all oneOfOptionText are suppressed is also possiable.
1813 << ResetFlags (); >>
1814 IDOO:OneOf << WriteOpByte (IDOO->getLine(), EFI_IFR_ONE_OF_OP); >>
1815 VarId "=" vfrStructFieldName[2] ","
1816 Prompt "=" getStringId "," // writes string identifier
1817 Help "=" getStringId "," // writes string identifier
1818 ( oneOfOptionText )+ // there must be at least 1 option to be choosed, not 2.
1819 IDEOO:EndOneOf ";" << TestOneOfFlags (IDEOO->getLine()); WriteOpByte (IDEOO->getLine(), EFI_IFR_END_ONE_OF_OP); >>
1822 //*****************************************************************************
1826 // orderedlist varid = MyNv.OrderedListData,
1827 // prompt = STRING_TOKEN(STR_ORDERED_LIST_PROMPT),
1828 // help = STRING_TOKEN(STR_ORDERED_LIST_HELP),
1829 // option text = STRING_TOKEN(STR_ORDERED_LIST_TEXT), value = 0, flags = INTERACTIVE;
1830 // -- additional option text --
1833 vfrStatementOrderedList :
1834 << ResetFlags (); InitOrderedList(); >>
1835 IDOL:OrderedList << WriteOpByte (IDOL->getLine(), EFI_IFR_ORDERED_LIST_OP); >>
1836 VarId "=" vfrStructFieldNameArray[1] ","
1837 Prompt "=" getStringId "," // writes string identifier
1838 Help "=" getStringId "," // writes string identifier
1839 orderedListOptionText ( orderedListOptionText )+
1840 IDEOL:EndList ";" << WriteOpByte (IDEOL->getLine(), EFI_IFR_END_OP); EndOrderedList(IDEOL->getLine()); >>
1843 //*****************************************************************************
1847 // option text = STRING_TOKEN(STRING_ID), value = 0 flags = 99;
1849 // Differs from the oneOfOptionText in that we don't allow the DEFAULT flag to
1850 // be set, and value cannot be 0.
1852 orderedListOptionText :
1853 << UINT32 KeyValue = 0; >>
1854 IDO:Option << WriteOpByte (IDO->getLine(), EFI_IFR_ONE_OF_OPTION_OP); >>
1855 Text "=" getStringId "," // writes string identifier
1856 Value "=" WVAL:Number "," <<
1857 if (GetNumber(WVAL->getText(), WVAL->getLine(), 2) == 0) {
1858 PrintErrorMessage (WVAL->getLine(), "value=0 is invalid for ordered lists", NULL);
1860 WriteWord (GetNumber(WVAL->getText(), WVAL->getLine(), 2));
1863 FF:Flags "=" orderedListFlagsField
1864 ("\|" orderedListFlagsField )*
1866 "," Key "=" KV:Number << KeyValue = GetNumber (KV->getText(), KV->getLine(), 2); >>
1868 << WriteFlagsKey (KeyValue, FF->getLine()); >>
1869 ";" << mOptionCount++; >>
1872 //*****************************************************************************
1876 // flags = 0x10 | DEFAULT | MANUFACTURING | INTERACTIVE | NV_ACCESS | RESET_REQUIRED | LATE_CHECK
1878 // The ordered list flags field cannot have a default.
1880 orderedListFlagsField :
1881 VAL:Number << SetFlags (GetNumber(VAL->getText(), VAL->getLine(), 4), VAL->getLine()); >>
1882 | IF:InteractiveFlag << SetFlags (EFI_IFR_FLAG_INTERACTIVE, IF->getLine()); >>
1883 | MF:ManufacturingFlag << SetFlags (EFI_IFR_FLAG_MANUFACTURING, MF->getLine()); >>
1884 | NV:NVAccessFlag << SetFlags (EFI_IFR_FLAG_NV_ACCESS, NV->getLine()); >>
1885 | RR:ResetRequiredFlag << SetFlags (EFI_IFR_FLAG_RESET_REQUIRED, RR->getLine()); >>
1886 | LC:LateCheckFlag << SetFlags (EFI_IFR_FLAG_LATE_CHECK, LC->getLine()); >>
1887 | DF:DefaultFlag << PrintWarningMessage (DF->getLine(), "DEFAULT flag not valid for ordered lists", NULL); >>
1891 // Parse references to VFR structure field names of form "MyNvStructure.Field".
1892 // This implementation is specific to strings, passwords, and references in an
1893 // ordered list statement because we want to specify the size of the entire
1894 // field, rather than just one element. Then call a function to write out its
1895 // offset and length.
1897 vfrStructFieldNameArray[int FieldWidth] :
1898 << int ArrayIndex = 1; char IsArrayIndex = 0; >>
1899 SName:StringIdentifier
1901 SFieldName:StringIdentifier
1902 { OpenBracket AIndex:Number CloseBracket << ArrayIndex = GetNumber(AIndex->getText(), AIndex->getLine(), 4); IsArrayIndex = 1; >> }
1904 WriteFieldOffset (1,
1907 SFieldName->getText(),
1908 SFieldName->getLine(),
1918 // Parse references to VFR structure field names of form "MyNvStructure.Field",
1919 // then call a function to write out its offset and length.
1921 vfrStructFieldName[int FieldWidth] :
1922 << int ArrayIndex = 1; char IsArrayIndex = 0; >>
1923 SName:StringIdentifier
1925 SFieldName:StringIdentifier
1926 { OpenBracket AIndex:Number CloseBracket << ArrayIndex = GetNumber(AIndex->getText(), AIndex->getLine(), 4); IsArrayIndex = 1; >> }
1928 WriteFieldOffset (1,
1931 SFieldName->getText(),
1932 SFieldName->getLine(),
1941 //*****************************************************************************
1945 // MyNvStructure.FieldName[4]
1947 // Parse references to VFR structure field names of form "MyNvStructure.Field",
1948 // then call a function to write out the offset with no length.
1950 vfrStructFieldNameNL[int FieldWidth] :
1951 << int ArrayIndex = 1; char IsArrayIndex = 0; >>
1952 SName:StringIdentifier
1954 SFieldName:StringIdentifier
1955 { OpenBracket AIndex:Number CloseBracket << ArrayIndex = GetNumber(AIndex->getText(), AIndex->getLine(), 4); IsArrayIndex = 1; >> }
1957 WriteFieldOffset (0,
1960 SFieldName->getText(),
1961 SFieldName->getLine(),
1970 //*****************************************************************************
1973 // suppressif TRUE OR FALSE;
1974 // grayoutif FALSE OR TRUE;
1975 // option text = STRING_TOKEN(STRING_ID), value = 0 flags = 99;
1976 // option text = STRING_TOKEN(STRING_ID2), value = 1 flags = 98;
1980 suppressIfOptionText |
1981 grayOutIfOptionText |
1985 suppressIfOptionText :
1986 << ResetFlags (); >>
1987 OPID:SuppressIf << WriteOpByte (OPID->getLine(), EFI_IFR_SUPPRESS_IF_OP); SetIfStart (OPID->getLine()); >>
1989 FF:Flags "=" flagsField ( "\|" flagsField )* ","
1991 << WriteFlags (); >> // write the flags field
1992 vfrBooleanExpression
1994 { suppressIfGrayOutIf } ( commonOptionText )+
1995 ENDOP:EndIf ";" << WriteOpByte (ENDOP->getLine(), EFI_IFR_END_IF_OP); SetIfStart (0); >>
1998 grayOutIfOptionText :
1999 << ResetFlags (); >>
2000 OPID:GrayOutIf << WriteOpByte (OPID->getLine(), EFI_IFR_GRAYOUT_IF_OP); SetIfStart (OPID->getLine()); >>
2002 FF:Flags "=" flagsField ( "\|" flagsField )* ","
2004 << WriteFlags (); >> // write the flags field
2005 vfrBooleanExpression
2007 { grayoutIfSuppressIf } ( commonOptionText )+
2008 ENDOP:EndIf ";" << WriteOpByte (ENDOP->getLine(), EFI_IFR_END_IF_OP); SetIfStart (0); >>
2012 << UINT32 KeyValue = 0; >>
2013 IDO:Option << WriteOpByte (IDO->getLine(), EFI_IFR_ONE_OF_OPTION_OP); >>
2014 Text "=" getStringId "," // writes string identifier
2015 Value "=" WVal:Number "," << WriteWord (GetNumber(WVal->getText(), WVal->getLine(), 2)); >>
2016 FF:Flags "=" flagsField ("\|" flagsField )*
2018 "," Key "=" KV:Number << KeyValue = GetNumber (KV->getText(), KV->getLine(), 2); >>
2020 << WriteFlagsKey (KeyValue, FF->getLine()); >>
2021 ";" << mOptionCount++; >>
2025 // Gets a string identifier. It must be a numeric value of form:
2027 // STRING_TOKEN(100)
2030 << unsigned short StrId; >>
2031 StringToken OpenParen
2032 IdVal:Number << StrId = GetNumber (IdVal->getText(), IdVal->getLine(), 2); WriteStringIdWord (StrId); >>
2036 //******************************************************************************
2038 // Parser class definition.
2040 class EfiVfrParser {
2043 // Parser definitions go here
2046 STRUCT_DEFINITION *mFirstStructDefinition;
2047 STRUCT_DEFINITION *mLastStructDefinition;
2048 INT32 mNvDataStructSize;
2049 INT32 mNonNvDataStructSize;
2051 // Flag to indicate that we're processing a ideqid VFR statement so that
2052 // we can do late checks on the statement.
2055 INT32 mLastNVVariableDataSize;
2056 GOTO_REFERENCE *mGotoReferences;
2057 FORM_ID_VALUE *mFormIdValues;
2058 VfrOpcodeHandler mOpcodeHandler;
2059 UINT16_LIST *mUint16List;
2060 UINT16_LIST *mLastUint16;
2061 UINT16_LIST *mDefinedLabels;
2062 UINT16_LIST *mDefinedVarStoreId;
2063 UINT16_LIST *mLastDefinedVarStoreId;
2064 UINT32 mMinimumValue, mMaximumValue, mStepValue, mDefaultValue;
2066 UINT32 mSubStmtFlags;
2067 UINT32 mSubStmtFlagsLineNum;
2068 EFI_GUID mFormSetGuid;
2069 UINT8 mNvDataStructDefined;
2070 UINT16 mClass, mSubclass;
2072 UINT32 mOptionCount; // how many "option" fields in a given statement
2073 UINT32 mLastVarIdSize;
2078 EfiVfrParser::SetIfStart (
2083 Routine Description:
2084 Invoked during VFR parsing when an "if" is encountered. Save the
2085 source line number so we can point to it if we don't find a
2086 corresponding endif later.
2089 LineNum - source line number where the "if" was parsed.
2099 EfiVfrParser::SetClass (
2105 Routine Description:
2106 Invoked during VFR parsing when a "class" statement is found. Check the
2107 range on the class value and save it for later.
2110 LineNum - source line number where the class statement was parsed.
2111 Value - the class value
2118 if (Value & 0xFFFF0000) {
2119 PrintWarningMessage (LineNum, NULL, "class value exceeds maximum allowed");
2121 mClass |= (UINT16)Value;
2124 EfiVfrParser::SetSubclass (
2130 Routine Description:
2131 Invoked during VFR parsing when a subclass statement is found. Check the
2132 range on the value and save it for later.
2135 LineNum - source line number where the class statement was parsed.
2136 Value - the subclass value from the VFR statement
2143 if (Value & 0xFFFF0000) {
2144 PrintWarningMessage (LineNum, NULL, "subclass value exceeds maximum allowed");
2146 mSubclass |= (UINT16)Value;
2148 VOID EfiVfrParser::WriteClass ()
2153 VOID EfiVfrParser::WriteSubclass ()
2155 WriteWord (mSubclass);
2158 VOID EfiVfrParser::WriteIfrBytes ()
2160 mOpcodeHandler.WriteIfrBytes ();
2163 EfiVfrParser::WriteFlagsKey (
2169 Routine Description:
2170 Write out the flags and key values from the previous VFR statement.
2171 Many statements take a flags/key pair. If not specified, then 0
2172 values are written out. However do not allow an interactive flags field
2173 to be specified if no key value is specified. Also, if NV_ACCESS flag
2174 is set but INTERACTIVE is not, then set interactive and issue a warning.
2177 KeyValue - the key value from the VFR statement
2178 LineNum - source line number where the statement was parsed
2185 if ((mSubStmtFlags & EFI_IFR_FLAG_INTERACTIVE) && (KeyValue == 0)) {
2186 PrintErrorMessage (LineNum, NULL, "invalid or missing key value - required with INTERACTIVE");
2188 if ((mSubStmtFlags & EFI_IFR_FLAG_NV_ACCESS) && !(mSubStmtFlags & EFI_IFR_FLAG_INTERACTIVE)) {
2189 PrintWarningMessage (LineNum, NULL, "NV_ACCESS without INTERACTIVE has no effect -- setting INTERACTIVE");
2190 mSubStmtFlags |= EFI_IFR_FLAG_INTERACTIVE;
2193 WriteWord (KeyValue);
2196 EfiVfrParser::InitOrderedList ()
2201 EfiVfrParser::EndOrderedList (
2205 if (mLastVarIdSize < mOptionCount) {
2206 PrintErrorMessage (LineNum, NULL, "number of options exceeds the variable store size");
2210 EfiVfrParser::ResetFlags ()
2213 Routine Description:
2215 Flags are set for each substatement in a given one-of statement.
2216 To make sure there are no conflicts, for example setting DEFAULT on
2217 more than one substatement, we keep track of the flags at a statement
2218 level and a substatement level. This function resets the flags so
2219 we get a fresh start.
2230 mSubStmtFlagsLineNum = 0;
2234 // Test validity of flags value for a one-of statement.
2237 EfiVfrParser::TestOneOfFlags (
2242 // One of the fields must have had the default bit set
2244 if ((mStmtFlags & EFI_IFR_FLAG_DEFAULT) == 0) {
2245 PrintWarningMessage (LineNum, "default value must be specified", NULL);
2249 EfiVfrParser::SetFlags (
2255 // Check for redefinitions and invalid combinations
2257 if (mStmtFlags & Flags & EFI_IFR_FLAG_MANUFACTURING) {
2258 PrintErrorMessage (LineNum, "MANUFACTURING", "a field with this flag already defined");
2260 if (mStmtFlags & Flags & EFI_IFR_FLAG_DEFAULT) {
2261 PrintErrorMessage (LineNum, "DEFAULT", "a field with this flag already defined");
2263 mSubStmtFlags |= Flags;
2264 mSubStmtFlagsLineNum = LineNum;
2267 EfiVfrParser::WriteFlags ()
2270 // Check value for validity
2272 if (mSubStmtFlags & ~(EFI_IFR_FLAG_DEFAULT |
2273 EFI_IFR_FLAG_MANUFACTURING |
2274 EFI_IFR_FLAG_INTERACTIVE |
2275 EFI_IFR_FLAG_NV_ACCESS |
2276 EFI_IFR_FLAG_RESET_REQUIRED |
2277 EFI_IFR_FLAG_LATE_CHECK )) {
2278 PrintWarningMessage (mSubStmtFlagsLineNum, "invalid bits defined in flag", NULL);
2280 WriteByte ((UINT8)mSubStmtFlags, 'F');
2282 // We can now clear the substatement flags
2284 mStmtFlags |= mSubStmtFlags;
2288 // When we parse a min/max/step/default sequence, save off the values for
2289 // later use. Call this first to init the values.
2292 EfiVfrParser::InitMinMaxStepDefault ()
2300 EfiVfrParser::WriteMinMaxStepDefault ()
2302 WriteWord (mMinimumValue);
2303 WriteWord (mMaximumValue);
2304 WriteWord (mStepValue);
2305 WriteWord (mDefaultValue);
2308 EfiVfrParser::SetMinMaxStepDefault (
2319 mMinimumValue = Value;
2320 mDefaultValue = Value;
2324 } else if (MMSD == 1) {
2325 mMaximumValue = Value;
2327 // If min > max, then swap the values. That includes resetting the default
2330 if (mMinimumValue > mMaximumValue) {
2331 PrintWarningMessage (LineNum, NULL, "maximum < minimum");
2333 mMaximumValue = mMinimumValue;
2334 mMinimumValue = TempValue;
2335 mDefaultValue = mMinimumValue;
2340 } else if (MMSD == 2) {
2343 // Default specified. Make sure min <= default <= max.
2345 } else if (MMSD == 3) {
2346 mDefaultValue = Value;
2347 if (mMinimumValue > Value) {
2348 PrintErrorMessage (LineNum, NULL, "default value < minimum value");
2349 } else if (Value > mMaximumValue) {
2350 PrintErrorMessage (LineNum, NULL, "default value > maximum value");
2353 PrintErrorMessage (LineNum, "application error", "internal MMSD error");
2357 EfiVfrParser::AddLabel (
2365 // Added a label from the user VFR script. Make sure they haven't already
2366 // defined the same label elsewhere
2368 for (Label = mDefinedLabels; Label != NULL; Label = Label->Next) {
2369 if (Label->Value == LabelNumber) {
2370 PrintErrorMessage (LineNum, NULL, "label already defined");
2371 PrintErrorMessage (Label->LineNum, NULL, "previous definition of redefined label");
2375 Label = (UINT16_LIST *)malloc (sizeof (UINT16_LIST));
2376 if (Label == NULL) {
2377 PrintErrorMessage (0, NULL, "memory allocation error");
2380 memset ((char *)Label, 0, sizeof (UINT16_LIST));
2381 Label->Value = LabelNumber;
2382 Label->LineNum = LineNum;
2383 Label->Next = mDefinedLabels;
2384 mDefinedLabels = Label;
2387 EfiVfrParser::QueueIdEqValList (
2393 U16 = (UINT16_LIST *)malloc (sizeof (UINT16_LIST));
2395 Error (PROGRAM_NAME, 0, 0, NULL, "memory allocation failed");
2397 memset ((char *)U16, 0, sizeof (UINT16_LIST));
2399 if (mUint16List == NULL) {
2402 mLastUint16->Next = U16;
2408 EfiVfrParser::FlushQueueIdEqValList ()
2413 // We queued up a list of IdEqValList items. The IFR requires a count
2414 // followed by the actual values. Do it.
2417 mLastUint16 = mUint16List;
2418 while (mLastUint16 != NULL) {
2420 mLastUint16 = mLastUint16->Next;
2422 // BUGBUG -- check for more than 16K items?
2425 // Now write the values.
2427 mLastUint16 = mUint16List;
2428 while (mLastUint16 != NULL) {
2429 WriteWord ((UINT32)mLastUint16->Value);
2430 mLastUint16 = mLastUint16->Next;
2435 mLastUint16 = mUint16List;
2436 while (mUint16List != NULL) {
2437 mLastUint16 = mUint16List->Next;
2439 mUint16List = mLastUint16;
2443 EfiVfrParser::PrintErrorMessage (
2452 FileName = ConvertLineNumber ((UINT32 *)&LineNum);
2453 Error (FileName, LineNum, 0, Msg1, Msg2);
2455 Error (PROGRAM_NAME, 0, 0, Msg1, Msg2);
2459 EfiVfrParser::PrintWarningMessage (
2468 FileName = ConvertLineNumber ((UINT32 *)&LineNum);
2469 Warning (FileName, LineNum, 0, Msg1, Msg2);
2471 Warning (PROGRAM_NAME, 0, 0, Msg1, Msg2);
2476 ANTLRAbstractToken *Tok,
2479 ANTLRTokenType ETok,
2484 Routine Description:
2485 Called by the parser base class as a result of parse syntax errors.
2488 Tok - token that caused the error
2490 Eset - index in token table of the expected token
2501 LineNum = Tok->getLine ();
2502 FileName = ConvertLineNumber ((UINT32 *)&LineNum);
2504 // Sometimes the token number is 0, in which case I don't know what to
2508 Error (FileName, LineNum, 0, Tok->getText (), "unexpected token");
2511 // If we were expecting an endif, then report the line where the corresponding
2514 if ((strcmp (_token_tbl[ETok], "endif") == 0) && (mIfStart != 0)) {
2516 FileName = ConvertLineNumber (&LineNum);
2517 Error (FileName, LineNum, 0, "statement missing corresponding endif", NULL);
2519 Error (FileName, LineNum, 0, Tok->getText (), "expected %s", _token_tbl[ETok]);
2525 EfiVfrParser::init()
2528 Routine Description:
2529 Initializations function for our parser.
2539 ANTLRParser::init();
2542 // Used for queuing a variable list of UINT16's
2546 mFirstStructDefinition = NULL;
2547 mLastStructDefinition = NULL;
2548 mNvDataStructSize = 0;
2549 mNonNvDataStructSize = 0;
2550 mNvDataStructDefined = 0;
2551 mGotoReferences = NULL;
2552 mFormIdValues = NULL;
2553 mDefinedLabels = NULL;
2557 mDefinedVarStoreId = NULL;
2558 mLastDefinedVarStoreId = NULL;
2560 mLastNVVariableDataSize = 0;
2562 memset ((char *)&mFormSetGuid, 0, sizeof (EFI_GUID));
2565 // Destructor for the parser.
2567 EfiVfrParser::~EfiVfrParser(VOID)
2572 EfiVfrParser::Cleanup (VOID)
2575 Routine Description:
2576 Free memory allocated during parsing
2586 STRUCT_DEFINITION *NextStruct;
2587 STRUCT_FIELD_DEFINITION *NextField;
2589 UINT16_LIST *NextU16List;
2592 // Free up the structure definitions if any
2594 while (mFirstStructDefinition != NULL) {
2596 // Free up all the fields for this struct
2598 while (mFirstStructDefinition->Field != NULL) {
2599 NextField = mFirstStructDefinition->Field->Next;
2600 free (mFirstStructDefinition->Field->Name);
2601 free (mFirstStructDefinition->Field);
2602 mFirstStructDefinition->Field = NextField;
2604 NextStruct = mFirstStructDefinition->Next;
2605 free (mFirstStructDefinition->Name);
2606 free (mFirstStructDefinition);
2607 mFirstStructDefinition = NextStruct;
2610 // Free up the goto references and form id defines
2612 FreeGotoReferences ();
2614 // Free up label list
2616 while (mDefinedLabels != NULL) {
2617 NextU16List = mDefinedLabels->Next;
2618 delete (mDefinedLabels);
2619 mDefinedLabels = NextU16List;
2622 // Free up the list of defined variable storage IDs
2624 while (mDefinedVarStoreId != NULL) {
2625 NextU16List = mDefinedVarStoreId->Next;
2626 delete (mDefinedVarStoreId);
2627 mDefinedVarStoreId = NextU16List;
2632 EfiVfrParser::AtoX (
2639 Routine Description:
2640 Given a pointer to a ascii hex string, convert to a number with the given
2644 HexString - pointer to a string of format 30BCA
2645 Size - number of bytes to convert
2646 HexValue - return result
2649 The number of bytes converted.
2658 while (Count < NumBytes) {
2659 if ((*HexString >= '0') && (*HexString <= '9')) {
2660 Value = *HexString - '0';
2661 } else if ((*HexString >= 'a') && (*HexString <= 'f')) {
2662 Value = *HexString - 'a' + 10;
2663 } else if ((*HexString >= 'A') && (*HexString <= 'F')) {
2664 Value = *HexString - 'A' + 10;
2669 *HexValue = (*HexValue << 4) | Value;
2670 if ((*HexString >= '0') && (*HexString <= '9')) {
2671 Value = *HexString - '0';
2672 } else if ((*HexString >= 'a') && (*HexString <= 'f')) {
2673 Value = *HexString - 'a' + 10;
2674 } else if ((*HexString >= 'A') && (*HexString <= 'F')) {
2675 Value = *HexString - 'A' + 10;
2679 *HexValue = (*HexValue << 4) | Value;
2686 EfiVfrParser::WriteGuidValue (
2687 UINT32 TokenLineNum,
2702 Routine Description:
2703 A Guid was parsed, likely of format:
2704 #define MY_GUID { 0x12345678, 0xAABB, 0xCCDD, 0xEE, 0xFF, 0x11, 0x22, 0x33, 0x44, 0x55, 0x66 }
2706 Write out the value.
2709 TokenLineNum - line number where the guid was used
2710 G1-G11 - the 11 fields of the guid value
2720 mFormSetGuid.Data1 = GetNumber (G1, TokenLineNum, 4);
2721 mFormSetGuid.Data2 = (UINT16)GetNumber (G2, TokenLineNum, 2);
2722 mFormSetGuid.Data3 = (UINT16)GetNumber (G3, TokenLineNum, 2);
2723 mFormSetGuid.Data4[0] = (UINT8)GetNumber (G4, TokenLineNum, 1);
2724 mFormSetGuid.Data4[1] = (UINT8)GetNumber (G5, TokenLineNum, 1);
2725 mFormSetGuid.Data4[2] = (UINT8)GetNumber (G6, TokenLineNum, 1);
2726 mFormSetGuid.Data4[3] = (UINT8)GetNumber (G7, TokenLineNum, 1);
2727 mFormSetGuid.Data4[4] = (UINT8)GetNumber (G8, TokenLineNum, 1);
2728 mFormSetGuid.Data4[5] = (UINT8)GetNumber (G9, TokenLineNum, 1);
2729 mFormSetGuid.Data4[6] = (UINT8)GetNumber (G10, TokenLineNum, 1);
2730 mFormSetGuid.Data4[7] = (UINT8)GetNumber (G11, TokenLineNum, 1);
2732 WriteDWord (mFormSetGuid.Data1, 'G');
2733 WriteWord (mFormSetGuid.Data2);
2734 WriteWord (mFormSetGuid.Data3);
2735 WriteByte (mFormSetGuid.Data4[0], 0);
2736 WriteByte (mFormSetGuid.Data4[1], 0);
2737 WriteByte (mFormSetGuid.Data4[2], 0);
2738 WriteByte (mFormSetGuid.Data4[3], 0);
2739 WriteByte (mFormSetGuid.Data4[4], 0);
2740 WriteByte (mFormSetGuid.Data4[5], 0);
2741 WriteByte (mFormSetGuid.Data4[6], 0);
2742 WriteByte (mFormSetGuid.Data4[7], 0);
2745 EfiVfrParser::WriteFieldOffset (
2758 Routine Description:
2759 A VFR script referenced the NV store structure. Given the structure's name
2760 and the field's name, write the offset of the field to the output file.
2763 WriteLength - write the field length byte out
2764 StructName - name of the NV store structure
2765 LineNum1 - line number in the VFR where we are (for error printing)
2766 FieldName - the name of the field within the NV store structure
2767 LineNum2 - line number in the VFR where FieldName is referenced
2768 ArrayIndex - the index specified, for example NV_DATA.Field[ArrayIndex]
2769 IsArrayIndex - non-zero if an array index was specified
2770 FieldWidth - expected size for the Field (1 byte? 2 bytes?)
2771 WriteArraySize - write the size of the entire field, not the size of a single element
2778 STRUCT_DEFINITION *StructDef;
2779 STRUCT_FIELD_DEFINITION *FieldDef;
2784 // If we're writing an array size, then they better have referenced the field without an
2787 if (WriteArraySize && IsArrayIndex) {
2788 sprintf (Msg, "array index specified where an array is required");
2789 PrintErrorMessage (LineNum2, FieldName, Msg);
2793 // Look through our list of known structures for a match
2795 for (StructDef = mFirstStructDefinition; StructDef != NULL; StructDef = StructDef->Next) {
2797 // Check for matching structure name
2799 if (strcmp (StructDef->Name, StructName) == 0) {
2801 // Mark it as referenced (for debug purposes only). Check the
2802 // flag that indicates that we have already found a varstore VFR
2803 // statement for it.
2805 StructDef->Referenced++;
2806 if (StructDef->VarStoreIdValid == 0) {
2808 // Set it valid so we don't flag it multiple times, then emit the error
2810 StructDef->VarStoreIdValid = 1;
2811 PrintErrorMessage (LineNum1, StructName, "varstore statement missing for this variable store");
2814 // Let the opcode-handler know which variable storage we're now using
2817 mOpcodeHandler.SetSecondaryVarStoreId (StructDef->VarStoreId);
2819 mOpcodeHandler.SetVarStoreId (StructDef->VarStoreId);
2822 // Found matching structure name. Now find the matching field name
2824 for (FieldDef = StructDef->Field; FieldDef != NULL; FieldDef = FieldDef->Next) {
2825 if (strcmp (FieldDef->Name, FieldName) == 0) {
2827 // Make sure the variable size is valid
2829 if ((FieldWidth != 0) && (FieldDef->DataSize > FieldWidth)) {
2830 sprintf (Msg, "field width exceeds %d byte%c", FieldWidth, FieldWidth == 1 ? ' ' : 's');
2831 PrintErrorMessage (LineNum2, FieldName, Msg);
2834 // If they specified an index (MyVfrData.FieldX[10]), then make sure that the
2835 // data structure was declared as an array, and that the index is in bounds.
2836 // If they did not specify an index, then we'll assume 0. This is required for
2840 VarSize = FieldDef->DataSize;
2841 if (FieldDef->IsArray == 0) {
2842 PrintErrorMessage (LineNum2, FieldName, "field is not declared as an array");
2845 if (FieldDef->ArrayLength < ArrayIndex) {
2846 PrintErrorMessage (LineNum2, FieldName, "array index exceeds declared size of field");
2850 if (FieldDef->IsArray) {
2851 VarSize = FieldDef->DataSize * FieldDef->ArrayLength;
2853 VarSize = FieldDef->DataSize;
2857 // If we're in the middle of a ideqid VFR statement, then this is the second
2858 // variable ID that we're now processing. Make sure that its size is the same
2859 // as the first variable.
2862 if (mLastVarIdSize != VarSize) {
2863 PrintErrorMessage (LineNum2, FieldName, "variables must have the same size");
2867 mLastVarIdSize = VarSize;
2869 // If we're supposed to write an array size, then require it to be an array
2871 if (WriteArraySize && !FieldDef->IsArray) {
2872 PrintErrorMessage (LineNum2, FieldName, "array required");
2876 // Write the variable offset and size. If we're in the non-NV structure, then
2877 // set the offset beyond the NV data structure size.
2879 Offset = FieldDef->Offset + FieldDef->DataSize * (ArrayIndex - 1);
2880 if (StructDef->IsNonNV) Offset += mNvDataStructSize;
2883 if (WriteArraySize) {
2884 if (FieldDef->DataSize * FieldDef->ArrayLength > 255) {
2885 PrintErrorMessage (LineNum2, FieldName, "array size exceeds 255 maximum encoding limit");
2888 WriteByte (FieldDef->DataSize * FieldDef->ArrayLength, 0);
2890 WriteByte (FieldDef->DataSize, 0);
2896 sprintf (Msg, "structure %s does not have a field named '%s'", StructName, FieldName);
2897 PrintErrorMessage (LineNum2, Msg, NULL);
2898 PrintErrorMessage (StructDef->LineNum, "see structure definition", NULL);
2903 // The structure was not found in the defined list. See if it's the "Date" structure
2905 if (strcmp (StructName, "Date") == 0) {
2907 // BUGBUG -- remove support for Date and Time as valid structure
2908 // names. They should use the NON_NV_DATA_MAP structure for this.
2910 // Someone specified Date.Years|Months|Days
2911 // BUGBUG -- define some constants for the IDs used here
2912 // Length == 0 implies that this is not user NV data storage.
2914 if (strcmp (FieldName, "Year") == 0) {
2916 // Write ID (offset), ID, and size
2918 WriteWord (mNvDataStructSize + mNonNvDataStructSize + 0);
2922 } else if (strcmp (FieldName, "Month") == 0) {
2924 // Write ID (offset), ID, and size
2926 WriteWord (mNvDataStructSize + mNonNvDataStructSize + 2);
2930 } else if (strcmp (FieldName, "Day") == 0) {
2932 // Write ID (offset), ID, and size
2934 WriteWord (mNvDataStructSize + mNonNvDataStructSize + 4);
2939 PrintErrorMessage (LineNum1, FieldName, "expected valid field name TheYear/TheMonth/TheDay");
2942 } else if (strcmp (StructName, "Time") == 0) {
2944 // Someone specified Time.Hours|Minutes|Seconds
2945 // BUGBUG -- define some constants for the IDs used here
2947 if (strcmp (FieldName, "Hours") == 0) {
2949 // Write ID (offset), ID, and size
2951 WriteWord (mNvDataStructSize + mNonNvDataStructSize + 6);
2955 } else if (strcmp (FieldName, "Minutes") == 0) {
2957 // Write ID (offset), ID, and size
2959 WriteWord (mNvDataStructSize + mNonNvDataStructSize + 8);
2963 } else if (strcmp (FieldName, "Seconds") == 0) {
2965 // Write ID (offset), ID, and size
2967 WriteWord (mNvDataStructSize + mNonNvDataStructSize + 10);
2972 PrintErrorMessage (LineNum1, FieldName, "expected valid field name Hours/Minutes/Seconds");
2976 PrintErrorMessage (LineNum1, StructName, "undefined structure");
2981 EfiVfrParser::StartStructDefinition (
2987 Routine Description:
2988 Called when we encounter a new "struct _MY_STRUCT..." statement while parsing.
2989 Initialize internal data and structures for parsing the fields of the structure.
2992 LineNum - line number in the source file (for error reporting purposes)
2993 IsNonNv - flag indicating (if nonzero) that the variable referred to is not in
2994 the standard NV store.
3000 STRUCT_DEFINITION *StructDef;
3002 // Allocate memory for the structure record
3004 StructDef = (STRUCT_DEFINITION *)malloc (sizeof (STRUCT_DEFINITION));
3005 memset (StructDef, 0, sizeof (STRUCT_DEFINITION));
3006 StructDef->LineNum = LineNum;
3008 // Set flag indicating non-NV data structure or not
3010 StructDef->IsNonNV = IsNonNV;
3012 // Add it to the end of our linked list. If it's the first one
3013 // defined, then it's the default varstore ID, so set it valid.
3015 if (mFirstStructDefinition == NULL) {
3016 mFirstStructDefinition = StructDef;
3017 StructDef->VarStoreIdValid = 1;
3019 mLastStructDefinition->Next = StructDef;
3021 mLastStructDefinition = StructDef;
3024 EfiVfrParser::EndStructDefinition (
3029 STRUCT_DEFINITION *StructDef;
3030 STRUCT_FIELD_DEFINITION *FieldDef;
3033 // Make sure they have not already defined a structure with this name
3035 for (StructDef = mFirstStructDefinition; StructDef != NULL; StructDef = StructDef->Next) {
3036 if ((StructDef->Name != NULL) && (strcmp (StructDef->Name, StructName) == 0)) {
3037 PrintErrorMessage (LineNum, StructName, "structure with this name already defined");
3039 // Fall through and fill in the rest of the structure information. We do
3040 // this because the structure has already been added to our global list,
3041 // so will be used elsewhere, so we want it to contain valid fields.
3046 // Allocate memory for the structure name
3048 mLastStructDefinition->Name = (char *)malloc (strlen (StructName) + 1);
3049 strcpy (mLastStructDefinition->Name, StructName);
3051 // Compute the structure size, and the offsets to each field
3054 for (FieldDef = mLastStructDefinition->Field; FieldDef != NULL; FieldDef = FieldDef->Next) {
3055 FieldDef->Offset = Offset;
3056 Offset += FieldDef->ArrayLength * FieldDef->DataSize;
3058 mLastStructDefinition->Size = Offset;
3060 // Go through all the structure we have so far and figure out (if we can)
3061 // the size of the non-NV storage. We also assume that the first structure
3062 // definition is the primary/default storage for the VFR form.
3064 if (mNonNvDataStructSize == 0) {
3065 for (StructDef = mFirstStructDefinition; StructDef != NULL; StructDef = StructDef->Next) {
3066 if (StructDef->IsNonNV) {
3067 mNonNvDataStructSize = StructDef->Size;
3072 if (mNvDataStructSize == 0) {
3073 for (StructDef = mFirstStructDefinition; StructDef != NULL; StructDef = StructDef->Next) {
3074 if (StructDef->IsNonNV == 0) {
3075 mNvDataStructSize = StructDef->Size;
3082 EfiVfrParser::AddStructField (
3091 Routine Description:
3092 We're parsing the VFR structure definition. Add another defined field to
3096 FieldName - name of the field in the structure.
3097 LineNum - the line number from the input (preprocessor output) file
3098 DataSize - the size of the field (1, 2, or 4 bytes)
3099 ArrayLength - the number of elements (for array)
3100 IsArray - non-zero if the field is an array
3107 STRUCT_FIELD_DEFINITION *FieldDef;
3108 STRUCT_FIELD_DEFINITION *Temp;
3110 // Make sure we don't already have a field of this name in our structure
3112 for (FieldDef = mLastStructDefinition->Field; FieldDef != NULL; FieldDef = FieldDef->Next) {
3113 if (strcmp (FieldDef->Name, FieldName) == 0) {
3114 PrintErrorMessage (LineNum, FieldName, "field with this name already defined");
3119 // If it's an array, then they better not have a size of 0. For example:
3120 // UINT8 MyBytes[0];
3122 if (IsArray && (ArrayLength <= 0)) {
3123 PrintErrorMessage (LineNum, FieldName, "invalid array size");
3127 // Allocate memory for a new structure field definition
3129 FieldDef = (STRUCT_FIELD_DEFINITION *)malloc (sizeof (STRUCT_FIELD_DEFINITION));
3130 memset ((char *)FieldDef, 0, sizeof (STRUCT_FIELD_DEFINITION));
3131 FieldDef->ArrayLength = ArrayLength;
3132 FieldDef->DataSize = DataSize;
3133 FieldDef->IsArray = IsArray;
3134 FieldDef->Name = (char *)malloc (strlen (FieldName) + 1);
3135 strcpy (FieldDef->Name, FieldName);
3137 // Add it to the end of the field list for the currently active structure
3139 if (mLastStructDefinition->Field == NULL) {
3140 mLastStructDefinition->Field = FieldDef;
3142 mLastStructDefinition->LastField->Next = FieldDef;
3144 mLastStructDefinition->LastField = FieldDef;
3147 EfiVfrParser::AddVarStore (
3148 CHAR8 *StructName, // actual name of the structure
3149 CHAR8 *VarName, // actual NV variable name
3150 UINT16 VarStoreId, // key value
3151 INT32 LineNum // parse line number (for error reporting)
3155 Routine Description:
3156 Called while parsing a varstore statement. Add the variable store
3160 StructName - the name of the typedef'ed structure to use
3161 VarName - the NV variable name as specified in the varstore statement
3162 VarStoreId - the variable store ID as specified in the varstore statememt
3163 LineNum - the line number from the input (preprocessor output) file
3170 STRUCT_DEFINITION *StructDef;
3171 UINT16_LIST *L16Ptr;
3173 // Go through our list of previously-defined variable store IDs and
3174 // make sure this one is not a duplicate in name or key value.
3176 for (L16Ptr = mDefinedVarStoreId; L16Ptr != NULL; L16Ptr = L16Ptr->Next) {
3177 if (L16Ptr->Value == VarStoreId) {
3178 PrintErrorMessage (LineNum, "variable storage key already used", NULL);
3179 PrintErrorMessage (L16Ptr->LineNum, "previous usage of storage key", NULL);
3183 // Key value of 0 is invalid since that's assigned by default to the default
3184 // variable store (the first structure parsed).
3186 if (VarStoreId == 0) {
3187 PrintErrorMessage (LineNum, "variable storage key of 0 is invalid", NULL);
3190 // Create a new element to add to the list
3192 L16Ptr = (UINT16_LIST *)malloc(sizeof (UINT16_LIST));
3193 memset (L16Ptr, 0, sizeof (UINT16_LIST));
3194 L16Ptr->LineNum = LineNum;
3195 L16Ptr->Value = VarStoreId;
3196 if (mDefinedVarStoreId == NULL) {
3197 mDefinedVarStoreId = L16Ptr;
3199 mLastDefinedVarStoreId->Next = L16Ptr;
3201 mLastDefinedVarStoreId = L16Ptr;
3203 // Find the structure definition with this name
3205 for (StructDef = mFirstStructDefinition; StructDef != NULL; StructDef = StructDef->Next) {
3206 if (strcmp (StructDef->Name, StructName) == 0) {
3208 // Make sure they did not already define a variable storage ID
3209 // for this structure.
3211 if (StructDef->VarStoreId != 0) {
3212 PrintErrorMessage (LineNum, StructName, "variable storage already defined for this structure");
3213 PrintErrorMessage (StructDef->VarStoreLineNum, StructName, "previous definition for variable storage");
3215 StructDef->VarStoreId = VarStoreId;
3216 StructDef->VarStoreIdValid = 1;
3217 StructDef->VarStoreLineNum = LineNum;
3218 WriteWord (StructDef->Size);
3220 WriteByte(*VarName, 0);
3227 PrintErrorMessage (LineNum, StructName, "structure with this name not defined");
3230 EfiVfrParser::WriteDWord (
3236 Routine Description:
3237 During parsing, we came upon some code that requires a 32-bit value be
3238 written to the VFR binary file. Queue up the 4 bytes.
3241 Value - the 32-bit value to write
3242 KeyByte - a single character which gets written out beside the first byte.
3243 This is used to tag the data in the output file so that during
3244 debug you have an idea what the value is.
3252 // Write 4 bytes, little endian. Specify a key byte only on the first one
3254 mOpcodeHandler.AddByte ((UINT8)Value, KeyByte);
3256 mOpcodeHandler.AddByte ((UINT8)Value, 0);
3258 mOpcodeHandler.AddByte ((UINT8)Value, 0);
3260 mOpcodeHandler.AddByte ((UINT8)Value, 0);
3263 EfiVfrParser::WriteOpByte (
3269 Routine Description:
3271 During parsing, we came upon a new VFR opcode. At this point we flush
3272 the output queue and then queue up this byte (with 'O' for opcode tag).
3276 ByteValue - opcode value
3284 mOpcodeHandler.AddOpcodeByte (ByteValue, LineNum);
3287 EfiVfrParser::WriteByte (
3293 Routine Description:
3295 During parsing of the VFR we spoonfeed this function with bytes to write to
3296 the output VFR binary file. This function simply queues up the bytes, and
3297 the queue gets flushed each time a new VFR opcode is encountered.
3301 ByteValue - raw byte to write
3302 Key - character to tag the byte with when we write ByteValue to the
3311 mOpcodeHandler.AddByte (ByteValue, Key);
3314 EfiVfrParser::WriteWord (
3319 Routine Description:
3320 During VFR parsing we came upon a case where we need to write out a
3321 16-bit value. Queue it up.
3324 Value - value to write.
3331 mOpcodeHandler.AddByte ((UINT8)Value, 0);
3332 mOpcodeHandler.AddByte ((UINT8)((Value \>> 8) & 0xFF), 0);
3335 EfiVfrParser::WriteStringIdWord (
3339 mOpcodeHandler.AddByte ((UINT8)WordValue, 'S');
3340 mOpcodeHandler.AddByte ((UINT8)((WordValue \>> 8) & 0xFF), 0);
3343 EfiVfrParser::FreeGotoReferences ()
3346 Routine Description:
3347 Called during cleanup to free up the memory we allocated when
3348 keeping track of VFR goto statements.
3358 GOTO_REFERENCE *CurrRef;
3359 GOTO_REFERENCE *NextRef;
3360 FORM_ID_VALUE *CurrFormId;
3361 FORM_ID_VALUE *NextFormId;
3366 // Go through all the "goto" references and make sure there was a
3367 // form ID of that value defined.
3369 for (CurrRef = mGotoReferences; CurrRef != NULL; CurrRef = CurrRef->Next) {
3371 for (CurrFormId = mFormIdValues; CurrFormId != NULL; CurrFormId = CurrFormId->Next) {
3372 if (CurrRef->Value == CurrFormId->Value) {
3378 sprintf (Name, "%d", (UINT32)CurrRef->Value);
3379 PrintErrorMessage (CurrRef->RefLineNum, Name, "undefined form ID");
3383 // Now free up the form id and goto references
3385 CurrFormId = mFormIdValues;
3386 while (CurrFormId != NULL) {
3387 NextFormId = CurrFormId->Next;
3389 CurrFormId = NextFormId;
3391 mFormIdValues = NULL;
3392 CurrRef = mGotoReferences;
3393 while (CurrRef != NULL) {
3394 NextRef = CurrRef->Next;
3398 mGotoReferences = NULL;
3401 EfiVfrParser::AddGotoReference (
3407 Routine Description:
3408 During VFR parsing we came upon a goto statement. Since we support
3409 forward references, save the referenced label and at the end of parsing
3410 we'll check that the label was actually defined somewhere.
3413 GotoNumber - the label number referenced
3414 LineNum - the line number where the reference was made (used for
3422 GOTO_REFERENCE *NewRef;
3424 NewRef = (GOTO_REFERENCE *)malloc (sizeof (GOTO_REFERENCE));
3425 if (NewRef == NULL) {
3426 Error (PROGRAM_NAME, 0, 0, NULL, "memory allocation failure");
3429 memset ((char *)NewRef, 0, sizeof (GOTO_REFERENCE));
3430 NewRef->Value = (UINT16)GotoNumber;
3431 NewRef->RefLineNum = LineNum;
3432 NewRef->Next = mGotoReferences;
3433 mGotoReferences = NewRef;
3436 EfiVfrParser::AddFormId (
3442 Routine Description:
3443 This function is called when we parse "form formid = 3" statements.
3444 We save the form ID valud so we can verify that duplicates are not
3445 defined. Also, these are the targets of goto statements, so when we're
3446 done parsing the script we also go through all the goto statements to
3447 check that there was a target FormId defined as referenced by each
3450 Note that formid = 0 is invalid.
3453 FormIdValue - the parsed value for the Form ID
3454 LineNum - line number of the source file we're parsing
3461 FORM_ID_VALUE *NewFormId;
3466 // Verify that FormId != 0
3468 if (FormIdValue == 0) {
3469 FileName = ConvertLineNumber (&LineNum);
3470 Error (FileName, LineNum, 0, "form ID cannot be 0", NULL);
3474 // First go through all previously defined form IDs and make sure they have not defined
3477 for (NewFormId = mFormIdValues; NewFormId != NULL; NewFormId = NewFormId->Next) {
3478 if ((UINT16)FormIdValue == NewFormId->Value) {
3479 FileName = ConvertLineNumber (&LineNum);
3480 LineNum2 = NewFormId->LineNum;
3481 FileName2 = ConvertLineNumber (&LineNum2);
3482 Error (FileName, LineNum, 0, NULL, "form ID %d already defined", FormIdValue);
3483 Error (FileName2, LineNum2, 0, NULL, "form ID %d previous definition", FormIdValue);
3488 // Allocate memory for a new one
3490 NewFormId = (FORM_ID_VALUE *)malloc (sizeof (FORM_ID_VALUE));
3491 if (NewFormId == NULL) {
3492 Error (PROGRAM_NAME, 0, 0, NULL, "memory allocation failure");
3495 memset ((char *)NewFormId, 0, sizeof (FORM_ID_VALUE));
3496 NewFormId->LineNum = LineNum;
3497 NewFormId->Next = mFormIdValues;
3498 NewFormId->Value = (UINT16)FormIdValue;
3499 mFormIdValues = NewFormId;
3502 EfiVfrParser::GetNumber (
3510 if ((NumStr[0] == '0') && (NumStr[1] == 'x')) {
3511 AtoX (NumStr + 2, 4, &Value);
3513 Value = (UINT32)atoi (NumStr);
3518 if ((NumBytes < 4) && (Value & ((UINT32)0xFFFFFFFF << (NumBytes * 8)))) {
3519 PrintErrorMessage (LineNum, NumStr, "value out of range");
3527 } // end grammar class