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