BaseTools: Enable structure pcd in FDF file
[mirror_edk2.git] / BaseTools / Source / Python / AutoGen / GenC.py
CommitLineData
f51461c8
LG
1## @file\r
2# Routines for generating AutoGen.h and AutoGen.c\r
3#\r
eca980c0 4# Copyright (c) 2007 - 2018, Intel Corporation. All rights reserved.<BR>\r
f51461c8
LG
5# This program and the accompanying materials\r
6# are licensed and made available under the terms and conditions of the BSD License\r
7# which accompanies this distribution. The full text of the license may be found at\r
8# http://opensource.org/licenses/bsd-license.php\r
9#\r
10# THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
11# WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
12#\r
13\r
14## Import Modules\r
15#\r
16import string\r
333ba578
YZ
17import collections\r
18import struct\r
f51461c8
LG
19from Common import EdkLogger\r
20\r
21from Common.BuildToolError import *\r
22from Common.DataType import *\r
23from Common.Misc import *\r
5a57246e 24from Common.StringUtils import StringToArray\r
f51461c8
LG
25from StrGather import *\r
26from GenPcdDb import CreatePcdDatabaseCode\r
333ba578 27from IdfClassObject import *\r
f51461c8
LG
28\r
29## PCD type string\r
30gItemTypeStringDatabase = {\r
be409b67
CJ
31 TAB_PCDS_FEATURE_FLAG : TAB_PCDS_FIXED_AT_BUILD,\r
32 TAB_PCDS_FIXED_AT_BUILD : TAB_PCDS_FIXED_AT_BUILD,\r
f51461c8
LG
33 TAB_PCDS_PATCHABLE_IN_MODULE: 'BinaryPatch',\r
34 TAB_PCDS_DYNAMIC : '',\r
35 TAB_PCDS_DYNAMIC_DEFAULT : '',\r
36 TAB_PCDS_DYNAMIC_VPD : '',\r
37 TAB_PCDS_DYNAMIC_HII : '',\r
38 TAB_PCDS_DYNAMIC_EX : '',\r
39 TAB_PCDS_DYNAMIC_EX_DEFAULT : '',\r
40 TAB_PCDS_DYNAMIC_EX_VPD : '',\r
41 TAB_PCDS_DYNAMIC_EX_HII : '',\r
42}\r
43\r
f51461c8
LG
44\r
45## Datum size\r
656d2539
CJ
46gDatumSizeStringDatabase = {TAB_UINT8:'8',TAB_UINT16:'16',TAB_UINT32:'32',TAB_UINT64:'64','BOOLEAN':'BOOLEAN',TAB_VOID:'8'}\r
47gDatumSizeStringDatabaseH = {TAB_UINT8:'8',TAB_UINT16:'16',TAB_UINT32:'32',TAB_UINT64:'64','BOOLEAN':'BOOL',TAB_VOID:'PTR'}\r
48gDatumSizeStringDatabaseLib = {TAB_UINT8:'8',TAB_UINT16:'16',TAB_UINT32:'32',TAB_UINT64:'64','BOOLEAN':'Bool',TAB_VOID:'Ptr'}\r
f51461c8
LG
49\r
50## AutoGen File Header Templates\r
51gAutoGenHeaderString = TemplateString("""\\r
52/**\r
53 DO NOT EDIT\r
54 FILE auto-generated\r
55 Module name:\r
56 ${FileName}\r
57 Abstract: Auto-generated ${FileName} for building module or library.\r
58**/\r
59""")\r
60\r
61gAutoGenHPrologueString = TemplateString("""\r
62#ifndef _${File}_${Guid}\r
63#define _${File}_${Guid}\r
64\r
65""")\r
66\r
67gAutoGenHCppPrologueString = """\\r
68#ifdef __cplusplus\r
69extern "C" {\r
70#endif\r
71\r
72"""\r
73\r
74gAutoGenHEpilogueString = """\r
75\r
76#ifdef __cplusplus\r
77}\r
78#endif\r
79\r
80#endif\r
81"""\r
82\r
83## PEI Core Entry Point Templates\r
84gPeiCoreEntryPointPrototype = TemplateString("""\r
85${BEGIN}\r
86VOID\r
87EFIAPI\r
88${Function} (\r
89 IN CONST EFI_SEC_PEI_HAND_OFF *SecCoreData,\r
90 IN CONST EFI_PEI_PPI_DESCRIPTOR *PpiList,\r
91 IN VOID *Context\r
92 );\r
93${END}\r
94""")\r
95\r
96gPeiCoreEntryPointString = TemplateString("""\r
97${BEGIN}\r
98VOID\r
99EFIAPI\r
100ProcessModuleEntryPointList (\r
101 IN CONST EFI_SEC_PEI_HAND_OFF *SecCoreData,\r
102 IN CONST EFI_PEI_PPI_DESCRIPTOR *PpiList,\r
103 IN VOID *Context\r
104 )\r
105\r
106{\r
107 ${Function} (SecCoreData, PpiList, Context);\r
108}\r
109${END}\r
110""")\r
111\r
112\r
113## DXE Core Entry Point Templates\r
114gDxeCoreEntryPointPrototype = TemplateString("""\r
115${BEGIN}\r
116VOID\r
117EFIAPI\r
118${Function} (\r
119 IN VOID *HobStart\r
120 );\r
121${END}\r
122""")\r
123\r
124gDxeCoreEntryPointString = TemplateString("""\r
125${BEGIN}\r
126VOID\r
127EFIAPI\r
128ProcessModuleEntryPointList (\r
129 IN VOID *HobStart\r
130 )\r
131\r
132{\r
133 ${Function} (HobStart);\r
134}\r
135${END}\r
136""")\r
137\r
138## PEIM Entry Point Templates\r
139gPeimEntryPointPrototype = TemplateString("""\r
140${BEGIN}\r
141EFI_STATUS\r
142EFIAPI\r
143${Function} (\r
144 IN EFI_PEI_FILE_HANDLE FileHandle,\r
145 IN CONST EFI_PEI_SERVICES **PeiServices\r
146 );\r
147${END}\r
148""")\r
149\r
150gPeimEntryPointString = [\r
151TemplateString("""\r
152GLOBAL_REMOVE_IF_UNREFERENCED const UINT32 _gPeimRevision = ${PiSpecVersion};\r
153\r
154EFI_STATUS\r
155EFIAPI\r
156ProcessModuleEntryPointList (\r
157 IN EFI_PEI_FILE_HANDLE FileHandle,\r
158 IN CONST EFI_PEI_SERVICES **PeiServices\r
159 )\r
160\r
161{\r
162 return EFI_SUCCESS;\r
163}\r
164"""),\r
165TemplateString("""\r
166GLOBAL_REMOVE_IF_UNREFERENCED const UINT32 _gPeimRevision = ${PiSpecVersion};\r
167${BEGIN}\r
168EFI_STATUS\r
169EFIAPI\r
170ProcessModuleEntryPointList (\r
171 IN EFI_PEI_FILE_HANDLE FileHandle,\r
172 IN CONST EFI_PEI_SERVICES **PeiServices\r
173 )\r
174\r
175{\r
176 return ${Function} (FileHandle, PeiServices);\r
177}\r
178${END}\r
179"""),\r
180TemplateString("""\r
181GLOBAL_REMOVE_IF_UNREFERENCED const UINT32 _gPeimRevision = ${PiSpecVersion};\r
182\r
183EFI_STATUS\r
184EFIAPI\r
185ProcessModuleEntryPointList (\r
186 IN EFI_PEI_FILE_HANDLE FileHandle,\r
187 IN CONST EFI_PEI_SERVICES **PeiServices\r
188 )\r
189\r
190{\r
191 EFI_STATUS Status;\r
192 EFI_STATUS CombinedStatus;\r
193\r
194 CombinedStatus = EFI_LOAD_ERROR;\r
195${BEGIN}\r
196 Status = ${Function} (FileHandle, PeiServices);\r
197 if (!EFI_ERROR (Status) || EFI_ERROR (CombinedStatus)) {\r
198 CombinedStatus = Status;\r
199 }\r
200${END}\r
201 return CombinedStatus;\r
202}\r
203""")\r
204]\r
205\r
206## SMM_CORE Entry Point Templates\r
207gSmmCoreEntryPointPrototype = TemplateString("""\r
208${BEGIN}\r
209EFI_STATUS\r
210EFIAPI\r
211${Function} (\r
212 IN EFI_HANDLE ImageHandle,\r
213 IN EFI_SYSTEM_TABLE *SystemTable\r
214 );\r
215${END}\r
216""")\r
217\r
218gSmmCoreEntryPointString = TemplateString("""\r
219${BEGIN}\r
220const UINT32 _gUefiDriverRevision = ${UefiSpecVersion};\r
221const UINT32 _gDxeRevision = ${PiSpecVersion};\r
222\r
223EFI_STATUS\r
224EFIAPI\r
225ProcessModuleEntryPointList (\r
226 IN EFI_HANDLE ImageHandle,\r
227 IN EFI_SYSTEM_TABLE *SystemTable\r
228 )\r
229{\r
230 return ${Function} (ImageHandle, SystemTable);\r
231}\r
232${END}\r
233""")\r
234\r
5a9c3e3e
SV
235## MM_CORE_STANDALONE Entry Point Templates\r
236gMmCoreStandaloneEntryPointPrototype = TemplateString("""\r
237${BEGIN}\r
238EFI_STATUS\r
239EFIAPI\r
240${Function} (\r
241 IN VOID *HobStart\r
242 );\r
243${END}\r
244""")\r
245\r
246gMmCoreStandaloneEntryPointString = TemplateString("""\r
247${BEGIN}\r
248const UINT32 _gMmRevision = ${PiSpecVersion};\r
249\r
250VOID\r
251EFIAPI\r
252ProcessModuleEntryPointList (\r
253 IN VOID *HobStart\r
254 )\r
255{\r
256 ${Function} (HobStart);\r
257}\r
258${END}\r
259""")\r
260\r
261## MM_STANDALONE Entry Point Templates\r
262gMmStandaloneEntryPointPrototype = TemplateString("""\r
263${BEGIN}\r
264EFI_STATUS\r
265EFIAPI\r
266${Function} (\r
267 IN EFI_HANDLE ImageHandle,\r
268 IN EFI_SMM_SYSTEM_TABLE2 *MmSystemTable\r
269 );\r
270${END}\r
271""")\r
272\r
273gMmStandaloneEntryPointString = [\r
274TemplateString("""\r
275GLOBAL_REMOVE_IF_UNREFERENCED const UINT32 _gMmRevision = ${PiSpecVersion};\r
276\r
277EFI_STATUS\r
278EFIAPI\r
279ProcessModuleEntryPointList (\r
280 IN EFI_HANDLE ImageHandle,\r
281 IN EFI_SMM_SYSTEM_TABLE2 *MmSystemTable\r
282 )\r
283\r
284{\r
285 return EFI_SUCCESS;\r
286}\r
287"""),\r
288TemplateString("""\r
289GLOBAL_REMOVE_IF_UNREFERENCED const UINT32 _gMmRevision = ${PiSpecVersion};\r
290${BEGIN}\r
291EFI_STATUS\r
292EFIAPI\r
293ProcessModuleEntryPointList (\r
294 IN EFI_HANDLE ImageHandle,\r
295 IN EFI_SMM_SYSTEM_TABLE2 *MmSystemTable\r
296 )\r
297\r
298{\r
299 return ${Function} (ImageHandle, MmSystemTable);\r
300}\r
301${END}\r
302"""),\r
303TemplateString("""\r
304GLOBAL_REMOVE_IF_UNREFERENCED const UINT32 _gMmRevision = ${PiSpecVersion};\r
305\r
306EFI_STATUS\r
307EFIAPI\r
308ProcessModuleEntryPointList (\r
309 IN EFI_HANDLE ImageHandle,\r
310 IN EFI_SMM_SYSTEM_TABLE2 *MmSystemTable\r
311 )\r
312\r
313{\r
314 EFI_STATUS Status;\r
315 EFI_STATUS CombinedStatus;\r
316\r
317 CombinedStatus = EFI_LOAD_ERROR;\r
318${BEGIN}\r
319 Status = ${Function} (ImageHandle, MmSystemTable);\r
320 if (!EFI_ERROR (Status) || EFI_ERROR (CombinedStatus)) {\r
321 CombinedStatus = Status;\r
322 }\r
323${END}\r
324 return CombinedStatus;\r
325}\r
326""")\r
327]\r
328\r
f51461c8
LG
329## DXE SMM Entry Point Templates\r
330gDxeSmmEntryPointPrototype = TemplateString("""\r
331${BEGIN}\r
332EFI_STATUS\r
333EFIAPI\r
334${Function} (\r
335 IN EFI_HANDLE ImageHandle,\r
336 IN EFI_SYSTEM_TABLE *SystemTable\r
337 );\r
338${END}\r
339""")\r
340\r
341gDxeSmmEntryPointString = [\r
342TemplateString("""\r
343const UINT32 _gUefiDriverRevision = ${UefiSpecVersion};\r
344const UINT32 _gDxeRevision = ${PiSpecVersion};\r
345\r
346EFI_STATUS\r
347EFIAPI\r
348ProcessModuleEntryPointList (\r
349 IN EFI_HANDLE ImageHandle,\r
350 IN EFI_SYSTEM_TABLE *SystemTable\r
351 )\r
352\r
353{\r
354 return EFI_SUCCESS;\r
355}\r
356"""),\r
357TemplateString("""\r
358const UINT32 _gUefiDriverRevision = ${UefiSpecVersion};\r
359const UINT32 _gDxeRevision = ${PiSpecVersion};\r
360\r
361static BASE_LIBRARY_JUMP_BUFFER mJumpContext;\r
362static EFI_STATUS mDriverEntryPointStatus;\r
363\r
364VOID\r
365EFIAPI\r
366ExitDriver (\r
367 IN EFI_STATUS Status\r
368 )\r
369{\r
370 if (!EFI_ERROR (Status) || EFI_ERROR (mDriverEntryPointStatus)) {\r
371 mDriverEntryPointStatus = Status;\r
372 }\r
373 LongJump (&mJumpContext, (UINTN)-1);\r
374 ASSERT (FALSE);\r
375}\r
376\r
377EFI_STATUS\r
378EFIAPI\r
379ProcessModuleEntryPointList (\r
380 IN EFI_HANDLE ImageHandle,\r
381 IN EFI_SYSTEM_TABLE *SystemTable\r
382 )\r
383{\r
384 mDriverEntryPointStatus = EFI_LOAD_ERROR;\r
385\r
386${BEGIN}\r
387 if (SetJump (&mJumpContext) == 0) {\r
388 ExitDriver (${Function} (ImageHandle, SystemTable));\r
389 ASSERT (FALSE);\r
390 }\r
391${END}\r
392\r
393 return mDriverEntryPointStatus;\r
394}\r
395""")\r
396]\r
397\r
398## UEFI Driver Entry Point Templates\r
399gUefiDriverEntryPointPrototype = TemplateString("""\r
400${BEGIN}\r
401EFI_STATUS\r
402EFIAPI\r
403${Function} (\r
404 IN EFI_HANDLE ImageHandle,\r
405 IN EFI_SYSTEM_TABLE *SystemTable\r
406 );\r
407${END}\r
408""")\r
409\r
410gUefiDriverEntryPointString = [\r
411TemplateString("""\r
412const UINT32 _gUefiDriverRevision = ${UefiSpecVersion};\r
413const UINT32 _gDxeRevision = ${PiSpecVersion};\r
414\r
415EFI_STATUS\r
416EFIAPI\r
417ProcessModuleEntryPointList (\r
418 IN EFI_HANDLE ImageHandle,\r
419 IN EFI_SYSTEM_TABLE *SystemTable\r
420 )\r
421{\r
422 return EFI_SUCCESS;\r
423}\r
424"""),\r
425TemplateString("""\r
426const UINT32 _gUefiDriverRevision = ${UefiSpecVersion};\r
427const UINT32 _gDxeRevision = ${PiSpecVersion};\r
428\r
429${BEGIN}\r
430EFI_STATUS\r
431EFIAPI\r
432ProcessModuleEntryPointList (\r
433 IN EFI_HANDLE ImageHandle,\r
434 IN EFI_SYSTEM_TABLE *SystemTable\r
435 )\r
436\r
437{\r
438 return ${Function} (ImageHandle, SystemTable);\r
439}\r
440${END}\r
441VOID\r
442EFIAPI\r
443ExitDriver (\r
444 IN EFI_STATUS Status\r
445 )\r
446{\r
447 if (EFI_ERROR (Status)) {\r
448 ProcessLibraryDestructorList (gImageHandle, gST);\r
449 }\r
450 gBS->Exit (gImageHandle, Status, 0, NULL);\r
451}\r
452"""),\r
453TemplateString("""\r
454const UINT32 _gUefiDriverRevision = ${UefiSpecVersion};\r
455const UINT32 _gDxeRevision = ${PiSpecVersion};\r
456\r
457static BASE_LIBRARY_JUMP_BUFFER mJumpContext;\r
458static EFI_STATUS mDriverEntryPointStatus;\r
459\r
460EFI_STATUS\r
461EFIAPI\r
462ProcessModuleEntryPointList (\r
463 IN EFI_HANDLE ImageHandle,\r
464 IN EFI_SYSTEM_TABLE *SystemTable\r
465 )\r
466{\r
467 mDriverEntryPointStatus = EFI_LOAD_ERROR;\r
468 ${BEGIN}\r
469 if (SetJump (&mJumpContext) == 0) {\r
470 ExitDriver (${Function} (ImageHandle, SystemTable));\r
471 ASSERT (FALSE);\r
472 }\r
473 ${END}\r
474 return mDriverEntryPointStatus;\r
475}\r
476\r
477VOID\r
478EFIAPI\r
479ExitDriver (\r
480 IN EFI_STATUS Status\r
481 )\r
482{\r
483 if (!EFI_ERROR (Status) || EFI_ERROR (mDriverEntryPointStatus)) {\r
484 mDriverEntryPointStatus = Status;\r
485 }\r
486 LongJump (&mJumpContext, (UINTN)-1);\r
487 ASSERT (FALSE);\r
488}\r
489""")\r
490]\r
491\r
492\r
493## UEFI Application Entry Point Templates\r
494gUefiApplicationEntryPointPrototype = TemplateString("""\r
495${BEGIN}\r
496EFI_STATUS\r
497EFIAPI\r
498${Function} (\r
499 IN EFI_HANDLE ImageHandle,\r
500 IN EFI_SYSTEM_TABLE *SystemTable\r
501 );\r
502${END}\r
503""")\r
504\r
505gUefiApplicationEntryPointString = [\r
506TemplateString("""\r
507const UINT32 _gUefiDriverRevision = ${UefiSpecVersion};\r
508\r
509EFI_STATUS\r
510EFIAPI\r
511ProcessModuleEntryPointList (\r
512 IN EFI_HANDLE ImageHandle,\r
513 IN EFI_SYSTEM_TABLE *SystemTable\r
514 )\r
515{\r
516 return EFI_SUCCESS;\r
517}\r
518"""),\r
519TemplateString("""\r
520const UINT32 _gUefiDriverRevision = ${UefiSpecVersion};\r
521\r
522${BEGIN}\r
523EFI_STATUS\r
524EFIAPI\r
525ProcessModuleEntryPointList (\r
526 IN EFI_HANDLE ImageHandle,\r
527 IN EFI_SYSTEM_TABLE *SystemTable\r
528 )\r
529\r
530{\r
531 return ${Function} (ImageHandle, SystemTable);\r
532}\r
533${END}\r
534VOID\r
535EFIAPI\r
536ExitDriver (\r
537 IN EFI_STATUS Status\r
538 )\r
539{\r
540 if (EFI_ERROR (Status)) {\r
541 ProcessLibraryDestructorList (gImageHandle, gST);\r
542 }\r
543 gBS->Exit (gImageHandle, Status, 0, NULL);\r
544}\r
545"""),\r
546TemplateString("""\r
547const UINT32 _gUefiDriverRevision = ${UefiSpecVersion};\r
548\r
549EFI_STATUS\r
550EFIAPI\r
551ProcessModuleEntryPointList (\r
552 IN EFI_HANDLE ImageHandle,\r
553 IN EFI_SYSTEM_TABLE *SystemTable\r
554 )\r
555\r
556{\r
557 ${BEGIN}\r
558 if (SetJump (&mJumpContext) == 0) {\r
559 ExitDriver (${Function} (ImageHandle, SystemTable));\r
560 ASSERT (FALSE);\r
561 }\r
562 ${END}\r
563 return mDriverEntryPointStatus;\r
564}\r
565\r
566static BASE_LIBRARY_JUMP_BUFFER mJumpContext;\r
567static EFI_STATUS mDriverEntryPointStatus = EFI_LOAD_ERROR;\r
568\r
569VOID\r
570EFIAPI\r
571ExitDriver (\r
572 IN EFI_STATUS Status\r
573 )\r
574{\r
575 if (!EFI_ERROR (Status) || EFI_ERROR (mDriverEntryPointStatus)) {\r
576 mDriverEntryPointStatus = Status;\r
577 }\r
578 LongJump (&mJumpContext, (UINTN)-1);\r
579 ASSERT (FALSE);\r
580}\r
581""")\r
582]\r
583\r
584## UEFI Unload Image Templates\r
585gUefiUnloadImagePrototype = TemplateString("""\r
586${BEGIN}\r
587EFI_STATUS\r
588EFIAPI\r
589${Function} (\r
590 IN EFI_HANDLE ImageHandle\r
591 );\r
592${END}\r
593""")\r
594\r
595gUefiUnloadImageString = [\r
596TemplateString("""\r
597GLOBAL_REMOVE_IF_UNREFERENCED const UINT8 _gDriverUnloadImageCount = ${Count};\r
598\r
599EFI_STATUS\r
600EFIAPI\r
601ProcessModuleUnloadList (\r
602 IN EFI_HANDLE ImageHandle\r
603 )\r
604{\r
605 return EFI_SUCCESS;\r
606}\r
607"""),\r
608TemplateString("""\r
609GLOBAL_REMOVE_IF_UNREFERENCED const UINT8 _gDriverUnloadImageCount = ${Count};\r
610\r
611${BEGIN}\r
612EFI_STATUS\r
613EFIAPI\r
614ProcessModuleUnloadList (\r
615 IN EFI_HANDLE ImageHandle\r
616 )\r
617{\r
618 return ${Function} (ImageHandle);\r
619}\r
620${END}\r
621"""),\r
622TemplateString("""\r
623GLOBAL_REMOVE_IF_UNREFERENCED const UINT8 _gDriverUnloadImageCount = ${Count};\r
624\r
625EFI_STATUS\r
626EFIAPI\r
627ProcessModuleUnloadList (\r
628 IN EFI_HANDLE ImageHandle\r
629 )\r
630{\r
631 EFI_STATUS Status;\r
632\r
633 Status = EFI_SUCCESS;\r
634${BEGIN}\r
635 if (EFI_ERROR (Status)) {\r
636 ${Function} (ImageHandle);\r
637 } else {\r
638 Status = ${Function} (ImageHandle);\r
639 }\r
640${END}\r
641 return Status;\r
642}\r
643""")\r
644]\r
645\r
646gLibraryStructorPrototype = {\r
8bb63e37 647SUP_MODULE_BASE : TemplateString("""${BEGIN}\r
f51461c8
LG
648RETURN_STATUS\r
649EFIAPI\r
650${Function} (\r
651 VOID\r
652 );${END}\r
653"""),\r
654\r
655'PEI' : TemplateString("""${BEGIN}\r
656EFI_STATUS\r
657EFIAPI\r
658${Function} (\r
659 IN EFI_PEI_FILE_HANDLE FileHandle,\r
660 IN CONST EFI_PEI_SERVICES **PeiServices\r
661 );${END}\r
662"""),\r
663\r
664'DXE' : TemplateString("""${BEGIN}\r
665EFI_STATUS\r
666EFIAPI\r
667${Function} (\r
668 IN EFI_HANDLE ImageHandle,\r
669 IN EFI_SYSTEM_TABLE *SystemTable\r
670 );${END}\r
671"""),\r
5a9c3e3e
SV
672\r
673'MM' : TemplateString("""${BEGIN}\r
674EFI_STATUS\r
675EFIAPI\r
676${Function} (\r
677 IN EFI_HANDLE ImageHandle,\r
678 IN EFI_SMM_SYSTEM_TABLE2 *MmSystemTable\r
679 );${END}\r
680"""),\r
f51461c8
LG
681}\r
682\r
683gLibraryStructorCall = {\r
8bb63e37 684SUP_MODULE_BASE : TemplateString("""${BEGIN}\r
f51461c8
LG
685 Status = ${Function} ();\r
686 ASSERT_EFI_ERROR (Status);${END}\r
687"""),\r
688\r
689'PEI' : TemplateString("""${BEGIN}\r
690 Status = ${Function} (FileHandle, PeiServices);\r
691 ASSERT_EFI_ERROR (Status);${END}\r
692"""),\r
693\r
694'DXE' : TemplateString("""${BEGIN}\r
695 Status = ${Function} (ImageHandle, SystemTable);\r
696 ASSERT_EFI_ERROR (Status);${END}\r
697"""),\r
5a9c3e3e
SV
698\r
699'MM' : TemplateString("""${BEGIN}\r
700 Status = ${Function} (ImageHandle, MmSystemTable);\r
701 ASSERT_EFI_ERROR (Status);${END}\r
702"""),\r
f51461c8
LG
703}\r
704\r
705## Library Constructor and Destructor Templates\r
706gLibraryString = {\r
8bb63e37 707SUP_MODULE_BASE : TemplateString("""\r
f51461c8
LG
708${BEGIN}${FunctionPrototype}${END}\r
709\r
710VOID\r
711EFIAPI\r
712ProcessLibrary${Type}List (\r
713 VOID\r
714 )\r
715{\r
716${BEGIN} EFI_STATUS Status;\r
717${FunctionCall}${END}\r
718}\r
719"""),\r
720\r
721'PEI' : TemplateString("""\r
722${BEGIN}${FunctionPrototype}${END}\r
723\r
724VOID\r
725EFIAPI\r
726ProcessLibrary${Type}List (\r
727 IN EFI_PEI_FILE_HANDLE FileHandle,\r
728 IN CONST EFI_PEI_SERVICES **PeiServices\r
729 )\r
730{\r
731${BEGIN} EFI_STATUS Status;\r
732${FunctionCall}${END}\r
733}\r
734"""),\r
735\r
736'DXE' : TemplateString("""\r
737${BEGIN}${FunctionPrototype}${END}\r
738\r
739VOID\r
740EFIAPI\r
741ProcessLibrary${Type}List (\r
742 IN EFI_HANDLE ImageHandle,\r
743 IN EFI_SYSTEM_TABLE *SystemTable\r
744 )\r
745{\r
746${BEGIN} EFI_STATUS Status;\r
747${FunctionCall}${END}\r
748}\r
749"""),\r
5a9c3e3e
SV
750\r
751'MM' : TemplateString("""\r
752${BEGIN}${FunctionPrototype}${END}\r
753\r
754VOID\r
755EFIAPI\r
756ProcessLibrary${Type}List (\r
757 IN EFI_HANDLE ImageHandle,\r
758 IN EFI_SMM_SYSTEM_TABLE2 *MmSystemTable\r
759 )\r
760{\r
761${BEGIN} EFI_STATUS Status;\r
762${FunctionCall}${END}\r
763}\r
764"""),\r
f51461c8
LG
765}\r
766\r
767gBasicHeaderFile = "Base.h"\r
768\r
769gModuleTypeHeaderFile = {\r
8bb63e37
CJ
770 SUP_MODULE_BASE : [gBasicHeaderFile],\r
771 SUP_MODULE_SEC : ["PiPei.h", "Library/DebugLib.h"],\r
772 SUP_MODULE_PEI_CORE : ["PiPei.h", "Library/DebugLib.h", "Library/PeiCoreEntryPoint.h"],\r
773 SUP_MODULE_PEIM : ["PiPei.h", "Library/DebugLib.h", "Library/PeimEntryPoint.h"],\r
774 SUP_MODULE_DXE_CORE : ["PiDxe.h", "Library/DebugLib.h", "Library/DxeCoreEntryPoint.h"],\r
775 SUP_MODULE_DXE_DRIVER : ["PiDxe.h", "Library/BaseLib.h", "Library/DebugLib.h", "Library/UefiBootServicesTableLib.h", "Library/UefiDriverEntryPoint.h"],\r
776 SUP_MODULE_DXE_SMM_DRIVER : ["PiDxe.h", "Library/BaseLib.h", "Library/DebugLib.h", "Library/UefiBootServicesTableLib.h", "Library/UefiDriverEntryPoint.h"],\r
777 SUP_MODULE_DXE_RUNTIME_DRIVER: ["PiDxe.h", "Library/BaseLib.h", "Library/DebugLib.h", "Library/UefiBootServicesTableLib.h", "Library/UefiDriverEntryPoint.h"],\r
778 SUP_MODULE_DXE_SAL_DRIVER : ["PiDxe.h", "Library/BaseLib.h", "Library/DebugLib.h", "Library/UefiBootServicesTableLib.h", "Library/UefiDriverEntryPoint.h"],\r
779 SUP_MODULE_UEFI_DRIVER : ["Uefi.h", "Library/BaseLib.h", "Library/DebugLib.h", "Library/UefiBootServicesTableLib.h", "Library/UefiDriverEntryPoint.h"],\r
780 SUP_MODULE_UEFI_APPLICATION : ["Uefi.h", "Library/BaseLib.h", "Library/DebugLib.h", "Library/UefiBootServicesTableLib.h", "Library/UefiApplicationEntryPoint.h"],\r
781 SUP_MODULE_SMM_CORE : ["PiDxe.h", "Library/BaseLib.h", "Library/DebugLib.h", "Library/UefiDriverEntryPoint.h"],\r
782 SUP_MODULE_MM_STANDALONE : ["PiSmm.h", "Library/BaseLib.h", "Library/DebugLib.h", "Library/SmmDriverStandaloneEntryPoint.h"],\r
783 SUP_MODULE_MM_CORE_STANDALONE : ["PiSmm.h", "Library/BaseLib.h", "Library/DebugLib.h", "Library/SmmCoreStandaloneEntryPoint.h"],\r
784 SUP_MODULE_USER_DEFINED : [gBasicHeaderFile]\r
f51461c8
LG
785}\r
786\r
f7496d71 787## Autogen internal worker macro to define DynamicEx PCD name includes both the TokenSpaceGuidName\r
f51461c8
LG
788# the TokenName and Guid comparison to avoid define name collisions.\r
789#\r
790# @param Info The ModuleAutoGen object\r
791# @param AutoGenH The TemplateString object for header file\r
792#\r
793#\r
794def DynExPcdTokenNumberMapping(Info, AutoGenH):\r
795 ExTokenCNameList = []\r
796 PcdExList = []\r
d590cce5
YZ
797 # Even it is the Library, the PCD is saved in the ModulePcdList\r
798 PcdList = Info.ModulePcdList\r
f51461c8 799 for Pcd in PcdList:\r
eece4292 800 if Pcd.Type in PCD_DYNAMIC_EX_TYPE_SET:\r
f51461c8
LG
801 ExTokenCNameList.append(Pcd.TokenCName)\r
802 PcdExList.append(Pcd)\r
803 if len(ExTokenCNameList) == 0:\r
804 return\r
805 AutoGenH.Append('\n#define COMPAREGUID(Guid1, Guid2) (BOOLEAN)(*(CONST UINT64*)Guid1 == *(CONST UINT64*)Guid2 && *((CONST UINT64*)Guid1 + 1) == *((CONST UINT64*)Guid2 + 1))\n')\r
806 # AutoGen for each PCD listed in a [PcdEx] section of a Module/Lib INF file.\r
f7496d71 807 # Auto generate a macro for each TokenName that takes a Guid pointer as a parameter.\r
f51461c8 808 # Use the Guid pointer to see if it matches any of the token space GUIDs.\r
72fbe88d 809 TokenCNameList = set()\r
f51461c8
LG
810 for TokenCName in ExTokenCNameList:\r
811 if TokenCName in TokenCNameList:\r
812 continue\r
813 Index = 0\r
814 Count = ExTokenCNameList.count(TokenCName)\r
815 for Pcd in PcdExList:\r
2a29017e
YZ
816 RealTokenCName = Pcd.TokenCName\r
817 for PcdItem in GlobalData.MixedPcd:\r
818 if (Pcd.TokenCName, Pcd.TokenSpaceGuidCName) in GlobalData.MixedPcd[PcdItem]:\r
819 RealTokenCName = PcdItem[0]\r
820 break\r
f51461c8
LG
821 if Pcd.TokenCName == TokenCName:\r
822 Index = Index + 1\r
823 if Index == 1:\r
2a29017e 824 AutoGenH.Append('\n#define __PCD_%s_ADDR_CMP(GuidPtr) (' % (RealTokenCName))\r
f7496d71 825 AutoGenH.Append('\\\n (GuidPtr == &%s) ? _PCD_TOKEN_%s_%s:'\r
2a29017e 826 % (Pcd.TokenSpaceGuidCName, Pcd.TokenSpaceGuidCName, RealTokenCName))\r
f51461c8 827 else:\r
f7496d71 828 AutoGenH.Append('\\\n (GuidPtr == &%s) ? _PCD_TOKEN_%s_%s:'\r
2a29017e 829 % (Pcd.TokenSpaceGuidCName, Pcd.TokenSpaceGuidCName, RealTokenCName))\r
f51461c8
LG
830 if Index == Count:\r
831 AutoGenH.Append('0 \\\n )\n')\r
72fbe88d 832 TokenCNameList.add(TokenCName)\r
f7496d71 833\r
72fbe88d 834 TokenCNameList = set()\r
f51461c8
LG
835 for TokenCName in ExTokenCNameList:\r
836 if TokenCName in TokenCNameList:\r
837 continue\r
838 Index = 0\r
839 Count = ExTokenCNameList.count(TokenCName)\r
840 for Pcd in PcdExList:\r
2a29017e
YZ
841 RealTokenCName = Pcd.TokenCName\r
842 for PcdItem in GlobalData.MixedPcd:\r
843 if (Pcd.TokenCName, Pcd.TokenSpaceGuidCName) in GlobalData.MixedPcd[PcdItem]:\r
844 RealTokenCName = PcdItem[0]\r
845 break\r
eece4292 846 if Pcd.Type in PCD_DYNAMIC_EX_TYPE_SET and Pcd.TokenCName == TokenCName:\r
f51461c8
LG
847 Index = Index + 1\r
848 if Index == 1:\r
2a29017e 849 AutoGenH.Append('\n#define __PCD_%s_VAL_CMP(GuidPtr) (' % (RealTokenCName))\r
9023704f 850 AutoGenH.Append('\\\n (GuidPtr == NULL) ? 0:')\r
f7496d71 851 AutoGenH.Append('\\\n COMPAREGUID (GuidPtr, &%s) ? _PCD_TOKEN_%s_%s:'\r
2a29017e 852 % (Pcd.TokenSpaceGuidCName, Pcd.TokenSpaceGuidCName, RealTokenCName))\r
f51461c8 853 else:\r
f7496d71 854 AutoGenH.Append('\\\n COMPAREGUID (GuidPtr, &%s) ? _PCD_TOKEN_%s_%s:'\r
2a29017e 855 % (Pcd.TokenSpaceGuidCName, Pcd.TokenSpaceGuidCName, RealTokenCName))\r
f51461c8
LG
856 if Index == Count:\r
857 AutoGenH.Append('0 \\\n )\n')\r
f7496d71 858 # Autogen internal worker macro to compare GUIDs. Guid1 is a pointer to a GUID.\r
f51461c8
LG
859 # Guid2 is a C name for a GUID. Compare pointers first because optimizing compiler\r
860 # can do this at build time on CONST GUID pointers and optimize away call to COMPAREGUID().\r
861 # COMPAREGUID() will only be used if the Guid passed in is local to the module.\r
862 AutoGenH.Append('#define _PCD_TOKEN_EX_%s(GuidPtr) __PCD_%s_ADDR_CMP(GuidPtr) ? __PCD_%s_ADDR_CMP(GuidPtr) : __PCD_%s_VAL_CMP(GuidPtr) \n'\r
2a29017e 863 % (RealTokenCName, RealTokenCName, RealTokenCName, RealTokenCName))\r
72fbe88d 864 TokenCNameList.add(TokenCName)\r
f51461c8
LG
865\r
866## Create code for module PCDs\r
867#\r
868# @param Info The ModuleAutoGen object\r
869# @param AutoGenC The TemplateString object for C code\r
870# @param AutoGenH The TemplateString object for header file\r
871# @param Pcd The PCD object\r
872#\r
873def CreateModulePcdCode(Info, AutoGenC, AutoGenH, Pcd):\r
874 TokenSpaceGuidValue = Pcd.TokenSpaceGuidValue #Info.GuidList[Pcd.TokenSpaceGuidCName]\r
875 PcdTokenNumber = Info.PlatformInfo.PcdTokenNumber\r
2a29017e
YZ
876 #\r
877 # Write PCDs\r
878 #\r
879 TokenCName = Pcd.TokenCName\r
880 for PcdItem in GlobalData.MixedPcd:\r
881 if (Pcd.TokenCName, Pcd.TokenSpaceGuidCName) in GlobalData.MixedPcd[PcdItem]:\r
882 TokenCName = PcdItem[0]\r
883 break\r
884 PcdTokenName = '_PCD_TOKEN_' + TokenCName\r
885 PatchPcdSizeTokenName = '_PCD_PATCHABLE_' + TokenCName +'_SIZE'\r
886 PatchPcdSizeVariableName = '_gPcd_BinaryPatch_Size_' + TokenCName\r
f7b31aa5 887 PatchPcdMaxSizeVariable = '_gPcd_BinaryPatch_MaxSize_' + TokenCName\r
2a29017e 888 FixPcdSizeTokenName = '_PCD_SIZE_' + TokenCName\r
1bfcf64f 889 FixedPcdSizeVariableName = '_gPcd_FixedAtBuild_Size_' + TokenCName\r
763e8edf 890\r
0f228f19
B
891 if Pcd.PcdValueFromComm:\r
892 Pcd.DefaultValue = Pcd.PcdValueFromComm\r
543f5ac3
B
893 elif Pcd.PcdValueFromFdf:\r
894 Pcd.DefaultValue = Pcd.PcdValueFromFdf\r
f7496d71 895\r
eece4292 896 if Pcd.Type in PCD_DYNAMIC_EX_TYPE_SET:\r
f51461c8 897 TokenNumber = int(Pcd.TokenValue, 0)\r
f7496d71 898 # Add TokenSpaceGuidValue value to PcdTokenName to discriminate the DynamicEx PCDs with\r
f51461c8 899 # different Guids but same TokenCName\r
2a29017e 900 PcdExTokenName = '_PCD_TOKEN_' + Pcd.TokenSpaceGuidCName + '_' + TokenCName\r
f51461c8
LG
901 AutoGenH.Append('\n#define %s %dU\n' % (PcdExTokenName, TokenNumber))\r
902 else:\r
903 if (Pcd.TokenCName, Pcd.TokenSpaceGuidCName) not in PcdTokenNumber:\r
f7496d71
LG
904 # If one of the Source built modules listed in the DSC is not listed in FDF modules,\r
905 # and the INF lists a PCD can only use the PcdsDynamic access method (it is only\r
906 # listed in the DEC file that declares the PCD as PcdsDynamic), then build tool will\r
907 # report warning message notify the PI that they are attempting to build a module\r
908 # that must be included in a flash image in order to be functional. These Dynamic PCD\r
909 # will not be added into the Database unless it is used by other modules that are\r
910 # included in the FDF file.\r
f51461c8 911 # In this case, just assign an invalid token number to make it pass build.\r
eece4292 912 if Pcd.Type in PCD_DYNAMIC_TYPE_SET:\r
f51461c8
LG
913 TokenNumber = 0\r
914 else:\r
915 EdkLogger.error("build", AUTOGEN_ERROR,\r
2a29017e 916 "No generated token number for %s.%s\n" % (Pcd.TokenSpaceGuidCName, TokenCName),\r
f51461c8
LG
917 ExtraData="[%s]" % str(Info))\r
918 else:\r
919 TokenNumber = PcdTokenNumber[Pcd.TokenCName, Pcd.TokenSpaceGuidCName]\r
920 AutoGenH.Append('\n#define %s %dU\n' % (PcdTokenName, TokenNumber))\r
921\r
2a29017e 922 EdkLogger.debug(EdkLogger.DEBUG_3, "Creating code for " + TokenCName + "." + Pcd.TokenSpaceGuidCName)\r
f51461c8
LG
923 if Pcd.Type not in gItemTypeStringDatabase:\r
924 EdkLogger.error("build", AUTOGEN_ERROR,\r
2a29017e 925 "Unknown PCD type [%s] of PCD %s.%s" % (Pcd.Type, Pcd.TokenSpaceGuidCName, TokenCName),\r
f51461c8 926 ExtraData="[%s]" % str(Info))\r
f51461c8 927\r
656d2539
CJ
928 DatumSize = gDatumSizeStringDatabase[Pcd.DatumType] if Pcd.DatumType in gDatumSizeStringDatabase else gDatumSizeStringDatabase[TAB_VOID]\r
929 DatumSizeLib = gDatumSizeStringDatabaseLib[Pcd.DatumType] if Pcd.DatumType in gDatumSizeStringDatabaseLib else gDatumSizeStringDatabaseLib[TAB_VOID]\r
930 GetModeName = '_PCD_GET_MODE_' + gDatumSizeStringDatabaseH[Pcd.DatumType] + '_' + TokenCName if Pcd.DatumType in gDatumSizeStringDatabaseH else '_PCD_GET_MODE_' + gDatumSizeStringDatabaseH[TAB_VOID] + '_' + TokenCName\r
931 SetModeName = '_PCD_SET_MODE_' + gDatumSizeStringDatabaseH[Pcd.DatumType] + '_' + TokenCName if Pcd.DatumType in gDatumSizeStringDatabaseH else '_PCD_SET_MODE_' + gDatumSizeStringDatabaseH[TAB_VOID] + '_' + TokenCName\r
932 SetModeStatusName = '_PCD_SET_MODE_' + gDatumSizeStringDatabaseH[Pcd.DatumType] + '_S_' + TokenCName if Pcd.DatumType in gDatumSizeStringDatabaseH else '_PCD_SET_MODE_' + gDatumSizeStringDatabaseH[TAB_VOID] + '_S_' + TokenCName\r
2a29017e 933 GetModeSizeName = '_PCD_GET_MODE_SIZE' + '_' + TokenCName\r
f7496d71 934\r
eece4292 935 if Pcd.Type in PCD_DYNAMIC_EX_TYPE_SET:\r
f51461c8
LG
936 if Info.IsLibrary:\r
937 PcdList = Info.LibraryPcdList\r
938 else:\r
939 PcdList = Info.ModulePcdList\r
72fbe88d 940 PcdExCNameTest = 0\r
f51461c8 941 for PcdModule in PcdList:\r
eece4292 942 if PcdModule.Type in PCD_DYNAMIC_EX_TYPE_SET and Pcd.TokenCName == PcdModule.TokenCName:\r
72fbe88d
CJ
943 PcdExCNameTest += 1\r
944 # get out early once we found > 1...\r
945 if PcdExCNameTest > 1:\r
946 break\r
f51461c8
LG
947 # Be compatible with the current code which using PcdToken and PcdGet/Set for DynamicEx Pcd.\r
948 # If only PcdToken and PcdGet/Set used in all Pcds with different CName, it should succeed to build.\r
949 # If PcdToken and PcdGet/Set used in the Pcds with different Guids but same CName, it should failed to build.\r
72fbe88d 950 if PcdExCNameTest > 1:\r
f51461c8
LG
951 AutoGenH.Append('// Disabled the macros, as PcdToken and PcdGet/Set are not allowed in the case that more than one DynamicEx Pcds are different Guids but same CName.\n')\r
952 AutoGenH.Append('// #define %s %s\n' % (PcdTokenName, PcdExTokenName))\r
953 AutoGenH.Append('// #define %s LibPcdGetEx%s(&%s, %s)\n' % (GetModeName, DatumSizeLib, Pcd.TokenSpaceGuidCName, PcdTokenName))\r
ccaa7754 954 AutoGenH.Append('// #define %s LibPcdGetExSize(&%s, %s)\n' % (GetModeSizeName, Pcd.TokenSpaceGuidCName, PcdTokenName))\r
656d2539 955 if Pcd.DatumType not in TAB_PCD_NUMERIC_TYPES:\r
f51461c8 956 AutoGenH.Append('// #define %s(SizeOfBuffer, Buffer) LibPcdSetEx%s(&%s, %s, (SizeOfBuffer), (Buffer))\n' % (SetModeName, DatumSizeLib, Pcd.TokenSpaceGuidCName, PcdTokenName))\r
82a6a960 957 AutoGenH.Append('// #define %s(SizeOfBuffer, Buffer) LibPcdSetEx%sS(&%s, %s, (SizeOfBuffer), (Buffer))\n' % (SetModeStatusName, DatumSizeLib, Pcd.TokenSpaceGuidCName, PcdTokenName))\r
f51461c8
LG
958 else:\r
959 AutoGenH.Append('// #define %s(Value) LibPcdSetEx%s(&%s, %s, (Value))\n' % (SetModeName, DatumSizeLib, Pcd.TokenSpaceGuidCName, PcdTokenName))\r
82a6a960 960 AutoGenH.Append('// #define %s(Value) LibPcdSetEx%sS(&%s, %s, (Value))\n' % (SetModeStatusName, DatumSizeLib, Pcd.TokenSpaceGuidCName, PcdTokenName))\r
f51461c8
LG
961 else:\r
962 AutoGenH.Append('#define %s %s\n' % (PcdTokenName, PcdExTokenName))\r
963 AutoGenH.Append('#define %s LibPcdGetEx%s(&%s, %s)\n' % (GetModeName, DatumSizeLib, Pcd.TokenSpaceGuidCName, PcdTokenName))\r
ccaa7754 964 AutoGenH.Append('#define %s LibPcdGetExSize(&%s, %s)\n' % (GetModeSizeName, Pcd.TokenSpaceGuidCName, PcdTokenName))\r
656d2539 965 if Pcd.DatumType not in TAB_PCD_NUMERIC_TYPES:\r
f51461c8 966 AutoGenH.Append('#define %s(SizeOfBuffer, Buffer) LibPcdSetEx%s(&%s, %s, (SizeOfBuffer), (Buffer))\n' % (SetModeName, DatumSizeLib, Pcd.TokenSpaceGuidCName, PcdTokenName))\r
82a6a960 967 AutoGenH.Append('#define %s(SizeOfBuffer, Buffer) LibPcdSetEx%sS(&%s, %s, (SizeOfBuffer), (Buffer))\n' % (SetModeStatusName, DatumSizeLib, Pcd.TokenSpaceGuidCName, PcdTokenName))\r
f51461c8
LG
968 else:\r
969 AutoGenH.Append('#define %s(Value) LibPcdSetEx%s(&%s, %s, (Value))\n' % (SetModeName, DatumSizeLib, Pcd.TokenSpaceGuidCName, PcdTokenName))\r
82a6a960 970 AutoGenH.Append('#define %s(Value) LibPcdSetEx%sS(&%s, %s, (Value))\n' % (SetModeStatusName, DatumSizeLib, Pcd.TokenSpaceGuidCName, PcdTokenName))\r
eece4292 971 elif Pcd.Type in PCD_DYNAMIC_TYPE_SET:\r
72fbe88d
CJ
972 PcdCNameTest = 0\r
973 for PcdModule in Info.LibraryPcdList + Info.ModulePcdList:\r
eece4292 974 if PcdModule.Type in PCD_DYNAMIC_TYPE_SET and Pcd.TokenCName == PcdModule.TokenCName:\r
72fbe88d
CJ
975 PcdCNameTest += 1\r
976 # get out early once we found > 1...\r
977 if PcdCNameTest > 1:\r
978 break\r
979 if PcdCNameTest > 1:\r
2a29017e 980 EdkLogger.error("build", AUTOGEN_ERROR, "More than one Dynamic Pcds [%s] are different Guids but same CName. They need to be changed to DynamicEx type to avoid the confliction.\n" % (TokenCName), ExtraData="[%s]" % str(Info.MetaFile.Path))\r
f51461c8 981 else:\r
38b986e3
YZ
982 AutoGenH.Append('#define %s LibPcdGet%s(%s)\n' % (GetModeName, DatumSizeLib, PcdTokenName))\r
983 AutoGenH.Append('#define %s LibPcdGetSize(%s)\n' % (GetModeSizeName, PcdTokenName))\r
656d2539 984 if Pcd.DatumType not in TAB_PCD_NUMERIC_TYPES:\r
38b986e3
YZ
985 AutoGenH.Append('#define %s(SizeOfBuffer, Buffer) LibPcdSet%s(%s, (SizeOfBuffer), (Buffer))\n' %(SetModeName, DatumSizeLib, PcdTokenName))\r
986 AutoGenH.Append('#define %s(SizeOfBuffer, Buffer) LibPcdSet%sS(%s, (SizeOfBuffer), (Buffer))\n' % (SetModeStatusName, DatumSizeLib, PcdTokenName))\r
987 else:\r
988 AutoGenH.Append('#define %s(Value) LibPcdSet%s(%s, (Value))\n' % (SetModeName, DatumSizeLib, PcdTokenName))\r
989 AutoGenH.Append('#define %s(Value) LibPcdSet%sS(%s, (Value))\n' % (SetModeStatusName, DatumSizeLib, PcdTokenName))\r
f51461c8 990 else:\r
2a29017e 991 PcdVariableName = '_gPcd_' + gItemTypeStringDatabase[Pcd.Type] + '_' + TokenCName\r
f51461c8
LG
992 Const = 'const'\r
993 if Pcd.Type == TAB_PCDS_PATCHABLE_IN_MODULE:\r
994 Const = ''\r
995 Type = ''\r
996 Array = ''\r
997 Value = Pcd.DefaultValue\r
998 Unicode = False\r
999 ValueNumber = 0\r
1000\r
1001 if Pcd.DatumType == 'BOOLEAN':\r
1002 BoolValue = Value.upper()\r
1003 if BoolValue == 'TRUE' or BoolValue == '1':\r
1004 Value = '1U'\r
1005 elif BoolValue == 'FALSE' or BoolValue == '0':\r
1006 Value = '0U'\r
1007\r
656d2539 1008 if Pcd.DatumType in TAB_PCD_CLEAN_NUMERIC_TYPES:\r
f51461c8 1009 try:\r
726c501c
YZ
1010 if Value.upper().endswith('L'):\r
1011 Value = Value[:-1]\r
0944818a 1012 ValueNumber = int (Value, 0)\r
f51461c8
LG
1013 except:\r
1014 EdkLogger.error("build", AUTOGEN_ERROR,\r
2a29017e 1015 "PCD value is not valid dec or hex number for datum type [%s] of PCD %s.%s" % (Pcd.DatumType, Pcd.TokenSpaceGuidCName, TokenCName),\r
f51461c8 1016 ExtraData="[%s]" % str(Info))\r
656d2539 1017 if Pcd.DatumType == TAB_UINT64:\r
f51461c8
LG
1018 if ValueNumber < 0:\r
1019 EdkLogger.error("build", AUTOGEN_ERROR,\r
2a29017e 1020 "PCD can't be set to negative value for datum type [%s] of PCD %s.%s" % (Pcd.DatumType, Pcd.TokenSpaceGuidCName, TokenCName),\r
f51461c8
LG
1021 ExtraData="[%s]" % str(Info))\r
1022 elif ValueNumber >= 0x10000000000000000:\r
1023 EdkLogger.error("build", AUTOGEN_ERROR,\r
2a29017e 1024 "Too large PCD value for datum type [%s] of PCD %s.%s" % (Pcd.DatumType, Pcd.TokenSpaceGuidCName, TokenCName),\r
f51461c8
LG
1025 ExtraData="[%s]" % str(Info))\r
1026 if not Value.endswith('ULL'):\r
1027 Value += 'ULL'\r
656d2539 1028 elif Pcd.DatumType == TAB_UINT32:\r
f51461c8
LG
1029 if ValueNumber < 0:\r
1030 EdkLogger.error("build", AUTOGEN_ERROR,\r
2a29017e 1031 "PCD can't be set to negative value for datum type [%s] of PCD %s.%s" % (Pcd.DatumType, Pcd.TokenSpaceGuidCName, TokenCName),\r
f51461c8
LG
1032 ExtraData="[%s]" % str(Info))\r
1033 elif ValueNumber >= 0x100000000:\r
1034 EdkLogger.error("build", AUTOGEN_ERROR,\r
2a29017e 1035 "Too large PCD value for datum type [%s] of PCD %s.%s" % (Pcd.DatumType, Pcd.TokenSpaceGuidCName, TokenCName),\r
f51461c8
LG
1036 ExtraData="[%s]" % str(Info))\r
1037 if not Value.endswith('U'):\r
1038 Value += 'U'\r
656d2539 1039 elif Pcd.DatumType == TAB_UINT16:\r
f51461c8
LG
1040 if ValueNumber < 0:\r
1041 EdkLogger.error("build", AUTOGEN_ERROR,\r
2a29017e 1042 "PCD can't be set to negative value for datum type [%s] of PCD %s.%s" % (Pcd.DatumType, Pcd.TokenSpaceGuidCName, TokenCName),\r
f51461c8
LG
1043 ExtraData="[%s]" % str(Info))\r
1044 elif ValueNumber >= 0x10000:\r
1045 EdkLogger.error("build", AUTOGEN_ERROR,\r
2a29017e 1046 "Too large PCD value for datum type [%s] of PCD %s.%s" % (Pcd.DatumType, Pcd.TokenSpaceGuidCName, TokenCName),\r
f51461c8
LG
1047 ExtraData="[%s]" % str(Info))\r
1048 if not Value.endswith('U'):\r
f7496d71 1049 Value += 'U'\r
656d2539 1050 elif Pcd.DatumType == TAB_UINT8:\r
f51461c8
LG
1051 if ValueNumber < 0:\r
1052 EdkLogger.error("build", AUTOGEN_ERROR,\r
2a29017e 1053 "PCD can't be set to negative value for datum type [%s] of PCD %s.%s" % (Pcd.DatumType, Pcd.TokenSpaceGuidCName, TokenCName),\r
f51461c8
LG
1054 ExtraData="[%s]" % str(Info))\r
1055 elif ValueNumber >= 0x100:\r
1056 EdkLogger.error("build", AUTOGEN_ERROR,\r
2a29017e 1057 "Too large PCD value for datum type [%s] of PCD %s.%s" % (Pcd.DatumType, Pcd.TokenSpaceGuidCName, TokenCName),\r
f51461c8
LG
1058 ExtraData="[%s]" % str(Info))\r
1059 if not Value.endswith('U'):\r
1060 Value += 'U'\r
656d2539 1061 if Pcd.DatumType not in TAB_PCD_NUMERIC_TYPES:\r
6b285ca3 1062 if not Pcd.MaxDatumSize:\r
f51461c8 1063 EdkLogger.error("build", AUTOGEN_ERROR,\r
2a29017e 1064 "Unknown [MaxDatumSize] of PCD [%s.%s]" % (Pcd.TokenSpaceGuidCName, TokenCName),\r
f51461c8
LG
1065 ExtraData="[%s]" % str(Info))\r
1066\r
1067 ArraySize = int(Pcd.MaxDatumSize, 0)\r
1068 if Value[0] == '{':\r
1069 Type = '(VOID *)'\r
6b285ca3 1070 ValueSize = len(Value.split(','))\r
f51461c8
LG
1071 else:\r
1072 if Value[0] == 'L':\r
1073 Unicode = True\r
1074 Value = Value.lstrip('L') #.strip('"')\r
1075 Value = eval(Value) # translate escape character\r
6b285ca3 1076 ValueSize = len(Value) + 1\r
f51461c8 1077 NewValue = '{'\r
ccaa7754 1078 for Index in range(0, len(Value)):\r
f51461c8
LG
1079 if Unicode:\r
1080 NewValue = NewValue + str(ord(Value[Index]) % 0x10000) + ', '\r
1081 else:\r
1082 NewValue = NewValue + str(ord(Value[Index]) % 0x100) + ', '\r
1083 if Unicode:\r
6b285ca3 1084 ArraySize = ArraySize / 2\r
f51461c8 1085 Value = NewValue + '0 }'\r
6b285ca3
YF
1086 if ArraySize < ValueSize:\r
1087 if Pcd.MaxSizeUserSet:\r
1088 EdkLogger.error("build", AUTOGEN_ERROR,\r
1089 "The maximum size of VOID* type PCD '%s.%s' is less than its actual size occupied." % (Pcd.TokenSpaceGuidCName, TokenCName),\r
1090 ExtraData="[%s]" % str(Info))\r
1091 else:\r
1092 ArraySize = Pcd.GetPcdSize()\r
1093 if Unicode:\r
1094 ArraySize = ArraySize / 2\r
f51461c8
LG
1095 Array = '[%d]' % ArraySize\r
1096 #\r
1097 # skip casting for fixed at build since it breaks ARM assembly.\r
1098 # Long term we need PCD macros that work in assembly\r
1099 #\r
656d2539 1100 elif Pcd.Type != TAB_PCDS_FIXED_AT_BUILD and Pcd.DatumType in TAB_PCD_NUMERIC_TYPES_VOID:\r
f51461c8
LG
1101 Value = "((%s)%s)" % (Pcd.DatumType, Value)\r
1102\r
1103 if Pcd.Type == TAB_PCDS_PATCHABLE_IN_MODULE:\r
2a29017e 1104 PcdValueName = '_PCD_PATCHABLE_VALUE_' + TokenCName\r
f51461c8 1105 else:\r
2a29017e 1106 PcdValueName = '_PCD_VALUE_' + TokenCName\r
f7496d71 1107\r
656d2539 1108 if Pcd.DatumType not in TAB_PCD_NUMERIC_TYPES:\r
f51461c8
LG
1109 #\r
1110 # For unicode, UINT16 array will be generated, so the alignment of unicode is guaranteed.\r
1111 #\r
674e2014 1112 AutoGenH.Append('#define %s %s%s\n' %(PcdValueName, Type, PcdVariableName))\r
f51461c8 1113 if Unicode:\r
f51461c8
LG
1114 AutoGenC.Append('GLOBAL_REMOVE_IF_UNREFERENCED %s UINT16 %s%s = %s;\n' % (Const, PcdVariableName, Array, Value))\r
1115 AutoGenH.Append('extern %s UINT16 %s%s;\n' %(Const, PcdVariableName, Array))\r
f51461c8 1116 else:\r
f51461c8
LG
1117 AutoGenC.Append('GLOBAL_REMOVE_IF_UNREFERENCED %s UINT8 %s%s = %s;\n' % (Const, PcdVariableName, Array, Value))\r
1118 AutoGenH.Append('extern %s UINT8 %s%s;\n' %(Const, PcdVariableName, Array))\r
674e2014 1119 AutoGenH.Append('#define %s %s%s\n' %(GetModeName, Type, PcdVariableName))\r
f7496d71 1120\r
5565a8c4 1121 PcdDataSize = Pcd.GetPcdSize()\r
2f5acc3b
BF
1122 if Pcd.Type == TAB_PCDS_FIXED_AT_BUILD:\r
1123 AutoGenH.Append('#define %s %s\n' % (FixPcdSizeTokenName, PcdDataSize))\r
ccaa7754
GL
1124 AutoGenH.Append('#define %s %s \n' % (GetModeSizeName, FixPcdSizeTokenName))\r
1125 AutoGenC.Append('GLOBAL_REMOVE_IF_UNREFERENCED const UINTN %s = %s;\n' % (FixedPcdSizeVariableName, PcdDataSize))\r
2f5acc3b
BF
1126 if Pcd.Type == TAB_PCDS_PATCHABLE_IN_MODULE:\r
1127 AutoGenH.Append('#define %s %s\n' % (PatchPcdSizeTokenName, Pcd.MaxDatumSize))\r
ccaa7754 1128 AutoGenH.Append('#define %s %s \n' % (GetModeSizeName, PatchPcdSizeVariableName))\r
2f5acc3b 1129 AutoGenH.Append('extern UINTN %s; \n' % PatchPcdSizeVariableName)\r
ccaa7754
GL
1130 AutoGenC.Append('GLOBAL_REMOVE_IF_UNREFERENCED UINTN %s = %s;\n' % (PatchPcdSizeVariableName, PcdDataSize))\r
1131 AutoGenC.Append('GLOBAL_REMOVE_IF_UNREFERENCED const UINTN %s = %s;\n' % (PatchPcdMaxSizeVariable, Pcd.MaxDatumSize))\r
f51461c8
LG
1132 elif Pcd.Type == TAB_PCDS_PATCHABLE_IN_MODULE:\r
1133 AutoGenH.Append('#define %s %s\n' %(PcdValueName, Value))\r
1134 AutoGenC.Append('volatile %s %s %s = %s;\n' %(Const, Pcd.DatumType, PcdVariableName, PcdValueName))\r
1135 AutoGenH.Append('extern volatile %s %s %s%s;\n' % (Const, Pcd.DatumType, PcdVariableName, Array))\r
1136 AutoGenH.Append('#define %s %s%s\n' % (GetModeName, Type, PcdVariableName))\r
f7496d71 1137\r
5565a8c4 1138 PcdDataSize = Pcd.GetPcdSize()\r
2f5acc3b 1139 AutoGenH.Append('#define %s %s\n' % (PatchPcdSizeTokenName, PcdDataSize))\r
f7496d71 1140\r
ccaa7754 1141 AutoGenH.Append('#define %s %s \n' % (GetModeSizeName, PatchPcdSizeVariableName))\r
2f5acc3b 1142 AutoGenH.Append('extern UINTN %s; \n' % PatchPcdSizeVariableName)\r
ccaa7754 1143 AutoGenC.Append('GLOBAL_REMOVE_IF_UNREFERENCED UINTN %s = %s;\n' % (PatchPcdSizeVariableName, PcdDataSize))\r
f51461c8 1144 else:\r
5565a8c4 1145 PcdDataSize = Pcd.GetPcdSize()\r
2f5acc3b 1146 AutoGenH.Append('#define %s %s\n' % (FixPcdSizeTokenName, PcdDataSize))\r
ccaa7754 1147 AutoGenH.Append('#define %s %s \n' % (GetModeSizeName, FixPcdSizeTokenName))\r
f7496d71 1148\r
f51461c8
LG
1149 AutoGenH.Append('#define %s %s\n' %(PcdValueName, Value))\r
1150 AutoGenC.Append('GLOBAL_REMOVE_IF_UNREFERENCED %s %s %s = %s;\n' %(Const, Pcd.DatumType, PcdVariableName, PcdValueName))\r
1151 AutoGenH.Append('extern %s %s %s%s;\n' % (Const, Pcd.DatumType, PcdVariableName, Array))\r
1152 AutoGenH.Append('#define %s %s%s\n' % (GetModeName, Type, PcdVariableName))\r
1153\r
1154 if Pcd.Type == TAB_PCDS_PATCHABLE_IN_MODULE:\r
656d2539 1155 if Pcd.DatumType not in TAB_PCD_NUMERIC_TYPES:\r
e70504cd
LG
1156 AutoGenH.Append('#define %s(SizeOfBuffer, Buffer) LibPatchPcdSetPtrAndSize((VOID *)_gPcd_BinaryPatch_%s, &_gPcd_BinaryPatch_Size_%s, (UINTN)_PCD_PATCHABLE_%s_SIZE, (SizeOfBuffer), (Buffer))\n' % (SetModeName, Pcd.TokenCName, Pcd.TokenCName, Pcd.TokenCName))\r
1157 AutoGenH.Append('#define %s(SizeOfBuffer, Buffer) LibPatchPcdSetPtrAndSizeS((VOID *)_gPcd_BinaryPatch_%s, &_gPcd_BinaryPatch_Size_%s, (UINTN)_PCD_PATCHABLE_%s_SIZE, (SizeOfBuffer), (Buffer))\n' % (SetModeStatusName, Pcd.TokenCName, Pcd.TokenCName, Pcd.TokenCName))\r
f51461c8
LG
1158 else:\r
1159 AutoGenH.Append('#define %s(Value) (%s = (Value))\n' % (SetModeName, PcdVariableName))\r
82a6a960 1160 AutoGenH.Append('#define %s(Value) ((%s = (Value)), RETURN_SUCCESS) \n' % (SetModeStatusName, PcdVariableName))\r
f51461c8
LG
1161 else:\r
1162 AutoGenH.Append('//#define %s ASSERT(FALSE) // It is not allowed to set value for a FIXED_AT_BUILD PCD\n' % SetModeName)\r
1163\r
1164## Create code for library module PCDs\r
1165#\r
1166# @param Info The ModuleAutoGen object\r
1167# @param AutoGenC The TemplateString object for C code\r
1168# @param AutoGenH The TemplateString object for header file\r
1169# @param Pcd The PCD object\r
1170#\r
1171def CreateLibraryPcdCode(Info, AutoGenC, AutoGenH, Pcd):\r
1172 PcdTokenNumber = Info.PlatformInfo.PcdTokenNumber\r
1173 TokenSpaceGuidCName = Pcd.TokenSpaceGuidCName\r
1174 TokenCName = Pcd.TokenCName\r
2a29017e
YZ
1175 for PcdItem in GlobalData.MixedPcd:\r
1176 if (TokenCName, TokenSpaceGuidCName) in GlobalData.MixedPcd[PcdItem]:\r
1177 TokenCName = PcdItem[0]\r
1178 break\r
f51461c8 1179 PcdTokenName = '_PCD_TOKEN_' + TokenCName\r
2a29017e
YZ
1180 FixPcdSizeTokenName = '_PCD_SIZE_' + TokenCName\r
1181 PatchPcdSizeTokenName = '_PCD_PATCHABLE_' + TokenCName +'_SIZE'\r
1182 PatchPcdSizeVariableName = '_gPcd_BinaryPatch_Size_' + TokenCName\r
f7b31aa5 1183 PatchPcdMaxSizeVariable = '_gPcd_BinaryPatch_MaxSize_' + TokenCName\r
1bfcf64f 1184 FixedPcdSizeVariableName = '_gPcd_FixedAtBuild_Size_' + TokenCName\r
763e8edf 1185\r
0f228f19
B
1186 if Pcd.PcdValueFromComm:\r
1187 Pcd.DefaultValue = Pcd.PcdValueFromComm\r
543f5ac3
B
1188 elif Pcd.PcdValueFromFdf:\r
1189 Pcd.DefaultValue = Pcd.PcdValueFromFdf\r
f51461c8
LG
1190 #\r
1191 # Write PCDs\r
1192 #\r
eece4292 1193 if Pcd.Type in PCD_DYNAMIC_EX_TYPE_SET:\r
f51461c8
LG
1194 TokenNumber = int(Pcd.TokenValue, 0)\r
1195 else:\r
1196 if (Pcd.TokenCName, Pcd.TokenSpaceGuidCName) not in PcdTokenNumber:\r
f7496d71
LG
1197 # If one of the Source built modules listed in the DSC is not listed in FDF modules,\r
1198 # and the INF lists a PCD can only use the PcdsDynamic access method (it is only\r
1199 # listed in the DEC file that declares the PCD as PcdsDynamic), then build tool will\r
1200 # report warning message notify the PI that they are attempting to build a module\r
1201 # that must be included in a flash image in order to be functional. These Dynamic PCD\r
1202 # will not be added into the Database unless it is used by other modules that are\r
1203 # included in the FDF file.\r
f51461c8 1204 # In this case, just assign an invalid token number to make it pass build.\r
eece4292 1205 if Pcd.Type in PCD_DYNAMIC_TYPE_SET:\r
f51461c8
LG
1206 TokenNumber = 0\r
1207 else:\r
1208 EdkLogger.error("build", AUTOGEN_ERROR,\r
2a29017e 1209 "No generated token number for %s.%s\n" % (Pcd.TokenSpaceGuidCName, TokenCName),\r
f51461c8
LG
1210 ExtraData="[%s]" % str(Info))\r
1211 else:\r
1212 TokenNumber = PcdTokenNumber[Pcd.TokenCName, Pcd.TokenSpaceGuidCName]\r
1213\r
1214 if Pcd.Type not in gItemTypeStringDatabase:\r
1215 EdkLogger.error("build", AUTOGEN_ERROR,\r
2a29017e 1216 "Unknown PCD type [%s] of PCD %s.%s" % (Pcd.Type, Pcd.TokenSpaceGuidCName, TokenCName),\r
f51461c8 1217 ExtraData="[%s]" % str(Info))\r
f51461c8
LG
1218\r
1219 DatumType = Pcd.DatumType\r
656d2539
CJ
1220 DatumSize = gDatumSizeStringDatabase[Pcd.DatumType] if Pcd.DatumType in gDatumSizeStringDatabase else gDatumSizeStringDatabase[TAB_VOID]\r
1221 DatumSizeLib = gDatumSizeStringDatabaseLib[Pcd.DatumType] if Pcd.DatumType in gDatumSizeStringDatabaseLib else gDatumSizeStringDatabaseLib[TAB_VOID]\r
1222 GetModeName = '_PCD_GET_MODE_' + gDatumSizeStringDatabaseH[Pcd.DatumType] + '_' + TokenCName if Pcd.DatumType in gDatumSizeStringDatabaseH else '_PCD_GET_MODE_' + gDatumSizeStringDatabaseH[TAB_VOID] + '_' + TokenCName\r
1223 SetModeName = '_PCD_SET_MODE_' + gDatumSizeStringDatabaseH[Pcd.DatumType] + '_' + TokenCName if Pcd.DatumType in gDatumSizeStringDatabaseH else '_PCD_SET_MODE_' + gDatumSizeStringDatabaseH[TAB_VOID] + '_' + TokenCName\r
1224 SetModeStatusName = '_PCD_SET_MODE_' + gDatumSizeStringDatabaseH[Pcd.DatumType] + '_S_' + TokenCName if Pcd.DatumType in gDatumSizeStringDatabaseH else '_PCD_SET_MODE_' + gDatumSizeStringDatabaseH[TAB_VOID] + '_S_' + TokenCName\r
2a29017e 1225 GetModeSizeName = '_PCD_GET_MODE_SIZE' + '_' + TokenCName\r
f51461c8
LG
1226\r
1227 Type = ''\r
1228 Array = ''\r
656d2539 1229 if Pcd.DatumType not in TAB_PCD_NUMERIC_TYPES:\r
d66670f9
YZ
1230 if Pcd.DefaultValue[0]== '{':\r
1231 Type = '(VOID *)'\r
f51461c8
LG
1232 Array = '[]'\r
1233 PcdItemType = Pcd.Type\r
eece4292 1234 if PcdItemType in PCD_DYNAMIC_EX_TYPE_SET:\r
2a29017e 1235 PcdExTokenName = '_PCD_TOKEN_' + TokenSpaceGuidCName + '_' + TokenCName\r
f51461c8 1236 AutoGenH.Append('\n#define %s %dU\n' % (PcdExTokenName, TokenNumber))\r
f7496d71 1237\r
f51461c8
LG
1238 if Info.IsLibrary:\r
1239 PcdList = Info.LibraryPcdList\r
1240 else:\r
1241 PcdList = Info.ModulePcdList\r
72fbe88d 1242 PcdExCNameTest = 0\r
f51461c8 1243 for PcdModule in PcdList:\r
eece4292 1244 if PcdModule.Type in PCD_DYNAMIC_EX_TYPE_SET and Pcd.TokenCName == PcdModule.TokenCName:\r
72fbe88d
CJ
1245 PcdExCNameTest += 1\r
1246 # get out early once we found > 1...\r
1247 if PcdExCNameTest > 1:\r
1248 break\r
f51461c8
LG
1249 # Be compatible with the current code which using PcdGet/Set for DynamicEx Pcd.\r
1250 # If only PcdGet/Set used in all Pcds with different CName, it should succeed to build.\r
1251 # If PcdGet/Set used in the Pcds with different Guids but same CName, it should failed to build.\r
72fbe88d 1252 if PcdExCNameTest > 1:\r
f51461c8
LG
1253 AutoGenH.Append('// Disabled the macros, as PcdToken and PcdGet/Set are not allowed in the case that more than one DynamicEx Pcds are different Guids but same CName.\n')\r
1254 AutoGenH.Append('// #define %s %s\n' % (PcdTokenName, PcdExTokenName))\r
1255 AutoGenH.Append('// #define %s LibPcdGetEx%s(&%s, %s)\n' % (GetModeName, DatumSizeLib, Pcd.TokenSpaceGuidCName, PcdTokenName))\r
ccaa7754 1256 AutoGenH.Append('// #define %s LibPcdGetExSize(&%s, %s)\n' % (GetModeSizeName, Pcd.TokenSpaceGuidCName, PcdTokenName))\r
656d2539 1257 if Pcd.DatumType not in TAB_PCD_NUMERIC_TYPES:\r
f51461c8 1258 AutoGenH.Append('// #define %s(SizeOfBuffer, Buffer) LibPcdSetEx%s(&%s, %s, (SizeOfBuffer), (Buffer))\n' % (SetModeName, DatumSizeLib, Pcd.TokenSpaceGuidCName, PcdTokenName))\r
82a6a960 1259 AutoGenH.Append('// #define %s(SizeOfBuffer, Buffer) LibPcdSetEx%sS(&%s, %s, (SizeOfBuffer), (Buffer))\n' % (SetModeStatusName, DatumSizeLib, Pcd.TokenSpaceGuidCName, PcdTokenName))\r
f51461c8
LG
1260 else:\r
1261 AutoGenH.Append('// #define %s(Value) LibPcdSetEx%s(&%s, %s, (Value))\n' % (SetModeName, DatumSizeLib, Pcd.TokenSpaceGuidCName, PcdTokenName))\r
82a6a960 1262 AutoGenH.Append('// #define %s(Value) LibPcdSetEx%sS(&%s, %s, (Value))\n' % (SetModeStatusName, DatumSizeLib, Pcd.TokenSpaceGuidCName, PcdTokenName))\r
f51461c8
LG
1263 else:\r
1264 AutoGenH.Append('#define %s %s\n' % (PcdTokenName, PcdExTokenName))\r
1265 AutoGenH.Append('#define %s LibPcdGetEx%s(&%s, %s)\n' % (GetModeName, DatumSizeLib, Pcd.TokenSpaceGuidCName, PcdTokenName))\r
ccaa7754 1266 AutoGenH.Append('#define %s LibPcdGetExSize(&%s, %s)\n' % (GetModeSizeName, Pcd.TokenSpaceGuidCName, PcdTokenName))\r
656d2539 1267 if Pcd.DatumType not in TAB_PCD_NUMERIC_TYPES:\r
f51461c8 1268 AutoGenH.Append('#define %s(SizeOfBuffer, Buffer) LibPcdSetEx%s(&%s, %s, (SizeOfBuffer), (Buffer))\n' % (SetModeName, DatumSizeLib, Pcd.TokenSpaceGuidCName, PcdTokenName))\r
82a6a960 1269 AutoGenH.Append('#define %s(SizeOfBuffer, Buffer) LibPcdSetEx%sS(&%s, %s, (SizeOfBuffer), (Buffer))\n' % (SetModeStatusName, DatumSizeLib, Pcd.TokenSpaceGuidCName, PcdTokenName))\r
f51461c8
LG
1270 else:\r
1271 AutoGenH.Append('#define %s(Value) LibPcdSetEx%s(&%s, %s, (Value))\n' % (SetModeName, DatumSizeLib, Pcd.TokenSpaceGuidCName, PcdTokenName))\r
82a6a960 1272 AutoGenH.Append('#define %s(Value) LibPcdSetEx%sS(&%s, %s, (Value))\n' % (SetModeStatusName, DatumSizeLib, Pcd.TokenSpaceGuidCName, PcdTokenName))\r
f51461c8
LG
1273 else:\r
1274 AutoGenH.Append('#define _PCD_TOKEN_%s %dU\n' % (TokenCName, TokenNumber))\r
eece4292 1275 if PcdItemType in PCD_DYNAMIC_TYPE_SET:\r
38b986e3
YZ
1276 PcdList = []\r
1277 PcdCNameList = []\r
1278 PcdList.extend(Info.LibraryPcdList)\r
1279 PcdList.extend(Info.ModulePcdList)\r
1280 for PcdModule in PcdList:\r
eece4292 1281 if PcdModule.Type in PCD_DYNAMIC_TYPE_SET:\r
38b986e3
YZ
1282 PcdCNameList.append(PcdModule.TokenCName)\r
1283 if PcdCNameList.count(Pcd.TokenCName) > 1:\r
2a29017e 1284 EdkLogger.error("build", AUTOGEN_ERROR, "More than one Dynamic Pcds [%s] are different Guids but same CName.They need to be changed to DynamicEx type to avoid the confliction.\n" % (TokenCName), ExtraData="[%s]" % str(Info.MetaFile.Path))\r
f51461c8 1285 else:\r
38b986e3
YZ
1286 AutoGenH.Append('#define %s LibPcdGet%s(%s)\n' % (GetModeName, DatumSizeLib, PcdTokenName))\r
1287 AutoGenH.Append('#define %s LibPcdGetSize(%s)\n' % (GetModeSizeName, PcdTokenName))\r
656d2539 1288 if DatumType not in TAB_PCD_NUMERIC_TYPES:\r
38b986e3
YZ
1289 AutoGenH.Append('#define %s(SizeOfBuffer, Buffer) LibPcdSet%s(%s, (SizeOfBuffer), (Buffer))\n' %(SetModeName, DatumSizeLib, PcdTokenName))\r
1290 AutoGenH.Append('#define %s(SizeOfBuffer, Buffer) LibPcdSet%sS(%s, (SizeOfBuffer), (Buffer))\n' % (SetModeStatusName, DatumSizeLib, PcdTokenName))\r
1291 else:\r
1292 AutoGenH.Append('#define %s(Value) LibPcdSet%s(%s, (Value))\n' % (SetModeName, DatumSizeLib, PcdTokenName))\r
1293 AutoGenH.Append('#define %s(Value) LibPcdSet%sS(%s, (Value))\n' % (SetModeStatusName, DatumSizeLib, PcdTokenName))\r
f51461c8 1294 if PcdItemType == TAB_PCDS_PATCHABLE_IN_MODULE:\r
f7b31aa5 1295 GetModeMaxSizeName = '_PCD_GET_MODE_MAXSIZE' + '_' + TokenCName\r
f51461c8 1296 PcdVariableName = '_gPcd_' + gItemTypeStringDatabase[TAB_PCDS_PATCHABLE_IN_MODULE] + '_' + TokenCName\r
656d2539
CJ
1297 if DatumType not in TAB_PCD_NUMERIC_TYPES:\r
1298 if DatumType == TAB_VOID and Array == '[]':\r
1299 DatumType = [TAB_UINT8, TAB_UINT16][Pcd.DefaultValue[0] == 'L']\r
f7b31aa5 1300 else:\r
656d2539 1301 DatumType = TAB_UINT8\r
d66670f9
YZ
1302 AutoGenH.Append('extern %s _gPcd_BinaryPatch_%s%s;\n' %(DatumType, TokenCName, Array))\r
1303 else:\r
1304 AutoGenH.Append('extern volatile %s %s%s;\n' % (DatumType, PcdVariableName, Array))\r
f51461c8 1305 AutoGenH.Append('#define %s %s_gPcd_BinaryPatch_%s\n' %(GetModeName, Type, TokenCName))\r
5565a8c4 1306 PcdDataSize = Pcd.GetPcdSize()\r
656d2539 1307 if Pcd.DatumType not in TAB_PCD_NUMERIC_TYPES:\r
f7b31aa5
YZ
1308 AutoGenH.Append('#define %s(SizeOfBuffer, Buffer) LibPatchPcdSetPtrAndSize((VOID *)_gPcd_BinaryPatch_%s, &%s, %s, (SizeOfBuffer), (Buffer))\n' % (SetModeName, TokenCName, PatchPcdSizeVariableName, PatchPcdMaxSizeVariable))\r
1309 AutoGenH.Append('#define %s(SizeOfBuffer, Buffer) LibPatchPcdSetPtrAndSizeS((VOID *)_gPcd_BinaryPatch_%s, &%s, %s, (SizeOfBuffer), (Buffer))\n' % (SetModeStatusName, TokenCName, PatchPcdSizeVariableName, PatchPcdMaxSizeVariable))\r
1310 AutoGenH.Append('#define %s %s\n' % (GetModeMaxSizeName, PatchPcdMaxSizeVariable))\r
1311 AutoGenH.Append('extern const UINTN %s; \n' % PatchPcdMaxSizeVariable)\r
27187d24
LG
1312 else:\r
1313 AutoGenH.Append('#define %s(Value) (%s = (Value))\n' % (SetModeName, PcdVariableName))\r
1314 AutoGenH.Append('#define %s(Value) ((%s = (Value)), RETURN_SUCCESS)\n' % (SetModeStatusName, PcdVariableName))\r
a6c31c6d
YZ
1315 AutoGenH.Append('#define %s %s\n' % (PatchPcdSizeTokenName, PcdDataSize))\r
1316\r
ccaa7754 1317 AutoGenH.Append('#define %s %s\n' % (GetModeSizeName, PatchPcdSizeVariableName))\r
2f5acc3b 1318 AutoGenH.Append('extern UINTN %s; \n' % PatchPcdSizeVariableName)\r
f7496d71 1319\r
f51461c8 1320 if PcdItemType == TAB_PCDS_FIXED_AT_BUILD or PcdItemType == TAB_PCDS_FEATURE_FLAG:\r
ccaa7754 1321 key = ".".join((Pcd.TokenSpaceGuidCName, Pcd.TokenCName))\r
7256bd55 1322 PcdVariableName = '_gPcd_' + gItemTypeStringDatabase[Pcd.Type] + '_' + TokenCName\r
656d2539
CJ
1323 if DatumType == TAB_VOID and Array == '[]':\r
1324 DatumType = [TAB_UINT8, TAB_UINT16][Pcd.DefaultValue[0] == 'L']\r
1325 if DatumType not in TAB_PCD_NUMERIC_TYPES_VOID:\r
1326 DatumType = TAB_UINT8\r
f51461c8
LG
1327 AutoGenH.Append('extern const %s _gPcd_FixedAtBuild_%s%s;\n' %(DatumType, TokenCName, Array))\r
1328 AutoGenH.Append('#define %s %s_gPcd_FixedAtBuild_%s\n' %(GetModeName, Type, TokenCName))\r
1329 AutoGenH.Append('//#define %s ASSERT(FALSE) // It is not allowed to set value for a FIXED_AT_BUILD PCD\n' % SetModeName)\r
f7496d71 1330\r
1bfcf64f 1331 ConstFixedPcd = False\r
c9da41b2 1332 if PcdItemType == TAB_PCDS_FIXED_AT_BUILD and (key in Info.ConstPcd or (Info.IsLibrary and not Info._ReferenceModules)):\r
1bfcf64f 1333 ConstFixedPcd = True\r
eca980c0
YZ
1334 if key in Info.ConstPcd:\r
1335 Pcd.DefaultValue = Info.ConstPcd[key]\r
656d2539 1336 if Pcd.DatumType not in TAB_PCD_NUMERIC_TYPES:\r
7256bd55
YZ
1337 AutoGenH.Append('#define _PCD_VALUE_%s %s%s\n' %(TokenCName, Type, PcdVariableName))\r
1338 else:\r
1339 AutoGenH.Append('#define _PCD_VALUE_%s %s\n' %(TokenCName, Pcd.DefaultValue))\r
5565a8c4 1340 PcdDataSize = Pcd.GetPcdSize()\r
2f5acc3b 1341 if PcdItemType == TAB_PCDS_FIXED_AT_BUILD:\r
656d2539 1342 if Pcd.DatumType not in TAB_PCD_NUMERIC_TYPES:\r
1bfcf64f
YZ
1343 if ConstFixedPcd:\r
1344 AutoGenH.Append('#define %s %s\n' % (FixPcdSizeTokenName, PcdDataSize))\r
ccaa7754 1345 AutoGenH.Append('#define %s %s\n' % (GetModeSizeName, FixPcdSizeTokenName))\r
1bfcf64f 1346 else:\r
ccaa7754
GL
1347 AutoGenH.Append('#define %s %s\n' % (GetModeSizeName, FixedPcdSizeVariableName))\r
1348 AutoGenH.Append('#define %s %s\n' % (FixPcdSizeTokenName, FixedPcdSizeVariableName))\r
1bfcf64f
YZ
1349 AutoGenH.Append('extern const UINTN %s; \n' % FixedPcdSizeVariableName)\r
1350 else:\r
1351 AutoGenH.Append('#define %s %s\n' % (FixPcdSizeTokenName, PcdDataSize))\r
ccaa7754 1352 AutoGenH.Append('#define %s %s\n' % (GetModeSizeName, FixPcdSizeTokenName))\r
f51461c8
LG
1353\r
1354## Create code for library constructor\r
1355#\r
1356# @param Info The ModuleAutoGen object\r
1357# @param AutoGenC The TemplateString object for C code\r
1358# @param AutoGenH The TemplateString object for header file\r
1359#\r
1360def CreateLibraryConstructorCode(Info, AutoGenC, AutoGenH):\r
1361 #\r
1362 # Library Constructors\r
1363 #\r
1364 ConstructorPrototypeString = TemplateString()\r
1365 ConstructorCallingString = TemplateString()\r
1366 if Info.IsLibrary:\r
1367 DependentLibraryList = [Info.Module]\r
1368 else:\r
1369 DependentLibraryList = Info.DependentLibraryList\r
1370 for Lib in DependentLibraryList:\r
1371 if len(Lib.ConstructorList) <= 0:\r
1372 continue\r
1373 Dict = {'Function':Lib.ConstructorList}\r
8bb63e37
CJ
1374 if Lib.ModuleType in [SUP_MODULE_BASE, SUP_MODULE_SEC]:\r
1375 ConstructorPrototypeString.Append(gLibraryStructorPrototype[SUP_MODULE_BASE].Replace(Dict))\r
1376 ConstructorCallingString.Append(gLibraryStructorCall[SUP_MODULE_BASE].Replace(Dict))\r
88c6c1b6 1377 elif Lib.ModuleType in SUP_MODULE_SET_PEI:\r
f51461c8
LG
1378 ConstructorPrototypeString.Append(gLibraryStructorPrototype['PEI'].Replace(Dict))\r
1379 ConstructorCallingString.Append(gLibraryStructorCall['PEI'].Replace(Dict))\r
ccaa7754
GL
1380 elif Lib.ModuleType in [SUP_MODULE_DXE_CORE, SUP_MODULE_DXE_DRIVER, SUP_MODULE_DXE_SMM_DRIVER, SUP_MODULE_DXE_RUNTIME_DRIVER,\r
1381 SUP_MODULE_DXE_SAL_DRIVER, SUP_MODULE_UEFI_DRIVER, SUP_MODULE_UEFI_APPLICATION, SUP_MODULE_SMM_CORE]:\r
f51461c8
LG
1382 ConstructorPrototypeString.Append(gLibraryStructorPrototype['DXE'].Replace(Dict))\r
1383 ConstructorCallingString.Append(gLibraryStructorCall['DXE'].Replace(Dict))\r
ccaa7754 1384 elif Lib.ModuleType in [SUP_MODULE_MM_STANDALONE, SUP_MODULE_MM_CORE_STANDALONE]:\r
5a9c3e3e
SV
1385 ConstructorPrototypeString.Append(gLibraryStructorPrototype['MM'].Replace(Dict))\r
1386 ConstructorCallingString.Append(gLibraryStructorCall['MM'].Replace(Dict))\r
f51461c8
LG
1387\r
1388 if str(ConstructorPrototypeString) == '':\r
1389 ConstructorPrototypeList = []\r
1390 else:\r
1391 ConstructorPrototypeList = [str(ConstructorPrototypeString)]\r
1392 if str(ConstructorCallingString) == '':\r
1393 ConstructorCallingList = []\r
1394 else:\r
1395 ConstructorCallingList = [str(ConstructorCallingString)]\r
1396\r
1397 Dict = {\r
1398 'Type' : 'Constructor',\r
1399 'FunctionPrototype' : ConstructorPrototypeList,\r
1400 'FunctionCall' : ConstructorCallingList\r
1401 }\r
1402 if Info.IsLibrary:\r
1403 AutoGenH.Append("${BEGIN}${FunctionPrototype}${END}", Dict)\r
1404 else:\r
8bb63e37
CJ
1405 if Info.ModuleType in [SUP_MODULE_BASE, SUP_MODULE_SEC]:\r
1406 AutoGenC.Append(gLibraryString[SUP_MODULE_BASE].Replace(Dict))\r
88c6c1b6 1407 elif Info.ModuleType in SUP_MODULE_SET_PEI:\r
f51461c8 1408 AutoGenC.Append(gLibraryString['PEI'].Replace(Dict))\r
ccaa7754
GL
1409 elif Info.ModuleType in [SUP_MODULE_DXE_CORE, SUP_MODULE_DXE_DRIVER, SUP_MODULE_DXE_SMM_DRIVER, SUP_MODULE_DXE_RUNTIME_DRIVER,\r
1410 SUP_MODULE_DXE_SAL_DRIVER, SUP_MODULE_UEFI_DRIVER, SUP_MODULE_UEFI_APPLICATION, SUP_MODULE_SMM_CORE]:\r
f51461c8 1411 AutoGenC.Append(gLibraryString['DXE'].Replace(Dict))\r
ccaa7754 1412 elif Info.ModuleType in [SUP_MODULE_MM_STANDALONE, SUP_MODULE_MM_CORE_STANDALONE]:\r
5a9c3e3e 1413 AutoGenC.Append(gLibraryString['MM'].Replace(Dict))\r
f51461c8
LG
1414\r
1415## Create code for library destructor\r
1416#\r
1417# @param Info The ModuleAutoGen object\r
1418# @param AutoGenC The TemplateString object for C code\r
1419# @param AutoGenH The TemplateString object for header file\r
1420#\r
1421def CreateLibraryDestructorCode(Info, AutoGenC, AutoGenH):\r
1422 #\r
1423 # Library Destructors\r
1424 #\r
1425 DestructorPrototypeString = TemplateString()\r
1426 DestructorCallingString = TemplateString()\r
1427 if Info.IsLibrary:\r
1428 DependentLibraryList = [Info.Module]\r
1429 else:\r
1430 DependentLibraryList = Info.DependentLibraryList\r
1431 for Index in range(len(DependentLibraryList)-1, -1, -1):\r
1432 Lib = DependentLibraryList[Index]\r
1433 if len(Lib.DestructorList) <= 0:\r
1434 continue\r
1435 Dict = {'Function':Lib.DestructorList}\r
8bb63e37
CJ
1436 if Lib.ModuleType in [SUP_MODULE_BASE, SUP_MODULE_SEC]:\r
1437 DestructorPrototypeString.Append(gLibraryStructorPrototype[SUP_MODULE_BASE].Replace(Dict))\r
1438 DestructorCallingString.Append(gLibraryStructorCall[SUP_MODULE_BASE].Replace(Dict))\r
88c6c1b6 1439 elif Lib.ModuleType in SUP_MODULE_SET_PEI:\r
f51461c8
LG
1440 DestructorPrototypeString.Append(gLibraryStructorPrototype['PEI'].Replace(Dict))\r
1441 DestructorCallingString.Append(gLibraryStructorCall['PEI'].Replace(Dict))\r
ccaa7754
GL
1442 elif Lib.ModuleType in [SUP_MODULE_DXE_CORE, SUP_MODULE_DXE_DRIVER, SUP_MODULE_DXE_SMM_DRIVER, SUP_MODULE_DXE_RUNTIME_DRIVER,\r
1443 SUP_MODULE_DXE_SAL_DRIVER, SUP_MODULE_UEFI_DRIVER, SUP_MODULE_UEFI_APPLICATION, SUP_MODULE_SMM_CORE]:\r
f51461c8
LG
1444 DestructorPrototypeString.Append(gLibraryStructorPrototype['DXE'].Replace(Dict))\r
1445 DestructorCallingString.Append(gLibraryStructorCall['DXE'].Replace(Dict))\r
ccaa7754 1446 elif Lib.ModuleType in [SUP_MODULE_MM_STANDALONE, SUP_MODULE_MM_CORE_STANDALONE]:\r
5a9c3e3e
SV
1447 DestructorPrototypeString.Append(gLibraryStructorPrototype['MM'].Replace(Dict))\r
1448 DestructorCallingString.Append(gLibraryStructorCall['MM'].Replace(Dict))\r
f51461c8
LG
1449\r
1450 if str(DestructorPrototypeString) == '':\r
1451 DestructorPrototypeList = []\r
1452 else:\r
1453 DestructorPrototypeList = [str(DestructorPrototypeString)]\r
1454 if str(DestructorCallingString) == '':\r
1455 DestructorCallingList = []\r
1456 else:\r
1457 DestructorCallingList = [str(DestructorCallingString)]\r
1458\r
1459 Dict = {\r
1460 'Type' : 'Destructor',\r
1461 'FunctionPrototype' : DestructorPrototypeList,\r
1462 'FunctionCall' : DestructorCallingList\r
1463 }\r
1464 if Info.IsLibrary:\r
1465 AutoGenH.Append("${BEGIN}${FunctionPrototype}${END}", Dict)\r
1466 else:\r
8bb63e37
CJ
1467 if Info.ModuleType in [SUP_MODULE_BASE, SUP_MODULE_SEC]:\r
1468 AutoGenC.Append(gLibraryString[SUP_MODULE_BASE].Replace(Dict))\r
88c6c1b6 1469 elif Info.ModuleType in SUP_MODULE_SET_PEI:\r
f51461c8 1470 AutoGenC.Append(gLibraryString['PEI'].Replace(Dict))\r
ccaa7754
GL
1471 elif Info.ModuleType in [SUP_MODULE_DXE_CORE, SUP_MODULE_DXE_DRIVER, SUP_MODULE_DXE_SMM_DRIVER, SUP_MODULE_DXE_RUNTIME_DRIVER,\r
1472 SUP_MODULE_DXE_SAL_DRIVER, SUP_MODULE_UEFI_DRIVER, SUP_MODULE_UEFI_APPLICATION, SUP_MODULE_SMM_CORE]:\r
f51461c8 1473 AutoGenC.Append(gLibraryString['DXE'].Replace(Dict))\r
ccaa7754 1474 elif Info.ModuleType in [SUP_MODULE_MM_STANDALONE, SUP_MODULE_MM_CORE_STANDALONE]:\r
5a9c3e3e 1475 AutoGenC.Append(gLibraryString['MM'].Replace(Dict))\r
f51461c8
LG
1476\r
1477\r
1478## Create code for ModuleEntryPoint\r
1479#\r
1480# @param Info The ModuleAutoGen object\r
1481# @param AutoGenC The TemplateString object for C code\r
1482# @param AutoGenH The TemplateString object for header file\r
1483#\r
1484def CreateModuleEntryPointCode(Info, AutoGenC, AutoGenH):\r
8bb63e37 1485 if Info.IsLibrary or Info.ModuleType in [SUP_MODULE_USER_DEFINED, SUP_MODULE_SEC]:\r
f51461c8
LG
1486 return\r
1487 #\r
1488 # Module Entry Points\r
1489 #\r
1490 NumEntryPoints = len(Info.Module.ModuleEntryPointList)\r
1491 if 'PI_SPECIFICATION_VERSION' in Info.Module.Specification:\r
1492 PiSpecVersion = Info.Module.Specification['PI_SPECIFICATION_VERSION']\r
1493 else:\r
1494 PiSpecVersion = '0x00000000'\r
1495 if 'UEFI_SPECIFICATION_VERSION' in Info.Module.Specification:\r
1496 UefiSpecVersion = Info.Module.Specification['UEFI_SPECIFICATION_VERSION']\r
1497 else:\r
1498 UefiSpecVersion = '0x00000000'\r
1499 Dict = {\r
1500 'Function' : Info.Module.ModuleEntryPointList,\r
1501 'PiSpecVersion' : PiSpecVersion + 'U',\r
1502 'UefiSpecVersion': UefiSpecVersion + 'U'\r
1503 }\r
1504\r
8bb63e37 1505 if Info.ModuleType in [SUP_MODULE_PEI_CORE, SUP_MODULE_DXE_CORE, SUP_MODULE_SMM_CORE, SUP_MODULE_MM_CORE_STANDALONE]:\r
128d435f 1506 if Info.SourceFileList:\r
f51461c8
LG
1507 if NumEntryPoints != 1:\r
1508 EdkLogger.error(\r
1509 "build",\r
1510 AUTOGEN_ERROR,\r
1511 '%s must have exactly one entry point' % Info.ModuleType,\r
1512 File=str(Info),\r
1513 ExtraData= ", ".join(Info.Module.ModuleEntryPointList)\r
1514 )\r
8bb63e37 1515 if Info.ModuleType == SUP_MODULE_PEI_CORE:\r
f51461c8
LG
1516 AutoGenC.Append(gPeiCoreEntryPointString.Replace(Dict))\r
1517 AutoGenH.Append(gPeiCoreEntryPointPrototype.Replace(Dict))\r
8bb63e37 1518 elif Info.ModuleType == SUP_MODULE_DXE_CORE:\r
f51461c8
LG
1519 AutoGenC.Append(gDxeCoreEntryPointString.Replace(Dict))\r
1520 AutoGenH.Append(gDxeCoreEntryPointPrototype.Replace(Dict))\r
8bb63e37 1521 elif Info.ModuleType == SUP_MODULE_SMM_CORE:\r
f51461c8
LG
1522 AutoGenC.Append(gSmmCoreEntryPointString.Replace(Dict))\r
1523 AutoGenH.Append(gSmmCoreEntryPointPrototype.Replace(Dict))\r
8bb63e37 1524 elif Info.ModuleType == SUP_MODULE_MM_CORE_STANDALONE:\r
5a9c3e3e
SV
1525 AutoGenC.Append(gMmCoreStandaloneEntryPointString.Replace(Dict))\r
1526 AutoGenH.Append(gMmCoreStandaloneEntryPointPrototype.Replace(Dict))\r
8bb63e37 1527 elif Info.ModuleType == SUP_MODULE_PEIM:\r
f51461c8
LG
1528 if NumEntryPoints < 2:\r
1529 AutoGenC.Append(gPeimEntryPointString[NumEntryPoints].Replace(Dict))\r
1530 else:\r
1531 AutoGenC.Append(gPeimEntryPointString[2].Replace(Dict))\r
1532 AutoGenH.Append(gPeimEntryPointPrototype.Replace(Dict))\r
ccaa7754 1533 elif Info.ModuleType in [SUP_MODULE_DXE_RUNTIME_DRIVER, SUP_MODULE_DXE_DRIVER, SUP_MODULE_DXE_SAL_DRIVER, SUP_MODULE_UEFI_DRIVER]:\r
f51461c8
LG
1534 if NumEntryPoints < 2:\r
1535 AutoGenC.Append(gUefiDriverEntryPointString[NumEntryPoints].Replace(Dict))\r
1536 else:\r
1537 AutoGenC.Append(gUefiDriverEntryPointString[2].Replace(Dict))\r
1538 AutoGenH.Append(gUefiDriverEntryPointPrototype.Replace(Dict))\r
8bb63e37 1539 elif Info.ModuleType == SUP_MODULE_DXE_SMM_DRIVER:\r
f51461c8
LG
1540 if NumEntryPoints == 0:\r
1541 AutoGenC.Append(gDxeSmmEntryPointString[0].Replace(Dict))\r
1542 else:\r
1543 AutoGenC.Append(gDxeSmmEntryPointString[1].Replace(Dict))\r
5a9c3e3e 1544 AutoGenH.Append(gDxeSmmEntryPointPrototype.Replace(Dict))\r
8bb63e37 1545 elif Info.ModuleType == SUP_MODULE_MM_STANDALONE:\r
5a9c3e3e
SV
1546 if NumEntryPoints < 2:\r
1547 AutoGenC.Append(gMmStandaloneEntryPointString[NumEntryPoints].Replace(Dict))\r
1548 else:\r
1549 AutoGenC.Append(gMmStandaloneEntryPointString[2].Replace(Dict))\r
1550 AutoGenH.Append(gMmStandaloneEntryPointPrototype.Replace(Dict))\r
8bb63e37 1551 elif Info.ModuleType == SUP_MODULE_UEFI_APPLICATION:\r
f51461c8
LG
1552 if NumEntryPoints < 2:\r
1553 AutoGenC.Append(gUefiApplicationEntryPointString[NumEntryPoints].Replace(Dict))\r
1554 else:\r
1555 AutoGenC.Append(gUefiApplicationEntryPointString[2].Replace(Dict))\r
1556 AutoGenH.Append(gUefiApplicationEntryPointPrototype.Replace(Dict))\r
1557\r
1558## Create code for ModuleUnloadImage\r
1559#\r
1560# @param Info The ModuleAutoGen object\r
1561# @param AutoGenC The TemplateString object for C code\r
1562# @param AutoGenH The TemplateString object for header file\r
1563#\r
1564def CreateModuleUnloadImageCode(Info, AutoGenC, AutoGenH):\r
8bb63e37 1565 if Info.IsLibrary or Info.ModuleType in [SUP_MODULE_USER_DEFINED, SUP_MODULE_SEC]:\r
f51461c8
LG
1566 return\r
1567 #\r
1568 # Unload Image Handlers\r
1569 #\r
1570 NumUnloadImage = len(Info.Module.ModuleUnloadImageList)\r
1571 Dict = {'Count':str(NumUnloadImage) + 'U', 'Function':Info.Module.ModuleUnloadImageList}\r
1572 if NumUnloadImage < 2:\r
1573 AutoGenC.Append(gUefiUnloadImageString[NumUnloadImage].Replace(Dict))\r
1574 else:\r
1575 AutoGenC.Append(gUefiUnloadImageString[2].Replace(Dict))\r
1576 AutoGenH.Append(gUefiUnloadImagePrototype.Replace(Dict))\r
1577\r
1578## Create code for GUID\r
1579#\r
1580# @param Info The ModuleAutoGen object\r
1581# @param AutoGenC The TemplateString object for C code\r
1582# @param AutoGenH The TemplateString object for header file\r
1583#\r
1584def CreateGuidDefinitionCode(Info, AutoGenC, AutoGenH):\r
8bb63e37 1585 if Info.ModuleType in [SUP_MODULE_USER_DEFINED, SUP_MODULE_BASE]:\r
91fa33ee 1586 GuidType = TAB_GUID\r
f51461c8
LG
1587 else:\r
1588 GuidType = "EFI_GUID"\r
1589\r
1590 if Info.GuidList:\r
7beed8a3
YZ
1591 if not Info.IsLibrary:\r
1592 AutoGenC.Append("\n// Guids\n")\r
8262037f 1593 AutoGenH.Append("\n// Guids\n")\r
f51461c8
LG
1594 #\r
1595 # GUIDs\r
1596 #\r
1597 for Key in Info.GuidList:\r
7beed8a3
YZ
1598 if not Info.IsLibrary:\r
1599 AutoGenC.Append('GLOBAL_REMOVE_IF_UNREFERENCED %s %s = %s;\n' % (GuidType, Key, Info.GuidList[Key]))\r
8262037f 1600 AutoGenH.Append('extern %s %s;\n' % (GuidType, Key))\r
f51461c8
LG
1601\r
1602## Create code for protocol\r
1603#\r
1604# @param Info The ModuleAutoGen object\r
1605# @param AutoGenC The TemplateString object for C code\r
1606# @param AutoGenH The TemplateString object for header file\r
1607#\r
1608def CreateProtocolDefinitionCode(Info, AutoGenC, AutoGenH):\r
8bb63e37 1609 if Info.ModuleType in [SUP_MODULE_USER_DEFINED, SUP_MODULE_BASE]:\r
91fa33ee 1610 GuidType = TAB_GUID\r
f51461c8
LG
1611 else:\r
1612 GuidType = "EFI_GUID"\r
1613\r
1614 if Info.ProtocolList:\r
7beed8a3
YZ
1615 if not Info.IsLibrary:\r
1616 AutoGenC.Append("\n// Protocols\n")\r
8262037f 1617 AutoGenH.Append("\n// Protocols\n")\r
f51461c8
LG
1618 #\r
1619 # Protocol GUIDs\r
1620 #\r
1621 for Key in Info.ProtocolList:\r
7beed8a3
YZ
1622 if not Info.IsLibrary:\r
1623 AutoGenC.Append('GLOBAL_REMOVE_IF_UNREFERENCED %s %s = %s;\n' % (GuidType, Key, Info.ProtocolList[Key]))\r
8262037f 1624 AutoGenH.Append('extern %s %s;\n' % (GuidType, Key))\r
f51461c8
LG
1625\r
1626## Create code for PPI\r
1627#\r
1628# @param Info The ModuleAutoGen object\r
1629# @param AutoGenC The TemplateString object for C code\r
1630# @param AutoGenH The TemplateString object for header file\r
1631#\r
1632def CreatePpiDefinitionCode(Info, AutoGenC, AutoGenH):\r
8bb63e37 1633 if Info.ModuleType in [SUP_MODULE_USER_DEFINED, SUP_MODULE_BASE]:\r
91fa33ee 1634 GuidType = TAB_GUID\r
f51461c8
LG
1635 else:\r
1636 GuidType = "EFI_GUID"\r
1637\r
1638 if Info.PpiList:\r
7beed8a3
YZ
1639 if not Info.IsLibrary:\r
1640 AutoGenC.Append("\n// PPIs\n")\r
8262037f 1641 AutoGenH.Append("\n// PPIs\n")\r
f51461c8
LG
1642 #\r
1643 # PPI GUIDs\r
1644 #\r
1645 for Key in Info.PpiList:\r
7beed8a3
YZ
1646 if not Info.IsLibrary:\r
1647 AutoGenC.Append('GLOBAL_REMOVE_IF_UNREFERENCED %s %s = %s;\n' % (GuidType, Key, Info.PpiList[Key]))\r
8262037f 1648 AutoGenH.Append('extern %s %s;\n' % (GuidType, Key))\r
f51461c8
LG
1649\r
1650## Create code for PCD\r
1651#\r
1652# @param Info The ModuleAutoGen object\r
1653# @param AutoGenC The TemplateString object for C code\r
1654# @param AutoGenH The TemplateString object for header file\r
1655#\r
1656def CreatePcdCode(Info, AutoGenC, AutoGenH):\r
1657\r
1658 # Collect Token Space GUIDs used by DynamicEc PCDs\r
1659 TokenSpaceList = []\r
1660 for Pcd in Info.ModulePcdList:\r
eece4292 1661 if Pcd.Type in PCD_DYNAMIC_EX_TYPE_SET and Pcd.TokenSpaceGuidCName not in TokenSpaceList:\r
caf74495 1662 TokenSpaceList.append(Pcd.TokenSpaceGuidCName)\r
f7496d71 1663\r
8518bf0b
LG
1664 SkuMgr = Info.Workspace.Platform.SkuIdMgr\r
1665 AutoGenH.Append("\n// Definition of SkuId Array\n")\r
1666 AutoGenH.Append("extern UINT64 _gPcd_SkuId_Array[];\n")\r
f51461c8 1667 # Add extern declarations to AutoGen.h if one or more Token Space GUIDs were found\r
72fbe88d 1668 if TokenSpaceList:\r
f51461c8 1669 AutoGenH.Append("\n// Definition of PCD Token Space GUIDs used in this module\n\n")\r
8bb63e37 1670 if Info.ModuleType in [SUP_MODULE_USER_DEFINED, SUP_MODULE_BASE]:\r
91fa33ee 1671 GuidType = TAB_GUID\r
f51461c8 1672 else:\r
f7496d71 1673 GuidType = "EFI_GUID"\r
f51461c8
LG
1674 for Item in TokenSpaceList:\r
1675 AutoGenH.Append('extern %s %s;\n' % (GuidType, Item))\r
1676\r
1677 if Info.IsLibrary:\r
1678 if Info.ModulePcdList:\r
1679 AutoGenH.Append("\n// PCD definitions\n")\r
1680 for Pcd in Info.ModulePcdList:\r
1681 CreateLibraryPcdCode(Info, AutoGenC, AutoGenH, Pcd)\r
1682 DynExPcdTokenNumberMapping (Info, AutoGenH)\r
1683 else:\r
8518bf0b
LG
1684 AutoGenC.Append("\n// Definition of SkuId Array\n")\r
1685 AutoGenC.Append("GLOBAL_REMOVE_IF_UNREFERENCED UINT64 _gPcd_SkuId_Array[] = %s;\n" % SkuMgr.DumpSkuIdArrary())\r
f51461c8
LG
1686 if Info.ModulePcdList:\r
1687 AutoGenH.Append("\n// Definition of PCDs used in this module\n")\r
1688 AutoGenC.Append("\n// Definition of PCDs used in this module\n")\r
1689 for Pcd in Info.ModulePcdList:\r
1690 CreateModulePcdCode(Info, AutoGenC, AutoGenH, Pcd)\r
1691 DynExPcdTokenNumberMapping (Info, AutoGenH)\r
1692 if Info.LibraryPcdList:\r
1693 AutoGenH.Append("\n// Definition of PCDs used in libraries is in AutoGen.c\n")\r
1694 AutoGenC.Append("\n// Definition of PCDs used in libraries\n")\r
1695 for Pcd in Info.LibraryPcdList:\r
1696 CreateModulePcdCode(Info, AutoGenC, AutoGenC, Pcd)\r
1697 CreatePcdDatabaseCode(Info, AutoGenC, AutoGenH)\r
1698\r
1699## Create code for unicode string definition\r
1700#\r
1701# @param Info The ModuleAutoGen object\r
1702# @param AutoGenC The TemplateString object for C code\r
1703# @param AutoGenH The TemplateString object for header file\r
1704# @param UniGenCFlag UniString is generated into AutoGen C file when it is set to True\r
1705# @param UniGenBinBuffer Buffer to store uni string package data\r
1706#\r
1707def CreateUnicodeStringCode(Info, AutoGenC, AutoGenH, UniGenCFlag, UniGenBinBuffer):\r
1708 WorkingDir = os.getcwd()\r
1709 os.chdir(Info.WorkspaceDir)\r
1710\r
1711 IncList = [Info.MetaFile.Dir]\r
1712 # Get all files under [Sources] section in inf file for EDK-II module\r
1713 EDK2Module = True\r
1714 SrcList = [F for F in Info.SourceFileList]\r
1715 if Info.AutoGenVersion < 0x00010005:\r
1716 EDK2Module = False\r
1717 # Get all files under the module directory for EDK-I module\r
1718 Cwd = os.getcwd()\r
1719 os.chdir(Info.MetaFile.Dir)\r
1720 for Root, Dirs, Files in os.walk("."):\r
1721 if 'CVS' in Dirs:\r
1722 Dirs.remove('CVS')\r
1723 if '.svn' in Dirs:\r
1724 Dirs.remove('.svn')\r
1725 for File in Files:\r
1726 File = PathClass(os.path.join(Root, File), Info.MetaFile.Dir)\r
1727 if File in SrcList:\r
1728 continue\r
1729 SrcList.append(File)\r
1730 os.chdir(Cwd)\r
1731\r
1732 if 'BUILD' in Info.BuildOption and Info.BuildOption['BUILD']['FLAGS'].find('-c') > -1:\r
1733 CompatibleMode = True\r
1734 else:\r
1735 CompatibleMode = False\r
1736\r
1737 #\r
1738 # -s is a temporary option dedicated for building .UNI files with ISO 639-2 language codes of EDK Shell in EDK2\r
1739 #\r
1740 if 'BUILD' in Info.BuildOption and Info.BuildOption['BUILD']['FLAGS'].find('-s') > -1:\r
1741 if CompatibleMode:\r
1742 EdkLogger.error("build", AUTOGEN_ERROR,\r
1743 "-c and -s build options should be used exclusively",\r
1744 ExtraData="[%s]" % str(Info))\r
1745 ShellMode = True\r
1746 else:\r
1747 ShellMode = False\r
1748\r
1749 #RFC4646 is only for EDKII modules and ISO639-2 for EDK modules\r
1750 if EDK2Module:\r
1751 FilterInfo = [EDK2Module] + [Info.PlatformInfo.Platform.RFCLanguages]\r
1752 else:\r
1753 FilterInfo = [EDK2Module] + [Info.PlatformInfo.Platform.ISOLanguages]\r
1754 Header, Code = GetStringFiles(Info.UnicodeFileList, SrcList, IncList, Info.IncludePathList, ['.uni', '.inf'], Info.Name, CompatibleMode, ShellMode, UniGenCFlag, UniGenBinBuffer, FilterInfo)\r
1755 if CompatibleMode or UniGenCFlag:\r
1756 AutoGenC.Append("\n//\n//Unicode String Pack Definition\n//\n")\r
1757 AutoGenC.Append(Code)\r
1758 AutoGenC.Append("\n")\r
1759 AutoGenH.Append("\n//\n//Unicode String ID\n//\n")\r
1760 AutoGenH.Append(Header)\r
1761 if CompatibleMode or UniGenCFlag:\r
1762 AutoGenH.Append("\n#define STRING_ARRAY_NAME %sStrings\n" % Info.Name)\r
1763 os.chdir(WorkingDir)\r
1764\r
333ba578
YZ
1765def CreateIdfFileCode(Info, AutoGenC, StringH, IdfGenCFlag, IdfGenBinBuffer):\r
1766 if len(Info.IdfFileList) > 0:\r
1767 ImageFiles = IdfFileClassObject(sorted (Info.IdfFileList))\r
1768 if ImageFiles.ImageFilesDict:\r
1769 Index = 1\r
1770 PaletteIndex = 1\r
1771 IncList = [Info.MetaFile.Dir]\r
1772 SrcList = [F for F in Info.SourceFileList]\r
1773 SkipList = ['.jpg', '.png', '.bmp', '.inf', '.idf']\r
1774 FileList = GetFileList(SrcList, IncList, SkipList)\r
1775 ValueStartPtr = 60\r
1776 StringH.Append("\n//\n//Image ID\n//\n")\r
1777 ImageInfoOffset = 0\r
1778 PaletteInfoOffset = 0\r
1779 ImageBuffer = pack('x')\r
1780 PaletteBuffer = pack('x')\r
1781 BufferStr = ''\r
1782 PaletteStr = ''\r
6d034a2a 1783 FileDict = {}\r
333ba578
YZ
1784 for Idf in ImageFiles.ImageFilesDict:\r
1785 if ImageFiles.ImageFilesDict[Idf]:\r
1786 for FileObj in ImageFiles.ImageFilesDict[Idf]:\r
1787 for sourcefile in Info.SourceFileList:\r
1788 if FileObj.FileName == sourcefile.File:\r
1789 if not sourcefile.Ext.upper() in ['.PNG', '.BMP', '.JPG']:\r
1790 EdkLogger.error("build", AUTOGEN_ERROR, "The %s's postfix must be one of .bmp, .jpg, .png" % (FileObj.FileName), ExtraData="[%s]" % str(Info))\r
1791 FileObj.File = sourcefile\r
1792 break\r
1793 else:\r
1794 EdkLogger.error("build", AUTOGEN_ERROR, "The %s in %s is not defined in the driver's [Sources] section" % (FileObj.FileName, Idf), ExtraData="[%s]" % str(Info))\r
1795\r
1796 for FileObj in ImageFiles.ImageFilesDict[Idf]:\r
1797 ID = FileObj.ImageID\r
1798 File = FileObj.File\r
1799 if not os.path.exists(File.Path) or not os.path.isfile(File.Path):\r
1800 EdkLogger.error("build", FILE_NOT_FOUND, ExtraData=File.Path)\r
1801 SearchImageID (FileObj, FileList)\r
1802 if FileObj.Referenced:\r
1803 if (ValueStartPtr - len(DEFINE_STR + ID)) <= 0:\r
1804 Line = DEFINE_STR + ' ' + ID + ' ' + DecToHexStr(Index, 4) + '\n'\r
1805 else:\r
1806 Line = DEFINE_STR + ' ' + ID + ' ' * (ValueStartPtr - len(DEFINE_STR + ID)) + DecToHexStr(Index, 4) + '\n'\r
1807\r
6d034a2a
YZ
1808 if File not in FileDict:\r
1809 FileDict[File] = Index\r
1810 else:\r
1811 DuplicateBlock = pack('B', EFI_HII_IIBT_DUPLICATE)\r
1812 DuplicateBlock += pack('H', FileDict[File])\r
1813 ImageBuffer += DuplicateBlock\r
1814 BufferStr = WriteLine(BufferStr, '// %s: %s: %s' % (DecToHexStr(Index, 4), ID, DecToHexStr(Index, 4)))\r
1815 TempBufferList = AscToHexList(DuplicateBlock)\r
1816 BufferStr = WriteLine(BufferStr, CreateArrayItem(TempBufferList, 16) + '\n')\r
1817 StringH.Append(Line)\r
1818 Index += 1\r
1819 continue\r
1820\r
333ba578
YZ
1821 TmpFile = open(File.Path, 'rb')\r
1822 Buffer = TmpFile.read()\r
1823 TmpFile.close()\r
1824 if File.Ext.upper() == '.PNG':\r
1825 TempBuffer = pack('B', EFI_HII_IIBT_IMAGE_PNG)\r
1826 TempBuffer += pack('I', len(Buffer))\r
1827 TempBuffer += Buffer\r
1828 elif File.Ext.upper() == '.JPG':\r
1829 ImageType, = struct.unpack('4s', Buffer[6:10])\r
1830 if ImageType != 'JFIF':\r
1831 EdkLogger.error("build", FILE_TYPE_MISMATCH, "The file %s is not a standard JPG file." % File.Path)\r
1832 TempBuffer = pack('B', EFI_HII_IIBT_IMAGE_JPEG)\r
1833 TempBuffer += pack('I', len(Buffer))\r
1834 TempBuffer += Buffer\r
1835 elif File.Ext.upper() == '.BMP':\r
1836 TempBuffer, TempPalette = BmpImageDecoder(File, Buffer, PaletteIndex, FileObj.TransParent)\r
1837 if len(TempPalette) > 1:\r
1838 PaletteIndex += 1\r
e148e6e9
YZ
1839 NewPalette = pack('H', len(TempPalette))\r
1840 NewPalette += TempPalette\r
1841 PaletteBuffer += NewPalette\r
333ba578 1842 PaletteStr = WriteLine(PaletteStr, '// %s: %s: %s' % (DecToHexStr(PaletteIndex - 1, 4), ID, DecToHexStr(PaletteIndex - 1, 4)))\r
e148e6e9 1843 TempPaletteList = AscToHexList(NewPalette)\r
333ba578
YZ
1844 PaletteStr = WriteLine(PaletteStr, CreateArrayItem(TempPaletteList, 16) + '\n')\r
1845 ImageBuffer += TempBuffer\r
1846 BufferStr = WriteLine(BufferStr, '// %s: %s: %s' % (DecToHexStr(Index, 4), ID, DecToHexStr(Index, 4)))\r
1847 TempBufferList = AscToHexList(TempBuffer)\r
1848 BufferStr = WriteLine(BufferStr, CreateArrayItem(TempBufferList, 16) + '\n')\r
1849\r
1850 StringH.Append(Line)\r
1851 Index += 1\r
1852\r
1853 BufferStr = WriteLine(BufferStr, '// End of the Image Info')\r
1854 BufferStr = WriteLine(BufferStr, CreateArrayItem(DecToHexList(EFI_HII_IIBT_END, 2)) + '\n')\r
1855 ImageEnd = pack('B', EFI_HII_IIBT_END)\r
1856 ImageBuffer += ImageEnd\r
1857\r
1858 if len(ImageBuffer) > 1:\r
1859 ImageInfoOffset = 12\r
1860 if len(PaletteBuffer) > 1:\r
1861 PaletteInfoOffset = 12 + len(ImageBuffer) - 1 # -1 is for the first empty pad byte of ImageBuffer\r
1862\r
1863 IMAGE_PACKAGE_HDR = pack('=II', ImageInfoOffset, PaletteInfoOffset)\r
1864 # PACKAGE_HEADER_Length = PACKAGE_HEADER + ImageInfoOffset + PaletteInfoOffset + ImageBuffer Length + PaletteCount + PaletteBuffer Length\r
1865 if len(PaletteBuffer) > 1:\r
1866 PACKAGE_HEADER_Length = 4 + 4 + 4 + len(ImageBuffer) - 1 + 2 + len(PaletteBuffer) - 1\r
1867 else:\r
1868 PACKAGE_HEADER_Length = 4 + 4 + 4 + len(ImageBuffer) - 1\r
1869 if PaletteIndex > 1:\r
1870 PALETTE_INFO_HEADER = pack('H', PaletteIndex - 1)\r
1871 # EFI_HII_PACKAGE_HEADER length max value is 0xFFFFFF\r
1872 Hex_Length = '%06X' % PACKAGE_HEADER_Length\r
1873 if PACKAGE_HEADER_Length > 0xFFFFFF:\r
1874 EdkLogger.error("build", AUTOGEN_ERROR, "The Length of EFI_HII_PACKAGE_HEADER exceed its maximum value", ExtraData="[%s]" % str(Info))\r
1875 PACKAGE_HEADER = pack('=HBB', int('0x' + Hex_Length[2:], 16), int('0x' + Hex_Length[0:2], 16), EFI_HII_PACKAGE_IMAGES)\r
1876\r
1877 IdfGenBinBuffer.write(PACKAGE_HEADER)\r
1878 IdfGenBinBuffer.write(IMAGE_PACKAGE_HDR)\r
1879 if len(ImageBuffer) > 1 :\r
1880 IdfGenBinBuffer.write(ImageBuffer[1:])\r
1881 if PaletteIndex > 1:\r
1882 IdfGenBinBuffer.write(PALETTE_INFO_HEADER)\r
1883 if len(PaletteBuffer) > 1:\r
1884 IdfGenBinBuffer.write(PaletteBuffer[1:])\r
1885\r
1886 if IdfGenCFlag:\r
1887 TotalLength = EFI_HII_ARRAY_SIZE_LENGTH + PACKAGE_HEADER_Length\r
1888 AutoGenC.Append("\n//\n//Image Pack Definition\n//\n")\r
1889 AllStr = WriteLine('', CHAR_ARRAY_DEFIN + ' ' + Info.Module.BaseName + 'Images' + '[] = {\n')\r
1890 AllStr = WriteLine(AllStr, '// STRGATHER_OUTPUT_HEADER')\r
1891 AllStr = WriteLine(AllStr, CreateArrayItem(DecToHexList(TotalLength)) + '\n')\r
1892 AllStr = WriteLine(AllStr, '// Image PACKAGE HEADER\n')\r
1893 IMAGE_PACKAGE_HDR_List = AscToHexList(PACKAGE_HEADER)\r
1894 IMAGE_PACKAGE_HDR_List += AscToHexList(IMAGE_PACKAGE_HDR)\r
1895 AllStr = WriteLine(AllStr, CreateArrayItem(IMAGE_PACKAGE_HDR_List, 16) + '\n')\r
1896 AllStr = WriteLine(AllStr, '// Image DATA\n')\r
1897 if BufferStr:\r
1898 AllStr = WriteLine(AllStr, BufferStr)\r
1899 if PaletteStr:\r
1900 AllStr = WriteLine(AllStr, '// Palette Header\n')\r
1901 PALETTE_INFO_HEADER_List = AscToHexList(PALETTE_INFO_HEADER)\r
1902 AllStr = WriteLine(AllStr, CreateArrayItem(PALETTE_INFO_HEADER_List, 16) + '\n')\r
1903 AllStr = WriteLine(AllStr, '// Palette Data\n')\r
1904 AllStr = WriteLine(AllStr, PaletteStr)\r
1905 AllStr = WriteLine(AllStr, '};')\r
1906 AutoGenC.Append(AllStr)\r
1907 AutoGenC.Append("\n")\r
1908 StringH.Append('\nextern unsigned char ' + Info.Module.BaseName + 'Images[];\n')\r
1909 StringH.Append("\n#define IMAGE_ARRAY_NAME %sImages\n" % Info.Module.BaseName)\r
1910\r
1911# typedef struct _EFI_HII_IMAGE_PACKAGE_HDR {\r
1912# EFI_HII_PACKAGE_HEADER Header; # Standard package header, where Header.Type = EFI_HII_PACKAGE_IMAGES\r
1913# UINT32 ImageInfoOffset;\r
1914# UINT32 PaletteInfoOffset;\r
1915# } EFI_HII_IMAGE_PACKAGE_HDR;\r
1916\r
1917# typedef struct {\r
1918# UINT32 Length:24;\r
1919# UINT32 Type:8;\r
1920# UINT8 Data[];\r
1921# } EFI_HII_PACKAGE_HEADER;\r
1922\r
1923# typedef struct _EFI_HII_IMAGE_BLOCK {\r
1924# UINT8 BlockType;\r
1925# UINT8 BlockBody[];\r
1926# } EFI_HII_IMAGE_BLOCK;\r
1927\r
1928def BmpImageDecoder(File, Buffer, PaletteIndex, TransParent):\r
1929 ImageType, = struct.unpack('2s', Buffer[0:2])\r
1930 if ImageType!= 'BM': # BMP file type is 'BM'\r
1931 EdkLogger.error("build", FILE_TYPE_MISMATCH, "The file %s is not a standard BMP file." % File.Path)\r
ccaa7754 1932 BMP_IMAGE_HEADER = collections.namedtuple('BMP_IMAGE_HEADER', ['bfSize', 'bfReserved1', 'bfReserved2', 'bfOffBits', 'biSize', 'biWidth', 'biHeight', 'biPlanes', 'biBitCount', 'biCompression', 'biSizeImage', 'biXPelsPerMeter', 'biYPelsPerMeter', 'biClrUsed', 'biClrImportant'])\r
333ba578
YZ
1933 BMP_IMAGE_HEADER_STRUCT = struct.Struct('IHHIIIIHHIIIIII')\r
1934 BmpHeader = BMP_IMAGE_HEADER._make(BMP_IMAGE_HEADER_STRUCT.unpack_from(Buffer[2:]))\r
1935 #\r
1936 # Doesn't support compress.\r
1937 #\r
1938 if BmpHeader.biCompression != 0:\r
1939 EdkLogger.error("build", FORMAT_NOT_SUPPORTED, "The compress BMP file %s is not support." % File.Path)\r
1940\r
1941 # The Width and Height is UINT16 type in Image Package\r
1942 if BmpHeader.biWidth > 0xFFFF:\r
1943 EdkLogger.error("build", FORMAT_NOT_SUPPORTED, "The BMP file %s Width is exceed 0xFFFF." % File.Path)\r
1944 if BmpHeader.biHeight > 0xFFFF:\r
1945 EdkLogger.error("build", FORMAT_NOT_SUPPORTED, "The BMP file %s Height is exceed 0xFFFF." % File.Path)\r
1946\r
1947 PaletteBuffer = pack('x')\r
1948 if BmpHeader.biBitCount == 1:\r
1949 if TransParent:\r
1950 ImageBuffer = pack('B', EFI_HII_IIBT_IMAGE_1BIT_TRANS)\r
1951 else:\r
1952 ImageBuffer = pack('B', EFI_HII_IIBT_IMAGE_1BIT)\r
1953 ImageBuffer += pack('B', PaletteIndex)\r
1954 Width = (BmpHeader.biWidth + 7)/8\r
1955 if BmpHeader.bfOffBits > BMP_IMAGE_HEADER_STRUCT.size + 2:\r
1956 PaletteBuffer = Buffer[BMP_IMAGE_HEADER_STRUCT.size + 2 : BmpHeader.bfOffBits]\r
1957 elif BmpHeader.biBitCount == 4:\r
1958 if TransParent:\r
1959 ImageBuffer = pack('B', EFI_HII_IIBT_IMAGE_4BIT_TRANS)\r
1960 else:\r
1961 ImageBuffer = pack('B', EFI_HII_IIBT_IMAGE_4BIT)\r
1962 ImageBuffer += pack('B', PaletteIndex)\r
1963 Width = (BmpHeader.biWidth + 1)/2\r
1964 if BmpHeader.bfOffBits > BMP_IMAGE_HEADER_STRUCT.size + 2:\r
1965 PaletteBuffer = Buffer[BMP_IMAGE_HEADER_STRUCT.size + 2 : BmpHeader.bfOffBits]\r
1966 elif BmpHeader.biBitCount == 8:\r
1967 if TransParent:\r
1968 ImageBuffer = pack('B', EFI_HII_IIBT_IMAGE_8BIT_TRANS)\r
1969 else:\r
1970 ImageBuffer = pack('B', EFI_HII_IIBT_IMAGE_8BIT)\r
1971 ImageBuffer += pack('B', PaletteIndex)\r
1972 Width = BmpHeader.biWidth\r
1973 if BmpHeader.bfOffBits > BMP_IMAGE_HEADER_STRUCT.size + 2:\r
1974 PaletteBuffer = Buffer[BMP_IMAGE_HEADER_STRUCT.size + 2 : BmpHeader.bfOffBits]\r
1975 elif BmpHeader.biBitCount == 24:\r
1976 if TransParent:\r
1977 ImageBuffer = pack('B', EFI_HII_IIBT_IMAGE_24BIT_TRANS)\r
1978 else:\r
1979 ImageBuffer = pack('B', EFI_HII_IIBT_IMAGE_24BIT)\r
1980 Width = BmpHeader.biWidth * 3\r
1981 else:\r
1982 EdkLogger.error("build", FORMAT_NOT_SUPPORTED, "Only support the 1 bit, 4 bit, 8bit, 24 bit BMP files.", ExtraData="[%s]" % str(File.Path))\r
1983\r
1984 ImageBuffer += pack('H', BmpHeader.biWidth)\r
1985 ImageBuffer += pack('H', BmpHeader.biHeight)\r
1986 Start = BmpHeader.bfOffBits\r
1987 End = BmpHeader.bfSize - 1\r
1988 for Height in range(0, BmpHeader.biHeight):\r
1989 if Width % 4 != 0:\r
1990 Start = End + (Width % 4) - 4 - Width\r
1991 else:\r
1992 Start = End - Width\r
1993 ImageBuffer += Buffer[Start + 1 : Start + Width + 1]\r
1994 End = Start\r
1995\r
1996 # handle the Palette info, BMP use 4 bytes for R, G, B and Reserved info while EFI_HII_RGB_PIXEL only have the R, G, B info\r
1997 if PaletteBuffer and len(PaletteBuffer) > 1:\r
1998 PaletteTemp = pack('x')\r
1999 for Index in range(0, len(PaletteBuffer)):\r
2000 if Index % 4 == 3:\r
2001 continue\r
2002 PaletteTemp += PaletteBuffer[Index]\r
2003 PaletteBuffer = PaletteTemp[1:]\r
2004 return ImageBuffer, PaletteBuffer\r
2005\r
f51461c8
LG
2006## Create common code\r
2007#\r
2008# @param Info The ModuleAutoGen object\r
2009# @param AutoGenC The TemplateString object for C code\r
2010# @param AutoGenH The TemplateString object for header file\r
2011#\r
2012def CreateHeaderCode(Info, AutoGenC, AutoGenH):\r
2013 # file header\r
2014 AutoGenH.Append(gAutoGenHeaderString.Replace({'FileName':'AutoGen.h'}))\r
2015 # header file Prologue\r
ccaa7754 2016 AutoGenH.Append(gAutoGenHPrologueString.Replace({'File':'AUTOGENH','Guid':Info.Guid.replace('-', '_')}))\r
f51461c8
LG
2017 AutoGenH.Append(gAutoGenHCppPrologueString)\r
2018 if Info.AutoGenVersion >= 0x00010005:\r
2019 # header files includes\r
b1aff264 2020 if Info.ModuleType in gModuleTypeHeaderFile:\r
f51461c8
LG
2021 AutoGenH.Append("#include <%s>\n" % gModuleTypeHeaderFile[Info.ModuleType][0])\r
2022 #\r
f7496d71 2023 # if either PcdLib in [LibraryClasses] sections or there exist Pcd section, add PcdLib.h\r
f51461c8
LG
2024 # As if modules only uses FixedPcd, then PcdLib is not needed in [LibraryClasses] section.\r
2025 #\r
2026 if 'PcdLib' in Info.Module.LibraryClasses or Info.Module.Pcds:\r
2027 AutoGenH.Append("#include <Library/PcdLib.h>\n")\r
2028\r
2029 AutoGenH.Append('\nextern GUID gEfiCallerIdGuid;')\r
2030 AutoGenH.Append('\nextern CHAR8 *gEfiCallerBaseName;\n\n')\r
2031\r
2032 if Info.IsLibrary:\r
2033 return\r
2034\r
2035 AutoGenH.Append("#define EFI_CALLER_ID_GUID \\\n %s\n" % GuidStringToGuidStructureString(Info.Guid))\r
2036\r
2037 if Info.IsLibrary:\r
2038 return\r
2039 # C file header\r
2040 AutoGenC.Append(gAutoGenHeaderString.Replace({'FileName':'AutoGen.c'}))\r
2041 if Info.AutoGenVersion >= 0x00010005:\r
2042 # C file header files includes\r
2043 if Info.ModuleType in gModuleTypeHeaderFile:\r
2044 for Inc in gModuleTypeHeaderFile[Info.ModuleType]:\r
2045 AutoGenC.Append("#include <%s>\n" % Inc)\r
2046 else:\r
2047 AutoGenC.Append("#include <%s>\n" % gBasicHeaderFile)\r
2048\r
2049 #\r
2050 # Publish the CallerId Guid\r
2051 #\r
2052 AutoGenC.Append('\nGLOBAL_REMOVE_IF_UNREFERENCED GUID gEfiCallerIdGuid = %s;\n' % GuidStringToGuidStructureString(Info.Guid))\r
2053 AutoGenC.Append('\nGLOBAL_REMOVE_IF_UNREFERENCED CHAR8 *gEfiCallerBaseName = "%s";\n' % Info.Name)\r
2054\r
2055## Create common code for header file\r
2056#\r
2057# @param Info The ModuleAutoGen object\r
2058# @param AutoGenC The TemplateString object for C code\r
2059# @param AutoGenH The TemplateString object for header file\r
2060#\r
2061def CreateFooterCode(Info, AutoGenC, AutoGenH):\r
2062 AutoGenH.Append(gAutoGenHEpilogueString)\r
2063\r
2064## Create code for a module\r
2065#\r
2066# @param Info The ModuleAutoGen object\r
2067# @param AutoGenC The TemplateString object for C code\r
2068# @param AutoGenH The TemplateString object for header file\r
333ba578 2069# @param StringH The TemplateString object for header file\r
f51461c8
LG
2070# @param UniGenCFlag UniString is generated into AutoGen C file when it is set to True\r
2071# @param UniGenBinBuffer Buffer to store uni string package data\r
333ba578
YZ
2072# @param StringIdf The TemplateString object for header file\r
2073# @param IdfGenCFlag IdfString is generated into AutoGen C file when it is set to True\r
2074# @param IdfGenBinBuffer Buffer to store Idf string package data\r
f51461c8 2075#\r
333ba578 2076def CreateCode(Info, AutoGenC, AutoGenH, StringH, UniGenCFlag, UniGenBinBuffer, StringIdf, IdfGenCFlag, IdfGenBinBuffer):\r
f51461c8
LG
2077 CreateHeaderCode(Info, AutoGenC, AutoGenH)\r
2078\r
2079 if Info.AutoGenVersion >= 0x00010005:\r
2080 CreateGuidDefinitionCode(Info, AutoGenC, AutoGenH)\r
2081 CreateProtocolDefinitionCode(Info, AutoGenC, AutoGenH)\r
2082 CreatePpiDefinitionCode(Info, AutoGenC, AutoGenH)\r
2083 CreatePcdCode(Info, AutoGenC, AutoGenH)\r
2084 CreateLibraryConstructorCode(Info, AutoGenC, AutoGenH)\r
2085 CreateLibraryDestructorCode(Info, AutoGenC, AutoGenH)\r
2086 CreateModuleEntryPointCode(Info, AutoGenC, AutoGenH)\r
2087 CreateModuleUnloadImageCode(Info, AutoGenC, AutoGenH)\r
2088\r
2089 if Info.UnicodeFileList:\r
2090 FileName = "%sStrDefs.h" % Info.Name\r
2091 StringH.Append(gAutoGenHeaderString.Replace({'FileName':FileName}))\r
ccaa7754 2092 StringH.Append(gAutoGenHPrologueString.Replace({'File':'STRDEFS', 'Guid':Info.Guid.replace('-', '_')}))\r
f51461c8 2093 CreateUnicodeStringCode(Info, AutoGenC, StringH, UniGenCFlag, UniGenBinBuffer)\r
8200fcfe
YL
2094\r
2095 GuidMacros = []\r
2096 for Guid in Info.Module.Guids:\r
2097 if Guid in Info.Module.GetGuidsUsedByPcd():\r
2098 continue\r
2099 GuidMacros.append('#define %s %s' % (Guid, Info.Module.Guids[Guid]))\r
2100 for Guid, Value in Info.Module.Protocols.items() + Info.Module.Ppis.items():\r
2101 GuidMacros.append('#define %s %s' % (Guid, Value))\r
58cf30f7 2102 # supports FixedAtBuild and FeaturePcd usage in VFR file\r
5b97eb4c
YZ
2103 if Info.VfrFileList and Info.ModulePcdList:\r
2104 GuidMacros.append('#define %s %s' % ('FixedPcdGetBool(TokenName)', '_PCD_VALUE_##TokenName'))\r
2105 GuidMacros.append('#define %s %s' % ('FixedPcdGet8(TokenName)', '_PCD_VALUE_##TokenName'))\r
2106 GuidMacros.append('#define %s %s' % ('FixedPcdGet16(TokenName)', '_PCD_VALUE_##TokenName'))\r
2107 GuidMacros.append('#define %s %s' % ('FixedPcdGet32(TokenName)', '_PCD_VALUE_##TokenName'))\r
2108 GuidMacros.append('#define %s %s' % ('FixedPcdGet64(TokenName)', '_PCD_VALUE_##TokenName'))\r
58cf30f7 2109 GuidMacros.append('#define %s %s' % ('FeaturePcdGet(TokenName)', '_PCD_VALUE_##TokenName'))\r
5b97eb4c 2110 for Pcd in Info.ModulePcdList:\r
58cf30f7 2111 if Pcd.Type in [TAB_PCDS_FIXED_AT_BUILD, TAB_PCDS_FEATURE_FLAG]:\r
5b97eb4c
YZ
2112 TokenCName = Pcd.TokenCName\r
2113 Value = Pcd.DefaultValue\r
2114 if Pcd.DatumType == 'BOOLEAN':\r
2115 BoolValue = Value.upper()\r
2116 if BoolValue == 'TRUE':\r
2117 Value = '1'\r
2118 elif BoolValue == 'FALSE':\r
2119 Value = '0'\r
2120 for PcdItem in GlobalData.MixedPcd:\r
2121 if (Pcd.TokenCName, Pcd.TokenSpaceGuidCName) in GlobalData.MixedPcd[PcdItem]:\r
2122 TokenCName = PcdItem[0]\r
2123 break\r
2124 GuidMacros.append('#define %s %s' % ('_PCD_VALUE_'+TokenCName, Value))\r
2125\r
bc7d95c0
YZ
2126 if Info.IdfFileList:\r
2127 GuidMacros.append('#include "%sImgDefs.h"' % Info.Name)\r
2128\r
8200fcfe
YL
2129 if GuidMacros:\r
2130 StringH.Append('\n#ifdef VFRCOMPILE\n%s\n#endif\n' % '\n'.join(GuidMacros))\r
2131\r
f51461c8
LG
2132 StringH.Append("\n#endif\n")\r
2133 AutoGenH.Append('#include "%s"\n' % FileName)\r
2134\r
333ba578
YZ
2135 if Info.IdfFileList:\r
2136 FileName = "%sImgDefs.h" % Info.Name\r
2137 StringIdf.Append(gAutoGenHeaderString.Replace({'FileName':FileName}))\r
ccaa7754 2138 StringIdf.Append(gAutoGenHPrologueString.Replace({'File':'IMAGEDEFS', 'Guid':Info.Guid.replace('-', '_')}))\r
333ba578
YZ
2139 CreateIdfFileCode(Info, AutoGenC, StringIdf, IdfGenCFlag, IdfGenBinBuffer)\r
2140\r
2141 StringIdf.Append("\n#endif\n")\r
2142 AutoGenH.Append('#include "%s"\n' % FileName)\r
2143\r
f51461c8
LG
2144 CreateFooterCode(Info, AutoGenC, AutoGenH)\r
2145\r
2146 # no generation of AutoGen.c for Edk modules without unicode file\r
2147 if Info.AutoGenVersion < 0x00010005 and len(Info.UnicodeFileList) == 0:\r
2148 AutoGenC.String = ''\r
2149\r
2150## Create the code file\r
2151#\r
2152# @param FilePath The path of code file\r
2153# @param Content The content of code file\r
2154# @param IsBinaryFile The flag indicating if the file is binary file or not\r
2155#\r
2156# @retval True If file content is changed or file doesn't exist\r
2157# @retval False If the file exists and the content is not changed\r
2158#\r
2159def Generate(FilePath, Content, IsBinaryFile):\r
2160 return SaveFileOnChange(FilePath, Content, IsBinaryFile)\r
2161\r