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