]>
Commit | Line | Data |
---|---|---|
30fdf114 LG |
1 | ## @file |
2 | # Routines for generating AutoGen.h and AutoGen.c | |
3 | # | |
da92f276 | 4 | # Copyright (c) 2007 - 2011, Intel Corporation. All rights reserved.<BR> |
40d841f6 | 5 | # This program and the accompanying materials |
30fdf114 LG |
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 | ||
b36d134f LG |
70 | #define PCD_TYPE_DATA (0x0U << PCD_TYPE_SHIFT) |
71 | #define PCD_TYPE_HII (0x8U << PCD_TYPE_SHIFT) | |
72 | #define PCD_TYPE_VPD (0x4U << PCD_TYPE_SHIFT) | |
73 | #define PCD_TYPE_SKU_ENABLED (0x2U << PCD_TYPE_SHIFT) | |
74 | #define PCD_TYPE_STRING (0x1U << PCD_TYPE_SHIFT) | |
30fdf114 LG |
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 | ||
b36d134f LG |
80 | #define PCD_DATUM_TYPE_POINTER (0x0U << PCD_DATUM_TYPE_SHIFT) |
81 | #define PCD_DATUM_TYPE_UINT8 (0x1U << PCD_DATUM_TYPE_SHIFT) | |
82 | #define PCD_DATUM_TYPE_UINT16 (0x2U << PCD_DATUM_TYPE_SHIFT) | |
83 | #define PCD_DATUM_TYPE_UINT32 (0x4U << PCD_DATUM_TYPE_SHIFT) | |
84 | #define PCD_DATUM_TYPE_UINT64 (0x8U << PCD_DATUM_TYPE_SHIFT) | |
30fdf114 LG |
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} | |
52302d4d | 165 | ${BEGIN} VARIABLE_HEAD ${VARIABLE_HEAD_CNAME_DECL}_${VARIABLE_HEAD_GUID_DECL}_Variable_Header[${VARIABLE_HEAD_NUMSKUS_DECL}]; |
30fdf114 LG |
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 | { | |
52302d4d | 256 | ${BEGIN} offsetof(${PHASE}_PCD_DATABASE, ${TOKEN_INIT}.${TOKEN_CNAME}_${TOKEN_GUID}${VARDEF_HEADER}) | ${TOKEN_TYPE}, |
30fdf114 LG |
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} | |
52302d4d | 266 | ${BEGIN} /* ${VARIABLE_HEAD_CNAME_DECL}_${VARIABLE_HEAD_GUID_DECL}_Variable_Header[${VARIABLE_HEAD_NUMSKUS_DECL}] */ |
30fdf114 LG |
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 | ||
d40b2ee6 LG |
313 | #ifdef __cplusplus |
314 | extern "C" { | |
315 | #endif | |
316 | ||
30fdf114 LG |
317 | """) |
318 | ||
319 | gAutoGenHEpilogueString = """ | |
d40b2ee6 LG |
320 | |
321 | #ifdef __cplusplus | |
322 | } | |
323 | #endif | |
324 | ||
30fdf114 LG |
325 | #endif |
326 | """ | |
327 | ||
328 | ## PEI Core Entry Point Templates | |
329 | gPeiCoreEntryPointPrototype = TemplateString(""" | |
330 | ${BEGIN} | |
331 | VOID | |
332 | EFIAPI | |
333 | ${Function} ( | |
334 | IN CONST EFI_SEC_PEI_HAND_OFF *SecCoreData, | |
335 | IN CONST EFI_PEI_PPI_DESCRIPTOR *PpiList, | |
336 | IN VOID *Context | |
337 | ); | |
338 | ${END} | |
339 | """) | |
340 | ||
341 | gPeiCoreEntryPointString = TemplateString(""" | |
342 | ${BEGIN} | |
343 | VOID | |
344 | EFIAPI | |
345 | ProcessModuleEntryPointList ( | |
346 | IN CONST EFI_SEC_PEI_HAND_OFF *SecCoreData, | |
347 | IN CONST EFI_PEI_PPI_DESCRIPTOR *PpiList, | |
348 | IN VOID *Context | |
349 | ) | |
350 | ||
351 | { | |
352 | ${Function} (SecCoreData, PpiList, Context); | |
353 | } | |
354 | ${END} | |
355 | """) | |
356 | ||
357 | ||
358 | ## DXE Core Entry Point Templates | |
359 | gDxeCoreEntryPointPrototype = TemplateString(""" | |
360 | ${BEGIN} | |
361 | VOID | |
362 | EFIAPI | |
363 | ${Function} ( | |
364 | IN VOID *HobStart | |
365 | ); | |
366 | ${END} | |
367 | """) | |
368 | ||
369 | gDxeCoreEntryPointString = TemplateString(""" | |
370 | ${BEGIN} | |
371 | VOID | |
372 | EFIAPI | |
373 | ProcessModuleEntryPointList ( | |
374 | IN VOID *HobStart | |
375 | ) | |
376 | ||
377 | { | |
378 | ${Function} (HobStart); | |
379 | } | |
380 | ${END} | |
381 | """) | |
382 | ||
383 | ## PEIM Entry Point Templates | |
384 | gPeimEntryPointPrototype = TemplateString(""" | |
385 | ${BEGIN} | |
386 | EFI_STATUS | |
387 | EFIAPI | |
388 | ${Function} ( | |
389 | IN EFI_PEI_FILE_HANDLE FileHandle, | |
390 | IN CONST EFI_PEI_SERVICES **PeiServices | |
391 | ); | |
392 | ${END} | |
393 | """) | |
394 | ||
30fdf114 LG |
395 | gPeimEntryPointString = [ |
396 | TemplateString(""" | |
397 | GLOBAL_REMOVE_IF_UNREFERENCED const UINT32 _gPeimRevision = ${PiSpecVersion}; | |
398 | ||
399 | EFI_STATUS | |
400 | EFIAPI | |
401 | ProcessModuleEntryPointList ( | |
402 | IN EFI_PEI_FILE_HANDLE FileHandle, | |
403 | IN CONST EFI_PEI_SERVICES **PeiServices | |
404 | ) | |
405 | ||
406 | { | |
407 | return EFI_SUCCESS; | |
408 | } | |
409 | """), | |
410 | TemplateString(""" | |
411 | GLOBAL_REMOVE_IF_UNREFERENCED const UINT32 _gPeimRevision = ${PiSpecVersion}; | |
412 | ${BEGIN} | |
413 | EFI_STATUS | |
414 | EFIAPI | |
415 | ProcessModuleEntryPointList ( | |
416 | IN EFI_PEI_FILE_HANDLE FileHandle, | |
417 | IN CONST EFI_PEI_SERVICES **PeiServices | |
418 | ) | |
419 | ||
420 | { | |
421 | return ${Function} (FileHandle, PeiServices); | |
422 | } | |
423 | ${END} | |
424 | """), | |
425 | TemplateString(""" | |
426 | GLOBAL_REMOVE_IF_UNREFERENCED const UINT32 _gPeimRevision = ${PiSpecVersion}; | |
427 | ||
428 | EFI_STATUS | |
429 | EFIAPI | |
430 | ProcessModuleEntryPointList ( | |
431 | IN EFI_PEI_FILE_HANDLE FileHandle, | |
432 | IN CONST EFI_PEI_SERVICES **PeiServices | |
433 | ) | |
434 | ||
435 | { | |
436 | EFI_STATUS Status; | |
437 | EFI_STATUS CombinedStatus; | |
438 | ||
439 | CombinedStatus = EFI_LOAD_ERROR; | |
440 | ${BEGIN} | |
441 | Status = ${Function} (FileHandle, PeiServices); | |
442 | if (!EFI_ERROR (Status) || EFI_ERROR (CombinedStatus)) { | |
443 | CombinedStatus = Status; | |
444 | } | |
445 | ${END} | |
446 | return CombinedStatus; | |
447 | } | |
448 | """) | |
449 | ] | |
450 | ||
b303ea72 LG |
451 | ## SMM_CORE Entry Point Templates |
452 | gSmmCoreEntryPointPrototype = TemplateString(""" | |
453 | ${BEGIN} | |
454 | EFI_STATUS | |
455 | EFIAPI | |
456 | ${Function} ( | |
457 | IN EFI_HANDLE ImageHandle, | |
458 | IN EFI_SYSTEM_TABLE *SystemTable | |
459 | ); | |
460 | ${END} | |
461 | """) | |
462 | ||
463 | gSmmCoreEntryPointString = TemplateString(""" | |
464 | ${BEGIN} | |
52302d4d | 465 | const UINT32 _gUefiDriverRevision = ${UefiSpecVersion}; |
b303ea72 LG |
466 | const UINT32 _gDxeRevision = ${PiSpecVersion}; |
467 | ||
468 | EFI_STATUS | |
469 | EFIAPI | |
470 | ProcessModuleEntryPointList ( | |
471 | IN EFI_HANDLE ImageHandle, | |
472 | IN EFI_SYSTEM_TABLE *SystemTable | |
473 | ) | |
474 | { | |
475 | return ${Function} (ImageHandle, SystemTable); | |
476 | } | |
477 | ${END} | |
478 | """) | |
479 | ||
30fdf114 LG |
480 | ## DXE SMM Entry Point Templates |
481 | gDxeSmmEntryPointPrototype = TemplateString(""" | |
482 | ${BEGIN} | |
483 | EFI_STATUS | |
484 | EFIAPI | |
485 | ${Function} ( | |
486 | IN EFI_HANDLE ImageHandle, | |
487 | IN EFI_SYSTEM_TABLE *SystemTable | |
488 | ); | |
489 | ${END} | |
490 | """) | |
491 | ||
492 | gDxeSmmEntryPointString = [ | |
493 | TemplateString(""" | |
52302d4d | 494 | const UINT32 _gUefiDriverRevision = ${UefiSpecVersion}; |
30fdf114 LG |
495 | const UINT32 _gDxeRevision = ${PiSpecVersion}; |
496 | ||
497 | EFI_STATUS | |
498 | EFIAPI | |
499 | ProcessModuleEntryPointList ( | |
500 | IN EFI_HANDLE ImageHandle, | |
501 | IN EFI_SYSTEM_TABLE *SystemTable | |
502 | ) | |
503 | ||
504 | { | |
505 | return EFI_SUCCESS; | |
506 | } | |
507 | """), | |
508 | TemplateString(""" | |
52302d4d | 509 | const UINT32 _gUefiDriverRevision = ${UefiSpecVersion}; |
30fdf114 LG |
510 | const UINT32 _gDxeRevision = ${PiSpecVersion}; |
511 | ||
512 | static BASE_LIBRARY_JUMP_BUFFER mJumpContext; | |
52302d4d | 513 | static EFI_STATUS mDriverEntryPointStatus; |
30fdf114 LG |
514 | |
515 | VOID | |
516 | EFIAPI | |
517 | ExitDriver ( | |
518 | IN EFI_STATUS Status | |
519 | ) | |
520 | { | |
521 | if (!EFI_ERROR (Status) || EFI_ERROR (mDriverEntryPointStatus)) { | |
522 | mDriverEntryPointStatus = Status; | |
523 | } | |
524 | LongJump (&mJumpContext, (UINTN)-1); | |
525 | ASSERT (FALSE); | |
526 | } | |
527 | ||
528 | EFI_STATUS | |
529 | EFIAPI | |
530 | ProcessModuleEntryPointList ( | |
531 | IN EFI_HANDLE ImageHandle, | |
532 | IN EFI_SYSTEM_TABLE *SystemTable | |
533 | ) | |
30fdf114 | 534 | { |
52302d4d LG |
535 | mDriverEntryPointStatus = EFI_LOAD_ERROR; |
536 | ||
30fdf114 LG |
537 | ${BEGIN} |
538 | if (SetJump (&mJumpContext) == 0) { | |
539 | ExitDriver (${Function} (ImageHandle, SystemTable)); | |
540 | ASSERT (FALSE); | |
541 | } | |
542 | ${END} | |
543 | ||
544 | return mDriverEntryPointStatus; | |
545 | } | |
546 | """) | |
547 | ] | |
548 | ||
549 | ## UEFI Driver Entry Point Templates | |
550 | gUefiDriverEntryPointPrototype = TemplateString(""" | |
551 | ${BEGIN} | |
552 | EFI_STATUS | |
553 | EFIAPI | |
554 | ${Function} ( | |
555 | IN EFI_HANDLE ImageHandle, | |
556 | IN EFI_SYSTEM_TABLE *SystemTable | |
557 | ); | |
558 | ${END} | |
559 | """) | |
560 | ||
561 | gUefiDriverEntryPointString = [ | |
562 | TemplateString(""" | |
52302d4d | 563 | const UINT32 _gUefiDriverRevision = ${UefiSpecVersion}; |
30fdf114 LG |
564 | const UINT32 _gDxeRevision = ${PiSpecVersion}; |
565 | ||
566 | EFI_STATUS | |
567 | EFIAPI | |
568 | ProcessModuleEntryPointList ( | |
569 | IN EFI_HANDLE ImageHandle, | |
570 | IN EFI_SYSTEM_TABLE *SystemTable | |
571 | ) | |
572 | { | |
573 | return EFI_SUCCESS; | |
574 | } | |
575 | """), | |
576 | TemplateString(""" | |
52302d4d | 577 | const UINT32 _gUefiDriverRevision = ${UefiSpecVersion}; |
30fdf114 LG |
578 | const UINT32 _gDxeRevision = ${PiSpecVersion}; |
579 | ||
580 | ${BEGIN} | |
581 | EFI_STATUS | |
582 | EFIAPI | |
583 | ProcessModuleEntryPointList ( | |
584 | IN EFI_HANDLE ImageHandle, | |
585 | IN EFI_SYSTEM_TABLE *SystemTable | |
586 | ) | |
587 | ||
588 | { | |
589 | return ${Function} (ImageHandle, SystemTable); | |
590 | } | |
591 | ${END} | |
592 | VOID | |
593 | EFIAPI | |
594 | ExitDriver ( | |
595 | IN EFI_STATUS Status | |
596 | ) | |
597 | { | |
598 | if (EFI_ERROR (Status)) { | |
599 | ProcessLibraryDestructorList (gImageHandle, gST); | |
600 | } | |
601 | gBS->Exit (gImageHandle, Status, 0, NULL); | |
602 | } | |
603 | """), | |
604 | TemplateString(""" | |
52302d4d | 605 | const UINT32 _gUefiDriverRevision = ${UefiSpecVersion}; |
30fdf114 LG |
606 | const UINT32 _gDxeRevision = ${PiSpecVersion}; |
607 | ||
52302d4d LG |
608 | static BASE_LIBRARY_JUMP_BUFFER mJumpContext; |
609 | static EFI_STATUS mDriverEntryPointStatus; | |
610 | ||
30fdf114 LG |
611 | EFI_STATUS |
612 | EFIAPI | |
613 | ProcessModuleEntryPointList ( | |
614 | IN EFI_HANDLE ImageHandle, | |
615 | IN EFI_SYSTEM_TABLE *SystemTable | |
616 | ) | |
30fdf114 | 617 | { |
52302d4d | 618 | mDriverEntryPointStatus = EFI_LOAD_ERROR; |
30fdf114 LG |
619 | ${BEGIN} |
620 | if (SetJump (&mJumpContext) == 0) { | |
621 | ExitDriver (${Function} (ImageHandle, SystemTable)); | |
622 | ASSERT (FALSE); | |
623 | } | |
624 | ${END} | |
625 | return mDriverEntryPointStatus; | |
626 | } | |
627 | ||
30fdf114 LG |
628 | VOID |
629 | EFIAPI | |
630 | ExitDriver ( | |
631 | IN EFI_STATUS Status | |
632 | ) | |
633 | { | |
634 | if (!EFI_ERROR (Status) || EFI_ERROR (mDriverEntryPointStatus)) { | |
635 | mDriverEntryPointStatus = Status; | |
636 | } | |
637 | LongJump (&mJumpContext, (UINTN)-1); | |
638 | ASSERT (FALSE); | |
639 | } | |
640 | """) | |
641 | ] | |
642 | ||
643 | ||
644 | ## UEFI Application Entry Point Templates | |
645 | gUefiApplicationEntryPointPrototype = TemplateString(""" | |
646 | ${BEGIN} | |
647 | EFI_STATUS | |
648 | EFIAPI | |
649 | ${Function} ( | |
650 | IN EFI_HANDLE ImageHandle, | |
651 | IN EFI_SYSTEM_TABLE *SystemTable | |
652 | ); | |
653 | ${END} | |
654 | """) | |
655 | ||
656 | gUefiApplicationEntryPointString = [ | |
657 | TemplateString(""" | |
52302d4d | 658 | const UINT32 _gUefiDriverRevision = ${UefiSpecVersion}; |
30fdf114 LG |
659 | |
660 | EFI_STATUS | |
661 | EFIAPI | |
662 | ProcessModuleEntryPointList ( | |
663 | IN EFI_HANDLE ImageHandle, | |
664 | IN EFI_SYSTEM_TABLE *SystemTable | |
665 | ) | |
666 | { | |
667 | return EFI_SUCCESS; | |
668 | } | |
669 | """), | |
670 | TemplateString(""" | |
52302d4d | 671 | const UINT32 _gUefiDriverRevision = ${UefiSpecVersion}; |
30fdf114 LG |
672 | |
673 | ${BEGIN} | |
674 | EFI_STATUS | |
675 | EFIAPI | |
676 | ProcessModuleEntryPointList ( | |
677 | IN EFI_HANDLE ImageHandle, | |
678 | IN EFI_SYSTEM_TABLE *SystemTable | |
679 | ) | |
680 | ||
681 | { | |
682 | return ${Function} (ImageHandle, SystemTable); | |
683 | } | |
684 | ${END} | |
685 | VOID | |
686 | EFIAPI | |
687 | ExitDriver ( | |
688 | IN EFI_STATUS Status | |
689 | ) | |
690 | { | |
691 | if (EFI_ERROR (Status)) { | |
692 | ProcessLibraryDestructorList (gImageHandle, gST); | |
693 | } | |
694 | gBS->Exit (gImageHandle, Status, 0, NULL); | |
695 | } | |
696 | """), | |
697 | TemplateString(""" | |
52302d4d | 698 | const UINT32 _gUefiDriverRevision = ${UefiSpecVersion}; |
30fdf114 LG |
699 | |
700 | EFI_STATUS | |
701 | EFIAPI | |
702 | ProcessModuleEntryPointList ( | |
703 | IN EFI_HANDLE ImageHandle, | |
704 | IN EFI_SYSTEM_TABLE *SystemTable | |
705 | ) | |
706 | ||
707 | { | |
708 | ${BEGIN} | |
709 | if (SetJump (&mJumpContext) == 0) { | |
710 | ExitDriver (${Function} (ImageHandle, SystemTable)); | |
711 | ASSERT (FALSE); | |
712 | } | |
713 | ${END} | |
714 | return mDriverEntryPointStatus; | |
715 | } | |
716 | ||
717 | static BASE_LIBRARY_JUMP_BUFFER mJumpContext; | |
718 | static EFI_STATUS mDriverEntryPointStatus = EFI_LOAD_ERROR; | |
719 | ||
720 | VOID | |
721 | EFIAPI | |
722 | ExitDriver ( | |
723 | IN EFI_STATUS Status | |
724 | ) | |
725 | { | |
726 | if (!EFI_ERROR (Status) || EFI_ERROR (mDriverEntryPointStatus)) { | |
727 | mDriverEntryPointStatus = Status; | |
728 | } | |
729 | LongJump (&mJumpContext, (UINTN)-1); | |
730 | ASSERT (FALSE); | |
731 | } | |
732 | """) | |
733 | ] | |
734 | ||
735 | ## UEFI Unload Image Templates | |
736 | gUefiUnloadImagePrototype = TemplateString(""" | |
737 | ${BEGIN} | |
738 | EFI_STATUS | |
739 | EFIAPI | |
740 | ${Function} ( | |
741 | IN EFI_HANDLE ImageHandle | |
742 | ); | |
743 | ${END} | |
744 | """) | |
745 | ||
746 | gUefiUnloadImageString = [ | |
747 | TemplateString(""" | |
748 | GLOBAL_REMOVE_IF_UNREFERENCED const UINT8 _gDriverUnloadImageCount = ${Count}; | |
749 | ||
750 | EFI_STATUS | |
751 | EFIAPI | |
752 | ProcessModuleUnloadList ( | |
753 | IN EFI_HANDLE ImageHandle | |
754 | ) | |
755 | { | |
756 | return EFI_SUCCESS; | |
757 | } | |
758 | """), | |
759 | TemplateString(""" | |
760 | GLOBAL_REMOVE_IF_UNREFERENCED const UINT8 _gDriverUnloadImageCount = ${Count}; | |
761 | ||
762 | ${BEGIN} | |
763 | EFI_STATUS | |
764 | EFIAPI | |
765 | ProcessModuleUnloadList ( | |
766 | IN EFI_HANDLE ImageHandle | |
767 | ) | |
768 | { | |
769 | return ${Function} (ImageHandle); | |
770 | } | |
771 | ${END} | |
772 | """), | |
773 | TemplateString(""" | |
774 | GLOBAL_REMOVE_IF_UNREFERENCED const UINT8 _gDriverUnloadImageCount = ${Count}; | |
775 | ||
776 | EFI_STATUS | |
777 | EFIAPI | |
778 | ProcessModuleUnloadList ( | |
779 | IN EFI_HANDLE ImageHandle | |
780 | ) | |
781 | { | |
782 | EFI_STATUS Status; | |
783 | ||
784 | Status = EFI_SUCCESS; | |
785 | ${BEGIN} | |
786 | if (EFI_ERROR (Status)) { | |
787 | ${Function} (ImageHandle); | |
788 | } else { | |
789 | Status = ${Function} (ImageHandle); | |
790 | } | |
791 | ${END} | |
792 | return Status; | |
793 | } | |
794 | """) | |
795 | ] | |
796 | ||
797 | gLibraryStructorPrototype = { | |
798 | 'BASE' : TemplateString("""${BEGIN} | |
799 | RETURN_STATUS | |
800 | EFIAPI | |
801 | ${Function} ( | |
802 | VOID | |
803 | );${END} | |
804 | """), | |
805 | ||
806 | 'PEI' : TemplateString("""${BEGIN} | |
807 | EFI_STATUS | |
808 | EFIAPI | |
809 | ${Function} ( | |
810 | IN EFI_PEI_FILE_HANDLE FileHandle, | |
811 | IN CONST EFI_PEI_SERVICES **PeiServices | |
812 | );${END} | |
813 | """), | |
814 | ||
815 | 'DXE' : TemplateString("""${BEGIN} | |
816 | EFI_STATUS | |
817 | EFIAPI | |
818 | ${Function} ( | |
819 | IN EFI_HANDLE ImageHandle, | |
820 | IN EFI_SYSTEM_TABLE *SystemTable | |
821 | );${END} | |
822 | """), | |
823 | } | |
824 | ||
825 | gLibraryStructorCall = { | |
826 | 'BASE' : TemplateString("""${BEGIN} | |
827 | Status = ${Function} (); | |
828 | ASSERT_EFI_ERROR (Status);${END} | |
829 | """), | |
830 | ||
831 | 'PEI' : TemplateString("""${BEGIN} | |
832 | Status = ${Function} (FileHandle, PeiServices); | |
833 | ASSERT_EFI_ERROR (Status);${END} | |
834 | """), | |
835 | ||
836 | 'DXE' : TemplateString("""${BEGIN} | |
837 | Status = ${Function} (ImageHandle, SystemTable); | |
838 | ASSERT_EFI_ERROR (Status);${END} | |
839 | """), | |
840 | } | |
841 | ||
842 | ## Library Constructor and Destructor Templates | |
843 | gLibraryString = { | |
844 | 'BASE' : TemplateString(""" | |
845 | ${BEGIN}${FunctionPrototype}${END} | |
846 | ||
847 | VOID | |
848 | EFIAPI | |
849 | ProcessLibrary${Type}List ( | |
850 | VOID | |
851 | ) | |
852 | { | |
853 | ${BEGIN} EFI_STATUS Status; | |
854 | ${FunctionCall}${END} | |
855 | } | |
856 | """), | |
857 | ||
858 | 'PEI' : TemplateString(""" | |
859 | ${BEGIN}${FunctionPrototype}${END} | |
860 | ||
861 | VOID | |
862 | EFIAPI | |
863 | ProcessLibrary${Type}List ( | |
864 | IN EFI_PEI_FILE_HANDLE FileHandle, | |
865 | IN CONST EFI_PEI_SERVICES **PeiServices | |
866 | ) | |
867 | { | |
868 | ${BEGIN} EFI_STATUS Status; | |
869 | ${FunctionCall}${END} | |
870 | } | |
871 | """), | |
872 | ||
873 | 'DXE' : TemplateString(""" | |
874 | ${BEGIN}${FunctionPrototype}${END} | |
875 | ||
876 | VOID | |
877 | EFIAPI | |
878 | ProcessLibrary${Type}List ( | |
879 | IN EFI_HANDLE ImageHandle, | |
880 | IN EFI_SYSTEM_TABLE *SystemTable | |
881 | ) | |
882 | { | |
883 | ${BEGIN} EFI_STATUS Status; | |
884 | ${FunctionCall}${END} | |
885 | } | |
886 | """), | |
887 | } | |
888 | ||
30fdf114 LG |
889 | gBasicHeaderFile = "Base.h" |
890 | ||
891 | gModuleTypeHeaderFile = { | |
892 | "BASE" : [gBasicHeaderFile], | |
893 | "SEC" : ["PiPei.h", "Library/DebugLib.h"], | |
894 | "PEI_CORE" : ["PiPei.h", "Library/DebugLib.h", "Library/PeiCoreEntryPoint.h"], | |
895 | "PEIM" : ["PiPei.h", "Library/DebugLib.h", "Library/PeimEntryPoint.h"], | |
896 | "DXE_CORE" : ["PiDxe.h", "Library/DebugLib.h", "Library/DxeCoreEntryPoint.h"], | |
897 | "DXE_DRIVER" : ["PiDxe.h", "Library/BaseLib.h", "Library/DebugLib.h", "Library/UefiBootServicesTableLib.h", "Library/UefiDriverEntryPoint.h"], | |
898 | "DXE_SMM_DRIVER" : ["PiDxe.h", "Library/BaseLib.h", "Library/DebugLib.h", "Library/UefiBootServicesTableLib.h", "Library/UefiDriverEntryPoint.h"], | |
899 | "DXE_RUNTIME_DRIVER": ["PiDxe.h", "Library/BaseLib.h", "Library/DebugLib.h", "Library/UefiBootServicesTableLib.h", "Library/UefiDriverEntryPoint.h"], | |
900 | "DXE_SAL_DRIVER" : ["PiDxe.h", "Library/BaseLib.h", "Library/DebugLib.h", "Library/UefiBootServicesTableLib.h", "Library/UefiDriverEntryPoint.h"], | |
901 | "UEFI_DRIVER" : ["Uefi.h", "Library/BaseLib.h", "Library/DebugLib.h", "Library/UefiBootServicesTableLib.h", "Library/UefiDriverEntryPoint.h"], | |
902 | "UEFI_APPLICATION" : ["Uefi.h", "Library/BaseLib.h", "Library/DebugLib.h", "Library/UefiBootServicesTableLib.h", "Library/UefiApplicationEntryPoint.h"], | |
b303ea72 | 903 | "SMM_CORE" : ["PiDxe.h", "Library/BaseLib.h", "Library/DebugLib.h", "Library/UefiDriverEntryPoint.h"], |
30fdf114 LG |
904 | "USER_DEFINED" : [gBasicHeaderFile] |
905 | } | |
906 | ||
907 | ## Create code for module PCDs | |
908 | # | |
909 | # @param Info The ModuleAutoGen object | |
910 | # @param AutoGenC The TemplateString object for C code | |
911 | # @param AutoGenH The TemplateString object for header file | |
912 | # @param Pcd The PCD object | |
913 | # | |
914 | def CreateModulePcdCode(Info, AutoGenC, AutoGenH, Pcd): | |
915 | TokenSpaceGuidValue = Pcd.TokenSpaceGuidValue #Info.GuidList[Pcd.TokenSpaceGuidCName] | |
916 | PcdTokenNumber = Info.PlatformInfo.PcdTokenNumber | |
917 | # | |
918 | # Write PCDs | |
919 | # | |
920 | PcdTokenName = '_PCD_TOKEN_' + Pcd.TokenCName | |
921 | if Pcd.Type in gDynamicExPcd: | |
922 | TokenNumber = int(Pcd.TokenValue, 0) | |
923 | else: | |
924 | if (Pcd.TokenCName, Pcd.TokenSpaceGuidCName) not in PcdTokenNumber: | |
925 | EdkLogger.error("build", AUTOGEN_ERROR, | |
926 | "No generated token number for %s.%s\n" % (Pcd.TokenSpaceGuidCName, Pcd.TokenCName), | |
927 | ExtraData="[%s]" % str(Info)) | |
928 | TokenNumber = PcdTokenNumber[Pcd.TokenCName, Pcd.TokenSpaceGuidCName] | |
d40b2ee6 | 929 | AutoGenH.Append('\n#define %s %dU\n' % (PcdTokenName, TokenNumber)) |
30fdf114 LG |
930 | |
931 | EdkLogger.debug(EdkLogger.DEBUG_3, "Creating code for " + Pcd.TokenCName + "." + Pcd.TokenSpaceGuidCName) | |
932 | if Pcd.Type not in gItemTypeStringDatabase: | |
933 | EdkLogger.error("build", AUTOGEN_ERROR, | |
934 | "Unknown PCD type [%s] of PCD %s.%s" % (Pcd.Type, Pcd.TokenSpaceGuidCName, Pcd.TokenCName), | |
935 | ExtraData="[%s]" % str(Info)) | |
936 | if Pcd.DatumType not in gDatumSizeStringDatabase: | |
937 | EdkLogger.error("build", AUTOGEN_ERROR, | |
938 | "Unknown datum type [%s] of PCD %s.%s" % (Pcd.DatumType, Pcd.TokenSpaceGuidCName, Pcd.TokenCName), | |
939 | ExtraData="[%s]" % str(Info)) | |
940 | ||
941 | DatumSize = gDatumSizeStringDatabase[Pcd.DatumType] | |
942 | DatumSizeLib = gDatumSizeStringDatabaseLib[Pcd.DatumType] | |
943 | GetModeName = '_PCD_GET_MODE_' + gDatumSizeStringDatabaseH[Pcd.DatumType] + '_' + Pcd.TokenCName | |
944 | SetModeName = '_PCD_SET_MODE_' + gDatumSizeStringDatabaseH[Pcd.DatumType] + '_' + Pcd.TokenCName | |
945 | ||
946 | if Pcd.Type in gDynamicExPcd: | |
947 | AutoGenH.Append('#define %s LibPcdGetEx%s(&%s, %s)\n' % (GetModeName, DatumSizeLib, Pcd.TokenSpaceGuidCName, PcdTokenName)) | |
948 | if Pcd.DatumType == 'VOID*': | |
949 | AutoGenH.Append('#define %s(SizeOfBuffer, Buffer) LibPcdSetEx%s(&%s, %s, (SizeOfBuffer), (Buffer))\n' % (SetModeName, DatumSizeLib, Pcd.TokenSpaceGuidCName, PcdTokenName)) | |
950 | else: | |
951 | AutoGenH.Append('#define %s(Value) LibPcdSetEx%s(&%s, %s, (Value))\n' % (SetModeName, DatumSizeLib, Pcd.TokenSpaceGuidCName, PcdTokenName)) | |
952 | elif Pcd.Type in gDynamicPcd: | |
953 | AutoGenH.Append('#define %s LibPcdGet%s(%s)\n' % (GetModeName, DatumSizeLib, PcdTokenName)) | |
954 | if Pcd.DatumType == 'VOID*': | |
955 | AutoGenH.Append('#define %s(SizeOfBuffer, Buffer) LibPcdSet%s(%s, (SizeOfBuffer), (Buffer))\n' %(SetModeName, DatumSizeLib, PcdTokenName)) | |
956 | else: | |
957 | AutoGenH.Append('#define %s(Value) LibPcdSet%s(%s, (Value))\n' % (SetModeName, DatumSizeLib, PcdTokenName)) | |
958 | else: | |
959 | PcdVariableName = '_gPcd_' + gItemTypeStringDatabase[Pcd.Type] + '_' + Pcd.TokenCName | |
960 | Const = 'const' | |
961 | if Pcd.Type == TAB_PCDS_PATCHABLE_IN_MODULE: | |
962 | Const = '' | |
963 | Type = '' | |
964 | Array = '' | |
52302d4d | 965 | Value = Pcd.DefaultValue |
30fdf114 | 966 | Unicode = False |
52302d4d | 967 | ValueNumber = 0 |
0d2711a6 LG |
968 | |
969 | if Pcd.DatumType == 'BOOLEAN': | |
970 | BoolValue = Value.upper() | |
971 | if BoolValue == 'TRUE': | |
d40b2ee6 | 972 | Value = '1U' |
0d2711a6 | 973 | elif BoolValue == 'FALSE': |
d40b2ee6 | 974 | Value = '0U' |
0d2711a6 | 975 | |
52302d4d LG |
976 | if Pcd.DatumType in ['UINT64', 'UINT32', 'UINT16', 'UINT8']: |
977 | try: | |
978 | if Value.upper().startswith('0X'): | |
979 | ValueNumber = int (Value, 16) | |
980 | else: | |
981 | ValueNumber = int (Value) | |
982 | except: | |
983 | EdkLogger.error("build", AUTOGEN_ERROR, | |
984 | "PCD value is not valid dec or hex number for datum type [%s] of PCD %s.%s" % (Pcd.DatumType, Pcd.TokenSpaceGuidCName, Pcd.TokenCName), | |
985 | ExtraData="[%s]" % str(Info)) | |
986 | if Pcd.DatumType == 'UINT64': | |
987 | if ValueNumber < 0: | |
988 | EdkLogger.error("build", AUTOGEN_ERROR, | |
989 | "PCD can't be set to negative value for datum type [%s] of PCD %s.%s" % (Pcd.DatumType, Pcd.TokenSpaceGuidCName, Pcd.TokenCName), | |
990 | ExtraData="[%s]" % str(Info)) | |
991 | elif ValueNumber >= 0x10000000000000000: | |
992 | EdkLogger.error("build", AUTOGEN_ERROR, | |
993 | "Too large PCD value for datum type [%s] of PCD %s.%s" % (Pcd.DatumType, Pcd.TokenSpaceGuidCName, Pcd.TokenCName), | |
994 | ExtraData="[%s]" % str(Info)) | |
995 | if not Value.endswith('ULL'): | |
996 | Value += 'ULL' | |
997 | elif Pcd.DatumType == 'UINT32': | |
998 | if ValueNumber < 0: | |
999 | EdkLogger.error("build", AUTOGEN_ERROR, | |
1000 | "PCD can't be set to negative value for datum type [%s] of PCD %s.%s" % (Pcd.DatumType, Pcd.TokenSpaceGuidCName, Pcd.TokenCName), | |
1001 | ExtraData="[%s]" % str(Info)) | |
1002 | elif ValueNumber >= 0x100000000: | |
1003 | EdkLogger.error("build", AUTOGEN_ERROR, | |
1004 | "Too large PCD value for datum type [%s] of PCD %s.%s" % (Pcd.DatumType, Pcd.TokenSpaceGuidCName, Pcd.TokenCName), | |
1005 | ExtraData="[%s]" % str(Info)) | |
d40b2ee6 LG |
1006 | if not Value.endswith('U'): |
1007 | Value += 'U' | |
52302d4d LG |
1008 | elif Pcd.DatumType == 'UINT16': |
1009 | if ValueNumber < 0: | |
1010 | EdkLogger.error("build", AUTOGEN_ERROR, | |
1011 | "PCD can't be set to negative value for datum type [%s] of PCD %s.%s" % (Pcd.DatumType, Pcd.TokenSpaceGuidCName, Pcd.TokenCName), | |
1012 | ExtraData="[%s]" % str(Info)) | |
1013 | elif ValueNumber >= 0x10000: | |
1014 | EdkLogger.error("build", AUTOGEN_ERROR, | |
1015 | "Too large PCD value for datum type [%s] of PCD %s.%s" % (Pcd.DatumType, Pcd.TokenSpaceGuidCName, Pcd.TokenCName), | |
1016 | ExtraData="[%s]" % str(Info)) | |
d40b2ee6 LG |
1017 | if not Value.endswith('U'): |
1018 | Value += 'U' | |
52302d4d LG |
1019 | elif Pcd.DatumType == 'UINT8': |
1020 | if ValueNumber < 0: | |
1021 | EdkLogger.error("build", AUTOGEN_ERROR, | |
1022 | "PCD can't be set to negative value for datum type [%s] of PCD %s.%s" % (Pcd.DatumType, Pcd.TokenSpaceGuidCName, Pcd.TokenCName), | |
1023 | ExtraData="[%s]" % str(Info)) | |
1024 | elif ValueNumber >= 0x100: | |
1025 | EdkLogger.error("build", AUTOGEN_ERROR, | |
1026 | "Too large PCD value for datum type [%s] of PCD %s.%s" % (Pcd.DatumType, Pcd.TokenSpaceGuidCName, Pcd.TokenCName), | |
1027 | ExtraData="[%s]" % str(Info)) | |
d40b2ee6 LG |
1028 | if not Value.endswith('U'): |
1029 | Value += 'U' | |
30fdf114 LG |
1030 | if Pcd.DatumType == 'VOID*': |
1031 | if Pcd.MaxDatumSize == None or Pcd.MaxDatumSize == '': | |
1032 | EdkLogger.error("build", AUTOGEN_ERROR, | |
1033 | "Unknown [MaxDatumSize] of PCD [%s.%s]" % (Pcd.TokenSpaceGuidCName, Pcd.TokenCName), | |
1034 | ExtraData="[%s]" % str(Info)) | |
1035 | ||
1036 | ArraySize = int(Pcd.MaxDatumSize, 0) | |
1037 | if Value[0] == '{': | |
1038 | Type = '(VOID *)' | |
52302d4d | 1039 | else: |
30fdf114 LG |
1040 | if Value[0] == 'L': |
1041 | Unicode = True | |
1042 | Value = Value.lstrip('L') #.strip('"') | |
1043 | Value = eval(Value) # translate escape character | |
1044 | NewValue = '{' | |
1045 | for Index in range(0,len(Value)): | |
1046 | if Unicode: | |
52302d4d LG |
1047 | NewValue = NewValue + str(ord(Value[Index]) % 0x10000) + ', ' |
1048 | else: | |
30fdf114 | 1049 | NewValue = NewValue + str(ord(Value[Index]) % 0x100) + ', ' |
52302d4d LG |
1050 | if Unicode: |
1051 | ArraySize = ArraySize / 2; | |
1052 | ||
30fdf114 | 1053 | if ArraySize < (len(Value) + 1): |
e56468c0 | 1054 | EdkLogger.error("build", AUTOGEN_ERROR, |
1055 | "The maximum size of VOID* type PCD '%s.%s' is less than its actual size occupied." % (Pcd.TokenSpaceGuidCName, Pcd.TokenCName), | |
1056 | ExtraData="[%s]" % str(Info)) | |
52302d4d | 1057 | Value = NewValue + '0 }' |
30fdf114 LG |
1058 | Array = '[%d]' % ArraySize |
1059 | # | |
1060 | # skip casting for fixed at build since it breaks ARM assembly. | |
1061 | # Long term we need PCD macros that work in assembly | |
1062 | # | |
1063 | elif Pcd.Type != TAB_PCDS_FIXED_AT_BUILD: | |
1064 | Value = "((%s)%s)" % (Pcd.DatumType, Value) | |
1065 | ||
1066 | if Pcd.Type == TAB_PCDS_PATCHABLE_IN_MODULE: | |
1067 | PcdValueName = '_PCD_PATCHABLE_VALUE_' + Pcd.TokenCName | |
1068 | else: | |
1069 | PcdValueName = '_PCD_VALUE_' + Pcd.TokenCName | |
1070 | ||
52302d4d LG |
1071 | if Pcd.DatumType == 'VOID*': |
1072 | # | |
1073 | # For unicode, UINT16 array will be generated, so the alignment of unicode is guaranteed. | |
1074 | # | |
1075 | if Unicode: | |
1076 | AutoGenH.Append('#define _PCD_PATCHABLE_%s_SIZE %s\n' % (Pcd.TokenCName, Pcd.MaxDatumSize)) | |
1077 | AutoGenH.Append('#define %s %s%s\n' %(PcdValueName, Type, PcdVariableName)) | |
1078 | AutoGenC.Append('GLOBAL_REMOVE_IF_UNREFERENCED %s UINT16 %s%s = %s;\n' % (Const, PcdVariableName, Array, Value)) | |
1079 | AutoGenH.Append('extern %s UINT16 %s%s;\n' %(Const, PcdVariableName, Array)) | |
1080 | AutoGenH.Append('#define %s %s%s\n' %(GetModeName, Type, PcdVariableName)) | |
30fdf114 LG |
1081 | else: |
1082 | AutoGenH.Append('#define _PCD_PATCHABLE_%s_SIZE %s\n' % (Pcd.TokenCName, Pcd.MaxDatumSize)) | |
1083 | AutoGenH.Append('#define %s %s%s\n' %(PcdValueName, Type, PcdVariableName)) | |
1084 | AutoGenC.Append('GLOBAL_REMOVE_IF_UNREFERENCED %s UINT8 %s%s = %s;\n' % (Const, PcdVariableName, Array, Value)) | |
1085 | AutoGenH.Append('extern %s UINT8 %s%s;\n' %(Const, PcdVariableName, Array)) | |
1086 | AutoGenH.Append('#define %s %s%s\n' %(GetModeName, Type, PcdVariableName)) | |
1087 | elif Pcd.Type == TAB_PCDS_PATCHABLE_IN_MODULE: | |
1088 | AutoGenH.Append('#define %s %s\n' %(PcdValueName, Value)) | |
52302d4d | 1089 | AutoGenC.Append('volatile %s %s %s = %s;\n' %(Const, Pcd.DatumType, PcdVariableName, PcdValueName)) |
30fdf114 LG |
1090 | AutoGenH.Append('extern volatile %s %s %s%s;\n' % (Const, Pcd.DatumType, PcdVariableName, Array)) |
1091 | AutoGenH.Append('#define %s %s%s\n' % (GetModeName, Type, PcdVariableName)) | |
1092 | else: | |
1093 | AutoGenH.Append('#define %s %s\n' %(PcdValueName, Value)) | |
1094 | AutoGenC.Append('GLOBAL_REMOVE_IF_UNREFERENCED %s %s %s = %s;\n' %(Const, Pcd.DatumType, PcdVariableName, PcdValueName)) | |
1095 | AutoGenH.Append('extern %s %s %s%s;\n' % (Const, Pcd.DatumType, PcdVariableName, Array)) | |
1096 | AutoGenH.Append('#define %s %s%s\n' % (GetModeName, Type, PcdVariableName)) | |
1097 | ||
1098 | if Pcd.Type == TAB_PCDS_PATCHABLE_IN_MODULE: | |
1099 | if Pcd.DatumType == 'VOID*': | |
1100 | AutoGenH.Append('#define %s(SizeOfBuffer, Buffer) LibPatchPcdSetPtr(_gPcd_BinaryPatch_%s, (UINTN)_PCD_PATCHABLE_%s_SIZE, (SizeOfBuffer), (Buffer))\n' % (SetModeName, Pcd.TokenCName, Pcd.TokenCName)) | |
1101 | else: | |
1102 | AutoGenH.Append('#define %s(Value) (%s = (Value))\n' % (SetModeName, PcdVariableName)) | |
1103 | else: | |
1104 | AutoGenH.Append('//#define %s ASSERT(FALSE) // It is not allowed to set value for a FIXED_AT_BUILD PCD\n' % SetModeName) | |
1105 | ||
1106 | ## Create code for library module PCDs | |
1107 | # | |
1108 | # @param Info The ModuleAutoGen object | |
1109 | # @param AutoGenC The TemplateString object for C code | |
1110 | # @param AutoGenH The TemplateString object for header file | |
1111 | # @param Pcd The PCD object | |
1112 | # | |
1113 | def CreateLibraryPcdCode(Info, AutoGenC, AutoGenH, Pcd): | |
1114 | PcdTokenNumber = Info.PlatformInfo.PcdTokenNumber | |
1115 | TokenSpaceGuidCName = Pcd.TokenSpaceGuidCName | |
1116 | TokenCName = Pcd.TokenCName | |
1117 | TokenSpaceGuidValue = Pcd.TokenSpaceGuidValue #Info.GuidList[TokenSpaceGuidCName] | |
1118 | if (Pcd.TokenCName, Pcd.TokenSpaceGuidCName) not in PcdTokenNumber: | |
1119 | EdkLogger.error("build", AUTOGEN_ERROR, | |
1120 | "No generated token number for %s.%s\n" % (Pcd.TokenSpaceGuidCName, Pcd.TokenCName), | |
1121 | ExtraData="[%s]" % str(Info)) | |
1122 | TokenNumber = PcdTokenNumber[TokenCName, TokenSpaceGuidCName] | |
1123 | ||
da92f276 LG |
1124 | # If PCD is DynamicEx, then use TokenNumber declared in DEC file |
1125 | if Pcd.Type in gDynamicExPcd: | |
1126 | TokenNumber = int(Pcd.TokenValue, 0) | |
1127 | ||
30fdf114 LG |
1128 | if Pcd.Type not in gItemTypeStringDatabase: |
1129 | EdkLogger.error("build", AUTOGEN_ERROR, | |
1130 | "Unknown PCD type [%s] of PCD %s.%s" % (Pcd.Type, Pcd.TokenSpaceGuidCName, Pcd.TokenCName), | |
1131 | ExtraData="[%s]" % str(Info)) | |
1132 | if Pcd.DatumType not in gDatumSizeStringDatabase: | |
1133 | EdkLogger.error("build", AUTOGEN_ERROR, | |
1134 | "Unknown datum type [%s] of PCD %s.%s" % (Pcd.DatumType, Pcd.TokenSpaceGuidCName, Pcd.TokenCName), | |
1135 | ExtraData="[%s]" % str(Info)) | |
1136 | ||
1137 | DatumType = Pcd.DatumType | |
1138 | DatumSize = gDatumSizeStringDatabaseH[DatumType] | |
1139 | DatumSizeLib= gDatumSizeStringDatabaseLib[DatumType] | |
1140 | GetModeName = '_PCD_GET_MODE_' + DatumSize + '_' + TokenCName | |
1141 | SetModeName = '_PCD_SET_MODE_' + DatumSize + '_' + TokenCName | |
1142 | ||
1143 | Type = '' | |
1144 | Array = '' | |
1145 | if Pcd.DatumType == 'VOID*': | |
1146 | Type = '(VOID *)' | |
1147 | Array = '[]' | |
1148 | ||
d40b2ee6 | 1149 | AutoGenH.Append('#define _PCD_TOKEN_%s %dU\n' % (TokenCName, TokenNumber)) |
30fdf114 LG |
1150 | |
1151 | PcdItemType = Pcd.Type | |
1152 | #if PcdItemType in gDynamicPcd: | |
1153 | # PcdItemType = TAB_PCDS_FIXED_AT_BUILD | |
1154 | # if (TokenCName, TokenSpaceGuidCName) in Info.PlatformInfo.Platform.Pcds: | |
1155 | # PcdItemType = Info.PlatformInfo.Platform.Pcds[TokenCName, TokenSpaceGuidCName].Type | |
1156 | if PcdItemType in gDynamicExPcd: | |
1157 | PcdTokenName = '_PCD_TOKEN_' + TokenCName | |
1158 | AutoGenH.Append('#define %s LibPcdGetEx%s(&%s, %s)\n' % (GetModeName, DatumSizeLib, TokenSpaceGuidCName, PcdTokenName)) | |
1159 | if DatumType == 'VOID*': | |
1160 | AutoGenH.Append('#define %s(SizeOfBuffer, Buffer) LibPcdSetEx%s(&%s, %s, (SizeOfBuffer), (Buffer))\n' % (SetModeName,DatumSizeLib, TokenSpaceGuidCName, PcdTokenName)) | |
1161 | else: | |
1162 | AutoGenH.Append('#define %s(Value) LibPcdSetEx%s(&%s, %s, (Value))\n' % (SetModeName, DatumSizeLib, TokenSpaceGuidCName, PcdTokenName)) | |
1163 | if PcdItemType in gDynamicPcd: | |
1164 | PcdTokenName = '_PCD_TOKEN_' + TokenCName | |
1165 | AutoGenH.Append('#define %s LibPcdGet%s(%s)\n' % (GetModeName, DatumSizeLib, PcdTokenName)) | |
1166 | if DatumType == 'VOID*': | |
1167 | AutoGenH.Append('#define %s(SizeOfBuffer, Buffer) LibPcdSet%s(%s, (SizeOfBuffer), (Buffer))\n' %(SetModeName, DatumSizeLib, PcdTokenName)) | |
1168 | else: | |
1169 | AutoGenH.Append('#define %s(Value) LibPcdSet%s(%s, (Value))\n' % (SetModeName, DatumSizeLib, PcdTokenName)) | |
1170 | if PcdItemType == TAB_PCDS_PATCHABLE_IN_MODULE: | |
1171 | PcdVariableName = '_gPcd_' + gItemTypeStringDatabase[TAB_PCDS_PATCHABLE_IN_MODULE] + '_' + TokenCName | |
1172 | AutoGenH.Append('extern %s _gPcd_BinaryPatch_%s%s;\n' %(DatumType, TokenCName, Array) ) | |
1173 | AutoGenH.Append('#define %s %s_gPcd_BinaryPatch_%s\n' %(GetModeName, Type, TokenCName)) | |
1174 | AutoGenH.Append('#define %s(Value) (%s = (Value))\n' % (SetModeName, PcdVariableName)) | |
1175 | if PcdItemType == TAB_PCDS_FIXED_AT_BUILD or PcdItemType == TAB_PCDS_FEATURE_FLAG: | |
1176 | AutoGenH.Append('extern const %s _gPcd_FixedAtBuild_%s%s;\n' %(DatumType, TokenCName, Array)) | |
1177 | #AutoGenH.Append('#define _PCD_VALUE_%s _gPcd_FixedAtBuild_%s\n' %(TokenCName, TokenCName)) | |
1178 | AutoGenH.Append('#define %s %s_gPcd_FixedAtBuild_%s\n' %(GetModeName, Type, TokenCName)) | |
1179 | AutoGenH.Append('//#define %s ASSERT(FALSE) // It is not allowed to set value for a FIXED_AT_BUILD PCD\n' % SetModeName) | |
1180 | ||
1181 | ## Create code for PCD database in DXE or PEI phase | |
1182 | # | |
1183 | # @param Platform The platform object | |
1184 | # @retval tuple Two TemplateString objects for C code and header file, | |
1185 | # respectively | |
1186 | # | |
1187 | def CreatePcdDatabasePhaseSpecificAutoGen (Platform, Phase): | |
1188 | AutoGenC = TemplateString() | |
1189 | AutoGenH = TemplateString() | |
1190 | ||
1191 | Dict = { | |
1192 | 'PHASE' : Phase, | |
1193 | 'GUID_TABLE_SIZE' : '1', | |
1194 | 'STRING_TABLE_SIZE' : '1', | |
1195 | 'SKUID_TABLE_SIZE' : '1', | |
1196 | 'LOCAL_TOKEN_NUMBER_TABLE_SIZE' : '1', | |
1197 | 'LOCAL_TOKEN_NUMBER' : '0', | |
1198 | 'EXMAPPING_TABLE_SIZE' : '1', | |
1199 | 'EX_TOKEN_NUMBER' : '0', | |
1200 | 'SIZE_TABLE_SIZE' : '2', | |
1201 | 'GUID_TABLE_EMPTY' : 'TRUE', | |
1202 | 'STRING_TABLE_EMPTY' : 'TRUE', | |
1203 | 'SKUID_TABLE_EMPTY' : 'TRUE', | |
1204 | 'DATABASE_EMPTY' : 'TRUE', | |
1205 | 'EXMAP_TABLE_EMPTY' : 'TRUE', | |
1206 | 'PCD_DATABASE_UNINIT_EMPTY' : ' UINT8 dummy; /* PCD_DATABASE_UNINIT is emptry */', | |
1207 | 'SYSTEM_SKU_ID' : ' SKU_ID SystemSkuId;', | |
1208 | 'SYSTEM_SKU_ID_VALUE' : '0' | |
1209 | } | |
1210 | ||
52302d4d | 1211 | for DatumType in ['UINT64','UINT32','UINT16','UINT8','BOOLEAN', "VOID*"]: |
30fdf114 LG |
1212 | Dict['VARDEF_CNAME_' + DatumType] = [] |
1213 | Dict['VARDEF_GUID_' + DatumType] = [] | |
1214 | Dict['VARDEF_SKUID_' + DatumType] = [] | |
1215 | Dict['VARDEF_VALUE_' + DatumType] = [] | |
1216 | for Init in ['INIT','UNINIT']: | |
1217 | Dict[Init+'_CNAME_DECL_' + DatumType] = [] | |
1218 | Dict[Init+'_GUID_DECL_' + DatumType] = [] | |
1219 | Dict[Init+'_NUMSKUS_DECL_' + DatumType] = [] | |
1220 | Dict[Init+'_VALUE_' + DatumType] = [] | |
1221 | ||
1222 | for Type in ['STRING_HEAD','VPD_HEAD','VARIABLE_HEAD']: | |
1223 | Dict[Type + '_CNAME_DECL'] = [] | |
1224 | Dict[Type + '_GUID_DECL'] = [] | |
1225 | Dict[Type + '_NUMSKUS_DECL'] = [] | |
1226 | Dict[Type + '_VALUE'] = [] | |
1227 | ||
1228 | Dict['STRING_TABLE_INDEX'] = [] | |
1229 | Dict['STRING_TABLE_LENGTH'] = [] | |
1230 | Dict['STRING_TABLE_CNAME'] = [] | |
1231 | Dict['STRING_TABLE_GUID'] = [] | |
1232 | Dict['STRING_TABLE_VALUE'] = [] | |
1233 | ||
1234 | Dict['SIZE_TABLE_CNAME'] = [] | |
1235 | Dict['SIZE_TABLE_GUID'] = [] | |
1236 | Dict['SIZE_TABLE_CURRENT_LENGTH'] = [] | |
1237 | Dict['SIZE_TABLE_MAXIMUM_LENGTH'] = [] | |
1238 | ||
1239 | Dict['EXMAPPING_TABLE_EXTOKEN'] = [] | |
1240 | Dict['EXMAPPING_TABLE_LOCAL_TOKEN'] = [] | |
1241 | Dict['EXMAPPING_TABLE_GUID_INDEX'] = [] | |
1242 | ||
1243 | Dict['GUID_STRUCTURE'] = [] | |
1244 | ||
1245 | Dict['SKUID_VALUE'] = [] | |
52302d4d | 1246 | Dict['VARDEF_HEADER'] = [] |
30fdf114 LG |
1247 | if Phase == 'DXE': |
1248 | Dict['SYSTEM_SKU_ID'] = '' | |
1249 | Dict['SYSTEM_SKU_ID_VALUE'] = '' | |
1250 | ||
1251 | StringTableIndex = 0 | |
1252 | StringTableSize = 0 | |
1253 | NumberOfLocalTokens = 0 | |
1254 | NumberOfPeiLocalTokens = 0 | |
1255 | NumberOfDxeLocalTokens = 0 | |
1256 | NumberOfExTokens = 0 | |
1257 | NumberOfSizeItems = 0 | |
1258 | GuidList = [] | |
9053bc51 | 1259 | |
30fdf114 LG |
1260 | for Pcd in Platform.DynamicPcdList: |
1261 | CName = Pcd.TokenCName | |
1262 | TokenSpaceGuidCName = Pcd.TokenSpaceGuidCName | |
1263 | ||
1264 | EdkLogger.debug(EdkLogger.DEBUG_3, "PCD: %s %s (%s : %s)" % (CName, TokenSpaceGuidCName, Pcd.Phase, Phase)) | |
1265 | if Pcd.DatumType not in gDatumSizeStringDatabase: | |
1266 | EdkLogger.error("build", AUTOGEN_ERROR, | |
1267 | "Unknown datum type [%s] of PCD %s.%s" % (Pcd.DatumType, Pcd.TokenSpaceGuidCName, Pcd.TokenCName), | |
1268 | ExtraData="[%s]" % str(Platform)) | |
1269 | ||
1270 | if Pcd.Phase == 'PEI': | |
1271 | NumberOfPeiLocalTokens += 1 | |
1272 | if Pcd.Phase == 'DXE': | |
1273 | NumberOfDxeLocalTokens += 1 | |
1274 | if Pcd.Phase != Phase: | |
1275 | continue | |
1276 | ||
1277 | # | |
1278 | # TODO: need GetGuidValue() definition | |
1279 | # | |
1280 | TokenSpaceGuidStructure = Pcd.TokenSpaceGuidValue | |
1281 | TokenSpaceGuid = GuidStructureStringToGuidValueName(TokenSpaceGuidStructure) | |
1282 | if Pcd.Type in gDynamicExPcd: | |
1283 | if TokenSpaceGuid not in GuidList: | |
1284 | GuidList += [TokenSpaceGuid] | |
1285 | Dict['GUID_STRUCTURE'].append(TokenSpaceGuidStructure) | |
1286 | NumberOfExTokens += 1 | |
1287 | ||
1288 | ValueList = [] | |
1289 | StringHeadOffsetList = [] | |
1290 | VpdHeadOffsetList = [] | |
1291 | VariableHeadValueList = [] | |
1292 | Pcd.InitString = 'UNINIT' | |
1293 | ||
e56468c0 | 1294 | if Pcd.DatumType == 'VOID*': |
1295 | if Pcd.Type not in ["DynamicVpd", "DynamicExVpd"]: | |
1296 | Pcd.TokenTypeList = ['PCD_TYPE_STRING'] | |
1297 | else: | |
1298 | Pcd.TokenTypeList = [] | |
30fdf114 LG |
1299 | elif Pcd.DatumType == 'BOOLEAN': |
1300 | Pcd.TokenTypeList = ['PCD_DATUM_TYPE_UINT8'] | |
1301 | else: | |
1302 | Pcd.TokenTypeList = ['PCD_DATUM_TYPE_' + Pcd.DatumType] | |
1303 | ||
1304 | if len(Pcd.SkuInfoList) > 1: | |
1305 | Pcd.TokenTypeList += ['PCD_TYPE_SKU_ENABLED'] | |
1306 | ||
1307 | for SkuName in Pcd.SkuInfoList: | |
1308 | Sku = Pcd.SkuInfoList[SkuName] | |
1309 | SkuId = Sku.SkuId | |
1310 | if SkuId == None or SkuId == '': | |
1311 | continue | |
1312 | ||
1313 | if SkuId not in Dict['SKUID_VALUE']: | |
1314 | Dict['SKUID_VALUE'].append(SkuId) | |
1315 | ||
1316 | SkuIdIndex = Dict['SKUID_VALUE'].index(SkuId) | |
1317 | if len(Sku.VariableName) > 0: | |
1318 | Pcd.TokenTypeList += ['PCD_TYPE_HII'] | |
1319 | Pcd.InitString = 'INIT' | |
1320 | VariableNameStructure = StringToArray(Sku.VariableName) | |
1321 | if VariableNameStructure not in Dict['STRING_TABLE_VALUE']: | |
1322 | Dict['STRING_TABLE_CNAME'].append(CName) | |
1323 | Dict['STRING_TABLE_GUID'].append(TokenSpaceGuid) | |
1324 | if StringTableIndex == 0: | |
1325 | Dict['STRING_TABLE_INDEX'].append('') | |
1326 | else: | |
1327 | Dict['STRING_TABLE_INDEX'].append('_%d' % StringTableIndex) | |
1328 | ||
1329 | Dict['STRING_TABLE_LENGTH'].append((len(Sku.VariableName) - 3 + 1) * 2) | |
1330 | Dict['STRING_TABLE_VALUE'].append(VariableNameStructure) | |
1331 | StringTableIndex += 1 | |
1332 | StringTableSize += (len(Sku.VariableName) - 3 + 1) * 2 | |
1333 | ||
1334 | VariableHeadStringIndex = 0 | |
1335 | for Index in range(Dict['STRING_TABLE_VALUE'].index(VariableNameStructure)): | |
1336 | VariableHeadStringIndex += Dict['STRING_TABLE_LENGTH'][Index] | |
1337 | ||
1338 | VariableGuidStructure = Sku.VariableGuidValue | |
1339 | VariableGuid = GuidStructureStringToGuidValueName(VariableGuidStructure) | |
1340 | if VariableGuid not in GuidList: | |
1341 | GuidList += [VariableGuid] | |
1342 | Dict['GUID_STRUCTURE'].append(VariableGuidStructure) | |
1343 | VariableHeadGuidIndex = GuidList.index(VariableGuid) | |
1344 | ||
52302d4d LG |
1345 | if "PCD_TYPE_STRING" in Pcd.TokenTypeList: |
1346 | VariableHeadValueList.append('%d, %d, %s, offsetof(%s_PCD_DATABASE, Init.%s_%s)' % | |
1347 | (VariableHeadGuidIndex, VariableHeadStringIndex, Sku.VariableOffset, | |
1348 | Phase, CName, TokenSpaceGuid)) | |
1349 | else: | |
1350 | VariableHeadValueList.append('%d, %d, %s, offsetof(%s_PCD_DATABASE, Init.%s_%s_VariableDefault_%s)' % | |
1351 | (VariableHeadGuidIndex, VariableHeadStringIndex, Sku.VariableOffset, | |
1352 | Phase, CName, TokenSpaceGuid, SkuIdIndex)) | |
30fdf114 LG |
1353 | Dict['VARDEF_CNAME_'+Pcd.DatumType].append(CName) |
1354 | Dict['VARDEF_GUID_'+Pcd.DatumType].append(TokenSpaceGuid) | |
1355 | Dict['VARDEF_SKUID_'+Pcd.DatumType].append(SkuIdIndex) | |
52302d4d LG |
1356 | if "PCD_TYPE_STRING" in Pcd.TokenTypeList: |
1357 | Dict['VARDEF_VALUE_' + Pcd.DatumType].append("%s_%s[%d]" % (Pcd.TokenCName, TokenSpaceGuid, SkuIdIndex)) | |
1358 | else: | |
1359 | Dict['VARDEF_VALUE_'+Pcd.DatumType].append(Sku.HiiDefaultValue) | |
30fdf114 LG |
1360 | elif Sku.VpdOffset != '': |
1361 | Pcd.TokenTypeList += ['PCD_TYPE_VPD'] | |
1362 | Pcd.InitString = 'INIT' | |
1363 | VpdHeadOffsetList.append(Sku.VpdOffset) | |
9053bc51 | 1364 | continue |
52302d4d LG |
1365 | |
1366 | if Pcd.DatumType == 'VOID*': | |
1367 | Pcd.TokenTypeList += ['PCD_TYPE_STRING'] | |
1368 | Pcd.InitString = 'INIT' | |
1369 | if Sku.HiiDefaultValue != '' and Sku.DefaultValue == '': | |
1370 | Sku.DefaultValue = Sku.HiiDefaultValue | |
1371 | if Sku.DefaultValue != '': | |
1372 | NumberOfSizeItems += 1 | |
1373 | Dict['STRING_TABLE_CNAME'].append(CName) | |
1374 | Dict['STRING_TABLE_GUID'].append(TokenSpaceGuid) | |
1375 | ||
1376 | if StringTableIndex == 0: | |
1377 | Dict['STRING_TABLE_INDEX'].append('') | |
1378 | else: | |
1379 | Dict['STRING_TABLE_INDEX'].append('_%d' % StringTableIndex) | |
1380 | if Sku.DefaultValue[0] == 'L': | |
1381 | Size = (len(Sku.DefaultValue) - 3 + 1) * 2 | |
1382 | Dict['STRING_TABLE_VALUE'].append(StringToArray(Sku.DefaultValue)) | |
1383 | elif Sku.DefaultValue[0] == '"': | |
1384 | Size = len(Sku.DefaultValue) - 2 + 1 | |
1385 | Dict['STRING_TABLE_VALUE'].append(StringToArray(Sku.DefaultValue)) | |
1386 | elif Sku.DefaultValue[0] == '{': | |
1387 | Size = len(Sku.DefaultValue.replace(',',' ').split()) | |
1388 | Dict['STRING_TABLE_VALUE'].append(Sku.DefaultValue) | |
1389 | ||
1390 | StringHeadOffsetList.append(str(StringTableSize)) | |
1391 | Dict['SIZE_TABLE_CNAME'].append(CName) | |
1392 | Dict['SIZE_TABLE_GUID'].append(TokenSpaceGuid) | |
1393 | Dict['SIZE_TABLE_CURRENT_LENGTH'].append(Size) | |
1394 | Dict['SIZE_TABLE_MAXIMUM_LENGTH'].append(Pcd.MaxDatumSize) | |
1395 | if Pcd.MaxDatumSize != '': | |
1396 | MaxDatumSize = int(Pcd.MaxDatumSize, 0) | |
e56468c0 | 1397 | if MaxDatumSize < Size: |
1398 | EdkLogger.error("build", AUTOGEN_ERROR, | |
1399 | "The maximum size of VOID* type PCD '%s.%s' is less than its actual size occupied." % (Pcd.TokenSpaceGuidCName, Pcd.TokenCName), | |
1400 | ExtraData="[%s]" % str(Platform)) | |
1401 | Size = MaxDatumSize | |
52302d4d LG |
1402 | Dict['STRING_TABLE_LENGTH'].append(Size) |
1403 | StringTableIndex += 1 | |
1404 | StringTableSize += (Size) | |
30fdf114 | 1405 | else: |
52302d4d | 1406 | if "PCD_TYPE_HII" not in Pcd.TokenTypeList: |
30fdf114 LG |
1407 | Pcd.TokenTypeList += ['PCD_TYPE_DATA'] |
1408 | if Sku.DefaultValue == 'TRUE': | |
1409 | Pcd.InitString = 'INIT' | |
1410 | else: | |
1411 | try: | |
1412 | if int(Sku.DefaultValue, 0) != 0: | |
1413 | Pcd.InitString = 'INIT' | |
1414 | except: | |
1415 | pass | |
52302d4d LG |
1416 | |
1417 | # | |
1418 | # For UNIT64 type PCD's value, ULL should be append to avoid | |
1419 | # warning under linux building environment. | |
1420 | # | |
1421 | if Pcd.DatumType == "UINT64": | |
1422 | ValueList.append(Sku.DefaultValue + "ULL") | |
d40b2ee6 LG |
1423 | elif Pcd.DatumType in ("UINT32", "UINT16", "UINT8"): |
1424 | ValueList.append(Sku.DefaultValue + "U") | |
52302d4d LG |
1425 | else: |
1426 | ValueList.append(Sku.DefaultValue) | |
30fdf114 LG |
1427 | |
1428 | Pcd.TokenTypeList = list(set(Pcd.TokenTypeList)) | |
52302d4d | 1429 | |
30fdf114 LG |
1430 | |
1431 | if 'PCD_TYPE_HII' in Pcd.TokenTypeList: | |
1432 | Dict['VARIABLE_HEAD_CNAME_DECL'].append(CName) | |
1433 | Dict['VARIABLE_HEAD_GUID_DECL'].append(TokenSpaceGuid) | |
1434 | Dict['VARIABLE_HEAD_NUMSKUS_DECL'].append(len(Pcd.SkuInfoList)) | |
1435 | Dict['VARIABLE_HEAD_VALUE'].append('{ %s }\n' % ' },\n { '.join(VariableHeadValueList)) | |
52302d4d LG |
1436 | Dict['VARDEF_HEADER'].append('_Variable_Header') |
1437 | else: | |
1438 | Dict['VARDEF_HEADER'].append('') | |
30fdf114 LG |
1439 | if 'PCD_TYPE_VPD' in Pcd.TokenTypeList: |
1440 | Dict['VPD_HEAD_CNAME_DECL'].append(CName) | |
1441 | Dict['VPD_HEAD_GUID_DECL'].append(TokenSpaceGuid) | |
1442 | Dict['VPD_HEAD_NUMSKUS_DECL'].append(len(Pcd.SkuInfoList)) | |
1443 | Dict['VPD_HEAD_VALUE'].append('{ %s }' % ' }, { '.join(VpdHeadOffsetList)) | |
1444 | if 'PCD_TYPE_STRING' in Pcd.TokenTypeList: | |
1445 | Dict['STRING_HEAD_CNAME_DECL'].append(CName) | |
1446 | Dict['STRING_HEAD_GUID_DECL'].append(TokenSpaceGuid) | |
1447 | Dict['STRING_HEAD_NUMSKUS_DECL'].append(len(Pcd.SkuInfoList)) | |
1448 | Dict['STRING_HEAD_VALUE'].append(', '.join(StringHeadOffsetList)) | |
1449 | if 'PCD_TYPE_DATA' in Pcd.TokenTypeList: | |
1450 | Dict[Pcd.InitString+'_CNAME_DECL_'+Pcd.DatumType].append(CName) | |
1451 | Dict[Pcd.InitString+'_GUID_DECL_'+Pcd.DatumType].append(TokenSpaceGuid) | |
1452 | Dict[Pcd.InitString+'_NUMSKUS_DECL_'+Pcd.DatumType].append(len(Pcd.SkuInfoList)) | |
1453 | if Pcd.InitString == 'UNINIT': | |
1454 | Dict['PCD_DATABASE_UNINIT_EMPTY'] = '' | |
1455 | else: | |
1456 | Dict[Pcd.InitString+'_VALUE_'+Pcd.DatumType].append(', '.join(ValueList)) | |
1457 | ||
1458 | if Phase == 'PEI': | |
1459 | NumberOfLocalTokens = NumberOfPeiLocalTokens | |
1460 | if Phase == 'DXE': | |
1461 | NumberOfLocalTokens = NumberOfDxeLocalTokens | |
1462 | ||
1463 | Dict['TOKEN_INIT'] = ['' for x in range(NumberOfLocalTokens)] | |
1464 | Dict['TOKEN_CNAME'] = ['' for x in range(NumberOfLocalTokens)] | |
1465 | Dict['TOKEN_GUID'] = ['' for x in range(NumberOfLocalTokens)] | |
1466 | Dict['TOKEN_TYPE'] = ['' for x in range(NumberOfLocalTokens)] | |
52302d4d | 1467 | |
30fdf114 LG |
1468 | for Pcd in Platform.DynamicPcdList: |
1469 | CName = Pcd.TokenCName | |
1470 | TokenSpaceGuidCName = Pcd.TokenSpaceGuidCName | |
1471 | if Pcd.Phase != Phase: | |
1472 | continue | |
1473 | ||
1474 | TokenSpaceGuid = GuidStructureStringToGuidValueName(Pcd.TokenSpaceGuidValue) #(Platform.PackageList, TokenSpaceGuidCName)) | |
1475 | GeneratedTokenNumber = Platform.PcdTokenNumber[CName, TokenSpaceGuidCName] - 1 | |
1476 | if Phase == 'DXE': | |
1477 | GeneratedTokenNumber -= NumberOfPeiLocalTokens | |
1478 | ||
1479 | EdkLogger.debug(EdkLogger.DEBUG_1, "PCD = %s.%s" % (CName, TokenSpaceGuidCName)) | |
1480 | EdkLogger.debug(EdkLogger.DEBUG_1, "phase = %s" % Phase) | |
1481 | EdkLogger.debug(EdkLogger.DEBUG_1, "GeneratedTokenNumber = %s" % str(GeneratedTokenNumber)) | |
1482 | ||
1483 | Dict['TOKEN_INIT'][GeneratedTokenNumber] = 'Init' | |
1484 | if Pcd.InitString == 'UNINIT': | |
1485 | Dict['TOKEN_INIT'][GeneratedTokenNumber] = 'Uninit' | |
1486 | Dict['TOKEN_CNAME'][GeneratedTokenNumber] = CName | |
1487 | Dict['TOKEN_GUID'][GeneratedTokenNumber] = TokenSpaceGuid | |
1488 | Dict['TOKEN_TYPE'][GeneratedTokenNumber] = ' | '.join(Pcd.TokenTypeList) | |
1489 | if Pcd.Type in gDynamicExPcd: | |
1490 | Dict['EXMAPPING_TABLE_EXTOKEN'].append(Pcd.TokenValue) | |
1491 | if Phase == 'DXE': | |
1492 | GeneratedTokenNumber += NumberOfPeiLocalTokens | |
1493 | # | |
1494 | # Per, PCD architecture specification, PCD Token Number is 1 based and 0 is defined as invalid token number. | |
1495 | # For each EX type PCD, a PCD Token Number is assigned. When the | |
1496 | # PCD Driver/PEIM map EX_GUID and EX_TOKEN_NUMBER to the PCD Token Number, | |
1497 | # the non-EX Protocol/PPI interface can be called to get/set the value. This assumption is made by | |
1498 | # Pcd Driver/PEIM in MdeModulePkg. | |
1499 | # Therefore, 1 is added to GeneratedTokenNumber to generate a PCD Token Number before being inserted | |
1500 | # to the EXMAPPING_TABLE. | |
1501 | # | |
1502 | Dict['EXMAPPING_TABLE_LOCAL_TOKEN'].append(GeneratedTokenNumber + 1) | |
1503 | Dict['EXMAPPING_TABLE_GUID_INDEX'].append(GuidList.index(TokenSpaceGuid)) | |
1504 | ||
1505 | if GuidList != []: | |
1506 | Dict['GUID_TABLE_EMPTY'] = 'FALSE' | |
1507 | Dict['GUID_TABLE_SIZE'] = len(GuidList) | |
1508 | else: | |
1509 | Dict['GUID_STRUCTURE'] = [GuidStringToGuidStructureString('00000000-0000-0000-0000-000000000000')] | |
1510 | ||
1511 | if StringTableIndex == 0: | |
1512 | Dict['STRING_TABLE_INDEX'].append('') | |
1513 | Dict['STRING_TABLE_LENGTH'].append(1) | |
1514 | Dict['STRING_TABLE_CNAME'].append('') | |
1515 | Dict['STRING_TABLE_GUID'].append('') | |
1516 | Dict['STRING_TABLE_VALUE'].append('{ 0 }') | |
1517 | else: | |
1518 | Dict['STRING_TABLE_EMPTY'] = 'FALSE' | |
1519 | Dict['STRING_TABLE_SIZE'] = StringTableSize | |
1520 | ||
1521 | if Dict['SIZE_TABLE_CNAME'] == []: | |
1522 | Dict['SIZE_TABLE_CNAME'].append('') | |
1523 | Dict['SIZE_TABLE_GUID'].append('') | |
1524 | Dict['SIZE_TABLE_CURRENT_LENGTH'].append(0) | |
1525 | Dict['SIZE_TABLE_MAXIMUM_LENGTH'].append(0) | |
1526 | ||
1527 | if NumberOfLocalTokens != 0: | |
1528 | Dict['DATABASE_EMPTY'] = 'FALSE' | |
1529 | Dict['LOCAL_TOKEN_NUMBER_TABLE_SIZE'] = NumberOfLocalTokens | |
1530 | Dict['LOCAL_TOKEN_NUMBER'] = NumberOfLocalTokens | |
1531 | ||
1532 | if NumberOfExTokens != 0: | |
1533 | Dict['EXMAP_TABLE_EMPTY'] = 'FALSE' | |
1534 | Dict['EXMAPPING_TABLE_SIZE'] = NumberOfExTokens | |
1535 | Dict['EX_TOKEN_NUMBER'] = NumberOfExTokens | |
1536 | else: | |
1537 | Dict['EXMAPPING_TABLE_EXTOKEN'].append(0) | |
1538 | Dict['EXMAPPING_TABLE_LOCAL_TOKEN'].append(0) | |
1539 | Dict['EXMAPPING_TABLE_GUID_INDEX'].append(0) | |
1540 | ||
1541 | if NumberOfSizeItems != 0: | |
1542 | Dict['SIZE_TABLE_SIZE'] = NumberOfSizeItems * 2 | |
1543 | ||
1544 | AutoGenH.Append(gPcdDatabaseAutoGenH.Replace(Dict)) | |
1545 | if NumberOfLocalTokens == 0: | |
1546 | AutoGenC.Append(gEmptyPcdDatabaseAutoGenC.Replace(Dict)) | |
1547 | else: | |
1548 | AutoGenC.Append(gPcdDatabaseAutoGenC.Replace(Dict)) | |
1549 | ||
1550 | return AutoGenH, AutoGenC | |
1551 | ||
1552 | ## Create code for PCD database | |
1553 | # | |
1554 | # @param Info The ModuleAutoGen object | |
1555 | # @param AutoGenC The TemplateString object for C code | |
1556 | # @param AutoGenH The TemplateString object for header file | |
1557 | # | |
1558 | def CreatePcdDatabaseCode (Info, AutoGenC, AutoGenH): | |
1559 | if Info.PcdIsDriver == "": | |
1560 | return | |
1561 | if Info.PcdIsDriver not in gPcdPhaseMap: | |
1562 | EdkLogger.error("build", AUTOGEN_ERROR, "Not supported PcdIsDriver type:%s" % Info.PcdIsDriver, | |
1563 | ExtraData="[%s]" % str(Info)) | |
1564 | ||
1565 | AutoGenH.Append(gPcdDatabaseCommonAutoGenH) | |
1566 | AdditionalAutoGenH, AdditionalAutoGenC = CreatePcdDatabasePhaseSpecificAutoGen (Info.PlatformInfo, 'PEI') | |
1567 | AutoGenH.Append(AdditionalAutoGenH.String) | |
1568 | ||
1569 | Phase = gPcdPhaseMap[Info.PcdIsDriver] | |
1570 | if Phase == 'PEI': | |
1571 | AutoGenC.Append(AdditionalAutoGenC.String) | |
1572 | ||
1573 | if Phase == 'DXE': | |
1574 | AdditionalAutoGenH, AdditionalAutoGenC = CreatePcdDatabasePhaseSpecificAutoGen (Info.PlatformInfo, Phase) | |
1575 | AutoGenH.Append(AdditionalAutoGenH.String) | |
1576 | AutoGenC.Append(AdditionalAutoGenC.String) | |
1577 | AutoGenH.Append(gPcdDatabaseEpilogueAutoGenH) | |
1578 | ||
1579 | ## Create code for library constructor | |
1580 | # | |
1581 | # @param Info The ModuleAutoGen object | |
1582 | # @param AutoGenC The TemplateString object for C code | |
1583 | # @param AutoGenH The TemplateString object for header file | |
1584 | # | |
1585 | def CreateLibraryConstructorCode(Info, AutoGenC, AutoGenH): | |
1586 | # | |
1587 | # Library Constructors | |
1588 | # | |
1589 | ConstructorPrototypeString = TemplateString() | |
1590 | ConstructorCallingString = TemplateString() | |
1591 | if Info.IsLibrary: | |
1592 | DependentLibraryList = [Info.Module] | |
1593 | else: | |
1594 | DependentLibraryList = Info.DependentLibraryList | |
1595 | for Lib in DependentLibraryList: | |
1596 | if len(Lib.ConstructorList) <= 0: | |
1597 | continue | |
1598 | Dict = {'Function':Lib.ConstructorList} | |
1599 | if Lib.ModuleType in ['BASE', 'SEC']: | |
1600 | ConstructorPrototypeString.Append(gLibraryStructorPrototype['BASE'].Replace(Dict)) | |
1601 | ConstructorCallingString.Append(gLibraryStructorCall['BASE'].Replace(Dict)) | |
1602 | elif Lib.ModuleType in ['PEI_CORE','PEIM']: | |
1603 | ConstructorPrototypeString.Append(gLibraryStructorPrototype['PEI'].Replace(Dict)) | |
1604 | ConstructorCallingString.Append(gLibraryStructorCall['PEI'].Replace(Dict)) | |
1605 | elif Lib.ModuleType in ['DXE_CORE','DXE_DRIVER','DXE_SMM_DRIVER','DXE_RUNTIME_DRIVER', | |
b303ea72 | 1606 | 'DXE_SAL_DRIVER','UEFI_DRIVER','UEFI_APPLICATION','SMM_CORE']: |
30fdf114 LG |
1607 | ConstructorPrototypeString.Append(gLibraryStructorPrototype['DXE'].Replace(Dict)) |
1608 | ConstructorCallingString.Append(gLibraryStructorCall['DXE'].Replace(Dict)) | |
1609 | ||
1610 | if str(ConstructorPrototypeString) == '': | |
1611 | ConstructorPrototypeList = [] | |
1612 | else: | |
1613 | ConstructorPrototypeList = [str(ConstructorPrototypeString)] | |
1614 | if str(ConstructorCallingString) == '': | |
1615 | ConstructorCallingList = [] | |
1616 | else: | |
1617 | ConstructorCallingList = [str(ConstructorCallingString)] | |
1618 | ||
1619 | Dict = { | |
1620 | 'Type' : 'Constructor', | |
1621 | 'FunctionPrototype' : ConstructorPrototypeList, | |
1622 | 'FunctionCall' : ConstructorCallingList | |
1623 | } | |
1624 | if Info.IsLibrary: | |
1625 | AutoGenH.Append("${BEGIN}${FunctionPrototype}${END}", Dict) | |
1626 | else: | |
1627 | if Info.ModuleType in ['BASE', 'SEC']: | |
1628 | AutoGenC.Append(gLibraryString['BASE'].Replace(Dict)) | |
1629 | elif Info.ModuleType in ['PEI_CORE','PEIM']: | |
1630 | AutoGenC.Append(gLibraryString['PEI'].Replace(Dict)) | |
1631 | elif Info.ModuleType in ['DXE_CORE','DXE_DRIVER','DXE_SMM_DRIVER','DXE_RUNTIME_DRIVER', | |
b303ea72 | 1632 | 'DXE_SAL_DRIVER','UEFI_DRIVER','UEFI_APPLICATION','SMM_CORE']: |
30fdf114 LG |
1633 | AutoGenC.Append(gLibraryString['DXE'].Replace(Dict)) |
1634 | ||
1635 | ## Create code for library destructor | |
1636 | # | |
1637 | # @param Info The ModuleAutoGen object | |
1638 | # @param AutoGenC The TemplateString object for C code | |
1639 | # @param AutoGenH The TemplateString object for header file | |
1640 | # | |
1641 | def CreateLibraryDestructorCode(Info, AutoGenC, AutoGenH): | |
1642 | # | |
1643 | # Library Destructors | |
1644 | # | |
1645 | DestructorPrototypeString = TemplateString() | |
1646 | DestructorCallingString = TemplateString() | |
1647 | if Info.IsLibrary: | |
1648 | DependentLibraryList = [Info.Module] | |
1649 | else: | |
1650 | DependentLibraryList = Info.DependentLibraryList | |
1651 | for Index in range(len(DependentLibraryList)-1, -1, -1): | |
1652 | Lib = DependentLibraryList[Index] | |
1653 | if len(Lib.DestructorList) <= 0: | |
1654 | continue | |
1655 | Dict = {'Function':Lib.DestructorList} | |
1656 | if Lib.ModuleType in ['BASE', 'SEC']: | |
1657 | DestructorPrototypeString.Append(gLibraryStructorPrototype['BASE'].Replace(Dict)) | |
1658 | DestructorCallingString.Append(gLibraryStructorCall['BASE'].Replace(Dict)) | |
1659 | elif Lib.ModuleType in ['PEI_CORE','PEIM']: | |
1660 | DestructorPrototypeString.Append(gLibraryStructorPrototype['PEI'].Replace(Dict)) | |
1661 | DestructorCallingString.Append(gLibraryStructorCall['PEI'].Replace(Dict)) | |
1662 | elif Lib.ModuleType in ['DXE_CORE','DXE_DRIVER','DXE_SMM_DRIVER','DXE_RUNTIME_DRIVER', | |
b303ea72 | 1663 | 'DXE_SAL_DRIVER','UEFI_DRIVER','UEFI_APPLICATION', 'SMM_CORE']: |
30fdf114 LG |
1664 | DestructorPrototypeString.Append(gLibraryStructorPrototype['DXE'].Replace(Dict)) |
1665 | DestructorCallingString.Append(gLibraryStructorCall['DXE'].Replace(Dict)) | |
1666 | ||
1667 | if str(DestructorPrototypeString) == '': | |
1668 | DestructorPrototypeList = [] | |
1669 | else: | |
1670 | DestructorPrototypeList = [str(DestructorPrototypeString)] | |
1671 | if str(DestructorCallingString) == '': | |
1672 | DestructorCallingList = [] | |
1673 | else: | |
1674 | DestructorCallingList = [str(DestructorCallingString)] | |
1675 | ||
1676 | Dict = { | |
1677 | 'Type' : 'Destructor', | |
1678 | 'FunctionPrototype' : DestructorPrototypeList, | |
1679 | 'FunctionCall' : DestructorCallingList | |
1680 | } | |
1681 | if Info.IsLibrary: | |
1682 | AutoGenH.Append("${BEGIN}${FunctionPrototype}${END}", Dict) | |
1683 | else: | |
1684 | if Info.ModuleType in ['BASE', 'SEC']: | |
1685 | AutoGenC.Append(gLibraryString['BASE'].Replace(Dict)) | |
1686 | elif Info.ModuleType in ['PEI_CORE','PEIM']: | |
1687 | AutoGenC.Append(gLibraryString['PEI'].Replace(Dict)) | |
1688 | elif Info.ModuleType in ['DXE_CORE','DXE_DRIVER','DXE_SMM_DRIVER','DXE_RUNTIME_DRIVER', | |
b303ea72 | 1689 | 'DXE_SAL_DRIVER','UEFI_DRIVER','UEFI_APPLICATION','SMM_CORE']: |
30fdf114 LG |
1690 | AutoGenC.Append(gLibraryString['DXE'].Replace(Dict)) |
1691 | ||
1692 | ||
1693 | ## Create code for ModuleEntryPoint | |
1694 | # | |
1695 | # @param Info The ModuleAutoGen object | |
1696 | # @param AutoGenC The TemplateString object for C code | |
1697 | # @param AutoGenH The TemplateString object for header file | |
1698 | # | |
1699 | def CreateModuleEntryPointCode(Info, AutoGenC, AutoGenH): | |
1700 | if Info.IsLibrary or Info.ModuleType in ['USER_DEFINED', 'SEC']: | |
1701 | return | |
1702 | # | |
1703 | # Module Entry Points | |
1704 | # | |
1705 | NumEntryPoints = len(Info.Module.ModuleEntryPointList) | |
1706 | if 'PI_SPECIFICATION_VERSION' in Info.Module.Specification: | |
1707 | PiSpecVersion = Info.Module.Specification['PI_SPECIFICATION_VERSION'] | |
1708 | else: | |
da92f276 | 1709 | PiSpecVersion = '0x00000000' |
52302d4d LG |
1710 | if 'UEFI_SPECIFICATION_VERSION' in Info.Module.Specification: |
1711 | UefiSpecVersion = Info.Module.Specification['UEFI_SPECIFICATION_VERSION'] | |
30fdf114 | 1712 | else: |
da92f276 | 1713 | UefiSpecVersion = '0x00000000' |
30fdf114 | 1714 | Dict = { |
52302d4d LG |
1715 | 'Function' : Info.Module.ModuleEntryPointList, |
1716 | 'PiSpecVersion' : PiSpecVersion, | |
1717 | 'UefiSpecVersion': UefiSpecVersion | |
30fdf114 LG |
1718 | } |
1719 | ||
1720 | if Info.ModuleType in ['PEI_CORE', 'DXE_CORE', 'SMM_CORE']: | |
da92f276 LG |
1721 | if Info.SourceFileList <> None and Info.SourceFileList <> []: |
1722 | if NumEntryPoints != 1: | |
1723 | EdkLogger.error( | |
1724 | "build", | |
1725 | AUTOGEN_ERROR, | |
1726 | '%s must have exactly one entry point' % Info.ModuleType, | |
1727 | File=str(Info), | |
1728 | ExtraData= ", ".join(Info.Module.ModuleEntryPointList) | |
1729 | ) | |
30fdf114 LG |
1730 | if Info.ModuleType == 'PEI_CORE': |
1731 | AutoGenC.Append(gPeiCoreEntryPointString.Replace(Dict)) | |
1732 | AutoGenH.Append(gPeiCoreEntryPointPrototype.Replace(Dict)) | |
1733 | elif Info.ModuleType == 'DXE_CORE': | |
1734 | AutoGenC.Append(gDxeCoreEntryPointString.Replace(Dict)) | |
1735 | AutoGenH.Append(gDxeCoreEntryPointPrototype.Replace(Dict)) | |
1736 | elif Info.ModuleType == 'SMM_CORE': | |
1737 | AutoGenC.Append(gSmmCoreEntryPointString.Replace(Dict)) | |
b303ea72 | 1738 | AutoGenH.Append(gSmmCoreEntryPointPrototype.Replace(Dict)) |
30fdf114 LG |
1739 | elif Info.ModuleType == 'PEIM': |
1740 | if NumEntryPoints < 2: | |
1741 | AutoGenC.Append(gPeimEntryPointString[NumEntryPoints].Replace(Dict)) | |
1742 | else: | |
1743 | AutoGenC.Append(gPeimEntryPointString[2].Replace(Dict)) | |
1744 | AutoGenH.Append(gPeimEntryPointPrototype.Replace(Dict)) | |
b303ea72 LG |
1745 | elif Info.ModuleType in ['DXE_RUNTIME_DRIVER','DXE_DRIVER','DXE_SAL_DRIVER','UEFI_DRIVER']: |
1746 | if NumEntryPoints < 2: | |
1747 | AutoGenC.Append(gUefiDriverEntryPointString[NumEntryPoints].Replace(Dict)) | |
30fdf114 | 1748 | else: |
b303ea72 LG |
1749 | AutoGenC.Append(gUefiDriverEntryPointString[2].Replace(Dict)) |
1750 | AutoGenH.Append(gUefiDriverEntryPointPrototype.Replace(Dict)) | |
1751 | elif Info.ModuleType == 'DXE_SMM_DRIVER': | |
1752 | if NumEntryPoints == 0: | |
1753 | AutoGenC.Append(gDxeSmmEntryPointString[0].Replace(Dict)) | |
1754 | else: | |
1755 | AutoGenC.Append(gDxeSmmEntryPointString[1].Replace(Dict)) | |
1756 | AutoGenH.Append(gDxeSmmEntryPointPrototype.Replace(Dict)) | |
30fdf114 LG |
1757 | elif Info.ModuleType == 'UEFI_APPLICATION': |
1758 | if NumEntryPoints < 2: | |
1759 | AutoGenC.Append(gUefiApplicationEntryPointString[NumEntryPoints].Replace(Dict)) | |
1760 | else: | |
1761 | AutoGenC.Append(gUefiApplicationEntryPointString[2].Replace(Dict)) | |
1762 | AutoGenH.Append(gUefiApplicationEntryPointPrototype.Replace(Dict)) | |
1763 | ||
1764 | ## Create code for ModuleUnloadImage | |
1765 | # | |
1766 | # @param Info The ModuleAutoGen object | |
1767 | # @param AutoGenC The TemplateString object for C code | |
1768 | # @param AutoGenH The TemplateString object for header file | |
1769 | # | |
1770 | def CreateModuleUnloadImageCode(Info, AutoGenC, AutoGenH): | |
1771 | if Info.IsLibrary or Info.ModuleType in ['USER_DEFINED', 'SEC']: | |
1772 | return | |
1773 | # | |
1774 | # Unload Image Handlers | |
1775 | # | |
1776 | NumUnloadImage = len(Info.Module.ModuleUnloadImageList) | |
1777 | Dict = {'Count':NumUnloadImage, 'Function':Info.Module.ModuleUnloadImageList} | |
1778 | if NumUnloadImage < 2: | |
1779 | AutoGenC.Append(gUefiUnloadImageString[NumUnloadImage].Replace(Dict)) | |
1780 | else: | |
1781 | AutoGenC.Append(gUefiUnloadImageString[2].Replace(Dict)) | |
1782 | AutoGenH.Append(gUefiUnloadImagePrototype.Replace(Dict)) | |
1783 | ||
1784 | ## Create code for GUID | |
1785 | # | |
1786 | # @param Info The ModuleAutoGen object | |
1787 | # @param AutoGenC The TemplateString object for C code | |
1788 | # @param AutoGenH The TemplateString object for header file | |
1789 | # | |
1790 | def CreateGuidDefinitionCode(Info, AutoGenC, AutoGenH): | |
1791 | if Info.IsLibrary: | |
1792 | return | |
1793 | ||
1794 | if Info.ModuleType in ["USER_DEFINED", "BASE"]: | |
1795 | GuidType = "GUID" | |
1796 | else: | |
1797 | GuidType = "EFI_GUID" | |
1798 | ||
1799 | if Info.GuidList: | |
1800 | AutoGenC.Append("\n// Guids\n") | |
1801 | # | |
1802 | # GUIDs | |
1803 | # | |
1804 | for Key in Info.GuidList: | |
1805 | AutoGenC.Append('GLOBAL_REMOVE_IF_UNREFERENCED %s %s = %s;\n' % (GuidType, Key, Info.GuidList[Key])) | |
1806 | ||
1807 | ## Create code for protocol | |
1808 | # | |
1809 | # @param Info The ModuleAutoGen object | |
1810 | # @param AutoGenC The TemplateString object for C code | |
1811 | # @param AutoGenH The TemplateString object for header file | |
1812 | # | |
1813 | def CreateProtocolDefinitionCode(Info, AutoGenC, AutoGenH): | |
1814 | if Info.IsLibrary: | |
1815 | return | |
1816 | ||
1817 | if Info.ModuleType in ["USER_DEFINED", "BASE"]: | |
1818 | GuidType = "GUID" | |
1819 | else: | |
1820 | GuidType = "EFI_GUID" | |
1821 | ||
1822 | if Info.ProtocolList: | |
1823 | AutoGenC.Append("\n// Protocols\n") | |
1824 | # | |
1825 | # Protocol GUIDs | |
1826 | # | |
1827 | for Key in Info.ProtocolList: | |
1828 | AutoGenC.Append('GLOBAL_REMOVE_IF_UNREFERENCED %s %s = %s;\n' % (GuidType, Key, Info.ProtocolList[Key])) | |
1829 | ||
1830 | ## Create code for PPI | |
1831 | # | |
1832 | # @param Info The ModuleAutoGen object | |
1833 | # @param AutoGenC The TemplateString object for C code | |
1834 | # @param AutoGenH The TemplateString object for header file | |
1835 | # | |
1836 | def CreatePpiDefinitionCode(Info, AutoGenC, AutoGenH): | |
1837 | if Info.IsLibrary: | |
1838 | return | |
1839 | ||
1840 | if Info.ModuleType in ["USER_DEFINED", "BASE"]: | |
1841 | GuidType = "GUID" | |
1842 | else: | |
1843 | GuidType = "EFI_GUID" | |
1844 | ||
1845 | if Info.PpiList: | |
1846 | AutoGenC.Append("\n// PPIs\n") | |
1847 | # | |
1848 | # PPI GUIDs | |
1849 | # | |
1850 | for Key in Info.PpiList: | |
1851 | AutoGenC.Append('GLOBAL_REMOVE_IF_UNREFERENCED %s %s = %s;\n' % (GuidType, Key, Info.PpiList[Key])) | |
1852 | ||
1853 | ## Create code for PCD | |
1854 | # | |
1855 | # @param Info The ModuleAutoGen object | |
1856 | # @param AutoGenC The TemplateString object for C code | |
1857 | # @param AutoGenH The TemplateString object for header file | |
1858 | # | |
1859 | def CreatePcdCode(Info, AutoGenC, AutoGenH): | |
da92f276 LG |
1860 | |
1861 | # Collect Token Space GUIDs used by DynamicEc PCDs | |
1862 | TokenSpaceList = [] | |
1863 | for Pcd in Info.ModulePcdList: | |
1864 | if Pcd.Type in gDynamicExPcd and Pcd.TokenSpaceGuidCName not in TokenSpaceList: | |
1865 | TokenSpaceList += [Pcd.TokenSpaceGuidCName] | |
1866 | ||
1867 | # Add extern declarations to AutoGen.h if one or more Token Space GUIDs were found | |
1868 | if TokenSpaceList <> []: | |
1869 | AutoGenH.Append("\n// Definition of PCD Token Space GUIDs used in this module\n\n") | |
1870 | if Info.ModuleType in ["USER_DEFINED", "BASE"]: | |
1871 | GuidType = "GUID" | |
1872 | else: | |
1873 | GuidType = "EFI_GUID" | |
1874 | for Item in TokenSpaceList: | |
1875 | AutoGenH.Append('extern %s %s;\n' % (GuidType, Item)) | |
1876 | ||
30fdf114 LG |
1877 | if Info.IsLibrary: |
1878 | if Info.ModulePcdList: | |
1879 | AutoGenH.Append("\n// PCD definitions\n") | |
1880 | for Pcd in Info.ModulePcdList: | |
1881 | CreateLibraryPcdCode(Info, AutoGenC, AutoGenH, Pcd) | |
1882 | else: | |
1883 | if Info.ModulePcdList: | |
1884 | AutoGenH.Append("\n// Definition of PCDs used in this module\n") | |
1885 | AutoGenC.Append("\n// Definition of PCDs used in this module\n") | |
1886 | for Pcd in Info.ModulePcdList: | |
1887 | CreateModulePcdCode(Info, AutoGenC, AutoGenH, Pcd) | |
1888 | ||
1889 | if Info.LibraryPcdList: | |
1890 | AutoGenH.Append("\n// Definition of PCDs used in libraries is in AutoGen.c\n") | |
1891 | AutoGenC.Append("\n// Definition of PCDs used in libraries\n") | |
1892 | for Pcd in Info.LibraryPcdList: | |
1893 | CreateModulePcdCode(Info, AutoGenC, AutoGenC, Pcd) | |
1894 | CreatePcdDatabaseCode(Info, AutoGenC, AutoGenH) | |
1895 | ||
1896 | ## Create code for unicode string definition | |
1897 | # | |
1898 | # @param Info The ModuleAutoGen object | |
1899 | # @param AutoGenC The TemplateString object for C code | |
1900 | # @param AutoGenH The TemplateString object for header file | |
b303ea72 LG |
1901 | # @param UniGenCFlag UniString is generated into AutoGen C file when it is set to True |
1902 | # @param UniGenBinBuffer Buffer to store uni string package data | |
30fdf114 | 1903 | # |
b303ea72 | 1904 | def CreateUnicodeStringCode(Info, AutoGenC, AutoGenH, UniGenCFlag, UniGenBinBuffer): |
30fdf114 LG |
1905 | WorkingDir = os.getcwd() |
1906 | os.chdir(Info.WorkspaceDir) | |
1907 | ||
1908 | IncList = [Info.MetaFile.Dir] | |
1909 | # Get all files under [Sources] section in inf file for EDK-II module | |
6780eef1 | 1910 | EDK2Module = True |
30fdf114 LG |
1911 | SrcList = [F for F in Info.SourceFileList] |
1912 | if Info.AutoGenVersion < 0x00010005: | |
6780eef1 | 1913 | EDK2Module = False |
30fdf114 LG |
1914 | # Get all files under the module directory for EDK-I module |
1915 | Cwd = os.getcwd() | |
1916 | os.chdir(Info.MetaFile.Dir) | |
1917 | for Root, Dirs, Files in os.walk("."): | |
1918 | if 'CVS' in Dirs: | |
1919 | Dirs.remove('CVS') | |
1920 | if '.svn' in Dirs: | |
1921 | Dirs.remove('.svn') | |
1922 | for File in Files: | |
1923 | File = PathClass(os.path.join(Root, File), Info.MetaFile.Dir) | |
1924 | if File in SrcList: | |
1925 | continue | |
1926 | SrcList.append(File) | |
1927 | os.chdir(Cwd) | |
1928 | ||
1929 | if 'BUILD' in Info.BuildOption and Info.BuildOption['BUILD']['FLAGS'].find('-c') > -1: | |
1930 | CompatibleMode = True | |
1931 | else: | |
1932 | CompatibleMode = False | |
1933 | ||
1934 | # | |
6780eef1 | 1935 | # -s is a temporary option dedicated for building .UNI files with ISO 639-2 language codes of EDK Shell in EDK2 |
30fdf114 LG |
1936 | # |
1937 | if 'BUILD' in Info.BuildOption and Info.BuildOption['BUILD']['FLAGS'].find('-s') > -1: | |
1938 | if CompatibleMode: | |
1939 | EdkLogger.error("build", AUTOGEN_ERROR, | |
1940 | "-c and -s build options should be used exclusively", | |
1941 | ExtraData="[%s]" % str(Info)) | |
1942 | ShellMode = True | |
1943 | else: | |
1944 | ShellMode = False | |
1945 | ||
6780eef1 LG |
1946 | #RFC4646 is only for EDKII modules and ISO639-2 for EDK modules |
1947 | if EDK2Module: | |
1948 | FilterInfo = [EDK2Module] + [Info.PlatformInfo.Platform.RFCLanguages] | |
1949 | else: | |
1950 | FilterInfo = [EDK2Module] + [Info.PlatformInfo.Platform.ISOLanguages] | |
1951 | Header, Code = GetStringFiles(Info.UnicodeFileList, SrcList, IncList, Info.IncludePathList, ['.uni', '.inf'], Info.Name, CompatibleMode, ShellMode, UniGenCFlag, UniGenBinBuffer, FilterInfo) | |
b303ea72 LG |
1952 | if CompatibleMode or UniGenCFlag: |
1953 | AutoGenC.Append("\n//\n//Unicode String Pack Definition\n//\n") | |
1954 | AutoGenC.Append(Code) | |
1955 | AutoGenC.Append("\n") | |
30fdf114 LG |
1956 | AutoGenH.Append("\n//\n//Unicode String ID\n//\n") |
1957 | AutoGenH.Append(Header) | |
b303ea72 LG |
1958 | if CompatibleMode or UniGenCFlag: |
1959 | AutoGenH.Append("\n#define STRING_ARRAY_NAME %sStrings\n" % Info.Name) | |
30fdf114 LG |
1960 | os.chdir(WorkingDir) |
1961 | ||
1962 | ## Create common code | |
1963 | # | |
1964 | # @param Info The ModuleAutoGen object | |
1965 | # @param AutoGenC The TemplateString object for C code | |
1966 | # @param AutoGenH The TemplateString object for header file | |
1967 | # | |
1968 | def CreateHeaderCode(Info, AutoGenC, AutoGenH): | |
1969 | # file header | |
1970 | AutoGenH.Append(gAutoGenHeaderString.Replace({'FileName':'AutoGen.h'})) | |
1971 | # header file Prologue | |
1972 | AutoGenH.Append(gAutoGenHPrologueString.Replace({'File':'AUTOGENH','Guid':Info.Guid.replace('-','_')})) | |
1973 | if Info.AutoGenVersion >= 0x00010005: | |
30fdf114 LG |
1974 | # header files includes |
1975 | AutoGenH.Append("#include <%s>\n" % gBasicHeaderFile) | |
1976 | if Info.ModuleType in gModuleTypeHeaderFile \ | |
1977 | and gModuleTypeHeaderFile[Info.ModuleType][0] != gBasicHeaderFile: | |
1978 | AutoGenH.Append("#include <%s>\n" % gModuleTypeHeaderFile[Info.ModuleType][0]) | |
b36d134f LG |
1979 | # |
1980 | # if either PcdLib in [LibraryClasses] sections or there exist Pcd section, add PcdLib.h | |
1981 | # As if modules only uses FixedPcd, then PcdLib is not needed in [LibraryClasses] section. | |
1982 | # | |
1983 | if 'PcdLib' in Info.Module.LibraryClasses or Info.Module.Pcds: | |
4234283c LG |
1984 | AutoGenH.Append("#include <Library/PcdLib.h>\n") |
1985 | ||
30fdf114 LG |
1986 | AutoGenH.Append('\nextern GUID gEfiCallerIdGuid;\n\n') |
1987 | ||
1988 | if Info.IsLibrary: | |
1989 | return | |
1990 | ||
1991 | AutoGenH.Append("#define EFI_CALLER_ID_GUID \\\n %s\n" % GuidStringToGuidStructureString(Info.Guid)) | |
1992 | ||
1993 | if Info.IsLibrary: | |
1994 | return | |
1995 | # C file header | |
1996 | AutoGenC.Append(gAutoGenHeaderString.Replace({'FileName':'AutoGen.c'})) | |
1997 | if Info.AutoGenVersion >= 0x00010005: | |
1998 | # C file header files includes | |
1999 | if Info.ModuleType in gModuleTypeHeaderFile: | |
2000 | for Inc in gModuleTypeHeaderFile[Info.ModuleType]: | |
2001 | AutoGenC.Append("#include <%s>\n" % Inc) | |
2002 | else: | |
2003 | AutoGenC.Append("#include <%s>\n" % gBasicHeaderFile) | |
2004 | ||
2005 | # | |
2006 | # Publish the CallerId Guid | |
2007 | # | |
2008 | AutoGenC.Append('\nGLOBAL_REMOVE_IF_UNREFERENCED GUID gEfiCallerIdGuid = %s;\n' % GuidStringToGuidStructureString(Info.Guid)) | |
2009 | ||
2010 | ## Create common code for header file | |
2011 | # | |
2012 | # @param Info The ModuleAutoGen object | |
2013 | # @param AutoGenC The TemplateString object for C code | |
2014 | # @param AutoGenH The TemplateString object for header file | |
2015 | # | |
2016 | def CreateFooterCode(Info, AutoGenC, AutoGenH): | |
2017 | AutoGenH.Append(gAutoGenHEpilogueString) | |
2018 | ||
2019 | ## Create code for a module | |
2020 | # | |
2021 | # @param Info The ModuleAutoGen object | |
2022 | # @param AutoGenC The TemplateString object for C code | |
2023 | # @param AutoGenH The TemplateString object for header file | |
b303ea72 LG |
2024 | # @param UniGenCFlag UniString is generated into AutoGen C file when it is set to True |
2025 | # @param UniGenBinBuffer Buffer to store uni string package data | |
30fdf114 | 2026 | # |
b303ea72 | 2027 | def CreateCode(Info, AutoGenC, AutoGenH, StringH, UniGenCFlag, UniGenBinBuffer): |
30fdf114 LG |
2028 | CreateHeaderCode(Info, AutoGenC, AutoGenH) |
2029 | ||
2030 | if Info.AutoGenVersion >= 0x00010005: | |
2031 | CreateGuidDefinitionCode(Info, AutoGenC, AutoGenH) | |
2032 | CreateProtocolDefinitionCode(Info, AutoGenC, AutoGenH) | |
2033 | CreatePpiDefinitionCode(Info, AutoGenC, AutoGenH) | |
2034 | CreatePcdCode(Info, AutoGenC, AutoGenH) | |
2035 | CreateLibraryConstructorCode(Info, AutoGenC, AutoGenH) | |
2036 | CreateLibraryDestructorCode(Info, AutoGenC, AutoGenH) | |
2037 | CreateModuleEntryPointCode(Info, AutoGenC, AutoGenH) | |
2038 | CreateModuleUnloadImageCode(Info, AutoGenC, AutoGenH) | |
2039 | ||
2040 | if Info.UnicodeFileList: | |
2041 | FileName = "%sStrDefs.h" % Info.Name | |
2042 | StringH.Append(gAutoGenHeaderString.Replace({'FileName':FileName})) | |
2043 | StringH.Append(gAutoGenHPrologueString.Replace({'File':'STRDEFS', 'Guid':Info.Guid.replace('-','_')})) | |
b303ea72 | 2044 | CreateUnicodeStringCode(Info, AutoGenC, StringH, UniGenCFlag, UniGenBinBuffer) |
30fdf114 LG |
2045 | StringH.Append("\n#endif\n") |
2046 | AutoGenH.Append('#include "%s"\n' % FileName) | |
2047 | ||
2048 | CreateFooterCode(Info, AutoGenC, AutoGenH) | |
2049 | ||
b36d134f | 2050 | # no generation of AutoGen.c for Edk modules without unicode file |
30fdf114 LG |
2051 | if Info.AutoGenVersion < 0x00010005 and len(Info.UnicodeFileList) == 0: |
2052 | AutoGenC.String = '' | |
2053 | ||
2054 | ## Create the code file | |
2055 | # | |
b303ea72 LG |
2056 | # @param FilePath The path of code file |
2057 | # @param Content The content of code file | |
2058 | # @param IsBinaryFile The flag indicating if the file is binary file or not | |
30fdf114 LG |
2059 | # |
2060 | # @retval True If file content is changed or file doesn't exist | |
2061 | # @retval False If the file exists and the content is not changed | |
2062 | # | |
b303ea72 LG |
2063 | def Generate(FilePath, Content, IsBinaryFile): |
2064 | return SaveFileOnChange(FilePath, Content, IsBinaryFile) | |
30fdf114 | 2065 |