OvmfPkg: AcpiPlatformDxe: Don't enable unsupported PCI attributes
[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
d66670f9 4# Copyright (c) 2007 - 2016, 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
17\r
18from Common import EdkLogger\r
19\r
20from Common.BuildToolError import *\r
21from Common.DataType import *\r
22from Common.Misc import *\r
23from Common.String import StringToArray\r
24from StrGather import *\r
25from GenPcdDb import CreatePcdDatabaseCode\r
26\r
27## PCD type string\r
28gItemTypeStringDatabase = {\r
29 TAB_PCDS_FEATURE_FLAG : 'FixedAtBuild',\r
30 TAB_PCDS_FIXED_AT_BUILD : 'FixedAtBuild',\r
31 TAB_PCDS_PATCHABLE_IN_MODULE: 'BinaryPatch',\r
32 TAB_PCDS_DYNAMIC : '',\r
33 TAB_PCDS_DYNAMIC_DEFAULT : '',\r
34 TAB_PCDS_DYNAMIC_VPD : '',\r
35 TAB_PCDS_DYNAMIC_HII : '',\r
36 TAB_PCDS_DYNAMIC_EX : '',\r
37 TAB_PCDS_DYNAMIC_EX_DEFAULT : '',\r
38 TAB_PCDS_DYNAMIC_EX_VPD : '',\r
39 TAB_PCDS_DYNAMIC_EX_HII : '',\r
40}\r
41\r
42## Dynamic PCD types\r
43gDynamicPcd = [TAB_PCDS_DYNAMIC, TAB_PCDS_DYNAMIC_DEFAULT, TAB_PCDS_DYNAMIC_VPD, TAB_PCDS_DYNAMIC_HII]\r
44\r
45## Dynamic-ex PCD types\r
46gDynamicExPcd = [TAB_PCDS_DYNAMIC_EX, TAB_PCDS_DYNAMIC_EX_DEFAULT, TAB_PCDS_DYNAMIC_EX_VPD, TAB_PCDS_DYNAMIC_EX_HII]\r
47\r
48## Datum size\r
49gDatumSizeStringDatabase = {'UINT8':'8','UINT16':'16','UINT32':'32','UINT64':'64','BOOLEAN':'BOOLEAN','VOID*':'8'}\r
50gDatumSizeStringDatabaseH = {'UINT8':'8','UINT16':'16','UINT32':'32','UINT64':'64','BOOLEAN':'BOOL','VOID*':'PTR'}\r
51gDatumSizeStringDatabaseLib = {'UINT8':'8','UINT16':'16','UINT32':'32','UINT64':'64','BOOLEAN':'Bool','VOID*':'Ptr'}\r
52\r
53## AutoGen File Header Templates\r
54gAutoGenHeaderString = TemplateString("""\\r
55/**\r
56 DO NOT EDIT\r
57 FILE auto-generated\r
58 Module name:\r
59 ${FileName}\r
60 Abstract: Auto-generated ${FileName} for building module or library.\r
61**/\r
62""")\r
63\r
64gAutoGenHPrologueString = TemplateString("""\r
65#ifndef _${File}_${Guid}\r
66#define _${File}_${Guid}\r
67\r
68""")\r
69\r
70gAutoGenHCppPrologueString = """\\r
71#ifdef __cplusplus\r
72extern "C" {\r
73#endif\r
74\r
75"""\r
76\r
77gAutoGenHEpilogueString = """\r
78\r
79#ifdef __cplusplus\r
80}\r
81#endif\r
82\r
83#endif\r
84"""\r
85\r
86## PEI Core Entry Point Templates\r
87gPeiCoreEntryPointPrototype = TemplateString("""\r
88${BEGIN}\r
89VOID\r
90EFIAPI\r
91${Function} (\r
92 IN CONST EFI_SEC_PEI_HAND_OFF *SecCoreData,\r
93 IN CONST EFI_PEI_PPI_DESCRIPTOR *PpiList,\r
94 IN VOID *Context\r
95 );\r
96${END}\r
97""")\r
98\r
99gPeiCoreEntryPointString = TemplateString("""\r
100${BEGIN}\r
101VOID\r
102EFIAPI\r
103ProcessModuleEntryPointList (\r
104 IN CONST EFI_SEC_PEI_HAND_OFF *SecCoreData,\r
105 IN CONST EFI_PEI_PPI_DESCRIPTOR *PpiList,\r
106 IN VOID *Context\r
107 )\r
108\r
109{\r
110 ${Function} (SecCoreData, PpiList, Context);\r
111}\r
112${END}\r
113""")\r
114\r
115\r
116## DXE Core Entry Point Templates\r
117gDxeCoreEntryPointPrototype = TemplateString("""\r
118${BEGIN}\r
119VOID\r
120EFIAPI\r
121${Function} (\r
122 IN VOID *HobStart\r
123 );\r
124${END}\r
125""")\r
126\r
127gDxeCoreEntryPointString = TemplateString("""\r
128${BEGIN}\r
129VOID\r
130EFIAPI\r
131ProcessModuleEntryPointList (\r
132 IN VOID *HobStart\r
133 )\r
134\r
135{\r
136 ${Function} (HobStart);\r
137}\r
138${END}\r
139""")\r
140\r
141## PEIM Entry Point Templates\r
142gPeimEntryPointPrototype = TemplateString("""\r
143${BEGIN}\r
144EFI_STATUS\r
145EFIAPI\r
146${Function} (\r
147 IN EFI_PEI_FILE_HANDLE FileHandle,\r
148 IN CONST EFI_PEI_SERVICES **PeiServices\r
149 );\r
150${END}\r
151""")\r
152\r
153gPeimEntryPointString = [\r
154TemplateString("""\r
155GLOBAL_REMOVE_IF_UNREFERENCED const UINT32 _gPeimRevision = ${PiSpecVersion};\r
156\r
157EFI_STATUS\r
158EFIAPI\r
159ProcessModuleEntryPointList (\r
160 IN EFI_PEI_FILE_HANDLE FileHandle,\r
161 IN CONST EFI_PEI_SERVICES **PeiServices\r
162 )\r
163\r
164{\r
165 return EFI_SUCCESS;\r
166}\r
167"""),\r
168TemplateString("""\r
169GLOBAL_REMOVE_IF_UNREFERENCED const UINT32 _gPeimRevision = ${PiSpecVersion};\r
170${BEGIN}\r
171EFI_STATUS\r
172EFIAPI\r
173ProcessModuleEntryPointList (\r
174 IN EFI_PEI_FILE_HANDLE FileHandle,\r
175 IN CONST EFI_PEI_SERVICES **PeiServices\r
176 )\r
177\r
178{\r
179 return ${Function} (FileHandle, PeiServices);\r
180}\r
181${END}\r
182"""),\r
183TemplateString("""\r
184GLOBAL_REMOVE_IF_UNREFERENCED const UINT32 _gPeimRevision = ${PiSpecVersion};\r
185\r
186EFI_STATUS\r
187EFIAPI\r
188ProcessModuleEntryPointList (\r
189 IN EFI_PEI_FILE_HANDLE FileHandle,\r
190 IN CONST EFI_PEI_SERVICES **PeiServices\r
191 )\r
192\r
193{\r
194 EFI_STATUS Status;\r
195 EFI_STATUS CombinedStatus;\r
196\r
197 CombinedStatus = EFI_LOAD_ERROR;\r
198${BEGIN}\r
199 Status = ${Function} (FileHandle, PeiServices);\r
200 if (!EFI_ERROR (Status) || EFI_ERROR (CombinedStatus)) {\r
201 CombinedStatus = Status;\r
202 }\r
203${END}\r
204 return CombinedStatus;\r
205}\r
206""")\r
207]\r
208\r
209## SMM_CORE Entry Point Templates\r
210gSmmCoreEntryPointPrototype = TemplateString("""\r
211${BEGIN}\r
212EFI_STATUS\r
213EFIAPI\r
214${Function} (\r
215 IN EFI_HANDLE ImageHandle,\r
216 IN EFI_SYSTEM_TABLE *SystemTable\r
217 );\r
218${END}\r
219""")\r
220\r
221gSmmCoreEntryPointString = TemplateString("""\r
222${BEGIN}\r
223const UINT32 _gUefiDriverRevision = ${UefiSpecVersion};\r
224const UINT32 _gDxeRevision = ${PiSpecVersion};\r
225\r
226EFI_STATUS\r
227EFIAPI\r
228ProcessModuleEntryPointList (\r
229 IN EFI_HANDLE ImageHandle,\r
230 IN EFI_SYSTEM_TABLE *SystemTable\r
231 )\r
232{\r
233 return ${Function} (ImageHandle, SystemTable);\r
234}\r
235${END}\r
236""")\r
237\r
238## DXE SMM Entry Point Templates\r
239gDxeSmmEntryPointPrototype = TemplateString("""\r
240${BEGIN}\r
241EFI_STATUS\r
242EFIAPI\r
243${Function} (\r
244 IN EFI_HANDLE ImageHandle,\r
245 IN EFI_SYSTEM_TABLE *SystemTable\r
246 );\r
247${END}\r
248""")\r
249\r
250gDxeSmmEntryPointString = [\r
251TemplateString("""\r
252const UINT32 _gUefiDriverRevision = ${UefiSpecVersion};\r
253const UINT32 _gDxeRevision = ${PiSpecVersion};\r
254\r
255EFI_STATUS\r
256EFIAPI\r
257ProcessModuleEntryPointList (\r
258 IN EFI_HANDLE ImageHandle,\r
259 IN EFI_SYSTEM_TABLE *SystemTable\r
260 )\r
261\r
262{\r
263 return EFI_SUCCESS;\r
264}\r
265"""),\r
266TemplateString("""\r
267const UINT32 _gUefiDriverRevision = ${UefiSpecVersion};\r
268const UINT32 _gDxeRevision = ${PiSpecVersion};\r
269\r
270static BASE_LIBRARY_JUMP_BUFFER mJumpContext;\r
271static EFI_STATUS mDriverEntryPointStatus;\r
272\r
273VOID\r
274EFIAPI\r
275ExitDriver (\r
276 IN EFI_STATUS Status\r
277 )\r
278{\r
279 if (!EFI_ERROR (Status) || EFI_ERROR (mDriverEntryPointStatus)) {\r
280 mDriverEntryPointStatus = Status;\r
281 }\r
282 LongJump (&mJumpContext, (UINTN)-1);\r
283 ASSERT (FALSE);\r
284}\r
285\r
286EFI_STATUS\r
287EFIAPI\r
288ProcessModuleEntryPointList (\r
289 IN EFI_HANDLE ImageHandle,\r
290 IN EFI_SYSTEM_TABLE *SystemTable\r
291 )\r
292{\r
293 mDriverEntryPointStatus = EFI_LOAD_ERROR;\r
294\r
295${BEGIN}\r
296 if (SetJump (&mJumpContext) == 0) {\r
297 ExitDriver (${Function} (ImageHandle, SystemTable));\r
298 ASSERT (FALSE);\r
299 }\r
300${END}\r
301\r
302 return mDriverEntryPointStatus;\r
303}\r
304""")\r
305]\r
306\r
307## UEFI Driver Entry Point Templates\r
308gUefiDriverEntryPointPrototype = TemplateString("""\r
309${BEGIN}\r
310EFI_STATUS\r
311EFIAPI\r
312${Function} (\r
313 IN EFI_HANDLE ImageHandle,\r
314 IN EFI_SYSTEM_TABLE *SystemTable\r
315 );\r
316${END}\r
317""")\r
318\r
319gUefiDriverEntryPointString = [\r
320TemplateString("""\r
321const UINT32 _gUefiDriverRevision = ${UefiSpecVersion};\r
322const UINT32 _gDxeRevision = ${PiSpecVersion};\r
323\r
324EFI_STATUS\r
325EFIAPI\r
326ProcessModuleEntryPointList (\r
327 IN EFI_HANDLE ImageHandle,\r
328 IN EFI_SYSTEM_TABLE *SystemTable\r
329 )\r
330{\r
331 return EFI_SUCCESS;\r
332}\r
333"""),\r
334TemplateString("""\r
335const UINT32 _gUefiDriverRevision = ${UefiSpecVersion};\r
336const UINT32 _gDxeRevision = ${PiSpecVersion};\r
337\r
338${BEGIN}\r
339EFI_STATUS\r
340EFIAPI\r
341ProcessModuleEntryPointList (\r
342 IN EFI_HANDLE ImageHandle,\r
343 IN EFI_SYSTEM_TABLE *SystemTable\r
344 )\r
345\r
346{\r
347 return ${Function} (ImageHandle, SystemTable);\r
348}\r
349${END}\r
350VOID\r
351EFIAPI\r
352ExitDriver (\r
353 IN EFI_STATUS Status\r
354 )\r
355{\r
356 if (EFI_ERROR (Status)) {\r
357 ProcessLibraryDestructorList (gImageHandle, gST);\r
358 }\r
359 gBS->Exit (gImageHandle, Status, 0, NULL);\r
360}\r
361"""),\r
362TemplateString("""\r
363const UINT32 _gUefiDriverRevision = ${UefiSpecVersion};\r
364const UINT32 _gDxeRevision = ${PiSpecVersion};\r
365\r
366static BASE_LIBRARY_JUMP_BUFFER mJumpContext;\r
367static EFI_STATUS mDriverEntryPointStatus;\r
368\r
369EFI_STATUS\r
370EFIAPI\r
371ProcessModuleEntryPointList (\r
372 IN EFI_HANDLE ImageHandle,\r
373 IN EFI_SYSTEM_TABLE *SystemTable\r
374 )\r
375{\r
376 mDriverEntryPointStatus = EFI_LOAD_ERROR;\r
377 ${BEGIN}\r
378 if (SetJump (&mJumpContext) == 0) {\r
379 ExitDriver (${Function} (ImageHandle, SystemTable));\r
380 ASSERT (FALSE);\r
381 }\r
382 ${END}\r
383 return mDriverEntryPointStatus;\r
384}\r
385\r
386VOID\r
387EFIAPI\r
388ExitDriver (\r
389 IN EFI_STATUS Status\r
390 )\r
391{\r
392 if (!EFI_ERROR (Status) || EFI_ERROR (mDriverEntryPointStatus)) {\r
393 mDriverEntryPointStatus = Status;\r
394 }\r
395 LongJump (&mJumpContext, (UINTN)-1);\r
396 ASSERT (FALSE);\r
397}\r
398""")\r
399]\r
400\r
401\r
402## UEFI Application Entry Point Templates\r
403gUefiApplicationEntryPointPrototype = TemplateString("""\r
404${BEGIN}\r
405EFI_STATUS\r
406EFIAPI\r
407${Function} (\r
408 IN EFI_HANDLE ImageHandle,\r
409 IN EFI_SYSTEM_TABLE *SystemTable\r
410 );\r
411${END}\r
412""")\r
413\r
414gUefiApplicationEntryPointString = [\r
415TemplateString("""\r
416const UINT32 _gUefiDriverRevision = ${UefiSpecVersion};\r
417\r
418EFI_STATUS\r
419EFIAPI\r
420ProcessModuleEntryPointList (\r
421 IN EFI_HANDLE ImageHandle,\r
422 IN EFI_SYSTEM_TABLE *SystemTable\r
423 )\r
424{\r
425 return EFI_SUCCESS;\r
426}\r
427"""),\r
428TemplateString("""\r
429const UINT32 _gUefiDriverRevision = ${UefiSpecVersion};\r
430\r
431${BEGIN}\r
432EFI_STATUS\r
433EFIAPI\r
434ProcessModuleEntryPointList (\r
435 IN EFI_HANDLE ImageHandle,\r
436 IN EFI_SYSTEM_TABLE *SystemTable\r
437 )\r
438\r
439{\r
440 return ${Function} (ImageHandle, SystemTable);\r
441}\r
442${END}\r
443VOID\r
444EFIAPI\r
445ExitDriver (\r
446 IN EFI_STATUS Status\r
447 )\r
448{\r
449 if (EFI_ERROR (Status)) {\r
450 ProcessLibraryDestructorList (gImageHandle, gST);\r
451 }\r
452 gBS->Exit (gImageHandle, Status, 0, NULL);\r
453}\r
454"""),\r
455TemplateString("""\r
456const UINT32 _gUefiDriverRevision = ${UefiSpecVersion};\r
457\r
458EFI_STATUS\r
459EFIAPI\r
460ProcessModuleEntryPointList (\r
461 IN EFI_HANDLE ImageHandle,\r
462 IN EFI_SYSTEM_TABLE *SystemTable\r
463 )\r
464\r
465{\r
466 ${BEGIN}\r
467 if (SetJump (&mJumpContext) == 0) {\r
468 ExitDriver (${Function} (ImageHandle, SystemTable));\r
469 ASSERT (FALSE);\r
470 }\r
471 ${END}\r
472 return mDriverEntryPointStatus;\r
473}\r
474\r
475static BASE_LIBRARY_JUMP_BUFFER mJumpContext;\r
476static EFI_STATUS mDriverEntryPointStatus = EFI_LOAD_ERROR;\r
477\r
478VOID\r
479EFIAPI\r
480ExitDriver (\r
481 IN EFI_STATUS Status\r
482 )\r
483{\r
484 if (!EFI_ERROR (Status) || EFI_ERROR (mDriverEntryPointStatus)) {\r
485 mDriverEntryPointStatus = Status;\r
486 }\r
487 LongJump (&mJumpContext, (UINTN)-1);\r
488 ASSERT (FALSE);\r
489}\r
490""")\r
491]\r
492\r
493## UEFI Unload Image Templates\r
494gUefiUnloadImagePrototype = TemplateString("""\r
495${BEGIN}\r
496EFI_STATUS\r
497EFIAPI\r
498${Function} (\r
499 IN EFI_HANDLE ImageHandle\r
500 );\r
501${END}\r
502""")\r
503\r
504gUefiUnloadImageString = [\r
505TemplateString("""\r
506GLOBAL_REMOVE_IF_UNREFERENCED const UINT8 _gDriverUnloadImageCount = ${Count};\r
507\r
508EFI_STATUS\r
509EFIAPI\r
510ProcessModuleUnloadList (\r
511 IN EFI_HANDLE ImageHandle\r
512 )\r
513{\r
514 return EFI_SUCCESS;\r
515}\r
516"""),\r
517TemplateString("""\r
518GLOBAL_REMOVE_IF_UNREFERENCED const UINT8 _gDriverUnloadImageCount = ${Count};\r
519\r
520${BEGIN}\r
521EFI_STATUS\r
522EFIAPI\r
523ProcessModuleUnloadList (\r
524 IN EFI_HANDLE ImageHandle\r
525 )\r
526{\r
527 return ${Function} (ImageHandle);\r
528}\r
529${END}\r
530"""),\r
531TemplateString("""\r
532GLOBAL_REMOVE_IF_UNREFERENCED const UINT8 _gDriverUnloadImageCount = ${Count};\r
533\r
534EFI_STATUS\r
535EFIAPI\r
536ProcessModuleUnloadList (\r
537 IN EFI_HANDLE ImageHandle\r
538 )\r
539{\r
540 EFI_STATUS Status;\r
541\r
542 Status = EFI_SUCCESS;\r
543${BEGIN}\r
544 if (EFI_ERROR (Status)) {\r
545 ${Function} (ImageHandle);\r
546 } else {\r
547 Status = ${Function} (ImageHandle);\r
548 }\r
549${END}\r
550 return Status;\r
551}\r
552""")\r
553]\r
554\r
555gLibraryStructorPrototype = {\r
556'BASE' : TemplateString("""${BEGIN}\r
557RETURN_STATUS\r
558EFIAPI\r
559${Function} (\r
560 VOID\r
561 );${END}\r
562"""),\r
563\r
564'PEI' : TemplateString("""${BEGIN}\r
565EFI_STATUS\r
566EFIAPI\r
567${Function} (\r
568 IN EFI_PEI_FILE_HANDLE FileHandle,\r
569 IN CONST EFI_PEI_SERVICES **PeiServices\r
570 );${END}\r
571"""),\r
572\r
573'DXE' : TemplateString("""${BEGIN}\r
574EFI_STATUS\r
575EFIAPI\r
576${Function} (\r
577 IN EFI_HANDLE ImageHandle,\r
578 IN EFI_SYSTEM_TABLE *SystemTable\r
579 );${END}\r
580"""),\r
581}\r
582\r
583gLibraryStructorCall = {\r
584'BASE' : TemplateString("""${BEGIN}\r
585 Status = ${Function} ();\r
586 ASSERT_EFI_ERROR (Status);${END}\r
587"""),\r
588\r
589'PEI' : TemplateString("""${BEGIN}\r
590 Status = ${Function} (FileHandle, PeiServices);\r
591 ASSERT_EFI_ERROR (Status);${END}\r
592"""),\r
593\r
594'DXE' : TemplateString("""${BEGIN}\r
595 Status = ${Function} (ImageHandle, SystemTable);\r
596 ASSERT_EFI_ERROR (Status);${END}\r
597"""),\r
598}\r
599\r
600## Library Constructor and Destructor Templates\r
601gLibraryString = {\r
602'BASE' : TemplateString("""\r
603${BEGIN}${FunctionPrototype}${END}\r
604\r
605VOID\r
606EFIAPI\r
607ProcessLibrary${Type}List (\r
608 VOID\r
609 )\r
610{\r
611${BEGIN} EFI_STATUS Status;\r
612${FunctionCall}${END}\r
613}\r
614"""),\r
615\r
616'PEI' : TemplateString("""\r
617${BEGIN}${FunctionPrototype}${END}\r
618\r
619VOID\r
620EFIAPI\r
621ProcessLibrary${Type}List (\r
622 IN EFI_PEI_FILE_HANDLE FileHandle,\r
623 IN CONST EFI_PEI_SERVICES **PeiServices\r
624 )\r
625{\r
626${BEGIN} EFI_STATUS Status;\r
627${FunctionCall}${END}\r
628}\r
629"""),\r
630\r
631'DXE' : TemplateString("""\r
632${BEGIN}${FunctionPrototype}${END}\r
633\r
634VOID\r
635EFIAPI\r
636ProcessLibrary${Type}List (\r
637 IN EFI_HANDLE ImageHandle,\r
638 IN EFI_SYSTEM_TABLE *SystemTable\r
639 )\r
640{\r
641${BEGIN} EFI_STATUS Status;\r
642${FunctionCall}${END}\r
643}\r
644"""),\r
645}\r
646\r
647gBasicHeaderFile = "Base.h"\r
648\r
649gModuleTypeHeaderFile = {\r
650 "BASE" : [gBasicHeaderFile],\r
651 "SEC" : ["PiPei.h", "Library/DebugLib.h"],\r
652 "PEI_CORE" : ["PiPei.h", "Library/DebugLib.h", "Library/PeiCoreEntryPoint.h"],\r
653 "PEIM" : ["PiPei.h", "Library/DebugLib.h", "Library/PeimEntryPoint.h"],\r
654 "DXE_CORE" : ["PiDxe.h", "Library/DebugLib.h", "Library/DxeCoreEntryPoint.h"],\r
655 "DXE_DRIVER" : ["PiDxe.h", "Library/BaseLib.h", "Library/DebugLib.h", "Library/UefiBootServicesTableLib.h", "Library/UefiDriverEntryPoint.h"],\r
656 "DXE_SMM_DRIVER" : ["PiDxe.h", "Library/BaseLib.h", "Library/DebugLib.h", "Library/UefiBootServicesTableLib.h", "Library/UefiDriverEntryPoint.h"],\r
657 "DXE_RUNTIME_DRIVER": ["PiDxe.h", "Library/BaseLib.h", "Library/DebugLib.h", "Library/UefiBootServicesTableLib.h", "Library/UefiDriverEntryPoint.h"],\r
658 "DXE_SAL_DRIVER" : ["PiDxe.h", "Library/BaseLib.h", "Library/DebugLib.h", "Library/UefiBootServicesTableLib.h", "Library/UefiDriverEntryPoint.h"],\r
659 "UEFI_DRIVER" : ["Uefi.h", "Library/BaseLib.h", "Library/DebugLib.h", "Library/UefiBootServicesTableLib.h", "Library/UefiDriverEntryPoint.h"],\r
660 "UEFI_APPLICATION" : ["Uefi.h", "Library/BaseLib.h", "Library/DebugLib.h", "Library/UefiBootServicesTableLib.h", "Library/UefiApplicationEntryPoint.h"],\r
661 "SMM_CORE" : ["PiDxe.h", "Library/BaseLib.h", "Library/DebugLib.h", "Library/UefiDriverEntryPoint.h"],\r
662 "USER_DEFINED" : [gBasicHeaderFile]\r
663}\r
664\r
665## Autogen internal worker macro to define DynamicEx PCD name includes both the TokenSpaceGuidName \r
666# the TokenName and Guid comparison to avoid define name collisions.\r
667#\r
668# @param Info The ModuleAutoGen object\r
669# @param AutoGenH The TemplateString object for header file\r
670#\r
671#\r
672def DynExPcdTokenNumberMapping(Info, AutoGenH):\r
673 ExTokenCNameList = []\r
674 PcdExList = []\r
675 if Info.IsLibrary:\r
676 PcdList = Info.LibraryPcdList\r
677 else:\r
678 PcdList = Info.ModulePcdList\r
679 for Pcd in PcdList:\r
680 if Pcd.Type in gDynamicExPcd:\r
681 ExTokenCNameList.append(Pcd.TokenCName)\r
682 PcdExList.append(Pcd)\r
683 if len(ExTokenCNameList) == 0:\r
684 return\r
685 AutoGenH.Append('\n#define COMPAREGUID(Guid1, Guid2) (BOOLEAN)(*(CONST UINT64*)Guid1 == *(CONST UINT64*)Guid2 && *((CONST UINT64*)Guid1 + 1) == *((CONST UINT64*)Guid2 + 1))\n')\r
686 # AutoGen for each PCD listed in a [PcdEx] section of a Module/Lib INF file.\r
687 # Auto generate a macro for each TokenName that takes a Guid pointer as a parameter. \r
688 # Use the Guid pointer to see if it matches any of the token space GUIDs.\r
689 TokenCNameList = []\r
690 for TokenCName in ExTokenCNameList:\r
691 if TokenCName in TokenCNameList:\r
692 continue\r
693 Index = 0\r
694 Count = ExTokenCNameList.count(TokenCName)\r
695 for Pcd in PcdExList:\r
696 if Pcd.TokenCName == TokenCName:\r
697 Index = Index + 1\r
698 if Index == 1:\r
699 AutoGenH.Append('\n#define __PCD_%s_ADDR_CMP(GuidPtr) (' % (Pcd.TokenCName))\r
700 AutoGenH.Append('\\\n (GuidPtr == &%s) ? _PCD_TOKEN_%s_%s:' \r
701 % (Pcd.TokenSpaceGuidCName, Pcd.TokenSpaceGuidCName, Pcd.TokenCName))\r
702 else:\r
703 AutoGenH.Append('\\\n (GuidPtr == &%s) ? _PCD_TOKEN_%s_%s:' \r
704 % (Pcd.TokenSpaceGuidCName, Pcd.TokenSpaceGuidCName, Pcd.TokenCName))\r
705 if Index == Count:\r
706 AutoGenH.Append('0 \\\n )\n')\r
707 TokenCNameList.append(TokenCName)\r
708 \r
709 TokenCNameList = []\r
710 for TokenCName in ExTokenCNameList:\r
711 if TokenCName in TokenCNameList:\r
712 continue\r
713 Index = 0\r
714 Count = ExTokenCNameList.count(TokenCName)\r
715 for Pcd in PcdExList:\r
716 if Pcd.Type in gDynamicExPcd and Pcd.TokenCName == TokenCName:\r
717 Index = Index + 1\r
718 if Index == 1:\r
719 AutoGenH.Append('\n#define __PCD_%s_VAL_CMP(GuidPtr) (' % (Pcd.TokenCName))\r
9023704f 720 AutoGenH.Append('\\\n (GuidPtr == NULL) ? 0:')\r
f51461c8
LG
721 AutoGenH.Append('\\\n COMPAREGUID (GuidPtr, &%s) ? _PCD_TOKEN_%s_%s:' \r
722 % (Pcd.TokenSpaceGuidCName, Pcd.TokenSpaceGuidCName, Pcd.TokenCName))\r
723 else:\r
724 AutoGenH.Append('\\\n COMPAREGUID (GuidPtr, &%s) ? _PCD_TOKEN_%s_%s:' \r
725 % (Pcd.TokenSpaceGuidCName, Pcd.TokenSpaceGuidCName, Pcd.TokenCName))\r
726 if Index == Count:\r
727 AutoGenH.Append('0 \\\n )\n')\r
728 # Autogen internal worker macro to compare GUIDs. Guid1 is a pointer to a GUID. \r
729 # Guid2 is a C name for a GUID. Compare pointers first because optimizing compiler\r
730 # can do this at build time on CONST GUID pointers and optimize away call to COMPAREGUID().\r
731 # COMPAREGUID() will only be used if the Guid passed in is local to the module.\r
732 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
733 % (Pcd.TokenCName, Pcd.TokenCName, Pcd.TokenCName, Pcd.TokenCName))\r
734 TokenCNameList.append(TokenCName)\r
735\r
2f5acc3b
BF
736def GetPcdSize(Pcd):\r
737 if Pcd.DatumType == 'VOID*':\r
738 Value = Pcd.DefaultValue\r
739 if Value in [None, '']:\r
740 return 1\r
741 elif Value[0] == 'L':\r
742 return (len(Value) - 2) * 2\r
743 elif Value[0] == '{':\r
744 return len(Value.split(','))\r
745 else:\r
746 return len(Value) - 1\r
747 if Pcd.DatumType == 'UINT64':\r
748 return 8\r
749 if Pcd.DatumType == 'UINT32':\r
750 return 4\r
751 if Pcd.DatumType == 'UINT16':\r
752 return 2\r
753 if Pcd.DatumType == 'UINT8':\r
754 return 1\r
755 if Pcd.DatumType == 'BOOLEAN':\r
756 return 1\r
757\r
758\r
f51461c8
LG
759## Create code for module PCDs\r
760#\r
761# @param Info The ModuleAutoGen object\r
762# @param AutoGenC The TemplateString object for C code\r
763# @param AutoGenH The TemplateString object for header file\r
764# @param Pcd The PCD object\r
765#\r
766def CreateModulePcdCode(Info, AutoGenC, AutoGenH, Pcd):\r
767 TokenSpaceGuidValue = Pcd.TokenSpaceGuidValue #Info.GuidList[Pcd.TokenSpaceGuidCName]\r
768 PcdTokenNumber = Info.PlatformInfo.PcdTokenNumber\r
763e8edf
YZ
769\r
770 if GlobalData.BuildOptionPcd:\r
771 for PcdItem in GlobalData.BuildOptionPcd:\r
772 if (Pcd.TokenSpaceGuidCName, Pcd.TokenCName) == (PcdItem[0], PcdItem[1]):\r
773 Pcd.DefaultValue = PcdItem[2]\r
774 break\r
775\r
f51461c8
LG
776 #\r
777 # Write PCDs\r
778 #\r
779 PcdTokenName = '_PCD_TOKEN_' + Pcd.TokenCName\r
2f5acc3b
BF
780 PatchPcdSizeTokenName = '_PCD_PATCHABLE_' + Pcd.TokenCName +'_SIZE'\r
781 PatchPcdSizeVariableName = '_gPcd_BinaryPatch_Size_' + Pcd.TokenCName\r
782 FixPcdSizeTokenName = '_PCD_SIZE_' + Pcd.TokenCName\r
783 \r
f51461c8
LG
784 if Pcd.Type in gDynamicExPcd:\r
785 TokenNumber = int(Pcd.TokenValue, 0)\r
786 # Add TokenSpaceGuidValue value to PcdTokenName to discriminate the DynamicEx PCDs with \r
787 # different Guids but same TokenCName\r
788 PcdExTokenName = '_PCD_TOKEN_' + Pcd.TokenSpaceGuidCName + '_' + Pcd.TokenCName\r
789 AutoGenH.Append('\n#define %s %dU\n' % (PcdExTokenName, TokenNumber))\r
790 else:\r
791 if (Pcd.TokenCName, Pcd.TokenSpaceGuidCName) not in PcdTokenNumber:\r
792 # If one of the Source built modules listed in the DSC is not listed in FDF modules, \r
793 # and the INF lists a PCD can only use the PcdsDynamic access method (it is only \r
794 # listed in the DEC file that declares the PCD as PcdsDynamic), then build tool will \r
795 # report warning message notify the PI that they are attempting to build a module \r
796 # that must be included in a flash image in order to be functional. These Dynamic PCD \r
797 # will not be added into the Database unless it is used by other modules that are \r
798 # included in the FDF file. \r
799 # In this case, just assign an invalid token number to make it pass build.\r
800 if Pcd.Type in PCD_DYNAMIC_TYPE_LIST:\r
801 TokenNumber = 0\r
802 else:\r
803 EdkLogger.error("build", AUTOGEN_ERROR,\r
804 "No generated token number for %s.%s\n" % (Pcd.TokenSpaceGuidCName, Pcd.TokenCName),\r
805 ExtraData="[%s]" % str(Info))\r
806 else:\r
807 TokenNumber = PcdTokenNumber[Pcd.TokenCName, Pcd.TokenSpaceGuidCName]\r
808 AutoGenH.Append('\n#define %s %dU\n' % (PcdTokenName, TokenNumber))\r
809\r
810 EdkLogger.debug(EdkLogger.DEBUG_3, "Creating code for " + Pcd.TokenCName + "." + Pcd.TokenSpaceGuidCName)\r
811 if Pcd.Type not in gItemTypeStringDatabase:\r
812 EdkLogger.error("build", AUTOGEN_ERROR,\r
813 "Unknown PCD type [%s] of PCD %s.%s" % (Pcd.Type, Pcd.TokenSpaceGuidCName, Pcd.TokenCName),\r
814 ExtraData="[%s]" % str(Info))\r
815 if Pcd.DatumType not in gDatumSizeStringDatabase:\r
816 EdkLogger.error("build", AUTOGEN_ERROR,\r
817 "Unknown datum type [%s] of PCD %s.%s" % (Pcd.DatumType, Pcd.TokenSpaceGuidCName, Pcd.TokenCName),\r
818 ExtraData="[%s]" % str(Info))\r
819\r
820 DatumSize = gDatumSizeStringDatabase[Pcd.DatumType]\r
821 DatumSizeLib = gDatumSizeStringDatabaseLib[Pcd.DatumType]\r
822 GetModeName = '_PCD_GET_MODE_' + gDatumSizeStringDatabaseH[Pcd.DatumType] + '_' + Pcd.TokenCName\r
823 SetModeName = '_PCD_SET_MODE_' + gDatumSizeStringDatabaseH[Pcd.DatumType] + '_' + Pcd.TokenCName\r
82a6a960 824 SetModeStatusName = '_PCD_SET_MODE_' + gDatumSizeStringDatabaseH[Pcd.DatumType] + '_S_' + Pcd.TokenCName\r
2f5acc3b
BF
825 GetModeSizeName = '_PCD_GET_MODE_SIZE' + '_' + Pcd.TokenCName\r
826 \r
f51461c8
LG
827 PcdExCNameList = []\r
828 if Pcd.Type in gDynamicExPcd:\r
829 if Info.IsLibrary:\r
830 PcdList = Info.LibraryPcdList\r
831 else:\r
832 PcdList = Info.ModulePcdList\r
833 for PcdModule in PcdList:\r
834 if PcdModule.Type in gDynamicExPcd:\r
835 PcdExCNameList.append(PcdModule.TokenCName)\r
836 # Be compatible with the current code which using PcdToken and PcdGet/Set for DynamicEx Pcd.\r
837 # If only PcdToken and PcdGet/Set used in all Pcds with different CName, it should succeed to build.\r
838 # If PcdToken and PcdGet/Set used in the Pcds with different Guids but same CName, it should failed to build.\r
839 if PcdExCNameList.count(Pcd.TokenCName) > 1:\r
840 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
841 AutoGenH.Append('// #define %s %s\n' % (PcdTokenName, PcdExTokenName))\r
842 AutoGenH.Append('// #define %s LibPcdGetEx%s(&%s, %s)\n' % (GetModeName, DatumSizeLib, Pcd.TokenSpaceGuidCName, PcdTokenName))\r
38b986e3 843 AutoGenH.Append('// #define %s LibPcdGetExSize(&%s, %s)\n' % (GetModeSizeName,Pcd.TokenSpaceGuidCName, PcdTokenName))\r
f51461c8
LG
844 if Pcd.DatumType == 'VOID*':\r
845 AutoGenH.Append('// #define %s(SizeOfBuffer, Buffer) LibPcdSetEx%s(&%s, %s, (SizeOfBuffer), (Buffer))\n' % (SetModeName, DatumSizeLib, Pcd.TokenSpaceGuidCName, PcdTokenName))\r
82a6a960 846 AutoGenH.Append('// #define %s(SizeOfBuffer, Buffer) LibPcdSetEx%sS(&%s, %s, (SizeOfBuffer), (Buffer))\n' % (SetModeStatusName, DatumSizeLib, Pcd.TokenSpaceGuidCName, PcdTokenName))\r
f51461c8
LG
847 else:\r
848 AutoGenH.Append('// #define %s(Value) LibPcdSetEx%s(&%s, %s, (Value))\n' % (SetModeName, DatumSizeLib, Pcd.TokenSpaceGuidCName, PcdTokenName))\r
82a6a960 849 AutoGenH.Append('// #define %s(Value) LibPcdSetEx%sS(&%s, %s, (Value))\n' % (SetModeStatusName, DatumSizeLib, Pcd.TokenSpaceGuidCName, PcdTokenName))\r
f51461c8
LG
850 else:\r
851 AutoGenH.Append('#define %s %s\n' % (PcdTokenName, PcdExTokenName))\r
852 AutoGenH.Append('#define %s LibPcdGetEx%s(&%s, %s)\n' % (GetModeName, DatumSizeLib, Pcd.TokenSpaceGuidCName, PcdTokenName))\r
2f5acc3b 853 AutoGenH.Append('#define %s LibPcdGetExSize(&%s, %s)\n' % (GetModeSizeName,Pcd.TokenSpaceGuidCName, PcdTokenName))\r
f51461c8
LG
854 if Pcd.DatumType == 'VOID*':\r
855 AutoGenH.Append('#define %s(SizeOfBuffer, Buffer) LibPcdSetEx%s(&%s, %s, (SizeOfBuffer), (Buffer))\n' % (SetModeName, DatumSizeLib, Pcd.TokenSpaceGuidCName, PcdTokenName))\r
82a6a960 856 AutoGenH.Append('#define %s(SizeOfBuffer, Buffer) LibPcdSetEx%sS(&%s, %s, (SizeOfBuffer), (Buffer))\n' % (SetModeStatusName, DatumSizeLib, Pcd.TokenSpaceGuidCName, PcdTokenName))\r
f51461c8
LG
857 else:\r
858 AutoGenH.Append('#define %s(Value) LibPcdSetEx%s(&%s, %s, (Value))\n' % (SetModeName, DatumSizeLib, Pcd.TokenSpaceGuidCName, PcdTokenName))\r
82a6a960 859 AutoGenH.Append('#define %s(Value) LibPcdSetEx%sS(&%s, %s, (Value))\n' % (SetModeStatusName, DatumSizeLib, Pcd.TokenSpaceGuidCName, PcdTokenName))\r
f51461c8 860 elif Pcd.Type in gDynamicPcd:\r
38b986e3
YZ
861 PcdList = []\r
862 PcdCNameList = []\r
863 PcdList.extend(Info.LibraryPcdList)\r
864 PcdList.extend(Info.ModulePcdList)\r
865 for PcdModule in PcdList:\r
866 if PcdModule.Type in gDynamicPcd:\r
867 PcdCNameList.append(PcdModule.TokenCName)\r
868 if PcdCNameList.count(Pcd.TokenCName) > 1:\r
869 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" % (Pcd.TokenCName), ExtraData="[%s]" % str(Info.MetaFile.Path))\r
f51461c8 870 else:\r
38b986e3
YZ
871 AutoGenH.Append('#define %s LibPcdGet%s(%s)\n' % (GetModeName, DatumSizeLib, PcdTokenName))\r
872 AutoGenH.Append('#define %s LibPcdGetSize(%s)\n' % (GetModeSizeName, PcdTokenName))\r
873 if Pcd.DatumType == 'VOID*':\r
874 AutoGenH.Append('#define %s(SizeOfBuffer, Buffer) LibPcdSet%s(%s, (SizeOfBuffer), (Buffer))\n' %(SetModeName, DatumSizeLib, PcdTokenName))\r
875 AutoGenH.Append('#define %s(SizeOfBuffer, Buffer) LibPcdSet%sS(%s, (SizeOfBuffer), (Buffer))\n' % (SetModeStatusName, DatumSizeLib, PcdTokenName))\r
876 else:\r
877 AutoGenH.Append('#define %s(Value) LibPcdSet%s(%s, (Value))\n' % (SetModeName, DatumSizeLib, PcdTokenName))\r
878 AutoGenH.Append('#define %s(Value) LibPcdSet%sS(%s, (Value))\n' % (SetModeStatusName, DatumSizeLib, PcdTokenName))\r
f51461c8
LG
879 else:\r
880 PcdVariableName = '_gPcd_' + gItemTypeStringDatabase[Pcd.Type] + '_' + Pcd.TokenCName\r
881 Const = 'const'\r
882 if Pcd.Type == TAB_PCDS_PATCHABLE_IN_MODULE:\r
883 Const = ''\r
884 Type = ''\r
885 Array = ''\r
886 Value = Pcd.DefaultValue\r
887 Unicode = False\r
888 ValueNumber = 0\r
889\r
890 if Pcd.DatumType == 'BOOLEAN':\r
891 BoolValue = Value.upper()\r
892 if BoolValue == 'TRUE' or BoolValue == '1':\r
893 Value = '1U'\r
894 elif BoolValue == 'FALSE' or BoolValue == '0':\r
895 Value = '0U'\r
896\r
897 if Pcd.DatumType in ['UINT64', 'UINT32', 'UINT16', 'UINT8']:\r
898 try:\r
899 if Value.upper().startswith('0X'):\r
900 ValueNumber = int (Value, 16)\r
901 else:\r
902 ValueNumber = int (Value)\r
903 except:\r
904 EdkLogger.error("build", AUTOGEN_ERROR,\r
905 "PCD value is not valid dec or hex number for datum type [%s] of PCD %s.%s" % (Pcd.DatumType, Pcd.TokenSpaceGuidCName, Pcd.TokenCName),\r
906 ExtraData="[%s]" % str(Info))\r
907 if Pcd.DatumType == 'UINT64':\r
908 if ValueNumber < 0:\r
909 EdkLogger.error("build", AUTOGEN_ERROR,\r
910 "PCD can't be set to negative value for datum type [%s] of PCD %s.%s" % (Pcd.DatumType, Pcd.TokenSpaceGuidCName, Pcd.TokenCName),\r
911 ExtraData="[%s]" % str(Info))\r
912 elif ValueNumber >= 0x10000000000000000:\r
913 EdkLogger.error("build", AUTOGEN_ERROR,\r
914 "Too large PCD value for datum type [%s] of PCD %s.%s" % (Pcd.DatumType, Pcd.TokenSpaceGuidCName, Pcd.TokenCName),\r
915 ExtraData="[%s]" % str(Info))\r
916 if not Value.endswith('ULL'):\r
917 Value += 'ULL'\r
918 elif Pcd.DatumType == 'UINT32':\r
919 if ValueNumber < 0:\r
920 EdkLogger.error("build", AUTOGEN_ERROR,\r
921 "PCD can't be set to negative value for datum type [%s] of PCD %s.%s" % (Pcd.DatumType, Pcd.TokenSpaceGuidCName, Pcd.TokenCName),\r
922 ExtraData="[%s]" % str(Info))\r
923 elif ValueNumber >= 0x100000000:\r
924 EdkLogger.error("build", AUTOGEN_ERROR,\r
925 "Too large PCD value for datum type [%s] of PCD %s.%s" % (Pcd.DatumType, Pcd.TokenSpaceGuidCName, Pcd.TokenCName),\r
926 ExtraData="[%s]" % str(Info))\r
927 if not Value.endswith('U'):\r
928 Value += 'U'\r
929 elif Pcd.DatumType == 'UINT16':\r
930 if ValueNumber < 0:\r
931 EdkLogger.error("build", AUTOGEN_ERROR,\r
932 "PCD can't be set to negative value for datum type [%s] of PCD %s.%s" % (Pcd.DatumType, Pcd.TokenSpaceGuidCName, Pcd.TokenCName),\r
933 ExtraData="[%s]" % str(Info))\r
934 elif ValueNumber >= 0x10000:\r
935 EdkLogger.error("build", AUTOGEN_ERROR,\r
936 "Too large PCD value for datum type [%s] of PCD %s.%s" % (Pcd.DatumType, Pcd.TokenSpaceGuidCName, Pcd.TokenCName),\r
937 ExtraData="[%s]" % str(Info))\r
938 if not Value.endswith('U'):\r
939 Value += 'U' \r
940 elif Pcd.DatumType == 'UINT8':\r
941 if ValueNumber < 0:\r
942 EdkLogger.error("build", AUTOGEN_ERROR,\r
943 "PCD can't be set to negative value for datum type [%s] of PCD %s.%s" % (Pcd.DatumType, Pcd.TokenSpaceGuidCName, Pcd.TokenCName),\r
944 ExtraData="[%s]" % str(Info))\r
945 elif ValueNumber >= 0x100:\r
946 EdkLogger.error("build", AUTOGEN_ERROR,\r
947 "Too large PCD value for datum type [%s] of PCD %s.%s" % (Pcd.DatumType, Pcd.TokenSpaceGuidCName, Pcd.TokenCName),\r
948 ExtraData="[%s]" % str(Info))\r
949 if not Value.endswith('U'):\r
950 Value += 'U'\r
951 if Pcd.DatumType == 'VOID*':\r
952 if Pcd.MaxDatumSize == None or Pcd.MaxDatumSize == '':\r
953 EdkLogger.error("build", AUTOGEN_ERROR,\r
954 "Unknown [MaxDatumSize] of PCD [%s.%s]" % (Pcd.TokenSpaceGuidCName, Pcd.TokenCName),\r
955 ExtraData="[%s]" % str(Info))\r
956\r
957 ArraySize = int(Pcd.MaxDatumSize, 0)\r
958 if Value[0] == '{':\r
959 Type = '(VOID *)'\r
960 else:\r
961 if Value[0] == 'L':\r
962 Unicode = True\r
963 Value = Value.lstrip('L') #.strip('"')\r
964 Value = eval(Value) # translate escape character\r
965 NewValue = '{'\r
966 for Index in range(0,len(Value)):\r
967 if Unicode:\r
968 NewValue = NewValue + str(ord(Value[Index]) % 0x10000) + ', '\r
969 else:\r
970 NewValue = NewValue + str(ord(Value[Index]) % 0x100) + ', '\r
971 if Unicode:\r
972 ArraySize = ArraySize / 2;\r
973\r
974 if ArraySize < (len(Value) + 1):\r
975 EdkLogger.error("build", AUTOGEN_ERROR,\r
976 "The maximum size of VOID* type PCD '%s.%s' is less than its actual size occupied." % (Pcd.TokenSpaceGuidCName, Pcd.TokenCName),\r
977 ExtraData="[%s]" % str(Info))\r
978 Value = NewValue + '0 }'\r
979 Array = '[%d]' % ArraySize\r
980 #\r
981 # skip casting for fixed at build since it breaks ARM assembly.\r
982 # Long term we need PCD macros that work in assembly\r
983 #\r
984 elif Pcd.Type != TAB_PCDS_FIXED_AT_BUILD:\r
985 Value = "((%s)%s)" % (Pcd.DatumType, Value)\r
986\r
987 if Pcd.Type == TAB_PCDS_PATCHABLE_IN_MODULE:\r
988 PcdValueName = '_PCD_PATCHABLE_VALUE_' + Pcd.TokenCName\r
989 else:\r
990 PcdValueName = '_PCD_VALUE_' + Pcd.TokenCName\r
991 \r
992 if Pcd.DatumType == 'VOID*':\r
993 #\r
994 # For unicode, UINT16 array will be generated, so the alignment of unicode is guaranteed.\r
995 #\r
996 if Unicode:\r
f51461c8
LG
997 AutoGenH.Append('#define %s %s%s\n' %(PcdValueName, Type, PcdVariableName))\r
998 AutoGenC.Append('GLOBAL_REMOVE_IF_UNREFERENCED %s UINT16 %s%s = %s;\n' % (Const, PcdVariableName, Array, Value))\r
999 AutoGenH.Append('extern %s UINT16 %s%s;\n' %(Const, PcdVariableName, Array))\r
1000 AutoGenH.Append('#define %s %s%s\n' %(GetModeName, Type, PcdVariableName))\r
1001 else:\r
f51461c8
LG
1002 AutoGenH.Append('#define %s %s%s\n' %(PcdValueName, Type, PcdVariableName))\r
1003 AutoGenC.Append('GLOBAL_REMOVE_IF_UNREFERENCED %s UINT8 %s%s = %s;\n' % (Const, PcdVariableName, Array, Value))\r
1004 AutoGenH.Append('extern %s UINT8 %s%s;\n' %(Const, PcdVariableName, Array))\r
1005 AutoGenH.Append('#define %s %s%s\n' %(GetModeName, Type, PcdVariableName))\r
2f5acc3b
BF
1006 \r
1007 PcdDataSize = GetPcdSize(Pcd)\r
1008 if Pcd.Type == TAB_PCDS_FIXED_AT_BUILD:\r
1009 AutoGenH.Append('#define %s %s\n' % (FixPcdSizeTokenName, PcdDataSize))\r
1010 AutoGenH.Append('#define %s %s \n' % (GetModeSizeName,FixPcdSizeTokenName))\r
1011 \r
1012 if Pcd.Type == TAB_PCDS_PATCHABLE_IN_MODULE:\r
1013 AutoGenH.Append('#define %s %s\n' % (PatchPcdSizeTokenName, Pcd.MaxDatumSize))\r
1014 AutoGenH.Append('#define %s %s \n' % (GetModeSizeName,PatchPcdSizeVariableName))\r
1015 AutoGenH.Append('extern UINTN %s; \n' % PatchPcdSizeVariableName)\r
1016 AutoGenC.Append('GLOBAL_REMOVE_IF_UNREFERENCED UINTN %s = %s;\n' % (PatchPcdSizeVariableName,PcdDataSize))\r
f51461c8
LG
1017 elif Pcd.Type == TAB_PCDS_PATCHABLE_IN_MODULE:\r
1018 AutoGenH.Append('#define %s %s\n' %(PcdValueName, Value))\r
1019 AutoGenC.Append('volatile %s %s %s = %s;\n' %(Const, Pcd.DatumType, PcdVariableName, PcdValueName))\r
1020 AutoGenH.Append('extern volatile %s %s %s%s;\n' % (Const, Pcd.DatumType, PcdVariableName, Array))\r
1021 AutoGenH.Append('#define %s %s%s\n' % (GetModeName, Type, PcdVariableName))\r
2f5acc3b
BF
1022 \r
1023 PcdDataSize = GetPcdSize(Pcd)\r
1024 AutoGenH.Append('#define %s %s\n' % (PatchPcdSizeTokenName, PcdDataSize))\r
1025 \r
1026 AutoGenH.Append('#define %s %s \n' % (GetModeSizeName,PatchPcdSizeVariableName))\r
1027 AutoGenH.Append('extern UINTN %s; \n' % PatchPcdSizeVariableName)\r
1028 AutoGenC.Append('GLOBAL_REMOVE_IF_UNREFERENCED UINTN %s = %s;\n' % (PatchPcdSizeVariableName,PcdDataSize))\r
f51461c8 1029 else:\r
2f5acc3b
BF
1030 PcdDataSize = GetPcdSize(Pcd)\r
1031 AutoGenH.Append('#define %s %s\n' % (FixPcdSizeTokenName, PcdDataSize))\r
1032 AutoGenH.Append('#define %s %s \n' % (GetModeSizeName,FixPcdSizeTokenName))\r
1033 \r
f51461c8
LG
1034 AutoGenH.Append('#define %s %s\n' %(PcdValueName, Value))\r
1035 AutoGenC.Append('GLOBAL_REMOVE_IF_UNREFERENCED %s %s %s = %s;\n' %(Const, Pcd.DatumType, PcdVariableName, PcdValueName))\r
1036 AutoGenH.Append('extern %s %s %s%s;\n' % (Const, Pcd.DatumType, PcdVariableName, Array))\r
1037 AutoGenH.Append('#define %s %s%s\n' % (GetModeName, Type, PcdVariableName))\r
1038\r
1039 if Pcd.Type == TAB_PCDS_PATCHABLE_IN_MODULE:\r
1040 if Pcd.DatumType == 'VOID*':\r
e70504cd
LG
1041 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
1042 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
1043 else:\r
1044 AutoGenH.Append('#define %s(Value) (%s = (Value))\n' % (SetModeName, PcdVariableName))\r
82a6a960 1045 AutoGenH.Append('#define %s(Value) ((%s = (Value)), RETURN_SUCCESS) \n' % (SetModeStatusName, PcdVariableName))\r
f51461c8
LG
1046 else:\r
1047 AutoGenH.Append('//#define %s ASSERT(FALSE) // It is not allowed to set value for a FIXED_AT_BUILD PCD\n' % SetModeName)\r
1048\r
1049## Create code for library module PCDs\r
1050#\r
1051# @param Info The ModuleAutoGen object\r
1052# @param AutoGenC The TemplateString object for C code\r
1053# @param AutoGenH The TemplateString object for header file\r
1054# @param Pcd The PCD object\r
1055#\r
1056def CreateLibraryPcdCode(Info, AutoGenC, AutoGenH, Pcd):\r
1057 PcdTokenNumber = Info.PlatformInfo.PcdTokenNumber\r
1058 TokenSpaceGuidCName = Pcd.TokenSpaceGuidCName\r
1059 TokenCName = Pcd.TokenCName\r
1060 PcdTokenName = '_PCD_TOKEN_' + TokenCName\r
2f5acc3b
BF
1061 FixPcdSizeTokenName = '_PCD_SIZE_' + Pcd.TokenCName\r
1062 PatchPcdSizeTokenName = '_PCD_PATCHABLE_' + Pcd.TokenCName +'_SIZE'\r
1063 PatchPcdSizeVariableName = '_gPcd_BinaryPatch_Size_' + Pcd.TokenCName\r
763e8edf
YZ
1064\r
1065 if GlobalData.BuildOptionPcd:\r
1066 for PcdItem in GlobalData.BuildOptionPcd:\r
1067 if (Pcd.TokenSpaceGuidCName, Pcd.TokenCName) == (PcdItem[0], PcdItem[1]):\r
1068 Pcd.DefaultValue = PcdItem[2]\r
1069 break\r
1070\r
f51461c8
LG
1071 #\r
1072 # Write PCDs\r
1073 #\r
1074 if Pcd.Type in gDynamicExPcd:\r
1075 TokenNumber = int(Pcd.TokenValue, 0)\r
1076 else:\r
1077 if (Pcd.TokenCName, Pcd.TokenSpaceGuidCName) not in PcdTokenNumber:\r
1078 # If one of the Source built modules listed in the DSC is not listed in FDF modules, \r
1079 # and the INF lists a PCD can only use the PcdsDynamic access method (it is only \r
1080 # listed in the DEC file that declares the PCD as PcdsDynamic), then build tool will \r
1081 # report warning message notify the PI that they are attempting to build a module \r
1082 # that must be included in a flash image in order to be functional. These Dynamic PCD \r
1083 # will not be added into the Database unless it is used by other modules that are \r
1084 # included in the FDF file. \r
1085 # In this case, just assign an invalid token number to make it pass build.\r
1086 if Pcd.Type in PCD_DYNAMIC_TYPE_LIST:\r
1087 TokenNumber = 0\r
1088 else:\r
1089 EdkLogger.error("build", AUTOGEN_ERROR,\r
1090 "No generated token number for %s.%s\n" % (Pcd.TokenSpaceGuidCName, Pcd.TokenCName),\r
1091 ExtraData="[%s]" % str(Info))\r
1092 else:\r
1093 TokenNumber = PcdTokenNumber[Pcd.TokenCName, Pcd.TokenSpaceGuidCName]\r
1094\r
1095 if Pcd.Type not in gItemTypeStringDatabase:\r
1096 EdkLogger.error("build", AUTOGEN_ERROR,\r
1097 "Unknown PCD type [%s] of PCD %s.%s" % (Pcd.Type, Pcd.TokenSpaceGuidCName, Pcd.TokenCName),\r
1098 ExtraData="[%s]" % str(Info))\r
1099 if Pcd.DatumType not in gDatumSizeStringDatabase:\r
1100 EdkLogger.error("build", AUTOGEN_ERROR,\r
1101 "Unknown datum type [%s] of PCD %s.%s" % (Pcd.DatumType, Pcd.TokenSpaceGuidCName, Pcd.TokenCName),\r
1102 ExtraData="[%s]" % str(Info))\r
1103\r
1104 DatumType = Pcd.DatumType\r
1105 DatumSize = gDatumSizeStringDatabaseH[DatumType]\r
1106 DatumSizeLib= gDatumSizeStringDatabaseLib[DatumType]\r
1107 GetModeName = '_PCD_GET_MODE_' + DatumSize + '_' + TokenCName\r
1108 SetModeName = '_PCD_SET_MODE_' + DatumSize + '_' + TokenCName\r
82a6a960 1109 SetModeStatusName = '_PCD_SET_MODE_' + DatumSize + '_S_' + TokenCName\r
2f5acc3b 1110 GetModeSizeName = '_PCD_GET_MODE_SIZE' + '_' + Pcd.TokenCName\r
f51461c8
LG
1111\r
1112 Type = ''\r
1113 Array = ''\r
1114 if Pcd.DatumType == 'VOID*':\r
d66670f9
YZ
1115 if Pcd.DefaultValue[0]== '{':\r
1116 Type = '(VOID *)'\r
f51461c8
LG
1117 Array = '[]'\r
1118 PcdItemType = Pcd.Type\r
1119 PcdExCNameList = []\r
1120 if PcdItemType in gDynamicExPcd:\r
1121 PcdExTokenName = '_PCD_TOKEN_' + TokenSpaceGuidCName + '_' + Pcd.TokenCName\r
1122 AutoGenH.Append('\n#define %s %dU\n' % (PcdExTokenName, TokenNumber))\r
1123 \r
1124 if Info.IsLibrary:\r
1125 PcdList = Info.LibraryPcdList\r
1126 else:\r
1127 PcdList = Info.ModulePcdList\r
1128 for PcdModule in PcdList:\r
1129 if PcdModule.Type in gDynamicExPcd:\r
1130 PcdExCNameList.append(PcdModule.TokenCName)\r
1131 # Be compatible with the current code which using PcdGet/Set for DynamicEx Pcd.\r
1132 # If only PcdGet/Set used in all Pcds with different CName, it should succeed to build.\r
1133 # If PcdGet/Set used in the Pcds with different Guids but same CName, it should failed to build.\r
1134 if PcdExCNameList.count(Pcd.TokenCName) > 1:\r
1135 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
1136 AutoGenH.Append('// #define %s %s\n' % (PcdTokenName, PcdExTokenName))\r
1137 AutoGenH.Append('// #define %s LibPcdGetEx%s(&%s, %s)\n' % (GetModeName, DatumSizeLib, Pcd.TokenSpaceGuidCName, PcdTokenName))\r
38b986e3 1138 AutoGenH.Append('// #define %s LibPcdGetExSize(&%s, %s \n' % (GetModeSizeName,Pcd.TokenSpaceGuidCName, PcdTokenName))\r
f51461c8
LG
1139 if Pcd.DatumType == 'VOID*':\r
1140 AutoGenH.Append('// #define %s(SizeOfBuffer, Buffer) LibPcdSetEx%s(&%s, %s, (SizeOfBuffer), (Buffer))\n' % (SetModeName, DatumSizeLib, Pcd.TokenSpaceGuidCName, PcdTokenName))\r
82a6a960 1141 AutoGenH.Append('// #define %s(SizeOfBuffer, Buffer) LibPcdSetEx%sS(&%s, %s, (SizeOfBuffer), (Buffer))\n' % (SetModeStatusName, DatumSizeLib, Pcd.TokenSpaceGuidCName, PcdTokenName))\r
f51461c8
LG
1142 else:\r
1143 AutoGenH.Append('// #define %s(Value) LibPcdSetEx%s(&%s, %s, (Value))\n' % (SetModeName, DatumSizeLib, Pcd.TokenSpaceGuidCName, PcdTokenName))\r
82a6a960 1144 AutoGenH.Append('// #define %s(Value) LibPcdSetEx%sS(&%s, %s, (Value))\n' % (SetModeStatusName, DatumSizeLib, Pcd.TokenSpaceGuidCName, PcdTokenName))\r
f51461c8
LG
1145 else:\r
1146 AutoGenH.Append('#define %s %s\n' % (PcdTokenName, PcdExTokenName))\r
1147 AutoGenH.Append('#define %s LibPcdGetEx%s(&%s, %s)\n' % (GetModeName, DatumSizeLib, Pcd.TokenSpaceGuidCName, PcdTokenName))\r
2f5acc3b 1148 AutoGenH.Append('#define %s LibPcdGetExSize(&%s, %s)\n' % (GetModeSizeName,Pcd.TokenSpaceGuidCName, PcdTokenName))\r
f51461c8
LG
1149 if Pcd.DatumType == 'VOID*':\r
1150 AutoGenH.Append('#define %s(SizeOfBuffer, Buffer) LibPcdSetEx%s(&%s, %s, (SizeOfBuffer), (Buffer))\n' % (SetModeName, DatumSizeLib, Pcd.TokenSpaceGuidCName, PcdTokenName))\r
82a6a960 1151 AutoGenH.Append('#define %s(SizeOfBuffer, Buffer) LibPcdSetEx%sS(&%s, %s, (SizeOfBuffer), (Buffer))\n' % (SetModeStatusName, DatumSizeLib, Pcd.TokenSpaceGuidCName, PcdTokenName))\r
f51461c8
LG
1152 else:\r
1153 AutoGenH.Append('#define %s(Value) LibPcdSetEx%s(&%s, %s, (Value))\n' % (SetModeName, DatumSizeLib, Pcd.TokenSpaceGuidCName, PcdTokenName))\r
82a6a960 1154 AutoGenH.Append('#define %s(Value) LibPcdSetEx%sS(&%s, %s, (Value))\n' % (SetModeStatusName, DatumSizeLib, Pcd.TokenSpaceGuidCName, PcdTokenName))\r
f51461c8
LG
1155 else:\r
1156 AutoGenH.Append('#define _PCD_TOKEN_%s %dU\n' % (TokenCName, TokenNumber))\r
1157 if PcdItemType in gDynamicPcd:\r
38b986e3
YZ
1158 PcdList = []\r
1159 PcdCNameList = []\r
1160 PcdList.extend(Info.LibraryPcdList)\r
1161 PcdList.extend(Info.ModulePcdList)\r
1162 for PcdModule in PcdList:\r
1163 if PcdModule.Type in gDynamicPcd:\r
1164 PcdCNameList.append(PcdModule.TokenCName)\r
1165 if PcdCNameList.count(Pcd.TokenCName) > 1:\r
1166 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" % (Pcd.TokenCName), ExtraData="[%s]" % str(Info.MetaFile.Path))\r
f51461c8 1167 else:\r
38b986e3
YZ
1168 AutoGenH.Append('#define %s LibPcdGet%s(%s)\n' % (GetModeName, DatumSizeLib, PcdTokenName))\r
1169 AutoGenH.Append('#define %s LibPcdGetSize(%s)\n' % (GetModeSizeName, PcdTokenName))\r
1170 if DatumType == 'VOID*':\r
1171 AutoGenH.Append('#define %s(SizeOfBuffer, Buffer) LibPcdSet%s(%s, (SizeOfBuffer), (Buffer))\n' %(SetModeName, DatumSizeLib, PcdTokenName))\r
1172 AutoGenH.Append('#define %s(SizeOfBuffer, Buffer) LibPcdSet%sS(%s, (SizeOfBuffer), (Buffer))\n' % (SetModeStatusName, DatumSizeLib, PcdTokenName))\r
1173 else:\r
1174 AutoGenH.Append('#define %s(Value) LibPcdSet%s(%s, (Value))\n' % (SetModeName, DatumSizeLib, PcdTokenName))\r
1175 AutoGenH.Append('#define %s(Value) LibPcdSet%sS(%s, (Value))\n' % (SetModeStatusName, DatumSizeLib, PcdTokenName))\r
f51461c8
LG
1176 if PcdItemType == TAB_PCDS_PATCHABLE_IN_MODULE:\r
1177 PcdVariableName = '_gPcd_' + gItemTypeStringDatabase[TAB_PCDS_PATCHABLE_IN_MODULE] + '_' + TokenCName\r
d66670f9
YZ
1178 if DatumType == 'VOID*':\r
1179 ArraySize = int(Pcd.MaxDatumSize, 0)\r
1180 if Pcd.DefaultValue[0] == 'L':\r
1181 ArraySize = ArraySize / 2\r
1182 Array = '[%d]' % ArraySize\r
1183 DatumType = ['UINT8', 'UINT16'][Pcd.DefaultValue[0] == 'L']\r
1184 AutoGenH.Append('extern %s _gPcd_BinaryPatch_%s%s;\n' %(DatumType, TokenCName, Array))\r
1185 else:\r
1186 AutoGenH.Append('extern volatile %s %s%s;\n' % (DatumType, PcdVariableName, Array))\r
f51461c8 1187 AutoGenH.Append('#define %s %s_gPcd_BinaryPatch_%s\n' %(GetModeName, Type, TokenCName))\r
27187d24 1188 if Pcd.DatumType == 'VOID*':\r
e70504cd
LG
1189 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
1190 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
27187d24
LG
1191 else:\r
1192 AutoGenH.Append('#define %s(Value) (%s = (Value))\n' % (SetModeName, PcdVariableName))\r
1193 AutoGenH.Append('#define %s(Value) ((%s = (Value)), RETURN_SUCCESS)\n' % (SetModeStatusName, PcdVariableName))\r
2f5acc3b
BF
1194 \r
1195 PcdDataSize = GetPcdSize(Pcd)\r
1196 AutoGenH.Append('#define %s %s\n' % (PatchPcdSizeTokenName, PcdDataSize))\r
1197 AutoGenH.Append('#define %s %s\n' % (GetModeSizeName,PatchPcdSizeVariableName))\r
1198 AutoGenH.Append('extern UINTN %s; \n' % PatchPcdSizeVariableName)\r
1199 \r
f51461c8
LG
1200 if PcdItemType == TAB_PCDS_FIXED_AT_BUILD or PcdItemType == TAB_PCDS_FEATURE_FLAG:\r
1201 key = ".".join((Pcd.TokenSpaceGuidCName,Pcd.TokenCName))\r
1202 \r
41ab153f 1203 if DatumType == 'VOID*' and Array == '[]':\r
2f5acc3b 1204 DatumType = ['UINT8', 'UINT16'][Pcd.DefaultValue[0] == 'L']\r
f51461c8
LG
1205 AutoGenH.Append('extern const %s _gPcd_FixedAtBuild_%s%s;\n' %(DatumType, TokenCName, Array))\r
1206 AutoGenH.Append('#define %s %s_gPcd_FixedAtBuild_%s\n' %(GetModeName, Type, TokenCName))\r
1207 AutoGenH.Append('//#define %s ASSERT(FALSE) // It is not allowed to set value for a FIXED_AT_BUILD PCD\n' % SetModeName)\r
1208 \r
1209 if PcdItemType == TAB_PCDS_FIXED_AT_BUILD and key in Info.ConstPcd:\r
1210 AutoGenH.Append('#define _PCD_VALUE_%s %s\n' %(TokenCName, Pcd.DefaultValue))\r
1211 \r
2f5acc3b
BF
1212 if PcdItemType == TAB_PCDS_FIXED_AT_BUILD:\r
1213 PcdDataSize = GetPcdSize(Pcd)\r
1214 AutoGenH.Append('#define %s %s\n' % (FixPcdSizeTokenName, PcdDataSize))\r
1215 AutoGenH.Append('#define %s %s\n' % (GetModeSizeName,FixPcdSizeTokenName))\r
f51461c8
LG
1216\r
1217## Create code for library constructor\r
1218#\r
1219# @param Info The ModuleAutoGen object\r
1220# @param AutoGenC The TemplateString object for C code\r
1221# @param AutoGenH The TemplateString object for header file\r
1222#\r
1223def CreateLibraryConstructorCode(Info, AutoGenC, AutoGenH):\r
1224 #\r
1225 # Library Constructors\r
1226 #\r
1227 ConstructorPrototypeString = TemplateString()\r
1228 ConstructorCallingString = TemplateString()\r
1229 if Info.IsLibrary:\r
1230 DependentLibraryList = [Info.Module]\r
1231 else:\r
1232 DependentLibraryList = Info.DependentLibraryList\r
1233 for Lib in DependentLibraryList:\r
1234 if len(Lib.ConstructorList) <= 0:\r
1235 continue\r
1236 Dict = {'Function':Lib.ConstructorList}\r
1237 if Lib.ModuleType in ['BASE', 'SEC']:\r
1238 ConstructorPrototypeString.Append(gLibraryStructorPrototype['BASE'].Replace(Dict))\r
1239 ConstructorCallingString.Append(gLibraryStructorCall['BASE'].Replace(Dict))\r
1240 elif Lib.ModuleType in ['PEI_CORE','PEIM']:\r
1241 ConstructorPrototypeString.Append(gLibraryStructorPrototype['PEI'].Replace(Dict))\r
1242 ConstructorCallingString.Append(gLibraryStructorCall['PEI'].Replace(Dict))\r
1243 elif Lib.ModuleType in ['DXE_CORE','DXE_DRIVER','DXE_SMM_DRIVER','DXE_RUNTIME_DRIVER',\r
1244 'DXE_SAL_DRIVER','UEFI_DRIVER','UEFI_APPLICATION','SMM_CORE']:\r
1245 ConstructorPrototypeString.Append(gLibraryStructorPrototype['DXE'].Replace(Dict))\r
1246 ConstructorCallingString.Append(gLibraryStructorCall['DXE'].Replace(Dict))\r
1247\r
1248 if str(ConstructorPrototypeString) == '':\r
1249 ConstructorPrototypeList = []\r
1250 else:\r
1251 ConstructorPrototypeList = [str(ConstructorPrototypeString)]\r
1252 if str(ConstructorCallingString) == '':\r
1253 ConstructorCallingList = []\r
1254 else:\r
1255 ConstructorCallingList = [str(ConstructorCallingString)]\r
1256\r
1257 Dict = {\r
1258 'Type' : 'Constructor',\r
1259 'FunctionPrototype' : ConstructorPrototypeList,\r
1260 'FunctionCall' : ConstructorCallingList\r
1261 }\r
1262 if Info.IsLibrary:\r
1263 AutoGenH.Append("${BEGIN}${FunctionPrototype}${END}", Dict)\r
1264 else:\r
1265 if Info.ModuleType in ['BASE', 'SEC']:\r
1266 AutoGenC.Append(gLibraryString['BASE'].Replace(Dict))\r
1267 elif Info.ModuleType in ['PEI_CORE','PEIM']:\r
1268 AutoGenC.Append(gLibraryString['PEI'].Replace(Dict))\r
1269 elif Info.ModuleType in ['DXE_CORE','DXE_DRIVER','DXE_SMM_DRIVER','DXE_RUNTIME_DRIVER',\r
1270 'DXE_SAL_DRIVER','UEFI_DRIVER','UEFI_APPLICATION','SMM_CORE']:\r
1271 AutoGenC.Append(gLibraryString['DXE'].Replace(Dict))\r
1272\r
1273## Create code for library destructor\r
1274#\r
1275# @param Info The ModuleAutoGen object\r
1276# @param AutoGenC The TemplateString object for C code\r
1277# @param AutoGenH The TemplateString object for header file\r
1278#\r
1279def CreateLibraryDestructorCode(Info, AutoGenC, AutoGenH):\r
1280 #\r
1281 # Library Destructors\r
1282 #\r
1283 DestructorPrototypeString = TemplateString()\r
1284 DestructorCallingString = TemplateString()\r
1285 if Info.IsLibrary:\r
1286 DependentLibraryList = [Info.Module]\r
1287 else:\r
1288 DependentLibraryList = Info.DependentLibraryList\r
1289 for Index in range(len(DependentLibraryList)-1, -1, -1):\r
1290 Lib = DependentLibraryList[Index]\r
1291 if len(Lib.DestructorList) <= 0:\r
1292 continue\r
1293 Dict = {'Function':Lib.DestructorList}\r
1294 if Lib.ModuleType in ['BASE', 'SEC']:\r
1295 DestructorPrototypeString.Append(gLibraryStructorPrototype['BASE'].Replace(Dict))\r
1296 DestructorCallingString.Append(gLibraryStructorCall['BASE'].Replace(Dict))\r
1297 elif Lib.ModuleType in ['PEI_CORE','PEIM']:\r
1298 DestructorPrototypeString.Append(gLibraryStructorPrototype['PEI'].Replace(Dict))\r
1299 DestructorCallingString.Append(gLibraryStructorCall['PEI'].Replace(Dict))\r
1300 elif Lib.ModuleType in ['DXE_CORE','DXE_DRIVER','DXE_SMM_DRIVER','DXE_RUNTIME_DRIVER',\r
1301 'DXE_SAL_DRIVER','UEFI_DRIVER','UEFI_APPLICATION', 'SMM_CORE']:\r
1302 DestructorPrototypeString.Append(gLibraryStructorPrototype['DXE'].Replace(Dict))\r
1303 DestructorCallingString.Append(gLibraryStructorCall['DXE'].Replace(Dict))\r
1304\r
1305 if str(DestructorPrototypeString) == '':\r
1306 DestructorPrototypeList = []\r
1307 else:\r
1308 DestructorPrototypeList = [str(DestructorPrototypeString)]\r
1309 if str(DestructorCallingString) == '':\r
1310 DestructorCallingList = []\r
1311 else:\r
1312 DestructorCallingList = [str(DestructorCallingString)]\r
1313\r
1314 Dict = {\r
1315 'Type' : 'Destructor',\r
1316 'FunctionPrototype' : DestructorPrototypeList,\r
1317 'FunctionCall' : DestructorCallingList\r
1318 }\r
1319 if Info.IsLibrary:\r
1320 AutoGenH.Append("${BEGIN}${FunctionPrototype}${END}", Dict)\r
1321 else:\r
1322 if Info.ModuleType in ['BASE', 'SEC']:\r
1323 AutoGenC.Append(gLibraryString['BASE'].Replace(Dict))\r
1324 elif Info.ModuleType in ['PEI_CORE','PEIM']:\r
1325 AutoGenC.Append(gLibraryString['PEI'].Replace(Dict))\r
1326 elif Info.ModuleType in ['DXE_CORE','DXE_DRIVER','DXE_SMM_DRIVER','DXE_RUNTIME_DRIVER',\r
1327 'DXE_SAL_DRIVER','UEFI_DRIVER','UEFI_APPLICATION','SMM_CORE']:\r
1328 AutoGenC.Append(gLibraryString['DXE'].Replace(Dict))\r
1329\r
1330\r
1331## Create code for ModuleEntryPoint\r
1332#\r
1333# @param Info The ModuleAutoGen object\r
1334# @param AutoGenC The TemplateString object for C code\r
1335# @param AutoGenH The TemplateString object for header file\r
1336#\r
1337def CreateModuleEntryPointCode(Info, AutoGenC, AutoGenH):\r
1338 if Info.IsLibrary or Info.ModuleType in ['USER_DEFINED', 'SEC']:\r
1339 return\r
1340 #\r
1341 # Module Entry Points\r
1342 #\r
1343 NumEntryPoints = len(Info.Module.ModuleEntryPointList)\r
1344 if 'PI_SPECIFICATION_VERSION' in Info.Module.Specification:\r
1345 PiSpecVersion = Info.Module.Specification['PI_SPECIFICATION_VERSION']\r
1346 else:\r
1347 PiSpecVersion = '0x00000000'\r
1348 if 'UEFI_SPECIFICATION_VERSION' in Info.Module.Specification:\r
1349 UefiSpecVersion = Info.Module.Specification['UEFI_SPECIFICATION_VERSION']\r
1350 else:\r
1351 UefiSpecVersion = '0x00000000'\r
1352 Dict = {\r
1353 'Function' : Info.Module.ModuleEntryPointList,\r
1354 'PiSpecVersion' : PiSpecVersion + 'U',\r
1355 'UefiSpecVersion': UefiSpecVersion + 'U'\r
1356 }\r
1357\r
1358 if Info.ModuleType in ['PEI_CORE', 'DXE_CORE', 'SMM_CORE']:\r
1359 if Info.SourceFileList <> None and Info.SourceFileList <> []:\r
1360 if NumEntryPoints != 1:\r
1361 EdkLogger.error(\r
1362 "build",\r
1363 AUTOGEN_ERROR,\r
1364 '%s must have exactly one entry point' % Info.ModuleType,\r
1365 File=str(Info),\r
1366 ExtraData= ", ".join(Info.Module.ModuleEntryPointList)\r
1367 )\r
1368 if Info.ModuleType == 'PEI_CORE':\r
1369 AutoGenC.Append(gPeiCoreEntryPointString.Replace(Dict))\r
1370 AutoGenH.Append(gPeiCoreEntryPointPrototype.Replace(Dict))\r
1371 elif Info.ModuleType == 'DXE_CORE':\r
1372 AutoGenC.Append(gDxeCoreEntryPointString.Replace(Dict))\r
1373 AutoGenH.Append(gDxeCoreEntryPointPrototype.Replace(Dict))\r
1374 elif Info.ModuleType == 'SMM_CORE':\r
1375 AutoGenC.Append(gSmmCoreEntryPointString.Replace(Dict))\r
1376 AutoGenH.Append(gSmmCoreEntryPointPrototype.Replace(Dict))\r
1377 elif Info.ModuleType == 'PEIM':\r
1378 if NumEntryPoints < 2:\r
1379 AutoGenC.Append(gPeimEntryPointString[NumEntryPoints].Replace(Dict))\r
1380 else:\r
1381 AutoGenC.Append(gPeimEntryPointString[2].Replace(Dict))\r
1382 AutoGenH.Append(gPeimEntryPointPrototype.Replace(Dict))\r
1383 elif Info.ModuleType in ['DXE_RUNTIME_DRIVER','DXE_DRIVER','DXE_SAL_DRIVER','UEFI_DRIVER']:\r
1384 if NumEntryPoints < 2:\r
1385 AutoGenC.Append(gUefiDriverEntryPointString[NumEntryPoints].Replace(Dict))\r
1386 else:\r
1387 AutoGenC.Append(gUefiDriverEntryPointString[2].Replace(Dict))\r
1388 AutoGenH.Append(gUefiDriverEntryPointPrototype.Replace(Dict))\r
1389 elif Info.ModuleType == 'DXE_SMM_DRIVER':\r
1390 if NumEntryPoints == 0:\r
1391 AutoGenC.Append(gDxeSmmEntryPointString[0].Replace(Dict))\r
1392 else:\r
1393 AutoGenC.Append(gDxeSmmEntryPointString[1].Replace(Dict))\r
1394 AutoGenH.Append(gDxeSmmEntryPointPrototype.Replace(Dict)) \r
1395 elif Info.ModuleType == 'UEFI_APPLICATION':\r
1396 if NumEntryPoints < 2:\r
1397 AutoGenC.Append(gUefiApplicationEntryPointString[NumEntryPoints].Replace(Dict))\r
1398 else:\r
1399 AutoGenC.Append(gUefiApplicationEntryPointString[2].Replace(Dict))\r
1400 AutoGenH.Append(gUefiApplicationEntryPointPrototype.Replace(Dict))\r
1401\r
1402## Create code for ModuleUnloadImage\r
1403#\r
1404# @param Info The ModuleAutoGen object\r
1405# @param AutoGenC The TemplateString object for C code\r
1406# @param AutoGenH The TemplateString object for header file\r
1407#\r
1408def CreateModuleUnloadImageCode(Info, AutoGenC, AutoGenH):\r
1409 if Info.IsLibrary or Info.ModuleType in ['USER_DEFINED', 'SEC']:\r
1410 return\r
1411 #\r
1412 # Unload Image Handlers\r
1413 #\r
1414 NumUnloadImage = len(Info.Module.ModuleUnloadImageList)\r
1415 Dict = {'Count':str(NumUnloadImage) + 'U', 'Function':Info.Module.ModuleUnloadImageList}\r
1416 if NumUnloadImage < 2:\r
1417 AutoGenC.Append(gUefiUnloadImageString[NumUnloadImage].Replace(Dict))\r
1418 else:\r
1419 AutoGenC.Append(gUefiUnloadImageString[2].Replace(Dict))\r
1420 AutoGenH.Append(gUefiUnloadImagePrototype.Replace(Dict))\r
1421\r
1422## Create code for GUID\r
1423#\r
1424# @param Info The ModuleAutoGen object\r
1425# @param AutoGenC The TemplateString object for C code\r
1426# @param AutoGenH The TemplateString object for header file\r
1427#\r
1428def CreateGuidDefinitionCode(Info, AutoGenC, AutoGenH):\r
f51461c8
LG
1429 if Info.ModuleType in ["USER_DEFINED", "BASE"]:\r
1430 GuidType = "GUID"\r
1431 else:\r
1432 GuidType = "EFI_GUID"\r
1433\r
1434 if Info.GuidList:\r
7beed8a3
YZ
1435 if not Info.IsLibrary:\r
1436 AutoGenC.Append("\n// Guids\n")\r
8262037f 1437 AutoGenH.Append("\n// Guids\n")\r
f51461c8
LG
1438 #\r
1439 # GUIDs\r
1440 #\r
1441 for Key in Info.GuidList:\r
7beed8a3
YZ
1442 if not Info.IsLibrary:\r
1443 AutoGenC.Append('GLOBAL_REMOVE_IF_UNREFERENCED %s %s = %s;\n' % (GuidType, Key, Info.GuidList[Key]))\r
8262037f 1444 AutoGenH.Append('extern %s %s;\n' % (GuidType, Key))\r
f51461c8
LG
1445\r
1446## Create code for protocol\r
1447#\r
1448# @param Info The ModuleAutoGen object\r
1449# @param AutoGenC The TemplateString object for C code\r
1450# @param AutoGenH The TemplateString object for header file\r
1451#\r
1452def CreateProtocolDefinitionCode(Info, AutoGenC, AutoGenH):\r
f51461c8
LG
1453 if Info.ModuleType in ["USER_DEFINED", "BASE"]:\r
1454 GuidType = "GUID"\r
1455 else:\r
1456 GuidType = "EFI_GUID"\r
1457\r
1458 if Info.ProtocolList:\r
7beed8a3
YZ
1459 if not Info.IsLibrary:\r
1460 AutoGenC.Append("\n// Protocols\n")\r
8262037f 1461 AutoGenH.Append("\n// Protocols\n")\r
f51461c8
LG
1462 #\r
1463 # Protocol GUIDs\r
1464 #\r
1465 for Key in Info.ProtocolList:\r
7beed8a3
YZ
1466 if not Info.IsLibrary:\r
1467 AutoGenC.Append('GLOBAL_REMOVE_IF_UNREFERENCED %s %s = %s;\n' % (GuidType, Key, Info.ProtocolList[Key]))\r
8262037f 1468 AutoGenH.Append('extern %s %s;\n' % (GuidType, Key))\r
f51461c8
LG
1469\r
1470## Create code for PPI\r
1471#\r
1472# @param Info The ModuleAutoGen object\r
1473# @param AutoGenC The TemplateString object for C code\r
1474# @param AutoGenH The TemplateString object for header file\r
1475#\r
1476def CreatePpiDefinitionCode(Info, AutoGenC, AutoGenH):\r
f51461c8
LG
1477 if Info.ModuleType in ["USER_DEFINED", "BASE"]:\r
1478 GuidType = "GUID"\r
1479 else:\r
1480 GuidType = "EFI_GUID"\r
1481\r
1482 if Info.PpiList:\r
7beed8a3
YZ
1483 if not Info.IsLibrary:\r
1484 AutoGenC.Append("\n// PPIs\n")\r
8262037f 1485 AutoGenH.Append("\n// PPIs\n")\r
f51461c8
LG
1486 #\r
1487 # PPI GUIDs\r
1488 #\r
1489 for Key in Info.PpiList:\r
7beed8a3
YZ
1490 if not Info.IsLibrary:\r
1491 AutoGenC.Append('GLOBAL_REMOVE_IF_UNREFERENCED %s %s = %s;\n' % (GuidType, Key, Info.PpiList[Key]))\r
8262037f 1492 AutoGenH.Append('extern %s %s;\n' % (GuidType, Key))\r
f51461c8
LG
1493\r
1494## Create code for PCD\r
1495#\r
1496# @param Info The ModuleAutoGen object\r
1497# @param AutoGenC The TemplateString object for C code\r
1498# @param AutoGenH The TemplateString object for header file\r
1499#\r
1500def CreatePcdCode(Info, AutoGenC, AutoGenH):\r
1501\r
1502 # Collect Token Space GUIDs used by DynamicEc PCDs\r
1503 TokenSpaceList = []\r
1504 for Pcd in Info.ModulePcdList:\r
1505 if Pcd.Type in gDynamicExPcd and Pcd.TokenSpaceGuidCName not in TokenSpaceList:\r
1506 TokenSpaceList += [Pcd.TokenSpaceGuidCName]\r
1507 \r
1508 # Add extern declarations to AutoGen.h if one or more Token Space GUIDs were found\r
1509 if TokenSpaceList <> []: \r
1510 AutoGenH.Append("\n// Definition of PCD Token Space GUIDs used in this module\n\n")\r
1511 if Info.ModuleType in ["USER_DEFINED", "BASE"]:\r
1512 GuidType = "GUID"\r
1513 else:\r
1514 GuidType = "EFI_GUID" \r
1515 for Item in TokenSpaceList:\r
1516 AutoGenH.Append('extern %s %s;\n' % (GuidType, Item))\r
1517\r
1518 if Info.IsLibrary:\r
1519 if Info.ModulePcdList:\r
1520 AutoGenH.Append("\n// PCD definitions\n")\r
1521 for Pcd in Info.ModulePcdList:\r
1522 CreateLibraryPcdCode(Info, AutoGenC, AutoGenH, Pcd)\r
1523 DynExPcdTokenNumberMapping (Info, AutoGenH)\r
1524 else:\r
1525 if Info.ModulePcdList:\r
1526 AutoGenH.Append("\n// Definition of PCDs used in this module\n")\r
1527 AutoGenC.Append("\n// Definition of PCDs used in this module\n")\r
1528 for Pcd in Info.ModulePcdList:\r
1529 CreateModulePcdCode(Info, AutoGenC, AutoGenH, Pcd)\r
1530 DynExPcdTokenNumberMapping (Info, AutoGenH)\r
1531 if Info.LibraryPcdList:\r
1532 AutoGenH.Append("\n// Definition of PCDs used in libraries is in AutoGen.c\n")\r
1533 AutoGenC.Append("\n// Definition of PCDs used in libraries\n")\r
1534 for Pcd in Info.LibraryPcdList:\r
1535 CreateModulePcdCode(Info, AutoGenC, AutoGenC, Pcd)\r
1536 CreatePcdDatabaseCode(Info, AutoGenC, AutoGenH)\r
1537\r
1538## Create code for unicode string definition\r
1539#\r
1540# @param Info The ModuleAutoGen object\r
1541# @param AutoGenC The TemplateString object for C code\r
1542# @param AutoGenH The TemplateString object for header file\r
1543# @param UniGenCFlag UniString is generated into AutoGen C file when it is set to True\r
1544# @param UniGenBinBuffer Buffer to store uni string package data\r
1545#\r
1546def CreateUnicodeStringCode(Info, AutoGenC, AutoGenH, UniGenCFlag, UniGenBinBuffer):\r
1547 WorkingDir = os.getcwd()\r
1548 os.chdir(Info.WorkspaceDir)\r
1549\r
1550 IncList = [Info.MetaFile.Dir]\r
1551 # Get all files under [Sources] section in inf file for EDK-II module\r
1552 EDK2Module = True\r
1553 SrcList = [F for F in Info.SourceFileList]\r
1554 if Info.AutoGenVersion < 0x00010005:\r
1555 EDK2Module = False\r
1556 # Get all files under the module directory for EDK-I module\r
1557 Cwd = os.getcwd()\r
1558 os.chdir(Info.MetaFile.Dir)\r
1559 for Root, Dirs, Files in os.walk("."):\r
1560 if 'CVS' in Dirs:\r
1561 Dirs.remove('CVS')\r
1562 if '.svn' in Dirs:\r
1563 Dirs.remove('.svn')\r
1564 for File in Files:\r
1565 File = PathClass(os.path.join(Root, File), Info.MetaFile.Dir)\r
1566 if File in SrcList:\r
1567 continue\r
1568 SrcList.append(File)\r
1569 os.chdir(Cwd)\r
1570\r
1571 if 'BUILD' in Info.BuildOption and Info.BuildOption['BUILD']['FLAGS'].find('-c') > -1:\r
1572 CompatibleMode = True\r
1573 else:\r
1574 CompatibleMode = False\r
1575\r
1576 #\r
1577 # -s is a temporary option dedicated for building .UNI files with ISO 639-2 language codes of EDK Shell in EDK2\r
1578 #\r
1579 if 'BUILD' in Info.BuildOption and Info.BuildOption['BUILD']['FLAGS'].find('-s') > -1:\r
1580 if CompatibleMode:\r
1581 EdkLogger.error("build", AUTOGEN_ERROR,\r
1582 "-c and -s build options should be used exclusively",\r
1583 ExtraData="[%s]" % str(Info))\r
1584 ShellMode = True\r
1585 else:\r
1586 ShellMode = False\r
1587\r
1588 #RFC4646 is only for EDKII modules and ISO639-2 for EDK modules\r
1589 if EDK2Module:\r
1590 FilterInfo = [EDK2Module] + [Info.PlatformInfo.Platform.RFCLanguages]\r
1591 else:\r
1592 FilterInfo = [EDK2Module] + [Info.PlatformInfo.Platform.ISOLanguages]\r
1593 Header, Code = GetStringFiles(Info.UnicodeFileList, SrcList, IncList, Info.IncludePathList, ['.uni', '.inf'], Info.Name, CompatibleMode, ShellMode, UniGenCFlag, UniGenBinBuffer, FilterInfo)\r
1594 if CompatibleMode or UniGenCFlag:\r
1595 AutoGenC.Append("\n//\n//Unicode String Pack Definition\n//\n")\r
1596 AutoGenC.Append(Code)\r
1597 AutoGenC.Append("\n")\r
1598 AutoGenH.Append("\n//\n//Unicode String ID\n//\n")\r
1599 AutoGenH.Append(Header)\r
1600 if CompatibleMode or UniGenCFlag:\r
1601 AutoGenH.Append("\n#define STRING_ARRAY_NAME %sStrings\n" % Info.Name)\r
1602 os.chdir(WorkingDir)\r
1603\r
1604## Create common code\r
1605#\r
1606# @param Info The ModuleAutoGen object\r
1607# @param AutoGenC The TemplateString object for C code\r
1608# @param AutoGenH The TemplateString object for header file\r
1609#\r
1610def CreateHeaderCode(Info, AutoGenC, AutoGenH):\r
1611 # file header\r
1612 AutoGenH.Append(gAutoGenHeaderString.Replace({'FileName':'AutoGen.h'}))\r
1613 # header file Prologue\r
1614 AutoGenH.Append(gAutoGenHPrologueString.Replace({'File':'AUTOGENH','Guid':Info.Guid.replace('-','_')}))\r
1615 AutoGenH.Append(gAutoGenHCppPrologueString)\r
1616 if Info.AutoGenVersion >= 0x00010005:\r
1617 # header files includes\r
1618 AutoGenH.Append("#include <%s>\n" % gBasicHeaderFile)\r
1619 if Info.ModuleType in gModuleTypeHeaderFile \\r
1620 and gModuleTypeHeaderFile[Info.ModuleType][0] != gBasicHeaderFile:\r
1621 AutoGenH.Append("#include <%s>\n" % gModuleTypeHeaderFile[Info.ModuleType][0])\r
1622 #\r
1623 # if either PcdLib in [LibraryClasses] sections or there exist Pcd section, add PcdLib.h \r
1624 # As if modules only uses FixedPcd, then PcdLib is not needed in [LibraryClasses] section.\r
1625 #\r
1626 if 'PcdLib' in Info.Module.LibraryClasses or Info.Module.Pcds:\r
1627 AutoGenH.Append("#include <Library/PcdLib.h>\n")\r
1628\r
1629 AutoGenH.Append('\nextern GUID gEfiCallerIdGuid;')\r
1630 AutoGenH.Append('\nextern CHAR8 *gEfiCallerBaseName;\n\n')\r
1631\r
1632 if Info.IsLibrary:\r
1633 return\r
1634\r
1635 AutoGenH.Append("#define EFI_CALLER_ID_GUID \\\n %s\n" % GuidStringToGuidStructureString(Info.Guid))\r
1636\r
1637 if Info.IsLibrary:\r
1638 return\r
1639 # C file header\r
1640 AutoGenC.Append(gAutoGenHeaderString.Replace({'FileName':'AutoGen.c'}))\r
1641 if Info.AutoGenVersion >= 0x00010005:\r
1642 # C file header files includes\r
1643 if Info.ModuleType in gModuleTypeHeaderFile:\r
1644 for Inc in gModuleTypeHeaderFile[Info.ModuleType]:\r
1645 AutoGenC.Append("#include <%s>\n" % Inc)\r
1646 else:\r
1647 AutoGenC.Append("#include <%s>\n" % gBasicHeaderFile)\r
1648\r
1649 #\r
1650 # Publish the CallerId Guid\r
1651 #\r
1652 AutoGenC.Append('\nGLOBAL_REMOVE_IF_UNREFERENCED GUID gEfiCallerIdGuid = %s;\n' % GuidStringToGuidStructureString(Info.Guid))\r
1653 AutoGenC.Append('\nGLOBAL_REMOVE_IF_UNREFERENCED CHAR8 *gEfiCallerBaseName = "%s";\n' % Info.Name)\r
1654\r
1655## Create common code for header file\r
1656#\r
1657# @param Info The ModuleAutoGen object\r
1658# @param AutoGenC The TemplateString object for C code\r
1659# @param AutoGenH The TemplateString object for header file\r
1660#\r
1661def CreateFooterCode(Info, AutoGenC, AutoGenH):\r
1662 AutoGenH.Append(gAutoGenHEpilogueString)\r
1663\r
1664## Create code for a module\r
1665#\r
1666# @param Info The ModuleAutoGen object\r
1667# @param AutoGenC The TemplateString object for C code\r
1668# @param AutoGenH The TemplateString object for header file\r
1669# @param UniGenCFlag UniString is generated into AutoGen C file when it is set to True\r
1670# @param UniGenBinBuffer Buffer to store uni string package data\r
1671#\r
1672def CreateCode(Info, AutoGenC, AutoGenH, StringH, UniGenCFlag, UniGenBinBuffer):\r
1673 CreateHeaderCode(Info, AutoGenC, AutoGenH)\r
1674\r
1675 if Info.AutoGenVersion >= 0x00010005:\r
1676 CreateGuidDefinitionCode(Info, AutoGenC, AutoGenH)\r
1677 CreateProtocolDefinitionCode(Info, AutoGenC, AutoGenH)\r
1678 CreatePpiDefinitionCode(Info, AutoGenC, AutoGenH)\r
1679 CreatePcdCode(Info, AutoGenC, AutoGenH)\r
1680 CreateLibraryConstructorCode(Info, AutoGenC, AutoGenH)\r
1681 CreateLibraryDestructorCode(Info, AutoGenC, AutoGenH)\r
1682 CreateModuleEntryPointCode(Info, AutoGenC, AutoGenH)\r
1683 CreateModuleUnloadImageCode(Info, AutoGenC, AutoGenH)\r
1684\r
1685 if Info.UnicodeFileList:\r
1686 FileName = "%sStrDefs.h" % Info.Name\r
1687 StringH.Append(gAutoGenHeaderString.Replace({'FileName':FileName}))\r
1688 StringH.Append(gAutoGenHPrologueString.Replace({'File':'STRDEFS', 'Guid':Info.Guid.replace('-','_')}))\r
1689 CreateUnicodeStringCode(Info, AutoGenC, StringH, UniGenCFlag, UniGenBinBuffer)\r
8200fcfe
YL
1690\r
1691 GuidMacros = []\r
1692 for Guid in Info.Module.Guids:\r
1693 if Guid in Info.Module.GetGuidsUsedByPcd():\r
1694 continue\r
1695 GuidMacros.append('#define %s %s' % (Guid, Info.Module.Guids[Guid]))\r
1696 for Guid, Value in Info.Module.Protocols.items() + Info.Module.Ppis.items():\r
1697 GuidMacros.append('#define %s %s' % (Guid, Value))\r
1698 if GuidMacros:\r
1699 StringH.Append('\n#ifdef VFRCOMPILE\n%s\n#endif\n' % '\n'.join(GuidMacros))\r
1700\r
f51461c8
LG
1701 StringH.Append("\n#endif\n")\r
1702 AutoGenH.Append('#include "%s"\n' % FileName)\r
1703\r
1704 CreateFooterCode(Info, AutoGenC, AutoGenH)\r
1705\r
1706 # no generation of AutoGen.c for Edk modules without unicode file\r
1707 if Info.AutoGenVersion < 0x00010005 and len(Info.UnicodeFileList) == 0:\r
1708 AutoGenC.String = ''\r
1709\r
1710## Create the code file\r
1711#\r
1712# @param FilePath The path of code file\r
1713# @param Content The content of code file\r
1714# @param IsBinaryFile The flag indicating if the file is binary file or not\r
1715#\r
1716# @retval True If file content is changed or file doesn't exist\r
1717# @retval False If the file exists and the content is not changed\r
1718#\r
1719def Generate(FilePath, Content, IsBinaryFile):\r
1720 return SaveFileOnChange(FilePath, Content, IsBinaryFile)\r
1721\r