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