]>
Commit | Line | Data |
---|---|---|
30fdf114 LG |
1 | ## @file |
2 | # Routines for generating AutoGen.h and AutoGen.c | |
3 | # | |
4 | # Copyright (c) 2007, Intel Corporation | |
5 | # All rights reserved. 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 | ||
26 | ## PCD type string | |
27 | gItemTypeStringDatabase = { | |
28 | TAB_PCDS_FEATURE_FLAG : 'FixedAtBuild', | |
29 | TAB_PCDS_FIXED_AT_BUILD : 'FixedAtBuild', | |
30 | TAB_PCDS_PATCHABLE_IN_MODULE: 'BinaryPatch', | |
31 | TAB_PCDS_DYNAMIC : '', | |
32 | TAB_PCDS_DYNAMIC_DEFAULT : '', | |
33 | TAB_PCDS_DYNAMIC_VPD : '', | |
34 | TAB_PCDS_DYNAMIC_HII : '', | |
35 | TAB_PCDS_DYNAMIC_EX : '', | |
36 | TAB_PCDS_DYNAMIC_EX_DEFAULT : '', | |
37 | TAB_PCDS_DYNAMIC_EX_VPD : '', | |
38 | TAB_PCDS_DYNAMIC_EX_HII : '', | |
39 | } | |
40 | ||
41 | ## Dynamic PCD types | |
42 | gDynamicPcd = [TAB_PCDS_DYNAMIC, TAB_PCDS_DYNAMIC_DEFAULT, TAB_PCDS_DYNAMIC_VPD, TAB_PCDS_DYNAMIC_HII] | |
43 | ||
44 | ## Dynamic-ex PCD types | |
45 | gDynamicExPcd = [TAB_PCDS_DYNAMIC_EX, TAB_PCDS_DYNAMIC_EX_DEFAULT, TAB_PCDS_DYNAMIC_EX_VPD, TAB_PCDS_DYNAMIC_EX_HII] | |
46 | ||
47 | ## Datum size | |
48 | gDatumSizeStringDatabase = {'UINT8':'8','UINT16':'16','UINT32':'32','UINT64':'64','BOOLEAN':'BOOLEAN','VOID*':'8'} | |
49 | gDatumSizeStringDatabaseH = {'UINT8':'8','UINT16':'16','UINT32':'32','UINT64':'64','BOOLEAN':'BOOL','VOID*':'PTR'} | |
50 | gDatumSizeStringDatabaseLib = {'UINT8':'8','UINT16':'16','UINT32':'32','UINT64':'64','BOOLEAN':'Bool','VOID*':'Ptr'} | |
51 | ||
52 | ## Mapping between PCD driver type and EFI phase | |
53 | gPcdPhaseMap = { | |
54 | "PEI_PCD_DRIVER" : "PEI", | |
55 | "DXE_PCD_DRIVER" : "DXE" | |
56 | } | |
57 | ||
58 | gPcdDatabaseCommonAutoGenH = """ | |
59 | // | |
60 | // The following definition will be generated by build tool | |
61 | // | |
62 | ||
63 | // | |
64 | // Common definitions | |
65 | // | |
66 | typedef UINT8 SKU_ID; | |
67 | ||
68 | #define PCD_TYPE_SHIFT 28 | |
69 | ||
70 | #define PCD_TYPE_DATA (0x0 << PCD_TYPE_SHIFT) | |
71 | #define PCD_TYPE_HII (0x8 << PCD_TYPE_SHIFT) | |
72 | #define PCD_TYPE_VPD (0x4 << PCD_TYPE_SHIFT) | |
73 | #define PCD_TYPE_SKU_ENABLED (0x2 << PCD_TYPE_SHIFT) | |
74 | #define PCD_TYPE_STRING (0x1 << PCD_TYPE_SHIFT) | |
75 | ||
76 | #define PCD_TYPE_ALL_SET (PCD_TYPE_DATA | PCD_TYPE_HII | PCD_TYPE_VPD | PCD_TYPE_SKU_ENABLED | PCD_TYPE_STRING) | |
77 | ||
78 | #define PCD_DATUM_TYPE_SHIFT 24 | |
79 | ||
80 | #define PCD_DATUM_TYPE_POINTER (0x0 << PCD_DATUM_TYPE_SHIFT) | |
81 | #define PCD_DATUM_TYPE_UINT8 (0x1 << PCD_DATUM_TYPE_SHIFT) | |
82 | #define PCD_DATUM_TYPE_UINT16 (0x2 << PCD_DATUM_TYPE_SHIFT) | |
83 | #define PCD_DATUM_TYPE_UINT32 (0x4 << PCD_DATUM_TYPE_SHIFT) | |
84 | #define PCD_DATUM_TYPE_UINT64 (0x8 << PCD_DATUM_TYPE_SHIFT) | |
85 | ||
86 | #define PCD_DATUM_TYPE_ALL_SET (PCD_DATUM_TYPE_POINTER | \\ | |
87 | PCD_DATUM_TYPE_UINT8 | \\ | |
88 | PCD_DATUM_TYPE_UINT16 | \\ | |
89 | PCD_DATUM_TYPE_UINT32 | \\ | |
90 | PCD_DATUM_TYPE_UINT64) | |
91 | ||
92 | #define PCD_DATABASE_OFFSET_MASK (~(PCD_TYPE_ALL_SET | PCD_DATUM_TYPE_ALL_SET)) | |
93 | ||
94 | typedef struct { | |
95 | UINT32 ExTokenNumber; | |
96 | UINT16 LocalTokenNumber; // PCD Number of this particular platform build | |
97 | UINT16 ExGuidIndex; // Index of GuidTable | |
98 | } DYNAMICEX_MAPPING; | |
99 | ||
100 | typedef struct { | |
101 | UINT32 SkuDataStartOffset; //We have to use offsetof MACRO as we don't know padding done by compiler | |
102 | UINT32 SkuIdTableOffset; //Offset from the PCD_DB | |
103 | } SKU_HEAD; | |
104 | ||
105 | typedef struct { | |
106 | UINT16 GuidTableIndex; // Offset in Guid Table in units of GUID. | |
107 | UINT16 StringIndex; // Offset in String Table in units of UINT16. | |
108 | UINT16 Offset; // Offset in Variable | |
109 | UINT16 DefaultValueOffset; // Offset of the Default Value | |
110 | } VARIABLE_HEAD; | |
111 | ||
112 | typedef struct { | |
113 | UINT32 Offset; | |
114 | } VPD_HEAD; | |
115 | ||
116 | typedef UINT16 STRING_HEAD; | |
117 | ||
118 | typedef UINT16 SIZE_INFO; | |
119 | ||
120 | #define offsetof(s,m) (UINT32) (UINTN) &(((s *)0)->m) | |
121 | ||
122 | """ | |
123 | ||
124 | gPcdDatabaseEpilogueAutoGenH = """ | |
125 | typedef struct { | |
126 | PEI_PCD_DATABASE PeiDb; | |
127 | DXE_PCD_DATABASE DxeDb; | |
128 | } PCD_DATABASE; | |
129 | ||
130 | #define PCD_TOTAL_TOKEN_NUMBER (PEI_LOCAL_TOKEN_NUMBER + DXE_LOCAL_TOKEN_NUMBER) | |
131 | ||
132 | """ | |
133 | ||
134 | gPcdDatabaseAutoGenH = TemplateString(""" | |
135 | #define ${PHASE}_GUID_TABLE_SIZE ${GUID_TABLE_SIZE} | |
136 | #define ${PHASE}_STRING_TABLE_SIZE ${STRING_TABLE_SIZE} | |
137 | #define ${PHASE}_SKUID_TABLE_SIZE ${SKUID_TABLE_SIZE} | |
138 | #define ${PHASE}_LOCAL_TOKEN_NUMBER_TABLE_SIZE ${LOCAL_TOKEN_NUMBER_TABLE_SIZE} | |
139 | #define ${PHASE}_LOCAL_TOKEN_NUMBER ${LOCAL_TOKEN_NUMBER} | |
140 | #define ${PHASE}_EXMAPPING_TABLE_SIZE ${EXMAPPING_TABLE_SIZE} | |
141 | #define ${PHASE}_EX_TOKEN_NUMBER ${EX_TOKEN_NUMBER} | |
142 | #define ${PHASE}_SIZE_TABLE_SIZE ${SIZE_TABLE_SIZE} | |
143 | #define ${PHASE}_GUID_TABLE_EMPTY ${GUID_TABLE_EMPTY} | |
144 | #define ${PHASE}_STRING_TABLE_EMPTY ${STRING_TABLE_EMPTY} | |
145 | #define ${PHASE}_SKUID_TABLE_EMPTY ${SKUID_TABLE_EMPTY} | |
146 | #define ${PHASE}_DATABASE_EMPTY ${DATABASE_EMPTY} | |
147 | #define ${PHASE}_EXMAP_TABLE_EMPTY ${EXMAP_TABLE_EMPTY} | |
148 | ||
149 | typedef struct { | |
150 | ${BEGIN} UINT64 ${INIT_CNAME_DECL_UINT64}_${INIT_GUID_DECL_UINT64}[${INIT_NUMSKUS_DECL_UINT64}]; | |
151 | ${END} | |
152 | ${BEGIN} UINT64 ${VARDEF_CNAME_UINT64}_${VARDEF_GUID_UINT64}_VariableDefault_${VARDEF_SKUID_UINT64}; | |
153 | ${END} | |
154 | ${BEGIN} UINT32 ${INIT_CNAME_DECL_UINT32}_${INIT_GUID_DECL_UINT32}[${INIT_NUMSKUS_DECL_UINT32}]; | |
155 | ${END} | |
156 | ${BEGIN} UINT32 ${VARDEF_CNAME_UINT32}_${VARDEF_GUID_UINT32}_VariableDefault_${VARDEF_SKUID_UINT32}; | |
157 | ${END} | |
158 | ${BEGIN} VPD_HEAD ${VPD_HEAD_CNAME_DECL}_${VPD_HEAD_GUID_DECL}[${VPD_HEAD_NUMSKUS_DECL}]; | |
159 | ${END} | |
160 | DYNAMICEX_MAPPING ExMapTable[${PHASE}_EXMAPPING_TABLE_SIZE]; | |
161 | UINT32 LocalTokenNumberTable[${PHASE}_LOCAL_TOKEN_NUMBER_TABLE_SIZE]; | |
162 | GUID GuidTable[${PHASE}_GUID_TABLE_SIZE]; | |
163 | ${BEGIN} STRING_HEAD ${STRING_HEAD_CNAME_DECL}_${STRING_HEAD_GUID_DECL}[${STRING_HEAD_NUMSKUS_DECL}]; | |
164 | ${END} | |
165 | ${BEGIN} VARIABLE_HEAD ${VARIABLE_HEAD_CNAME_DECL}_${VARIABLE_HEAD_GUID_DECL}[${VARIABLE_HEAD_NUMSKUS_DECL}]; | |
166 | ${END} | |
167 | ${BEGIN} UINT8 StringTable${STRING_TABLE_INDEX}[${STRING_TABLE_LENGTH}]; /* ${STRING_TABLE_CNAME}_${STRING_TABLE_GUID} */ | |
168 | ${END} | |
169 | SIZE_INFO SizeTable[${PHASE}_SIZE_TABLE_SIZE]; | |
170 | ${BEGIN} UINT16 ${INIT_CNAME_DECL_UINT16}_${INIT_GUID_DECL_UINT16}[${INIT_NUMSKUS_DECL_UINT16}]; | |
171 | ${END} | |
172 | ${BEGIN} UINT16 ${VARDEF_CNAME_UINT16}_${VARDEF_GUID_UINT16}_VariableDefault_${VARDEF_SKUID_UINT16}; | |
173 | ${END} | |
174 | ${BEGIN} UINT8 ${INIT_CNAME_DECL_UINT8}_${INIT_GUID_DECL_UINT8}[${INIT_NUMSKUS_DECL_UINT8}]; | |
175 | ${END} | |
176 | ${BEGIN} UINT8 ${VARDEF_CNAME_UINT8}_${VARDEF_GUID_UINT8}_VariableDefault_${VARDEF_SKUID_UINT8}; | |
177 | ${END} | |
178 | ${BEGIN} BOOLEAN ${INIT_CNAME_DECL_BOOLEAN}_${INIT_GUID_DECL_BOOLEAN}[${INIT_NUMSKUS_DECL_BOOLEAN}]; | |
179 | ${END} | |
180 | ${BEGIN} BOOLEAN ${VARDEF_CNAME_BOOLEAN}_${VARDEF_GUID_BOOLEAN}_VariableDefault_${VARDEF_SKUID_BOOLEAN}; | |
181 | ${END} | |
182 | UINT8 SkuIdTable[${PHASE}_SKUID_TABLE_SIZE]; | |
183 | ${SYSTEM_SKU_ID} | |
184 | } ${PHASE}_PCD_DATABASE_INIT; | |
185 | ||
186 | typedef struct { | |
187 | ${PCD_DATABASE_UNINIT_EMPTY} | |
188 | ${BEGIN} UINT64 ${UNINIT_CNAME_DECL_UINT64}_${UNINIT_GUID_DECL_UINT64}[${UNINIT_NUMSKUS_DECL_UINT64}]; | |
189 | ${END} | |
190 | ${BEGIN} UINT32 ${UNINIT_CNAME_DECL_UINT32}_${UNINIT_GUID_DECL_UINT32}[${UNINIT_NUMSKUS_DECL_UINT32}]; | |
191 | ${END} | |
192 | ${BEGIN} UINT16 ${UNINIT_CNAME_DECL_UINT16}_${UNINIT_GUID_DECL_UINT16}[${UNINIT_NUMSKUS_DECL_UINT16}]; | |
193 | ${END} | |
194 | ${BEGIN} UINT8 ${UNINIT_CNAME_DECL_UINT8}_${UNINIT_GUID_DECL_UINT8}[${UNINIT_NUMSKUS_DECL_UINT8}]; | |
195 | ${END} | |
196 | ${BEGIN} BOOLEAN ${UNINIT_CNAME_DECL_BOOLEAN}_${UNINIT_GUID_DECL_BOOLEAN}[${UNINIT_NUMSKUS_DECL_BOOLEAN}]; | |
197 | ${END} | |
198 | } ${PHASE}_PCD_DATABASE_UNINIT; | |
199 | ||
200 | #define PCD_${PHASE}_SERVICE_DRIVER_VERSION 2 | |
201 | ||
202 | typedef struct { | |
203 | ${PHASE}_PCD_DATABASE_INIT Init; | |
204 | ${PHASE}_PCD_DATABASE_UNINIT Uninit; | |
205 | } ${PHASE}_PCD_DATABASE; | |
206 | ||
207 | #define ${PHASE}_NEX_TOKEN_NUMBER (${PHASE}_LOCAL_TOKEN_NUMBER - ${PHASE}_EX_TOKEN_NUMBER) | |
208 | """) | |
209 | ||
210 | gEmptyPcdDatabaseAutoGenC = TemplateString(""" | |
211 | ${PHASE}_PCD_DATABASE_INIT g${PHASE}PcdDbInit = { | |
212 | /* ExMapTable */ | |
213 | { | |
214 | {0, 0, 0} | |
215 | }, | |
216 | /* LocalTokenNumberTable */ | |
217 | { | |
218 | 0 | |
219 | }, | |
220 | /* GuidTable */ | |
221 | { | |
222 | {0x00000000, 0x0000, 0x0000, {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}} | |
223 | }, | |
224 | /* StringTable */ | |
225 | { 0 }, | |
226 | /* SizeTable */ | |
227 | { | |
228 | 0, 0 | |
229 | }, | |
230 | /* SkuIdTable */ | |
231 | { 0 }, | |
232 | ${SYSTEM_SKU_ID_VALUE} | |
233 | }; | |
234 | """) | |
235 | ||
236 | gPcdDatabaseAutoGenC = TemplateString(""" | |
237 | ${PHASE}_PCD_DATABASE_INIT g${PHASE}PcdDbInit = { | |
238 | ${BEGIN} { ${INIT_VALUE_UINT64} }, /* ${INIT_CNAME_DECL_UINT64}_${INIT_GUID_DECL_UINT64}[${INIT_NUMSKUS_DECL_UINT64}] */ | |
239 | ${END} | |
240 | ${BEGIN} ${VARDEF_VALUE_UINT64}, /* ${VARDEF_CNAME_UINT64}_${VARDEF_GUID_UINT64}_VariableDefault_${VARDEF_SKUID_UINT64} */ | |
241 | ${END} | |
242 | ${BEGIN} { ${INIT_VALUE_UINT32} }, /* ${INIT_CNAME_DECL_UINT32}_${INIT_GUID_DECL_UINT32}[${INIT_NUMSKUS_DECL_UINT32}] */ | |
243 | ${END} | |
244 | ${BEGIN} ${VARDEF_VALUE_UINT32}, /* ${VARDEF_CNAME_UINT32}_${VARDEF_GUID_UINT32}_VariableDefault_${VARDEF_SKUID_UINT32} */ | |
245 | ${END} | |
246 | /* VPD */ | |
247 | ${BEGIN} { ${VPD_HEAD_VALUE} }, /* ${VPD_HEAD_CNAME_DECL}_${VPD_HEAD_GUID_DECL}[${VPD_HEAD_NUMSKUS_DECL}] */ | |
248 | ${END} | |
249 | /* ExMapTable */ | |
250 | { | |
251 | ${BEGIN} { ${EXMAPPING_TABLE_EXTOKEN}, ${EXMAPPING_TABLE_LOCAL_TOKEN}, ${EXMAPPING_TABLE_GUID_INDEX} }, | |
252 | ${END} | |
253 | }, | |
254 | /* LocalTokenNumberTable */ | |
255 | { | |
256 | ${BEGIN} offsetof(${PHASE}_PCD_DATABASE, ${TOKEN_INIT}.${TOKEN_CNAME}_${TOKEN_GUID}) | ${TOKEN_TYPE}, | |
257 | ${END} | |
258 | }, | |
259 | /* GuidTable */ | |
260 | { | |
261 | ${BEGIN} ${GUID_STRUCTURE}, | |
262 | ${END} | |
263 | }, | |
264 | ${BEGIN} { ${STRING_HEAD_VALUE} }, /* ${STRING_HEAD_CNAME_DECL}_${STRING_HEAD_GUID_DECL}[${STRING_HEAD_NUMSKUS_DECL}] */ | |
265 | ${END} | |
266 | ${BEGIN} /* ${VARIABLE_HEAD_CNAME_DECL}_${VARIABLE_HEAD_GUID_DECL}[${VARIABLE_HEAD_NUMSKUS_DECL}] */ | |
267 | { | |
268 | ${VARIABLE_HEAD_VALUE} | |
269 | }, | |
270 | ${END} | |
271 | /* StringTable */ | |
272 | ${BEGIN} ${STRING_TABLE_VALUE}, /* ${STRING_TABLE_CNAME}_${STRING_TABLE_GUID} */ | |
273 | ${END} | |
274 | /* SizeTable */ | |
275 | { | |
276 | ${BEGIN} ${SIZE_TABLE_MAXIMUM_LENGTH}, ${SIZE_TABLE_CURRENT_LENGTH}, /* ${SIZE_TABLE_CNAME}_${SIZE_TABLE_GUID} */ | |
277 | ${END} | |
278 | }, | |
279 | ${BEGIN} { ${INIT_VALUE_UINT16} }, /* ${INIT_CNAME_DECL_UINT16}_${INIT_GUID_DECL_UINT16}[${INIT_NUMSKUS_DECL_UINT16}] */ | |
280 | ${END} | |
281 | ${BEGIN} ${VARDEF_VALUE_UINT16}, /* ${VARDEF_CNAME_UINT16}_${VARDEF_GUID_UINT16}_VariableDefault_${VARDEF_SKUID_UINT16} */ | |
282 | ${END} | |
283 | ${BEGIN} { ${INIT_VALUE_UINT8} }, /* ${INIT_CNAME_DECL_UINT8}_${INIT_GUID_DECL_UINT8}[${INIT_NUMSKUS_DECL_UINT8}] */ | |
284 | ${END} | |
285 | ${BEGIN} ${VARDEF_VALUE_UINT8}, /* ${VARDEF_CNAME_UINT8}_${VARDEF_GUID_UINT8}_VariableDefault_${VARDEF_SKUID_UINT8} */ | |
286 | ${END} | |
287 | ${BEGIN} { ${INIT_VALUE_BOOLEAN} }, /* ${INIT_CNAME_DECL_BOOLEAN}_${INIT_GUID_DECL_BOOLEAN}[${INIT_NUMSKUS_DECL_BOOLEAN}] */ | |
288 | ${END} | |
289 | ${BEGIN} ${VARDEF_VALUE_BOOLEAN}, /* ${VARDEF_CNAME_BOOLEAN}_${VARDEF_GUID_BOOLEAN}_VariableDefault_${VARDEF_SKUID_BOOLEAN} */ | |
290 | ${END} | |
291 | /* SkuIdTable */ | |
292 | { ${BEGIN}${SKUID_VALUE}, ${END} }, | |
293 | ${SYSTEM_SKU_ID_VALUE} | |
294 | }; | |
295 | """) | |
296 | ||
297 | ||
298 | ## AutoGen File Header Templates | |
299 | gAutoGenHeaderString = TemplateString("""\ | |
300 | /** | |
301 | DO NOT EDIT | |
302 | FILE auto-generated | |
303 | Module name: | |
304 | ${FileName} | |
305 | Abstract: Auto-generated ${FileName} for building module or library. | |
306 | **/ | |
307 | """) | |
308 | ||
309 | gAutoGenHPrologueString = TemplateString(""" | |
310 | #ifndef _${File}_${Guid} | |
311 | #define _${File}_${Guid} | |
312 | ||
313 | """) | |
314 | ||
315 | gAutoGenHEpilogueString = """ | |
316 | #endif | |
317 | """ | |
318 | ||
319 | ## PEI Core Entry Point Templates | |
320 | gPeiCoreEntryPointPrototype = TemplateString(""" | |
321 | ${BEGIN} | |
322 | VOID | |
323 | EFIAPI | |
324 | ${Function} ( | |
325 | IN CONST EFI_SEC_PEI_HAND_OFF *SecCoreData, | |
326 | IN CONST EFI_PEI_PPI_DESCRIPTOR *PpiList, | |
327 | IN VOID *Context | |
328 | ); | |
329 | ${END} | |
330 | """) | |
331 | ||
332 | gPeiCoreEntryPointString = TemplateString(""" | |
333 | ${BEGIN} | |
334 | VOID | |
335 | EFIAPI | |
336 | ProcessModuleEntryPointList ( | |
337 | IN CONST EFI_SEC_PEI_HAND_OFF *SecCoreData, | |
338 | IN CONST EFI_PEI_PPI_DESCRIPTOR *PpiList, | |
339 | IN VOID *Context | |
340 | ) | |
341 | ||
342 | { | |
343 | ${Function} (SecCoreData, PpiList, Context); | |
344 | } | |
345 | ${END} | |
346 | """) | |
347 | ||
348 | ||
349 | ## DXE Core Entry Point Templates | |
350 | gDxeCoreEntryPointPrototype = TemplateString(""" | |
351 | ${BEGIN} | |
352 | VOID | |
353 | EFIAPI | |
354 | ${Function} ( | |
355 | IN VOID *HobStart | |
356 | ); | |
357 | ${END} | |
358 | """) | |
359 | ||
360 | gDxeCoreEntryPointString = TemplateString(""" | |
361 | ${BEGIN} | |
362 | VOID | |
363 | EFIAPI | |
364 | ProcessModuleEntryPointList ( | |
365 | IN VOID *HobStart | |
366 | ) | |
367 | ||
368 | { | |
369 | ${Function} (HobStart); | |
370 | } | |
371 | ${END} | |
372 | """) | |
373 | ||
374 | ## PEIM Entry Point Templates | |
375 | gPeimEntryPointPrototype = TemplateString(""" | |
376 | ${BEGIN} | |
377 | EFI_STATUS | |
378 | EFIAPI | |
379 | ${Function} ( | |
380 | IN EFI_PEI_FILE_HANDLE FileHandle, | |
381 | IN CONST EFI_PEI_SERVICES **PeiServices | |
382 | ); | |
383 | ${END} | |
384 | """) | |
385 | ||
30fdf114 LG |
386 | gPeimEntryPointString = [ |
387 | TemplateString(""" | |
388 | GLOBAL_REMOVE_IF_UNREFERENCED const UINT32 _gPeimRevision = ${PiSpecVersion}; | |
389 | ||
390 | EFI_STATUS | |
391 | EFIAPI | |
392 | ProcessModuleEntryPointList ( | |
393 | IN EFI_PEI_FILE_HANDLE FileHandle, | |
394 | IN CONST EFI_PEI_SERVICES **PeiServices | |
395 | ) | |
396 | ||
397 | { | |
398 | return EFI_SUCCESS; | |
399 | } | |
400 | """), | |
401 | TemplateString(""" | |
402 | GLOBAL_REMOVE_IF_UNREFERENCED const UINT32 _gPeimRevision = ${PiSpecVersion}; | |
403 | ${BEGIN} | |
404 | EFI_STATUS | |
405 | EFIAPI | |
406 | ProcessModuleEntryPointList ( | |
407 | IN EFI_PEI_FILE_HANDLE FileHandle, | |
408 | IN CONST EFI_PEI_SERVICES **PeiServices | |
409 | ) | |
410 | ||
411 | { | |
412 | return ${Function} (FileHandle, PeiServices); | |
413 | } | |
414 | ${END} | |
415 | """), | |
416 | TemplateString(""" | |
417 | GLOBAL_REMOVE_IF_UNREFERENCED const UINT32 _gPeimRevision = ${PiSpecVersion}; | |
418 | ||
419 | EFI_STATUS | |
420 | EFIAPI | |
421 | ProcessModuleEntryPointList ( | |
422 | IN EFI_PEI_FILE_HANDLE FileHandle, | |
423 | IN CONST EFI_PEI_SERVICES **PeiServices | |
424 | ) | |
425 | ||
426 | { | |
427 | EFI_STATUS Status; | |
428 | EFI_STATUS CombinedStatus; | |
429 | ||
430 | CombinedStatus = EFI_LOAD_ERROR; | |
431 | ${BEGIN} | |
432 | Status = ${Function} (FileHandle, PeiServices); | |
433 | if (!EFI_ERROR (Status) || EFI_ERROR (CombinedStatus)) { | |
434 | CombinedStatus = Status; | |
435 | } | |
436 | ${END} | |
437 | return CombinedStatus; | |
438 | } | |
439 | """) | |
440 | ] | |
441 | ||
b303ea72 LG |
442 | ## SMM_CORE Entry Point Templates |
443 | gSmmCoreEntryPointPrototype = TemplateString(""" | |
444 | ${BEGIN} | |
445 | EFI_STATUS | |
446 | EFIAPI | |
447 | ${Function} ( | |
448 | IN EFI_HANDLE ImageHandle, | |
449 | IN EFI_SYSTEM_TABLE *SystemTable | |
450 | ); | |
451 | ${END} | |
452 | """) | |
453 | ||
454 | gSmmCoreEntryPointString = TemplateString(""" | |
455 | ${BEGIN} | |
456 | const UINT32 _gUefiDriverRevision = ${EfiSpecVersion}; | |
457 | const UINT32 _gDxeRevision = ${PiSpecVersion}; | |
458 | ||
459 | EFI_STATUS | |
460 | EFIAPI | |
461 | ProcessModuleEntryPointList ( | |
462 | IN EFI_HANDLE ImageHandle, | |
463 | IN EFI_SYSTEM_TABLE *SystemTable | |
464 | ) | |
465 | { | |
466 | return ${Function} (ImageHandle, SystemTable); | |
467 | } | |
468 | ${END} | |
469 | """) | |
470 | ||
30fdf114 LG |
471 | ## DXE SMM Entry Point Templates |
472 | gDxeSmmEntryPointPrototype = TemplateString(""" | |
473 | ${BEGIN} | |
474 | EFI_STATUS | |
475 | EFIAPI | |
476 | ${Function} ( | |
477 | IN EFI_HANDLE ImageHandle, | |
478 | IN EFI_SYSTEM_TABLE *SystemTable | |
479 | ); | |
480 | ${END} | |
481 | """) | |
482 | ||
483 | gDxeSmmEntryPointString = [ | |
484 | TemplateString(""" | |
485 | const UINT32 _gUefiDriverRevision = ${EfiSpecVersion}; | |
486 | const UINT32 _gDxeRevision = ${PiSpecVersion}; | |
487 | ||
488 | EFI_STATUS | |
489 | EFIAPI | |
490 | ProcessModuleEntryPointList ( | |
491 | IN EFI_HANDLE ImageHandle, | |
492 | IN EFI_SYSTEM_TABLE *SystemTable | |
493 | ) | |
494 | ||
495 | { | |
496 | return EFI_SUCCESS; | |
497 | } | |
498 | """), | |
499 | TemplateString(""" | |
500 | const UINT32 _gUefiDriverRevision = ${EfiSpecVersion}; | |
501 | const UINT32 _gDxeRevision = ${PiSpecVersion}; | |
502 | ||
503 | static BASE_LIBRARY_JUMP_BUFFER mJumpContext; | |
504 | static EFI_STATUS mDriverEntryPointStatus = EFI_LOAD_ERROR; | |
505 | ||
506 | VOID | |
507 | EFIAPI | |
508 | ExitDriver ( | |
509 | IN EFI_STATUS Status | |
510 | ) | |
511 | { | |
512 | if (!EFI_ERROR (Status) || EFI_ERROR (mDriverEntryPointStatus)) { | |
513 | mDriverEntryPointStatus = Status; | |
514 | } | |
515 | LongJump (&mJumpContext, (UINTN)-1); | |
516 | ASSERT (FALSE); | |
517 | } | |
518 | ||
519 | EFI_STATUS | |
520 | EFIAPI | |
521 | ProcessModuleEntryPointList ( | |
522 | IN EFI_HANDLE ImageHandle, | |
523 | IN EFI_SYSTEM_TABLE *SystemTable | |
524 | ) | |
525 | ||
526 | { | |
527 | ${BEGIN} | |
528 | if (SetJump (&mJumpContext) == 0) { | |
529 | ExitDriver (${Function} (ImageHandle, SystemTable)); | |
530 | ASSERT (FALSE); | |
531 | } | |
532 | ${END} | |
533 | ||
534 | return mDriverEntryPointStatus; | |
535 | } | |
536 | """) | |
537 | ] | |
538 | ||
539 | ## UEFI Driver Entry Point Templates | |
540 | gUefiDriverEntryPointPrototype = TemplateString(""" | |
541 | ${BEGIN} | |
542 | EFI_STATUS | |
543 | EFIAPI | |
544 | ${Function} ( | |
545 | IN EFI_HANDLE ImageHandle, | |
546 | IN EFI_SYSTEM_TABLE *SystemTable | |
547 | ); | |
548 | ${END} | |
549 | """) | |
550 | ||
551 | gUefiDriverEntryPointString = [ | |
552 | TemplateString(""" | |
553 | const UINT32 _gUefiDriverRevision = ${EfiSpecVersion}; | |
554 | const UINT32 _gDxeRevision = ${PiSpecVersion}; | |
555 | ||
556 | EFI_STATUS | |
557 | EFIAPI | |
558 | ProcessModuleEntryPointList ( | |
559 | IN EFI_HANDLE ImageHandle, | |
560 | IN EFI_SYSTEM_TABLE *SystemTable | |
561 | ) | |
562 | { | |
563 | return EFI_SUCCESS; | |
564 | } | |
565 | """), | |
566 | TemplateString(""" | |
567 | const UINT32 _gUefiDriverRevision = ${EfiSpecVersion}; | |
568 | const UINT32 _gDxeRevision = ${PiSpecVersion}; | |
569 | ||
570 | ${BEGIN} | |
571 | EFI_STATUS | |
572 | EFIAPI | |
573 | ProcessModuleEntryPointList ( | |
574 | IN EFI_HANDLE ImageHandle, | |
575 | IN EFI_SYSTEM_TABLE *SystemTable | |
576 | ) | |
577 | ||
578 | { | |
579 | return ${Function} (ImageHandle, SystemTable); | |
580 | } | |
581 | ${END} | |
582 | VOID | |
583 | EFIAPI | |
584 | ExitDriver ( | |
585 | IN EFI_STATUS Status | |
586 | ) | |
587 | { | |
588 | if (EFI_ERROR (Status)) { | |
589 | ProcessLibraryDestructorList (gImageHandle, gST); | |
590 | } | |
591 | gBS->Exit (gImageHandle, Status, 0, NULL); | |
592 | } | |
593 | """), | |
594 | TemplateString(""" | |
595 | const UINT32 _gUefiDriverRevision = ${EfiSpecVersion}; | |
596 | const UINT32 _gDxeRevision = ${PiSpecVersion}; | |
597 | ||
598 | EFI_STATUS | |
599 | EFIAPI | |
600 | ProcessModuleEntryPointList ( | |
601 | IN EFI_HANDLE ImageHandle, | |
602 | IN EFI_SYSTEM_TABLE *SystemTable | |
603 | ) | |
604 | ||
605 | { | |
606 | ${BEGIN} | |
607 | if (SetJump (&mJumpContext) == 0) { | |
608 | ExitDriver (${Function} (ImageHandle, SystemTable)); | |
609 | ASSERT (FALSE); | |
610 | } | |
611 | ${END} | |
612 | return mDriverEntryPointStatus; | |
613 | } | |
614 | ||
615 | static BASE_LIBRARY_JUMP_BUFFER mJumpContext; | |
616 | static EFI_STATUS mDriverEntryPointStatus = EFI_LOAD_ERROR; | |
617 | ||
618 | VOID | |
619 | EFIAPI | |
620 | ExitDriver ( | |
621 | IN EFI_STATUS Status | |
622 | ) | |
623 | { | |
624 | if (!EFI_ERROR (Status) || EFI_ERROR (mDriverEntryPointStatus)) { | |
625 | mDriverEntryPointStatus = Status; | |
626 | } | |
627 | LongJump (&mJumpContext, (UINTN)-1); | |
628 | ASSERT (FALSE); | |
629 | } | |
630 | """) | |
631 | ] | |
632 | ||
633 | ||
634 | ## UEFI Application Entry Point Templates | |
635 | gUefiApplicationEntryPointPrototype = TemplateString(""" | |
636 | ${BEGIN} | |
637 | EFI_STATUS | |
638 | EFIAPI | |
639 | ${Function} ( | |
640 | IN EFI_HANDLE ImageHandle, | |
641 | IN EFI_SYSTEM_TABLE *SystemTable | |
642 | ); | |
643 | ${END} | |
644 | """) | |
645 | ||
646 | gUefiApplicationEntryPointString = [ | |
647 | TemplateString(""" | |
648 | const UINT32 _gUefiDriverRevision = ${EfiSpecVersion}; | |
649 | ||
650 | EFI_STATUS | |
651 | EFIAPI | |
652 | ProcessModuleEntryPointList ( | |
653 | IN EFI_HANDLE ImageHandle, | |
654 | IN EFI_SYSTEM_TABLE *SystemTable | |
655 | ) | |
656 | { | |
657 | return EFI_SUCCESS; | |
658 | } | |
659 | """), | |
660 | TemplateString(""" | |
661 | const UINT32 _gUefiDriverRevision = ${EfiSpecVersion}; | |
662 | ||
663 | ${BEGIN} | |
664 | EFI_STATUS | |
665 | EFIAPI | |
666 | ProcessModuleEntryPointList ( | |
667 | IN EFI_HANDLE ImageHandle, | |
668 | IN EFI_SYSTEM_TABLE *SystemTable | |
669 | ) | |
670 | ||
671 | { | |
672 | return ${Function} (ImageHandle, SystemTable); | |
673 | } | |
674 | ${END} | |
675 | VOID | |
676 | EFIAPI | |
677 | ExitDriver ( | |
678 | IN EFI_STATUS Status | |
679 | ) | |
680 | { | |
681 | if (EFI_ERROR (Status)) { | |
682 | ProcessLibraryDestructorList (gImageHandle, gST); | |
683 | } | |
684 | gBS->Exit (gImageHandle, Status, 0, NULL); | |
685 | } | |
686 | """), | |
687 | TemplateString(""" | |
688 | const UINT32 _gUefiDriverRevision = ${EfiSpecVersion}; | |
689 | ||
690 | EFI_STATUS | |
691 | EFIAPI | |
692 | ProcessModuleEntryPointList ( | |
693 | IN EFI_HANDLE ImageHandle, | |
694 | IN EFI_SYSTEM_TABLE *SystemTable | |
695 | ) | |
696 | ||
697 | { | |
698 | ${BEGIN} | |
699 | if (SetJump (&mJumpContext) == 0) { | |
700 | ExitDriver (${Function} (ImageHandle, SystemTable)); | |
701 | ASSERT (FALSE); | |
702 | } | |
703 | ${END} | |
704 | return mDriverEntryPointStatus; | |
705 | } | |
706 | ||
707 | static BASE_LIBRARY_JUMP_BUFFER mJumpContext; | |
708 | static EFI_STATUS mDriverEntryPointStatus = EFI_LOAD_ERROR; | |
709 | ||
710 | VOID | |
711 | EFIAPI | |
712 | ExitDriver ( | |
713 | IN EFI_STATUS Status | |
714 | ) | |
715 | { | |
716 | if (!EFI_ERROR (Status) || EFI_ERROR (mDriverEntryPointStatus)) { | |
717 | mDriverEntryPointStatus = Status; | |
718 | } | |
719 | LongJump (&mJumpContext, (UINTN)-1); | |
720 | ASSERT (FALSE); | |
721 | } | |
722 | """) | |
723 | ] | |
724 | ||
725 | ## UEFI Unload Image Templates | |
726 | gUefiUnloadImagePrototype = TemplateString(""" | |
727 | ${BEGIN} | |
728 | EFI_STATUS | |
729 | EFIAPI | |
730 | ${Function} ( | |
731 | IN EFI_HANDLE ImageHandle | |
732 | ); | |
733 | ${END} | |
734 | """) | |
735 | ||
736 | gUefiUnloadImageString = [ | |
737 | TemplateString(""" | |
738 | GLOBAL_REMOVE_IF_UNREFERENCED const UINT8 _gDriverUnloadImageCount = ${Count}; | |
739 | ||
740 | EFI_STATUS | |
741 | EFIAPI | |
742 | ProcessModuleUnloadList ( | |
743 | IN EFI_HANDLE ImageHandle | |
744 | ) | |
745 | { | |
746 | return EFI_SUCCESS; | |
747 | } | |
748 | """), | |
749 | TemplateString(""" | |
750 | GLOBAL_REMOVE_IF_UNREFERENCED const UINT8 _gDriverUnloadImageCount = ${Count}; | |
751 | ||
752 | ${BEGIN} | |
753 | EFI_STATUS | |
754 | EFIAPI | |
755 | ProcessModuleUnloadList ( | |
756 | IN EFI_HANDLE ImageHandle | |
757 | ) | |
758 | { | |
759 | return ${Function} (ImageHandle); | |
760 | } | |
761 | ${END} | |
762 | """), | |
763 | TemplateString(""" | |
764 | GLOBAL_REMOVE_IF_UNREFERENCED const UINT8 _gDriverUnloadImageCount = ${Count}; | |
765 | ||
766 | EFI_STATUS | |
767 | EFIAPI | |
768 | ProcessModuleUnloadList ( | |
769 | IN EFI_HANDLE ImageHandle | |
770 | ) | |
771 | { | |
772 | EFI_STATUS Status; | |
773 | ||
774 | Status = EFI_SUCCESS; | |
775 | ${BEGIN} | |
776 | if (EFI_ERROR (Status)) { | |
777 | ${Function} (ImageHandle); | |
778 | } else { | |
779 | Status = ${Function} (ImageHandle); | |
780 | } | |
781 | ${END} | |
782 | return Status; | |
783 | } | |
784 | """) | |
785 | ] | |
786 | ||
787 | gLibraryStructorPrototype = { | |
788 | 'BASE' : TemplateString("""${BEGIN} | |
789 | RETURN_STATUS | |
790 | EFIAPI | |
791 | ${Function} ( | |
792 | VOID | |
793 | );${END} | |
794 | """), | |
795 | ||
796 | 'PEI' : TemplateString("""${BEGIN} | |
797 | EFI_STATUS | |
798 | EFIAPI | |
799 | ${Function} ( | |
800 | IN EFI_PEI_FILE_HANDLE FileHandle, | |
801 | IN CONST EFI_PEI_SERVICES **PeiServices | |
802 | );${END} | |
803 | """), | |
804 | ||
805 | 'DXE' : TemplateString("""${BEGIN} | |
806 | EFI_STATUS | |
807 | EFIAPI | |
808 | ${Function} ( | |
809 | IN EFI_HANDLE ImageHandle, | |
810 | IN EFI_SYSTEM_TABLE *SystemTable | |
811 | );${END} | |
812 | """), | |
813 | } | |
814 | ||
815 | gLibraryStructorCall = { | |
816 | 'BASE' : TemplateString("""${BEGIN} | |
817 | Status = ${Function} (); | |
818 | ASSERT_EFI_ERROR (Status);${END} | |
819 | """), | |
820 | ||
821 | 'PEI' : TemplateString("""${BEGIN} | |
822 | Status = ${Function} (FileHandle, PeiServices); | |
823 | ASSERT_EFI_ERROR (Status);${END} | |
824 | """), | |
825 | ||
826 | 'DXE' : TemplateString("""${BEGIN} | |
827 | Status = ${Function} (ImageHandle, SystemTable); | |
828 | ASSERT_EFI_ERROR (Status);${END} | |
829 | """), | |
830 | } | |
831 | ||
832 | ## Library Constructor and Destructor Templates | |
833 | gLibraryString = { | |
834 | 'BASE' : TemplateString(""" | |
835 | ${BEGIN}${FunctionPrototype}${END} | |
836 | ||
837 | VOID | |
838 | EFIAPI | |
839 | ProcessLibrary${Type}List ( | |
840 | VOID | |
841 | ) | |
842 | { | |
843 | ${BEGIN} EFI_STATUS Status; | |
844 | ${FunctionCall}${END} | |
845 | } | |
846 | """), | |
847 | ||
848 | 'PEI' : TemplateString(""" | |
849 | ${BEGIN}${FunctionPrototype}${END} | |
850 | ||
851 | VOID | |
852 | EFIAPI | |
853 | ProcessLibrary${Type}List ( | |
854 | IN EFI_PEI_FILE_HANDLE FileHandle, | |
855 | IN CONST EFI_PEI_SERVICES **PeiServices | |
856 | ) | |
857 | { | |
858 | ${BEGIN} EFI_STATUS Status; | |
859 | ${FunctionCall}${END} | |
860 | } | |
861 | """), | |
862 | ||
863 | 'DXE' : TemplateString(""" | |
864 | ${BEGIN}${FunctionPrototype}${END} | |
865 | ||
866 | VOID | |
867 | EFIAPI | |
868 | ProcessLibrary${Type}List ( | |
869 | IN EFI_HANDLE ImageHandle, | |
870 | IN EFI_SYSTEM_TABLE *SystemTable | |
871 | ) | |
872 | { | |
873 | ${BEGIN} EFI_STATUS Status; | |
874 | ${FunctionCall}${END} | |
875 | } | |
876 | """), | |
877 | } | |
878 | ||
879 | gSpecificationString = TemplateString(""" | |
880 | ${BEGIN} | |
881 | #undef ${SpecificationName} | |
882 | #define ${SpecificationName} ${SpecificationValue} | |
883 | ${END} | |
884 | """) | |
885 | ||
886 | gBasicHeaderFile = "Base.h" | |
887 | ||
888 | gModuleTypeHeaderFile = { | |
889 | "BASE" : [gBasicHeaderFile], | |
890 | "SEC" : ["PiPei.h", "Library/DebugLib.h"], | |
891 | "PEI_CORE" : ["PiPei.h", "Library/DebugLib.h", "Library/PeiCoreEntryPoint.h"], | |
892 | "PEIM" : ["PiPei.h", "Library/DebugLib.h", "Library/PeimEntryPoint.h"], | |
893 | "DXE_CORE" : ["PiDxe.h", "Library/DebugLib.h", "Library/DxeCoreEntryPoint.h"], | |
894 | "DXE_DRIVER" : ["PiDxe.h", "Library/BaseLib.h", "Library/DebugLib.h", "Library/UefiBootServicesTableLib.h", "Library/UefiDriverEntryPoint.h"], | |
895 | "DXE_SMM_DRIVER" : ["PiDxe.h", "Library/BaseLib.h", "Library/DebugLib.h", "Library/UefiBootServicesTableLib.h", "Library/UefiDriverEntryPoint.h"], | |
896 | "DXE_RUNTIME_DRIVER": ["PiDxe.h", "Library/BaseLib.h", "Library/DebugLib.h", "Library/UefiBootServicesTableLib.h", "Library/UefiDriverEntryPoint.h"], | |
897 | "DXE_SAL_DRIVER" : ["PiDxe.h", "Library/BaseLib.h", "Library/DebugLib.h", "Library/UefiBootServicesTableLib.h", "Library/UefiDriverEntryPoint.h"], | |
898 | "UEFI_DRIVER" : ["Uefi.h", "Library/BaseLib.h", "Library/DebugLib.h", "Library/UefiBootServicesTableLib.h", "Library/UefiDriverEntryPoint.h"], | |
899 | "UEFI_APPLICATION" : ["Uefi.h", "Library/BaseLib.h", "Library/DebugLib.h", "Library/UefiBootServicesTableLib.h", "Library/UefiApplicationEntryPoint.h"], | |
b303ea72 | 900 | "SMM_CORE" : ["PiDxe.h", "Library/BaseLib.h", "Library/DebugLib.h", "Library/UefiDriverEntryPoint.h"], |
30fdf114 LG |
901 | "USER_DEFINED" : [gBasicHeaderFile] |
902 | } | |
903 | ||
904 | ## Create code for module PCDs | |
905 | # | |
906 | # @param Info The ModuleAutoGen object | |
907 | # @param AutoGenC The TemplateString object for C code | |
908 | # @param AutoGenH The TemplateString object for header file | |
909 | # @param Pcd The PCD object | |
910 | # | |
911 | def CreateModulePcdCode(Info, AutoGenC, AutoGenH, Pcd): | |
912 | TokenSpaceGuidValue = Pcd.TokenSpaceGuidValue #Info.GuidList[Pcd.TokenSpaceGuidCName] | |
913 | PcdTokenNumber = Info.PlatformInfo.PcdTokenNumber | |
914 | # | |
915 | # Write PCDs | |
916 | # | |
917 | PcdTokenName = '_PCD_TOKEN_' + Pcd.TokenCName | |
918 | if Pcd.Type in gDynamicExPcd: | |
919 | TokenNumber = int(Pcd.TokenValue, 0) | |
920 | else: | |
921 | if (Pcd.TokenCName, Pcd.TokenSpaceGuidCName) not in PcdTokenNumber: | |
922 | EdkLogger.error("build", AUTOGEN_ERROR, | |
923 | "No generated token number for %s.%s\n" % (Pcd.TokenSpaceGuidCName, Pcd.TokenCName), | |
924 | ExtraData="[%s]" % str(Info)) | |
925 | TokenNumber = PcdTokenNumber[Pcd.TokenCName, Pcd.TokenSpaceGuidCName] | |
926 | AutoGenH.Append('\n#define %s %d\n' % (PcdTokenName, TokenNumber)) | |
927 | ||
928 | EdkLogger.debug(EdkLogger.DEBUG_3, "Creating code for " + Pcd.TokenCName + "." + Pcd.TokenSpaceGuidCName) | |
929 | if Pcd.Type not in gItemTypeStringDatabase: | |
930 | EdkLogger.error("build", AUTOGEN_ERROR, | |
931 | "Unknown PCD type [%s] of PCD %s.%s" % (Pcd.Type, Pcd.TokenSpaceGuidCName, Pcd.TokenCName), | |
932 | ExtraData="[%s]" % str(Info)) | |
933 | if Pcd.DatumType not in gDatumSizeStringDatabase: | |
934 | EdkLogger.error("build", AUTOGEN_ERROR, | |
935 | "Unknown datum type [%s] of PCD %s.%s" % (Pcd.DatumType, Pcd.TokenSpaceGuidCName, Pcd.TokenCName), | |
936 | ExtraData="[%s]" % str(Info)) | |
937 | ||
938 | DatumSize = gDatumSizeStringDatabase[Pcd.DatumType] | |
939 | DatumSizeLib = gDatumSizeStringDatabaseLib[Pcd.DatumType] | |
940 | GetModeName = '_PCD_GET_MODE_' + gDatumSizeStringDatabaseH[Pcd.DatumType] + '_' + Pcd.TokenCName | |
941 | SetModeName = '_PCD_SET_MODE_' + gDatumSizeStringDatabaseH[Pcd.DatumType] + '_' + Pcd.TokenCName | |
942 | ||
943 | if Pcd.Type in gDynamicExPcd: | |
944 | AutoGenH.Append('#define %s LibPcdGetEx%s(&%s, %s)\n' % (GetModeName, DatumSizeLib, Pcd.TokenSpaceGuidCName, PcdTokenName)) | |
945 | if Pcd.DatumType == 'VOID*': | |
946 | AutoGenH.Append('#define %s(SizeOfBuffer, Buffer) LibPcdSetEx%s(&%s, %s, (SizeOfBuffer), (Buffer))\n' % (SetModeName, DatumSizeLib, Pcd.TokenSpaceGuidCName, PcdTokenName)) | |
947 | else: | |
948 | AutoGenH.Append('#define %s(Value) LibPcdSetEx%s(&%s, %s, (Value))\n' % (SetModeName, DatumSizeLib, Pcd.TokenSpaceGuidCName, PcdTokenName)) | |
949 | elif Pcd.Type in gDynamicPcd: | |
950 | AutoGenH.Append('#define %s LibPcdGet%s(%s)\n' % (GetModeName, DatumSizeLib, PcdTokenName)) | |
951 | if Pcd.DatumType == 'VOID*': | |
952 | AutoGenH.Append('#define %s(SizeOfBuffer, Buffer) LibPcdSet%s(%s, (SizeOfBuffer), (Buffer))\n' %(SetModeName, DatumSizeLib, PcdTokenName)) | |
953 | else: | |
954 | AutoGenH.Append('#define %s(Value) LibPcdSet%s(%s, (Value))\n' % (SetModeName, DatumSizeLib, PcdTokenName)) | |
955 | else: | |
956 | PcdVariableName = '_gPcd_' + gItemTypeStringDatabase[Pcd.Type] + '_' + Pcd.TokenCName | |
957 | Const = 'const' | |
958 | if Pcd.Type == TAB_PCDS_PATCHABLE_IN_MODULE: | |
959 | Const = '' | |
960 | Type = '' | |
961 | Array = '' | |
962 | Value = Pcd.DefaultValue\r | |
963 | Unicode = False | |
964 | if Pcd.DatumType == 'UINT64': | |
965 | if not Value.endswith('ULL'): | |
966 | Value += 'ULL' | |
967 | if Pcd.DatumType == 'VOID*': | |
968 | if Pcd.MaxDatumSize == None or Pcd.MaxDatumSize == '': | |
969 | EdkLogger.error("build", AUTOGEN_ERROR, | |
970 | "Unknown [MaxDatumSize] of PCD [%s.%s]" % (Pcd.TokenSpaceGuidCName, Pcd.TokenCName), | |
971 | ExtraData="[%s]" % str(Info)) | |
972 | ||
973 | ArraySize = int(Pcd.MaxDatumSize, 0) | |
974 | if Value[0] == '{': | |
975 | Type = '(VOID *)' | |
976 | else:\r | |
977 | if Value[0] == 'L': | |
978 | Unicode = True | |
979 | Value = Value.lstrip('L') #.strip('"') | |
980 | Value = eval(Value) # translate escape character | |
981 | NewValue = '{' | |
982 | for Index in range(0,len(Value)): | |
983 | if Unicode: | |
984 | NewValue = NewValue + str(ord(Value[Index]) % 0x10000) + ', '\r | |
985 | else:\r | |
986 | NewValue = NewValue + str(ord(Value[Index]) % 0x100) + ', ' | |
987 | if Unicode:\r | |
988 | ArraySize = ArraySize / 2;\r | |
989 | \r | |
990 | if ArraySize < (len(Value) + 1): | |
991 | ArraySize = len(Value) + 1 | |
992 | Value = NewValue + '0 }'\r | |
993 | Array = '[%d]' % ArraySize | |
994 | # | |
995 | # skip casting for fixed at build since it breaks ARM assembly. | |
996 | # Long term we need PCD macros that work in assembly | |
997 | # | |
998 | elif Pcd.Type != TAB_PCDS_FIXED_AT_BUILD: | |
999 | Value = "((%s)%s)" % (Pcd.DatumType, Value) | |
1000 | ||
1001 | if Pcd.Type == TAB_PCDS_PATCHABLE_IN_MODULE: | |
1002 | PcdValueName = '_PCD_PATCHABLE_VALUE_' + Pcd.TokenCName | |
1003 | else: | |
1004 | PcdValueName = '_PCD_VALUE_' + Pcd.TokenCName | |
1005 | ||
1006 | if Pcd.DatumType == 'VOID*':\r | |
1007 | #\r | |
1008 | # For unicode, UINT16 array will be generated, so the alignment of unicode is guaranteed.\r | |
1009 | #\r | |
1010 | if Unicode:\r | |
1011 | AutoGenH.Append('#define _PCD_PATCHABLE_%s_SIZE %s\n' % (Pcd.TokenCName, Pcd.MaxDatumSize))\r | |
1012 | AutoGenH.Append('#define %s %s%s\n' %(PcdValueName, Type, PcdVariableName))\r | |
1013 | AutoGenC.Append('GLOBAL_REMOVE_IF_UNREFERENCED %s UINT16 %s%s = %s;\n' % (Const, PcdVariableName, Array, Value))\r | |
1014 | AutoGenH.Append('extern %s UINT16 %s%s;\n' %(Const, PcdVariableName, Array))\r | |
1015 | AutoGenH.Append('#define %s %s%s\n' %(GetModeName, Type, PcdVariableName))\r | |
1016 | else: | |
1017 | AutoGenH.Append('#define _PCD_PATCHABLE_%s_SIZE %s\n' % (Pcd.TokenCName, Pcd.MaxDatumSize)) | |
1018 | AutoGenH.Append('#define %s %s%s\n' %(PcdValueName, Type, PcdVariableName)) | |
1019 | AutoGenC.Append('GLOBAL_REMOVE_IF_UNREFERENCED %s UINT8 %s%s = %s;\n' % (Const, PcdVariableName, Array, Value)) | |
1020 | AutoGenH.Append('extern %s UINT8 %s%s;\n' %(Const, PcdVariableName, Array)) | |
1021 | AutoGenH.Append('#define %s %s%s\n' %(GetModeName, Type, PcdVariableName)) | |
1022 | elif Pcd.Type == TAB_PCDS_PATCHABLE_IN_MODULE: | |
1023 | AutoGenH.Append('#define %s %s\n' %(PcdValueName, Value)) | |
1024 | AutoGenC.Append('GLOBAL_REMOVE_IF_UNREFERENCED volatile %s %s %s = %s;\n' %(Const, Pcd.DatumType, PcdVariableName, PcdValueName)) | |
1025 | AutoGenH.Append('extern volatile %s %s %s%s;\n' % (Const, Pcd.DatumType, PcdVariableName, Array)) | |
1026 | AutoGenH.Append('#define %s %s%s\n' % (GetModeName, Type, PcdVariableName)) | |
1027 | else: | |
1028 | AutoGenH.Append('#define %s %s\n' %(PcdValueName, Value)) | |
1029 | AutoGenC.Append('GLOBAL_REMOVE_IF_UNREFERENCED %s %s %s = %s;\n' %(Const, Pcd.DatumType, PcdVariableName, PcdValueName)) | |
1030 | AutoGenH.Append('extern %s %s %s%s;\n' % (Const, Pcd.DatumType, PcdVariableName, Array)) | |
1031 | AutoGenH.Append('#define %s %s%s\n' % (GetModeName, Type, PcdVariableName)) | |
1032 | ||
1033 | if Pcd.Type == TAB_PCDS_PATCHABLE_IN_MODULE: | |
1034 | if Pcd.DatumType == 'VOID*': | |
1035 | AutoGenH.Append('#define %s(SizeOfBuffer, Buffer) LibPatchPcdSetPtr(_gPcd_BinaryPatch_%s, (UINTN)_PCD_PATCHABLE_%s_SIZE, (SizeOfBuffer), (Buffer))\n' % (SetModeName, Pcd.TokenCName, Pcd.TokenCName)) | |
1036 | else: | |
1037 | AutoGenH.Append('#define %s(Value) (%s = (Value))\n' % (SetModeName, PcdVariableName)) | |
1038 | else: | |
1039 | AutoGenH.Append('//#define %s ASSERT(FALSE) // It is not allowed to set value for a FIXED_AT_BUILD PCD\n' % SetModeName) | |
1040 | ||
1041 | ## Create code for library module PCDs | |
1042 | # | |
1043 | # @param Info The ModuleAutoGen object | |
1044 | # @param AutoGenC The TemplateString object for C code | |
1045 | # @param AutoGenH The TemplateString object for header file | |
1046 | # @param Pcd The PCD object | |
1047 | # | |
1048 | def CreateLibraryPcdCode(Info, AutoGenC, AutoGenH, Pcd): | |
1049 | PcdTokenNumber = Info.PlatformInfo.PcdTokenNumber | |
1050 | TokenSpaceGuidCName = Pcd.TokenSpaceGuidCName | |
1051 | TokenCName = Pcd.TokenCName | |
1052 | TokenSpaceGuidValue = Pcd.TokenSpaceGuidValue #Info.GuidList[TokenSpaceGuidCName] | |
1053 | if (Pcd.TokenCName, Pcd.TokenSpaceGuidCName) not in PcdTokenNumber: | |
1054 | EdkLogger.error("build", AUTOGEN_ERROR, | |
1055 | "No generated token number for %s.%s\n" % (Pcd.TokenSpaceGuidCName, Pcd.TokenCName), | |
1056 | ExtraData="[%s]" % str(Info)) | |
1057 | TokenNumber = PcdTokenNumber[TokenCName, TokenSpaceGuidCName] | |
1058 | ||
1059 | if Pcd.Type not in gItemTypeStringDatabase: | |
1060 | EdkLogger.error("build", AUTOGEN_ERROR, | |
1061 | "Unknown PCD type [%s] of PCD %s.%s" % (Pcd.Type, Pcd.TokenSpaceGuidCName, Pcd.TokenCName), | |
1062 | ExtraData="[%s]" % str(Info)) | |
1063 | if Pcd.DatumType not in gDatumSizeStringDatabase: | |
1064 | EdkLogger.error("build", AUTOGEN_ERROR, | |
1065 | "Unknown datum type [%s] of PCD %s.%s" % (Pcd.DatumType, Pcd.TokenSpaceGuidCName, Pcd.TokenCName), | |
1066 | ExtraData="[%s]" % str(Info)) | |
1067 | ||
1068 | DatumType = Pcd.DatumType | |
1069 | DatumSize = gDatumSizeStringDatabaseH[DatumType] | |
1070 | DatumSizeLib= gDatumSizeStringDatabaseLib[DatumType] | |
1071 | GetModeName = '_PCD_GET_MODE_' + DatumSize + '_' + TokenCName | |
1072 | SetModeName = '_PCD_SET_MODE_' + DatumSize + '_' + TokenCName | |
1073 | ||
1074 | Type = '' | |
1075 | Array = '' | |
1076 | if Pcd.DatumType == 'VOID*': | |
1077 | Type = '(VOID *)' | |
1078 | Array = '[]' | |
1079 | ||
1080 | AutoGenH.Append('#define _PCD_TOKEN_%s %d\n' % (TokenCName, TokenNumber)) | |
1081 | ||
1082 | PcdItemType = Pcd.Type | |
1083 | #if PcdItemType in gDynamicPcd: | |
1084 | # PcdItemType = TAB_PCDS_FIXED_AT_BUILD | |
1085 | # if (TokenCName, TokenSpaceGuidCName) in Info.PlatformInfo.Platform.Pcds: | |
1086 | # PcdItemType = Info.PlatformInfo.Platform.Pcds[TokenCName, TokenSpaceGuidCName].Type | |
1087 | if PcdItemType in gDynamicExPcd: | |
1088 | PcdTokenName = '_PCD_TOKEN_' + TokenCName | |
1089 | AutoGenH.Append('#define %s LibPcdGetEx%s(&%s, %s)\n' % (GetModeName, DatumSizeLib, TokenSpaceGuidCName, PcdTokenName)) | |
1090 | if DatumType == 'VOID*': | |
1091 | AutoGenH.Append('#define %s(SizeOfBuffer, Buffer) LibPcdSetEx%s(&%s, %s, (SizeOfBuffer), (Buffer))\n' % (SetModeName,DatumSizeLib, TokenSpaceGuidCName, PcdTokenName)) | |
1092 | else: | |
1093 | AutoGenH.Append('#define %s(Value) LibPcdSetEx%s(&%s, %s, (Value))\n' % (SetModeName, DatumSizeLib, TokenSpaceGuidCName, PcdTokenName)) | |
1094 | if PcdItemType in gDynamicPcd: | |
1095 | PcdTokenName = '_PCD_TOKEN_' + TokenCName | |
1096 | AutoGenH.Append('#define %s LibPcdGet%s(%s)\n' % (GetModeName, DatumSizeLib, PcdTokenName)) | |
1097 | if DatumType == 'VOID*': | |
1098 | AutoGenH.Append('#define %s(SizeOfBuffer, Buffer) LibPcdSet%s(%s, (SizeOfBuffer), (Buffer))\n' %(SetModeName, DatumSizeLib, PcdTokenName)) | |
1099 | else: | |
1100 | AutoGenH.Append('#define %s(Value) LibPcdSet%s(%s, (Value))\n' % (SetModeName, DatumSizeLib, PcdTokenName)) | |
1101 | if PcdItemType == TAB_PCDS_PATCHABLE_IN_MODULE: | |
1102 | PcdVariableName = '_gPcd_' + gItemTypeStringDatabase[TAB_PCDS_PATCHABLE_IN_MODULE] + '_' + TokenCName | |
1103 | AutoGenH.Append('extern %s _gPcd_BinaryPatch_%s%s;\n' %(DatumType, TokenCName, Array) ) | |
1104 | AutoGenH.Append('#define %s %s_gPcd_BinaryPatch_%s\n' %(GetModeName, Type, TokenCName)) | |
1105 | AutoGenH.Append('#define %s(Value) (%s = (Value))\n' % (SetModeName, PcdVariableName)) | |
1106 | if PcdItemType == TAB_PCDS_FIXED_AT_BUILD or PcdItemType == TAB_PCDS_FEATURE_FLAG: | |
1107 | AutoGenH.Append('extern const %s _gPcd_FixedAtBuild_%s%s;\n' %(DatumType, TokenCName, Array)) | |
1108 | #AutoGenH.Append('#define _PCD_VALUE_%s _gPcd_FixedAtBuild_%s\n' %(TokenCName, TokenCName)) | |
1109 | AutoGenH.Append('#define %s %s_gPcd_FixedAtBuild_%s\n' %(GetModeName, Type, TokenCName)) | |
1110 | AutoGenH.Append('//#define %s ASSERT(FALSE) // It is not allowed to set value for a FIXED_AT_BUILD PCD\n' % SetModeName) | |
1111 | ||
1112 | ## Create code for PCD database in DXE or PEI phase | |
1113 | # | |
1114 | # @param Platform The platform object | |
1115 | # @retval tuple Two TemplateString objects for C code and header file, | |
1116 | # respectively | |
1117 | # | |
1118 | def CreatePcdDatabasePhaseSpecificAutoGen (Platform, Phase): | |
1119 | AutoGenC = TemplateString() | |
1120 | AutoGenH = TemplateString() | |
1121 | ||
1122 | Dict = { | |
1123 | 'PHASE' : Phase, | |
1124 | 'GUID_TABLE_SIZE' : '1', | |
1125 | 'STRING_TABLE_SIZE' : '1', | |
1126 | 'SKUID_TABLE_SIZE' : '1', | |
1127 | 'LOCAL_TOKEN_NUMBER_TABLE_SIZE' : '1', | |
1128 | 'LOCAL_TOKEN_NUMBER' : '0', | |
1129 | 'EXMAPPING_TABLE_SIZE' : '1', | |
1130 | 'EX_TOKEN_NUMBER' : '0', | |
1131 | 'SIZE_TABLE_SIZE' : '2', | |
1132 | 'GUID_TABLE_EMPTY' : 'TRUE', | |
1133 | 'STRING_TABLE_EMPTY' : 'TRUE', | |
1134 | 'SKUID_TABLE_EMPTY' : 'TRUE', | |
1135 | 'DATABASE_EMPTY' : 'TRUE', | |
1136 | 'EXMAP_TABLE_EMPTY' : 'TRUE', | |
1137 | 'PCD_DATABASE_UNINIT_EMPTY' : ' UINT8 dummy; /* PCD_DATABASE_UNINIT is emptry */', | |
1138 | 'SYSTEM_SKU_ID' : ' SKU_ID SystemSkuId;', | |
1139 | 'SYSTEM_SKU_ID_VALUE' : '0' | |
1140 | } | |
1141 | ||
1142 | for DatumType in ['UINT64','UINT32','UINT16','UINT8','BOOLEAN']: | |
1143 | Dict['VARDEF_CNAME_' + DatumType] = [] | |
1144 | Dict['VARDEF_GUID_' + DatumType] = [] | |
1145 | Dict['VARDEF_SKUID_' + DatumType] = [] | |
1146 | Dict['VARDEF_VALUE_' + DatumType] = [] | |
1147 | for Init in ['INIT','UNINIT']: | |
1148 | Dict[Init+'_CNAME_DECL_' + DatumType] = [] | |
1149 | Dict[Init+'_GUID_DECL_' + DatumType] = [] | |
1150 | Dict[Init+'_NUMSKUS_DECL_' + DatumType] = [] | |
1151 | Dict[Init+'_VALUE_' + DatumType] = [] | |
1152 | ||
1153 | for Type in ['STRING_HEAD','VPD_HEAD','VARIABLE_HEAD']: | |
1154 | Dict[Type + '_CNAME_DECL'] = [] | |
1155 | Dict[Type + '_GUID_DECL'] = [] | |
1156 | Dict[Type + '_NUMSKUS_DECL'] = [] | |
1157 | Dict[Type + '_VALUE'] = [] | |
1158 | ||
1159 | Dict['STRING_TABLE_INDEX'] = [] | |
1160 | Dict['STRING_TABLE_LENGTH'] = [] | |
1161 | Dict['STRING_TABLE_CNAME'] = [] | |
1162 | Dict['STRING_TABLE_GUID'] = [] | |
1163 | Dict['STRING_TABLE_VALUE'] = [] | |
1164 | ||
1165 | Dict['SIZE_TABLE_CNAME'] = [] | |
1166 | Dict['SIZE_TABLE_GUID'] = [] | |
1167 | Dict['SIZE_TABLE_CURRENT_LENGTH'] = [] | |
1168 | Dict['SIZE_TABLE_MAXIMUM_LENGTH'] = [] | |
1169 | ||
1170 | Dict['EXMAPPING_TABLE_EXTOKEN'] = [] | |
1171 | Dict['EXMAPPING_TABLE_LOCAL_TOKEN'] = [] | |
1172 | Dict['EXMAPPING_TABLE_GUID_INDEX'] = [] | |
1173 | ||
1174 | Dict['GUID_STRUCTURE'] = [] | |
1175 | ||
1176 | Dict['SKUID_VALUE'] = [] | |
1177 | ||
1178 | if Phase == 'DXE': | |
1179 | Dict['SYSTEM_SKU_ID'] = '' | |
1180 | Dict['SYSTEM_SKU_ID_VALUE'] = '' | |
1181 | ||
1182 | StringTableIndex = 0 | |
1183 | StringTableSize = 0 | |
1184 | NumberOfLocalTokens = 0 | |
1185 | NumberOfPeiLocalTokens = 0 | |
1186 | NumberOfDxeLocalTokens = 0 | |
1187 | NumberOfExTokens = 0 | |
1188 | NumberOfSizeItems = 0 | |
1189 | GuidList = [] | |
1190 | ||
1191 | for Pcd in Platform.DynamicPcdList: | |
1192 | CName = Pcd.TokenCName | |
1193 | TokenSpaceGuidCName = Pcd.TokenSpaceGuidCName | |
1194 | ||
1195 | EdkLogger.debug(EdkLogger.DEBUG_3, "PCD: %s %s (%s : %s)" % (CName, TokenSpaceGuidCName, Pcd.Phase, Phase)) | |
1196 | if Pcd.DatumType not in gDatumSizeStringDatabase: | |
1197 | EdkLogger.error("build", AUTOGEN_ERROR, | |
1198 | "Unknown datum type [%s] of PCD %s.%s" % (Pcd.DatumType, Pcd.TokenSpaceGuidCName, Pcd.TokenCName), | |
1199 | ExtraData="[%s]" % str(Platform)) | |
1200 | ||
1201 | if Pcd.Phase == 'PEI': | |
1202 | NumberOfPeiLocalTokens += 1 | |
1203 | if Pcd.Phase == 'DXE': | |
1204 | NumberOfDxeLocalTokens += 1 | |
1205 | if Pcd.Phase != Phase: | |
1206 | continue | |
1207 | ||
1208 | # | |
1209 | # TODO: need GetGuidValue() definition | |
1210 | # | |
1211 | TokenSpaceGuidStructure = Pcd.TokenSpaceGuidValue | |
1212 | TokenSpaceGuid = GuidStructureStringToGuidValueName(TokenSpaceGuidStructure) | |
1213 | if Pcd.Type in gDynamicExPcd: | |
1214 | if TokenSpaceGuid not in GuidList: | |
1215 | GuidList += [TokenSpaceGuid] | |
1216 | Dict['GUID_STRUCTURE'].append(TokenSpaceGuidStructure) | |
1217 | NumberOfExTokens += 1 | |
1218 | ||
1219 | ValueList = [] | |
1220 | StringHeadOffsetList = [] | |
1221 | VpdHeadOffsetList = [] | |
1222 | VariableHeadValueList = [] | |
1223 | Pcd.InitString = 'UNINIT' | |
1224 | ||
1225 | if Pcd.DatumType == 'VOID*': | |
1226 | Pcd.TokenTypeList = ['PCD_DATUM_TYPE_POINTER'] | |
1227 | elif Pcd.DatumType == 'BOOLEAN': | |
1228 | Pcd.TokenTypeList = ['PCD_DATUM_TYPE_UINT8'] | |
1229 | else: | |
1230 | Pcd.TokenTypeList = ['PCD_DATUM_TYPE_' + Pcd.DatumType] | |
1231 | ||
1232 | if len(Pcd.SkuInfoList) > 1: | |
1233 | Pcd.TokenTypeList += ['PCD_TYPE_SKU_ENABLED'] | |
1234 | ||
1235 | for SkuName in Pcd.SkuInfoList: | |
1236 | Sku = Pcd.SkuInfoList[SkuName] | |
1237 | SkuId = Sku.SkuId | |
1238 | if SkuId == None or SkuId == '': | |
1239 | continue | |
1240 | ||
1241 | if SkuId not in Dict['SKUID_VALUE']: | |
1242 | Dict['SKUID_VALUE'].append(SkuId) | |
1243 | ||
1244 | SkuIdIndex = Dict['SKUID_VALUE'].index(SkuId) | |
1245 | if len(Sku.VariableName) > 0: | |
1246 | Pcd.TokenTypeList += ['PCD_TYPE_HII'] | |
1247 | Pcd.InitString = 'INIT' | |
1248 | VariableNameStructure = StringToArray(Sku.VariableName) | |
1249 | if VariableNameStructure not in Dict['STRING_TABLE_VALUE']: | |
1250 | Dict['STRING_TABLE_CNAME'].append(CName) | |
1251 | Dict['STRING_TABLE_GUID'].append(TokenSpaceGuid) | |
1252 | if StringTableIndex == 0: | |
1253 | Dict['STRING_TABLE_INDEX'].append('') | |
1254 | else: | |
1255 | Dict['STRING_TABLE_INDEX'].append('_%d' % StringTableIndex) | |
1256 | ||
1257 | Dict['STRING_TABLE_LENGTH'].append((len(Sku.VariableName) - 3 + 1) * 2) | |
1258 | Dict['STRING_TABLE_VALUE'].append(VariableNameStructure) | |
1259 | StringTableIndex += 1 | |
1260 | StringTableSize += (len(Sku.VariableName) - 3 + 1) * 2 | |
1261 | ||
1262 | VariableHeadStringIndex = 0 | |
1263 | for Index in range(Dict['STRING_TABLE_VALUE'].index(VariableNameStructure)): | |
1264 | VariableHeadStringIndex += Dict['STRING_TABLE_LENGTH'][Index] | |
1265 | ||
1266 | VariableGuidStructure = Sku.VariableGuidValue | |
1267 | VariableGuid = GuidStructureStringToGuidValueName(VariableGuidStructure) | |
1268 | if VariableGuid not in GuidList: | |
1269 | GuidList += [VariableGuid] | |
1270 | Dict['GUID_STRUCTURE'].append(VariableGuidStructure) | |
1271 | VariableHeadGuidIndex = GuidList.index(VariableGuid) | |
1272 | ||
1273 | VariableHeadValueList.append('%d, %d, %s, offsetof(%s_PCD_DATABASE, Init.%s_%s_VariableDefault_%s)' % | |
1274 | (VariableHeadGuidIndex, VariableHeadStringIndex, Sku.VariableOffset, | |
1275 | Phase, CName, TokenSpaceGuid, SkuIdIndex)) | |
1276 | Dict['VARDEF_CNAME_'+Pcd.DatumType].append(CName) | |
1277 | Dict['VARDEF_GUID_'+Pcd.DatumType].append(TokenSpaceGuid) | |
1278 | Dict['VARDEF_SKUID_'+Pcd.DatumType].append(SkuIdIndex) | |
1279 | Dict['VARDEF_VALUE_'+Pcd.DatumType].append(Sku.HiiDefaultValue) | |
1280 | elif Sku.VpdOffset != '': | |
1281 | Pcd.TokenTypeList += ['PCD_TYPE_VPD'] | |
1282 | Pcd.InitString = 'INIT' | |
1283 | VpdHeadOffsetList.append(Sku.VpdOffset) | |
1284 | else: | |
1285 | if Pcd.DatumType == 'VOID*': | |
1286 | Pcd.TokenTypeList += ['PCD_TYPE_STRING'] | |
1287 | Pcd.InitString = 'INIT' | |
1288 | if Sku.DefaultValue != '': | |
1289 | NumberOfSizeItems += 1 | |
1290 | Dict['STRING_TABLE_CNAME'].append(CName) | |
1291 | Dict['STRING_TABLE_GUID'].append(TokenSpaceGuid) | |
1292 | ||
1293 | if StringTableIndex == 0: | |
1294 | Dict['STRING_TABLE_INDEX'].append('') | |
1295 | else: | |
1296 | Dict['STRING_TABLE_INDEX'].append('_%d' % StringTableIndex) | |
1297 | if Sku.DefaultValue[0] == 'L': | |
1298 | Size = (len(Sku.DefaultValue) - 3 + 1) * 2 | |
1299 | Dict['STRING_TABLE_VALUE'].append(StringToArray(Sku.DefaultValue)) | |
1300 | elif Sku.DefaultValue[0] == '"': | |
1301 | Size = len(Sku.DefaultValue) - 2 + 1 | |
1302 | Dict['STRING_TABLE_VALUE'].append(StringToArray(Sku.DefaultValue)) | |
1303 | elif Sku.DefaultValue[0] == '{': | |
1304 | Size = len(Sku.DefaultValue.replace(',',' ').split()) | |
1305 | Dict['STRING_TABLE_VALUE'].append(Sku.DefaultValue) | |
1306 | ||
1307 | StringHeadOffsetList.append(str(StringTableSize)) | |
1308 | Dict['SIZE_TABLE_CNAME'].append(CName) | |
1309 | Dict['SIZE_TABLE_GUID'].append(TokenSpaceGuid) | |
1310 | Dict['SIZE_TABLE_CURRENT_LENGTH'].append(Size) | |
1311 | Dict['SIZE_TABLE_MAXIMUM_LENGTH'].append(Pcd.MaxDatumSize) | |
1312 | if Pcd.MaxDatumSize != '': | |
1313 | MaxDatumSize = int(Pcd.MaxDatumSize, 0) | |
1314 | if MaxDatumSize > Size: | |
1315 | Size = MaxDatumSize | |
1316 | Dict['STRING_TABLE_LENGTH'].append(Size) | |
1317 | StringTableIndex += 1 | |
1318 | StringTableSize += (Size) | |
1319 | else: | |
1320 | Pcd.TokenTypeList += ['PCD_TYPE_DATA'] | |
1321 | if Sku.DefaultValue == 'TRUE': | |
1322 | Pcd.InitString = 'INIT' | |
1323 | else: | |
1324 | try: | |
1325 | if int(Sku.DefaultValue, 0) != 0: | |
1326 | Pcd.InitString = 'INIT' | |
1327 | except: | |
1328 | pass | |
1329 | ||
1330 | # | |
1331 | # For UNIT64 type PCD's value, ULL should be append to avoid | |
1332 | # warning under linux building environment. | |
1333 | # | |
1334 | if Pcd.DatumType == "UINT64": | |
1335 | ValueList.append(Sku.DefaultValue + "ULL") | |
1336 | else: | |
1337 | ValueList.append(Sku.DefaultValue) | |
1338 | ||
1339 | Pcd.TokenTypeList = list(set(Pcd.TokenTypeList)) | |
1340 | ||
1341 | if 'PCD_TYPE_HII' in Pcd.TokenTypeList: | |
1342 | Dict['VARIABLE_HEAD_CNAME_DECL'].append(CName) | |
1343 | Dict['VARIABLE_HEAD_GUID_DECL'].append(TokenSpaceGuid) | |
1344 | Dict['VARIABLE_HEAD_NUMSKUS_DECL'].append(len(Pcd.SkuInfoList)) | |
1345 | Dict['VARIABLE_HEAD_VALUE'].append('{ %s }\n' % ' },\n { '.join(VariableHeadValueList)) | |
1346 | if 'PCD_TYPE_VPD' in Pcd.TokenTypeList: | |
1347 | Dict['VPD_HEAD_CNAME_DECL'].append(CName) | |
1348 | Dict['VPD_HEAD_GUID_DECL'].append(TokenSpaceGuid) | |
1349 | Dict['VPD_HEAD_NUMSKUS_DECL'].append(len(Pcd.SkuInfoList)) | |
1350 | Dict['VPD_HEAD_VALUE'].append('{ %s }' % ' }, { '.join(VpdHeadOffsetList)) | |
1351 | if 'PCD_TYPE_STRING' in Pcd.TokenTypeList: | |
1352 | Dict['STRING_HEAD_CNAME_DECL'].append(CName) | |
1353 | Dict['STRING_HEAD_GUID_DECL'].append(TokenSpaceGuid) | |
1354 | Dict['STRING_HEAD_NUMSKUS_DECL'].append(len(Pcd.SkuInfoList)) | |
1355 | Dict['STRING_HEAD_VALUE'].append(', '.join(StringHeadOffsetList)) | |
1356 | if 'PCD_TYPE_DATA' in Pcd.TokenTypeList: | |
1357 | Dict[Pcd.InitString+'_CNAME_DECL_'+Pcd.DatumType].append(CName) | |
1358 | Dict[Pcd.InitString+'_GUID_DECL_'+Pcd.DatumType].append(TokenSpaceGuid) | |
1359 | Dict[Pcd.InitString+'_NUMSKUS_DECL_'+Pcd.DatumType].append(len(Pcd.SkuInfoList)) | |
1360 | if Pcd.InitString == 'UNINIT': | |
1361 | Dict['PCD_DATABASE_UNINIT_EMPTY'] = '' | |
1362 | else: | |
1363 | Dict[Pcd.InitString+'_VALUE_'+Pcd.DatumType].append(', '.join(ValueList)) | |
1364 | ||
1365 | if Phase == 'PEI': | |
1366 | NumberOfLocalTokens = NumberOfPeiLocalTokens | |
1367 | if Phase == 'DXE': | |
1368 | NumberOfLocalTokens = NumberOfDxeLocalTokens | |
1369 | ||
1370 | Dict['TOKEN_INIT'] = ['' for x in range(NumberOfLocalTokens)] | |
1371 | Dict['TOKEN_CNAME'] = ['' for x in range(NumberOfLocalTokens)] | |
1372 | Dict['TOKEN_GUID'] = ['' for x in range(NumberOfLocalTokens)] | |
1373 | Dict['TOKEN_TYPE'] = ['' for x in range(NumberOfLocalTokens)] | |
1374 | ||
1375 | for Pcd in Platform.DynamicPcdList: | |
1376 | CName = Pcd.TokenCName | |
1377 | TokenSpaceGuidCName = Pcd.TokenSpaceGuidCName | |
1378 | if Pcd.Phase != Phase: | |
1379 | continue | |
1380 | ||
1381 | TokenSpaceGuid = GuidStructureStringToGuidValueName(Pcd.TokenSpaceGuidValue) #(Platform.PackageList, TokenSpaceGuidCName)) | |
1382 | GeneratedTokenNumber = Platform.PcdTokenNumber[CName, TokenSpaceGuidCName] - 1 | |
1383 | if Phase == 'DXE': | |
1384 | GeneratedTokenNumber -= NumberOfPeiLocalTokens | |
1385 | ||
1386 | EdkLogger.debug(EdkLogger.DEBUG_1, "PCD = %s.%s" % (CName, TokenSpaceGuidCName)) | |
1387 | EdkLogger.debug(EdkLogger.DEBUG_1, "phase = %s" % Phase) | |
1388 | EdkLogger.debug(EdkLogger.DEBUG_1, "GeneratedTokenNumber = %s" % str(GeneratedTokenNumber)) | |
1389 | ||
1390 | Dict['TOKEN_INIT'][GeneratedTokenNumber] = 'Init' | |
1391 | if Pcd.InitString == 'UNINIT': | |
1392 | Dict['TOKEN_INIT'][GeneratedTokenNumber] = 'Uninit' | |
1393 | Dict['TOKEN_CNAME'][GeneratedTokenNumber] = CName | |
1394 | Dict['TOKEN_GUID'][GeneratedTokenNumber] = TokenSpaceGuid | |
1395 | Dict['TOKEN_TYPE'][GeneratedTokenNumber] = ' | '.join(Pcd.TokenTypeList) | |
1396 | if Pcd.Type in gDynamicExPcd: | |
1397 | Dict['EXMAPPING_TABLE_EXTOKEN'].append(Pcd.TokenValue) | |
1398 | if Phase == 'DXE': | |
1399 | GeneratedTokenNumber += NumberOfPeiLocalTokens | |
1400 | # | |
1401 | # Per, PCD architecture specification, PCD Token Number is 1 based and 0 is defined as invalid token number. | |
1402 | # For each EX type PCD, a PCD Token Number is assigned. When the | |
1403 | # PCD Driver/PEIM map EX_GUID and EX_TOKEN_NUMBER to the PCD Token Number, | |
1404 | # the non-EX Protocol/PPI interface can be called to get/set the value. This assumption is made by | |
1405 | # Pcd Driver/PEIM in MdeModulePkg. | |
1406 | # Therefore, 1 is added to GeneratedTokenNumber to generate a PCD Token Number before being inserted | |
1407 | # to the EXMAPPING_TABLE. | |
1408 | # | |
1409 | Dict['EXMAPPING_TABLE_LOCAL_TOKEN'].append(GeneratedTokenNumber + 1) | |
1410 | Dict['EXMAPPING_TABLE_GUID_INDEX'].append(GuidList.index(TokenSpaceGuid)) | |
1411 | ||
1412 | if GuidList != []: | |
1413 | Dict['GUID_TABLE_EMPTY'] = 'FALSE' | |
1414 | Dict['GUID_TABLE_SIZE'] = len(GuidList) | |
1415 | else: | |
1416 | Dict['GUID_STRUCTURE'] = [GuidStringToGuidStructureString('00000000-0000-0000-0000-000000000000')] | |
1417 | ||
1418 | if StringTableIndex == 0: | |
1419 | Dict['STRING_TABLE_INDEX'].append('') | |
1420 | Dict['STRING_TABLE_LENGTH'].append(1) | |
1421 | Dict['STRING_TABLE_CNAME'].append('') | |
1422 | Dict['STRING_TABLE_GUID'].append('') | |
1423 | Dict['STRING_TABLE_VALUE'].append('{ 0 }') | |
1424 | else: | |
1425 | Dict['STRING_TABLE_EMPTY'] = 'FALSE' | |
1426 | Dict['STRING_TABLE_SIZE'] = StringTableSize | |
1427 | ||
1428 | if Dict['SIZE_TABLE_CNAME'] == []: | |
1429 | Dict['SIZE_TABLE_CNAME'].append('') | |
1430 | Dict['SIZE_TABLE_GUID'].append('') | |
1431 | Dict['SIZE_TABLE_CURRENT_LENGTH'].append(0) | |
1432 | Dict['SIZE_TABLE_MAXIMUM_LENGTH'].append(0) | |
1433 | ||
1434 | if NumberOfLocalTokens != 0: | |
1435 | Dict['DATABASE_EMPTY'] = 'FALSE' | |
1436 | Dict['LOCAL_TOKEN_NUMBER_TABLE_SIZE'] = NumberOfLocalTokens | |
1437 | Dict['LOCAL_TOKEN_NUMBER'] = NumberOfLocalTokens | |
1438 | ||
1439 | if NumberOfExTokens != 0: | |
1440 | Dict['EXMAP_TABLE_EMPTY'] = 'FALSE' | |
1441 | Dict['EXMAPPING_TABLE_SIZE'] = NumberOfExTokens | |
1442 | Dict['EX_TOKEN_NUMBER'] = NumberOfExTokens | |
1443 | else: | |
1444 | Dict['EXMAPPING_TABLE_EXTOKEN'].append(0) | |
1445 | Dict['EXMAPPING_TABLE_LOCAL_TOKEN'].append(0) | |
1446 | Dict['EXMAPPING_TABLE_GUID_INDEX'].append(0) | |
1447 | ||
1448 | if NumberOfSizeItems != 0: | |
1449 | Dict['SIZE_TABLE_SIZE'] = NumberOfSizeItems * 2 | |
1450 | ||
1451 | AutoGenH.Append(gPcdDatabaseAutoGenH.Replace(Dict)) | |
1452 | if NumberOfLocalTokens == 0: | |
1453 | AutoGenC.Append(gEmptyPcdDatabaseAutoGenC.Replace(Dict)) | |
1454 | else: | |
1455 | AutoGenC.Append(gPcdDatabaseAutoGenC.Replace(Dict)) | |
1456 | ||
1457 | return AutoGenH, AutoGenC | |
1458 | ||
1459 | ## Create code for PCD database | |
1460 | # | |
1461 | # @param Info The ModuleAutoGen object | |
1462 | # @param AutoGenC The TemplateString object for C code | |
1463 | # @param AutoGenH The TemplateString object for header file | |
1464 | # | |
1465 | def CreatePcdDatabaseCode (Info, AutoGenC, AutoGenH): | |
1466 | if Info.PcdIsDriver == "": | |
1467 | return | |
1468 | if Info.PcdIsDriver not in gPcdPhaseMap: | |
1469 | EdkLogger.error("build", AUTOGEN_ERROR, "Not supported PcdIsDriver type:%s" % Info.PcdIsDriver, | |
1470 | ExtraData="[%s]" % str(Info)) | |
1471 | ||
1472 | AutoGenH.Append(gPcdDatabaseCommonAutoGenH) | |
1473 | AdditionalAutoGenH, AdditionalAutoGenC = CreatePcdDatabasePhaseSpecificAutoGen (Info.PlatformInfo, 'PEI') | |
1474 | AutoGenH.Append(AdditionalAutoGenH.String) | |
1475 | ||
1476 | Phase = gPcdPhaseMap[Info.PcdIsDriver] | |
1477 | if Phase == 'PEI': | |
1478 | AutoGenC.Append(AdditionalAutoGenC.String) | |
1479 | ||
1480 | if Phase == 'DXE': | |
1481 | AdditionalAutoGenH, AdditionalAutoGenC = CreatePcdDatabasePhaseSpecificAutoGen (Info.PlatformInfo, Phase) | |
1482 | AutoGenH.Append(AdditionalAutoGenH.String) | |
1483 | AutoGenC.Append(AdditionalAutoGenC.String) | |
1484 | AutoGenH.Append(gPcdDatabaseEpilogueAutoGenH) | |
1485 | ||
1486 | ## Create code for library constructor | |
1487 | # | |
1488 | # @param Info The ModuleAutoGen object | |
1489 | # @param AutoGenC The TemplateString object for C code | |
1490 | # @param AutoGenH The TemplateString object for header file | |
1491 | # | |
1492 | def CreateLibraryConstructorCode(Info, AutoGenC, AutoGenH): | |
1493 | # | |
1494 | # Library Constructors | |
1495 | # | |
1496 | ConstructorPrototypeString = TemplateString() | |
1497 | ConstructorCallingString = TemplateString() | |
1498 | if Info.IsLibrary: | |
1499 | DependentLibraryList = [Info.Module] | |
1500 | else: | |
1501 | DependentLibraryList = Info.DependentLibraryList | |
1502 | for Lib in DependentLibraryList: | |
1503 | if len(Lib.ConstructorList) <= 0: | |
1504 | continue | |
1505 | Dict = {'Function':Lib.ConstructorList} | |
1506 | if Lib.ModuleType in ['BASE', 'SEC']: | |
1507 | ConstructorPrototypeString.Append(gLibraryStructorPrototype['BASE'].Replace(Dict)) | |
1508 | ConstructorCallingString.Append(gLibraryStructorCall['BASE'].Replace(Dict)) | |
1509 | elif Lib.ModuleType in ['PEI_CORE','PEIM']: | |
1510 | ConstructorPrototypeString.Append(gLibraryStructorPrototype['PEI'].Replace(Dict)) | |
1511 | ConstructorCallingString.Append(gLibraryStructorCall['PEI'].Replace(Dict)) | |
1512 | elif Lib.ModuleType in ['DXE_CORE','DXE_DRIVER','DXE_SMM_DRIVER','DXE_RUNTIME_DRIVER', | |
b303ea72 | 1513 | 'DXE_SAL_DRIVER','UEFI_DRIVER','UEFI_APPLICATION','SMM_CORE']: |
30fdf114 LG |
1514 | ConstructorPrototypeString.Append(gLibraryStructorPrototype['DXE'].Replace(Dict)) |
1515 | ConstructorCallingString.Append(gLibraryStructorCall['DXE'].Replace(Dict)) | |
1516 | ||
1517 | if str(ConstructorPrototypeString) == '': | |
1518 | ConstructorPrototypeList = [] | |
1519 | else: | |
1520 | ConstructorPrototypeList = [str(ConstructorPrototypeString)] | |
1521 | if str(ConstructorCallingString) == '': | |
1522 | ConstructorCallingList = [] | |
1523 | else: | |
1524 | ConstructorCallingList = [str(ConstructorCallingString)] | |
1525 | ||
1526 | Dict = { | |
1527 | 'Type' : 'Constructor', | |
1528 | 'FunctionPrototype' : ConstructorPrototypeList, | |
1529 | 'FunctionCall' : ConstructorCallingList | |
1530 | } | |
1531 | if Info.IsLibrary: | |
1532 | AutoGenH.Append("${BEGIN}${FunctionPrototype}${END}", Dict) | |
1533 | else: | |
1534 | if Info.ModuleType in ['BASE', 'SEC']: | |
1535 | AutoGenC.Append(gLibraryString['BASE'].Replace(Dict)) | |
1536 | elif Info.ModuleType in ['PEI_CORE','PEIM']: | |
1537 | AutoGenC.Append(gLibraryString['PEI'].Replace(Dict)) | |
1538 | elif Info.ModuleType in ['DXE_CORE','DXE_DRIVER','DXE_SMM_DRIVER','DXE_RUNTIME_DRIVER', | |
b303ea72 | 1539 | 'DXE_SAL_DRIVER','UEFI_DRIVER','UEFI_APPLICATION','SMM_CORE']: |
30fdf114 LG |
1540 | AutoGenC.Append(gLibraryString['DXE'].Replace(Dict)) |
1541 | ||
1542 | ## Create code for library destructor | |
1543 | # | |
1544 | # @param Info The ModuleAutoGen object | |
1545 | # @param AutoGenC The TemplateString object for C code | |
1546 | # @param AutoGenH The TemplateString object for header file | |
1547 | # | |
1548 | def CreateLibraryDestructorCode(Info, AutoGenC, AutoGenH): | |
1549 | # | |
1550 | # Library Destructors | |
1551 | # | |
1552 | DestructorPrototypeString = TemplateString() | |
1553 | DestructorCallingString = TemplateString() | |
1554 | if Info.IsLibrary: | |
1555 | DependentLibraryList = [Info.Module] | |
1556 | else: | |
1557 | DependentLibraryList = Info.DependentLibraryList | |
1558 | for Index in range(len(DependentLibraryList)-1, -1, -1): | |
1559 | Lib = DependentLibraryList[Index] | |
1560 | if len(Lib.DestructorList) <= 0: | |
1561 | continue | |
1562 | Dict = {'Function':Lib.DestructorList} | |
1563 | if Lib.ModuleType in ['BASE', 'SEC']: | |
1564 | DestructorPrototypeString.Append(gLibraryStructorPrototype['BASE'].Replace(Dict)) | |
1565 | DestructorCallingString.Append(gLibraryStructorCall['BASE'].Replace(Dict)) | |
1566 | elif Lib.ModuleType in ['PEI_CORE','PEIM']: | |
1567 | DestructorPrototypeString.Append(gLibraryStructorPrototype['PEI'].Replace(Dict)) | |
1568 | DestructorCallingString.Append(gLibraryStructorCall['PEI'].Replace(Dict)) | |
1569 | elif Lib.ModuleType in ['DXE_CORE','DXE_DRIVER','DXE_SMM_DRIVER','DXE_RUNTIME_DRIVER', | |
b303ea72 | 1570 | 'DXE_SAL_DRIVER','UEFI_DRIVER','UEFI_APPLICATION', 'SMM_CORE']: |
30fdf114 LG |
1571 | DestructorPrototypeString.Append(gLibraryStructorPrototype['DXE'].Replace(Dict)) |
1572 | DestructorCallingString.Append(gLibraryStructorCall['DXE'].Replace(Dict)) | |
1573 | ||
1574 | if str(DestructorPrototypeString) == '': | |
1575 | DestructorPrototypeList = [] | |
1576 | else: | |
1577 | DestructorPrototypeList = [str(DestructorPrototypeString)] | |
1578 | if str(DestructorCallingString) == '': | |
1579 | DestructorCallingList = [] | |
1580 | else: | |
1581 | DestructorCallingList = [str(DestructorCallingString)] | |
1582 | ||
1583 | Dict = { | |
1584 | 'Type' : 'Destructor', | |
1585 | 'FunctionPrototype' : DestructorPrototypeList, | |
1586 | 'FunctionCall' : DestructorCallingList | |
1587 | } | |
1588 | if Info.IsLibrary: | |
1589 | AutoGenH.Append("${BEGIN}${FunctionPrototype}${END}", Dict) | |
1590 | else: | |
1591 | if Info.ModuleType in ['BASE', 'SEC']: | |
1592 | AutoGenC.Append(gLibraryString['BASE'].Replace(Dict)) | |
1593 | elif Info.ModuleType in ['PEI_CORE','PEIM']: | |
1594 | AutoGenC.Append(gLibraryString['PEI'].Replace(Dict)) | |
1595 | elif Info.ModuleType in ['DXE_CORE','DXE_DRIVER','DXE_SMM_DRIVER','DXE_RUNTIME_DRIVER', | |
b303ea72 | 1596 | 'DXE_SAL_DRIVER','UEFI_DRIVER','UEFI_APPLICATION','SMM_CORE']: |
30fdf114 LG |
1597 | AutoGenC.Append(gLibraryString['DXE'].Replace(Dict)) |
1598 | ||
1599 | ||
1600 | ## Create code for ModuleEntryPoint | |
1601 | # | |
1602 | # @param Info The ModuleAutoGen object | |
1603 | # @param AutoGenC The TemplateString object for C code | |
1604 | # @param AutoGenH The TemplateString object for header file | |
1605 | # | |
1606 | def CreateModuleEntryPointCode(Info, AutoGenC, AutoGenH): | |
1607 | if Info.IsLibrary or Info.ModuleType in ['USER_DEFINED', 'SEC']: | |
1608 | return | |
1609 | # | |
1610 | # Module Entry Points | |
1611 | # | |
1612 | NumEntryPoints = len(Info.Module.ModuleEntryPointList) | |
1613 | if 'PI_SPECIFICATION_VERSION' in Info.Module.Specification: | |
1614 | PiSpecVersion = Info.Module.Specification['PI_SPECIFICATION_VERSION'] | |
1615 | else: | |
1616 | PiSpecVersion = 0 | |
1617 | if 'EFI_SPECIFICATION_VERSION' in Info.Module.Specification: | |
1618 | EfiSpecVersion = Info.Module.Specification['EFI_SPECIFICATION_VERSION'] | |
1619 | else: | |
1620 | EfiSpecVersion = 0 | |
1621 | Dict = { | |
1622 | 'Function' : Info.Module.ModuleEntryPointList, | |
1623 | 'PiSpecVersion' : PiSpecVersion, | |
1624 | 'EfiSpecVersion': EfiSpecVersion | |
1625 | } | |
1626 | ||
1627 | if Info.ModuleType in ['PEI_CORE', 'DXE_CORE', 'SMM_CORE']: | |
1628 | if NumEntryPoints != 1: | |
1629 | EdkLogger.error( | |
1630 | "build", | |
1631 | AUTOGEN_ERROR, | |
1632 | '%s must have exactly one entry point' % Info.ModuleType, | |
1633 | File=str(Info), | |
1634 | ExtraData= ", ".join(Info.Module.ModuleEntryPointList) | |
1635 | ) | |
1636 | if Info.ModuleType == 'PEI_CORE': | |
1637 | AutoGenC.Append(gPeiCoreEntryPointString.Replace(Dict)) | |
1638 | AutoGenH.Append(gPeiCoreEntryPointPrototype.Replace(Dict)) | |
1639 | elif Info.ModuleType == 'DXE_CORE': | |
1640 | AutoGenC.Append(gDxeCoreEntryPointString.Replace(Dict)) | |
1641 | AutoGenH.Append(gDxeCoreEntryPointPrototype.Replace(Dict)) | |
1642 | elif Info.ModuleType == 'SMM_CORE': | |
1643 | AutoGenC.Append(gSmmCoreEntryPointString.Replace(Dict)) | |
b303ea72 | 1644 | AutoGenH.Append(gSmmCoreEntryPointPrototype.Replace(Dict)) |
30fdf114 LG |
1645 | elif Info.ModuleType == 'PEIM': |
1646 | if NumEntryPoints < 2: | |
1647 | AutoGenC.Append(gPeimEntryPointString[NumEntryPoints].Replace(Dict)) | |
1648 | else: | |
1649 | AutoGenC.Append(gPeimEntryPointString[2].Replace(Dict)) | |
1650 | AutoGenH.Append(gPeimEntryPointPrototype.Replace(Dict)) | |
b303ea72 LG |
1651 | elif Info.ModuleType in ['DXE_RUNTIME_DRIVER','DXE_DRIVER','DXE_SAL_DRIVER','UEFI_DRIVER']: |
1652 | if NumEntryPoints < 2: | |
1653 | AutoGenC.Append(gUefiDriverEntryPointString[NumEntryPoints].Replace(Dict)) | |
30fdf114 | 1654 | else: |
b303ea72 LG |
1655 | AutoGenC.Append(gUefiDriverEntryPointString[2].Replace(Dict)) |
1656 | AutoGenH.Append(gUefiDriverEntryPointPrototype.Replace(Dict)) | |
1657 | elif Info.ModuleType == 'DXE_SMM_DRIVER': | |
1658 | if NumEntryPoints == 0: | |
1659 | AutoGenC.Append(gDxeSmmEntryPointString[0].Replace(Dict)) | |
1660 | else: | |
1661 | AutoGenC.Append(gDxeSmmEntryPointString[1].Replace(Dict)) | |
1662 | AutoGenH.Append(gDxeSmmEntryPointPrototype.Replace(Dict)) | |
30fdf114 LG |
1663 | elif Info.ModuleType == 'UEFI_APPLICATION': |
1664 | if NumEntryPoints < 2: | |
1665 | AutoGenC.Append(gUefiApplicationEntryPointString[NumEntryPoints].Replace(Dict)) | |
1666 | else: | |
1667 | AutoGenC.Append(gUefiApplicationEntryPointString[2].Replace(Dict)) | |
1668 | AutoGenH.Append(gUefiApplicationEntryPointPrototype.Replace(Dict)) | |
1669 | ||
1670 | ## Create code for ModuleUnloadImage | |
1671 | # | |
1672 | # @param Info The ModuleAutoGen object | |
1673 | # @param AutoGenC The TemplateString object for C code | |
1674 | # @param AutoGenH The TemplateString object for header file | |
1675 | # | |
1676 | def CreateModuleUnloadImageCode(Info, AutoGenC, AutoGenH): | |
1677 | if Info.IsLibrary or Info.ModuleType in ['USER_DEFINED', 'SEC']: | |
1678 | return | |
1679 | # | |
1680 | # Unload Image Handlers | |
1681 | # | |
1682 | NumUnloadImage = len(Info.Module.ModuleUnloadImageList) | |
1683 | Dict = {'Count':NumUnloadImage, 'Function':Info.Module.ModuleUnloadImageList} | |
1684 | if NumUnloadImage < 2: | |
1685 | AutoGenC.Append(gUefiUnloadImageString[NumUnloadImage].Replace(Dict)) | |
1686 | else: | |
1687 | AutoGenC.Append(gUefiUnloadImageString[2].Replace(Dict)) | |
1688 | AutoGenH.Append(gUefiUnloadImagePrototype.Replace(Dict)) | |
1689 | ||
1690 | ## Create code for GUID | |
1691 | # | |
1692 | # @param Info The ModuleAutoGen object | |
1693 | # @param AutoGenC The TemplateString object for C code | |
1694 | # @param AutoGenH The TemplateString object for header file | |
1695 | # | |
1696 | def CreateGuidDefinitionCode(Info, AutoGenC, AutoGenH): | |
1697 | if Info.IsLibrary: | |
1698 | return | |
1699 | ||
1700 | if Info.ModuleType in ["USER_DEFINED", "BASE"]: | |
1701 | GuidType = "GUID" | |
1702 | else: | |
1703 | GuidType = "EFI_GUID" | |
1704 | ||
1705 | if Info.GuidList: | |
1706 | AutoGenC.Append("\n// Guids\n") | |
1707 | # | |
1708 | # GUIDs | |
1709 | # | |
1710 | for Key in Info.GuidList: | |
1711 | AutoGenC.Append('GLOBAL_REMOVE_IF_UNREFERENCED %s %s = %s;\n' % (GuidType, Key, Info.GuidList[Key])) | |
1712 | ||
1713 | ## Create code for protocol | |
1714 | # | |
1715 | # @param Info The ModuleAutoGen object | |
1716 | # @param AutoGenC The TemplateString object for C code | |
1717 | # @param AutoGenH The TemplateString object for header file | |
1718 | # | |
1719 | def CreateProtocolDefinitionCode(Info, AutoGenC, AutoGenH): | |
1720 | if Info.IsLibrary: | |
1721 | return | |
1722 | ||
1723 | if Info.ModuleType in ["USER_DEFINED", "BASE"]: | |
1724 | GuidType = "GUID" | |
1725 | else: | |
1726 | GuidType = "EFI_GUID" | |
1727 | ||
1728 | if Info.ProtocolList: | |
1729 | AutoGenC.Append("\n// Protocols\n") | |
1730 | # | |
1731 | # Protocol GUIDs | |
1732 | # | |
1733 | for Key in Info.ProtocolList: | |
1734 | AutoGenC.Append('GLOBAL_REMOVE_IF_UNREFERENCED %s %s = %s;\n' % (GuidType, Key, Info.ProtocolList[Key])) | |
1735 | ||
1736 | ## Create code for PPI | |
1737 | # | |
1738 | # @param Info The ModuleAutoGen object | |
1739 | # @param AutoGenC The TemplateString object for C code | |
1740 | # @param AutoGenH The TemplateString object for header file | |
1741 | # | |
1742 | def CreatePpiDefinitionCode(Info, AutoGenC, AutoGenH): | |
1743 | if Info.IsLibrary: | |
1744 | return | |
1745 | ||
1746 | if Info.ModuleType in ["USER_DEFINED", "BASE"]: | |
1747 | GuidType = "GUID" | |
1748 | else: | |
1749 | GuidType = "EFI_GUID" | |
1750 | ||
1751 | if Info.PpiList: | |
1752 | AutoGenC.Append("\n// PPIs\n") | |
1753 | # | |
1754 | # PPI GUIDs | |
1755 | # | |
1756 | for Key in Info.PpiList: | |
1757 | AutoGenC.Append('GLOBAL_REMOVE_IF_UNREFERENCED %s %s = %s;\n' % (GuidType, Key, Info.PpiList[Key])) | |
1758 | ||
1759 | ## Create code for PCD | |
1760 | # | |
1761 | # @param Info The ModuleAutoGen object | |
1762 | # @param AutoGenC The TemplateString object for C code | |
1763 | # @param AutoGenH The TemplateString object for header file | |
1764 | # | |
1765 | def CreatePcdCode(Info, AutoGenC, AutoGenH): | |
1766 | if Info.IsLibrary: | |
1767 | if Info.ModulePcdList: | |
1768 | AutoGenH.Append("\n// PCD definitions\n") | |
1769 | for Pcd in Info.ModulePcdList: | |
1770 | CreateLibraryPcdCode(Info, AutoGenC, AutoGenH, Pcd) | |
1771 | else: | |
1772 | if Info.ModulePcdList: | |
1773 | AutoGenH.Append("\n// Definition of PCDs used in this module\n") | |
1774 | AutoGenC.Append("\n// Definition of PCDs used in this module\n") | |
1775 | for Pcd in Info.ModulePcdList: | |
1776 | CreateModulePcdCode(Info, AutoGenC, AutoGenH, Pcd) | |
1777 | ||
1778 | if Info.LibraryPcdList: | |
1779 | AutoGenH.Append("\n// Definition of PCDs used in libraries is in AutoGen.c\n") | |
1780 | AutoGenC.Append("\n// Definition of PCDs used in libraries\n") | |
1781 | for Pcd in Info.LibraryPcdList: | |
1782 | CreateModulePcdCode(Info, AutoGenC, AutoGenC, Pcd) | |
1783 | CreatePcdDatabaseCode(Info, AutoGenC, AutoGenH) | |
1784 | ||
1785 | ## Create code for unicode string definition | |
1786 | # | |
1787 | # @param Info The ModuleAutoGen object | |
1788 | # @param AutoGenC The TemplateString object for C code | |
1789 | # @param AutoGenH The TemplateString object for header file | |
b303ea72 LG |
1790 | # @param UniGenCFlag UniString is generated into AutoGen C file when it is set to True |
1791 | # @param UniGenBinBuffer Buffer to store uni string package data | |
30fdf114 | 1792 | # |
b303ea72 | 1793 | def CreateUnicodeStringCode(Info, AutoGenC, AutoGenH, UniGenCFlag, UniGenBinBuffer): |
30fdf114 LG |
1794 | WorkingDir = os.getcwd() |
1795 | os.chdir(Info.WorkspaceDir) | |
1796 | ||
1797 | IncList = [Info.MetaFile.Dir] | |
1798 | # Get all files under [Sources] section in inf file for EDK-II module | |
1799 | SrcList = [F for F in Info.SourceFileList] | |
1800 | if Info.AutoGenVersion < 0x00010005: | |
1801 | # Get all files under the module directory for EDK-I module | |
1802 | Cwd = os.getcwd() | |
1803 | os.chdir(Info.MetaFile.Dir) | |
1804 | for Root, Dirs, Files in os.walk("."): | |
1805 | if 'CVS' in Dirs: | |
1806 | Dirs.remove('CVS') | |
1807 | if '.svn' in Dirs: | |
1808 | Dirs.remove('.svn') | |
1809 | for File in Files: | |
1810 | File = PathClass(os.path.join(Root, File), Info.MetaFile.Dir) | |
1811 | if File in SrcList: | |
1812 | continue | |
1813 | SrcList.append(File) | |
1814 | os.chdir(Cwd) | |
1815 | ||
1816 | if 'BUILD' in Info.BuildOption and Info.BuildOption['BUILD']['FLAGS'].find('-c') > -1: | |
1817 | CompatibleMode = True | |
1818 | else: | |
1819 | CompatibleMode = False | |
1820 | ||
1821 | # | |
1822 | # -s is a temporary option dedicated for building .UNI files with ISO 639-2 lanauge codes of EDK Shell in EDK2 | |
1823 | # | |
1824 | if 'BUILD' in Info.BuildOption and Info.BuildOption['BUILD']['FLAGS'].find('-s') > -1: | |
1825 | if CompatibleMode: | |
1826 | EdkLogger.error("build", AUTOGEN_ERROR, | |
1827 | "-c and -s build options should be used exclusively", | |
1828 | ExtraData="[%s]" % str(Info)) | |
1829 | ShellMode = True | |
1830 | else: | |
1831 | ShellMode = False | |
1832 | ||
b303ea72 LG |
1833 | Header, Code = GetStringFiles(Info.UnicodeFileList, SrcList, IncList, ['.uni', '.inf'], Info.Name, CompatibleMode, ShellMode, UniGenCFlag, UniGenBinBuffer) |
1834 | if CompatibleMode or UniGenCFlag: | |
1835 | AutoGenC.Append("\n//\n//Unicode String Pack Definition\n//\n") | |
1836 | AutoGenC.Append(Code) | |
1837 | AutoGenC.Append("\n") | |
30fdf114 LG |
1838 | AutoGenH.Append("\n//\n//Unicode String ID\n//\n") |
1839 | AutoGenH.Append(Header) | |
b303ea72 LG |
1840 | if CompatibleMode or UniGenCFlag: |
1841 | AutoGenH.Append("\n#define STRING_ARRAY_NAME %sStrings\n" % Info.Name) | |
30fdf114 LG |
1842 | os.chdir(WorkingDir) |
1843 | ||
1844 | ## Create common code | |
1845 | # | |
1846 | # @param Info The ModuleAutoGen object | |
1847 | # @param AutoGenC The TemplateString object for C code | |
1848 | # @param AutoGenH The TemplateString object for header file | |
1849 | # | |
1850 | def CreateHeaderCode(Info, AutoGenC, AutoGenH): | |
1851 | # file header | |
1852 | AutoGenH.Append(gAutoGenHeaderString.Replace({'FileName':'AutoGen.h'})) | |
1853 | # header file Prologue | |
1854 | AutoGenH.Append(gAutoGenHPrologueString.Replace({'File':'AUTOGENH','Guid':Info.Guid.replace('-','_')})) | |
1855 | if Info.AutoGenVersion >= 0x00010005: | |
1856 | # specification macros | |
1857 | AutoGenH.Append(gSpecificationString.Replace({'SpecificationName':Info.Specification.keys(), | |
1858 | 'SpecificationValue':Info.Specification.values()})) | |
1859 | # header files includes | |
1860 | AutoGenH.Append("#include <%s>\n" % gBasicHeaderFile) | |
1861 | if Info.ModuleType in gModuleTypeHeaderFile \ | |
1862 | and gModuleTypeHeaderFile[Info.ModuleType][0] != gBasicHeaderFile: | |
1863 | AutoGenH.Append("#include <%s>\n" % gModuleTypeHeaderFile[Info.ModuleType][0]) | |
1864 | AutoGenH.Append('\nextern GUID gEfiCallerIdGuid;\n\n') | |
1865 | ||
1866 | if Info.IsLibrary: | |
1867 | return | |
1868 | ||
1869 | AutoGenH.Append("#define EFI_CALLER_ID_GUID \\\n %s\n" % GuidStringToGuidStructureString(Info.Guid)) | |
1870 | ||
1871 | if Info.IsLibrary: | |
1872 | return | |
1873 | # C file header | |
1874 | AutoGenC.Append(gAutoGenHeaderString.Replace({'FileName':'AutoGen.c'})) | |
1875 | if Info.AutoGenVersion >= 0x00010005: | |
1876 | # C file header files includes | |
1877 | if Info.ModuleType in gModuleTypeHeaderFile: | |
1878 | for Inc in gModuleTypeHeaderFile[Info.ModuleType]: | |
1879 | AutoGenC.Append("#include <%s>\n" % Inc) | |
1880 | else: | |
1881 | AutoGenC.Append("#include <%s>\n" % gBasicHeaderFile) | |
1882 | ||
1883 | # | |
1884 | # Publish the CallerId Guid | |
1885 | # | |
1886 | AutoGenC.Append('\nGLOBAL_REMOVE_IF_UNREFERENCED GUID gEfiCallerIdGuid = %s;\n' % GuidStringToGuidStructureString(Info.Guid)) | |
1887 | ||
1888 | ## Create common code for header file | |
1889 | # | |
1890 | # @param Info The ModuleAutoGen object | |
1891 | # @param AutoGenC The TemplateString object for C code | |
1892 | # @param AutoGenH The TemplateString object for header file | |
1893 | # | |
1894 | def CreateFooterCode(Info, AutoGenC, AutoGenH): | |
1895 | AutoGenH.Append(gAutoGenHEpilogueString) | |
1896 | ||
1897 | ## Create code for a module | |
1898 | # | |
1899 | # @param Info The ModuleAutoGen object | |
1900 | # @param AutoGenC The TemplateString object for C code | |
1901 | # @param AutoGenH The TemplateString object for header file | |
b303ea72 LG |
1902 | # @param UniGenCFlag UniString is generated into AutoGen C file when it is set to True |
1903 | # @param UniGenBinBuffer Buffer to store uni string package data | |
30fdf114 | 1904 | # |
b303ea72 | 1905 | def CreateCode(Info, AutoGenC, AutoGenH, StringH, UniGenCFlag, UniGenBinBuffer): |
30fdf114 LG |
1906 | CreateHeaderCode(Info, AutoGenC, AutoGenH) |
1907 | ||
1908 | if Info.AutoGenVersion >= 0x00010005: | |
1909 | CreateGuidDefinitionCode(Info, AutoGenC, AutoGenH) | |
1910 | CreateProtocolDefinitionCode(Info, AutoGenC, AutoGenH) | |
1911 | CreatePpiDefinitionCode(Info, AutoGenC, AutoGenH) | |
1912 | CreatePcdCode(Info, AutoGenC, AutoGenH) | |
1913 | CreateLibraryConstructorCode(Info, AutoGenC, AutoGenH) | |
1914 | CreateLibraryDestructorCode(Info, AutoGenC, AutoGenH) | |
1915 | CreateModuleEntryPointCode(Info, AutoGenC, AutoGenH) | |
1916 | CreateModuleUnloadImageCode(Info, AutoGenC, AutoGenH) | |
1917 | ||
1918 | if Info.UnicodeFileList: | |
1919 | FileName = "%sStrDefs.h" % Info.Name | |
1920 | StringH.Append(gAutoGenHeaderString.Replace({'FileName':FileName})) | |
1921 | StringH.Append(gAutoGenHPrologueString.Replace({'File':'STRDEFS', 'Guid':Info.Guid.replace('-','_')})) | |
b303ea72 | 1922 | CreateUnicodeStringCode(Info, AutoGenC, StringH, UniGenCFlag, UniGenBinBuffer) |
30fdf114 LG |
1923 | StringH.Append("\n#endif\n") |
1924 | AutoGenH.Append('#include "%s"\n' % FileName) | |
1925 | ||
1926 | CreateFooterCode(Info, AutoGenC, AutoGenH) | |
1927 | ||
1928 | # no generation of AutoGen.c for R8 modules without unicode file | |
1929 | if Info.AutoGenVersion < 0x00010005 and len(Info.UnicodeFileList) == 0: | |
1930 | AutoGenC.String = '' | |
1931 | ||
1932 | ## Create the code file | |
1933 | # | |
b303ea72 LG |
1934 | # @param FilePath The path of code file |
1935 | # @param Content The content of code file | |
1936 | # @param IsBinaryFile The flag indicating if the file is binary file or not | |
30fdf114 LG |
1937 | # |
1938 | # @retval True If file content is changed or file doesn't exist | |
1939 | # @retval False If the file exists and the content is not changed | |
1940 | # | |
b303ea72 LG |
1941 | def Generate(FilePath, Content, IsBinaryFile): |
1942 | return SaveFileOnChange(FilePath, Content, IsBinaryFile) | |
30fdf114 | 1943 |