1 | ␊ |
2 | /*␊ |
3 | * Copyright 2007 David F. Elliott.␉ All rights reserved.␊ |
4 | */␊ |
5 | ␊ |
6 | /*␊ |
7 | * Copyright 2010,2011,2012 Cadet-petit Armel <armelcadetpetit@gmail.com>. All rights reserved.␊ |
8 | */␊ |
9 | ␊ |
10 | #include "libsaio.h"␊ |
11 | #include "bootstruct.h"␊ |
12 | #include "efi.h"␊ |
13 | #include "acpi.h"␊ |
14 | #include "fake_efi.h"␊ |
15 | #include "efi_tables.h"␊ |
16 | #include "platform.h"␊ |
17 | #include "device_inject.h"␊ |
18 | #include "convert.h"␊ |
19 | #include "pci.h"␊ |
20 | #include "sl.h"␊ |
21 | #include "modules.h"␊ |
22 | #include "vers.h"␊ |
23 | ␊ |
24 | #ifndef NO_SMP_SUPPORT␊ |
25 | #include "smp-imps.h"␊ |
26 | #endif␊ |
27 | ␊ |
28 | #ifndef DEBUG_EFI␊ |
29 | #define DEBUG_EFI 0␊ |
30 | #endif␊ |
31 | ␊ |
32 | #if DEBUG_EFI␊ |
33 | #define DBG(x...)␉printf(x)␊ |
34 | #else␊ |
35 | #define DBG(x...)␊ |
36 | #endif␊ |
37 | /*␊ |
38 | * Modern Darwin kernels require some amount of EFI because Apple machines all␊ |
39 | * have EFI. Modifying the kernel source to not require EFI is of course␊ |
40 | * possible but would have to be maintained as a separate patch because it is␊ |
41 | * unlikely that Apple wishes to add legacy support to their kernel.␊ |
42 | *␊ |
43 | * As you can see from the Apple-supplied code in bootstruct.c, it seems that␊ |
44 | * the intention was clearly to modify this booter to provide EFI-like structures␊ |
45 | * to the kernel rather than modifying the kernel to handle non-EFI stuff.␉ This␊ |
46 | * makes a lot of sense from an engineering point of view as it means the kernel␊ |
47 | * for the as yet unreleased EFI-only Macs could still be booted by the non-EFI␊ |
48 | * DTK systems so long as the kernel checked to ensure the boot tables were␊ |
49 | * filled in appropriately.␉ Modern xnu requires a system table and a runtime␊ |
50 | * services table and performs no checks whatsoever to ensure the pointers to␊ |
51 | * these tables are non-NULL.␉Therefore, any modern xnu kernel will page fault␊ |
52 | * early on in the boot process if the system table pointer is zero.␊ |
53 | *␊ |
54 | * Even before that happens, the tsc_init function in modern xnu requires the FSB␊ |
55 | * Frequency to be a property in the /efi/platform node of the device tree or else␊ |
56 | * it panics the bootstrap process very early on.␊ |
57 | *␊ |
58 | * As of this writing, the current implementation found here is good enough␊ |
59 | * to make the currently available xnu kernel boot without modification on a␊ |
60 | * system with an appropriate processor. With a minor source modification to␊ |
61 | * the tsc_init function to remove the explicit check for Core or Core 2␊ |
62 | * processors the kernel can be made to boot on other processors so long as␊ |
63 | * the code can be executed by the processor and the machine contains the␊ |
64 | * necessary hardware.␊ |
65 | */␊ |
66 | static inline char * mallocStringForGuid(EFI_GUID const *pGuid);␊ |
67 | static VOID EFI_ST_FIX_CRC32(void);␊ |
68 | static EFI_STATUS setupAcpiNoMod();␊ |
69 | static EFI_CHAR16* getSmbiosChar16(const char * key, size_t* len);␊ |
70 | static EFI_CHAR8* getSmbiosUUID();␊ |
71 | static int8_t *getSystemID();␊ |
72 | static VOID setupSystemType();␊ |
73 | static VOID setupEfiDeviceTree(void);␊ |
74 | static VOID setup_Smbios();␊ |
75 | static VOID setup_machine_signature();␊ |
76 | static VOID setupEfiConfigurationTable();␊ |
77 | ␊ |
78 | /*==========================================================================␊ |
79 | * Utility function to make a device tree string from an EFI_GUID␊ |
80 | */␊ |
81 | ␊ |
82 | static inline char * mallocStringForGuid(EFI_GUID const *pGuid)␊ |
83 | {␊ |
84 | ␉char *string = malloc(37);␊ |
85 | if (!string) {␊ |
86 | #if DEBUG_EFI␊ |
87 | char string_d[37];␊ |
88 | efi_guid_unparse_upper(pGuid, string_d, sizeof(string_d));␊ |
89 | printf("Couldn't allocate Guid String for %s\n", string_d); ␊ |
90 | #endif␊ |
91 | return NULL;␊ |
92 | }␊ |
93 | ␊ |
94 | ␉efi_guid_unparse_upper(pGuid, string, 37);␊ |
95 | ␉return string;␊ |
96 | }␊ |
97 | ␊ |
98 | /*==========================================================================␊ |
99 | * Function to map 32 bit physical address to 64 bit virtual address␊ |
100 | */␊ |
101 | ␊ |
102 | #define ptov64(addr) (uint64_t)((uint64_t)addr | 0xFFFFFF8000000000ULL)␊ |
103 | ␊ |
104 | /*==========================================================================␊ |
105 | * Fake EFI implementation␊ |
106 | */␊ |
107 | ␊ |
108 | static EFI_CHAR16 const FIRMWARE_VENDOR[] = {'A','p','p','l','e', 0}; ␊ |
109 | ␊ |
110 | /* Info About the current Firmware */␊ |
111 | #define FIRMWARE_MAINTENER "cparm, armelcadetpetit@gmail.com" ␊ |
112 | static EFI_CHAR16 const FIRMWARE_NAME[] = {'M','a','s','h','e','r','b','r','u','m','-','2', 0}; ␊ |
113 | static EFI_UINT32 const FIRMWARE_REVISION = 0x00010800; //1.8␊ |
114 | static EFI_UINT32 const DEVICE_SUPPORTED = 0x00000001;␊ |
115 | ␊ |
116 | /* Default platform system_id (fix by IntVar) */␊ |
117 | static EFI_CHAR8 const SYSTEM_ID[] = "0123456789ABCDEF"; //random value gen by uuidgen␊ |
118 | ␊ |
119 | /* Just a ret instruction */␊ |
120 | static uint8_t const VOIDRET_INSTRUCTIONS[] = {0xc3};␊ |
121 | ␊ |
122 | /* movl $0x80000003,%eax; ret */␊ |
123 | static uint8_t const UNSUPPORTEDRET_INSTRUCTIONS[] = {0xb8, 0x03, 0x00, 0x00, 0x80, 0xc3};␊ |
124 | ␊ |
125 | EFI_SYSTEM_TABLE_32 *gST32 = NULL;␊ |
126 | EFI_SYSTEM_TABLE_64 *gST64 = NULL;␊ |
127 | Node *gEfiConfigurationTableNode = NULL;␊ |
128 | ␊ |
129 | /* From Foundation/Efi/Guid/Smbios/SmBios.h */␊ |
130 | /* Modified to wrap Data4 array init with {} */␊ |
131 | #define EFI_SMBIOS_TABLE_GUID {0xeb9d2d31, 0x2d88, 0x11d3, {0x9a, 0x16, 0x0, 0x90, 0x27, 0x3f, 0xc1, 0x4d}}␊ |
132 | ␊ |
133 | #define EFI_ACPI_TABLE_GUID \␊ |
134 | { \␊ |
135 | 0xeb9d2d30, 0x2d88, 0x11d3, { 0x9a, 0x16, 0x0, 0x90, 0x27, 0x3f, 0xc1, 0x4d } \␊ |
136 | }␊ |
137 | ␊ |
138 | #define EFI_ACPI_20_TABLE_GUID \␊ |
139 | { \␊ |
140 | 0x8868e871, 0xe4f1, 0x11d3, { 0xbc, 0x22, 0x0, 0x80, 0xc7, 0x3c, 0x88, 0x81 } \␊ |
141 | }␊ |
142 | ␊ |
143 | #ifndef NO_SMP_SUPPORT␊ |
144 | #define EFI_MPS_TABLE_GUID \␊ |
145 | { \␊ |
146 | 0xeb9d2d2f,0x2d88,0x11d3,{0x9a,0x16,0x0,0x90,0x27,0x3f,0xc1,0x4d} \␊ |
147 | }␊ |
148 | #endif␊ |
149 | ␊ |
150 | /* From Foundation/Efi/Guid/Smbios/SmBios.c */␊ |
151 | EFI_GUID const␉gEfiSmbiosTableGuid = EFI_SMBIOS_TABLE_GUID;␊ |
152 | ␊ |
153 | EFI_GUID gEfiAcpiTableGuid = EFI_ACPI_TABLE_GUID;␊ |
154 | EFI_GUID gEfiAcpi20TableGuid = EFI_ACPI_20_TABLE_GUID;␊ |
155 | ␊ |
156 | #ifndef NO_SMP_SUPPORT␊ |
157 | EFI_GUID gEfiMpsTableGuid = EFI_MPS_TABLE_GUID;␊ |
158 | #endif␊ |
159 | ␊ |
160 | EFI_UINT32 gNumTables32 = 0;␊ |
161 | EFI_UINT64 gNumTables64 = 0;␊ |
162 | EFI_CONFIGURATION_TABLE_32 gEfiConfigurationTable32[MAX_CONFIGURATION_TABLE_ENTRIES];␊ |
163 | EFI_CONFIGURATION_TABLE_64 gEfiConfigurationTable64[MAX_CONFIGURATION_TABLE_ENTRIES];␊ |
164 | extern EFI_STATUS addConfigurationTable(EFI_GUID const *pGuid, void *table, char const *alias)␊ |
165 | {␊ |
166 | ␉EFI_UINTN i = 0;␊ |
167 | ␉␊ |
168 | if (pGuid == NULL || table == NULL)␊ |
169 | ␉␉return EFI_INVALID_PARAMETER;␊ |
170 | ␊ |
171 | char * GuidStr = mallocStringForGuid(pGuid);␊ |
172 | if (!GuidStr) {␊ |
173 | return EFI_OUT_OF_RESOURCES;␊ |
174 | }␊ |
175 | ␊ |
176 | ␉//Azi: as is, cpu's with em64t will use EFI64 on pre 10.6 systems,␊ |
177 | ␉// wich seems to cause no problem. In case it does, force i386 arch.␊ |
178 | ␉if (get_env(envarchCpuType) == CPU_TYPE_I386)␊ |
179 | ␉{␊ |
180 | ␉␉i = gNumTables32;␊ |
181 | ␉}␊ |
182 | ␉else␊ |
183 | ␉{␊ |
184 | ␉␉i = (EFI_UINTN)gNumTables64;␊ |
185 | ␉}␊ |
186 | ␉␊ |
187 | ␉// We only do adds, not modifications and deletes like InstallConfigurationTable␊ |
188 | ␉if (i >= MAX_CONFIGURATION_TABLE_ENTRIES)␊ |
189 | ␉{␊ |
190 | ␊ |
191 | ␉␉␊ |
192 | printf("Ran out of space for configuration tables (max = %d). Please, increase the reserved size in the code.\n", (int)MAX_CONFIGURATION_TABLE_ENTRIES);␊ |
193 | return EFI_ABORTED;␊ |
194 | } ␊ |
195 | ␊ |
196 | if (get_env(envarchCpuType) == CPU_TYPE_I386)␊ |
197 | ␉{ ␊ |
198 | ␊ |
199 | gEfiConfigurationTable32[i].VendorGuid = *pGuid;␊ |
200 | gEfiConfigurationTable32[i].VendorTable = (EFI_PTR32)table;␊ |
201 | ␊ |
202 | ␉␉gNumTables32++;␊ |
203 | ␉}␊ |
204 | ␉else␊ |
205 | ␉{ ␊ |
206 | gEfiConfigurationTable64[i].VendorGuid = *pGuid;␊ |
207 | gEfiConfigurationTable64[i].VendorTable = (EFI_PTR32)table;␊ |
208 | ␉␉gNumTables64++ ;␊ |
209 | ␉} ␊ |
210 | ␉␊ |
211 | ␊ |
212 | Node *tableNode = DT__AddChild(gEfiConfigurationTableNode, GuidStr);␊ |
213 | ␊ |
214 | // Use the pointer to the GUID we just stuffed into the system table␊ |
215 | DT__AddProperty(tableNode, "guid", sizeof(EFI_GUID), (void*)pGuid);␊ |
216 | ␊ |
217 | // The "table" property is the 32-bit (in our implementation) physical address of the table␊ |
218 | DT__AddProperty(tableNode, "table", sizeof(void*) * 2, table);␊ |
219 | ␊ |
220 | // Assume the alias pointer is a global or static piece of data␊ |
221 | if (alias != NULL)␊ |
222 | DT__AddProperty(tableNode, "alias", strlen(alias)+1, (char*)alias);␊ |
223 | ␊ |
224 | return EFI_SUCCESS;␊ |
225 | ␉␊ |
226 | }␊ |
227 | ␊ |
228 | static VOID EFI_ST_FIX_CRC32(void)␊ |
229 | {␊ |
230 | ␉if (get_env(envarchCpuType) == CPU_TYPE_I386)␊ |
231 | ␉{␊ |
232 | ␉␉gST32->Hdr.CRC32 = 0;␊ |
233 | ␉␉gST32->Hdr.CRC32 = crc32(0L, gST32, gST32->Hdr.HeaderSize);␊ |
234 | ␉}␊ |
235 | ␉else␊ |
236 | ␉{␊ |
237 | ␉␉gST64->Hdr.CRC32 = 0;␊ |
238 | ␉␉gST64->Hdr.CRC32 = crc32(0L, gST64, gST64->Hdr.HeaderSize);␊ |
239 | ␉}␊ |
240 | }␊ |
241 | ␊ |
242 | void finalizeEFIConfigTable(void )␊ |
243 | { ␊ |
244 | if (get_env(envarchCpuType) == CPU_TYPE_I386)␊ |
245 | ␉{␊ |
246 | ␉␉EFI_SYSTEM_TABLE_32 *efiSystemTable = gST32; ␊ |
247 | ␊ |
248 | efiSystemTable->NumberOfTableEntries = gNumTables32; ␊ |
249 | efiSystemTable->ConfigurationTable = (EFI_PTR32)gEfiConfigurationTable32;␊ |
250 | ␊ |
251 | ␉}␊ |
252 | ␉else␊ |
253 | ␉{␊ |
254 | ␉␉EFI_SYSTEM_TABLE_64 *efiSystemTable = gST64; ␊ |
255 | ␊ |
256 | efiSystemTable->NumberOfTableEntries = gNumTables64; ␊ |
257 | efiSystemTable->ConfigurationTable = ptov64((EFI_PTR32)gEfiConfigurationTable64); ␊ |
258 | ␊ |
259 | ␉}␊ |
260 | EFI_ST_FIX_CRC32();␊ |
261 | ␊ |
262 | #if DEBUG_EFI␊ |
263 | EFI_UINTN i;␊ |
264 | EFI_UINTN num = 0;␊ |
265 | uint32_t table ;␊ |
266 | EFI_GUID Guid;␊ |
267 | ␊ |
268 | if (get_env(envarchCpuType) == CPU_TYPE_I386)␊ |
269 | ␉{␊ |
270 | ␉␉num = gST32->NumberOfTableEntries; ␊ |
271 | ␊ |
272 | ␉}␊ |
273 | ␉else␊ |
274 | ␉{␊ |
275 | ␉␉num = (EFI_UINTN)gST64->NumberOfTableEntries; ␊ |
276 | ␊ |
277 | ␉}␊ |
278 | ␉msglog("EFI Configuration table :\n");␊ |
279 | for (i=0; i<num; i++)␊ |
280 | ␉{␊ |
281 | if (get_env(envarchCpuType) == CPU_TYPE_I386)␊ |
282 | {␊ |
283 | table = gEfiConfigurationTable32[i].VendorTable;␊ |
284 | Guid = gEfiConfigurationTable32[i].VendorGuid;␊ |
285 | ␊ |
286 | }␊ |
287 | else␊ |
288 | {␊ |
289 | table = gEfiConfigurationTable64[i].VendorTable;␊ |
290 | Guid = gEfiConfigurationTable64[i].VendorGuid;␊ |
291 | ␊ |
292 | }␊ |
293 | char id[4+1];␊ |
294 | bzero(id,sizeof(id)); ␊ |
295 | if (memcmp(&Guid, &gEfiSmbiosTableGuid, sizeof(EFI_GUID)) == 0)␊ |
296 | ␉␉{␊ |
297 | snprintf(id, sizeof(id),"%s", "_SM_");␊ |
298 | }␊ |
299 | ␉␉else if (memcmp(&Guid, &gEfiAcpiTableGuid, sizeof(EFI_GUID)) == 0)␊ |
300 | ␉␉{␊ |
301 | snprintf(id,sizeof(id), "%s", "RSD1");␊ |
302 | }␊ |
303 | ␉␉else if (memcmp(&Guid, &gEfiAcpi20TableGuid, sizeof(EFI_GUID)) == 0)␊ |
304 | ␉␉{␊ |
305 | snprintf(id, sizeof(id),"%s", "RSD2");␊ |
306 | }␊ |
307 | #ifndef NO_SMP_SUPPORT␊ |
308 | ␉␉else if (memcmp(&Guid, &gEfiMpsTableGuid, sizeof(EFI_GUID)) == 0)␊ |
309 | ␉␉{␊ |
310 | snprintf(id, sizeof(id),"%s", "_MP_");␊ |
311 | } ␊ |
312 | #endif␊ |
313 | ␉␉␊ |
314 | msglog("table [%d]:%s , 32Bit addr : 0x%x\n",i,id,table);␊ |
315 | ␊ |
316 | }␊ |
317 | msglog("\n");␊ |
318 | #endif␊ |
319 | ␊ |
320 | }␊ |
321 | ␊ |
322 | /*␊ |
323 | * What we do here is simply allocate a fake EFI system table and a fake EFI␊ |
324 | * runtime services table.␊ |
325 | *␊ |
326 | * Because we build against modern headers with kBootArgsRevision 4 we␊ |
327 | * also take care to set efiMode = 32.␊ |
328 | */␊ |
329 | ␊ |
330 | ␊ |
331 | #define pto(mode, addr) (mode == 64) ? ptov64((EFI_PTR32)addr) : (EFI_PTR32)addr␊ |
332 | ␊ |
333 | #define setupEfiTables(mode) \␊ |
334 | { \␊ |
335 | struct fake_efi_pages \␊ |
336 | {\␊ |
337 | /* We use the fake_efi_pages struct so that we only need to do one kernel␊ |
338 | * memory allocation for all needed EFI data. Otherwise, small allocations␊ |
339 | * like the FIRMWARE_VENDOR string would take up an entire page.␊ |
340 | * NOTE WELL: Do NOT assume this struct has any particular layout within itself.␊ |
341 | * It is absolutely not intended to be publicly exposed anywhere␊ |
342 | * We say pages (plural) although right now we are well within the 1 page size␊ |
343 | * and probably will stay that way.␊ |
344 | */\␊ |
345 | EFI_SYSTEM_TABLE_##mode efiSystemTable;\␊ |
346 | EFI_RUNTIME_SERVICES_##mode efiRuntimeServices;\␊ |
347 | EFI_CONFIGURATION_TABLE_##mode efiConfigurationTable[MAX_CONFIGURATION_TABLE_ENTRIES];\␊ |
348 | EFI_CHAR16 firmwareVendor[sizeof(FIRMWARE_VENDOR)/sizeof(EFI_CHAR16)];\␊ |
349 | uint8_t voidret_instructions[sizeof(VOIDRET_INSTRUCTIONS)/sizeof(uint8_t)];\␊ |
350 | uint8_t unsupportedret_instructions[sizeof(UNSUPPORTEDRET_INSTRUCTIONS)/sizeof(uint8_t)];\␊ |
351 | };\␊ |
352 | struct fake_efi_pages *fakeEfiPages = (struct fake_efi_pages*)AllocateKernelMemory(sizeof(struct fake_efi_pages));\␊ |
353 | /* Zero out all the tables in case fields are added later*/\␊ |
354 | bzero(fakeEfiPages, sizeof(struct fake_efi_pages));\␊ |
355 | /*--------------------------------------------------------------------␊ |
356 | * Initialize some machine code that will return EFI_UNSUPPORTED for␊ |
357 | * functions returning int and simply return for void functions.*/\␊ |
358 | memcpy(fakeEfiPages->voidret_instructions, VOIDRET_INSTRUCTIONS, sizeof(VOIDRET_INSTRUCTIONS));\␊ |
359 | memcpy(fakeEfiPages->unsupportedret_instructions, UNSUPPORTEDRET_INSTRUCTIONS, sizeof(UNSUPPORTEDRET_INSTRUCTIONS));\␊ |
360 | /*--------------------------------------------------------------------␊ |
361 | * System table*/\␊ |
362 | EFI_SYSTEM_TABLE_##mode *efiSystemTable = gST##mode = &fakeEfiPages->efiSystemTable;\␊ |
363 | efiSystemTable->Hdr.Signature = EFI_SYSTEM_TABLE_SIGNATURE;\␊ |
364 | efiSystemTable->Hdr.Revision = EFI_SYSTEM_TABLE_REVISION;\␊ |
365 | efiSystemTable->Hdr.HeaderSize = sizeof(EFI_SYSTEM_TABLE_##mode);\␊ |
366 | efiSystemTable->Hdr.CRC32 = 0;/*Initialize to zero and then do CRC32*/ \␊ |
367 | efiSystemTable->Hdr.Reserved = 0;\␊ |
368 | efiSystemTable->FirmwareVendor = pto(mode, &fakeEfiPages->firmwareVendor);\␊ |
369 | memcpy(fakeEfiPages->firmwareVendor, FIRMWARE_VENDOR, sizeof(FIRMWARE_VENDOR));\␊ |
370 | efiSystemTable->FirmwareRevision = FIRMWARE_REVISION;\␊ |
371 | /* XXX: We may need to have basic implementations of ConIn/ConOut/StdErr␊ |
372 | * The EFI spec states that all handles are invalid after boot services have been␊ |
373 | * exited so we can probably get by with leaving the handles as zero.␊ |
374 | */\␊ |
375 | efiSystemTable->ConsoleInHandle = 0;\␊ |
376 | efiSystemTable->ConIn = 0;\␊ |
377 | efiSystemTable->ConsoleOutHandle = 0;\␊ |
378 | efiSystemTable->ConOut = 0;\␊ |
379 | efiSystemTable->StandardErrorHandle = 0;\␊ |
380 | efiSystemTable->StdErr = 0;\␊ |
381 | efiSystemTable->RuntimeServices = pto(mode,&fakeEfiPages->efiRuntimeServices) ;\␊ |
382 | /* According to the EFI spec, BootServices aren't valid after the␊ |
383 | * boot process is exited so we can probably do without it.␊ |
384 | * Apple didn't provide a definition for it in pexpert/i386/efi.h␊ |
385 | * so I'm guessing they don't use it.␊ |
386 | */\␊ |
387 | efiSystemTable->BootServices = 0;\␊ |
388 | efiSystemTable->NumberOfTableEntries = 0;\␊ |
389 | efiSystemTable->ConfigurationTable = pto(mode,fakeEfiPages->efiConfigurationTable);\␊ |
390 | /* We're done. Now CRC32 the thing so the kernel will accept it.␊ |
391 | * Must be initialized to zero before CRC32, done above.␊ |
392 | */\␊ |
393 | gST##mode->Hdr.CRC32 = crc32(0L, gST##mode, gST##mode->Hdr.HeaderSize);\␊ |
394 | /*--------------------------------------------------------------------␊ |
395 | * Runtime services*/\␊ |
396 | EFI_RUNTIME_SERVICES_##mode *efiRuntimeServices = &fakeEfiPages->efiRuntimeServices;\␊ |
397 | efiRuntimeServices->Hdr.Signature = EFI_RUNTIME_SERVICES_SIGNATURE;\␊ |
398 | efiRuntimeServices->Hdr.Revision = EFI_RUNTIME_SERVICES_REVISION;\␊ |
399 | efiRuntimeServices->Hdr.HeaderSize = sizeof(EFI_RUNTIME_SERVICES_##mode);\␊ |
400 | efiRuntimeServices->Hdr.CRC32 = 0;\␊ |
401 | efiRuntimeServices->Hdr.Reserved = 0;\␊ |
402 | /* There are a number of function pointers in the efiRuntimeServices table.␊ |
403 | * These are the Foundation (e.g. core) services and are expected to be present on␊ |
404 | * all EFI-compliant machines.␉Some kernel extensions (notably AppleEFIRuntime)␊ |
405 | * will call these without checking to see if they are null.␊ |
406 | *␊ |
407 | * We don't really feel like doing an EFI implementation in the bootloader␊ |
408 | * but it is nice if we can at least prevent a complete crash by␊ |
409 | * at least providing some sort of implementation until one can be provided␊ |
410 | * nicely in a kext.␊ |
411 | */\␊ |
412 | void (*voidret_fp)() = (void*)fakeEfiPages->voidret_instructions;\␊ |
413 | void (*unsupportedret_fp)() = (void*)fakeEfiPages->unsupportedret_instructions;\␊ |
414 | efiRuntimeServices->GetTime = pto(mode,unsupportedret_fp);\␊ |
415 | efiRuntimeServices->SetTime = pto(mode,unsupportedret_fp);\␊ |
416 | efiRuntimeServices->GetWakeupTime = pto(mode,unsupportedret_fp);\␊ |
417 | efiRuntimeServices->SetWakeupTime = pto(mode,unsupportedret_fp);\␊ |
418 | efiRuntimeServices->SetVirtualAddressMap = pto(mode,unsupportedret_fp);\␊ |
419 | efiRuntimeServices->ConvertPointer = pto(mode,unsupportedret_fp);\␊ |
420 | efiRuntimeServices->GetVariable = pto(mode,unsupportedret_fp);\␊ |
421 | efiRuntimeServices->GetNextVariableName = pto(mode,unsupportedret_fp);\␊ |
422 | efiRuntimeServices->SetVariable = pto(mode,unsupportedret_fp);\␊ |
423 | efiRuntimeServices->GetNextHighMonotonicCount = pto(mode,unsupportedret_fp);\␊ |
424 | efiRuntimeServices->ResetSystem = pto(mode,voidret_fp);\␊ |
425 | /*We're done.␉Now CRC32 the thing so the kernel will accept it*/\␊ |
426 | efiRuntimeServices->Hdr.CRC32 = crc32(0L, efiRuntimeServices, efiRuntimeServices->Hdr.HeaderSize);\␊ |
427 | /*--------------------------------------------------------------------␊ |
428 | * Finish filling in the rest of the boot args that we need.*/\␊ |
429 | bootArgs->efiSystemTable = (uint32_t)efiSystemTable;\␊ |
430 | bootArgs->efiMode = kBootArgsEfiMode##mode;\␊ |
431 | /* The bootArgs structure as a whole is bzero'd so we don't need to fill in␊ |
432 | * things like efiRuntimeServices* and what not.␊ |
433 | *␊ |
434 | * In fact, the only code that seems to use that is the hibernate code so it␊ |
435 | * knows not to save the pages.␉ It even checks to make sure its nonzero.␊ |
436 | */\␊ |
437 | }␊ |
438 | ␊ |
439 | /*␊ |
440 | * In addition to the EFI tables there is also the EFI device tree node.␊ |
441 | * In particular, we need /efi/platform to have an FSBFrequency key. Without it,␊ |
442 | * the tsc_init function will panic very early on in kernel startup, before␊ |
443 | * the console is available.␊ |
444 | */␊ |
445 | ␊ |
446 | /*==========================================================================␊ |
447 | * FSB Frequency detection␊ |
448 | */␊ |
449 | ␊ |
450 | /* These should be const but DT__AddProperty takes char* */␊ |
451 | #if UNUSED␊ |
452 | static const char const TSC_Frequency_prop[] = "TSCFrequency";␊ |
453 | static const char const CPU_Frequency_prop[] = "CPUFrequency";␊ |
454 | #endif␊ |
455 | static const char const FSB_Frequency_prop[] = "FSBFrequency";␊ |
456 | ␊ |
457 | /*==========================================================================␊ |
458 | * SMBIOS␊ |
459 | */␊ |
460 | ␊ |
461 | static uint64_t smbios_p;␊ |
462 | ␊ |
463 | void Register_Smbios_Efi(void* smbios)␊ |
464 | {␊ |
465 | smbios_p = ((uint64_t)((uint32_t)smbios));␉␊ |
466 | }␊ |
467 | ␊ |
468 | /*==========================================================================␊ |
469 | * ACPI ␊ |
470 | */␊ |
471 | ␊ |
472 | static uint64_t local_rsd_p;␊ |
473 | static ACPI_TABLES acpi_tables;␊ |
474 | static uint64_t kFSBFrequency;␊ |
475 | static uint32_t␉␉kHardware_signature;␊ |
476 | static uint8_t␉␉kType;␊ |
477 | static uint32_t␉␉kAdler32;␊ |
478 | ␊ |
479 | EFI_STATUS Register_Acpi_Efi(void* rsd_p, unsigned char rev )␊ |
480 | {␊ |
481 | ␉EFI_STATUS Status = EFI_UNSUPPORTED;␊ |
482 | ␉local_rsd_p = ((U64)((U32)rsd_p));␊ |
483 | ␊ |
484 | ␉if (local_rsd_p) {␊ |
485 | ␉␉if (rev == 2)␊ |
486 | ␉␉{␊ |
487 | ␉␉␉Status = addConfigurationTable(&gEfiAcpi20TableGuid, &local_rsd_p, "ACPI_20");␊ |
488 | ␉␉}␊ |
489 | ␉␉else␊ |
490 | ␉␉{␊ |
491 | ␉␉␉Status = addConfigurationTable(&gEfiAcpiTableGuid, &local_rsd_p, "ACPI");␉␉␉␊ |
492 | ␉␉}␊ |
493 | ␉}␉␉␊ |
494 | ␉␊ |
495 | ␉return Status;␉␊ |
496 | }␊ |
497 | ␊ |
498 | /* Setup ACPI without any patch. */␊ |
499 | static EFI_STATUS setupAcpiNoMod()␊ |
500 | { ␉␊ |
501 | ␉EFI_STATUS ret = EFI_UNSUPPORTED;␊ |
502 | ␉␊ |
503 | ACPI_TABLE_RSDP* rsdp = (ACPI_TABLE_RSDP*)((uint32_t)local_rsd_p);␊ |
504 | if(rsdp->Revision > 0 && (GetChecksum(rsdp, sizeof(ACPI_TABLE_RSDP)) == 0))␊ |
505 | ␉{␊ |
506 | ␉␉ret = addConfigurationTable(&gEfiAcpi20TableGuid, &local_rsd_p, "ACPI_20");␉␉ ␊ |
507 | ␉}␊ |
508 | ␉else␊ |
509 | ␉{␊ |
510 | ␉␉ret = addConfigurationTable(&gEfiAcpiTableGuid, &local_rsd_p, "ACPI");␉␉␊ |
511 | ␉}␊ |
512 | ␉␊ |
513 | ␉return ret;␊ |
514 | }␊ |
515 | ␊ |
516 | EFI_STATUS setup_acpi (void)␊ |
517 | {␉␊ |
518 | ␉EFI_STATUS ret = EFI_UNSUPPORTED;␉␊ |
519 | ␉␊ |
520 | ␉do {␊ |
521 | if (!FindAcpiTables(&acpi_tables))␊ |
522 | {␊ |
523 | printf("Failed to detect ACPI tables.\n");␊ |
524 | ret = EFI_NOT_FOUND;␊ |
525 | break;␊ |
526 | }␊ |
527 | ␊ |
528 | local_rsd_p = ((uint64_t)((uint32_t)acpi_tables.RsdPointer));␊ |
529 | ␊ |
530 | {␊ |
531 | ACPI_TABLE_FADT *FacpPointer = (acpi_tables.FacpPointer64 != (void*)0ul) ? (ACPI_TABLE_FADT *)acpi_tables.FacpPointer64 : (ACPI_TABLE_FADT *)acpi_tables.FacpPointer;␊ |
532 | ␊ |
533 | uint8_t type = FacpPointer->PreferredProfile;␊ |
534 | if (type <= MaxSupportedPMProfile) ␊ |
535 | safe_set_env(envType,type);␊ |
536 | } ␊ |
537 | ␊ |
538 | ret = setupAcpiNoMod();␊ |
539 | ␉␉␊ |
540 | ␉} while (0);␉␊ |
541 | ␉␊ |
542 | ␉return ret;␉␊ |
543 | ␉␊ |
544 | }␊ |
545 | ␊ |
546 | /*==========================================================================␊ |
547 | * Fake EFI implementation␊ |
548 | */␊ |
549 | ␊ |
550 | /* These should be const but DT__AddProperty takes char* */␊ |
551 | static const char const FIRMWARE_REVISION_PROP[] = "firmware-revision";␊ |
552 | static const char const FIRMWARE_ABI_PROP[] = "firmware-abi";␊ |
553 | static const char const FIRMWARE_VENDOR_PROP[] = "firmware-vendor";␊ |
554 | static const char const FIRMWARE_NAME_PROP[] = "firmware-name";␊ |
555 | static const char const FIRMWARE_DATE_PROP[] = "firmware-date";␊ |
556 | static const char const FIRMWARE_DEV_PROP[] = "firmware-maintener";␊ |
557 | static const char const FIRMWARE_PUBLISH_PROP[] = "firmware-publisher";␊ |
558 | ␊ |
559 | ␊ |
560 | static const char const FIRMWARE_ABI_32_PROP_VALUE[] = "EFI32";␊ |
561 | static const char const FIRMWARE_ABI_64_PROP_VALUE[] = "EFI64";␊ |
562 | static const char const SYSTEM_ID_PROP[] = "system-id";␊ |
563 | static const char const SYSTEM_SERIAL_PROP[] = "SystemSerialNumber";␊ |
564 | static const char const SYSTEM_TYPE_PROP[] = "system-type";␊ |
565 | static const char const MODEL_PROP[] = "Model";␊ |
566 | static const char const MOTHERBOARD_NAME_PROP[] = "motherboard-name";␊ |
567 | ␊ |
568 | ␊ |
569 | /*␊ |
570 | * Get an smbios option string option to convert to EFI_CHAR16 string␊ |
571 | */␊ |
572 | ␊ |
573 | static EFI_CHAR16* getSmbiosChar16(const char * key, size_t* len)␊ |
574 | {␊ |
575 | ␉if (!GetgPlatformName() && strcmp(key, "SMproductname") == 0)␊ |
576 | ␉␉readSMBIOS(thePlatformName);␊ |
577 | ␉␊ |
578 | ␉const char␉*PlatformName = GetgPlatformName() ;␊ |
579 | ␉␊ |
580 | ␉const char␉*src = (strcmp(key, "SMproductname") == 0) ? PlatformName : getStringForKey(key, DEFAULT_SMBIOS_CONFIG);␊ |
581 | ␉␊ |
582 | ␉EFI_CHAR16*␉ dst = 0;␉␊ |
583 | ␉␊ |
584 | ␉if (!key || !(*key) || !src) return 0;␊ |
585 | ␉␊ |
586 | int tmp_len = strlen(src);␊ |
587 | ␊ |
588 | ␉dst = (EFI_CHAR16*) malloc( ((tmp_len)+1) * 2 );␊ |
589 | if (!dst) ␊ |
590 | {␊ |
591 | *len = 0;␊ |
592 | return NULL;␊ |
593 | }␊ |
594 | ␊ |
595 | *len = tmp_len;␊ |
596 | ␉{␊ |
597 | ␉␉size_t␉␉ i = 0;␊ |
598 | ␉␉for (; i < (*len); i++)␉ dst[i] = src[i];␊ |
599 | ␉}␊ |
600 | ␉dst[(*len)] = '\0';␊ |
601 | ␉*len = ((*len)+1)*2; // return the CHAR16 bufsize in cluding zero terminated CHAR16␊ |
602 | ␉return dst;␊ |
603 | }␊ |
604 | ␊ |
605 | /*␊ |
606 | * Get the SystemID from the bios dmi info␊ |
607 | */␊ |
608 | ␊ |
609 | static EFI_CHAR8* getSmbiosUUID()␊ |
610 | {␊ |
611 | ␉static EFI_CHAR8␉␉ uuid[UUID_LEN];␊ |
612 | ␉int␉␉␉␉␉␉ i, isZero, isOnes;␊ |
613 | ␉SMBByte␉␉␉␉␉*p;␉␉␊ |
614 | ␉␊ |
615 | p = (SMBByte*)(uint32_t)get_env(envUUID);␊ |
616 | ␊ |
617 | if ( p == NULL )␊ |
618 | ␉{␊ |
619 | DBG("No patched UUID found, fallback to original UUID (if exist) \n");␊ |
620 | ␉␉␊ |
621 | readSMBIOS(theUUID);␉␉␊ |
622 | p = (SMBByte*)(uint32_t)get_env(envUUID);␊ |
623 | ␊ |
624 | }␊ |
625 | ␊ |
626 | ␉for (i=0, isZero=1, isOnes=1; i<UUID_LEN; i++)␊ |
627 | ␉{␊ |
628 | ␉␉if (p[i] != 0x00) isZero = 0;␊ |
629 | ␉␉if (p[i] != 0xff) isOnes = 0;␊ |
630 | ␉}␊ |
631 | ␉␊ |
632 | ␉if (isZero || isOnes) // empty or setable means: no uuid present␊ |
633 | ␉{␊ |
634 | ␉␉verbose("No UUID present in SMBIOS System Information Table\n");␊ |
635 | ␉␉return 0;␊ |
636 | ␉} ␊ |
637 | #if DEBUG_EFI␊ |
638 | ␉else␊ |
639 | ␉␉verbose("Found UUID in SMBIOS System Information Table\n");␊ |
640 | #endif␊ |
641 | ␉␊ |
642 | ␉memcpy(uuid, p, UUID_LEN);␊ |
643 | ␉return uuid;␊ |
644 | }␊ |
645 | ␊ |
646 | /*␊ |
647 | * return a binary UUID value from the overriden SystemID and SMUUID if found, ␊ |
648 | * or from the bios if not, or from a fixed value if no bios value is found ␊ |
649 | */␊ |
650 | ␊ |
651 | static int8_t *getSystemID()␊ |
652 | {␊ |
653 | static int8_t␉␉␉␉sysid[16];␊ |
654 | ␉// unable to determine UUID for host. Error: 35 fix␊ |
655 | ␉// Rek: new SMsystemid option conforming to smbios notation standards, this option should␊ |
656 | ␉// belong to smbios config only ...␊ |
657 | ␉EFI_CHAR8*␉ret = getUUIDFromString(getStringForKey(kSystemID, DEFAULT_BOOT_CONFIG));␊ |
658 | ␉␊ |
659 | ␉if (!ret) // try bios dmi info UUID extraction␉␊ |
660 | ␉␉ret = getSmbiosUUID();␊ |
661 | ␉␊ |
662 | ␉if (!ret)␊ |
663 | ␉{␊ |
664 | ␉␉// no bios dmi UUID available, set a fixed value for system-id␊ |
665 | ␉␉ret=getUUIDFromString((const char*) SYSTEM_ID);␊ |
666 | ␉␉verbose("Customizing SystemID with : %s\n", getStringFromUUID(ret)); // apply a nice formatting to the displayed output␊ |
667 | ␉}␊ |
668 | ␉else␉␊ |
669 | ␉{␊ |
670 | ␉␉const char *mac = getStringFromUUID(ret);␊ |
671 | ␉␉verbose("MAC address : %c%c:%c%c:%c%c:%c%c:%c%c:%c%c\n",mac[24],mac[25],mac[26],mac[27],mac[28],mac[29]␊ |
672 | ␉␉␉␉,mac[30],mac[31],mac[32],mac[33],mac[34],mac[35]);␉␉ ␊ |
673 | ␉␉␊ |
674 | ␉}␊ |
675 | ␉␊ |
676 | ␉if (ret)␊ |
677 | ␉{ ␊ |
678 | ␉␉memcpy(sysid, ret, UUID_LEN);␊ |
679 | set_env_copy(envSysId, sysid, sizeof(sysid));␊ |
680 | ␉}␊ |
681 | ␉␊ |
682 | ␉return sysid;␊ |
683 | }␊ |
684 | ␊ |
685 | /*␊ |
686 | * Must be called AFTER setup Acpi because we need to take care of correct␊ |
687 | * facp content to reflect in ioregs␊ |
688 | */␊ |
689 | ␊ |
690 | static VOID setupSystemType()␊ |
691 | {␊ |
692 | ␉Node *node = DT__FindNode("/", false);␊ |
693 | ␉if (node == 0) stop("Couldn't get root node");␊ |
694 | ␉// we need to write this property after facp parsing␊ |
695 | ␉// Export system-type only if it has been overrriden by the SystemType option␊ |
696 | kType = get_env(envType);␊ |
697 | ␉DT__AddProperty(node, SYSTEM_TYPE_PROP, sizeof(uint8_t), &kType);␊ |
698 | }␊ |
699 | ␊ |
700 | static VOID setupEfiDeviceTree(void)␊ |
701 | {␉␊ |
702 | ␉Node␉␉*node;␊ |
703 | ␉␊ |
704 | ␉node = DT__FindNode("/", false);␊ |
705 | ␉␊ |
706 | ␉if (node == 0) stop("Couldn't get root node");␊ |
707 | ␊ |
708 | #ifndef NO_BOOT_IMG␊ |
709 | ␉{␊ |
710 | ␉␉long size;␊ |
711 | ␉␉{␊ |
712 | #include "appleClut8.h"␊ |
713 | ␉␉␉size = sizeof(appleClut8);␊ |
714 | ␉␉␉long clut = AllocateKernelMemory(size);␊ |
715 | ␉␉␉bcopy(&appleClut8, (void*)clut, size);␊ |
716 | ␊ |
717 | if (((BVRef)(uint32_t)get_env(envgBootVolume))->OSVersion[3] == '8') ␊ |
718 | {␊ |
719 | AllocateMemoryRange( "FailedCLUT", clut, size);␊ |
720 | ␊ |
721 | } else␊ |
722 | AllocateMemoryRange( "BootCLUT", clut, size);␊ |
723 | ␉␉␉␊ |
724 | ␉␉}␊ |
725 | ␉␉␊ |
726 | ␉␉{␊ |
727 | #include "failedboot.h"␉␊ |
728 | ␉␉␉size = 32 + kFailedBootWidth * kFailedBootHeight;␊ |
729 | ␉␉␉long bootPict = AllocateKernelMemory(size);␊ |
730 | if (((BVRef)(uint32_t)get_env(envgBootVolume))->OSVersion[3] == '8') ␊ |
731 | {␊ |
732 | AllocateMemoryRange( "FailedImage", bootPict, size); ␊ |
733 | ␊ |
734 | } else␊ |
735 | AllocateMemoryRange( "Pict-FailedBoot", bootPict, size); ␊ |
736 | ␊ |
737 | ␉␉␉((boot_progress_element *)bootPict)->width = kFailedBootWidth;␊ |
738 | ␉␉␉((boot_progress_element *)bootPict)->height = kFailedBootHeight;␊ |
739 | ␉␉␉((boot_progress_element *)bootPict)->yOffset = kFailedBootOffset;␉␊ |
740 | ␉␉␉if (((BVRef)(uint32_t)get_env(envgBootVolume))->OSVersion[3] == '8') ␊ |
741 | {␊ |
742 | ((boot_progress_element *)bootPict)->data_size = size - 32; ␊ |
743 | }␊ |
744 | ␉␉␉bcopy((char *)gFailedBootPict, (char *)(bootPict + 32), size - 32);␊ |
745 | ␉␉}␊ |
746 | ␉}␊ |
747 | #endif␊ |
748 | ␉//Fix an error with the Lion's (DP2+) installer␉␊ |
749 | ␉if (execute_hook("getboardproductPatched", NULL, NULL, NULL, NULL, NULL, NULL) != EFI_SUCCESS)␊ |
750 | ␉{␊ |
751 | ␉␉Setgboardproduct(getStringForKey("SMboardproduct", DEFAULT_SMBIOS_CONFIG));␊ |
752 | ␉␉␊ |
753 | ␉␉if (!Getgboardproduct()) readSMBIOS(theProducBoard);␊ |
754 | ␉␉␊ |
755 | ␉}␊ |
756 | ␉if (Getgboardproduct())␊ |
757 | ␉{␊ |
758 | ␉␉DT__AddProperty(node, "board-id", strlen(Getgboardproduct())+1, Getgboardproduct());␊ |
759 | ␉}␊ |
760 | ␉␊ |
761 | ␉{␊ |
762 | ␉␉Node *chosenNode = DT__FindNode("/chosen", true);␊ |
763 | ␉␉if (chosenNode)␊ |
764 | ␉␉{␉␉␉␊ |
765 | ␉␉␉DT__AddProperty(chosenNode, "boot-args", strlen(bootArgs->CommandLine)+1, (EFI_CHAR16*)bootArgs->CommandLine);␊ |
766 | ␉␉␉␊ |
767 | ␉␉␉// "boot-uuid" MAIN GOAL IS SYMPLY TO BOOT FROM THE UUID SET IN THE DT AND DECREASE BOOT TIME, SEE IOKitBSDInit.cpp␊ |
768 | ␉␉␉// additionally this value can be used by third-party apps or osx components (ex: pre-10.7 kextcache, ...)␊ |
769 | ␉␉␉if (bootInfo->uuidStr[0]) ␉␉␉␊ |
770 | ␉␉␉␉DT__AddProperty(chosenNode, kBootUUIDKey, strlen(bootInfo->uuidStr)+1, bootInfo->uuidStr);␊ |
771 | ␉␉␉␊ |
772 | ␉␉␉if (GetgRootDevice())␊ |
773 | ␉␉␉{␊ |
774 | ␉␉␉␉␊ |
775 | ␉␉␉␉DT__AddProperty(chosenNode, "boot-device-path", strlen(GetgRootDevice())+1, GetgRootDevice());␉␉␉␊ |
776 | ␉␉␉␉␊ |
777 | ␉␉␉}␉␉␉␊ |
778 | #ifdef rootpath␊ |
779 | ␉␉␉else␊ |
780 | ␉␉␉␉if (gRootPath[0])␊ |
781 | ␉␉␉␉{␊ |
782 | ␉␉␉␉␉␊ |
783 | ␉␉␉␉␉DT__AddProperty(chosenNode, "rootpath", strlen(gRootPath)+1, gRootPath);␉␉␉␊ |
784 | ␉␉␉␉␉␊ |
785 | ␉␉␉␉} ␊ |
786 | ␊ |
787 | #endif␊ |
788 | ␉␉␉␊ |
789 | ␉␉␉// "boot-file" is not used by kextcache if there is no "boot-device-path" or if there is a valid "rootpath" ,␊ |
790 | ␉␉␉// but i let it by default since it may be used by another service␊ |
791 | ␉␉␉DT__AddProperty(chosenNode, "boot-file", strlen(bootInfo->bootFile)+1, (EFI_CHAR16*)bootInfo->bootFile);␉␉␉␊ |
792 | ␉␉␉␊ |
793 | ␉␉␉if ((kAdler32 = (uint32_t)get_env(envAdler32))) ␊ |
794 | ␉␉␉␉DT__AddProperty(chosenNode, "boot-kernelcache-adler32", sizeof(unsigned long), &kAdler32);␊ |
795 | ␉␉␉␊ |
796 | ␉␉}␊ |
797 | ␉}␉␊ |
798 | ␉␊ |
799 | ␉// We could also just do DT__FindNode("/efi/platform", true)␊ |
800 | ␉// But I think eventually we want to fill stuff in the efi node␊ |
801 | ␉// too so we might as well create it so we have a pointer for it too.␊ |
802 | ␉Node *efiNode = DT__AddChild(node, "efi");␊ |
803 | ␉␊ |
804 | ␉{␊ |
805 | ␉␉// Set up the /efi/runtime-services table node similar to the way a child node of configuration-table␊ |
806 | ␉␉// is set up. That is, name and table properties␊ |
807 | ␉␉Node *runtimeServicesNode = DT__AddChild(efiNode, "runtime-services");␉␉␊ |
808 | ␉␉Node *kernelCompatibilityNode = 0; // ??? not sure that it should be used like that (because it's maybe the kernel capability and not the cpu capability)␊ |
809 | ␉␉␊ |
810 | ␉␉if (((BVRef)(uint32_t)get_env(envgBootVolume))->OSVersion[3] > '6')␊ |
811 | ␉␉{␊ |
812 | ␉␉␉kernelCompatibilityNode = DT__AddChild(efiNode, "kernel-compatibility");␉␊ |
813 | ␉␉␉DT__AddProperty(kernelCompatibilityNode, "i386", sizeof(uint32_t), (EFI_UINT32*)&DEVICE_SUPPORTED);␊ |
814 | ␉␉}␊ |
815 | ␉␉␊ |
816 | ␉␉if (get_env(envarchCpuType) == CPU_TYPE_I386)␊ |
817 | ␉␉{␊ |
818 | ␉␉␉// The value of the table property is the 32-bit physical address for the RuntimeServices table.␊ |
819 | ␉␉␉// Since the EFI system table already has a pointer to it, we simply use the address of that pointer␊ |
820 | ␉␉␉// for the pointer to the property data. Warning.. DT finalization calls free on that but we're not␊ |
821 | ␉␉␉// the only thing to use a non-malloc'd pointer for something in the DT␊ |
822 | ␉␉␉␊ |
823 | ␉␉␉DT__AddProperty(runtimeServicesNode, "table", sizeof(uint64_t), &gST32->RuntimeServices);␊ |
824 | ␉␉␉DT__AddProperty(efiNode, FIRMWARE_ABI_PROP, sizeof(FIRMWARE_ABI_32_PROP_VALUE), (char*)FIRMWARE_ABI_32_PROP_VALUE);␊ |
825 | ␉␉}␊ |
826 | ␉␉else␊ |
827 | ␉␉{␊ |
828 | ␉␉␉if (kernelCompatibilityNode) ␊ |
829 | ␉␉␉␉DT__AddProperty(kernelCompatibilityNode, "x86_64", sizeof(uint32_t), (EFI_UINT32*)&DEVICE_SUPPORTED);␊ |
830 | ␉␉␉␊ |
831 | ␉␉␉DT__AddProperty(runtimeServicesNode, "table", sizeof(uint64_t), &gST64->RuntimeServices);␊ |
832 | ␉␉␉DT__AddProperty(efiNode, FIRMWARE_ABI_PROP, sizeof(FIRMWARE_ABI_64_PROP_VALUE), (char*)FIRMWARE_ABI_64_PROP_VALUE);␊ |
833 | ␉␉}␊ |
834 | ␉}␊ |
835 | ␉␊ |
836 | ␉DT__AddProperty(efiNode, FIRMWARE_REVISION_PROP, sizeof(FIRMWARE_REVISION), (EFI_UINT32*)&FIRMWARE_REVISION);␊ |
837 | ␉DT__AddProperty(efiNode, FIRMWARE_VENDOR_PROP, sizeof(FIRMWARE_VENDOR), (EFI_CHAR16*)FIRMWARE_VENDOR);␊ |
838 | ␉DT__AddProperty(efiNode, FIRMWARE_NAME_PROP, sizeof(FIRMWARE_NAME), (EFI_CHAR16*)FIRMWARE_NAME);␊ |
839 | ␉DT__AddProperty(efiNode, FIRMWARE_DATE_PROP, strlen(I386BOOT_BUILDDATE)+1, I386BOOT_BUILDDATE);␉␊ |
840 | ␉DT__AddProperty(efiNode, FIRMWARE_DEV_PROP, strlen(FIRMWARE_MAINTENER)+1, FIRMWARE_MAINTENER);␊ |
841 | ␉DT__AddProperty(efiNode, FIRMWARE_PUBLISH_PROP, strlen(FIRMWARE_PUBLISHER)+1, FIRMWARE_PUBLISHER);␊ |
842 | ␉␊ |
843 | ␉{␊ |
844 | ␉␉// Export it for amlsgn support␊ |
845 | ␉␉char * DefaultPlatform = readDefaultPlatformName();␊ |
846 | ␉␉if (DefaultPlatform)␊ |
847 | ␉␉{␊ |
848 | ␉␉␉DT__AddProperty(efiNode, MOTHERBOARD_NAME_PROP, strlen(DefaultPlatform)+1, DefaultPlatform);␊ |
849 | ␉␉}␊ |
850 | ␉␉␊ |
851 | ␉}␊ |
852 | ␉␊ |
853 | ␉// Set up the /efi/configuration-table node which will eventually have several child nodes for␊ |
854 | ␉// all of the configuration tables needed by various kernel extensions.␊ |
855 | ␉gEfiConfigurationTableNode = DT__AddChild(efiNode, "configuration-table");␊ |
856 | ␉␊ |
857 | ␉{␊ |
858 | ␉␉EFI_CHAR16 *serial = 0, *productname = 0;␊ |
859 | int8_t␉␉␉␉*sysid = 0;␊ |
860 | ␉␉size_t␉␉ len = 0;␊ |
861 | ␉␉␊ |
862 | ␉␉// Now fill in the /efi/platform Node␊ |
863 | ␉␉Node *efiPlatformNode = DT__AddChild(efiNode, "platform");␊ |
864 | ␉␉␊ |
865 | ␉␉DT__AddProperty(efiPlatformNode, "DevicePathsSupported", sizeof(uint32_t), (EFI_UINT32*)&DEVICE_SUPPORTED);␊ |
866 | ␉␉␊ |
867 | ␉␉// NOTE WELL: If you do add FSB Frequency detection, make sure to store␊ |
868 | ␉␉// the value in the fsbFrequency global and not an malloc'd pointer␊ |
869 | ␉␉// because the DT_AddProperty function does not copy its args.␊ |
870 | ␉␉␊ |
871 | kFSBFrequency = get_env(envFSBFreq);␊ |
872 | ␉␉if (kFSBFrequency != 0)␊ |
873 | ␉␉␉DT__AddProperty(efiPlatformNode, FSB_Frequency_prop, sizeof(uint64_t), &kFSBFrequency);␉␉␊ |
874 | ␉␉␊ |
875 | #if UNUSED␊ |
876 | ␉␉// Export TSC and CPU frequencies for use by the kernel or KEXTs␊ |
877 | ␉␉Platform.CPU.TSCFrequency = get_env(envTSCFreq);␊ |
878 | if (Platform.CPU.TSCFrequency != 0)␊ |
879 | ␉␉␉DT__AddProperty(efiPlatformNode, TSC_Frequency_prop, sizeof(uint64_t), &Platform.CPU.TSCFrequency);␊ |
880 | ␉␉␊ |
881 | Platform.CPU.CPUFrequency = get_env(envCPUFreq);␊ |
882 | ␉␉if (Platform.CPU.CPUFrequency != 0)␊ |
883 | ␉␉␉DT__AddProperty(efiPlatformNode, CPU_Frequency_prop, sizeof(uint64_t), &Platform.CPU.CPUFrequency);␊ |
884 | #endif␊ |
885 | ␉␉␊ |
886 | ␉␉// Export system-id. Can be disabled with SystemId=No in com.apple.Boot.plist␉␉␊ |
887 | ␉␉if ((sysid = getSystemID()))␊ |
888 | ␉␉␉DT__AddProperty(efiPlatformNode, SYSTEM_ID_PROP, UUID_LEN, (EFI_UINT32*) sysid);␊ |
889 | ␉␉␊ |
890 | ␉␉// Export SystemSerialNumber if present␊ |
891 | ␉␉if ((serial=getSmbiosChar16("SMserial", &len)))␊ |
892 | ␉␉␉DT__AddProperty(efiPlatformNode, SYSTEM_SERIAL_PROP, len, serial);␊ |
893 | ␉␉␊ |
894 | ␉␉// Export Model if present␊ |
895 | ␉␉if ((productname=getSmbiosChar16("SMproductname", &len)))␊ |
896 | ␉␉␉DT__AddProperty(efiPlatformNode, MODEL_PROP, len, productname);␊ |
897 | ␉}␉␉␊ |
898 | ␉␊ |
899 | ␉// Fill /efi/device-properties node.␉␉␉␊ |
900 | ␉setupDeviceProperties(efiNode);␊ |
901 | }␊ |
902 | ␊ |
903 | /*␊ |
904 | * Load the smbios.plist override config file if any␊ |
905 | */␊ |
906 | ␊ |
907 | void setupSmbiosConfigFile(const char *filename)␊ |
908 | {␉␊ |
909 | ␉static bool readSmbConfigFile = true;␊ |
910 | ␉␊ |
911 | ␉if (readSmbConfigFile == true)␊ |
912 | ␉{␊ |
913 | ␉␉char␉␉dirSpecSMBIOS[128] = "";␊ |
914 | ␉␉const char *override_pathname = NULL;␊ |
915 | ␉␉int␉␉␉len = 0, err = 0;␊ |
916 | ␉␉␊ |
917 | ␉␉// Take in account user overriding␊ |
918 | ␉␉if (getValueForKey("SMBIOS", &override_pathname, &len, DEFAULT_BOOT_CONFIG) && len > 0)␊ |
919 | ␉␉{␊ |
920 | ␉␉␉// Specify a path to a file, e.g. SMBIOS=/Extra/macProXY.plist␊ |
921 | ␉␉␉snprintf(dirSpecSMBIOS, sizeof(dirSpecSMBIOS),override_pathname);␊ |
922 | ␉␉␉err = loadConfigFile(dirSpecSMBIOS, DEFAULT_SMBIOS_CONFIG);␊ |
923 | ␉␉}␊ |
924 | ␉␉else␊ |
925 | ␉␉{␊ |
926 | ␉␉␉// Check selected volume's Extra.␊ |
927 | ␉␉␉snprintf(dirSpecSMBIOS, sizeof(dirSpecSMBIOS),"/Extra/%s", filename);␊ |
928 | ␉␉␉if ((err = loadConfigFile(dirSpecSMBIOS, DEFAULT_SMBIOS_CONFIG)))␊ |
929 | ␉␉␉{␊ |
930 | ␉␉␉␉// Check booter volume/rdbt Extra.␊ |
931 | ␉␉␉␉snprintf(dirSpecSMBIOS, sizeof(dirSpecSMBIOS),"bt(0,0)/Extra/%s", filename);␊ |
932 | ␉␉␉␉err = loadConfigFile(dirSpecSMBIOS, DEFAULT_SMBIOS_CONFIG);␊ |
933 | ␉␉␉}␊ |
934 | ␉␉}␊ |
935 | ␉␉␊ |
936 | ␉␉if (err)␊ |
937 | ␉␉{␊ |
938 | ␉␉␉verbose("No SMBIOS config file found.\n");␊ |
939 | ␉␉}␊ |
940 | ␉␉readSmbConfigFile = false;␊ |
941 | ␉}␊ |
942 | }␊ |
943 | ␊ |
944 | static VOID setup_Smbios()␊ |
945 | {␉␉␉␊ |
946 | ␉if (execute_hook("getSmbiosPatched",NULL, NULL, NULL, NULL, NULL, NULL) != EFI_SUCCESS)␊ |
947 | ␉{␊ |
948 | ␉␉DBG("Using the original SMBIOS !!\n");␉␊ |
949 | struct SMBEntryPoint *smbios_o = getSmbiosOriginal();␉␊ |
950 | smbios_p = ((uint64_t)((uint32_t)smbios_o)); ␊ |
951 | ␉}␉␊ |
952 | }␊ |
953 | ␊ |
954 | static VOID setup_machine_signature()␊ |
955 | {␊ |
956 | ␉Node *chosenNode = DT__FindNode("/chosen", false);␊ |
957 | ␉if (chosenNode)␊ |
958 | ␉{␊ |
959 | ␉␉if (get_env(envHardwareSignature) == 0xFFFFFFFF)␊ |
960 | ␉␉{␉␉␉␊ |
961 | ␉␉␉do {␊ |
962 | ␉␉␉␉if (!local_rsd_p)␊ |
963 | ␉␉␉␉{␉␉␉␊ |
964 | ␉␉␉␉␉if (!FindAcpiTables(&acpi_tables)){␊ |
965 | ␉␉␉␉␉␉printf("Failed to detect ACPI tables.\n");␊ |
966 | ␉␉␉␉␉␉break;␊ |
967 | ␉␉␉␉␉}␊ |
968 | ␉␉␉␉␉␊ |
969 | ␉␉␉␉␉local_rsd_p = ((uint64_t)((uint32_t)acpi_tables.RsdPointer));␊ |
970 | ␉␉␉␉}␊ |
971 | ␉␉␉␉␊ |
972 | ␉␉␉␉ACPI_TABLE_FACS *FacsPointer = (acpi_tables.FacsPointer64 != (void*)0ul) ? (ACPI_TABLE_FACS *)acpi_tables.FacsPointer64:(ACPI_TABLE_FACS *)acpi_tables.FacsPointer;␉␉␉␉␊ |
973 | ␊ |
974 | safe_set_env(envHardwareSignature , FacsPointer->HardwareSignature);␊ |
975 | ␉␉␉␉␊ |
976 | ␉␉␉} while (0); ␉␊ |
977 | ␉␉␉␊ |
978 | ␉␉␉// Verify that we have a valid hardware signature␊ |
979 | ␉␉␉if (get_env(envHardwareSignature) == 0xFFFFFFFF) ␊ |
980 | ␉␉␉{␊ |
981 | ␉␉␉␉verbose("Warning: hardware_signature is invalid, defaulting to 0 \n"); ␊ |
982 | safe_set_env(envHardwareSignature , 0);␊ |
983 | ␉␉␉}␊ |
984 | ␉␉}␊ |
985 | ␉␉␊ |
986 | kHardware_signature = get_env(envHardwareSignature); ␊ |
987 | ␉␉DT__AddProperty(chosenNode, "machine-signature", sizeof(uint32_t), &kHardware_signature);␊ |
988 | ␉}␊ |
989 | ␉␊ |
990 | }␊ |
991 | ␊ |
992 | /*␊ |
993 | * Installs all the needed configuration table entries␊ |
994 | */␊ |
995 | ␊ |
996 | static VOID setupEfiConfigurationTable()␊ |
997 | {␊ |
998 | if (smbios_p)␊ |
999 | addConfigurationTable(&gEfiSmbiosTableGuid, &smbios_p, NULL);␊ |
1000 | #ifndef NO_SMP_SUPPORT␊ |
1001 | ␉if (get_env(envVendor) == CPUID_VENDOR_INTEL )␊ |
1002 | ␉{␊ |
1003 | ␉␉int num_cpus;␊ |
1004 | ␉␉␊ |
1005 | ␉␉void *mps_p = imps_probe(&num_cpus);␊ |
1006 | ␉␉␊ |
1007 | ␉␉if (mps_p)␊ |
1008 | ␉␉{␉␉␊ |
1009 | ␉␉␉addConfigurationTable(&gEfiMpsTableGuid, ((uint64_t*)((uint32_t)mps_p)), NULL);␊ |
1010 | ␉␉}␊ |
1011 | ␉␉␊ |
1012 | #if DEBUG_EFI␊ |
1013 | if (num_cpus != get_env(envNoCores))␊ |
1014 | {␊ |
1015 | printf("Warning: SMP nb of core (%d) mismatch with the value found in cpu.c (%d) \n",num_cpus,get_env(envNoCores)); ␊ |
1016 | } ␊ |
1017 | #endif ␊ |
1018 | ␉}␉␊ |
1019 | #endif␊ |
1020 | ␉// PM_Model␊ |
1021 | ␉if (get_env(envIsServer))␊ |
1022 | {␊ |
1023 | safe_set_env(envType , Workstation);␊ |
1024 | ␉}␊ |
1025 | ␉else if (get_env(envIsMobile))//Slice␊ |
1026 | ␉{␉␊ |
1027 | safe_set_env(envType , Mobile);␊ |
1028 | ␉} ␊ |
1029 | ␉else␊ |
1030 | ␉{␊ |
1031 | safe_set_env(envType , Desktop);␊ |
1032 | ␉}␊ |
1033 | ␉␊ |
1034 | ␉// Invalidate the platform hardware signature (this needs to be verified with acpica, but i guess that 0xFFFFFFFF is an invalid signature) ␉␊ |
1035 | safe_set_env(envHardwareSignature , 0xFFFFFFFF);␊ |
1036 | ␉␊ |
1037 | ␉// Setup ACPI (based on the mackerintel's patch)␊ |
1038 | ␉(VOID)setup_acpi();␊ |
1039 | ␉␊ |
1040 | ␉setup_machine_signature();␊ |
1041 | ␉␊ |
1042 | ␉// We now have to write the system-type in ioregs: we cannot do it before in setupDeviceTree()␊ |
1043 | ␉// because we need to take care of facp original content, if it is correct.␊ |
1044 | ␉setupSystemType();␊ |
1045 | ␉␊ |
1046 | ␉// We've obviously changed the count.. so fix up the CRC32␉␊ |
1047 | EFI_ST_FIX_CRC32();␊ |
1048 | }␊ |
1049 | ␊ |
1050 | /*␊ |
1051 | * Entrypoint from boot.c␊ |
1052 | */␊ |
1053 | ␊ |
1054 | void setupFakeEfi(void)␊ |
1055 | {␊ |
1056 | ␉// Collect PCI info &| Generate device prop string␊ |
1057 | ␉setup_pci_devs(root_pci_dev);␊ |
1058 | ␉␊ |
1059 | ␉// load smbios.plist file if any␊ |
1060 | ␉setupSmbiosConfigFile("SMBIOS.plist");␊ |
1061 | ␉setup_Smbios();␊ |
1062 | ␉␊ |
1063 | ␉// Initialize the base table␊ |
1064 | ␉if (get_env(envarchCpuType) == CPU_TYPE_I386)␊ |
1065 | ␉{␊ |
1066 | ␉␉setupEfiTables(32); ␊ |
1067 | ␉}␊ |
1068 | ␉else␊ |
1069 | ␉{␊ |
1070 | ␉␉setupEfiTables(64); ␊ |
1071 | ␉}␊ |
1072 | ␉␊ |
1073 | ␉// Initialize the device tree␊ |
1074 | ␉setupEfiDeviceTree();␊ |
1075 | ␉␊ |
1076 | ␉// Add configuration table entries to both the services table and the device tree␊ |
1077 | ␉setupEfiConfigurationTable();␉␉␊ |
1078 | ␉␊ |
1079 | } |