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