]> git.proxmox.com Git - mirror_edk2.git/blob - BaseTools/Source/Python/AutoGen/GenC.py
BaseTools: Make AutoGen.h array declaration match AutoGen.c definition
[mirror_edk2.git] / BaseTools / Source / Python / AutoGen / GenC.py
1 ## @file
2 # Routines for generating AutoGen.h and AutoGen.c
3 #
4 # Copyright (c) 2007 - 2015, Intel Corporation. All rights reserved.<BR>
5 # This program and the accompanying materials
6 # are licensed and made available under the terms and conditions of the BSD License
7 # which accompanies this distribution. The full text of the license may be found at
8 # http://opensource.org/licenses/bsd-license.php
9 #
10 # THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
11 # WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
12 #
13
14 ## Import Modules
15 #
16 import string
17
18 from Common import EdkLogger
19
20 from Common.BuildToolError import *
21 from Common.DataType import *
22 from Common.Misc import *
23 from Common.String import StringToArray
24 from StrGather import *
25 from GenPcdDb import CreatePcdDatabaseCode
26
27 ## PCD type string
28 gItemTypeStringDatabase = {
29 TAB_PCDS_FEATURE_FLAG : 'FixedAtBuild',
30 TAB_PCDS_FIXED_AT_BUILD : 'FixedAtBuild',
31 TAB_PCDS_PATCHABLE_IN_MODULE: 'BinaryPatch',
32 TAB_PCDS_DYNAMIC : '',
33 TAB_PCDS_DYNAMIC_DEFAULT : '',
34 TAB_PCDS_DYNAMIC_VPD : '',
35 TAB_PCDS_DYNAMIC_HII : '',
36 TAB_PCDS_DYNAMIC_EX : '',
37 TAB_PCDS_DYNAMIC_EX_DEFAULT : '',
38 TAB_PCDS_DYNAMIC_EX_VPD : '',
39 TAB_PCDS_DYNAMIC_EX_HII : '',
40 }
41
42 ## Dynamic PCD types
43 gDynamicPcd = [TAB_PCDS_DYNAMIC, TAB_PCDS_DYNAMIC_DEFAULT, TAB_PCDS_DYNAMIC_VPD, TAB_PCDS_DYNAMIC_HII]
44
45 ## Dynamic-ex PCD types
46 gDynamicExPcd = [TAB_PCDS_DYNAMIC_EX, TAB_PCDS_DYNAMIC_EX_DEFAULT, TAB_PCDS_DYNAMIC_EX_VPD, TAB_PCDS_DYNAMIC_EX_HII]
47
48 ## Datum size
49 gDatumSizeStringDatabase = {'UINT8':'8','UINT16':'16','UINT32':'32','UINT64':'64','BOOLEAN':'BOOLEAN','VOID*':'8'}
50 gDatumSizeStringDatabaseH = {'UINT8':'8','UINT16':'16','UINT32':'32','UINT64':'64','BOOLEAN':'BOOL','VOID*':'PTR'}
51 gDatumSizeStringDatabaseLib = {'UINT8':'8','UINT16':'16','UINT32':'32','UINT64':'64','BOOLEAN':'Bool','VOID*':'Ptr'}
52
53 ## AutoGen File Header Templates
54 gAutoGenHeaderString = TemplateString("""\
55 /**
56 DO NOT EDIT
57 FILE auto-generated
58 Module name:
59 ${FileName}
60 Abstract: Auto-generated ${FileName} for building module or library.
61 **/
62 """)
63
64 gAutoGenHPrologueString = TemplateString("""
65 #ifndef _${File}_${Guid}
66 #define _${File}_${Guid}
67
68 """)
69
70 gAutoGenHCppPrologueString = """\
71 #ifdef __cplusplus
72 extern "C" {
73 #endif
74
75 """
76
77 gAutoGenHEpilogueString = """
78
79 #ifdef __cplusplus
80 }
81 #endif
82
83 #endif
84 """
85
86 ## PEI Core Entry Point Templates
87 gPeiCoreEntryPointPrototype = TemplateString("""
88 ${BEGIN}
89 VOID
90 EFIAPI
91 ${Function} (
92 IN CONST EFI_SEC_PEI_HAND_OFF *SecCoreData,
93 IN CONST EFI_PEI_PPI_DESCRIPTOR *PpiList,
94 IN VOID *Context
95 );
96 ${END}
97 """)
98
99 gPeiCoreEntryPointString = TemplateString("""
100 ${BEGIN}
101 VOID
102 EFIAPI
103 ProcessModuleEntryPointList (
104 IN CONST EFI_SEC_PEI_HAND_OFF *SecCoreData,
105 IN CONST EFI_PEI_PPI_DESCRIPTOR *PpiList,
106 IN VOID *Context
107 )
108
109 {
110 ${Function} (SecCoreData, PpiList, Context);
111 }
112 ${END}
113 """)
114
115
116 ## DXE Core Entry Point Templates
117 gDxeCoreEntryPointPrototype = TemplateString("""
118 ${BEGIN}
119 VOID
120 EFIAPI
121 ${Function} (
122 IN VOID *HobStart
123 );
124 ${END}
125 """)
126
127 gDxeCoreEntryPointString = TemplateString("""
128 ${BEGIN}
129 VOID
130 EFIAPI
131 ProcessModuleEntryPointList (
132 IN VOID *HobStart
133 )
134
135 {
136 ${Function} (HobStart);
137 }
138 ${END}
139 """)
140
141 ## PEIM Entry Point Templates
142 gPeimEntryPointPrototype = TemplateString("""
143 ${BEGIN}
144 EFI_STATUS
145 EFIAPI
146 ${Function} (
147 IN EFI_PEI_FILE_HANDLE FileHandle,
148 IN CONST EFI_PEI_SERVICES **PeiServices
149 );
150 ${END}
151 """)
152
153 gPeimEntryPointString = [
154 TemplateString("""
155 GLOBAL_REMOVE_IF_UNREFERENCED const UINT32 _gPeimRevision = ${PiSpecVersion};
156
157 EFI_STATUS
158 EFIAPI
159 ProcessModuleEntryPointList (
160 IN EFI_PEI_FILE_HANDLE FileHandle,
161 IN CONST EFI_PEI_SERVICES **PeiServices
162 )
163
164 {
165 return EFI_SUCCESS;
166 }
167 """),
168 TemplateString("""
169 GLOBAL_REMOVE_IF_UNREFERENCED const UINT32 _gPeimRevision = ${PiSpecVersion};
170 ${BEGIN}
171 EFI_STATUS
172 EFIAPI
173 ProcessModuleEntryPointList (
174 IN EFI_PEI_FILE_HANDLE FileHandle,
175 IN CONST EFI_PEI_SERVICES **PeiServices
176 )
177
178 {
179 return ${Function} (FileHandle, PeiServices);
180 }
181 ${END}
182 """),
183 TemplateString("""
184 GLOBAL_REMOVE_IF_UNREFERENCED const UINT32 _gPeimRevision = ${PiSpecVersion};
185
186 EFI_STATUS
187 EFIAPI
188 ProcessModuleEntryPointList (
189 IN EFI_PEI_FILE_HANDLE FileHandle,
190 IN CONST EFI_PEI_SERVICES **PeiServices
191 )
192
193 {
194 EFI_STATUS Status;
195 EFI_STATUS CombinedStatus;
196
197 CombinedStatus = EFI_LOAD_ERROR;
198 ${BEGIN}
199 Status = ${Function} (FileHandle, PeiServices);
200 if (!EFI_ERROR (Status) || EFI_ERROR (CombinedStatus)) {
201 CombinedStatus = Status;
202 }
203 ${END}
204 return CombinedStatus;
205 }
206 """)
207 ]
208
209 ## SMM_CORE Entry Point Templates
210 gSmmCoreEntryPointPrototype = TemplateString("""
211 ${BEGIN}
212 EFI_STATUS
213 EFIAPI
214 ${Function} (
215 IN EFI_HANDLE ImageHandle,
216 IN EFI_SYSTEM_TABLE *SystemTable
217 );
218 ${END}
219 """)
220
221 gSmmCoreEntryPointString = TemplateString("""
222 ${BEGIN}
223 const UINT32 _gUefiDriverRevision = ${UefiSpecVersion};
224 const UINT32 _gDxeRevision = ${PiSpecVersion};
225
226 EFI_STATUS
227 EFIAPI
228 ProcessModuleEntryPointList (
229 IN EFI_HANDLE ImageHandle,
230 IN EFI_SYSTEM_TABLE *SystemTable
231 )
232 {
233 return ${Function} (ImageHandle, SystemTable);
234 }
235 ${END}
236 """)
237
238 ## DXE SMM Entry Point Templates
239 gDxeSmmEntryPointPrototype = TemplateString("""
240 ${BEGIN}
241 EFI_STATUS
242 EFIAPI
243 ${Function} (
244 IN EFI_HANDLE ImageHandle,
245 IN EFI_SYSTEM_TABLE *SystemTable
246 );
247 ${END}
248 """)
249
250 gDxeSmmEntryPointString = [
251 TemplateString("""
252 const UINT32 _gUefiDriverRevision = ${UefiSpecVersion};
253 const UINT32 _gDxeRevision = ${PiSpecVersion};
254
255 EFI_STATUS
256 EFIAPI
257 ProcessModuleEntryPointList (
258 IN EFI_HANDLE ImageHandle,
259 IN EFI_SYSTEM_TABLE *SystemTable
260 )
261
262 {
263 return EFI_SUCCESS;
264 }
265 """),
266 TemplateString("""
267 const UINT32 _gUefiDriverRevision = ${UefiSpecVersion};
268 const UINT32 _gDxeRevision = ${PiSpecVersion};
269
270 static BASE_LIBRARY_JUMP_BUFFER mJumpContext;
271 static EFI_STATUS mDriverEntryPointStatus;
272
273 VOID
274 EFIAPI
275 ExitDriver (
276 IN EFI_STATUS Status
277 )
278 {
279 if (!EFI_ERROR (Status) || EFI_ERROR (mDriverEntryPointStatus)) {
280 mDriverEntryPointStatus = Status;
281 }
282 LongJump (&mJumpContext, (UINTN)-1);
283 ASSERT (FALSE);
284 }
285
286 EFI_STATUS
287 EFIAPI
288 ProcessModuleEntryPointList (
289 IN EFI_HANDLE ImageHandle,
290 IN EFI_SYSTEM_TABLE *SystemTable
291 )
292 {
293 mDriverEntryPointStatus = EFI_LOAD_ERROR;
294
295 ${BEGIN}
296 if (SetJump (&mJumpContext) == 0) {
297 ExitDriver (${Function} (ImageHandle, SystemTable));
298 ASSERT (FALSE);
299 }
300 ${END}
301
302 return mDriverEntryPointStatus;
303 }
304 """)
305 ]
306
307 ## UEFI Driver Entry Point Templates
308 gUefiDriverEntryPointPrototype = TemplateString("""
309 ${BEGIN}
310 EFI_STATUS
311 EFIAPI
312 ${Function} (
313 IN EFI_HANDLE ImageHandle,
314 IN EFI_SYSTEM_TABLE *SystemTable
315 );
316 ${END}
317 """)
318
319 gUefiDriverEntryPointString = [
320 TemplateString("""
321 const UINT32 _gUefiDriverRevision = ${UefiSpecVersion};
322 const UINT32 _gDxeRevision = ${PiSpecVersion};
323
324 EFI_STATUS
325 EFIAPI
326 ProcessModuleEntryPointList (
327 IN EFI_HANDLE ImageHandle,
328 IN EFI_SYSTEM_TABLE *SystemTable
329 )
330 {
331 return EFI_SUCCESS;
332 }
333 """),
334 TemplateString("""
335 const UINT32 _gUefiDriverRevision = ${UefiSpecVersion};
336 const UINT32 _gDxeRevision = ${PiSpecVersion};
337
338 ${BEGIN}
339 EFI_STATUS
340 EFIAPI
341 ProcessModuleEntryPointList (
342 IN EFI_HANDLE ImageHandle,
343 IN EFI_SYSTEM_TABLE *SystemTable
344 )
345
346 {
347 return ${Function} (ImageHandle, SystemTable);
348 }
349 ${END}
350 VOID
351 EFIAPI
352 ExitDriver (
353 IN EFI_STATUS Status
354 )
355 {
356 if (EFI_ERROR (Status)) {
357 ProcessLibraryDestructorList (gImageHandle, gST);
358 }
359 gBS->Exit (gImageHandle, Status, 0, NULL);
360 }
361 """),
362 TemplateString("""
363 const UINT32 _gUefiDriverRevision = ${UefiSpecVersion};
364 const UINT32 _gDxeRevision = ${PiSpecVersion};
365
366 static BASE_LIBRARY_JUMP_BUFFER mJumpContext;
367 static EFI_STATUS mDriverEntryPointStatus;
368
369 EFI_STATUS
370 EFIAPI
371 ProcessModuleEntryPointList (
372 IN EFI_HANDLE ImageHandle,
373 IN EFI_SYSTEM_TABLE *SystemTable
374 )
375 {
376 mDriverEntryPointStatus = EFI_LOAD_ERROR;
377 ${BEGIN}
378 if (SetJump (&mJumpContext) == 0) {
379 ExitDriver (${Function} (ImageHandle, SystemTable));
380 ASSERT (FALSE);
381 }
382 ${END}
383 return mDriverEntryPointStatus;
384 }
385
386 VOID
387 EFIAPI
388 ExitDriver (
389 IN EFI_STATUS Status
390 )
391 {
392 if (!EFI_ERROR (Status) || EFI_ERROR (mDriverEntryPointStatus)) {
393 mDriverEntryPointStatus = Status;
394 }
395 LongJump (&mJumpContext, (UINTN)-1);
396 ASSERT (FALSE);
397 }
398 """)
399 ]
400
401
402 ## UEFI Application Entry Point Templates
403 gUefiApplicationEntryPointPrototype = TemplateString("""
404 ${BEGIN}
405 EFI_STATUS
406 EFIAPI
407 ${Function} (
408 IN EFI_HANDLE ImageHandle,
409 IN EFI_SYSTEM_TABLE *SystemTable
410 );
411 ${END}
412 """)
413
414 gUefiApplicationEntryPointString = [
415 TemplateString("""
416 const UINT32 _gUefiDriverRevision = ${UefiSpecVersion};
417
418 EFI_STATUS
419 EFIAPI
420 ProcessModuleEntryPointList (
421 IN EFI_HANDLE ImageHandle,
422 IN EFI_SYSTEM_TABLE *SystemTable
423 )
424 {
425 return EFI_SUCCESS;
426 }
427 """),
428 TemplateString("""
429 const UINT32 _gUefiDriverRevision = ${UefiSpecVersion};
430
431 ${BEGIN}
432 EFI_STATUS
433 EFIAPI
434 ProcessModuleEntryPointList (
435 IN EFI_HANDLE ImageHandle,
436 IN EFI_SYSTEM_TABLE *SystemTable
437 )
438
439 {
440 return ${Function} (ImageHandle, SystemTable);
441 }
442 ${END}
443 VOID
444 EFIAPI
445 ExitDriver (
446 IN EFI_STATUS Status
447 )
448 {
449 if (EFI_ERROR (Status)) {
450 ProcessLibraryDestructorList (gImageHandle, gST);
451 }
452 gBS->Exit (gImageHandle, Status, 0, NULL);
453 }
454 """),
455 TemplateString("""
456 const UINT32 _gUefiDriverRevision = ${UefiSpecVersion};
457
458 EFI_STATUS
459 EFIAPI
460 ProcessModuleEntryPointList (
461 IN EFI_HANDLE ImageHandle,
462 IN EFI_SYSTEM_TABLE *SystemTable
463 )
464
465 {
466 ${BEGIN}
467 if (SetJump (&mJumpContext) == 0) {
468 ExitDriver (${Function} (ImageHandle, SystemTable));
469 ASSERT (FALSE);
470 }
471 ${END}
472 return mDriverEntryPointStatus;
473 }
474
475 static BASE_LIBRARY_JUMP_BUFFER mJumpContext;
476 static EFI_STATUS mDriverEntryPointStatus = EFI_LOAD_ERROR;
477
478 VOID
479 EFIAPI
480 ExitDriver (
481 IN EFI_STATUS Status
482 )
483 {
484 if (!EFI_ERROR (Status) || EFI_ERROR (mDriverEntryPointStatus)) {
485 mDriverEntryPointStatus = Status;
486 }
487 LongJump (&mJumpContext, (UINTN)-1);
488 ASSERT (FALSE);
489 }
490 """)
491 ]
492
493 ## UEFI Unload Image Templates
494 gUefiUnloadImagePrototype = TemplateString("""
495 ${BEGIN}
496 EFI_STATUS
497 EFIAPI
498 ${Function} (
499 IN EFI_HANDLE ImageHandle
500 );
501 ${END}
502 """)
503
504 gUefiUnloadImageString = [
505 TemplateString("""
506 GLOBAL_REMOVE_IF_UNREFERENCED const UINT8 _gDriverUnloadImageCount = ${Count};
507
508 EFI_STATUS
509 EFIAPI
510 ProcessModuleUnloadList (
511 IN EFI_HANDLE ImageHandle
512 )
513 {
514 return EFI_SUCCESS;
515 }
516 """),
517 TemplateString("""
518 GLOBAL_REMOVE_IF_UNREFERENCED const UINT8 _gDriverUnloadImageCount = ${Count};
519
520 ${BEGIN}
521 EFI_STATUS
522 EFIAPI
523 ProcessModuleUnloadList (
524 IN EFI_HANDLE ImageHandle
525 )
526 {
527 return ${Function} (ImageHandle);
528 }
529 ${END}
530 """),
531 TemplateString("""
532 GLOBAL_REMOVE_IF_UNREFERENCED const UINT8 _gDriverUnloadImageCount = ${Count};
533
534 EFI_STATUS
535 EFIAPI
536 ProcessModuleUnloadList (
537 IN EFI_HANDLE ImageHandle
538 )
539 {
540 EFI_STATUS Status;
541
542 Status = EFI_SUCCESS;
543 ${BEGIN}
544 if (EFI_ERROR (Status)) {
545 ${Function} (ImageHandle);
546 } else {
547 Status = ${Function} (ImageHandle);
548 }
549 ${END}
550 return Status;
551 }
552 """)
553 ]
554
555 gLibraryStructorPrototype = {
556 'BASE' : TemplateString("""${BEGIN}
557 RETURN_STATUS
558 EFIAPI
559 ${Function} (
560 VOID
561 );${END}
562 """),
563
564 'PEI' : TemplateString("""${BEGIN}
565 EFI_STATUS
566 EFIAPI
567 ${Function} (
568 IN EFI_PEI_FILE_HANDLE FileHandle,
569 IN CONST EFI_PEI_SERVICES **PeiServices
570 );${END}
571 """),
572
573 'DXE' : TemplateString("""${BEGIN}
574 EFI_STATUS
575 EFIAPI
576 ${Function} (
577 IN EFI_HANDLE ImageHandle,
578 IN EFI_SYSTEM_TABLE *SystemTable
579 );${END}
580 """),
581 }
582
583 gLibraryStructorCall = {
584 'BASE' : TemplateString("""${BEGIN}
585 Status = ${Function} ();
586 ASSERT_EFI_ERROR (Status);${END}
587 """),
588
589 'PEI' : TemplateString("""${BEGIN}
590 Status = ${Function} (FileHandle, PeiServices);
591 ASSERT_EFI_ERROR (Status);${END}
592 """),
593
594 'DXE' : TemplateString("""${BEGIN}
595 Status = ${Function} (ImageHandle, SystemTable);
596 ASSERT_EFI_ERROR (Status);${END}
597 """),
598 }
599
600 ## Library Constructor and Destructor Templates
601 gLibraryString = {
602 'BASE' : TemplateString("""
603 ${BEGIN}${FunctionPrototype}${END}
604
605 VOID
606 EFIAPI
607 ProcessLibrary${Type}List (
608 VOID
609 )
610 {
611 ${BEGIN} EFI_STATUS Status;
612 ${FunctionCall}${END}
613 }
614 """),
615
616 'PEI' : TemplateString("""
617 ${BEGIN}${FunctionPrototype}${END}
618
619 VOID
620 EFIAPI
621 ProcessLibrary${Type}List (
622 IN EFI_PEI_FILE_HANDLE FileHandle,
623 IN CONST EFI_PEI_SERVICES **PeiServices
624 )
625 {
626 ${BEGIN} EFI_STATUS Status;
627 ${FunctionCall}${END}
628 }
629 """),
630
631 'DXE' : TemplateString("""
632 ${BEGIN}${FunctionPrototype}${END}
633
634 VOID
635 EFIAPI
636 ProcessLibrary${Type}List (
637 IN EFI_HANDLE ImageHandle,
638 IN EFI_SYSTEM_TABLE *SystemTable
639 )
640 {
641 ${BEGIN} EFI_STATUS Status;
642 ${FunctionCall}${END}
643 }
644 """),
645 }
646
647 gBasicHeaderFile = "Base.h"
648
649 gModuleTypeHeaderFile = {
650 "BASE" : [gBasicHeaderFile],
651 "SEC" : ["PiPei.h", "Library/DebugLib.h"],
652 "PEI_CORE" : ["PiPei.h", "Library/DebugLib.h", "Library/PeiCoreEntryPoint.h"],
653 "PEIM" : ["PiPei.h", "Library/DebugLib.h", "Library/PeimEntryPoint.h"],
654 "DXE_CORE" : ["PiDxe.h", "Library/DebugLib.h", "Library/DxeCoreEntryPoint.h"],
655 "DXE_DRIVER" : ["PiDxe.h", "Library/BaseLib.h", "Library/DebugLib.h", "Library/UefiBootServicesTableLib.h", "Library/UefiDriverEntryPoint.h"],
656 "DXE_SMM_DRIVER" : ["PiDxe.h", "Library/BaseLib.h", "Library/DebugLib.h", "Library/UefiBootServicesTableLib.h", "Library/UefiDriverEntryPoint.h"],
657 "DXE_RUNTIME_DRIVER": ["PiDxe.h", "Library/BaseLib.h", "Library/DebugLib.h", "Library/UefiBootServicesTableLib.h", "Library/UefiDriverEntryPoint.h"],
658 "DXE_SAL_DRIVER" : ["PiDxe.h", "Library/BaseLib.h", "Library/DebugLib.h", "Library/UefiBootServicesTableLib.h", "Library/UefiDriverEntryPoint.h"],
659 "UEFI_DRIVER" : ["Uefi.h", "Library/BaseLib.h", "Library/DebugLib.h", "Library/UefiBootServicesTableLib.h", "Library/UefiDriverEntryPoint.h"],
660 "UEFI_APPLICATION" : ["Uefi.h", "Library/BaseLib.h", "Library/DebugLib.h", "Library/UefiBootServicesTableLib.h", "Library/UefiApplicationEntryPoint.h"],
661 "SMM_CORE" : ["PiDxe.h", "Library/BaseLib.h", "Library/DebugLib.h", "Library/UefiDriverEntryPoint.h"],
662 "USER_DEFINED" : [gBasicHeaderFile]
663 }
664
665 ## Autogen internal worker macro to define DynamicEx PCD name includes both the TokenSpaceGuidName
666 # the TokenName and Guid comparison to avoid define name collisions.
667 #
668 # @param Info The ModuleAutoGen object
669 # @param AutoGenH The TemplateString object for header file
670 #
671 #
672 def DynExPcdTokenNumberMapping(Info, AutoGenH):
673 ExTokenCNameList = []
674 PcdExList = []
675 if Info.IsLibrary:
676 PcdList = Info.LibraryPcdList
677 else:
678 PcdList = Info.ModulePcdList
679 for Pcd in PcdList:
680 if Pcd.Type in gDynamicExPcd:
681 ExTokenCNameList.append(Pcd.TokenCName)
682 PcdExList.append(Pcd)
683 if len(ExTokenCNameList) == 0:
684 return
685 AutoGenH.Append('\n#define COMPAREGUID(Guid1, Guid2) (BOOLEAN)(*(CONST UINT64*)Guid1 == *(CONST UINT64*)Guid2 && *((CONST UINT64*)Guid1 + 1) == *((CONST UINT64*)Guid2 + 1))\n')
686 # AutoGen for each PCD listed in a [PcdEx] section of a Module/Lib INF file.
687 # Auto generate a macro for each TokenName that takes a Guid pointer as a parameter.
688 # Use the Guid pointer to see if it matches any of the token space GUIDs.
689 TokenCNameList = []
690 for TokenCName in ExTokenCNameList:
691 if TokenCName in TokenCNameList:
692 continue
693 Index = 0
694 Count = ExTokenCNameList.count(TokenCName)
695 for Pcd in PcdExList:
696 if Pcd.TokenCName == TokenCName:
697 Index = Index + 1
698 if Index == 1:
699 AutoGenH.Append('\n#define __PCD_%s_ADDR_CMP(GuidPtr) (' % (Pcd.TokenCName))
700 AutoGenH.Append('\\\n (GuidPtr == &%s) ? _PCD_TOKEN_%s_%s:'
701 % (Pcd.TokenSpaceGuidCName, Pcd.TokenSpaceGuidCName, Pcd.TokenCName))
702 else:
703 AutoGenH.Append('\\\n (GuidPtr == &%s) ? _PCD_TOKEN_%s_%s:'
704 % (Pcd.TokenSpaceGuidCName, Pcd.TokenSpaceGuidCName, Pcd.TokenCName))
705 if Index == Count:
706 AutoGenH.Append('0 \\\n )\n')
707 TokenCNameList.append(TokenCName)
708
709 TokenCNameList = []
710 for TokenCName in ExTokenCNameList:
711 if TokenCName in TokenCNameList:
712 continue
713 Index = 0
714 Count = ExTokenCNameList.count(TokenCName)
715 for Pcd in PcdExList:
716 if Pcd.Type in gDynamicExPcd and Pcd.TokenCName == TokenCName:
717 Index = Index + 1
718 if Index == 1:
719 AutoGenH.Append('\n#define __PCD_%s_VAL_CMP(GuidPtr) (' % (Pcd.TokenCName))
720 AutoGenH.Append('\\\n COMPAREGUID (GuidPtr, &%s) ? _PCD_TOKEN_%s_%s:'
721 % (Pcd.TokenSpaceGuidCName, Pcd.TokenSpaceGuidCName, Pcd.TokenCName))
722 else:
723 AutoGenH.Append('\\\n COMPAREGUID (GuidPtr, &%s) ? _PCD_TOKEN_%s_%s:'
724 % (Pcd.TokenSpaceGuidCName, Pcd.TokenSpaceGuidCName, Pcd.TokenCName))
725 if Index == Count:
726 AutoGenH.Append('0 \\\n )\n')
727 # Autogen internal worker macro to compare GUIDs. Guid1 is a pointer to a GUID.
728 # Guid2 is a C name for a GUID. Compare pointers first because optimizing compiler
729 # can do this at build time on CONST GUID pointers and optimize away call to COMPAREGUID().
730 # COMPAREGUID() will only be used if the Guid passed in is local to the module.
731 AutoGenH.Append('#define _PCD_TOKEN_EX_%s(GuidPtr) __PCD_%s_ADDR_CMP(GuidPtr) ? __PCD_%s_ADDR_CMP(GuidPtr) : __PCD_%s_VAL_CMP(GuidPtr) \n'
732 % (Pcd.TokenCName, Pcd.TokenCName, Pcd.TokenCName, Pcd.TokenCName))
733 TokenCNameList.append(TokenCName)
734
735 ## Create code for module PCDs
736 #
737 # @param Info The ModuleAutoGen object
738 # @param AutoGenC The TemplateString object for C code
739 # @param AutoGenH The TemplateString object for header file
740 # @param Pcd The PCD object
741 #
742 def CreateModulePcdCode(Info, AutoGenC, AutoGenH, Pcd):
743 TokenSpaceGuidValue = Pcd.TokenSpaceGuidValue #Info.GuidList[Pcd.TokenSpaceGuidCName]
744 PcdTokenNumber = Info.PlatformInfo.PcdTokenNumber
745 #
746 # Write PCDs
747 #
748 PcdTokenName = '_PCD_TOKEN_' + Pcd.TokenCName
749 if Pcd.Type in gDynamicExPcd:
750 TokenNumber = int(Pcd.TokenValue, 0)
751 # Add TokenSpaceGuidValue value to PcdTokenName to discriminate the DynamicEx PCDs with
752 # different Guids but same TokenCName
753 PcdExTokenName = '_PCD_TOKEN_' + Pcd.TokenSpaceGuidCName + '_' + Pcd.TokenCName
754 AutoGenH.Append('\n#define %s %dU\n' % (PcdExTokenName, TokenNumber))
755 else:
756 if (Pcd.TokenCName, Pcd.TokenSpaceGuidCName) not in PcdTokenNumber:
757 # If one of the Source built modules listed in the DSC is not listed in FDF modules,
758 # and the INF lists a PCD can only use the PcdsDynamic access method (it is only
759 # listed in the DEC file that declares the PCD as PcdsDynamic), then build tool will
760 # report warning message notify the PI that they are attempting to build a module
761 # that must be included in a flash image in order to be functional. These Dynamic PCD
762 # will not be added into the Database unless it is used by other modules that are
763 # included in the FDF file.
764 # In this case, just assign an invalid token number to make it pass build.
765 if Pcd.Type in PCD_DYNAMIC_TYPE_LIST:
766 TokenNumber = 0
767 else:
768 EdkLogger.error("build", AUTOGEN_ERROR,
769 "No generated token number for %s.%s\n" % (Pcd.TokenSpaceGuidCName, Pcd.TokenCName),
770 ExtraData="[%s]" % str(Info))
771 else:
772 TokenNumber = PcdTokenNumber[Pcd.TokenCName, Pcd.TokenSpaceGuidCName]
773 AutoGenH.Append('\n#define %s %dU\n' % (PcdTokenName, TokenNumber))
774
775 EdkLogger.debug(EdkLogger.DEBUG_3, "Creating code for " + Pcd.TokenCName + "." + Pcd.TokenSpaceGuidCName)
776 if Pcd.Type not in gItemTypeStringDatabase:
777 EdkLogger.error("build", AUTOGEN_ERROR,
778 "Unknown PCD type [%s] of PCD %s.%s" % (Pcd.Type, Pcd.TokenSpaceGuidCName, Pcd.TokenCName),
779 ExtraData="[%s]" % str(Info))
780 if Pcd.DatumType not in gDatumSizeStringDatabase:
781 EdkLogger.error("build", AUTOGEN_ERROR,
782 "Unknown datum type [%s] of PCD %s.%s" % (Pcd.DatumType, Pcd.TokenSpaceGuidCName, Pcd.TokenCName),
783 ExtraData="[%s]" % str(Info))
784
785 DatumSize = gDatumSizeStringDatabase[Pcd.DatumType]
786 DatumSizeLib = gDatumSizeStringDatabaseLib[Pcd.DatumType]
787 GetModeName = '_PCD_GET_MODE_' + gDatumSizeStringDatabaseH[Pcd.DatumType] + '_' + Pcd.TokenCName
788 SetModeName = '_PCD_SET_MODE_' + gDatumSizeStringDatabaseH[Pcd.DatumType] + '_' + Pcd.TokenCName
789 SetModeStatusName = '_PCD_SET_MODE_' + gDatumSizeStringDatabaseH[Pcd.DatumType] + '_S_' + Pcd.TokenCName
790
791 PcdExCNameList = []
792 if Pcd.Type in gDynamicExPcd:
793 if Info.IsLibrary:
794 PcdList = Info.LibraryPcdList
795 else:
796 PcdList = Info.ModulePcdList
797 for PcdModule in PcdList:
798 if PcdModule.Type in gDynamicExPcd:
799 PcdExCNameList.append(PcdModule.TokenCName)
800 # Be compatible with the current code which using PcdToken and PcdGet/Set for DynamicEx Pcd.
801 # If only PcdToken and PcdGet/Set used in all Pcds with different CName, it should succeed to build.
802 # If PcdToken and PcdGet/Set used in the Pcds with different Guids but same CName, it should failed to build.
803 if PcdExCNameList.count(Pcd.TokenCName) > 1:
804 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')
805 AutoGenH.Append('// #define %s %s\n' % (PcdTokenName, PcdExTokenName))
806 AutoGenH.Append('// #define %s LibPcdGetEx%s(&%s, %s)\n' % (GetModeName, DatumSizeLib, Pcd.TokenSpaceGuidCName, PcdTokenName))
807 if Pcd.DatumType == 'VOID*':
808 AutoGenH.Append('// #define %s(SizeOfBuffer, Buffer) LibPcdSetEx%s(&%s, %s, (SizeOfBuffer), (Buffer))\n' % (SetModeName, DatumSizeLib, Pcd.TokenSpaceGuidCName, PcdTokenName))
809 AutoGenH.Append('// #define %s(SizeOfBuffer, Buffer) LibPcdSetEx%sS(&%s, %s, (SizeOfBuffer), (Buffer))\n' % (SetModeStatusName, DatumSizeLib, Pcd.TokenSpaceGuidCName, PcdTokenName))
810 else:
811 AutoGenH.Append('// #define %s(Value) LibPcdSetEx%s(&%s, %s, (Value))\n' % (SetModeName, DatumSizeLib, Pcd.TokenSpaceGuidCName, PcdTokenName))
812 AutoGenH.Append('// #define %s(Value) LibPcdSetEx%sS(&%s, %s, (Value))\n' % (SetModeStatusName, DatumSizeLib, Pcd.TokenSpaceGuidCName, PcdTokenName))
813 else:
814 AutoGenH.Append('#define %s %s\n' % (PcdTokenName, PcdExTokenName))
815 AutoGenH.Append('#define %s LibPcdGetEx%s(&%s, %s)\n' % (GetModeName, DatumSizeLib, Pcd.TokenSpaceGuidCName, PcdTokenName))
816 if Pcd.DatumType == 'VOID*':
817 AutoGenH.Append('#define %s(SizeOfBuffer, Buffer) LibPcdSetEx%s(&%s, %s, (SizeOfBuffer), (Buffer))\n' % (SetModeName, DatumSizeLib, Pcd.TokenSpaceGuidCName, PcdTokenName))
818 AutoGenH.Append('#define %s(SizeOfBuffer, Buffer) LibPcdSetEx%sS(&%s, %s, (SizeOfBuffer), (Buffer))\n' % (SetModeStatusName, DatumSizeLib, Pcd.TokenSpaceGuidCName, PcdTokenName))
819 else:
820 AutoGenH.Append('#define %s(Value) LibPcdSetEx%s(&%s, %s, (Value))\n' % (SetModeName, DatumSizeLib, Pcd.TokenSpaceGuidCName, PcdTokenName))
821 AutoGenH.Append('#define %s(Value) LibPcdSetEx%sS(&%s, %s, (Value))\n' % (SetModeStatusName, DatumSizeLib, Pcd.TokenSpaceGuidCName, PcdTokenName))
822 elif Pcd.Type in gDynamicPcd:
823 AutoGenH.Append('#define %s LibPcdGet%s(%s)\n' % (GetModeName, DatumSizeLib, PcdTokenName))
824 if Pcd.DatumType == 'VOID*':
825 AutoGenH.Append('#define %s(SizeOfBuffer, Buffer) LibPcdSet%s(%s, (SizeOfBuffer), (Buffer))\n' %(SetModeName, DatumSizeLib, PcdTokenName))
826 AutoGenH.Append('#define %s(SizeOfBuffer, Buffer) LibPcdSet%sS(%s, (SizeOfBuffer), (Buffer))\n' % (SetModeStatusName, DatumSizeLib, PcdTokenName))
827 else:
828 AutoGenH.Append('#define %s(Value) LibPcdSet%s(%s, (Value))\n' % (SetModeName, DatumSizeLib, PcdTokenName))
829 AutoGenH.Append('#define %s(Value) LibPcdSet%sS(%s, (Value))\n' % (SetModeStatusName, DatumSizeLib, PcdTokenName))
830 else:
831 PcdVariableName = '_gPcd_' + gItemTypeStringDatabase[Pcd.Type] + '_' + Pcd.TokenCName
832 Const = 'const'
833 if Pcd.Type == TAB_PCDS_PATCHABLE_IN_MODULE:
834 Const = ''
835 Type = ''
836 Array = ''
837 Value = Pcd.DefaultValue
838 Unicode = False
839 ValueNumber = 0
840
841 if Pcd.DatumType == 'BOOLEAN':
842 BoolValue = Value.upper()
843 if BoolValue == 'TRUE' or BoolValue == '1':
844 Value = '1U'
845 elif BoolValue == 'FALSE' or BoolValue == '0':
846 Value = '0U'
847
848 if Pcd.DatumType in ['UINT64', 'UINT32', 'UINT16', 'UINT8']:
849 try:
850 if Value.upper().startswith('0X'):
851 ValueNumber = int (Value, 16)
852 else:
853 ValueNumber = int (Value)
854 except:
855 EdkLogger.error("build", AUTOGEN_ERROR,
856 "PCD value is not valid dec or hex number for datum type [%s] of PCD %s.%s" % (Pcd.DatumType, Pcd.TokenSpaceGuidCName, Pcd.TokenCName),
857 ExtraData="[%s]" % str(Info))
858 if Pcd.DatumType == 'UINT64':
859 if ValueNumber < 0:
860 EdkLogger.error("build", AUTOGEN_ERROR,
861 "PCD can't be set to negative value for datum type [%s] of PCD %s.%s" % (Pcd.DatumType, Pcd.TokenSpaceGuidCName, Pcd.TokenCName),
862 ExtraData="[%s]" % str(Info))
863 elif ValueNumber >= 0x10000000000000000:
864 EdkLogger.error("build", AUTOGEN_ERROR,
865 "Too large PCD value for datum type [%s] of PCD %s.%s" % (Pcd.DatumType, Pcd.TokenSpaceGuidCName, Pcd.TokenCName),
866 ExtraData="[%s]" % str(Info))
867 if not Value.endswith('ULL'):
868 Value += 'ULL'
869 elif Pcd.DatumType == 'UINT32':
870 if ValueNumber < 0:
871 EdkLogger.error("build", AUTOGEN_ERROR,
872 "PCD can't be set to negative value for datum type [%s] of PCD %s.%s" % (Pcd.DatumType, Pcd.TokenSpaceGuidCName, Pcd.TokenCName),
873 ExtraData="[%s]" % str(Info))
874 elif ValueNumber >= 0x100000000:
875 EdkLogger.error("build", AUTOGEN_ERROR,
876 "Too large PCD value for datum type [%s] of PCD %s.%s" % (Pcd.DatumType, Pcd.TokenSpaceGuidCName, Pcd.TokenCName),
877 ExtraData="[%s]" % str(Info))
878 if not Value.endswith('U'):
879 Value += 'U'
880 elif Pcd.DatumType == 'UINT16':
881 if ValueNumber < 0:
882 EdkLogger.error("build", AUTOGEN_ERROR,
883 "PCD can't be set to negative value for datum type [%s] of PCD %s.%s" % (Pcd.DatumType, Pcd.TokenSpaceGuidCName, Pcd.TokenCName),
884 ExtraData="[%s]" % str(Info))
885 elif ValueNumber >= 0x10000:
886 EdkLogger.error("build", AUTOGEN_ERROR,
887 "Too large PCD value for datum type [%s] of PCD %s.%s" % (Pcd.DatumType, Pcd.TokenSpaceGuidCName, Pcd.TokenCName),
888 ExtraData="[%s]" % str(Info))
889 if not Value.endswith('U'):
890 Value += 'U'
891 elif Pcd.DatumType == 'UINT8':
892 if ValueNumber < 0:
893 EdkLogger.error("build", AUTOGEN_ERROR,
894 "PCD can't be set to negative value for datum type [%s] of PCD %s.%s" % (Pcd.DatumType, Pcd.TokenSpaceGuidCName, Pcd.TokenCName),
895 ExtraData="[%s]" % str(Info))
896 elif ValueNumber >= 0x100:
897 EdkLogger.error("build", AUTOGEN_ERROR,
898 "Too large PCD value for datum type [%s] of PCD %s.%s" % (Pcd.DatumType, Pcd.TokenSpaceGuidCName, Pcd.TokenCName),
899 ExtraData="[%s]" % str(Info))
900 if not Value.endswith('U'):
901 Value += 'U'
902 if Pcd.DatumType == 'VOID*':
903 if Pcd.MaxDatumSize == None or Pcd.MaxDatumSize == '':
904 EdkLogger.error("build", AUTOGEN_ERROR,
905 "Unknown [MaxDatumSize] of PCD [%s.%s]" % (Pcd.TokenSpaceGuidCName, Pcd.TokenCName),
906 ExtraData="[%s]" % str(Info))
907
908 ArraySize = int(Pcd.MaxDatumSize, 0)
909 if Value[0] == '{':
910 Type = '(VOID *)'
911 else:
912 if Value[0] == 'L':
913 Unicode = True
914 Value = Value.lstrip('L') #.strip('"')
915 Value = eval(Value) # translate escape character
916 NewValue = '{'
917 for Index in range(0,len(Value)):
918 if Unicode:
919 NewValue = NewValue + str(ord(Value[Index]) % 0x10000) + ', '
920 else:
921 NewValue = NewValue + str(ord(Value[Index]) % 0x100) + ', '
922 if Unicode:
923 ArraySize = ArraySize / 2;
924
925 if ArraySize < (len(Value) + 1):
926 EdkLogger.error("build", AUTOGEN_ERROR,
927 "The maximum size of VOID* type PCD '%s.%s' is less than its actual size occupied." % (Pcd.TokenSpaceGuidCName, Pcd.TokenCName),
928 ExtraData="[%s]" % str(Info))
929 Value = NewValue + '0 }'
930 Array = '[%d]' % ArraySize
931 #
932 # skip casting for fixed at build since it breaks ARM assembly.
933 # Long term we need PCD macros that work in assembly
934 #
935 elif Pcd.Type != TAB_PCDS_FIXED_AT_BUILD:
936 Value = "((%s)%s)" % (Pcd.DatumType, Value)
937
938 if Pcd.Type == TAB_PCDS_PATCHABLE_IN_MODULE:
939 PcdValueName = '_PCD_PATCHABLE_VALUE_' + Pcd.TokenCName
940 else:
941 PcdValueName = '_PCD_VALUE_' + Pcd.TokenCName
942
943 if Pcd.DatumType == 'VOID*':
944 #
945 # For unicode, UINT16 array will be generated, so the alignment of unicode is guaranteed.
946 #
947 if Unicode:
948 AutoGenH.Append('#define _PCD_PATCHABLE_%s_SIZE %s\n' % (Pcd.TokenCName, Pcd.MaxDatumSize))
949 AutoGenH.Append('#define %s %s%s\n' %(PcdValueName, Type, PcdVariableName))
950 AutoGenC.Append('GLOBAL_REMOVE_IF_UNREFERENCED %s UINT16 %s%s = %s;\n' % (Const, PcdVariableName, Array, Value))
951 AutoGenH.Append('extern %s UINT16 %s%s;\n' %(Const, PcdVariableName, Array))
952 AutoGenH.Append('#define %s %s%s\n' %(GetModeName, Type, PcdVariableName))
953 else:
954 AutoGenH.Append('#define _PCD_PATCHABLE_%s_SIZE %s\n' % (Pcd.TokenCName, Pcd.MaxDatumSize))
955 AutoGenH.Append('#define %s %s%s\n' %(PcdValueName, Type, PcdVariableName))
956 AutoGenC.Append('GLOBAL_REMOVE_IF_UNREFERENCED %s UINT8 %s%s = %s;\n' % (Const, PcdVariableName, Array, Value))
957 AutoGenH.Append('extern %s UINT8 %s%s;\n' %(Const, PcdVariableName, Array))
958 AutoGenH.Append('#define %s %s%s\n' %(GetModeName, Type, PcdVariableName))
959 elif Pcd.Type == TAB_PCDS_PATCHABLE_IN_MODULE:
960 AutoGenH.Append('#define %s %s\n' %(PcdValueName, Value))
961 AutoGenC.Append('volatile %s %s %s = %s;\n' %(Const, Pcd.DatumType, PcdVariableName, PcdValueName))
962 AutoGenH.Append('extern volatile %s %s %s%s;\n' % (Const, Pcd.DatumType, PcdVariableName, Array))
963 AutoGenH.Append('#define %s %s%s\n' % (GetModeName, Type, PcdVariableName))
964 else:
965 AutoGenH.Append('#define %s %s\n' %(PcdValueName, Value))
966 AutoGenC.Append('GLOBAL_REMOVE_IF_UNREFERENCED %s %s %s = %s;\n' %(Const, Pcd.DatumType, PcdVariableName, PcdValueName))
967 AutoGenH.Append('extern %s %s %s%s;\n' % (Const, Pcd.DatumType, PcdVariableName, Array))
968 AutoGenH.Append('#define %s %s%s\n' % (GetModeName, Type, PcdVariableName))
969
970 if Pcd.Type == TAB_PCDS_PATCHABLE_IN_MODULE:
971 if Pcd.DatumType == 'VOID*':
972 AutoGenH.Append('#define %s(SizeOfBuffer, Buffer) LibPatchPcdSetPtr(_gPcd_BinaryPatch_%s, (UINTN)_PCD_PATCHABLE_%s_SIZE, (SizeOfBuffer), (Buffer))\n' % (SetModeName, Pcd.TokenCName, Pcd.TokenCName))
973 AutoGenH.Append('#define %s(SizeOfBuffer, Buffer) LibPatchPcdSetPtrS(_gPcd_BinaryPatch_%s, (UINTN)_PCD_PATCHABLE_%s_SIZE, (SizeOfBuffer), (Buffer))\n' % (SetModeStatusName, Pcd.TokenCName, Pcd.TokenCName))
974 else:
975 AutoGenH.Append('#define %s(Value) (%s = (Value))\n' % (SetModeName, PcdVariableName))
976 AutoGenH.Append('#define %s(Value) ((%s = (Value)), RETURN_SUCCESS) \n' % (SetModeStatusName, PcdVariableName))
977 else:
978 AutoGenH.Append('//#define %s ASSERT(FALSE) // It is not allowed to set value for a FIXED_AT_BUILD PCD\n' % SetModeName)
979
980 ## Create code for library module PCDs
981 #
982 # @param Info The ModuleAutoGen object
983 # @param AutoGenC The TemplateString object for C code
984 # @param AutoGenH The TemplateString object for header file
985 # @param Pcd The PCD object
986 #
987 def CreateLibraryPcdCode(Info, AutoGenC, AutoGenH, Pcd):
988 PcdTokenNumber = Info.PlatformInfo.PcdTokenNumber
989 TokenSpaceGuidCName = Pcd.TokenSpaceGuidCName
990 TokenCName = Pcd.TokenCName
991 PcdTokenName = '_PCD_TOKEN_' + TokenCName
992 #
993 # Write PCDs
994 #
995 if Pcd.Type in gDynamicExPcd:
996 TokenNumber = int(Pcd.TokenValue, 0)
997 else:
998 if (Pcd.TokenCName, Pcd.TokenSpaceGuidCName) not in PcdTokenNumber:
999 # If one of the Source built modules listed in the DSC is not listed in FDF modules,
1000 # and the INF lists a PCD can only use the PcdsDynamic access method (it is only
1001 # listed in the DEC file that declares the PCD as PcdsDynamic), then build tool will
1002 # report warning message notify the PI that they are attempting to build a module
1003 # that must be included in a flash image in order to be functional. These Dynamic PCD
1004 # will not be added into the Database unless it is used by other modules that are
1005 # included in the FDF file.
1006 # In this case, just assign an invalid token number to make it pass build.
1007 if Pcd.Type in PCD_DYNAMIC_TYPE_LIST:
1008 TokenNumber = 0
1009 else:
1010 EdkLogger.error("build", AUTOGEN_ERROR,
1011 "No generated token number for %s.%s\n" % (Pcd.TokenSpaceGuidCName, Pcd.TokenCName),
1012 ExtraData="[%s]" % str(Info))
1013 else:
1014 TokenNumber = PcdTokenNumber[Pcd.TokenCName, Pcd.TokenSpaceGuidCName]
1015
1016 if Pcd.Type not in gItemTypeStringDatabase:
1017 EdkLogger.error("build", AUTOGEN_ERROR,
1018 "Unknown PCD type [%s] of PCD %s.%s" % (Pcd.Type, Pcd.TokenSpaceGuidCName, Pcd.TokenCName),
1019 ExtraData="[%s]" % str(Info))
1020 if Pcd.DatumType not in gDatumSizeStringDatabase:
1021 EdkLogger.error("build", AUTOGEN_ERROR,
1022 "Unknown datum type [%s] of PCD %s.%s" % (Pcd.DatumType, Pcd.TokenSpaceGuidCName, Pcd.TokenCName),
1023 ExtraData="[%s]" % str(Info))
1024
1025 DatumType = Pcd.DatumType
1026 DatumSize = gDatumSizeStringDatabaseH[DatumType]
1027 DatumSizeLib= gDatumSizeStringDatabaseLib[DatumType]
1028 GetModeName = '_PCD_GET_MODE_' + DatumSize + '_' + TokenCName
1029 SetModeName = '_PCD_SET_MODE_' + DatumSize + '_' + TokenCName
1030 SetModeStatusName = '_PCD_SET_MODE_' + DatumSize + '_S_' + TokenCName
1031
1032 Type = ''
1033 Array = ''
1034 if Pcd.DatumType == 'VOID*':
1035 Type = '(VOID *)'
1036 Array = '[]'
1037 PcdItemType = Pcd.Type
1038 PcdExCNameList = []
1039 if PcdItemType in gDynamicExPcd:
1040 PcdExTokenName = '_PCD_TOKEN_' + TokenSpaceGuidCName + '_' + Pcd.TokenCName
1041 AutoGenH.Append('\n#define %s %dU\n' % (PcdExTokenName, TokenNumber))
1042
1043 if Info.IsLibrary:
1044 PcdList = Info.LibraryPcdList
1045 else:
1046 PcdList = Info.ModulePcdList
1047 for PcdModule in PcdList:
1048 if PcdModule.Type in gDynamicExPcd:
1049 PcdExCNameList.append(PcdModule.TokenCName)
1050 # Be compatible with the current code which using PcdGet/Set for DynamicEx Pcd.
1051 # If only PcdGet/Set used in all Pcds with different CName, it should succeed to build.
1052 # If PcdGet/Set used in the Pcds with different Guids but same CName, it should failed to build.
1053 if PcdExCNameList.count(Pcd.TokenCName) > 1:
1054 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')
1055 AutoGenH.Append('// #define %s %s\n' % (PcdTokenName, PcdExTokenName))
1056 AutoGenH.Append('// #define %s LibPcdGetEx%s(&%s, %s)\n' % (GetModeName, DatumSizeLib, Pcd.TokenSpaceGuidCName, PcdTokenName))
1057 if Pcd.DatumType == 'VOID*':
1058 AutoGenH.Append('// #define %s(SizeOfBuffer, Buffer) LibPcdSetEx%s(&%s, %s, (SizeOfBuffer), (Buffer))\n' % (SetModeName, DatumSizeLib, Pcd.TokenSpaceGuidCName, PcdTokenName))
1059 AutoGenH.Append('// #define %s(SizeOfBuffer, Buffer) LibPcdSetEx%sS(&%s, %s, (SizeOfBuffer), (Buffer))\n' % (SetModeStatusName, DatumSizeLib, Pcd.TokenSpaceGuidCName, PcdTokenName))
1060 else:
1061 AutoGenH.Append('// #define %s(Value) LibPcdSetEx%s(&%s, %s, (Value))\n' % (SetModeName, DatumSizeLib, Pcd.TokenSpaceGuidCName, PcdTokenName))
1062 AutoGenH.Append('// #define %s(Value) LibPcdSetEx%sS(&%s, %s, (Value))\n' % (SetModeStatusName, DatumSizeLib, Pcd.TokenSpaceGuidCName, PcdTokenName))
1063 else:
1064 AutoGenH.Append('#define %s %s\n' % (PcdTokenName, PcdExTokenName))
1065 AutoGenH.Append('#define %s LibPcdGetEx%s(&%s, %s)\n' % (GetModeName, DatumSizeLib, Pcd.TokenSpaceGuidCName, PcdTokenName))
1066 if Pcd.DatumType == 'VOID*':
1067 AutoGenH.Append('#define %s(SizeOfBuffer, Buffer) LibPcdSetEx%s(&%s, %s, (SizeOfBuffer), (Buffer))\n' % (SetModeName, DatumSizeLib, Pcd.TokenSpaceGuidCName, PcdTokenName))
1068 AutoGenH.Append('#define %s(SizeOfBuffer, Buffer) LibPcdSetEx%sS(&%s, %s, (SizeOfBuffer), (Buffer))\n' % (SetModeStatusName, DatumSizeLib, Pcd.TokenSpaceGuidCName, PcdTokenName))
1069 else:
1070 AutoGenH.Append('#define %s(Value) LibPcdSetEx%s(&%s, %s, (Value))\n' % (SetModeName, DatumSizeLib, Pcd.TokenSpaceGuidCName, PcdTokenName))
1071 AutoGenH.Append('#define %s(Value) LibPcdSetEx%sS(&%s, %s, (Value))\n' % (SetModeStatusName, DatumSizeLib, Pcd.TokenSpaceGuidCName, PcdTokenName))
1072 else:
1073 AutoGenH.Append('#define _PCD_TOKEN_%s %dU\n' % (TokenCName, TokenNumber))
1074 if PcdItemType in gDynamicPcd:
1075 AutoGenH.Append('#define %s LibPcdGet%s(%s)\n' % (GetModeName, DatumSizeLib, PcdTokenName))
1076 if DatumType == 'VOID*':
1077 AutoGenH.Append('#define %s(SizeOfBuffer, Buffer) LibPcdSet%s(%s, (SizeOfBuffer), (Buffer))\n' %(SetModeName, DatumSizeLib, PcdTokenName))
1078 AutoGenH.Append('#define %s(SizeOfBuffer, Buffer) LibPcdSet%sS(%s, (SizeOfBuffer), (Buffer))\n' % (SetModeStatusName, DatumSizeLib, PcdTokenName))
1079 else:
1080 AutoGenH.Append('#define %s(Value) LibPcdSet%s(%s, (Value))\n' % (SetModeName, DatumSizeLib, PcdTokenName))
1081 AutoGenH.Append('#define %s(Value) LibPcdSet%sS(%s, (Value))\n' % (SetModeStatusName, DatumSizeLib, PcdTokenName))
1082 if PcdItemType == TAB_PCDS_PATCHABLE_IN_MODULE:
1083 PcdVariableName = '_gPcd_' + gItemTypeStringDatabase[TAB_PCDS_PATCHABLE_IN_MODULE] + '_' + TokenCName
1084 AutoGenH.Append('extern volatile %s _gPcd_BinaryPatch_%s%s;\n' %(DatumType, TokenCName, Array) )
1085 AutoGenH.Append('#define %s %s_gPcd_BinaryPatch_%s\n' %(GetModeName, Type, TokenCName))
1086 AutoGenH.Append('#define %s(Value) (%s = (Value))\n' % (SetModeName, PcdVariableName))
1087 AutoGenH.Append('#define %s(Value) ((%s = (Value)), RETURN_SUCCESS)\n' % (SetModeStatusName, PcdVariableName))
1088 if PcdItemType == TAB_PCDS_FIXED_AT_BUILD or PcdItemType == TAB_PCDS_FEATURE_FLAG:
1089 key = ".".join((Pcd.TokenSpaceGuidCName,Pcd.TokenCName))
1090
1091 if DatumType == 'VOID*' and Array == '[]':
1092 DatumType = ['UINT8', 'UINT16'][Pcd.DefaultValue[0] == 'L']
1093 AutoGenH.Append('extern const %s _gPcd_FixedAtBuild_%s%s;\n' %(DatumType, TokenCName, Array))
1094 AutoGenH.Append('#define %s %s_gPcd_FixedAtBuild_%s\n' %(GetModeName, Type, TokenCName))
1095 AutoGenH.Append('//#define %s ASSERT(FALSE) // It is not allowed to set value for a FIXED_AT_BUILD PCD\n' % SetModeName)
1096
1097 if PcdItemType == TAB_PCDS_FIXED_AT_BUILD and key in Info.ConstPcd:
1098 AutoGenH.Append('#define _PCD_VALUE_%s %s\n' %(TokenCName, Pcd.DefaultValue))
1099
1100
1101
1102 ## Create code for library constructor
1103 #
1104 # @param Info The ModuleAutoGen object
1105 # @param AutoGenC The TemplateString object for C code
1106 # @param AutoGenH The TemplateString object for header file
1107 #
1108 def CreateLibraryConstructorCode(Info, AutoGenC, AutoGenH):
1109 #
1110 # Library Constructors
1111 #
1112 ConstructorPrototypeString = TemplateString()
1113 ConstructorCallingString = TemplateString()
1114 if Info.IsLibrary:
1115 DependentLibraryList = [Info.Module]
1116 else:
1117 DependentLibraryList = Info.DependentLibraryList
1118 for Lib in DependentLibraryList:
1119 if len(Lib.ConstructorList) <= 0:
1120 continue
1121 Dict = {'Function':Lib.ConstructorList}
1122 if Lib.ModuleType in ['BASE', 'SEC']:
1123 ConstructorPrototypeString.Append(gLibraryStructorPrototype['BASE'].Replace(Dict))
1124 ConstructorCallingString.Append(gLibraryStructorCall['BASE'].Replace(Dict))
1125 elif Lib.ModuleType in ['PEI_CORE','PEIM']:
1126 ConstructorPrototypeString.Append(gLibraryStructorPrototype['PEI'].Replace(Dict))
1127 ConstructorCallingString.Append(gLibraryStructorCall['PEI'].Replace(Dict))
1128 elif Lib.ModuleType in ['DXE_CORE','DXE_DRIVER','DXE_SMM_DRIVER','DXE_RUNTIME_DRIVER',
1129 'DXE_SAL_DRIVER','UEFI_DRIVER','UEFI_APPLICATION','SMM_CORE']:
1130 ConstructorPrototypeString.Append(gLibraryStructorPrototype['DXE'].Replace(Dict))
1131 ConstructorCallingString.Append(gLibraryStructorCall['DXE'].Replace(Dict))
1132
1133 if str(ConstructorPrototypeString) == '':
1134 ConstructorPrototypeList = []
1135 else:
1136 ConstructorPrototypeList = [str(ConstructorPrototypeString)]
1137 if str(ConstructorCallingString) == '':
1138 ConstructorCallingList = []
1139 else:
1140 ConstructorCallingList = [str(ConstructorCallingString)]
1141
1142 Dict = {
1143 'Type' : 'Constructor',
1144 'FunctionPrototype' : ConstructorPrototypeList,
1145 'FunctionCall' : ConstructorCallingList
1146 }
1147 if Info.IsLibrary:
1148 AutoGenH.Append("${BEGIN}${FunctionPrototype}${END}", Dict)
1149 else:
1150 if Info.ModuleType in ['BASE', 'SEC']:
1151 AutoGenC.Append(gLibraryString['BASE'].Replace(Dict))
1152 elif Info.ModuleType in ['PEI_CORE','PEIM']:
1153 AutoGenC.Append(gLibraryString['PEI'].Replace(Dict))
1154 elif Info.ModuleType in ['DXE_CORE','DXE_DRIVER','DXE_SMM_DRIVER','DXE_RUNTIME_DRIVER',
1155 'DXE_SAL_DRIVER','UEFI_DRIVER','UEFI_APPLICATION','SMM_CORE']:
1156 AutoGenC.Append(gLibraryString['DXE'].Replace(Dict))
1157
1158 ## Create code for library destructor
1159 #
1160 # @param Info The ModuleAutoGen object
1161 # @param AutoGenC The TemplateString object for C code
1162 # @param AutoGenH The TemplateString object for header file
1163 #
1164 def CreateLibraryDestructorCode(Info, AutoGenC, AutoGenH):
1165 #
1166 # Library Destructors
1167 #
1168 DestructorPrototypeString = TemplateString()
1169 DestructorCallingString = TemplateString()
1170 if Info.IsLibrary:
1171 DependentLibraryList = [Info.Module]
1172 else:
1173 DependentLibraryList = Info.DependentLibraryList
1174 for Index in range(len(DependentLibraryList)-1, -1, -1):
1175 Lib = DependentLibraryList[Index]
1176 if len(Lib.DestructorList) <= 0:
1177 continue
1178 Dict = {'Function':Lib.DestructorList}
1179 if Lib.ModuleType in ['BASE', 'SEC']:
1180 DestructorPrototypeString.Append(gLibraryStructorPrototype['BASE'].Replace(Dict))
1181 DestructorCallingString.Append(gLibraryStructorCall['BASE'].Replace(Dict))
1182 elif Lib.ModuleType in ['PEI_CORE','PEIM']:
1183 DestructorPrototypeString.Append(gLibraryStructorPrototype['PEI'].Replace(Dict))
1184 DestructorCallingString.Append(gLibraryStructorCall['PEI'].Replace(Dict))
1185 elif Lib.ModuleType in ['DXE_CORE','DXE_DRIVER','DXE_SMM_DRIVER','DXE_RUNTIME_DRIVER',
1186 'DXE_SAL_DRIVER','UEFI_DRIVER','UEFI_APPLICATION', 'SMM_CORE']:
1187 DestructorPrototypeString.Append(gLibraryStructorPrototype['DXE'].Replace(Dict))
1188 DestructorCallingString.Append(gLibraryStructorCall['DXE'].Replace(Dict))
1189
1190 if str(DestructorPrototypeString) == '':
1191 DestructorPrototypeList = []
1192 else:
1193 DestructorPrototypeList = [str(DestructorPrototypeString)]
1194 if str(DestructorCallingString) == '':
1195 DestructorCallingList = []
1196 else:
1197 DestructorCallingList = [str(DestructorCallingString)]
1198
1199 Dict = {
1200 'Type' : 'Destructor',
1201 'FunctionPrototype' : DestructorPrototypeList,
1202 'FunctionCall' : DestructorCallingList
1203 }
1204 if Info.IsLibrary:
1205 AutoGenH.Append("${BEGIN}${FunctionPrototype}${END}", Dict)
1206 else:
1207 if Info.ModuleType in ['BASE', 'SEC']:
1208 AutoGenC.Append(gLibraryString['BASE'].Replace(Dict))
1209 elif Info.ModuleType in ['PEI_CORE','PEIM']:
1210 AutoGenC.Append(gLibraryString['PEI'].Replace(Dict))
1211 elif Info.ModuleType in ['DXE_CORE','DXE_DRIVER','DXE_SMM_DRIVER','DXE_RUNTIME_DRIVER',
1212 'DXE_SAL_DRIVER','UEFI_DRIVER','UEFI_APPLICATION','SMM_CORE']:
1213 AutoGenC.Append(gLibraryString['DXE'].Replace(Dict))
1214
1215
1216 ## Create code for ModuleEntryPoint
1217 #
1218 # @param Info The ModuleAutoGen object
1219 # @param AutoGenC The TemplateString object for C code
1220 # @param AutoGenH The TemplateString object for header file
1221 #
1222 def CreateModuleEntryPointCode(Info, AutoGenC, AutoGenH):
1223 if Info.IsLibrary or Info.ModuleType in ['USER_DEFINED', 'SEC']:
1224 return
1225 #
1226 # Module Entry Points
1227 #
1228 NumEntryPoints = len(Info.Module.ModuleEntryPointList)
1229 if 'PI_SPECIFICATION_VERSION' in Info.Module.Specification:
1230 PiSpecVersion = Info.Module.Specification['PI_SPECIFICATION_VERSION']
1231 else:
1232 PiSpecVersion = '0x00000000'
1233 if 'UEFI_SPECIFICATION_VERSION' in Info.Module.Specification:
1234 UefiSpecVersion = Info.Module.Specification['UEFI_SPECIFICATION_VERSION']
1235 else:
1236 UefiSpecVersion = '0x00000000'
1237 Dict = {
1238 'Function' : Info.Module.ModuleEntryPointList,
1239 'PiSpecVersion' : PiSpecVersion + 'U',
1240 'UefiSpecVersion': UefiSpecVersion + 'U'
1241 }
1242
1243 if Info.ModuleType in ['PEI_CORE', 'DXE_CORE', 'SMM_CORE']:
1244 if Info.SourceFileList <> None and Info.SourceFileList <> []:
1245 if NumEntryPoints != 1:
1246 EdkLogger.error(
1247 "build",
1248 AUTOGEN_ERROR,
1249 '%s must have exactly one entry point' % Info.ModuleType,
1250 File=str(Info),
1251 ExtraData= ", ".join(Info.Module.ModuleEntryPointList)
1252 )
1253 if Info.ModuleType == 'PEI_CORE':
1254 AutoGenC.Append(gPeiCoreEntryPointString.Replace(Dict))
1255 AutoGenH.Append(gPeiCoreEntryPointPrototype.Replace(Dict))
1256 elif Info.ModuleType == 'DXE_CORE':
1257 AutoGenC.Append(gDxeCoreEntryPointString.Replace(Dict))
1258 AutoGenH.Append(gDxeCoreEntryPointPrototype.Replace(Dict))
1259 elif Info.ModuleType == 'SMM_CORE':
1260 AutoGenC.Append(gSmmCoreEntryPointString.Replace(Dict))
1261 AutoGenH.Append(gSmmCoreEntryPointPrototype.Replace(Dict))
1262 elif Info.ModuleType == 'PEIM':
1263 if NumEntryPoints < 2:
1264 AutoGenC.Append(gPeimEntryPointString[NumEntryPoints].Replace(Dict))
1265 else:
1266 AutoGenC.Append(gPeimEntryPointString[2].Replace(Dict))
1267 AutoGenH.Append(gPeimEntryPointPrototype.Replace(Dict))
1268 elif Info.ModuleType in ['DXE_RUNTIME_DRIVER','DXE_DRIVER','DXE_SAL_DRIVER','UEFI_DRIVER']:
1269 if NumEntryPoints < 2:
1270 AutoGenC.Append(gUefiDriverEntryPointString[NumEntryPoints].Replace(Dict))
1271 else:
1272 AutoGenC.Append(gUefiDriverEntryPointString[2].Replace(Dict))
1273 AutoGenH.Append(gUefiDriverEntryPointPrototype.Replace(Dict))
1274 elif Info.ModuleType == 'DXE_SMM_DRIVER':
1275 if NumEntryPoints == 0:
1276 AutoGenC.Append(gDxeSmmEntryPointString[0].Replace(Dict))
1277 else:
1278 AutoGenC.Append(gDxeSmmEntryPointString[1].Replace(Dict))
1279 AutoGenH.Append(gDxeSmmEntryPointPrototype.Replace(Dict))
1280 elif Info.ModuleType == 'UEFI_APPLICATION':
1281 if NumEntryPoints < 2:
1282 AutoGenC.Append(gUefiApplicationEntryPointString[NumEntryPoints].Replace(Dict))
1283 else:
1284 AutoGenC.Append(gUefiApplicationEntryPointString[2].Replace(Dict))
1285 AutoGenH.Append(gUefiApplicationEntryPointPrototype.Replace(Dict))
1286
1287 ## Create code for ModuleUnloadImage
1288 #
1289 # @param Info The ModuleAutoGen object
1290 # @param AutoGenC The TemplateString object for C code
1291 # @param AutoGenH The TemplateString object for header file
1292 #
1293 def CreateModuleUnloadImageCode(Info, AutoGenC, AutoGenH):
1294 if Info.IsLibrary or Info.ModuleType in ['USER_DEFINED', 'SEC']:
1295 return
1296 #
1297 # Unload Image Handlers
1298 #
1299 NumUnloadImage = len(Info.Module.ModuleUnloadImageList)
1300 Dict = {'Count':str(NumUnloadImage) + 'U', 'Function':Info.Module.ModuleUnloadImageList}
1301 if NumUnloadImage < 2:
1302 AutoGenC.Append(gUefiUnloadImageString[NumUnloadImage].Replace(Dict))
1303 else:
1304 AutoGenC.Append(gUefiUnloadImageString[2].Replace(Dict))
1305 AutoGenH.Append(gUefiUnloadImagePrototype.Replace(Dict))
1306
1307 ## Create code for GUID
1308 #
1309 # @param Info The ModuleAutoGen object
1310 # @param AutoGenC The TemplateString object for C code
1311 # @param AutoGenH The TemplateString object for header file
1312 #
1313 def CreateGuidDefinitionCode(Info, AutoGenC, AutoGenH):
1314 if Info.IsLibrary:
1315 return
1316
1317 if Info.ModuleType in ["USER_DEFINED", "BASE"]:
1318 GuidType = "GUID"
1319 else:
1320 GuidType = "EFI_GUID"
1321
1322 if Info.GuidList:
1323 AutoGenC.Append("\n// Guids\n")
1324 AutoGenH.Append("\n// Guids\n")
1325 #
1326 # GUIDs
1327 #
1328 for Key in Info.GuidList:
1329 AutoGenC.Append('GLOBAL_REMOVE_IF_UNREFERENCED %s %s = %s;\n' % (GuidType, Key, Info.GuidList[Key]))
1330 AutoGenH.Append('extern %s %s;\n' % (GuidType, Key))
1331
1332 ## Create code for protocol
1333 #
1334 # @param Info The ModuleAutoGen object
1335 # @param AutoGenC The TemplateString object for C code
1336 # @param AutoGenH The TemplateString object for header file
1337 #
1338 def CreateProtocolDefinitionCode(Info, AutoGenC, AutoGenH):
1339 if Info.IsLibrary:
1340 return
1341
1342 if Info.ModuleType in ["USER_DEFINED", "BASE"]:
1343 GuidType = "GUID"
1344 else:
1345 GuidType = "EFI_GUID"
1346
1347 if Info.ProtocolList:
1348 AutoGenC.Append("\n// Protocols\n")
1349 AutoGenH.Append("\n// Protocols\n")
1350 #
1351 # Protocol GUIDs
1352 #
1353 for Key in Info.ProtocolList:
1354 AutoGenC.Append('GLOBAL_REMOVE_IF_UNREFERENCED %s %s = %s;\n' % (GuidType, Key, Info.ProtocolList[Key]))
1355 AutoGenH.Append('extern %s %s;\n' % (GuidType, Key))
1356
1357 ## Create code for PPI
1358 #
1359 # @param Info The ModuleAutoGen object
1360 # @param AutoGenC The TemplateString object for C code
1361 # @param AutoGenH The TemplateString object for header file
1362 #
1363 def CreatePpiDefinitionCode(Info, AutoGenC, AutoGenH):
1364 if Info.IsLibrary:
1365 return
1366
1367 if Info.ModuleType in ["USER_DEFINED", "BASE"]:
1368 GuidType = "GUID"
1369 else:
1370 GuidType = "EFI_GUID"
1371
1372 if Info.PpiList:
1373 AutoGenC.Append("\n// PPIs\n")
1374 AutoGenH.Append("\n// PPIs\n")
1375 #
1376 # PPI GUIDs
1377 #
1378 for Key in Info.PpiList:
1379 AutoGenC.Append('GLOBAL_REMOVE_IF_UNREFERENCED %s %s = %s;\n' % (GuidType, Key, Info.PpiList[Key]))
1380 AutoGenH.Append('extern %s %s;\n' % (GuidType, Key))
1381
1382 ## Create code for PCD
1383 #
1384 # @param Info The ModuleAutoGen object
1385 # @param AutoGenC The TemplateString object for C code
1386 # @param AutoGenH The TemplateString object for header file
1387 #
1388 def CreatePcdCode(Info, AutoGenC, AutoGenH):
1389
1390 # Collect Token Space GUIDs used by DynamicEc PCDs
1391 TokenSpaceList = []
1392 for Pcd in Info.ModulePcdList:
1393 if Pcd.Type in gDynamicExPcd and Pcd.TokenSpaceGuidCName not in TokenSpaceList:
1394 TokenSpaceList += [Pcd.TokenSpaceGuidCName]
1395
1396 # Add extern declarations to AutoGen.h if one or more Token Space GUIDs were found
1397 if TokenSpaceList <> []:
1398 AutoGenH.Append("\n// Definition of PCD Token Space GUIDs used in this module\n\n")
1399 if Info.ModuleType in ["USER_DEFINED", "BASE"]:
1400 GuidType = "GUID"
1401 else:
1402 GuidType = "EFI_GUID"
1403 for Item in TokenSpaceList:
1404 AutoGenH.Append('extern %s %s;\n' % (GuidType, Item))
1405
1406 if Info.IsLibrary:
1407 if Info.ModulePcdList:
1408 AutoGenH.Append("\n// PCD definitions\n")
1409 for Pcd in Info.ModulePcdList:
1410 CreateLibraryPcdCode(Info, AutoGenC, AutoGenH, Pcd)
1411 DynExPcdTokenNumberMapping (Info, AutoGenH)
1412 else:
1413 if Info.ModulePcdList:
1414 AutoGenH.Append("\n// Definition of PCDs used in this module\n")
1415 AutoGenC.Append("\n// Definition of PCDs used in this module\n")
1416 for Pcd in Info.ModulePcdList:
1417 CreateModulePcdCode(Info, AutoGenC, AutoGenH, Pcd)
1418 DynExPcdTokenNumberMapping (Info, AutoGenH)
1419 if Info.LibraryPcdList:
1420 AutoGenH.Append("\n// Definition of PCDs used in libraries is in AutoGen.c\n")
1421 AutoGenC.Append("\n// Definition of PCDs used in libraries\n")
1422 for Pcd in Info.LibraryPcdList:
1423 CreateModulePcdCode(Info, AutoGenC, AutoGenC, Pcd)
1424 CreatePcdDatabaseCode(Info, AutoGenC, AutoGenH)
1425
1426 ## Create code for unicode string definition
1427 #
1428 # @param Info The ModuleAutoGen object
1429 # @param AutoGenC The TemplateString object for C code
1430 # @param AutoGenH The TemplateString object for header file
1431 # @param UniGenCFlag UniString is generated into AutoGen C file when it is set to True
1432 # @param UniGenBinBuffer Buffer to store uni string package data
1433 #
1434 def CreateUnicodeStringCode(Info, AutoGenC, AutoGenH, UniGenCFlag, UniGenBinBuffer):
1435 WorkingDir = os.getcwd()
1436 os.chdir(Info.WorkspaceDir)
1437
1438 IncList = [Info.MetaFile.Dir]
1439 # Get all files under [Sources] section in inf file for EDK-II module
1440 EDK2Module = True
1441 SrcList = [F for F in Info.SourceFileList]
1442 if Info.AutoGenVersion < 0x00010005:
1443 EDK2Module = False
1444 # Get all files under the module directory for EDK-I module
1445 Cwd = os.getcwd()
1446 os.chdir(Info.MetaFile.Dir)
1447 for Root, Dirs, Files in os.walk("."):
1448 if 'CVS' in Dirs:
1449 Dirs.remove('CVS')
1450 if '.svn' in Dirs:
1451 Dirs.remove('.svn')
1452 for File in Files:
1453 File = PathClass(os.path.join(Root, File), Info.MetaFile.Dir)
1454 if File in SrcList:
1455 continue
1456 SrcList.append(File)
1457 os.chdir(Cwd)
1458
1459 if 'BUILD' in Info.BuildOption and Info.BuildOption['BUILD']['FLAGS'].find('-c') > -1:
1460 CompatibleMode = True
1461 else:
1462 CompatibleMode = False
1463
1464 #
1465 # -s is a temporary option dedicated for building .UNI files with ISO 639-2 language codes of EDK Shell in EDK2
1466 #
1467 if 'BUILD' in Info.BuildOption and Info.BuildOption['BUILD']['FLAGS'].find('-s') > -1:
1468 if CompatibleMode:
1469 EdkLogger.error("build", AUTOGEN_ERROR,
1470 "-c and -s build options should be used exclusively",
1471 ExtraData="[%s]" % str(Info))
1472 ShellMode = True
1473 else:
1474 ShellMode = False
1475
1476 #RFC4646 is only for EDKII modules and ISO639-2 for EDK modules
1477 if EDK2Module:
1478 FilterInfo = [EDK2Module] + [Info.PlatformInfo.Platform.RFCLanguages]
1479 else:
1480 FilterInfo = [EDK2Module] + [Info.PlatformInfo.Platform.ISOLanguages]
1481 Header, Code = GetStringFiles(Info.UnicodeFileList, SrcList, IncList, Info.IncludePathList, ['.uni', '.inf'], Info.Name, CompatibleMode, ShellMode, UniGenCFlag, UniGenBinBuffer, FilterInfo)
1482 if CompatibleMode or UniGenCFlag:
1483 AutoGenC.Append("\n//\n//Unicode String Pack Definition\n//\n")
1484 AutoGenC.Append(Code)
1485 AutoGenC.Append("\n")
1486 AutoGenH.Append("\n//\n//Unicode String ID\n//\n")
1487 AutoGenH.Append(Header)
1488 if CompatibleMode or UniGenCFlag:
1489 AutoGenH.Append("\n#define STRING_ARRAY_NAME %sStrings\n" % Info.Name)
1490 os.chdir(WorkingDir)
1491
1492 ## Create common code
1493 #
1494 # @param Info The ModuleAutoGen object
1495 # @param AutoGenC The TemplateString object for C code
1496 # @param AutoGenH The TemplateString object for header file
1497 #
1498 def CreateHeaderCode(Info, AutoGenC, AutoGenH):
1499 # file header
1500 AutoGenH.Append(gAutoGenHeaderString.Replace({'FileName':'AutoGen.h'}))
1501 # header file Prologue
1502 AutoGenH.Append(gAutoGenHPrologueString.Replace({'File':'AUTOGENH','Guid':Info.Guid.replace('-','_')}))
1503 AutoGenH.Append(gAutoGenHCppPrologueString)
1504 if Info.AutoGenVersion >= 0x00010005:
1505 # header files includes
1506 AutoGenH.Append("#include <%s>\n" % gBasicHeaderFile)
1507 if Info.ModuleType in gModuleTypeHeaderFile \
1508 and gModuleTypeHeaderFile[Info.ModuleType][0] != gBasicHeaderFile:
1509 AutoGenH.Append("#include <%s>\n" % gModuleTypeHeaderFile[Info.ModuleType][0])
1510 #
1511 # if either PcdLib in [LibraryClasses] sections or there exist Pcd section, add PcdLib.h
1512 # As if modules only uses FixedPcd, then PcdLib is not needed in [LibraryClasses] section.
1513 #
1514 if 'PcdLib' in Info.Module.LibraryClasses or Info.Module.Pcds:
1515 AutoGenH.Append("#include <Library/PcdLib.h>\n")
1516
1517 AutoGenH.Append('\nextern GUID gEfiCallerIdGuid;')
1518 AutoGenH.Append('\nextern CHAR8 *gEfiCallerBaseName;\n\n')
1519
1520 if Info.IsLibrary:
1521 return
1522
1523 AutoGenH.Append("#define EFI_CALLER_ID_GUID \\\n %s\n" % GuidStringToGuidStructureString(Info.Guid))
1524
1525 if Info.IsLibrary:
1526 return
1527 # C file header
1528 AutoGenC.Append(gAutoGenHeaderString.Replace({'FileName':'AutoGen.c'}))
1529 if Info.AutoGenVersion >= 0x00010005:
1530 # C file header files includes
1531 if Info.ModuleType in gModuleTypeHeaderFile:
1532 for Inc in gModuleTypeHeaderFile[Info.ModuleType]:
1533 AutoGenC.Append("#include <%s>\n" % Inc)
1534 else:
1535 AutoGenC.Append("#include <%s>\n" % gBasicHeaderFile)
1536
1537 #
1538 # Publish the CallerId Guid
1539 #
1540 AutoGenC.Append('\nGLOBAL_REMOVE_IF_UNREFERENCED GUID gEfiCallerIdGuid = %s;\n' % GuidStringToGuidStructureString(Info.Guid))
1541 AutoGenC.Append('\nGLOBAL_REMOVE_IF_UNREFERENCED CHAR8 *gEfiCallerBaseName = "%s";\n' % Info.Name)
1542
1543 ## Create common code for header file
1544 #
1545 # @param Info The ModuleAutoGen object
1546 # @param AutoGenC The TemplateString object for C code
1547 # @param AutoGenH The TemplateString object for header file
1548 #
1549 def CreateFooterCode(Info, AutoGenC, AutoGenH):
1550 AutoGenH.Append(gAutoGenHEpilogueString)
1551
1552 ## Create code for a module
1553 #
1554 # @param Info The ModuleAutoGen object
1555 # @param AutoGenC The TemplateString object for C code
1556 # @param AutoGenH The TemplateString object for header file
1557 # @param UniGenCFlag UniString is generated into AutoGen C file when it is set to True
1558 # @param UniGenBinBuffer Buffer to store uni string package data
1559 #
1560 def CreateCode(Info, AutoGenC, AutoGenH, StringH, UniGenCFlag, UniGenBinBuffer):
1561 CreateHeaderCode(Info, AutoGenC, AutoGenH)
1562
1563 if Info.AutoGenVersion >= 0x00010005:
1564 CreateGuidDefinitionCode(Info, AutoGenC, AutoGenH)
1565 CreateProtocolDefinitionCode(Info, AutoGenC, AutoGenH)
1566 CreatePpiDefinitionCode(Info, AutoGenC, AutoGenH)
1567 CreatePcdCode(Info, AutoGenC, AutoGenH)
1568 CreateLibraryConstructorCode(Info, AutoGenC, AutoGenH)
1569 CreateLibraryDestructorCode(Info, AutoGenC, AutoGenH)
1570 CreateModuleEntryPointCode(Info, AutoGenC, AutoGenH)
1571 CreateModuleUnloadImageCode(Info, AutoGenC, AutoGenH)
1572
1573 if Info.UnicodeFileList:
1574 FileName = "%sStrDefs.h" % Info.Name
1575 StringH.Append(gAutoGenHeaderString.Replace({'FileName':FileName}))
1576 StringH.Append(gAutoGenHPrologueString.Replace({'File':'STRDEFS', 'Guid':Info.Guid.replace('-','_')}))
1577 CreateUnicodeStringCode(Info, AutoGenC, StringH, UniGenCFlag, UniGenBinBuffer)
1578
1579 GuidMacros = []
1580 for Guid in Info.Module.Guids:
1581 if Guid in Info.Module.GetGuidsUsedByPcd():
1582 continue
1583 GuidMacros.append('#define %s %s' % (Guid, Info.Module.Guids[Guid]))
1584 for Guid, Value in Info.Module.Protocols.items() + Info.Module.Ppis.items():
1585 GuidMacros.append('#define %s %s' % (Guid, Value))
1586 if GuidMacros:
1587 StringH.Append('\n#ifdef VFRCOMPILE\n%s\n#endif\n' % '\n'.join(GuidMacros))
1588
1589 StringH.Append("\n#endif\n")
1590 AutoGenH.Append('#include "%s"\n' % FileName)
1591
1592 CreateFooterCode(Info, AutoGenC, AutoGenH)
1593
1594 # no generation of AutoGen.c for Edk modules without unicode file
1595 if Info.AutoGenVersion < 0x00010005 and len(Info.UnicodeFileList) == 0:
1596 AutoGenC.String = ''
1597
1598 ## Create the code file
1599 #
1600 # @param FilePath The path of code file
1601 # @param Content The content of code file
1602 # @param IsBinaryFile The flag indicating if the file is binary file or not
1603 #
1604 # @retval True If file content is changed or file doesn't exist
1605 # @retval False If the file exists and the content is not changed
1606 #
1607 def Generate(FilePath, Content, IsBinaryFile):
1608 return SaveFileOnChange(FilePath, Content, IsBinaryFile)
1609