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