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