MdePkg UefiHii: Add IMAGE_TOKEN macro to access image resource in C and VFR
[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
2a29017e
YZ
696 RealTokenCName = Pcd.TokenCName\r
697 for PcdItem in GlobalData.MixedPcd:\r
698 if (Pcd.TokenCName, Pcd.TokenSpaceGuidCName) in GlobalData.MixedPcd[PcdItem]:\r
699 RealTokenCName = PcdItem[0]\r
700 break\r
f51461c8
LG
701 if Pcd.TokenCName == TokenCName:\r
702 Index = Index + 1\r
703 if Index == 1:\r
2a29017e 704 AutoGenH.Append('\n#define __PCD_%s_ADDR_CMP(GuidPtr) (' % (RealTokenCName))\r
f51461c8 705 AutoGenH.Append('\\\n (GuidPtr == &%s) ? _PCD_TOKEN_%s_%s:' \r
2a29017e 706 % (Pcd.TokenSpaceGuidCName, Pcd.TokenSpaceGuidCName, RealTokenCName))\r
f51461c8
LG
707 else:\r
708 AutoGenH.Append('\\\n (GuidPtr == &%s) ? _PCD_TOKEN_%s_%s:' \r
2a29017e 709 % (Pcd.TokenSpaceGuidCName, Pcd.TokenSpaceGuidCName, RealTokenCName))\r
f51461c8
LG
710 if Index == Count:\r
711 AutoGenH.Append('0 \\\n )\n')\r
712 TokenCNameList.append(TokenCName)\r
713 \r
714 TokenCNameList = []\r
715 for TokenCName in ExTokenCNameList:\r
716 if TokenCName in TokenCNameList:\r
717 continue\r
718 Index = 0\r
719 Count = ExTokenCNameList.count(TokenCName)\r
720 for Pcd in PcdExList:\r
2a29017e
YZ
721 RealTokenCName = Pcd.TokenCName\r
722 for PcdItem in GlobalData.MixedPcd:\r
723 if (Pcd.TokenCName, Pcd.TokenSpaceGuidCName) in GlobalData.MixedPcd[PcdItem]:\r
724 RealTokenCName = PcdItem[0]\r
725 break\r
f51461c8
LG
726 if Pcd.Type in gDynamicExPcd and Pcd.TokenCName == TokenCName:\r
727 Index = Index + 1\r
728 if Index == 1:\r
2a29017e 729 AutoGenH.Append('\n#define __PCD_%s_VAL_CMP(GuidPtr) (' % (RealTokenCName))\r
9023704f 730 AutoGenH.Append('\\\n (GuidPtr == NULL) ? 0:')\r
f51461c8 731 AutoGenH.Append('\\\n COMPAREGUID (GuidPtr, &%s) ? _PCD_TOKEN_%s_%s:' \r
2a29017e 732 % (Pcd.TokenSpaceGuidCName, Pcd.TokenSpaceGuidCName, RealTokenCName))\r
f51461c8
LG
733 else:\r
734 AutoGenH.Append('\\\n COMPAREGUID (GuidPtr, &%s) ? _PCD_TOKEN_%s_%s:' \r
2a29017e 735 % (Pcd.TokenSpaceGuidCName, Pcd.TokenSpaceGuidCName, RealTokenCName))\r
f51461c8
LG
736 if Index == Count:\r
737 AutoGenH.Append('0 \\\n )\n')\r
738 # Autogen internal worker macro to compare GUIDs. Guid1 is a pointer to a GUID. \r
739 # Guid2 is a C name for a GUID. Compare pointers first because optimizing compiler\r
740 # can do this at build time on CONST GUID pointers and optimize away call to COMPAREGUID().\r
741 # COMPAREGUID() will only be used if the Guid passed in is local to the module.\r
742 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 743 % (RealTokenCName, RealTokenCName, RealTokenCName, RealTokenCName))\r
f51461c8
LG
744 TokenCNameList.append(TokenCName)\r
745\r
2f5acc3b
BF
746def GetPcdSize(Pcd):\r
747 if Pcd.DatumType == 'VOID*':\r
748 Value = Pcd.DefaultValue\r
749 if Value in [None, '']:\r
750 return 1\r
751 elif Value[0] == 'L':\r
752 return (len(Value) - 2) * 2\r
753 elif Value[0] == '{':\r
754 return len(Value.split(','))\r
755 else:\r
756 return len(Value) - 1\r
757 if Pcd.DatumType == 'UINT64':\r
758 return 8\r
759 if Pcd.DatumType == 'UINT32':\r
760 return 4\r
761 if Pcd.DatumType == 'UINT16':\r
762 return 2\r
763 if Pcd.DatumType == 'UINT8':\r
764 return 1\r
765 if Pcd.DatumType == 'BOOLEAN':\r
766 return 1\r
767\r
768\r
f51461c8
LG
769## Create code for module PCDs\r
770#\r
771# @param Info The ModuleAutoGen object\r
772# @param AutoGenC The TemplateString object for C code\r
773# @param AutoGenH The TemplateString object for header file\r
774# @param Pcd The PCD object\r
775#\r
776def CreateModulePcdCode(Info, AutoGenC, AutoGenH, Pcd):\r
777 TokenSpaceGuidValue = Pcd.TokenSpaceGuidValue #Info.GuidList[Pcd.TokenSpaceGuidCName]\r
778 PcdTokenNumber = Info.PlatformInfo.PcdTokenNumber\r
2a29017e
YZ
779 #\r
780 # Write PCDs\r
781 #\r
782 TokenCName = Pcd.TokenCName\r
783 for PcdItem in GlobalData.MixedPcd:\r
784 if (Pcd.TokenCName, Pcd.TokenSpaceGuidCName) in GlobalData.MixedPcd[PcdItem]:\r
785 TokenCName = PcdItem[0]\r
786 break\r
787 PcdTokenName = '_PCD_TOKEN_' + TokenCName\r
788 PatchPcdSizeTokenName = '_PCD_PATCHABLE_' + TokenCName +'_SIZE'\r
789 PatchPcdSizeVariableName = '_gPcd_BinaryPatch_Size_' + TokenCName\r
790 FixPcdSizeTokenName = '_PCD_SIZE_' + TokenCName\r
763e8edf
YZ
791\r
792 if GlobalData.BuildOptionPcd:\r
793 for PcdItem in GlobalData.BuildOptionPcd:\r
2a29017e 794 if (Pcd.TokenSpaceGuidCName, TokenCName) == (PcdItem[0], PcdItem[1]):\r
763e8edf
YZ
795 Pcd.DefaultValue = PcdItem[2]\r
796 break\r
2f5acc3b 797 \r
f51461c8
LG
798 if Pcd.Type in gDynamicExPcd:\r
799 TokenNumber = int(Pcd.TokenValue, 0)\r
800 # Add TokenSpaceGuidValue value to PcdTokenName to discriminate the DynamicEx PCDs with \r
801 # different Guids but same TokenCName\r
2a29017e 802 PcdExTokenName = '_PCD_TOKEN_' + Pcd.TokenSpaceGuidCName + '_' + TokenCName\r
f51461c8
LG
803 AutoGenH.Append('\n#define %s %dU\n' % (PcdExTokenName, TokenNumber))\r
804 else:\r
805 if (Pcd.TokenCName, Pcd.TokenSpaceGuidCName) not in PcdTokenNumber:\r
806 # If one of the Source built modules listed in the DSC is not listed in FDF modules, \r
807 # and the INF lists a PCD can only use the PcdsDynamic access method (it is only \r
808 # listed in the DEC file that declares the PCD as PcdsDynamic), then build tool will \r
809 # report warning message notify the PI that they are attempting to build a module \r
810 # that must be included in a flash image in order to be functional. These Dynamic PCD \r
811 # will not be added into the Database unless it is used by other modules that are \r
812 # included in the FDF file. \r
813 # In this case, just assign an invalid token number to make it pass build.\r
814 if Pcd.Type in PCD_DYNAMIC_TYPE_LIST:\r
815 TokenNumber = 0\r
816 else:\r
817 EdkLogger.error("build", AUTOGEN_ERROR,\r
2a29017e 818 "No generated token number for %s.%s\n" % (Pcd.TokenSpaceGuidCName, TokenCName),\r
f51461c8
LG
819 ExtraData="[%s]" % str(Info))\r
820 else:\r
821 TokenNumber = PcdTokenNumber[Pcd.TokenCName, Pcd.TokenSpaceGuidCName]\r
822 AutoGenH.Append('\n#define %s %dU\n' % (PcdTokenName, TokenNumber))\r
823\r
2a29017e 824 EdkLogger.debug(EdkLogger.DEBUG_3, "Creating code for " + TokenCName + "." + Pcd.TokenSpaceGuidCName)\r
f51461c8
LG
825 if Pcd.Type not in gItemTypeStringDatabase:\r
826 EdkLogger.error("build", AUTOGEN_ERROR,\r
2a29017e 827 "Unknown PCD type [%s] of PCD %s.%s" % (Pcd.Type, Pcd.TokenSpaceGuidCName, TokenCName),\r
f51461c8
LG
828 ExtraData="[%s]" % str(Info))\r
829 if Pcd.DatumType not in gDatumSizeStringDatabase:\r
830 EdkLogger.error("build", AUTOGEN_ERROR,\r
2a29017e 831 "Unknown datum type [%s] of PCD %s.%s" % (Pcd.DatumType, Pcd.TokenSpaceGuidCName, TokenCName),\r
f51461c8
LG
832 ExtraData="[%s]" % str(Info))\r
833\r
834 DatumSize = gDatumSizeStringDatabase[Pcd.DatumType]\r
835 DatumSizeLib = gDatumSizeStringDatabaseLib[Pcd.DatumType]\r
2a29017e
YZ
836 GetModeName = '_PCD_GET_MODE_' + gDatumSizeStringDatabaseH[Pcd.DatumType] + '_' + TokenCName\r
837 SetModeName = '_PCD_SET_MODE_' + gDatumSizeStringDatabaseH[Pcd.DatumType] + '_' + TokenCName\r
838 SetModeStatusName = '_PCD_SET_MODE_' + gDatumSizeStringDatabaseH[Pcd.DatumType] + '_S_' + TokenCName\r
839 GetModeSizeName = '_PCD_GET_MODE_SIZE' + '_' + TokenCName\r
2f5acc3b 840 \r
f51461c8
LG
841 PcdExCNameList = []\r
842 if Pcd.Type in gDynamicExPcd:\r
843 if Info.IsLibrary:\r
844 PcdList = Info.LibraryPcdList\r
845 else:\r
846 PcdList = Info.ModulePcdList\r
847 for PcdModule in PcdList:\r
848 if PcdModule.Type in gDynamicExPcd:\r
849 PcdExCNameList.append(PcdModule.TokenCName)\r
850 # Be compatible with the current code which using PcdToken and PcdGet/Set for DynamicEx Pcd.\r
851 # If only PcdToken and PcdGet/Set used in all Pcds with different CName, it should succeed to build.\r
852 # If PcdToken and PcdGet/Set used in the Pcds with different Guids but same CName, it should failed to build.\r
853 if PcdExCNameList.count(Pcd.TokenCName) > 1:\r
854 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
855 AutoGenH.Append('// #define %s %s\n' % (PcdTokenName, PcdExTokenName))\r
856 AutoGenH.Append('// #define %s LibPcdGetEx%s(&%s, %s)\n' % (GetModeName, DatumSizeLib, Pcd.TokenSpaceGuidCName, PcdTokenName))\r
38b986e3 857 AutoGenH.Append('// #define %s LibPcdGetExSize(&%s, %s)\n' % (GetModeSizeName,Pcd.TokenSpaceGuidCName, PcdTokenName))\r
f51461c8
LG
858 if Pcd.DatumType == 'VOID*':\r
859 AutoGenH.Append('// #define %s(SizeOfBuffer, Buffer) LibPcdSetEx%s(&%s, %s, (SizeOfBuffer), (Buffer))\n' % (SetModeName, DatumSizeLib, Pcd.TokenSpaceGuidCName, PcdTokenName))\r
82a6a960 860 AutoGenH.Append('// #define %s(SizeOfBuffer, Buffer) LibPcdSetEx%sS(&%s, %s, (SizeOfBuffer), (Buffer))\n' % (SetModeStatusName, DatumSizeLib, Pcd.TokenSpaceGuidCName, PcdTokenName))\r
f51461c8
LG
861 else:\r
862 AutoGenH.Append('// #define %s(Value) LibPcdSetEx%s(&%s, %s, (Value))\n' % (SetModeName, DatumSizeLib, Pcd.TokenSpaceGuidCName, PcdTokenName))\r
82a6a960 863 AutoGenH.Append('// #define %s(Value) LibPcdSetEx%sS(&%s, %s, (Value))\n' % (SetModeStatusName, DatumSizeLib, Pcd.TokenSpaceGuidCName, PcdTokenName))\r
f51461c8
LG
864 else:\r
865 AutoGenH.Append('#define %s %s\n' % (PcdTokenName, PcdExTokenName))\r
866 AutoGenH.Append('#define %s LibPcdGetEx%s(&%s, %s)\n' % (GetModeName, DatumSizeLib, Pcd.TokenSpaceGuidCName, PcdTokenName))\r
2f5acc3b 867 AutoGenH.Append('#define %s LibPcdGetExSize(&%s, %s)\n' % (GetModeSizeName,Pcd.TokenSpaceGuidCName, PcdTokenName))\r
f51461c8
LG
868 if Pcd.DatumType == 'VOID*':\r
869 AutoGenH.Append('#define %s(SizeOfBuffer, Buffer) LibPcdSetEx%s(&%s, %s, (SizeOfBuffer), (Buffer))\n' % (SetModeName, DatumSizeLib, Pcd.TokenSpaceGuidCName, PcdTokenName))\r
82a6a960 870 AutoGenH.Append('#define %s(SizeOfBuffer, Buffer) LibPcdSetEx%sS(&%s, %s, (SizeOfBuffer), (Buffer))\n' % (SetModeStatusName, DatumSizeLib, Pcd.TokenSpaceGuidCName, PcdTokenName))\r
f51461c8
LG
871 else:\r
872 AutoGenH.Append('#define %s(Value) LibPcdSetEx%s(&%s, %s, (Value))\n' % (SetModeName, DatumSizeLib, Pcd.TokenSpaceGuidCName, PcdTokenName))\r
82a6a960 873 AutoGenH.Append('#define %s(Value) LibPcdSetEx%sS(&%s, %s, (Value))\n' % (SetModeStatusName, DatumSizeLib, Pcd.TokenSpaceGuidCName, PcdTokenName))\r
f51461c8 874 elif Pcd.Type in gDynamicPcd:\r
38b986e3
YZ
875 PcdList = []\r
876 PcdCNameList = []\r
877 PcdList.extend(Info.LibraryPcdList)\r
878 PcdList.extend(Info.ModulePcdList)\r
879 for PcdModule in PcdList:\r
880 if PcdModule.Type in gDynamicPcd:\r
881 PcdCNameList.append(PcdModule.TokenCName)\r
882 if PcdCNameList.count(Pcd.TokenCName) > 1:\r
2a29017e 883 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 884 else:\r
38b986e3
YZ
885 AutoGenH.Append('#define %s LibPcdGet%s(%s)\n' % (GetModeName, DatumSizeLib, PcdTokenName))\r
886 AutoGenH.Append('#define %s LibPcdGetSize(%s)\n' % (GetModeSizeName, PcdTokenName))\r
887 if Pcd.DatumType == 'VOID*':\r
888 AutoGenH.Append('#define %s(SizeOfBuffer, Buffer) LibPcdSet%s(%s, (SizeOfBuffer), (Buffer))\n' %(SetModeName, DatumSizeLib, PcdTokenName))\r
889 AutoGenH.Append('#define %s(SizeOfBuffer, Buffer) LibPcdSet%sS(%s, (SizeOfBuffer), (Buffer))\n' % (SetModeStatusName, DatumSizeLib, PcdTokenName))\r
890 else:\r
891 AutoGenH.Append('#define %s(Value) LibPcdSet%s(%s, (Value))\n' % (SetModeName, DatumSizeLib, PcdTokenName))\r
892 AutoGenH.Append('#define %s(Value) LibPcdSet%sS(%s, (Value))\n' % (SetModeStatusName, DatumSizeLib, PcdTokenName))\r
f51461c8 893 else:\r
2a29017e 894 PcdVariableName = '_gPcd_' + gItemTypeStringDatabase[Pcd.Type] + '_' + TokenCName\r
f51461c8
LG
895 Const = 'const'\r
896 if Pcd.Type == TAB_PCDS_PATCHABLE_IN_MODULE:\r
897 Const = ''\r
898 Type = ''\r
899 Array = ''\r
900 Value = Pcd.DefaultValue\r
901 Unicode = False\r
902 ValueNumber = 0\r
903\r
904 if Pcd.DatumType == 'BOOLEAN':\r
905 BoolValue = Value.upper()\r
906 if BoolValue == 'TRUE' or BoolValue == '1':\r
907 Value = '1U'\r
908 elif BoolValue == 'FALSE' or BoolValue == '0':\r
909 Value = '0U'\r
910\r
911 if Pcd.DatumType in ['UINT64', 'UINT32', 'UINT16', 'UINT8']:\r
912 try:\r
913 if Value.upper().startswith('0X'):\r
914 ValueNumber = int (Value, 16)\r
915 else:\r
916 ValueNumber = int (Value)\r
917 except:\r
918 EdkLogger.error("build", AUTOGEN_ERROR,\r
2a29017e 919 "PCD value is not valid dec or hex number for datum type [%s] of PCD %s.%s" % (Pcd.DatumType, Pcd.TokenSpaceGuidCName, TokenCName),\r
f51461c8
LG
920 ExtraData="[%s]" % str(Info))\r
921 if Pcd.DatumType == 'UINT64':\r
922 if ValueNumber < 0:\r
923 EdkLogger.error("build", AUTOGEN_ERROR,\r
2a29017e 924 "PCD can't be set to negative value for datum type [%s] of PCD %s.%s" % (Pcd.DatumType, Pcd.TokenSpaceGuidCName, TokenCName),\r
f51461c8
LG
925 ExtraData="[%s]" % str(Info))\r
926 elif ValueNumber >= 0x10000000000000000:\r
927 EdkLogger.error("build", AUTOGEN_ERROR,\r
2a29017e 928 "Too large PCD value for datum type [%s] of PCD %s.%s" % (Pcd.DatumType, Pcd.TokenSpaceGuidCName, TokenCName),\r
f51461c8
LG
929 ExtraData="[%s]" % str(Info))\r
930 if not Value.endswith('ULL'):\r
931 Value += 'ULL'\r
932 elif Pcd.DatumType == 'UINT32':\r
933 if ValueNumber < 0:\r
934 EdkLogger.error("build", AUTOGEN_ERROR,\r
2a29017e 935 "PCD can't be set to negative value for datum type [%s] of PCD %s.%s" % (Pcd.DatumType, Pcd.TokenSpaceGuidCName, TokenCName),\r
f51461c8
LG
936 ExtraData="[%s]" % str(Info))\r
937 elif ValueNumber >= 0x100000000:\r
938 EdkLogger.error("build", AUTOGEN_ERROR,\r
2a29017e 939 "Too large PCD value for datum type [%s] of PCD %s.%s" % (Pcd.DatumType, Pcd.TokenSpaceGuidCName, TokenCName),\r
f51461c8
LG
940 ExtraData="[%s]" % str(Info))\r
941 if not Value.endswith('U'):\r
942 Value += 'U'\r
943 elif Pcd.DatumType == 'UINT16':\r
944 if ValueNumber < 0:\r
945 EdkLogger.error("build", AUTOGEN_ERROR,\r
2a29017e 946 "PCD can't be set to negative value for datum type [%s] of PCD %s.%s" % (Pcd.DatumType, Pcd.TokenSpaceGuidCName, TokenCName),\r
f51461c8
LG
947 ExtraData="[%s]" % str(Info))\r
948 elif ValueNumber >= 0x10000:\r
949 EdkLogger.error("build", AUTOGEN_ERROR,\r
2a29017e 950 "Too large PCD value for datum type [%s] of PCD %s.%s" % (Pcd.DatumType, Pcd.TokenSpaceGuidCName, TokenCName),\r
f51461c8
LG
951 ExtraData="[%s]" % str(Info))\r
952 if not Value.endswith('U'):\r
953 Value += 'U' \r
954 elif Pcd.DatumType == 'UINT8':\r
955 if ValueNumber < 0:\r
956 EdkLogger.error("build", AUTOGEN_ERROR,\r
2a29017e 957 "PCD can't be set to negative value for datum type [%s] of PCD %s.%s" % (Pcd.DatumType, Pcd.TokenSpaceGuidCName, TokenCName),\r
f51461c8
LG
958 ExtraData="[%s]" % str(Info))\r
959 elif ValueNumber >= 0x100:\r
960 EdkLogger.error("build", AUTOGEN_ERROR,\r
2a29017e 961 "Too large PCD value for datum type [%s] of PCD %s.%s" % (Pcd.DatumType, Pcd.TokenSpaceGuidCName, TokenCName),\r
f51461c8
LG
962 ExtraData="[%s]" % str(Info))\r
963 if not Value.endswith('U'):\r
964 Value += 'U'\r
965 if Pcd.DatumType == 'VOID*':\r
966 if Pcd.MaxDatumSize == None or Pcd.MaxDatumSize == '':\r
967 EdkLogger.error("build", AUTOGEN_ERROR,\r
2a29017e 968 "Unknown [MaxDatumSize] of PCD [%s.%s]" % (Pcd.TokenSpaceGuidCName, TokenCName),\r
f51461c8
LG
969 ExtraData="[%s]" % str(Info))\r
970\r
971 ArraySize = int(Pcd.MaxDatumSize, 0)\r
972 if Value[0] == '{':\r
973 Type = '(VOID *)'\r
974 else:\r
975 if Value[0] == 'L':\r
976 Unicode = True\r
977 Value = Value.lstrip('L') #.strip('"')\r
978 Value = eval(Value) # translate escape character\r
979 NewValue = '{'\r
980 for Index in range(0,len(Value)):\r
981 if Unicode:\r
982 NewValue = NewValue + str(ord(Value[Index]) % 0x10000) + ', '\r
983 else:\r
984 NewValue = NewValue + str(ord(Value[Index]) % 0x100) + ', '\r
985 if Unicode:\r
986 ArraySize = ArraySize / 2;\r
987\r
988 if ArraySize < (len(Value) + 1):\r
989 EdkLogger.error("build", AUTOGEN_ERROR,\r
2a29017e 990 "The maximum size of VOID* type PCD '%s.%s' is less than its actual size occupied." % (Pcd.TokenSpaceGuidCName, TokenCName),\r
f51461c8
LG
991 ExtraData="[%s]" % str(Info))\r
992 Value = NewValue + '0 }'\r
993 Array = '[%d]' % ArraySize\r
994 #\r
995 # skip casting for fixed at build since it breaks ARM assembly.\r
996 # Long term we need PCD macros that work in assembly\r
997 #\r
998 elif Pcd.Type != TAB_PCDS_FIXED_AT_BUILD:\r
999 Value = "((%s)%s)" % (Pcd.DatumType, Value)\r
1000\r
1001 if Pcd.Type == TAB_PCDS_PATCHABLE_IN_MODULE:\r
2a29017e 1002 PcdValueName = '_PCD_PATCHABLE_VALUE_' + TokenCName\r
f51461c8 1003 else:\r
2a29017e 1004 PcdValueName = '_PCD_VALUE_' + TokenCName\r
f51461c8
LG
1005 \r
1006 if Pcd.DatumType == 'VOID*':\r
1007 #\r
1008 # For unicode, UINT16 array will be generated, so the alignment of unicode is guaranteed.\r
1009 #\r
1010 if Unicode:\r
f51461c8
LG
1011 AutoGenH.Append('#define %s %s%s\n' %(PcdValueName, Type, PcdVariableName))\r
1012 AutoGenC.Append('GLOBAL_REMOVE_IF_UNREFERENCED %s UINT16 %s%s = %s;\n' % (Const, PcdVariableName, Array, Value))\r
1013 AutoGenH.Append('extern %s UINT16 %s%s;\n' %(Const, PcdVariableName, Array))\r
1014 AutoGenH.Append('#define %s %s%s\n' %(GetModeName, Type, PcdVariableName))\r
1015 else:\r
f51461c8
LG
1016 AutoGenH.Append('#define %s %s%s\n' %(PcdValueName, Type, PcdVariableName))\r
1017 AutoGenC.Append('GLOBAL_REMOVE_IF_UNREFERENCED %s UINT8 %s%s = %s;\n' % (Const, PcdVariableName, Array, Value))\r
1018 AutoGenH.Append('extern %s UINT8 %s%s;\n' %(Const, PcdVariableName, Array))\r
1019 AutoGenH.Append('#define %s %s%s\n' %(GetModeName, Type, PcdVariableName))\r
2f5acc3b
BF
1020 \r
1021 PcdDataSize = GetPcdSize(Pcd)\r
1022 if Pcd.Type == TAB_PCDS_FIXED_AT_BUILD:\r
1023 AutoGenH.Append('#define %s %s\n' % (FixPcdSizeTokenName, PcdDataSize))\r
1024 AutoGenH.Append('#define %s %s \n' % (GetModeSizeName,FixPcdSizeTokenName))\r
1025 \r
1026 if Pcd.Type == TAB_PCDS_PATCHABLE_IN_MODULE:\r
1027 AutoGenH.Append('#define %s %s\n' % (PatchPcdSizeTokenName, Pcd.MaxDatumSize))\r
1028 AutoGenH.Append('#define %s %s \n' % (GetModeSizeName,PatchPcdSizeVariableName))\r
1029 AutoGenH.Append('extern UINTN %s; \n' % PatchPcdSizeVariableName)\r
1030 AutoGenC.Append('GLOBAL_REMOVE_IF_UNREFERENCED UINTN %s = %s;\n' % (PatchPcdSizeVariableName,PcdDataSize))\r
f51461c8
LG
1031 elif Pcd.Type == TAB_PCDS_PATCHABLE_IN_MODULE:\r
1032 AutoGenH.Append('#define %s %s\n' %(PcdValueName, Value))\r
1033 AutoGenC.Append('volatile %s %s %s = %s;\n' %(Const, Pcd.DatumType, PcdVariableName, PcdValueName))\r
1034 AutoGenH.Append('extern volatile %s %s %s%s;\n' % (Const, Pcd.DatumType, PcdVariableName, Array))\r
1035 AutoGenH.Append('#define %s %s%s\n' % (GetModeName, Type, PcdVariableName))\r
2f5acc3b
BF
1036 \r
1037 PcdDataSize = GetPcdSize(Pcd)\r
1038 AutoGenH.Append('#define %s %s\n' % (PatchPcdSizeTokenName, PcdDataSize))\r
1039 \r
1040 AutoGenH.Append('#define %s %s \n' % (GetModeSizeName,PatchPcdSizeVariableName))\r
1041 AutoGenH.Append('extern UINTN %s; \n' % PatchPcdSizeVariableName)\r
1042 AutoGenC.Append('GLOBAL_REMOVE_IF_UNREFERENCED UINTN %s = %s;\n' % (PatchPcdSizeVariableName,PcdDataSize))\r
f51461c8 1043 else:\r
2f5acc3b
BF
1044 PcdDataSize = GetPcdSize(Pcd)\r
1045 AutoGenH.Append('#define %s %s\n' % (FixPcdSizeTokenName, PcdDataSize))\r
1046 AutoGenH.Append('#define %s %s \n' % (GetModeSizeName,FixPcdSizeTokenName))\r
1047 \r
f51461c8
LG
1048 AutoGenH.Append('#define %s %s\n' %(PcdValueName, Value))\r
1049 AutoGenC.Append('GLOBAL_REMOVE_IF_UNREFERENCED %s %s %s = %s;\n' %(Const, Pcd.DatumType, PcdVariableName, PcdValueName))\r
1050 AutoGenH.Append('extern %s %s %s%s;\n' % (Const, Pcd.DatumType, PcdVariableName, Array))\r
1051 AutoGenH.Append('#define %s %s%s\n' % (GetModeName, Type, PcdVariableName))\r
1052\r
1053 if Pcd.Type == TAB_PCDS_PATCHABLE_IN_MODULE:\r
1054 if Pcd.DatumType == 'VOID*':\r
e70504cd
LG
1055 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
1056 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
1057 else:\r
1058 AutoGenH.Append('#define %s(Value) (%s = (Value))\n' % (SetModeName, PcdVariableName))\r
82a6a960 1059 AutoGenH.Append('#define %s(Value) ((%s = (Value)), RETURN_SUCCESS) \n' % (SetModeStatusName, PcdVariableName))\r
f51461c8
LG
1060 else:\r
1061 AutoGenH.Append('//#define %s ASSERT(FALSE) // It is not allowed to set value for a FIXED_AT_BUILD PCD\n' % SetModeName)\r
1062\r
1063## Create code for library module PCDs\r
1064#\r
1065# @param Info The ModuleAutoGen object\r
1066# @param AutoGenC The TemplateString object for C code\r
1067# @param AutoGenH The TemplateString object for header file\r
1068# @param Pcd The PCD object\r
1069#\r
1070def CreateLibraryPcdCode(Info, AutoGenC, AutoGenH, Pcd):\r
1071 PcdTokenNumber = Info.PlatformInfo.PcdTokenNumber\r
1072 TokenSpaceGuidCName = Pcd.TokenSpaceGuidCName\r
1073 TokenCName = Pcd.TokenCName\r
2a29017e
YZ
1074 for PcdItem in GlobalData.MixedPcd:\r
1075 if (TokenCName, TokenSpaceGuidCName) in GlobalData.MixedPcd[PcdItem]:\r
1076 TokenCName = PcdItem[0]\r
1077 break\r
f51461c8 1078 PcdTokenName = '_PCD_TOKEN_' + TokenCName\r
2a29017e
YZ
1079 FixPcdSizeTokenName = '_PCD_SIZE_' + TokenCName\r
1080 PatchPcdSizeTokenName = '_PCD_PATCHABLE_' + TokenCName +'_SIZE'\r
1081 PatchPcdSizeVariableName = '_gPcd_BinaryPatch_Size_' + TokenCName\r
763e8edf
YZ
1082\r
1083 if GlobalData.BuildOptionPcd:\r
1084 for PcdItem in GlobalData.BuildOptionPcd:\r
2a29017e 1085 if (Pcd.TokenSpaceGuidCName, TokenCName) == (PcdItem[0], PcdItem[1]):\r
763e8edf
YZ
1086 Pcd.DefaultValue = PcdItem[2]\r
1087 break\r
1088\r
f51461c8
LG
1089 #\r
1090 # Write PCDs\r
1091 #\r
1092 if Pcd.Type in gDynamicExPcd:\r
1093 TokenNumber = int(Pcd.TokenValue, 0)\r
1094 else:\r
1095 if (Pcd.TokenCName, Pcd.TokenSpaceGuidCName) not in PcdTokenNumber:\r
1096 # If one of the Source built modules listed in the DSC is not listed in FDF modules, \r
1097 # and the INF lists a PCD can only use the PcdsDynamic access method (it is only \r
1098 # listed in the DEC file that declares the PCD as PcdsDynamic), then build tool will \r
1099 # report warning message notify the PI that they are attempting to build a module \r
1100 # that must be included in a flash image in order to be functional. These Dynamic PCD \r
1101 # will not be added into the Database unless it is used by other modules that are \r
1102 # included in the FDF file. \r
1103 # In this case, just assign an invalid token number to make it pass build.\r
1104 if Pcd.Type in PCD_DYNAMIC_TYPE_LIST:\r
1105 TokenNumber = 0\r
1106 else:\r
1107 EdkLogger.error("build", AUTOGEN_ERROR,\r
2a29017e 1108 "No generated token number for %s.%s\n" % (Pcd.TokenSpaceGuidCName, TokenCName),\r
f51461c8
LG
1109 ExtraData="[%s]" % str(Info))\r
1110 else:\r
1111 TokenNumber = PcdTokenNumber[Pcd.TokenCName, Pcd.TokenSpaceGuidCName]\r
1112\r
1113 if Pcd.Type not in gItemTypeStringDatabase:\r
1114 EdkLogger.error("build", AUTOGEN_ERROR,\r
2a29017e 1115 "Unknown PCD type [%s] of PCD %s.%s" % (Pcd.Type, Pcd.TokenSpaceGuidCName, TokenCName),\r
f51461c8
LG
1116 ExtraData="[%s]" % str(Info))\r
1117 if Pcd.DatumType not in gDatumSizeStringDatabase:\r
1118 EdkLogger.error("build", AUTOGEN_ERROR,\r
2a29017e 1119 "Unknown datum type [%s] of PCD %s.%s" % (Pcd.DatumType, Pcd.TokenSpaceGuidCName, TokenCName),\r
f51461c8
LG
1120 ExtraData="[%s]" % str(Info))\r
1121\r
1122 DatumType = Pcd.DatumType\r
1123 DatumSize = gDatumSizeStringDatabaseH[DatumType]\r
1124 DatumSizeLib= gDatumSizeStringDatabaseLib[DatumType]\r
1125 GetModeName = '_PCD_GET_MODE_' + DatumSize + '_' + TokenCName\r
1126 SetModeName = '_PCD_SET_MODE_' + DatumSize + '_' + TokenCName\r
82a6a960 1127 SetModeStatusName = '_PCD_SET_MODE_' + DatumSize + '_S_' + TokenCName\r
2a29017e 1128 GetModeSizeName = '_PCD_GET_MODE_SIZE' + '_' + TokenCName\r
f51461c8
LG
1129\r
1130 Type = ''\r
1131 Array = ''\r
1132 if Pcd.DatumType == 'VOID*':\r
d66670f9
YZ
1133 if Pcd.DefaultValue[0]== '{':\r
1134 Type = '(VOID *)'\r
f51461c8
LG
1135 Array = '[]'\r
1136 PcdItemType = Pcd.Type\r
1137 PcdExCNameList = []\r
1138 if PcdItemType in gDynamicExPcd:\r
2a29017e 1139 PcdExTokenName = '_PCD_TOKEN_' + TokenSpaceGuidCName + '_' + TokenCName\r
f51461c8
LG
1140 AutoGenH.Append('\n#define %s %dU\n' % (PcdExTokenName, TokenNumber))\r
1141 \r
1142 if Info.IsLibrary:\r
1143 PcdList = Info.LibraryPcdList\r
1144 else:\r
1145 PcdList = Info.ModulePcdList\r
1146 for PcdModule in PcdList:\r
1147 if PcdModule.Type in gDynamicExPcd:\r
1148 PcdExCNameList.append(PcdModule.TokenCName)\r
1149 # Be compatible with the current code which using PcdGet/Set for DynamicEx Pcd.\r
1150 # If only PcdGet/Set used in all Pcds with different CName, it should succeed to build.\r
1151 # If PcdGet/Set used in the Pcds with different Guids but same CName, it should failed to build.\r
1152 if PcdExCNameList.count(Pcd.TokenCName) > 1:\r
1153 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
1154 AutoGenH.Append('// #define %s %s\n' % (PcdTokenName, PcdExTokenName))\r
1155 AutoGenH.Append('// #define %s LibPcdGetEx%s(&%s, %s)\n' % (GetModeName, DatumSizeLib, Pcd.TokenSpaceGuidCName, PcdTokenName))\r
38b986e3 1156 AutoGenH.Append('// #define %s LibPcdGetExSize(&%s, %s \n' % (GetModeSizeName,Pcd.TokenSpaceGuidCName, PcdTokenName))\r
f51461c8
LG
1157 if Pcd.DatumType == 'VOID*':\r
1158 AutoGenH.Append('// #define %s(SizeOfBuffer, Buffer) LibPcdSetEx%s(&%s, %s, (SizeOfBuffer), (Buffer))\n' % (SetModeName, DatumSizeLib, Pcd.TokenSpaceGuidCName, PcdTokenName))\r
82a6a960 1159 AutoGenH.Append('// #define %s(SizeOfBuffer, Buffer) LibPcdSetEx%sS(&%s, %s, (SizeOfBuffer), (Buffer))\n' % (SetModeStatusName, DatumSizeLib, Pcd.TokenSpaceGuidCName, PcdTokenName))\r
f51461c8
LG
1160 else:\r
1161 AutoGenH.Append('// #define %s(Value) LibPcdSetEx%s(&%s, %s, (Value))\n' % (SetModeName, DatumSizeLib, Pcd.TokenSpaceGuidCName, PcdTokenName))\r
82a6a960 1162 AutoGenH.Append('// #define %s(Value) LibPcdSetEx%sS(&%s, %s, (Value))\n' % (SetModeStatusName, DatumSizeLib, Pcd.TokenSpaceGuidCName, PcdTokenName))\r
f51461c8
LG
1163 else:\r
1164 AutoGenH.Append('#define %s %s\n' % (PcdTokenName, PcdExTokenName))\r
1165 AutoGenH.Append('#define %s LibPcdGetEx%s(&%s, %s)\n' % (GetModeName, DatumSizeLib, Pcd.TokenSpaceGuidCName, PcdTokenName))\r
2f5acc3b 1166 AutoGenH.Append('#define %s LibPcdGetExSize(&%s, %s)\n' % (GetModeSizeName,Pcd.TokenSpaceGuidCName, PcdTokenName))\r
f51461c8
LG
1167 if Pcd.DatumType == 'VOID*':\r
1168 AutoGenH.Append('#define %s(SizeOfBuffer, Buffer) LibPcdSetEx%s(&%s, %s, (SizeOfBuffer), (Buffer))\n' % (SetModeName, DatumSizeLib, Pcd.TokenSpaceGuidCName, PcdTokenName))\r
82a6a960 1169 AutoGenH.Append('#define %s(SizeOfBuffer, Buffer) LibPcdSetEx%sS(&%s, %s, (SizeOfBuffer), (Buffer))\n' % (SetModeStatusName, DatumSizeLib, Pcd.TokenSpaceGuidCName, PcdTokenName))\r
f51461c8
LG
1170 else:\r
1171 AutoGenH.Append('#define %s(Value) LibPcdSetEx%s(&%s, %s, (Value))\n' % (SetModeName, DatumSizeLib, Pcd.TokenSpaceGuidCName, PcdTokenName))\r
82a6a960 1172 AutoGenH.Append('#define %s(Value) LibPcdSetEx%sS(&%s, %s, (Value))\n' % (SetModeStatusName, DatumSizeLib, Pcd.TokenSpaceGuidCName, PcdTokenName))\r
f51461c8
LG
1173 else:\r
1174 AutoGenH.Append('#define _PCD_TOKEN_%s %dU\n' % (TokenCName, TokenNumber))\r
1175 if PcdItemType in gDynamicPcd:\r
38b986e3
YZ
1176 PcdList = []\r
1177 PcdCNameList = []\r
1178 PcdList.extend(Info.LibraryPcdList)\r
1179 PcdList.extend(Info.ModulePcdList)\r
1180 for PcdModule in PcdList:\r
1181 if PcdModule.Type in gDynamicPcd:\r
1182 PcdCNameList.append(PcdModule.TokenCName)\r
1183 if PcdCNameList.count(Pcd.TokenCName) > 1:\r
2a29017e 1184 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 1185 else:\r
38b986e3
YZ
1186 AutoGenH.Append('#define %s LibPcdGet%s(%s)\n' % (GetModeName, DatumSizeLib, PcdTokenName))\r
1187 AutoGenH.Append('#define %s LibPcdGetSize(%s)\n' % (GetModeSizeName, PcdTokenName))\r
1188 if DatumType == 'VOID*':\r
1189 AutoGenH.Append('#define %s(SizeOfBuffer, Buffer) LibPcdSet%s(%s, (SizeOfBuffer), (Buffer))\n' %(SetModeName, DatumSizeLib, PcdTokenName))\r
1190 AutoGenH.Append('#define %s(SizeOfBuffer, Buffer) LibPcdSet%sS(%s, (SizeOfBuffer), (Buffer))\n' % (SetModeStatusName, DatumSizeLib, PcdTokenName))\r
1191 else:\r
1192 AutoGenH.Append('#define %s(Value) LibPcdSet%s(%s, (Value))\n' % (SetModeName, DatumSizeLib, PcdTokenName))\r
1193 AutoGenH.Append('#define %s(Value) LibPcdSet%sS(%s, (Value))\n' % (SetModeStatusName, DatumSizeLib, PcdTokenName))\r
f51461c8
LG
1194 if PcdItemType == TAB_PCDS_PATCHABLE_IN_MODULE:\r
1195 PcdVariableName = '_gPcd_' + gItemTypeStringDatabase[TAB_PCDS_PATCHABLE_IN_MODULE] + '_' + TokenCName\r
d66670f9
YZ
1196 if DatumType == 'VOID*':\r
1197 ArraySize = int(Pcd.MaxDatumSize, 0)\r
1198 if Pcd.DefaultValue[0] == 'L':\r
1199 ArraySize = ArraySize / 2\r
1200 Array = '[%d]' % ArraySize\r
1201 DatumType = ['UINT8', 'UINT16'][Pcd.DefaultValue[0] == 'L']\r
1202 AutoGenH.Append('extern %s _gPcd_BinaryPatch_%s%s;\n' %(DatumType, TokenCName, Array))\r
1203 else:\r
1204 AutoGenH.Append('extern volatile %s %s%s;\n' % (DatumType, PcdVariableName, Array))\r
f51461c8 1205 AutoGenH.Append('#define %s %s_gPcd_BinaryPatch_%s\n' %(GetModeName, Type, TokenCName))\r
27187d24 1206 if Pcd.DatumType == 'VOID*':\r
2a29017e
YZ
1207 AutoGenH.Append('#define %s(SizeOfBuffer, Buffer) LibPatchPcdSetPtrAndSize((VOID *)_gPcd_BinaryPatch_%s, &_gPcd_BinaryPatch_Size_%s, (UINTN)_PCD_PATCHABLE_%s_SIZE, (SizeOfBuffer), (Buffer))\n' % (SetModeName, TokenCName, TokenCName, TokenCName))\r
1208 AutoGenH.Append('#define %s(SizeOfBuffer, Buffer) LibPatchPcdSetPtrAndSizeS((VOID *)_gPcd_BinaryPatch_%s, &_gPcd_BinaryPatch_Size_%s, (UINTN)_PCD_PATCHABLE_%s_SIZE, (SizeOfBuffer), (Buffer))\n' % (SetModeStatusName, TokenCName, TokenCName, TokenCName))\r
27187d24
LG
1209 else:\r
1210 AutoGenH.Append('#define %s(Value) (%s = (Value))\n' % (SetModeName, PcdVariableName))\r
1211 AutoGenH.Append('#define %s(Value) ((%s = (Value)), RETURN_SUCCESS)\n' % (SetModeStatusName, PcdVariableName))\r
2f5acc3b
BF
1212 \r
1213 PcdDataSize = GetPcdSize(Pcd)\r
1214 AutoGenH.Append('#define %s %s\n' % (PatchPcdSizeTokenName, PcdDataSize))\r
1215 AutoGenH.Append('#define %s %s\n' % (GetModeSizeName,PatchPcdSizeVariableName))\r
1216 AutoGenH.Append('extern UINTN %s; \n' % PatchPcdSizeVariableName)\r
1217 \r
f51461c8
LG
1218 if PcdItemType == TAB_PCDS_FIXED_AT_BUILD or PcdItemType == TAB_PCDS_FEATURE_FLAG:\r
1219 key = ".".join((Pcd.TokenSpaceGuidCName,Pcd.TokenCName))\r
1220 \r
41ab153f 1221 if DatumType == 'VOID*' and Array == '[]':\r
2f5acc3b 1222 DatumType = ['UINT8', 'UINT16'][Pcd.DefaultValue[0] == 'L']\r
f51461c8
LG
1223 AutoGenH.Append('extern const %s _gPcd_FixedAtBuild_%s%s;\n' %(DatumType, TokenCName, Array))\r
1224 AutoGenH.Append('#define %s %s_gPcd_FixedAtBuild_%s\n' %(GetModeName, Type, TokenCName))\r
1225 AutoGenH.Append('//#define %s ASSERT(FALSE) // It is not allowed to set value for a FIXED_AT_BUILD PCD\n' % SetModeName)\r
1226 \r
c9da41b2 1227 if PcdItemType == TAB_PCDS_FIXED_AT_BUILD and (key in Info.ConstPcd or (Info.IsLibrary and not Info._ReferenceModules)):\r
f51461c8
LG
1228 AutoGenH.Append('#define _PCD_VALUE_%s %s\n' %(TokenCName, Pcd.DefaultValue))\r
1229 \r
2f5acc3b
BF
1230 if PcdItemType == TAB_PCDS_FIXED_AT_BUILD:\r
1231 PcdDataSize = GetPcdSize(Pcd)\r
1232 AutoGenH.Append('#define %s %s\n' % (FixPcdSizeTokenName, PcdDataSize))\r
1233 AutoGenH.Append('#define %s %s\n' % (GetModeSizeName,FixPcdSizeTokenName))\r
f51461c8
LG
1234\r
1235## Create code for library constructor\r
1236#\r
1237# @param Info The ModuleAutoGen object\r
1238# @param AutoGenC The TemplateString object for C code\r
1239# @param AutoGenH The TemplateString object for header file\r
1240#\r
1241def CreateLibraryConstructorCode(Info, AutoGenC, AutoGenH):\r
1242 #\r
1243 # Library Constructors\r
1244 #\r
1245 ConstructorPrototypeString = TemplateString()\r
1246 ConstructorCallingString = TemplateString()\r
1247 if Info.IsLibrary:\r
1248 DependentLibraryList = [Info.Module]\r
1249 else:\r
1250 DependentLibraryList = Info.DependentLibraryList\r
1251 for Lib in DependentLibraryList:\r
1252 if len(Lib.ConstructorList) <= 0:\r
1253 continue\r
1254 Dict = {'Function':Lib.ConstructorList}\r
1255 if Lib.ModuleType in ['BASE', 'SEC']:\r
1256 ConstructorPrototypeString.Append(gLibraryStructorPrototype['BASE'].Replace(Dict))\r
1257 ConstructorCallingString.Append(gLibraryStructorCall['BASE'].Replace(Dict))\r
1258 elif Lib.ModuleType in ['PEI_CORE','PEIM']:\r
1259 ConstructorPrototypeString.Append(gLibraryStructorPrototype['PEI'].Replace(Dict))\r
1260 ConstructorCallingString.Append(gLibraryStructorCall['PEI'].Replace(Dict))\r
1261 elif Lib.ModuleType in ['DXE_CORE','DXE_DRIVER','DXE_SMM_DRIVER','DXE_RUNTIME_DRIVER',\r
1262 'DXE_SAL_DRIVER','UEFI_DRIVER','UEFI_APPLICATION','SMM_CORE']:\r
1263 ConstructorPrototypeString.Append(gLibraryStructorPrototype['DXE'].Replace(Dict))\r
1264 ConstructorCallingString.Append(gLibraryStructorCall['DXE'].Replace(Dict))\r
1265\r
1266 if str(ConstructorPrototypeString) == '':\r
1267 ConstructorPrototypeList = []\r
1268 else:\r
1269 ConstructorPrototypeList = [str(ConstructorPrototypeString)]\r
1270 if str(ConstructorCallingString) == '':\r
1271 ConstructorCallingList = []\r
1272 else:\r
1273 ConstructorCallingList = [str(ConstructorCallingString)]\r
1274\r
1275 Dict = {\r
1276 'Type' : 'Constructor',\r
1277 'FunctionPrototype' : ConstructorPrototypeList,\r
1278 'FunctionCall' : ConstructorCallingList\r
1279 }\r
1280 if Info.IsLibrary:\r
1281 AutoGenH.Append("${BEGIN}${FunctionPrototype}${END}", Dict)\r
1282 else:\r
1283 if Info.ModuleType in ['BASE', 'SEC']:\r
1284 AutoGenC.Append(gLibraryString['BASE'].Replace(Dict))\r
1285 elif Info.ModuleType in ['PEI_CORE','PEIM']:\r
1286 AutoGenC.Append(gLibraryString['PEI'].Replace(Dict))\r
1287 elif Info.ModuleType in ['DXE_CORE','DXE_DRIVER','DXE_SMM_DRIVER','DXE_RUNTIME_DRIVER',\r
1288 'DXE_SAL_DRIVER','UEFI_DRIVER','UEFI_APPLICATION','SMM_CORE']:\r
1289 AutoGenC.Append(gLibraryString['DXE'].Replace(Dict))\r
1290\r
1291## Create code for library destructor\r
1292#\r
1293# @param Info The ModuleAutoGen object\r
1294# @param AutoGenC The TemplateString object for C code\r
1295# @param AutoGenH The TemplateString object for header file\r
1296#\r
1297def CreateLibraryDestructorCode(Info, AutoGenC, AutoGenH):\r
1298 #\r
1299 # Library Destructors\r
1300 #\r
1301 DestructorPrototypeString = TemplateString()\r
1302 DestructorCallingString = TemplateString()\r
1303 if Info.IsLibrary:\r
1304 DependentLibraryList = [Info.Module]\r
1305 else:\r
1306 DependentLibraryList = Info.DependentLibraryList\r
1307 for Index in range(len(DependentLibraryList)-1, -1, -1):\r
1308 Lib = DependentLibraryList[Index]\r
1309 if len(Lib.DestructorList) <= 0:\r
1310 continue\r
1311 Dict = {'Function':Lib.DestructorList}\r
1312 if Lib.ModuleType in ['BASE', 'SEC']:\r
1313 DestructorPrototypeString.Append(gLibraryStructorPrototype['BASE'].Replace(Dict))\r
1314 DestructorCallingString.Append(gLibraryStructorCall['BASE'].Replace(Dict))\r
1315 elif Lib.ModuleType in ['PEI_CORE','PEIM']:\r
1316 DestructorPrototypeString.Append(gLibraryStructorPrototype['PEI'].Replace(Dict))\r
1317 DestructorCallingString.Append(gLibraryStructorCall['PEI'].Replace(Dict))\r
1318 elif Lib.ModuleType in ['DXE_CORE','DXE_DRIVER','DXE_SMM_DRIVER','DXE_RUNTIME_DRIVER',\r
1319 'DXE_SAL_DRIVER','UEFI_DRIVER','UEFI_APPLICATION', 'SMM_CORE']:\r
1320 DestructorPrototypeString.Append(gLibraryStructorPrototype['DXE'].Replace(Dict))\r
1321 DestructorCallingString.Append(gLibraryStructorCall['DXE'].Replace(Dict))\r
1322\r
1323 if str(DestructorPrototypeString) == '':\r
1324 DestructorPrototypeList = []\r
1325 else:\r
1326 DestructorPrototypeList = [str(DestructorPrototypeString)]\r
1327 if str(DestructorCallingString) == '':\r
1328 DestructorCallingList = []\r
1329 else:\r
1330 DestructorCallingList = [str(DestructorCallingString)]\r
1331\r
1332 Dict = {\r
1333 'Type' : 'Destructor',\r
1334 'FunctionPrototype' : DestructorPrototypeList,\r
1335 'FunctionCall' : DestructorCallingList\r
1336 }\r
1337 if Info.IsLibrary:\r
1338 AutoGenH.Append("${BEGIN}${FunctionPrototype}${END}", Dict)\r
1339 else:\r
1340 if Info.ModuleType in ['BASE', 'SEC']:\r
1341 AutoGenC.Append(gLibraryString['BASE'].Replace(Dict))\r
1342 elif Info.ModuleType in ['PEI_CORE','PEIM']:\r
1343 AutoGenC.Append(gLibraryString['PEI'].Replace(Dict))\r
1344 elif Info.ModuleType in ['DXE_CORE','DXE_DRIVER','DXE_SMM_DRIVER','DXE_RUNTIME_DRIVER',\r
1345 'DXE_SAL_DRIVER','UEFI_DRIVER','UEFI_APPLICATION','SMM_CORE']:\r
1346 AutoGenC.Append(gLibraryString['DXE'].Replace(Dict))\r
1347\r
1348\r
1349## Create code for ModuleEntryPoint\r
1350#\r
1351# @param Info The ModuleAutoGen object\r
1352# @param AutoGenC The TemplateString object for C code\r
1353# @param AutoGenH The TemplateString object for header file\r
1354#\r
1355def CreateModuleEntryPointCode(Info, AutoGenC, AutoGenH):\r
1356 if Info.IsLibrary or Info.ModuleType in ['USER_DEFINED', 'SEC']:\r
1357 return\r
1358 #\r
1359 # Module Entry Points\r
1360 #\r
1361 NumEntryPoints = len(Info.Module.ModuleEntryPointList)\r
1362 if 'PI_SPECIFICATION_VERSION' in Info.Module.Specification:\r
1363 PiSpecVersion = Info.Module.Specification['PI_SPECIFICATION_VERSION']\r
1364 else:\r
1365 PiSpecVersion = '0x00000000'\r
1366 if 'UEFI_SPECIFICATION_VERSION' in Info.Module.Specification:\r
1367 UefiSpecVersion = Info.Module.Specification['UEFI_SPECIFICATION_VERSION']\r
1368 else:\r
1369 UefiSpecVersion = '0x00000000'\r
1370 Dict = {\r
1371 'Function' : Info.Module.ModuleEntryPointList,\r
1372 'PiSpecVersion' : PiSpecVersion + 'U',\r
1373 'UefiSpecVersion': UefiSpecVersion + 'U'\r
1374 }\r
1375\r
1376 if Info.ModuleType in ['PEI_CORE', 'DXE_CORE', 'SMM_CORE']:\r
1377 if Info.SourceFileList <> None and Info.SourceFileList <> []:\r
1378 if NumEntryPoints != 1:\r
1379 EdkLogger.error(\r
1380 "build",\r
1381 AUTOGEN_ERROR,\r
1382 '%s must have exactly one entry point' % Info.ModuleType,\r
1383 File=str(Info),\r
1384 ExtraData= ", ".join(Info.Module.ModuleEntryPointList)\r
1385 )\r
1386 if Info.ModuleType == 'PEI_CORE':\r
1387 AutoGenC.Append(gPeiCoreEntryPointString.Replace(Dict))\r
1388 AutoGenH.Append(gPeiCoreEntryPointPrototype.Replace(Dict))\r
1389 elif Info.ModuleType == 'DXE_CORE':\r
1390 AutoGenC.Append(gDxeCoreEntryPointString.Replace(Dict))\r
1391 AutoGenH.Append(gDxeCoreEntryPointPrototype.Replace(Dict))\r
1392 elif Info.ModuleType == 'SMM_CORE':\r
1393 AutoGenC.Append(gSmmCoreEntryPointString.Replace(Dict))\r
1394 AutoGenH.Append(gSmmCoreEntryPointPrototype.Replace(Dict))\r
1395 elif Info.ModuleType == 'PEIM':\r
1396 if NumEntryPoints < 2:\r
1397 AutoGenC.Append(gPeimEntryPointString[NumEntryPoints].Replace(Dict))\r
1398 else:\r
1399 AutoGenC.Append(gPeimEntryPointString[2].Replace(Dict))\r
1400 AutoGenH.Append(gPeimEntryPointPrototype.Replace(Dict))\r
1401 elif Info.ModuleType in ['DXE_RUNTIME_DRIVER','DXE_DRIVER','DXE_SAL_DRIVER','UEFI_DRIVER']:\r
1402 if NumEntryPoints < 2:\r
1403 AutoGenC.Append(gUefiDriverEntryPointString[NumEntryPoints].Replace(Dict))\r
1404 else:\r
1405 AutoGenC.Append(gUefiDriverEntryPointString[2].Replace(Dict))\r
1406 AutoGenH.Append(gUefiDriverEntryPointPrototype.Replace(Dict))\r
1407 elif Info.ModuleType == 'DXE_SMM_DRIVER':\r
1408 if NumEntryPoints == 0:\r
1409 AutoGenC.Append(gDxeSmmEntryPointString[0].Replace(Dict))\r
1410 else:\r
1411 AutoGenC.Append(gDxeSmmEntryPointString[1].Replace(Dict))\r
1412 AutoGenH.Append(gDxeSmmEntryPointPrototype.Replace(Dict)) \r
1413 elif Info.ModuleType == 'UEFI_APPLICATION':\r
1414 if NumEntryPoints < 2:\r
1415 AutoGenC.Append(gUefiApplicationEntryPointString[NumEntryPoints].Replace(Dict))\r
1416 else:\r
1417 AutoGenC.Append(gUefiApplicationEntryPointString[2].Replace(Dict))\r
1418 AutoGenH.Append(gUefiApplicationEntryPointPrototype.Replace(Dict))\r
1419\r
1420## Create code for ModuleUnloadImage\r
1421#\r
1422# @param Info The ModuleAutoGen object\r
1423# @param AutoGenC The TemplateString object for C code\r
1424# @param AutoGenH The TemplateString object for header file\r
1425#\r
1426def CreateModuleUnloadImageCode(Info, AutoGenC, AutoGenH):\r
1427 if Info.IsLibrary or Info.ModuleType in ['USER_DEFINED', 'SEC']:\r
1428 return\r
1429 #\r
1430 # Unload Image Handlers\r
1431 #\r
1432 NumUnloadImage = len(Info.Module.ModuleUnloadImageList)\r
1433 Dict = {'Count':str(NumUnloadImage) + 'U', 'Function':Info.Module.ModuleUnloadImageList}\r
1434 if NumUnloadImage < 2:\r
1435 AutoGenC.Append(gUefiUnloadImageString[NumUnloadImage].Replace(Dict))\r
1436 else:\r
1437 AutoGenC.Append(gUefiUnloadImageString[2].Replace(Dict))\r
1438 AutoGenH.Append(gUefiUnloadImagePrototype.Replace(Dict))\r
1439\r
1440## Create code for GUID\r
1441#\r
1442# @param Info The ModuleAutoGen object\r
1443# @param AutoGenC The TemplateString object for C code\r
1444# @param AutoGenH The TemplateString object for header file\r
1445#\r
1446def CreateGuidDefinitionCode(Info, AutoGenC, AutoGenH):\r
f51461c8
LG
1447 if Info.ModuleType in ["USER_DEFINED", "BASE"]:\r
1448 GuidType = "GUID"\r
1449 else:\r
1450 GuidType = "EFI_GUID"\r
1451\r
1452 if Info.GuidList:\r
7beed8a3
YZ
1453 if not Info.IsLibrary:\r
1454 AutoGenC.Append("\n// Guids\n")\r
8262037f 1455 AutoGenH.Append("\n// Guids\n")\r
f51461c8
LG
1456 #\r
1457 # GUIDs\r
1458 #\r
1459 for Key in Info.GuidList:\r
7beed8a3
YZ
1460 if not Info.IsLibrary:\r
1461 AutoGenC.Append('GLOBAL_REMOVE_IF_UNREFERENCED %s %s = %s;\n' % (GuidType, Key, Info.GuidList[Key]))\r
8262037f 1462 AutoGenH.Append('extern %s %s;\n' % (GuidType, Key))\r
f51461c8
LG
1463\r
1464## Create code for protocol\r
1465#\r
1466# @param Info The ModuleAutoGen object\r
1467# @param AutoGenC The TemplateString object for C code\r
1468# @param AutoGenH The TemplateString object for header file\r
1469#\r
1470def CreateProtocolDefinitionCode(Info, AutoGenC, AutoGenH):\r
f51461c8
LG
1471 if Info.ModuleType in ["USER_DEFINED", "BASE"]:\r
1472 GuidType = "GUID"\r
1473 else:\r
1474 GuidType = "EFI_GUID"\r
1475\r
1476 if Info.ProtocolList:\r
7beed8a3
YZ
1477 if not Info.IsLibrary:\r
1478 AutoGenC.Append("\n// Protocols\n")\r
8262037f 1479 AutoGenH.Append("\n// Protocols\n")\r
f51461c8
LG
1480 #\r
1481 # Protocol GUIDs\r
1482 #\r
1483 for Key in Info.ProtocolList:\r
7beed8a3
YZ
1484 if not Info.IsLibrary:\r
1485 AutoGenC.Append('GLOBAL_REMOVE_IF_UNREFERENCED %s %s = %s;\n' % (GuidType, Key, Info.ProtocolList[Key]))\r
8262037f 1486 AutoGenH.Append('extern %s %s;\n' % (GuidType, Key))\r
f51461c8
LG
1487\r
1488## Create code for PPI\r
1489#\r
1490# @param Info The ModuleAutoGen object\r
1491# @param AutoGenC The TemplateString object for C code\r
1492# @param AutoGenH The TemplateString object for header file\r
1493#\r
1494def CreatePpiDefinitionCode(Info, AutoGenC, AutoGenH):\r
f51461c8
LG
1495 if Info.ModuleType in ["USER_DEFINED", "BASE"]:\r
1496 GuidType = "GUID"\r
1497 else:\r
1498 GuidType = "EFI_GUID"\r
1499\r
1500 if Info.PpiList:\r
7beed8a3
YZ
1501 if not Info.IsLibrary:\r
1502 AutoGenC.Append("\n// PPIs\n")\r
8262037f 1503 AutoGenH.Append("\n// PPIs\n")\r
f51461c8
LG
1504 #\r
1505 # PPI GUIDs\r
1506 #\r
1507 for Key in Info.PpiList:\r
7beed8a3
YZ
1508 if not Info.IsLibrary:\r
1509 AutoGenC.Append('GLOBAL_REMOVE_IF_UNREFERENCED %s %s = %s;\n' % (GuidType, Key, Info.PpiList[Key]))\r
8262037f 1510 AutoGenH.Append('extern %s %s;\n' % (GuidType, Key))\r
f51461c8
LG
1511\r
1512## Create code for PCD\r
1513#\r
1514# @param Info The ModuleAutoGen object\r
1515# @param AutoGenC The TemplateString object for C code\r
1516# @param AutoGenH The TemplateString object for header file\r
1517#\r
1518def CreatePcdCode(Info, AutoGenC, AutoGenH):\r
1519\r
1520 # Collect Token Space GUIDs used by DynamicEc PCDs\r
1521 TokenSpaceList = []\r
1522 for Pcd in Info.ModulePcdList:\r
1523 if Pcd.Type in gDynamicExPcd and Pcd.TokenSpaceGuidCName not in TokenSpaceList:\r
1524 TokenSpaceList += [Pcd.TokenSpaceGuidCName]\r
1525 \r
1526 # Add extern declarations to AutoGen.h if one or more Token Space GUIDs were found\r
1527 if TokenSpaceList <> []: \r
1528 AutoGenH.Append("\n// Definition of PCD Token Space GUIDs used in this module\n\n")\r
1529 if Info.ModuleType in ["USER_DEFINED", "BASE"]:\r
1530 GuidType = "GUID"\r
1531 else:\r
1532 GuidType = "EFI_GUID" \r
1533 for Item in TokenSpaceList:\r
1534 AutoGenH.Append('extern %s %s;\n' % (GuidType, Item))\r
1535\r
1536 if Info.IsLibrary:\r
1537 if Info.ModulePcdList:\r
1538 AutoGenH.Append("\n// PCD definitions\n")\r
1539 for Pcd in Info.ModulePcdList:\r
1540 CreateLibraryPcdCode(Info, AutoGenC, AutoGenH, Pcd)\r
1541 DynExPcdTokenNumberMapping (Info, AutoGenH)\r
1542 else:\r
1543 if Info.ModulePcdList:\r
1544 AutoGenH.Append("\n// Definition of PCDs used in this module\n")\r
1545 AutoGenC.Append("\n// Definition of PCDs used in this module\n")\r
1546 for Pcd in Info.ModulePcdList:\r
1547 CreateModulePcdCode(Info, AutoGenC, AutoGenH, Pcd)\r
1548 DynExPcdTokenNumberMapping (Info, AutoGenH)\r
1549 if Info.LibraryPcdList:\r
1550 AutoGenH.Append("\n// Definition of PCDs used in libraries is in AutoGen.c\n")\r
1551 AutoGenC.Append("\n// Definition of PCDs used in libraries\n")\r
1552 for Pcd in Info.LibraryPcdList:\r
1553 CreateModulePcdCode(Info, AutoGenC, AutoGenC, Pcd)\r
1554 CreatePcdDatabaseCode(Info, AutoGenC, AutoGenH)\r
1555\r
1556## Create code for unicode string definition\r
1557#\r
1558# @param Info The ModuleAutoGen object\r
1559# @param AutoGenC The TemplateString object for C code\r
1560# @param AutoGenH The TemplateString object for header file\r
1561# @param UniGenCFlag UniString is generated into AutoGen C file when it is set to True\r
1562# @param UniGenBinBuffer Buffer to store uni string package data\r
1563#\r
1564def CreateUnicodeStringCode(Info, AutoGenC, AutoGenH, UniGenCFlag, UniGenBinBuffer):\r
1565 WorkingDir = os.getcwd()\r
1566 os.chdir(Info.WorkspaceDir)\r
1567\r
1568 IncList = [Info.MetaFile.Dir]\r
1569 # Get all files under [Sources] section in inf file for EDK-II module\r
1570 EDK2Module = True\r
1571 SrcList = [F for F in Info.SourceFileList]\r
1572 if Info.AutoGenVersion < 0x00010005:\r
1573 EDK2Module = False\r
1574 # Get all files under the module directory for EDK-I module\r
1575 Cwd = os.getcwd()\r
1576 os.chdir(Info.MetaFile.Dir)\r
1577 for Root, Dirs, Files in os.walk("."):\r
1578 if 'CVS' in Dirs:\r
1579 Dirs.remove('CVS')\r
1580 if '.svn' in Dirs:\r
1581 Dirs.remove('.svn')\r
1582 for File in Files:\r
1583 File = PathClass(os.path.join(Root, File), Info.MetaFile.Dir)\r
1584 if File in SrcList:\r
1585 continue\r
1586 SrcList.append(File)\r
1587 os.chdir(Cwd)\r
1588\r
1589 if 'BUILD' in Info.BuildOption and Info.BuildOption['BUILD']['FLAGS'].find('-c') > -1:\r
1590 CompatibleMode = True\r
1591 else:\r
1592 CompatibleMode = False\r
1593\r
1594 #\r
1595 # -s is a temporary option dedicated for building .UNI files with ISO 639-2 language codes of EDK Shell in EDK2\r
1596 #\r
1597 if 'BUILD' in Info.BuildOption and Info.BuildOption['BUILD']['FLAGS'].find('-s') > -1:\r
1598 if CompatibleMode:\r
1599 EdkLogger.error("build", AUTOGEN_ERROR,\r
1600 "-c and -s build options should be used exclusively",\r
1601 ExtraData="[%s]" % str(Info))\r
1602 ShellMode = True\r
1603 else:\r
1604 ShellMode = False\r
1605\r
1606 #RFC4646 is only for EDKII modules and ISO639-2 for EDK modules\r
1607 if EDK2Module:\r
1608 FilterInfo = [EDK2Module] + [Info.PlatformInfo.Platform.RFCLanguages]\r
1609 else:\r
1610 FilterInfo = [EDK2Module] + [Info.PlatformInfo.Platform.ISOLanguages]\r
1611 Header, Code = GetStringFiles(Info.UnicodeFileList, SrcList, IncList, Info.IncludePathList, ['.uni', '.inf'], Info.Name, CompatibleMode, ShellMode, UniGenCFlag, UniGenBinBuffer, FilterInfo)\r
1612 if CompatibleMode or UniGenCFlag:\r
1613 AutoGenC.Append("\n//\n//Unicode String Pack Definition\n//\n")\r
1614 AutoGenC.Append(Code)\r
1615 AutoGenC.Append("\n")\r
1616 AutoGenH.Append("\n//\n//Unicode String ID\n//\n")\r
1617 AutoGenH.Append(Header)\r
1618 if CompatibleMode or UniGenCFlag:\r
1619 AutoGenH.Append("\n#define STRING_ARRAY_NAME %sStrings\n" % Info.Name)\r
1620 os.chdir(WorkingDir)\r
1621\r
1622## Create common code\r
1623#\r
1624# @param Info The ModuleAutoGen object\r
1625# @param AutoGenC The TemplateString object for C code\r
1626# @param AutoGenH The TemplateString object for header file\r
1627#\r
1628def CreateHeaderCode(Info, AutoGenC, AutoGenH):\r
1629 # file header\r
1630 AutoGenH.Append(gAutoGenHeaderString.Replace({'FileName':'AutoGen.h'}))\r
1631 # header file Prologue\r
1632 AutoGenH.Append(gAutoGenHPrologueString.Replace({'File':'AUTOGENH','Guid':Info.Guid.replace('-','_')}))\r
1633 AutoGenH.Append(gAutoGenHCppPrologueString)\r
1634 if Info.AutoGenVersion >= 0x00010005:\r
1635 # header files includes\r
1636 AutoGenH.Append("#include <%s>\n" % gBasicHeaderFile)\r
1637 if Info.ModuleType in gModuleTypeHeaderFile \\r
1638 and gModuleTypeHeaderFile[Info.ModuleType][0] != gBasicHeaderFile:\r
1639 AutoGenH.Append("#include <%s>\n" % gModuleTypeHeaderFile[Info.ModuleType][0])\r
1640 #\r
1641 # if either PcdLib in [LibraryClasses] sections or there exist Pcd section, add PcdLib.h \r
1642 # As if modules only uses FixedPcd, then PcdLib is not needed in [LibraryClasses] section.\r
1643 #\r
1644 if 'PcdLib' in Info.Module.LibraryClasses or Info.Module.Pcds:\r
1645 AutoGenH.Append("#include <Library/PcdLib.h>\n")\r
1646\r
1647 AutoGenH.Append('\nextern GUID gEfiCallerIdGuid;')\r
1648 AutoGenH.Append('\nextern CHAR8 *gEfiCallerBaseName;\n\n')\r
1649\r
1650 if Info.IsLibrary:\r
1651 return\r
1652\r
1653 AutoGenH.Append("#define EFI_CALLER_ID_GUID \\\n %s\n" % GuidStringToGuidStructureString(Info.Guid))\r
1654\r
1655 if Info.IsLibrary:\r
1656 return\r
1657 # C file header\r
1658 AutoGenC.Append(gAutoGenHeaderString.Replace({'FileName':'AutoGen.c'}))\r
1659 if Info.AutoGenVersion >= 0x00010005:\r
1660 # C file header files includes\r
1661 if Info.ModuleType in gModuleTypeHeaderFile:\r
1662 for Inc in gModuleTypeHeaderFile[Info.ModuleType]:\r
1663 AutoGenC.Append("#include <%s>\n" % Inc)\r
1664 else:\r
1665 AutoGenC.Append("#include <%s>\n" % gBasicHeaderFile)\r
1666\r
1667 #\r
1668 # Publish the CallerId Guid\r
1669 #\r
1670 AutoGenC.Append('\nGLOBAL_REMOVE_IF_UNREFERENCED GUID gEfiCallerIdGuid = %s;\n' % GuidStringToGuidStructureString(Info.Guid))\r
1671 AutoGenC.Append('\nGLOBAL_REMOVE_IF_UNREFERENCED CHAR8 *gEfiCallerBaseName = "%s";\n' % Info.Name)\r
1672\r
1673## Create common code for header file\r
1674#\r
1675# @param Info The ModuleAutoGen object\r
1676# @param AutoGenC The TemplateString object for C code\r
1677# @param AutoGenH The TemplateString object for header file\r
1678#\r
1679def CreateFooterCode(Info, AutoGenC, AutoGenH):\r
1680 AutoGenH.Append(gAutoGenHEpilogueString)\r
1681\r
1682## Create code for a module\r
1683#\r
1684# @param Info The ModuleAutoGen object\r
1685# @param AutoGenC The TemplateString object for C code\r
1686# @param AutoGenH The TemplateString object for header file\r
1687# @param UniGenCFlag UniString is generated into AutoGen C file when it is set to True\r
1688# @param UniGenBinBuffer Buffer to store uni string package data\r
1689#\r
1690def CreateCode(Info, AutoGenC, AutoGenH, StringH, UniGenCFlag, UniGenBinBuffer):\r
1691 CreateHeaderCode(Info, AutoGenC, AutoGenH)\r
1692\r
1693 if Info.AutoGenVersion >= 0x00010005:\r
1694 CreateGuidDefinitionCode(Info, AutoGenC, AutoGenH)\r
1695 CreateProtocolDefinitionCode(Info, AutoGenC, AutoGenH)\r
1696 CreatePpiDefinitionCode(Info, AutoGenC, AutoGenH)\r
1697 CreatePcdCode(Info, AutoGenC, AutoGenH)\r
1698 CreateLibraryConstructorCode(Info, AutoGenC, AutoGenH)\r
1699 CreateLibraryDestructorCode(Info, AutoGenC, AutoGenH)\r
1700 CreateModuleEntryPointCode(Info, AutoGenC, AutoGenH)\r
1701 CreateModuleUnloadImageCode(Info, AutoGenC, AutoGenH)\r
1702\r
1703 if Info.UnicodeFileList:\r
1704 FileName = "%sStrDefs.h" % Info.Name\r
1705 StringH.Append(gAutoGenHeaderString.Replace({'FileName':FileName}))\r
1706 StringH.Append(gAutoGenHPrologueString.Replace({'File':'STRDEFS', 'Guid':Info.Guid.replace('-','_')}))\r
1707 CreateUnicodeStringCode(Info, AutoGenC, StringH, UniGenCFlag, UniGenBinBuffer)\r
8200fcfe
YL
1708\r
1709 GuidMacros = []\r
1710 for Guid in Info.Module.Guids:\r
1711 if Guid in Info.Module.GetGuidsUsedByPcd():\r
1712 continue\r
1713 GuidMacros.append('#define %s %s' % (Guid, Info.Module.Guids[Guid]))\r
1714 for Guid, Value in Info.Module.Protocols.items() + Info.Module.Ppis.items():\r
1715 GuidMacros.append('#define %s %s' % (Guid, Value))\r
1716 if GuidMacros:\r
1717 StringH.Append('\n#ifdef VFRCOMPILE\n%s\n#endif\n' % '\n'.join(GuidMacros))\r
1718\r
f51461c8
LG
1719 StringH.Append("\n#endif\n")\r
1720 AutoGenH.Append('#include "%s"\n' % FileName)\r
1721\r
1722 CreateFooterCode(Info, AutoGenC, AutoGenH)\r
1723\r
1724 # no generation of AutoGen.c for Edk modules without unicode file\r
1725 if Info.AutoGenVersion < 0x00010005 and len(Info.UnicodeFileList) == 0:\r
1726 AutoGenC.String = ''\r
1727\r
1728## Create the code file\r
1729#\r
1730# @param FilePath The path of code file\r
1731# @param Content The content of code file\r
1732# @param IsBinaryFile The flag indicating if the file is binary file or not\r
1733#\r
1734# @retval True If file content is changed or file doesn't exist\r
1735# @retval False If the file exists and the content is not changed\r
1736#\r
1737def Generate(FilePath, Content, IsBinaryFile):\r
1738 return SaveFileOnChange(FilePath, Content, IsBinaryFile)\r
1739\r