Changed the uses of EdkLogger
[people/mcb30/basetools.git] / Source / Python / AutoGen / GenC.py
1 ## @file\r
2 # Routines for generating AutoGen.h and AutoGen.c\r
3 #\r
4 # Copyright (c) 2007, Intel Corporation\r
5 # All rights reserved. This program and the accompanying materials\r
6 # are licensed and made available under the terms and conditions of the BSD License\r
7 # which accompanies this distribution.  The full text of the license may be found at\r
8 # http://opensource.org/licenses/bsd-license.php\r
9 #\r
10 # THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
11 # WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
12 #\r
13 \r
14 ## Import Modules\r
15 #\r
16 import string\r
17 \r
18 from Common import EdkLogger\r
19 \r
20 from Common.BuildToolError import *\r
21 from Common.DataType import *\r
22 from Common.EdkIIWorkspace import *\r
23 from Common.Misc import *\r
24 from BuildInfo import *\r
25 from StrGather import *\r
26 \r
27 gItemTypeStringDatabase  = {\r
28     TAB_PCDS_FEATURE_FLAG:'FixedAtBuild',\r
29     TAB_PCDS_FIXED_AT_BUILD:'FixedAtBuild',\r
30     TAB_PCDS_PATCHABLE_IN_MODULE:'BinaryPatch',\r
31     TAB_PCDS_DYNAMIC:'',\r
32     TAB_PCDS_DYNAMIC_DEFAULT:'',\r
33     TAB_PCDS_DYNAMIC_VPD:'',\r
34     TAB_PCDS_DYNAMIC_HII:'',\r
35     TAB_PCDS_DYNAMIC_EX:'',\r
36     TAB_PCDS_DYNAMIC_EX_DEFAULT:'',\r
37     TAB_PCDS_DYNAMIC_EX_VPD:'',\r
38     TAB_PCDS_DYNAMIC_EX_HII:'',\r
39 }\r
40 \r
41 gDynamicPcd = [TAB_PCDS_DYNAMIC, TAB_PCDS_DYNAMIC_DEFAULT, TAB_PCDS_DYNAMIC_VPD, TAB_PCDS_DYNAMIC_HII]\r
42 gDynamicExPcd = [TAB_PCDS_DYNAMIC_EX, TAB_PCDS_DYNAMIC_EX_DEFAULT, TAB_PCDS_DYNAMIC_EX_VPD, TAB_PCDS_DYNAMIC_EX_HII]\r
43 \r
44 gDatumSizeStringDatabase = {'UINT8':'8','UINT16':'16','UINT32':'32','UINT64':'64','BOOLEAN':'BOOLEAN','VOID*':'8'}\r
45 gDatumSizeStringDatabaseH = {'UINT8':'8','UINT16':'16','UINT32':'32','UINT64':'64','BOOLEAN':'BOOL','VOID*':'PTR'}\r
46 gDatumSizeStringDatabaseLib = {'UINT8':'8','UINT16':'16','UINT32':'32','UINT64':'64','BOOLEAN':'Bool','VOID*':'Ptr'}\r
47 \r
48 gPcdPhaseMap = {\r
49     "PEI_PCD_DRIVER"    :   "PEI",\r
50     "DXE_PCD_DRIVER"    :   "DXE"\r
51 }\r
52 \r
53 gPcdDatabaseCommonAutoGenH = """\r
54 //\r
55 // The following definition will be generated by build tool\r
56 //\r
57 \r
58 //\r
59 // Common definitions\r
60 //\r
61 typedef UINT8 SKU_ID;\r
62 \r
63 #define PCD_TYPE_SHIFT        28\r
64 \r
65 #define PCD_TYPE_DATA         (0x0 << PCD_TYPE_SHIFT)\r
66 #define PCD_TYPE_HII          (0x8 << PCD_TYPE_SHIFT)\r
67 #define PCD_TYPE_VPD          (0x4 << PCD_TYPE_SHIFT)\r
68 #define PCD_TYPE_SKU_ENABLED  (0x2 << PCD_TYPE_SHIFT)\r
69 #define PCD_TYPE_STRING       (0x1 << PCD_TYPE_SHIFT)\r
70 \r
71 #define PCD_TYPE_ALL_SET      (PCD_TYPE_DATA | PCD_TYPE_HII | PCD_TYPE_VPD | PCD_TYPE_SKU_ENABLED | PCD_TYPE_STRING)\r
72 \r
73 #define PCD_DATUM_TYPE_SHIFT  24\r
74 \r
75 #define PCD_DATUM_TYPE_POINTER  (0x0 << PCD_DATUM_TYPE_SHIFT)\r
76 #define PCD_DATUM_TYPE_UINT8    (0x1 << PCD_DATUM_TYPE_SHIFT)\r
77 #define PCD_DATUM_TYPE_UINT16   (0x2 << PCD_DATUM_TYPE_SHIFT)\r
78 #define PCD_DATUM_TYPE_UINT32   (0x4 << PCD_DATUM_TYPE_SHIFT)\r
79 #define PCD_DATUM_TYPE_UINT64   (0x8 << PCD_DATUM_TYPE_SHIFT)\r
80 \r
81 #define PCD_DATUM_TYPE_ALL_SET  (PCD_DATUM_TYPE_POINTER | \\\r
82                                  PCD_DATUM_TYPE_UINT8   | \\\r
83                                  PCD_DATUM_TYPE_UINT16  | \\\r
84                                  PCD_DATUM_TYPE_UINT32  | \\\r
85                                  PCD_DATUM_TYPE_UINT64)\r
86 \r
87 #define PCD_DATABASE_OFFSET_MASK (~(PCD_TYPE_ALL_SET | PCD_DATUM_TYPE_ALL_SET))\r
88 \r
89 typedef struct  {\r
90   UINT32  ExTokenNumber;\r
91   UINT16  LocalTokenNumber;   // PCD Number of this particular platform build\r
92   UINT16  ExGuidIndex;        // Index of GuidTable\r
93 } DYNAMICEX_MAPPING;\r
94 \r
95 typedef struct {\r
96   UINT32  SkuDataStartOffset; //We have to use offsetof MACRO as we don't know padding done by compiler\r
97   UINT32  SkuIdTableOffset;   //Offset from the PCD_DB\r
98 } SKU_HEAD;\r
99 \r
100 typedef struct {\r
101   UINT16  GuidTableIndex;     // Offset in Guid Table in units of GUID.\r
102   UINT16  StringIndex;        // Offset in String Table in units of UINT16.\r
103   UINT16  Offset;             // Offset in Variable\r
104   UINT16  DefaultValueOffset; // Offset of the Default Value\r
105 } VARIABLE_HEAD;\r
106 \r
107 typedef  struct {\r
108   UINT32  Offset;\r
109 } VPD_HEAD;\r
110 \r
111 typedef UINT16 STRING_HEAD;\r
112 \r
113 typedef UINT16 SIZE_INFO;\r
114 \r
115 #define offsetof(s,m)  (UINT32) (UINTN) &(((s *)0)->m)\r
116 \r
117 """\r
118 \r
119 gPcdDatabaseEpilogueAutoGenH = """\r
120 typedef struct {\r
121   PEI_PCD_DATABASE PeiDb;\r
122   DXE_PCD_DATABASE DxeDb;\r
123 } PCD_DATABASE;\r
124 \r
125 #define PCD_TOTAL_TOKEN_NUMBER (PEI_LOCAL_TOKEN_NUMBER + DXE_LOCAL_TOKEN_NUMBER)\r
126 \r
127 """\r
128 \r
129 gPcdDatabaseAutoGenH = """\r
130 #define ${PHASE}_GUID_TABLE_SIZE                ${GUID_TABLE_SIZE}\r
131 #define ${PHASE}_STRING_TABLE_SIZE              ${STRING_TABLE_SIZE}\r
132 #define ${PHASE}_SKUID_TABLE_SIZE               ${SKUID_TABLE_SIZE}\r
133 #define ${PHASE}_LOCAL_TOKEN_NUMBER_TABLE_SIZE  ${LOCAL_TOKEN_NUMBER_TABLE_SIZE}\r
134 #define ${PHASE}_LOCAL_TOKEN_NUMBER             ${LOCAL_TOKEN_NUMBER}\r
135 #define ${PHASE}_EXMAPPING_TABLE_SIZE           ${EXMAPPING_TABLE_SIZE}\r
136 #define ${PHASE}_EX_TOKEN_NUMBER                ${EX_TOKEN_NUMBER}\r
137 #define ${PHASE}_SIZE_TABLE_SIZE                ${SIZE_TABLE_SIZE}\r
138 #define ${PHASE}_GUID_TABLE_EMPTY               ${GUID_TABLE_EMPTY}\r
139 #define ${PHASE}_STRING_TABLE_EMPTY             ${STRING_TABLE_EMPTY}\r
140 #define ${PHASE}_SKUID_TABLE_EMPTY              ${SKUID_TABLE_EMPTY}\r
141 #define ${PHASE}_DATABASE_EMPTY                 ${DATABASE_EMPTY}\r
142 #define ${PHASE}_EXMAP_TABLE_EMPTY              ${EXMAP_TABLE_EMPTY}\r
143 \r
144 typedef struct {\r
145 ${BEGIN}  UINT64             ${INIT_CNAME_DECL_UINT64}_${INIT_GUID_DECL_UINT64}[${INIT_NUMSKUS_DECL_UINT64}];\r
146 ${END}\r
147 ${BEGIN}  UINT64             ${VARDEF_CNAME_UINT64}_${VARDEF_GUID_UINT64}_VariableDefault_${VARDEF_SKUID_UINT64};\r
148 ${END}\r
149 ${BEGIN}  UINT32             ${INIT_CNAME_DECL_UINT32}_${INIT_GUID_DECL_UINT32}[${INIT_NUMSKUS_DECL_UINT32}];\r
150 ${END}\r
151 ${BEGIN}  UINT32             ${VARDEF_CNAME_UINT32}_${VARDEF_GUID_UINT32}_VariableDefault_${VARDEF_SKUID_UINT32};\r
152 ${END}\r
153 ${BEGIN}  VPD_HEAD           ${VPD_HEAD_CNAME_DECL}_${VPD_HEAD_GUID_DECL}[${VPD_HEAD_NUMSKUS_DECL}];\r
154 ${END}\r
155   DYNAMICEX_MAPPING  ExMapTable[${PHASE}_EXMAPPING_TABLE_SIZE];\r
156   UINT32             LocalTokenNumberTable[${PHASE}_LOCAL_TOKEN_NUMBER_TABLE_SIZE];\r
157   GUID               GuidTable[${PHASE}_GUID_TABLE_SIZE];\r
158 ${BEGIN}  STRING_HEAD        ${STRING_HEAD_CNAME_DECL}_${STRING_HEAD_GUID_DECL}[${STRING_HEAD_NUMSKUS_DECL}];\r
159 ${END}\r
160 ${BEGIN}  VARIABLE_HEAD      ${VARIABLE_HEAD_CNAME_DECL}_${VARIABLE_HEAD_GUID_DECL}[${VARIABLE_HEAD_NUMSKUS_DECL}];\r
161 ${END}\r
162 ${BEGIN}  UINT16             StringTable${STRING_TABLE_INDEX}[${STRING_TABLE_LENGTH}]; /* ${STRING_TABLE_CNAME}_${STRING_TABLE_GUID} */\r
163 ${END}\r
164   SIZE_INFO          SizeTable[${PHASE}_SIZE_TABLE_SIZE];\r
165 ${BEGIN}  UINT16             ${INIT_CNAME_DECL_UINT16}_${INIT_GUID_DECL_UINT16}[${INIT_NUMSKUS_DECL_UINT16}];\r
166 ${END}\r
167 ${BEGIN}  UINT16             ${VARDEF_CNAME_UINT16}_${VARDEF_GUID_UINT16}_VariableDefault_${VARDEF_SKUID_UINT16};\r
168 ${END}\r
169 ${BEGIN}  UINT8              ${INIT_CNAME_DECL_UINT8}_${INIT_GUID_DECL_UINT8}[${INIT_NUMSKUS_DECL_UINT8}];\r
170 ${END}\r
171 ${BEGIN}  UINT8              ${VARDEF_CNAME_UINT8}_${VARDEF_GUID_UINT8}_VariableDefault_${VARDEF_SKUID_UINT8};\r
172 ${END}\r
173 ${BEGIN}  BOOLEAN            ${INIT_CNAME_DECL_BOOLEAN}_${INIT_GUID_DECL_BOOLEAN}[${INIT_NUMSKUS_DECL_BOOLEAN}];\r
174 ${END}\r
175 ${BEGIN}  BOOLEAN            ${VARDEF_CNAME_BOOLEAN}_${VARDEF_GUID_BOOLEAN}_VariableDefault_${VARDEF_SKUID_BOOLEAN};\r
176 ${END}\r
177   UINT8              SkuIdTable[${PHASE}_SKUID_TABLE_SIZE];\r
178 ${SYSTEM_SKU_ID}\r
179 } ${PHASE}_PCD_DATABASE_INIT;\r
180 \r
181 typedef struct {\r
182 ${PCD_DATABASE_UNINIT_EMPTY}\r
183 ${BEGIN}  UINT64   ${UNINIT_CNAME_DECL_UINT64}_${UNINIT_GUID_DECL_UINT64}[${UNINIT_NUMSKUS_DECL_UINT64}];\r
184 ${END}\r
185 ${BEGIN}  UINT32   ${UNINIT_CNAME_DECL_UINT32}_${UNINIT_GUID_DECL_UINT32}[${UNINIT_NUMSKUS_DECL_UINT32}];\r
186 ${END}\r
187 ${BEGIN}  UINT16   ${UNINIT_CNAME_DECL_UINT16}_${UNINIT_GUID_DECL_UINT16}[${UNINIT_NUMSKUS_DECL_UINT16}];\r
188 ${END}\r
189 ${BEGIN}  UINT8    ${UNINIT_CNAME_DECL_UINT8}_${UNINIT_GUID_DECL_UINT8}[${UNINIT_NUMSKUS_DECL_UINT8}];\r
190 ${END}\r
191 ${BEGIN}  BOOLEAN  ${UNINIT_CNAME_DECL_BOOLEAN}_${UNINIT_GUID_DECL_BOOLEAN}[${UNINIT_NUMSKUS_DECL_BOOLEAN}];\r
192 ${END}\r
193 } ${PHASE}_PCD_DATABASE_UNINIT;\r
194 \r
195 #define PCD_${PHASE}_SERVICE_DRIVER_VERSION         2\r
196 \r
197 typedef struct {\r
198   ${PHASE}_PCD_DATABASE_INIT    Init;\r
199   ${PHASE}_PCD_DATABASE_UNINIT  Uninit;\r
200 } ${PHASE}_PCD_DATABASE;\r
201 \r
202 #define ${PHASE}_NEX_TOKEN_NUMBER (${PHASE}_LOCAL_TOKEN_NUMBER - ${PHASE}_EX_TOKEN_NUMBER)\r
203 """\r
204 \r
205 gEmptyPcdDatabaseAutoGenC = """\r
206 ${PHASE}_PCD_DATABASE_INIT g${PHASE}PcdDbInit = {\r
207   /* ExMapTable */\r
208   {\r
209     {0, 0, 0}\r
210   },\r
211   /* LocalTokenNumberTable */\r
212   {\r
213     0\r
214   },\r
215   /* GuidTable */\r
216   {\r
217     {0x00000000, 0x0000, 0x0000, {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}}\r
218   },\r
219   /* StringTable */\r
220   { 0 },\r
221   /* SizeTable */\r
222   {\r
223     0, 0\r
224   },\r
225   /* SkuIdTable */\r
226   { 0 },\r
227   ${SYSTEM_SKU_ID_VALUE}\r
228 };\r
229 """\r
230 \r
231 gPcdDatabaseAutoGenC = """\r
232 ${PHASE}_PCD_DATABASE_INIT g${PHASE}PcdDbInit = {\r
233 ${BEGIN}  { ${INIT_VALUE_UINT64} }, /*  ${INIT_CNAME_DECL_UINT64}_${INIT_GUID_DECL_UINT64}[${INIT_NUMSKUS_DECL_UINT64}] */\r
234 ${END}\r
235 ${BEGIN}  ${VARDEF_VALUE_UINT64}, /* ${VARDEF_CNAME_UINT64}_${VARDEF_GUID_UINT64}_VariableDefault_${VARDEF_SKUID_UINT64} */\r
236 ${END}\r
237 ${BEGIN}  { ${INIT_VALUE_UINT32} }, /*  ${INIT_CNAME_DECL_UINT32}_${INIT_GUID_DECL_UINT32}[${INIT_NUMSKUS_DECL_UINT32}] */\r
238 ${END}\r
239 ${BEGIN}  ${VARDEF_VALUE_UINT32}, /* ${VARDEF_CNAME_UINT32}_${VARDEF_GUID_UINT32}_VariableDefault_${VARDEF_SKUID_UINT32} */\r
240 ${END}\r
241   /* VPD */\r
242 ${BEGIN}  { ${VPD_HEAD_VALUE} }, /* ${VPD_HEAD_CNAME_DECL}_${VPD_HEAD_GUID_DECL}[${VPD_HEAD_NUMSKUS_DECL}] */\r
243 ${END}\r
244   /* ExMapTable */\r
245   {\r
246 ${BEGIN}    { ${EXMAPPING_TABLE_EXTOKEN}, ${EXMAPPING_TABLE_LOCAL_TOKEN}, ${EXMAPPING_TABLE_GUID_INDEX} },\r
247 ${END}\r
248   },\r
249   /* LocalTokenNumberTable */\r
250   {\r
251 ${BEGIN}    offsetof(${PHASE}_PCD_DATABASE, ${TOKEN_INIT}.${TOKEN_CNAME}_${TOKEN_GUID}) | ${TOKEN_TYPE},\r
252 ${END}\r
253   },\r
254   /* GuidTable */\r
255   {\r
256 ${BEGIN}    ${GUID_STRUCTURE},\r
257 ${END}\r
258   },\r
259 ${BEGIN}  { ${STRING_HEAD_VALUE} }, /* ${STRING_HEAD_CNAME_DECL}_${STRING_HEAD_GUID_DECL}[${STRING_HEAD_NUMSKUS_DECL}] */\r
260 ${END}\r
261 ${BEGIN}  /* ${VARIABLE_HEAD_CNAME_DECL}_${VARIABLE_HEAD_GUID_DECL}[${VARIABLE_HEAD_NUMSKUS_DECL}] */\r
262   {\r
263     ${VARIABLE_HEAD_VALUE}\r
264   },\r
265 ${END}\r
266  /* StringTable */\r
267 ${BEGIN}  ${STRING_TABLE_VALUE}, /* ${STRING_TABLE_CNAME}_${STRING_TABLE_GUID} */\r
268 ${END}\r
269   /* SizeTable */\r
270   {\r
271 ${BEGIN}    ${SIZE_TABLE_MAXIMUM_LENGTH}, ${SIZE_TABLE_CURRENT_LENGTH}, /* ${SIZE_TABLE_CNAME}_${SIZE_TABLE_GUID} */\r
272 ${END}\r
273   },\r
274 ${BEGIN}  { ${INIT_VALUE_UINT16} }, /*  ${INIT_CNAME_DECL_UINT16}_${INIT_GUID_DECL_UINT16}[${INIT_NUMSKUS_DECL_UINT16}] */\r
275 ${END}\r
276 ${BEGIN}  ${VARDEF_VALUE_UINT16}, /* ${VARDEF_CNAME_UINT16}_${VARDEF_GUID_UINT16}_VariableDefault_${VARDEF_SKUID_UINT16} */\r
277 ${END}\r
278 ${BEGIN}  { ${INIT_VALUE_UINT8} }, /*  ${INIT_CNAME_DECL_UINT8}_${INIT_GUID_DECL_UINT8}[${INIT_NUMSKUS_DECL_UINT8}] */\r
279 ${END}\r
280 ${BEGIN}  ${VARDEF_VALUE_UINT8}, /* ${VARDEF_CNAME_UINT8}_${VARDEF_GUID_UINT8}_VariableDefault_${VARDEF_SKUID_UINT8} */\r
281 ${END}\r
282 ${BEGIN}  { ${INIT_VALUE_BOOLEAN} }, /*  ${INIT_CNAME_DECL_BOOLEAN}_${INIT_GUID_DECL_BOOLEAN}[${INIT_NUMSKUS_DECL_BOOLEAN}] */\r
283 ${END}\r
284 ${BEGIN}  ${VARDEF_VALUE_BOOLEAN}, /* ${VARDEF_CNAME_BOOLEAN}_${VARDEF_GUID_BOOLEAN}_VariableDefault_${VARDEF_SKUID_BOOLEAN} */\r
285 ${END}\r
286   /* SkuIdTable */\r
287   { ${BEGIN}${SKUID_VALUE}, ${END} },\r
288   ${SYSTEM_SKU_ID_VALUE}\r
289 };\r
290 """\r
291 \r
292 #\r
293 # AutoGen File Header Templates\r
294 #\r
295 gAutoGenHeaderString = """\\r
296 /**\r
297   DO NOT EDIT\r
298   FILE auto-generated\r
299   Module name:\r
300     $FileName\r
301   Abstract:       Auto-generated $FileName for building module or library.\r
302 **/\r
303 """\r
304 \r
305 gAutoGenHPrologueString = """\r
306 #ifndef _AUTOGENH_${Guid}\r
307 #define _AUTOGENH_${Guid}\r
308 \r
309 extern int __make_me_compile_correctly;\r
310 """\r
311 \r
312 gAutoGenHEpilogueString = """\r
313 #endif\r
314 """\r
315 \r
316 #\r
317 # PEI Core Entry Point Templates\r
318 #\r
319 gPeiCoreEntryPointString = """\r
320 ${BEGIN}\r
321 EFI_STATUS\r
322 ${Function} (\r
323   IN CONST  EFI_SEC_PEI_HAND_OFF    *SecCoreData,\r
324   IN CONST  EFI_PEI_PPI_DESCRIPTOR  *PpiList,\r
325   IN VOID                           *OldCoreData\r
326   );\r
327 \r
328 EFI_STATUS\r
329 EFIAPI\r
330 ProcessModuleEntryPointList (\r
331   IN CONST  EFI_SEC_PEI_HAND_OFF    *SecCoreData,\r
332   IN CONST  EFI_PEI_PPI_DESCRIPTOR  *PpiList,\r
333   IN VOID                           *OldCoreData\r
334   )\r
335 \r
336 {\r
337   return ${Function} (SecCoreData, PpiList, OldCoreData);\r
338 }\r
339 ${END}\r
340 """\r
341 \r
342 #\r
343 # DXE Core Entry Point Templates\r
344 #\r
345 gDxeCoreEntryPointString = """\r
346 const UINT32 _gUefiDriverRevision = 0;\r
347 ${BEGIN}\r
348 VOID\r
349 ${Function} (\r
350   IN VOID  *HobStart\r
351   );\r
352 \r
353 VOID\r
354 EFIAPI\r
355 ProcessModuleEntryPointList (\r
356   IN VOID  *HobStart\r
357   )\r
358 \r
359 {\r
360   ${Function} (HobStart);\r
361 }\r
362 ${END}\r
363 """\r
364 \r
365 #\r
366 # PEIM Entry Point Templates\r
367 #\r
368 gPeimEntryPointString = [\r
369 """\r
370 GLOBAL_REMOVE_IF_UNREFERENCED const UINT32 _gPeimRevision = 0;\r
371 \r
372 EFI_STATUS\r
373 EFIAPI\r
374 ProcessModuleEntryPointList (\r
375   IN EFI_PEI_FILE_HANDLE  *FfsHeader,\r
376   IN EFI_PEI_SERVICES     **PeiServices\r
377   )\r
378 \r
379 {\r
380   return EFI_SUCCESS;\r
381 }\r
382 """,\r
383 """\r
384 GLOBAL_REMOVE_IF_UNREFERENCED const UINT32 _gPeimRevision = 0;\r
385 ${BEGIN}\r
386 EFI_STATUS\r
387 ${Function} (\r
388   IN EFI_PEI_FILE_HANDLE  *FfsHeader,\r
389   IN EFI_PEI_SERVICES     **PeiServices\r
390   );\r
391 \r
392 EFI_STATUS\r
393 EFIAPI\r
394 ProcessModuleEntryPointList (\r
395   IN EFI_PEI_FILE_HANDLE  *FfsHeader,\r
396   IN EFI_PEI_SERVICES     **PeiServices\r
397   )\r
398 \r
399 {\r
400   return ${Function} (FfsHeader, PeiServices);\r
401 }\r
402 ${END}\r
403 """,\r
404 """\r
405 GLOBAL_REMOVE_IF_UNREFERENCED const UINT32 _gPeimRevision = 0;\r
406 \r
407 ${BEGIN}\r
408 EFI_STATUS\r
409 ${Function} (\r
410   IN EFI_PEI_FILE_HANDLE  *FfsHeader,\r
411   IN EFI_PEI_SERVICES     **PeiServices\r
412   );\r
413 ${END}\r
414 \r
415 EFI_STATUS\r
416 EFIAPI\r
417 ProcessModuleEntryPointList (\r
418   IN EFI_PEI_FILE_HANDLE  *FfsHeader,\r
419   IN EFI_PEI_SERVICES     **PeiServices\r
420   )\r
421 \r
422 {\r
423   EFI_STATUS  Status;\r
424   EFI_STATUS  CombinedStatus;\r
425 \r
426   CombinedStatus = EFI_LOAD_ERROR;\r
427 ${BEGIN}\r
428   Status = ${Function} (FfsHeader, PeiServices);\r
429   if (!EFI_ERROR (Status) || EFI_ERROR (CombinedStatus)) {\r
430     CombinedStatus = Status;\r
431   }\r
432 ${END}\r
433   return CombinedStatus;\r
434 }\r
435 """\r
436 ]\r
437 \r
438 #\r
439 # DXE SMM Entry Point Templates\r
440 #\r
441 gDxeSmmEntryPointString = [\r
442 """\r
443 EFI_STATUS\r
444 EFIAPI\r
445 ProcessModuleEntryPointList (\r
446   IN EFI_HANDLE        ImageHandle,\r
447   IN EFI_SYSTEM_TABLE  *SystemTable\r
448   )\r
449 \r
450 {\r
451   return EFI_SUCCESS;\r
452 }\r
453 """,\r
454 """\r
455 ${BEGIN}\r
456 EFI_STATUS\r
457 ${Function} (\r
458   IN EFI_HANDLE        ImageHandle,\r
459   IN EFI_SYSTEM_TABLE  *SystemTable\r
460   );\r
461 ${END}\r
462 \r
463 static BASE_LIBRARY_JUMP_BUFFER  mJumpContext;\r
464 static EFI_STATUS  mDriverEntryPointStatus = EFI_LOAD_ERROR;\r
465 \r
466 VOID\r
467 EFIAPI\r
468 ExitDriver (\r
469   IN EFI_STATUS  Status\r
470   )\r
471 {\r
472   if (!EFI_ERROR (Status) || EFI_ERROR (mDriverEntryPointStatus)) {\r
473     mDriverEntryPointStatus = Status;\r
474   }\r
475   LongJump (&mJumpContext, (UINTN)-1);\r
476   ASSERT (FALSE);\r
477 }\r
478 \r
479 EFI_STATUS\r
480 EFIAPI\r
481 ProcessModuleEntryPointList (\r
482   IN EFI_HANDLE        ImageHandle,\r
483   IN EFI_SYSTEM_TABLE  *SystemTable\r
484   )\r
485 \r
486 {\r
487 ${BEGIN}\r
488   if (SetJump (&mJumpContext) == 0) {\r
489     ExitDriver (${Function} (ImageHandle, SystemTable));\r
490     ASSERT (FALSE);\r
491   }\r
492 ${END}\r
493 \r
494   return mDriverEntryPointStatus;\r
495 }\r
496 """\r
497 ]\r
498 \r
499 #\r
500 # UEFI Entry Point Templates\r
501 #\r
502 gUefiEntryPointString = [\r
503 """\r
504 const UINT32 _gUefiDriverRevision = 0;\r
505 \r
506 EFI_STATUS\r
507 EFIAPI\r
508 ProcessModuleEntryPointList (\r
509   IN EFI_HANDLE        ImageHandle,\r
510   IN EFI_SYSTEM_TABLE  *SystemTable\r
511   )\r
512 {\r
513   return EFI_SUCCESS;\r
514 }\r
515 """,\r
516 """\r
517 const UINT32 _gUefiDriverRevision = 0;\r
518 ${BEGIN}\r
519 EFI_STATUS\r
520 ${Function} (\r
521   IN EFI_HANDLE        ImageHandle,\r
522   IN EFI_SYSTEM_TABLE  *SystemTable\r
523   );\r
524 \r
525 EFI_STATUS\r
526 EFIAPI\r
527 ProcessModuleEntryPointList (\r
528   IN EFI_HANDLE        ImageHandle,\r
529   IN EFI_SYSTEM_TABLE  *SystemTable\r
530   )\r
531 \r
532 {\r
533   return ${Function} (ImageHandle, SystemTable);\r
534 }\r
535 ${END}\r
536 VOID\r
537 EFIAPI\r
538 ExitDriver (\r
539   IN EFI_STATUS  Status\r
540   )\r
541 {\r
542   if (EFI_ERROR (Status)) {\r
543     ProcessLibraryDestructorList (gImageHandle, gST);\r
544   }\r
545   gBS->Exit (gImageHandle, Status, 0, NULL);\r
546 }\r
547 """,\r
548 """\r
549 const UINT32 _gUefiDriverRevision = 0;\r
550 \r
551 ${BEGIN}\r
552 EFI_STATUS\r
553 ${Function} (\r
554   IN EFI_HANDLE        ImageHandle,\r
555   IN EFI_SYSTEM_TABLE  *SystemTable\r
556   );\r
557 ${END}\r
558 \r
559 EFI_STATUS\r
560 EFIAPI\r
561 ProcessModuleEntryPointList (\r
562   IN EFI_HANDLE        ImageHandle,\r
563   IN EFI_SYSTEM_TABLE  *SystemTable\r
564   )\r
565 \r
566 {\r
567   ${BEGIN}\r
568   if (SetJump (&mJumpContext) == 0) {\r
569     ExitDriver (${Function} (ImageHandle, SystemTable));\r
570     ASSERT (FALSE);\r
571   }\r
572   ${END}\r
573   return mDriverEntryPointStatus;\r
574 }\r
575 \r
576 static BASE_LIBRARY_JUMP_BUFFER  mJumpContext;\r
577 static EFI_STATUS  mDriverEntryPointStatus = EFI_LOAD_ERROR;\r
578 \r
579 VOID\r
580 EFIAPI\r
581 ExitDriver (\r
582   IN EFI_STATUS  Status\r
583   )\r
584 {\r
585   if (!EFI_ERROR (Status) || EFI_ERROR (mDriverEntryPointStatus)) {\r
586     mDriverEntryPointStatus = Status;\r
587   }\r
588   LongJump (&mJumpContext, (UINTN)-1);\r
589   ASSERT (FALSE);\r
590 }\r
591 """\r
592 ]\r
593 \r
594 #\r
595 # UEFI Unload Image Templates\r
596 #\r
597 gUefiUnloadImageString = [\r
598 """\r
599 GLOBAL_REMOVE_IF_UNREFERENCED const UINT8 _gDriverUnloadImageCount = ${Count};\r
600 \r
601 EFI_STATUS\r
602 EFIAPI\r
603 ProcessModuleUnloadList (\r
604   IN EFI_HANDLE        ImageHandle\r
605   )\r
606 {\r
607   return EFI_SUCCESS;\r
608 }\r
609 """,\r
610 """\r
611 GLOBAL_REMOVE_IF_UNREFERENCED const UINT8 _gDriverUnloadImageCount = ${Count};\r
612 \r
613 ${BEGIN}\r
614 EFI_STATUS\r
615 ${Function} (\r
616   IN EFI_HANDLE        ImageHandle\r
617   );\r
618 \r
619 EFI_STATUS\r
620 EFIAPI\r
621 ProcessModuleUnloadList (\r
622   IN EFI_HANDLE        ImageHandle\r
623   )\r
624 {\r
625   return ${Function} (ImageHandle);\r
626 }\r
627 ${END}\r
628 """,\r
629 """\r
630 GLOBAL_REMOVE_IF_UNREFERENCED const UINT8 _gDriverUnloadImageCount = ${Count};\r
631 \r
632 ${BEGIN}\r
633 EFI_STATUS\r
634 ${Function} (\r
635   IN EFI_HANDLE        ImageHandle\r
636   );\r
637 ${END}\r
638 \r
639 EFI_STATUS\r
640 EFIAPI\r
641 ProcessModuleUnloadList (\r
642   IN EFI_HANDLE        ImageHandle\r
643   )\r
644 {\r
645   EFI_STATUS  Status;\r
646 \r
647   Status = EFI_SUCCESS;\r
648 ${BEGIN}\r
649   if (EFI_ERROR (Status)) {\r
650     ${Function} (ImageHandle);\r
651   } else {\r
652     Status = ${Function} (ImageHandle);\r
653   }\r
654 ${END}\r
655   return Status;\r
656 }\r
657 """\r
658 ]\r
659 \r
660 #\r
661 # Library Constructor and Destructor Templates\r
662 #\r
663 gLibraryString = [\r
664 """\r
665 VOID\r
666 EFIAPI\r
667 ProcessLibrary${Type}List (\r
668   VOID\r
669   )\r
670 {\r
671 }\r
672 """,\r
673 """\r
674 VOID\r
675 EFIAPI\r
676 ProcessLibrary${Type}List (\r
677   IN EFI_PEI_FILE_HANDLE       *FfsHeader,\r
678   IN EFI_PEI_SERVICES          **PeiServices\r
679   )\r
680 {\r
681 }\r
682 """,\r
683 """\r
684 VOID\r
685 EFIAPI\r
686 ProcessLibrary${Type}List (\r
687   IN EFI_HANDLE        ImageHandle,\r
688   IN EFI_SYSTEM_TABLE  *SystemTable\r
689   )\r
690 {\r
691 }\r
692 """,\r
693 """\r
694 ${BEGIN}\r
695 RETURN_STATUS\r
696 EFIAPI\r
697 ${Function} (\r
698   VOID\r
699   );\r
700 ${END}\r
701 \r
702 VOID\r
703 EFIAPI\r
704 ProcessLibrary${Type}List (\r
705   VOID\r
706   )\r
707 {\r
708   EFI_STATUS  Status;\r
709 \r
710 ${BEGIN}\r
711   Status = ${Function} ();\r
712   ASSERT_EFI_ERROR (Status);\r
713 ${END}\r
714 }\r
715 """,\r
716 """\r
717 ${BEGIN}\r
718 EFI_STATUS\r
719 EFIAPI\r
720 ${Function} (\r
721   IN EFI_PEI_FILE_HANDLE       *FfsHeader,\r
722   IN EFI_PEI_SERVICES          **PeiServices\r
723   );\r
724 ${END}\r
725 \r
726 VOID\r
727 EFIAPI\r
728 ProcessLibrary${Type}List (\r
729   IN EFI_PEI_FILE_HANDLE       *FfsHeader,\r
730   IN EFI_PEI_SERVICES          **PeiServices\r
731   )\r
732 {\r
733   EFI_STATUS  Status;\r
734 \r
735 ${BEGIN}\r
736   Status = ${Function} (FfsHeader, PeiServices);\r
737   ASSERT_EFI_ERROR (Status);\r
738 ${END}\r
739 }\r
740 """,\r
741 """\r
742 ${BEGIN}\r
743 EFI_STATUS\r
744 EFIAPI\r
745 ${Function} (\r
746   IN EFI_HANDLE        ImageHandle,\r
747   IN EFI_SYSTEM_TABLE  *SystemTable\r
748   );\r
749 ${END}\r
750 \r
751 VOID\r
752 EFIAPI\r
753 ProcessLibrary${Type}List (\r
754   IN EFI_HANDLE        ImageHandle,\r
755   IN EFI_SYSTEM_TABLE  *SystemTable\r
756   )\r
757 {\r
758   EFI_STATUS  Status;\r
759 \r
760 ${BEGIN}\r
761   Status = ${Function} (ImageHandle, SystemTable);\r
762   ASSERT_EFI_ERROR (Status);\r
763 ${END}\r
764 }\r
765 """\r
766 ]\r
767 \r
768 gSpecificationString = """\r
769 ${BEGIN}\r
770 #define ${Specification}\r
771 ${END}\r
772 """\r
773 \r
774 gBasicHeaderFile = "Base.h"\r
775 \r
776 gModuleTypeHeaderFile = {\r
777     "BASE"              :   [gBasicHeaderFile],\r
778     "SEC"               :   ["PiPei.h", "Library/DebugLib.h"],\r
779     "PEI_CORE"          :   ["PiPei.h", "Library/DebugLib.h"],\r
780     "PEIM"              :   ["PiPei.h", "Library/DebugLib.h"],\r
781     "DXE_CORE"          :   ["PiDxe.h", "Library/DebugLib.h"],\r
782     "DXE_DRIVER"        :   ["PiDxe.h", "Library/BaseLib.h", "Library/DebugLib.h", "Library/UefiBootServicesTableLib.h"],\r
783     "DXE_SMM_DRIVER"    :   ["PiDxe.h", "Library/BaseLib.h", "Library/DebugLib.h", "Library/UefiBootServicesTableLib.h"],\r
784     "DXE_RUNTIME_DRIVER":   ["PiDxe.h", "Library/BaseLib.h", "Library/DebugLib.h", "Library/UefiBootServicesTableLib.h"],\r
785     "DXE_SAL_DRIVER"    :   ["PiDxe.h", "Library/BaseLib.h", "Library/DebugLib.h", "Library/UefiBootServicesTableLib.h"],\r
786     "UEFI_DRIVER"       :   ["Uefi.h",  "Library/BaseLib.h", "Library/DebugLib.h", "Library/UefiBootServicesTableLib.h"],\r
787     "UEFI_APPLICATION"  :   ["Uefi.h",  "Library/BaseLib.h", "Library/DebugLib.h", "Library/UefiBootServicesTableLib.h"],\r
788     "USER_DEFINED"      :   [gBasicHeaderFile]\r
789 }\r
790 \r
791 def GetGuidValue(Packages, CName):\r
792     for P in Packages:\r
793         if CName in P.Guids:\r
794             return P.Guids[CName]\r
795         if CName in P.Protocols:\r
796             return P.Protocols[CName]\r
797         if CName in P.Ppis:\r
798             return P.Ppis[CName]\r
799     else:\r
800         PackageListString = "\n\t".join([str(P) for P in Packages])\r
801         EdkLogger.error("AutoGen", AUTOGEN_ERROR,\r
802                         "Cannot find GUID value for %s in all given packages" % CName,\r
803                         ExtraData=PackageListString)\r
804 \r
805 def CreateModulePcdCode(Info, AutoGenC, AutoGenH, Pcd):\r
806     PcdTokenNumber = Info.PlatformInfo.PcdTokenNumber\r
807     #\r
808     # Write PCDs\r
809     #\r
810     PcdTokenName = '_PCD_TOKEN_' + Pcd.TokenCName\r
811     if Pcd.Type in gDynamicExPcd:\r
812         TokenNumber = int(Pcd.TokenValue, 0)\r
813     else:\r
814         if (Pcd.TokenCName, Pcd.TokenSpaceGuidCName) not in PcdTokenNumber:\r
815             EdkLogger.error("AutoGen", AUTOGEN_ERROR, "No generated token number for %s|%s\n" % (Pcd.TokenCName, Pcd.TokenSpaceGuidCName))\r
816         TokenNumber = PcdTokenNumber[Pcd.TokenCName, Pcd.TokenSpaceGuidCName]\r
817     AutoGenH.Append('#define %s  %d\n' % (PcdTokenName, TokenNumber))\r
818 \r
819     EdkLogger.debug(EdkLogger.DEBUG_3, "Creating code for " + Pcd.TokenCName + "|" + Pcd.TokenSpaceGuidCName)\r
820     if Pcd.Type not in gItemTypeStringDatabase:\r
821         EdkLogger.error("AutoGen", AUTOGEN_ERROR, "Unknown PCD type [%s] of PCD %s|%s" % (Pcd.Type, Pcd.TokenCName, Pcd.TokenSpaceGuidCName))\r
822     if Pcd.DatumType not in gDatumSizeStringDatabase:\r
823         EdkLogger.error("AutoGen", AUTOGEN_ERROR, "Unknown datum type [%s] of PCD %s|%s" % (Pcd.DatumType, Pcd.TokenCName, Pcd.TokenSpaceGuidCName))\r
824 \r
825     DatumSize = gDatumSizeStringDatabase[Pcd.DatumType]\r
826     DatumSizeLib = gDatumSizeStringDatabaseLib[Pcd.DatumType]\r
827     GetModeName = '_PCD_GET_MODE_' + gDatumSizeStringDatabaseH[Pcd.DatumType] + '_' + Pcd.TokenCName\r
828     SetModeName = '_PCD_SET_MODE_' + gDatumSizeStringDatabaseH[Pcd.DatumType] + '_' + Pcd.TokenCName\r
829 \r
830     if Pcd.Type in gDynamicExPcd:\r
831         AutoGenH.Append('#define %s  LibPcdGetEx%s(&%s, %s)\n' % (GetModeName, DatumSizeLib, Pcd.TokenSpaceGuidCName, PcdTokenName))\r
832         if Pcd.DatumType == 'VOID*':\r
833             AutoGenH.Append('#define %s(SizeOfBuffer, Buffer)  LibPcdSetEx%s(&%s, %s, (SizeOfBuffer), (Buffer))\n' % (SetModeName, DatumSizeLib, Pcd.TokenSpaceGuidCName, PcdTokenName))\r
834         else:\r
835             AutoGenH.Append('#define %s(Value)  LibPcdSetEx%s(&%s, %s, (Value))\n' % (SetModeName, DatumSizeLib, Pcd.TokenSpaceGuidCName, PcdTokenName))\r
836     elif Pcd.Type in gDynamicPcd:\r
837         AutoGenH.Append('#define %s  LibPcdGet%s(%s)\n' % (GetModeName, DatumSizeLib, PcdTokenName))\r
838         if Pcd.DatumType == 'VOID*':\r
839             AutoGenH.Append('#define %s(SizeOfBuffer, Buffer)  LibPcdSet%s(%s, (SizeOfBuffer), (Buffer))\n' %(SetModeName, DatumSizeLib, PcdTokenName))\r
840         else:\r
841             AutoGenH.Append('#define %s(Value)  LibPcdSet%s(%s, (Value))\n' % (SetModeName, DatumSizeLib, PcdTokenName))\r
842     else:\r
843         PcdVariableName = '_gPcd_' + gItemTypeStringDatabase[Pcd.Type] + '_' + Pcd.TokenCName\r
844         Const = 'const'\r
845         if Pcd.Type == TAB_PCDS_PATCHABLE_IN_MODULE:\r
846             Const = ''\r
847         Type = ''\r
848         Array = ''\r
849         Value = Pcd.DefaultValue\r
850         if Pcd.DatumType == 'UINT64':\r
851             if not Value.endswith('ULL'):\r
852                 Value += 'ULL'\r
853         if Pcd.DatumType == 'VOID*':\r
854             if Pcd.MaxDatumSize == None:\r
855                 EdkLogger.error("AutoGen", AUTOGEN_ERROR, "Unknown MaxDatumSize of PCD %s|%s" % (Pcd.TokenCName, Pcd.TokenSpaceGuidCName))\r
856 \r
857             ArraySize = int(Pcd.MaxDatumSize, 0)\r
858             if Value[0] == '{':\r
859                 Type = '(VOID *)'\r
860             else:\r
861                 Unicode = False\r
862                 if Value[0] == 'L':\r
863                     Unicode = True\r
864                 Value = Value.lstrip('L').strip('"')\r
865                 NewValue = '{'\r
866                 for Index in range(0,len(Value)):\r
867                     NewValue = NewValue + str(ord(Value[Index]) % 0x100) + ', '\r
868                     if Unicode:\r
869                         NewValue = NewValue + str(ord(Value[Index]) / 0x100) + ', '\r
870                 if Unicode:\r
871                     if ArraySize < (len(Value)*2 + 2):\r
872                         ArraySize = len(Value)*2 + 2\r
873                     NewValue = NewValue + '0, '\r
874                 else:\r
875                     if ArraySize < (len(Value) + 1):\r
876                         ArraySize = len(Value) + 1\r
877                 Value = NewValue + '0 }'\r
878             Array = '[%d]' % ArraySize\r
879 \r
880         PcdValueName = '_PCD_VALUE_' + Pcd.TokenCName\r
881         if Pcd.DatumType == 'VOID*' and Value[0] == '{':\r
882             AutoGenH.Append('#define _PCD_PATCHABLE_%s_SIZE %s\n' % (Pcd.TokenCName, Pcd.MaxDatumSize))\r
883             AutoGenH.Append('#define %s  %s%s\n' %(PcdValueName, Type, PcdVariableName))\r
884             AutoGenC.Append('GLOBAL_REMOVE_IF_UNREFERENCED %s UINT8 %s%s = %s;\n' % (Const, PcdVariableName, Array, Value))\r
885             AutoGenH.Append('extern %s UINT8 %s%s;\n' %(Const, PcdVariableName, Array))\r
886             AutoGenH.Append('#define %s  %s%s\n' %(GetModeName, Type, PcdVariableName))\r
887         else:\r
888             AutoGenH.Append('#define %s  %s\n' %(PcdValueName, Value))\r
889             AutoGenC.Append('GLOBAL_REMOVE_IF_UNREFERENCED %s %s %s = %s;\n' %(Const, Pcd.DatumType, PcdVariableName, PcdValueName))\r
890             AutoGenH.Append('extern %s  %s  %s%s;\n' % (Const, Pcd.DatumType, PcdVariableName, Array))\r
891             AutoGenH.Append('#define %s  %s%s\n' % (GetModeName, Type, PcdVariableName))\r
892 \r
893         if Pcd.Type == TAB_PCDS_PATCHABLE_IN_MODULE:\r
894             if Pcd.DatumType == 'VOID*':\r
895                 AutoGenH.Append('#define %s(SizeOfBuffer, Buffer)  LibPatchPcdSetPtr(_gPcd_BinaryPatch_%s, (UINTN)_PCD_PATCHABLE_%s_SIZE, (SizeOfBuffer), (Buffer))\n' % (SetModeName, Pcd.TokenCName, Pcd.TokenCName))\r
896             else:\r
897                 AutoGenH.Append('#define %s(Value)  (%s = (Value))\n' % (SetModeName, PcdVariableName))\r
898         else:\r
899             AutoGenH.Append('//#define %s  ASSERT(FALSE)  // It is not allowed to set value for a FIXED_AT_BUILD PCD\n' % SetModeName)\r
900 \r
901 def CreateLibraryPcdCode(Info, AutoGenC, AutoGenH, Pcd):\r
902     PcdTokenNumber = Info.PlatformInfo.PcdTokenNumber\r
903     TokenSpaceGuidCName = Pcd.TokenSpaceGuidCName\r
904     TokenCName  = Pcd.TokenCName\r
905     if (Pcd.TokenCName, Pcd.TokenSpaceGuidCName) not in PcdTokenNumber:\r
906         EdkLogger.error("AutoGen", AUTOGEN_ERROR, "No generated token number for %s|%s\n" % (Pcd.TokenCName, Pcd.TokenSpaceGuidCName))\r
907     TokenNumber = PcdTokenNumber[TokenCName, TokenSpaceGuidCName]\r
908 \r
909     if Pcd.Type not in gItemTypeStringDatabase:\r
910         EdkLogger.error("AutoGen", AUTOGEN_ERROR, "Unknown PCD type [%s] of PCD %s|%s" % (Pcd.Type, Pcd.TokenCName, Pcd.TokenSpaceGuidCName))\r
911     if Pcd.DatumType not in gDatumSizeStringDatabase:\r
912         EdkLogger.error("AutoGen", AUTOGEN_ERROR, "Unknown datum type [%s] of PCD %s|%s" % (Pcd.DatumType, Pcd.TokenCName, Pcd.TokenSpaceGuidCName))\r
913 \r
914     DatumType   = Pcd.DatumType\r
915     DatumSize   = gDatumSizeStringDatabaseH[DatumType]\r
916     DatumSizeLib= gDatumSizeStringDatabaseLib[DatumType]\r
917     GetModeName = '_PCD_GET_MODE_' + DatumSize + '_' + TokenCName\r
918     SetModeName = '_PCD_SET_MODE_' + DatumSize + '_' + TokenCName\r
919 \r
920     Type = ''\r
921     Array = ''\r
922     if Pcd.DatumType == 'VOID*':\r
923         Type = '(VOID *)'\r
924         Array = '[]'\r
925 \r
926     AutoGenH.Append('#define _PCD_TOKEN_%s  %d\n' % (TokenCName, TokenNumber))\r
927 \r
928     PcdItemType = Pcd.Type\r
929     if PcdItemType in gDynamicPcd:\r
930         PcdItemType = TAB_PCDS_FIXED_AT_BUILD\r
931         if (TokenCName, TokenSpaceGuidCName) in Info.PlatformInfo.Platform.Pcds:\r
932             PcdItemType  = Info.PlatformInfo.Platform.Pcds[TokenCName, TokenSpaceGuidCName].Type\r
933     if PcdItemType in gDynamicExPcd:\r
934         PcdTokenName = '_PCD_TOKEN_' + TokenCName\r
935         AutoGenH.Append('#define %s  LibPcdGetEx%s(&%s, %s)\n' % (GetModeName, DatumSizeLib, TokenSpaceGuidCName, PcdTokenName))\r
936         if DatumType == 'VOID*':\r
937             AutoGenH.Append('#define %s(SizeOfBuffer, Buffer)  LibPcdSetEx%s(&%s, %s, (SizeOfBuffer), (Buffer))\n' % (SetModeName,DatumSizeLib, TokenSpaceGuidCName, PcdTokenName))\r
938         else:\r
939             AutoGenH.Append('#define %s(Value)  LibPcdSetEx%s(&%s, %s, (Value))\n' % (SetModeName, DatumSizeLib, TokenSpaceGuidCName, PcdTokenName))\r
940     if PcdItemType in gDynamicPcd:\r
941         PcdTokenName = '_PCD_TOKEN_' + TokenCName\r
942         AutoGenH.Append('#define %s  LibPcdGet%s(%s)\n' % (GetModeName, DatumSizeLib, PcdTokenName))\r
943         if DatumType == 'VOID*':\r
944             AutoGenH.Append('#define %s(SizeOfBuffer, Buffer)  LibPcdSet%s(%s, (SizeOfBuffer), (Buffer))\n' %(SetModeName, DatumSizeLib, PcdTokenName))\r
945         else:\r
946             AutoGenH.Append('#define %s(Value)  LibPcdSet%s(%s, (Value))\n' % (SetModeName, DatumSizeLib, PcdTokenName))\r
947     if PcdItemType == TAB_PCDS_PATCHABLE_IN_MODULE:\r
948         PcdVariableName = '_gPcd_' + gItemTypeStringDatabase[TAB_PCDS_PATCHABLE_IN_MODULE] + '_' + TokenCName\r
949         AutoGenH.Append('extern %s _gPcd_BinaryPatch_%s%s;\n' %(DatumType, TokenCName, Array) )\r
950         AutoGenH.Append('#define %s  %s_gPcd_BinaryPatch_%s\n' %(GetModeName, Type, TokenCName))\r
951         AutoGenH.Append('#define %s(Value)  (%s = (Value))\n' % (SetModeName, PcdVariableName))\r
952     if PcdItemType == TAB_PCDS_FIXED_AT_BUILD or PcdItemType == TAB_PCDS_FEATURE_FLAG:\r
953         AutoGenH.Append('extern const %s _gPcd_FixedAtBuild_%s%s;\n' %(DatumType, TokenCName, Array))\r
954         AutoGenH.Append('#define %s  %s_gPcd_FixedAtBuild_%s\n' %(GetModeName, Type, TokenCName))\r
955         AutoGenH.Append('//#define %s  ASSERT(FALSE)  // It is not allowed to set value for a FIXED_AT_BUILD PCD\n' % SetModeName)\r
956 \r
957 def CreatePcdDatabasePhaseSpecificAutoGen (Platform, Phase):\r
958     AutoGenC = TemplateString()\r
959     AutoGenH = TemplateString()\r
960 \r
961     Dict = {\r
962         'PHASE'                         : Phase,\r
963         'GUID_TABLE_SIZE'               : '1',\r
964         'STRING_TABLE_SIZE'             : '1',\r
965         'SKUID_TABLE_SIZE'              : '1',\r
966         'LOCAL_TOKEN_NUMBER_TABLE_SIZE' : '1',\r
967         'LOCAL_TOKEN_NUMBER'            : '0',\r
968         'EXMAPPING_TABLE_SIZE'          : '1',\r
969         'EX_TOKEN_NUMBER'               : '0',\r
970         'SIZE_TABLE_SIZE'               : '2',\r
971         'GUID_TABLE_EMPTY'              : 'TRUE',\r
972         'STRING_TABLE_EMPTY'            : 'TRUE',\r
973         'SKUID_TABLE_EMPTY'             : 'TRUE',\r
974         'DATABASE_EMPTY'                : 'TRUE',\r
975         'EXMAP_TABLE_EMPTY'             : 'TRUE',\r
976         'PCD_DATABASE_UNINIT_EMPTY'     : '  UINT8  dummy; /* PCD_DATABASE_UNINIT is emptry */',\r
977         'SYSTEM_SKU_ID'                 : '  SKU_ID             SystemSkuId;',\r
978         'SYSTEM_SKU_ID_VALUE'           : '0'\r
979     }\r
980 \r
981     for DatumType in ['UINT64','UINT32','UINT16','UINT8','BOOLEAN']:\r
982         Dict['VARDEF_CNAME_' + DatumType] = []\r
983         Dict['VARDEF_GUID_' + DatumType]  = []\r
984         Dict['VARDEF_SKUID_' + DatumType] = []\r
985         Dict['VARDEF_VALUE_' + DatumType] = []\r
986         for Init in ['INIT','UNINIT']:\r
987             Dict[Init+'_CNAME_DECL_' + DatumType]   = []\r
988             Dict[Init+'_GUID_DECL_' + DatumType]    = []\r
989             Dict[Init+'_NUMSKUS_DECL_' + DatumType] = []\r
990             Dict[Init+'_VALUE_' + DatumType]        = []\r
991 \r
992     for Type in ['STRING_HEAD','VPD_HEAD','VARIABLE_HEAD']:\r
993         Dict[Type + '_CNAME_DECL']   = []\r
994         Dict[Type + '_GUID_DECL']    = []\r
995         Dict[Type + '_NUMSKUS_DECL'] = []\r
996         Dict[Type + '_VALUE'] = []\r
997 \r
998     Dict['STRING_TABLE_INDEX'] = []\r
999     Dict['STRING_TABLE_LENGTH']  = []\r
1000     Dict['STRING_TABLE_CNAME'] = []\r
1001     Dict['STRING_TABLE_GUID']  = []\r
1002     Dict['STRING_TABLE_VALUE'] = []\r
1003 \r
1004     Dict['SIZE_TABLE_CNAME'] = []\r
1005     Dict['SIZE_TABLE_GUID']  = []\r
1006     Dict['SIZE_TABLE_CURRENT_LENGTH']  = []\r
1007     Dict['SIZE_TABLE_MAXIMUM_LENGTH']  = []\r
1008 \r
1009     Dict['EXMAPPING_TABLE_EXTOKEN'] = []\r
1010     Dict['EXMAPPING_TABLE_LOCAL_TOKEN'] = []\r
1011     Dict['EXMAPPING_TABLE_GUID_INDEX'] = []\r
1012 \r
1013     Dict['GUID_STRUCTURE'] = []\r
1014 \r
1015     Dict['SKUID_VALUE'] = []\r
1016 \r
1017     if Phase == 'DXE':\r
1018         Dict['SYSTEM_SKU_ID'] = ''\r
1019         Dict['SYSTEM_SKU_ID_VALUE'] = ''\r
1020 \r
1021     StringTableIndex = 0\r
1022     StringTableSize = 0\r
1023     NumberOfLocalTokens = 0\r
1024     NumberOfPeiLocalTokens = 0\r
1025     NumberOfDxeLocalTokens = 0\r
1026     NumberOfExTokens = 0\r
1027     NumberOfSizeItems = 0\r
1028     GuidList = []\r
1029 \r
1030     for Pcd in Platform.DynamicPcdList:\r
1031         CName = Pcd.TokenCName\r
1032         TokenSpaceGuidCName = Pcd.TokenSpaceGuidCName\r
1033 \r
1034         EdkLogger.debug(EdkLogger.DEBUG_3, "PCD: %s %s (%s : %s)" % (CName, TokenSpaceGuidCName, Pcd.Phase, Phase))\r
1035         if Pcd.DatumType not in gDatumSizeStringDatabase:\r
1036             EdkLogger.error("AutoGen", AUTOGEN_ERROR, "Unknown datum type [%s] of PCD %s|%s" % (Pcd.DatumType, Pcd.TokenCName, Pcd.TokenSpaceGuidCName))\r
1037 \r
1038         if Pcd.Phase == 'PEI':\r
1039             NumberOfPeiLocalTokens += 1\r
1040         if Pcd.Phase == 'DXE':\r
1041             NumberOfDxeLocalTokens += 1\r
1042         if Pcd.Phase != Phase:\r
1043             continue\r
1044 \r
1045         #\r
1046         # TODO: need GetGuidValue() definition\r
1047         #\r
1048         TokenSpaceGuidStructure = GetGuidValue(Platform.PackageList, TokenSpaceGuidCName)\r
1049         TokenSpaceGuid = GuidStructureStringToGuidValueName(TokenSpaceGuidStructure)\r
1050         if Pcd.Type == 'DYNAMIC_EX':\r
1051             if TokenSpaceGuid not in GuidList:\r
1052                 GuidList += [TokenSpaceGuid]\r
1053                 Dict['GUID_STRUCTURE'].append(TokenSpaceGuidStructure)\r
1054             NumberOfExTokens += 1\r
1055 \r
1056         ValueList = []\r
1057         StringHeadOffsetList = []\r
1058         VpdHeadOffsetList = []\r
1059         VariableHeadValueList = []\r
1060         Pcd.InitString = 'UNINIT'\r
1061 \r
1062         if Pcd.DatumType == 'VOID*':\r
1063             Pcd.TokenTypeList = ['PCD_DATUM_TYPE_POINTER']\r
1064         elif Pcd.DatumType == 'BOOLEAN':\r
1065             Pcd.TokenTypeList = ['PCD_DATUM_TYPE_UINT8']\r
1066         else:\r
1067             Pcd.TokenTypeList = ['PCD_DATUM_TYPE_' + Pcd.DatumType]\r
1068 \r
1069         if len(Pcd.SkuInfoList) > 1:\r
1070             Pcd.TokenTypeList += ['PCD_TYPE_SKU_ENABLED']\r
1071 \r
1072         for SkuName in Pcd.SkuInfoList:\r
1073             Sku = Pcd.SkuInfoList[SkuName]\r
1074             SkuId = Sku.SkuId\r
1075             if SkuId == None or SkuId == '':\r
1076                 continue\r
1077 \r
1078             if SkuId not in Dict['SKUID_VALUE']:\r
1079                 Dict['SKUID_VALUE'].append(SkuId)\r
1080 \r
1081             SkuIdIndex =   Dict['SKUID_VALUE'].index(SkuId)\r
1082             if len(Sku.VariableName) > 0:\r
1083                 Pcd.TokenTypeList += ['PCD_TYPE_HII']\r
1084                 Pcd.InitString = 'INIT'\r
1085                 VariableNameStructure = '{' + ', '.join(Sku.VariableName.split(" ")) + ', 0x0000}'\r
1086                 if VariableNameStructure not in Dict['STRING_TABLE_VALUE']:\r
1087                     Dict['STRING_TABLE_CNAME'].append(CName)\r
1088                     Dict['STRING_TABLE_GUID'].append(TokenSpaceGuid)\r
1089                     if StringTableIndex == 0:\r
1090                         Dict['STRING_TABLE_INDEX'].append('')\r
1091                     else:\r
1092                         Dict['STRING_TABLE_INDEX'].append('_%d' % StringTableIndex)\r
1093 \r
1094                     Dict['STRING_TABLE_LENGTH'].append(len(Sku.VariableName) + 1)\r
1095                     Dict['STRING_TABLE_VALUE'].append(VariableNameStructure)\r
1096                     StringTableIndex += 1\r
1097                     StringTableSize += len(Sku.VariableName) + 1\r
1098 \r
1099                 VariableHeadStringIndex = 0\r
1100                 for Index in range(Dict['STRING_TABLE_VALUE'].index(VariableNameStructure)):\r
1101                     VariableHeadStringIndex += Dict['STRING_TABLE_LENGTH'][Index]\r
1102 \r
1103                 VariableGuidStructure = GetGuidValue(Platform.PackageList, Sku.VariableGuid)\r
1104                 VariableGuid = GuidStructureStringToGuidValueName(VariableGuidStructure)\r
1105                 if VariableGuid not in GuidList:\r
1106                     GuidList += [VariableGuid]\r
1107                     Dict['GUID_STRUCTURE'].append(VariableGuidStructure)\r
1108                 VariableHeadGuidIndex = GuidList.index(VariableGuid)\r
1109 \r
1110                 VariableHeadValueList.append('%d, %d, %s, offsetof(${PHASE}_PCD_DATABASE, Init.%s_%s_VariableDefault_%s)' %\r
1111                                              (VariableHeadGuidIndex, VariableHeadStringIndex, Sku.VariableOffset, CName, TokenSpaceGuid, SkuIdIndex))\r
1112                 Dict['VARDEF_CNAME_'+Pcd.DatumType].append(CName)\r
1113                 Dict['VARDEF_GUID_'+Pcd.DatumType].append(TokenSpaceGuid)\r
1114                 Dict['VARDEF_SKUID_'+Pcd.DatumType].append(SkuIdIndex)\r
1115                 Dict['VARDEF_VALUE_'+Pcd.DatumType].append(Sku.HiiDefaultValue)\r
1116             elif Sku.VpdOffset != '':\r
1117                 Pcd.TokenTypeList += ['PCD_TYPE_VPD']\r
1118                 Pcd.InitString = 'INIT'\r
1119                 VpdHeadOffsetList.append(Sku.VpdOffset)\r
1120             else:\r
1121                 if Pcd.DatumType == 'VOID*':\r
1122                     Pcd.TokenTypeList += ['PCD_TYPE_STRING']\r
1123                     Pcd.InitString = 'INIT'\r
1124                     if Sku.DefaultValue != '':\r
1125                         NumberOfSizeItems += 1\r
1126                         Dict['STRING_TABLE_CNAME'].append(CName)\r
1127                         Dict['STRING_TABLE_GUID'].append(TokenSpaceGuid)\r
1128 \r
1129                         if StringTableIndex == 0:\r
1130                             Dict['STRING_TABLE_INDEX'].append('')\r
1131                         else:\r
1132                             Dict['STRING_TABLE_INDEX'].append('_%d' % StringTableIndex)\r
1133                         if Sku.DefaultValue[0] == 'L':\r
1134                             Size = (len(Sku.DefaultValue) - 3) * 2\r
1135                             Dict['STRING_TABLE_VALUE'].append(Sku.DefaultValue)\r
1136                         elif Sku.DefaultValue[0] == '"':\r
1137                             Size = len(Sku.DefaultValue) - 2\r
1138                             Dict['STRING_TABLE_VALUE'].append(Sku.DefaultValue)\r
1139                         elif Sku.DefaultValue[0] == '{':\r
1140                             Size = len(Sku.DefaultValue.replace(',',' ').split())\r
1141                             Dict['STRING_TABLE_VALUE'].append('{' + Sku.DefaultValue + '}')\r
1142 \r
1143                         StringHeadOffsetList.append(str(StringTableSize))\r
1144                         Dict['SIZE_TABLE_CNAME'].append(CName)\r
1145                         Dict['SIZE_TABLE_GUID'].append(TokenSpaceGuid)\r
1146                         Dict['SIZE_TABLE_CURRENT_LENGTH'].append(Size)\r
1147                         Dict['SIZE_TABLE_MAXIMUM_LENGTH'].append(Pcd.MaxDatumSize)\r
1148                         if Pcd.MaxDatumSize != '' and Pcd.MaxDatumSize > Size:\r
1149                             Size = int(Pcd.MaxDatumSize, 0)\r
1150                         Dict['STRING_TABLE_LENGTH'].append(Size / 2 + 1)\r
1151                         StringTableIndex += 1\r
1152                         StringTableSize += (Size / 2 + 1)\r
1153                 else:\r
1154                     Pcd.TokenTypeList += ['PCD_TYPE_DATA']\r
1155                     if Sku.DefaultValue == 'TRUE':\r
1156                         Pcd.InitString = 'INIT'\r
1157                     else:\r
1158                         try:\r
1159                             if int(Sku.DefaultValue, 0) != 0:\r
1160                                 Pcd.InitString = 'INIT'\r
1161                         except:\r
1162                             pass\r
1163                     ValueList.append(Sku.DefaultValue)\r
1164 \r
1165         Pcd.TokenTypeList = list(set(Pcd.TokenTypeList))\r
1166 \r
1167         if 'PCD_TYPE_HII' in Pcd.TokenTypeList:\r
1168             Dict['VARIABLE_HEAD_CNAME_DECL'].append(CName)\r
1169             Dict['VARIABLE_HEAD_GUID_DECL'].append(TokenSpaceGuid)\r
1170             Dict['VARIABLE_HEAD_NUMSKUS_DECL'].append(len(Pcd.SkuInfoList))\r
1171             Dict['VARIABLE_HEAD_VALUE'].append('{ %s }\n' % ' },\n    { '.join(VariableHeadValueList))\r
1172         if 'PCD_TYPE_VPD' in Pcd.TokenTypeList:\r
1173             Dict['VPD_HEAD_CNAME_DECL'].append(CName)\r
1174             Dict['VPD_HEAD_GUID_DECL'].append(TokenSpaceGuid)\r
1175             Dict['VPD_HEAD_NUMSKUS_DECL'].append(len(Pcd.SkuInfoList))\r
1176             Dict['VPD_HEAD_VALUE'].append('{ %s }' % ' }, { '.join(VpdHeadOffsetList))\r
1177         if 'PCD_TYPE_STRING' in Pcd.TokenTypeList:\r
1178             Dict['STRING_HEAD_CNAME_DECL'].append(CName)\r
1179             Dict['STRING_HEAD_GUID_DECL'].append(TokenSpaceGuid)\r
1180             Dict['STRING_HEAD_NUMSKUS_DECL'].append(len(Pcd.SkuInfoList))\r
1181             Dict['STRING_HEAD_VALUE'].append(', '.join(StringHeadOffsetList))\r
1182         if 'PCD_TYPE_DATA' in Pcd.TokenTypeList:\r
1183             Dict[Pcd.InitString+'_CNAME_DECL_'+Pcd.DatumType].append(CName)\r
1184             Dict[Pcd.InitString+'_GUID_DECL_'+Pcd.DatumType].append(TokenSpaceGuid)\r
1185             Dict[Pcd.InitString+'_NUMSKUS_DECL_'+Pcd.DatumType].append(len(Pcd.SkuInfoList))\r
1186             if Pcd.InitString == 'UNINIT':\r
1187                 Dict['PCD_DATABASE_UNINIT_EMPTY'] = ''\r
1188             else:\r
1189                 Dict[Pcd.InitString+'_VALUE_'+Pcd.DatumType].append(', '.join(ValueList))\r
1190 \r
1191     if Phase == 'PEI':\r
1192         NumberOfLocalTokens = NumberOfPeiLocalTokens\r
1193     if Phase == 'DXE':\r
1194         NumberOfLocalTokens = NumberOfDxeLocalTokens\r
1195 \r
1196     Dict['TOKEN_INIT']       = ['' for x in range(NumberOfLocalTokens)]\r
1197     Dict['TOKEN_CNAME']      = ['' for x in range(NumberOfLocalTokens)]\r
1198     Dict['TOKEN_GUID']       = ['' for x in range(NumberOfLocalTokens)]\r
1199     Dict['TOKEN_TYPE']       = ['' for x in range(NumberOfLocalTokens)]\r
1200 \r
1201     for Pcd in Platform.DynamicPcdList:\r
1202         CName = Pcd.TokenCName\r
1203         TokenSpaceGuidCName = Pcd.TokenSpaceGuidCName\r
1204         if Pcd.Phase != Phase:\r
1205             continue\r
1206 \r
1207         TokenSpaceGuid = GuidStructureStringToGuidValueName(GetGuidValue(Platform.PackageList, TokenSpaceGuidCName))\r
1208         GeneratedTokenNumber = Platform.PcdTokenNumber[CName, TokenSpaceGuidCName] - 1\r
1209         if Phase == 'DXE':\r
1210             GeneratedTokenNumber -= NumberOfPeiLocalTokens\r
1211 \r
1212         EdkLogger.debug(EdkLogger.DEBUG_1, "PCD = %s | %s" % (CName, TokenSpaceGuidCName))\r
1213         EdkLogger.debug(EdkLogger.DEBUG_1, "phase = %s" % Phase)\r
1214         EdkLogger.debug(EdkLogger.DEBUG_1, "GeneratedTokenNumber = %s" % str(GeneratedTokenNumber))\r
1215 \r
1216         Dict['TOKEN_INIT'][GeneratedTokenNumber] = 'Init'\r
1217         if Pcd.InitString == 'UNINIT':\r
1218             Dict['TOKEN_INIT'][GeneratedTokenNumber] = 'Uninit'\r
1219         Dict['TOKEN_CNAME'][GeneratedTokenNumber] = CName\r
1220         Dict['TOKEN_GUID'][GeneratedTokenNumber] = TokenSpaceGuid\r
1221         Dict['TOKEN_TYPE'][GeneratedTokenNumber] = ' | '.join(Pcd.TokenTypeList)\r
1222         if Pcd.Type == 'DYNAMIC_EX':\r
1223             Dict['EXMAPPING_TABLE_EXTOKEN'].append(Pcd.Token)\r
1224             Dict['EXMAPPING_TABLE_LOCAL_TOKEN'].append(GeneratedTokenNumber)\r
1225             Dict['EXMAPPING_TABLE_GUID_INDEX'].append(GuidList.index(TokenSpaceGuid))\r
1226 \r
1227     if GuidList != []:\r
1228         Dict['GUID_TABLE_EMPTY'] = 'FALSE'\r
1229         Dict['GUID_TABLE_SIZE'] = len(GuidList)\r
1230     else:\r
1231         Dict['GUID_STRUCTURE'] = [GuidStringToGuidStructureString('00000000-0000-0000-0000-000000000000')]\r
1232 \r
1233     if StringTableIndex == 0:\r
1234         Dict['STRING_TABLE_INDEX'].append('')\r
1235         Dict['STRING_TABLE_LENGTH'].append(1)\r
1236         Dict['STRING_TABLE_CNAME'].append('')\r
1237         Dict['STRING_TABLE_GUID'].append('')\r
1238         Dict['STRING_TABLE_VALUE'].append('{ 0 }')\r
1239     else:\r
1240         Dict['STRING_TABLE_EMPTY'] = 'FALSE'\r
1241         Dict['STRING_TABLE_SIZE'] = StringTableSize\r
1242 \r
1243     if Dict['SIZE_TABLE_CNAME'] == []:\r
1244         Dict['SIZE_TABLE_CNAME'].append('')\r
1245         Dict['SIZE_TABLE_GUID'].append('')\r
1246         Dict['SIZE_TABLE_CURRENT_LENGTH'].append(0)\r
1247         Dict['SIZE_TABLE_MAXIMUM_LENGTH'].append(0)\r
1248 \r
1249     if NumberOfLocalTokens != 0:\r
1250         Dict['DATABASE_EMPTY']                = 'FALSE'\r
1251         Dict['LOCAL_TOKEN_NUMBER_TABLE_SIZE'] = NumberOfLocalTokens\r
1252         Dict['LOCAL_TOKEN_NUMBER']            = NumberOfLocalTokens\r
1253 \r
1254     if NumberOfExTokens != 0:\r
1255         Dict['EXMAP_TABLE_EMPTY']    = 'FALSE'\r
1256         Dict['EXMAPPING_TABLE_SIZE'] = NumberOfExTokens\r
1257         Dict['EX_TOKEN_NUMBER']      = NumberOfExTokens\r
1258     else:\r
1259         Dict['EXMAPPING_TABLE_EXTOKEN'].append(0)\r
1260         Dict['EXMAPPING_TABLE_LOCAL_TOKEN'].append(0)\r
1261         Dict['EXMAPPING_TABLE_GUID_INDEX'].append(0)\r
1262 \r
1263     if NumberOfSizeItems != 0:\r
1264         Dict['SIZE_TABLE_SIZE'] = NumberOfSizeItems * 2\r
1265 \r
1266     AutoGenH.Append(gPcdDatabaseAutoGenH, Dict)\r
1267     if NumberOfLocalTokens == 0:\r
1268         AutoGenC.Append(gEmptyPcdDatabaseAutoGenC, Dict)\r
1269     else:\r
1270         AutoGenC.Append(gPcdDatabaseAutoGenC, Dict)\r
1271 \r
1272     return AutoGenH, AutoGenC\r
1273 \r
1274 def CreatePcdDatabaseCode (Info, AutoGenC, AutoGenH):\r
1275     if Info.PcdIsDriver == "":\r
1276         return\r
1277     if Info.PcdIsDriver not in gPcdPhaseMap:\r
1278         EdkLogger.error("AutoGen", AUTOGEN_ERROR, "Not supported PcdIsDriver type:%s\n" % Info.PcdIsDriver)\r
1279 \r
1280     AutoGenH.Append(gPcdDatabaseCommonAutoGenH)\r
1281     AdditionalAutoGenH, AdditionalAutoGenC = CreatePcdDatabasePhaseSpecificAutoGen (Info.PlatformInfo, 'PEI')\r
1282     AutoGenH.Append(AdditionalAutoGenH.String)\r
1283 \r
1284     Phase = gPcdPhaseMap[Info.PcdIsDriver]\r
1285     if Phase == 'PEI':\r
1286         AutoGenC.Append(AdditionalAutoGenC.String)\r
1287 \r
1288     if Phase == 'DXE':\r
1289         AdditionalAutoGenH, AdditionalAutoGenC = CreatePcdDatabasePhaseSpecificAutoGen (Info.PlatformInfo, Phase)\r
1290         AutoGenH.Append(AdditionalAutoGenH.String)\r
1291         AutoGenC.Append(AdditionalAutoGenC.String)\r
1292         AutoGenH.Append(gPcdDatabaseEpilogueAutoGenH)\r
1293 \r
1294 def CreateLibraryConstructorCode(Info, AutoGenC, AutoGenH):\r
1295     if Info.IsLibrary:\r
1296         return\r
1297     #\r
1298     # Library Constructors\r
1299     #\r
1300     ConstructorList = []\r
1301     for Lib in Info.DependentLibraryList:\r
1302         if len(Lib.ConstructorList) <= 0:\r
1303             continue\r
1304         ConstructorList.extend(Lib.ConstructorList)\r
1305 \r
1306     Dict = {'Type':'Constructor', 'Function':ConstructorList}\r
1307     if Info.ModuleType == 'BASE':\r
1308         if len(ConstructorList) == 0:\r
1309             AutoGenC.Append(gLibraryString[0], Dict)\r
1310         else:\r
1311             AutoGenC.Append(gLibraryString[3], Dict)\r
1312     elif Info.ModuleType in ['PEI_CORE','PEIM']:\r
1313         if len(ConstructorList) == 0:\r
1314             AutoGenC.Append(gLibraryString[1], Dict)\r
1315         else:\r
1316             AutoGenC.Append(gLibraryString[4], Dict)\r
1317     elif Info.ModuleType in ['DXE_CORE','DXE_DRIVER','DXE_SMM_DRIVER','DXE_RUNTIME_DRIVER','DXE_SAL_DRIVER','UEFI_DRIVER','UEFI_APPLICATION']:\r
1318         if len(ConstructorList) == 0:\r
1319             AutoGenC.Append(gLibraryString[2], Dict)\r
1320         else:\r
1321             AutoGenC.Append(gLibraryString[5], Dict)\r
1322 \r
1323 def CreateLibraryDestructorCode(Info, AutoGenC, AutoGenH):\r
1324     if Info.IsLibrary:\r
1325         return\r
1326     #\r
1327     # Library Destructors\r
1328     #\r
1329     DestructorList = []\r
1330     for Lib in Info.DependentLibraryList:\r
1331         if len(Lib.DestructorList) <= 0:\r
1332             continue\r
1333         DestructorList.extend(Lib.DestructorList)\r
1334 \r
1335     DestructorList.reverse()\r
1336     if Info.ModuleType in ['DXE_CORE','DXE_DRIVER','DXE_SMM_DRIVER','DXE_RUNTIME_DRIVER','DXE_SAL_DRIVER','UEFI_DRIVER','UEFI_APPLICATION']:\r
1337         if len(DestructorList) == 0:\r
1338             AutoGenC.Append(gLibraryString[2], {'Type':'Destructor','Function':DestructorList})\r
1339         else:\r
1340             AutoGenC.Append(gLibraryString[5], {'Type':'Destructor','Function':DestructorList})\r
1341 \r
1342 \r
1343 def CreateModuleEntryPointCode(Info, AutoGenC, AutoGenH):\r
1344     if Info.IsLibrary or Info.ModuleType == "USER_DEFINED":\r
1345         return\r
1346     #\r
1347     # Module Entry Points\r
1348     #\r
1349     NumEntryPoints = len(Info.Module.ModuleEntryPointList)\r
1350     Dict = {'Function':Info.Module.ModuleEntryPointList}\r
1351 \r
1352     if Info.ModuleType in ['PEI_CORE', 'DXE_CORE']:\r
1353         if NumEntryPoints != 1:\r
1354             EdkLogger.error("AutoGen", AUTOGEN_ERROR, '%s must have exactly one entry point' % Info.ModuleType)\r
1355     if Info.ModuleType == 'PEI_CORE':\r
1356         AutoGenC.Append(gPeiCoreEntryPointString, Dict)\r
1357     elif Info.ModuleType == 'DXE_CORE':\r
1358         AutoGenC.Append(gDxeCoreEntryPointString, Dict)\r
1359     elif Info.ModuleType == 'PEIM':\r
1360         if NumEntryPoints < 2:\r
1361             AutoGenC.Append(gPeimEntryPointString[NumEntryPoints], Dict)\r
1362         else:\r
1363             AutoGenC.Append(gPeimEntryPointString[2], Dict)\r
1364     elif Info.ModuleType in ['DXE_RUNTIME_DRIVER','DXE_DRIVER','DXE_SMM_DRIVER', 'DXE_SAL_DRIVER','UEFI_DRIVER','UEFI_APPLICATION']:\r
1365         if Info.ModuleType == 'DXE_SMM_DRIVER':\r
1366             if NumEntryPoints == 0:\r
1367                 AutoGenC.Append(gDxeSmmEntryPointString[0], Dict)\r
1368             else:\r
1369                 AutoGenC.Append(gDxeSmmEntryPointString[1], Dict)\r
1370         else:\r
1371             if NumEntryPoints < 2:\r
1372                 AutoGenC.Append(gUefiEntryPointString[NumEntryPoints], Dict)\r
1373             else:\r
1374                 AutoGenC.Append(gUefiEntryPointString[2], Dict)\r
1375 \r
1376 def CreateModuleUnloadImageCode(Info, AutoGenC, AutoGenH):\r
1377     if Info.IsLibrary or Info.ModuleType == "USER_DEFINED":\r
1378         return\r
1379     #\r
1380     # Unload Image Handlers\r
1381     #\r
1382     NumUnloadImage = len(Info.Module.ModuleUnloadImageList)\r
1383     Dict = {'Count':NumUnloadImage, 'Function':Info.Module.ModuleUnloadImageList}\r
1384     if NumUnloadImage < 2:\r
1385         AutoGenC.Append(gUefiUnloadImageString[NumUnloadImage], Dict)\r
1386     else:\r
1387         AutoGenC.Append(gUefiUnloadImageString[2], Dict)\r
1388 \r
1389 def CreateGuidDefinitionCode(Info, AutoGenC, AutoGenH):\r
1390     if Info.IsLibrary:\r
1391         return\r
1392 \r
1393     if Info.ModuleType in ["USER_DEFINED", "BASE"]:\r
1394         GuidType = "GUID"\r
1395     else:\r
1396         GuidType = "EFI_GUID"\r
1397 \r
1398     #\r
1399     # GUIDs\r
1400     #\r
1401     for Key in Info.GuidList:\r
1402         AutoGenC.Append('GLOBAL_REMOVE_IF_UNREFERENCED %s %s = %s;\n' % (GuidType, Key, Info.GuidList[Key]))\r
1403 \r
1404 def CreateProtocolDefinitionCode(Info, AutoGenC, AutoGenH):\r
1405     if Info.IsLibrary:\r
1406         return\r
1407 \r
1408     if Info.ModuleType in ["USER_DEFINED", "BASE"]:\r
1409         GuidType = "GUID"\r
1410     else:\r
1411         GuidType = "EFI_GUID"\r
1412 \r
1413     #\r
1414     # Protocol GUIDs\r
1415     #\r
1416     for Key in Info.ProtocolList:\r
1417         AutoGenC.Append('GLOBAL_REMOVE_IF_UNREFERENCED %s %s = %s;\n' % (GuidType, Key, Info.ProtocolList[Key]))\r
1418 \r
1419 def CreatePpiDefinitionCode(Info, AutoGenC, AutoGenH):\r
1420     if Info.IsLibrary:\r
1421         return\r
1422 \r
1423     if Info.ModuleType in ["USER_DEFINED", "BASE"]:\r
1424         GuidType = "GUID"\r
1425     else:\r
1426         GuidType = "EFI_GUID"\r
1427 \r
1428     #\r
1429     # PPI GUIDs\r
1430     #\r
1431     for Key in Info.PpiList:\r
1432         AutoGenC.Append('GLOBAL_REMOVE_IF_UNREFERENCED %s %s = %s;\n' % (GuidType, Key, Info.PpiList[Key]))\r
1433 \r
1434 def CreatePcdCode(Info, AutoGenC, AutoGenH):\r
1435     if Info.IsLibrary:\r
1436         for Pcd in Info.PcdList:\r
1437             CreateLibraryPcdCode(Info, AutoGenC, AutoGenH, Pcd)\r
1438     else:\r
1439         for Pcd in Info.PcdList:\r
1440             CreateModulePcdCode(Info, AutoGenC, AutoGenH, Pcd)\r
1441     CreatePcdDatabaseCode(Info, AutoGenC, AutoGenH)\r
1442 \r
1443 def CreateUnicodeStringCode(Info, AutoGenC, AutoGenH):\r
1444     if len(Info.UnicodeFileList) == 0:\r
1445         return\r
1446 \r
1447     WorkingDir = os.getcwd()\r
1448     os.chdir(Info.WorkspaceDir)\r
1449 \r
1450     IncList = [os.path.join(Info.WorkspaceDir, Inc) for Inc in Info.IncludePathList]\r
1451     Header, Code = GetStringFiles(Info.UnicodeFileList, IncList, [], Info.Name)\r
1452     AutoGenC.Append("\n//\n//Unicode String Pack Definition\n//\n")\r
1453     AutoGenC.Append(Code)\r
1454     AutoGenC.Append("\n")\r
1455     AutoGenH.Append("\n//\n//Unicode String ID\n//\n")\r
1456     AutoGenH.Append(Header)\r
1457     AutoGenH.Append("\n#define STRING_ARRAY_NAME %sStrings\n" % Info.Name)\r
1458     os.chdir(WorkingDir)\r
1459 \r
1460 def CreateHeaderCode(Info, AutoGenC, AutoGenH):\r
1461     # file header\r
1462     AutoGenH.Append(gAutoGenHeaderString,   {'FileName':'AutoGen.h'})\r
1463     # header file Prologue\r
1464     AutoGenH.Append(gAutoGenHPrologueString,{'Guid':Info.Guid.replace('-','_')})\r
1465     # specification macros\r
1466     AutoGenH.Append(gSpecificationString,   {'Specification':Info.MacroList})\r
1467     # header files includes\r
1468     AutoGenH.Append("#include <%s>\n\n" % gBasicHeaderFile)\r
1469     #autoGenH.Append("\n#define ASM_PFX(name) _##name\n\n")\r
1470 \r
1471     AutoGenH.Append("#define EFI_CALLER_ID_GUID \\\n  %s\n" % GuidStringToGuidStructureString(Info.Guid))\r
1472     AutoGenH.Append('\nextern GUID  gEfiCallerIdGuid;\n\n')\r
1473 \r
1474     if Info.IsLibrary:\r
1475         return\r
1476 \r
1477     # C file header\r
1478     AutoGenC.Append(gAutoGenHeaderString, {'FileName':'AutoGen.c'})\r
1479     # C file header files includes\r
1480     for Inc in gModuleTypeHeaderFile[Info.ModuleType]:\r
1481         AutoGenC.Append("#include <%s>\n" % Inc)\r
1482 \r
1483     #\r
1484     # Publish the CallerId Guid\r
1485     #\r
1486     AutoGenC.Append('\nGLOBAL_REMOVE_IF_UNREFERENCED GUID gEfiCallerIdGuid = %s;\n' % GuidStringToGuidStructureString(Info.Guid))\r
1487 \r
1488 def CreateFooterCode(Info, AutoGenC, AutoGenH):\r
1489     AutoGenH.Append(gAutoGenHEpilogueString)\r
1490 \r
1491 def CreateCode(Info, AutoGenC, AutoGenH):\r
1492     CreateHeaderCode(Info, AutoGenC, AutoGenH)\r
1493 \r
1494     CreateLibraryConstructorCode(Info, AutoGenC, AutoGenH)\r
1495     CreateLibraryDestructorCode(Info, AutoGenC, AutoGenH)\r
1496     CreateModuleEntryPointCode(Info, AutoGenC, AutoGenH)\r
1497     CreateModuleUnloadImageCode(Info, AutoGenC, AutoGenH)\r
1498     CreateGuidDefinitionCode(Info, AutoGenC, AutoGenH)\r
1499     CreateProtocolDefinitionCode(Info, AutoGenC, AutoGenH)\r
1500     CreatePpiDefinitionCode(Info, AutoGenC, AutoGenH)\r
1501     CreatePcdCode(Info, AutoGenC, AutoGenH)\r
1502     CreateUnicodeStringCode(Info, AutoGenC, AutoGenH)\r
1503 \r
1504     CreateFooterCode(Info, AutoGenC, AutoGenH)\r
1505 \r
1506 def Generate(FilePath, Content):\r
1507     return SaveFileOnChange(FilePath, Content)\r