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