1 | ␊ |
2 | /*␊ |
3 | * Copyright 2007 David F. Elliott.␉ All rights reserved.␊ |
4 | */␊ |
5 | //#include "saio_types.h"␊ |
6 | //#include "libsaio.h"␊ |
7 | #include "boot.h"␊ |
8 | #include "bootstruct.h"␊ |
9 | #include "efi.h"␊ |
10 | #include "acpi.h"␊ |
11 | #include "fake_efi.h"␊ |
12 | #include "efi_tables.h"␊ |
13 | #include "platform.h"␊ |
14 | #include "acpi_patcher.h"␊ |
15 | #include "smbios.h"␊ |
16 | #include "device_inject.h"␊ |
17 | #include "convert.h"␊ |
18 | #include "pci.h"␊ |
19 | #include "sl.h"␊ |
20 | #include "failedboot.h"␊ |
21 | #include "appleClut8.h"␊ |
22 | //#include <mach-o/fat.h>␊ |
23 | //#include <mach-o/loader.h>␊ |
24 | ␊ |
25 | #if DEBUG␊ |
26 | #define DBG(x...)␉printf(x)␊ |
27 | #else␊ |
28 | #define DBG(x...)␉msglog(x)␊ |
29 | #endif␊ |
30 | ␊ |
31 | extern void setup_pci_devs(pci_dt_t *pci_dt);␊ |
32 | ␊ |
33 | /*␊ |
34 | * Modern Darwin kernels require some amount of EFI because Apple machines all␊ |
35 | * have EFI. Modifying the kernel source to not require EFI is of course␊ |
36 | * possible but would have to be maintained as a separate patch because it is␊ |
37 | * unlikely that Apple wishes to add legacy support to their kernel.␊ |
38 | *␊ |
39 | * As you can see from the Apple-supplied code in bootstruct.c, it seems that␊ |
40 | * the intention was clearly to modify this booter to provide EFI-like structures␊ |
41 | * to the kernel rather than modifying the kernel to handle non-EFI stuff. This␊ |
42 | * makes a lot of sense from an engineering point of view as it means the kernel␊ |
43 | * for the as yet unreleased EFI-only Macs could still be booted by the non-EFI␊ |
44 | * DTK systems so long as the kernel checked to ensure the boot tables were␊ |
45 | * filled in appropriately.␉Modern xnu requires a system table and a runtime␊ |
46 | * services table and performs no checks whatsoever to ensure the pointers to␊ |
47 | * these tables are non-NULL. Therefore, any modern xnu kernel will page fault␊ |
48 | * early on in the boot process if the system table pointer is zero.␊ |
49 | *␊ |
50 | * Even before that happens, the tsc_init function in modern xnu requires the FSB␊ |
51 | * Frequency to be a property in the /efi/platform node of the device tree or else␊ |
52 | * it panics the bootstrap process very early on.␊ |
53 | *␊ |
54 | * As of this writing, the current implementation found here is good enough␊ |
55 | * to make the currently available xnu kernel boot without modification on a␊ |
56 | * system with an appropriate processor. With a minor source modification to␊ |
57 | * the tsc_init function to remove the explicit check for Core or Core 2␊ |
58 | * processors the kernel can be made to boot on other processors so long as␊ |
59 | * the code can be executed by the processor and the machine contains the␊ |
60 | * necessary hardware.␊ |
61 | */␊ |
62 | ␊ |
63 | /*==========================================================================␊ |
64 | * Utility function to make a device tree string from an EFI_GUID␊ |
65 | */␊ |
66 | static inline char * mallocStringForGuid(EFI_GUID const *pGuid)␊ |
67 | {␊ |
68 | ␉char *string = malloc(37);␊ |
69 | ␉efi_guid_unparse_upper(pGuid, string);␊ |
70 | ␉return string;␊ |
71 | }␊ |
72 | ␊ |
73 | /*==========================================================================␊ |
74 | * Function to map 32 bit physical address to 64 bit virtual address␊ |
75 | */␊ |
76 | static uint64_t ptov64(uint32_t addr)␊ |
77 | {␊ |
78 | ␉return ((uint64_t)addr | 0xFFFFFF8000000000ULL);␊ |
79 | }␊ |
80 | ␊ |
81 | // ==========================================================================␊ |
82 | // ErmaC␊ |
83 | static inline uint64_t getCPUTick(void)␊ |
84 | {␊ |
85 | ␉uint32_t lowest;␊ |
86 | ␉uint32_t highest;␊ |
87 | ␉__asm__ volatile ("rdtsc" : "=a" (lowest), "=d" (highest));␊ |
88 | ␉return (uint64_t) highest << 32 | lowest;␊ |
89 | }␊ |
90 | ␊ |
91 | /*==========================================================================␊ |
92 | * Fake EFI implementation␊ |
93 | */␊ |
94 | ␊ |
95 | /* Identify ourselves as the EFI firmware vendor */␊ |
96 | static EFI_CHAR16 const FIRMWARE_VENDOR[] = {'C','h','a','m','e','l','e','o','n','_','2','.','3', 0};␊ |
97 | // Bungo␊ |
98 | //static EFI_UINT32 const FIRMWARE_REVISION = 132; /* FIXME: Find a constant for this. */␊ |
99 | static EFI_UINT32 const FIRMWARE_REVISION = 0x0001000a; // got from real MBP6,1␊ |
100 | // Bungo␊ |
101 | /* Default platform system_id (fix by IntVar)␊ |
102 | static EFI_CHAR8 const SYSTEM_ID[] = "0123456789ABCDEF"; //random value gen by uuidgen␊ |
103 | */␊ |
104 | ␊ |
105 | /* Just a ret instruction */␊ |
106 | static uint8_t const VOIDRET_INSTRUCTIONS[] = {0xc3};␊ |
107 | ␊ |
108 | /* movl $0x80000003,%eax; ret */␊ |
109 | static uint8_t const UNSUPPORTEDRET_INSTRUCTIONS_32[] = {0xb8, 0x03, 0x00, 0x00, 0x80, 0xc3};␊ |
110 | static uint8_t const UNSUPPORTEDRET_INSTRUCTIONS_64[] = {0x48, 0xb8, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0xc3};␊ |
111 | ␊ |
112 | /* EFI Guides */␊ |
113 | EFI_GUID const gEfiSmbiosTableGuid␉= EFI_SMBIOS_TABLE_GUID;␊ |
114 | EFI_GUID const gEfiAcpiTableGuid␉= EFI_ACPI_TABLE_GUID;␊ |
115 | EFI_GUID const gEfiAcpi20TableGuid␉= EFI_ACPI_20_TABLE_GUID;␊ |
116 | ␊ |
117 | EFI_SYSTEM_TABLE_32 *gST32 = NULL;␊ |
118 | EFI_SYSTEM_TABLE_64 *gST64 = NULL;␊ |
119 | Node *gEfiConfigurationTableNode = NULL;␊ |
120 | ␊ |
121 | // ==========================================================================␊ |
122 | ␊ |
123 | EFI_STATUS addConfigurationTable(EFI_GUID const *pGuid, void *table, char const *alias)␊ |
124 | {␊ |
125 | ␉EFI_UINTN i = 0;␊ |
126 | ␊ |
127 | ␉//Azi: as is, cpu's with em64t will use EFI64 on pre 10.6 systems,␊ |
128 | ␉// wich seems to cause no problem. In case it does, force i386 arch.␊ |
129 | ␉if (archCpuType == CPU_TYPE_I386)␊ |
130 | ␉{␊ |
131 | ␉␉i = gST32->NumberOfTableEntries;␊ |
132 | ␉}␊ |
133 | ␉else␊ |
134 | ␉{␊ |
135 | ␉␉i = gST64->NumberOfTableEntries;␊ |
136 | ␉}␊ |
137 | ␊ |
138 | ␉// We only do adds, not modifications and deletes like InstallConfigurationTable␊ |
139 | ␉if (i >= MAX_CONFIGURATION_TABLE_ENTRIES)␊ |
140 | ␉{␊ |
141 | ␉␉stop("Fake EFI [ERROR]: Ran out of space for configuration tables [%d]. Increase the reserved size in the code.\n", i);␊ |
142 | ␉}␊ |
143 | ␊ |
144 | ␉if (pGuid == NULL)␊ |
145 | ␉{␊ |
146 | ␉␉return EFI_INVALID_PARAMETER;␊ |
147 | ␉}␊ |
148 | ␊ |
149 | ␉if (table != NULL)␊ |
150 | ␉{␊ |
151 | ␉␉// FIXME␊ |
152 | ␉␉//((EFI_CONFIGURATION_TABLE_64 *)gST->ConfigurationTable)[i].VendorGuid = *pGuid;␊ |
153 | ␉␉//((EFI_CONFIGURATION_TABLE_64 *)gST->ConfigurationTable)[i].VendorTable = (EFI_PTR64)table;␊ |
154 | ␊ |
155 | ␉␉//++gST->NumberOfTableEntries;␊ |
156 | ␊ |
157 | ␉␉Node *tableNode = DT__AddChild(gEfiConfigurationTableNode, mallocStringForGuid(pGuid));␊ |
158 | ␊ |
159 | ␉␉// Use the pointer to the GUID we just stuffed into the system table␊ |
160 | ␉␉DT__AddProperty(tableNode, "guid", sizeof(EFI_GUID), (void *)pGuid);␊ |
161 | ␊ |
162 | ␉␉// The "table" property is the 32-bit (in our implementation) physical address of the table␊ |
163 | ␉␉DT__AddProperty(tableNode, "table", sizeof(EFI_UINT64), table);␊ |
164 | ␊ |
165 | ␉␉// Assume the alias pointer is a global or static piece of data␊ |
166 | ␉␉if (alias != NULL)␊ |
167 | ␉␉{␊ |
168 | ␉␉␉DT__AddProperty(tableNode, "alias", strlen(alias)+1, (void *)alias);␊ |
169 | ␉␉}␊ |
170 | ␊ |
171 | ␉␉i++;␊ |
172 | ␊ |
173 | ␉␉if (archCpuType == CPU_TYPE_I386)␊ |
174 | ␉␉{␊ |
175 | ␉␉␉gST32->NumberOfTableEntries = i;␊ |
176 | ␉␉}␊ |
177 | ␉␉else␊ |
178 | ␉␉{␊ |
179 | ␉␉␉gST64->NumberOfTableEntries = i;␊ |
180 | ␉␉}␊ |
181 | ␊ |
182 | ␉␉return EFI_SUCCESS;␊ |
183 | ␉}␊ |
184 | ␉return EFI_UNSUPPORTED;␊ |
185 | }␊ |
186 | ␊ |
187 | // ==========================================================================␊ |
188 | ␊ |
189 | //Azi: crc32 done in place, on the cases were it wasn't.␊ |
190 | /*static inline void fixupEfiSystemTableCRC32(EFI_SYSTEM_TABLE_64 *efiSystemTable)␊ |
191 | {␊ |
192 | ␉efiSystemTable->Hdr.CRC32 = 0;␊ |
193 | ␉efiSystemTable->Hdr.CRC32 = crc32(0L, efiSystemTable, efiSystemTable->Hdr.HeaderSize);␊ |
194 | }*/␊ |
195 | ␊ |
196 | /*␊ |
197 | * What we do here is simply allocate a fake EFI system table and a fake EFI␊ |
198 | * runtime services table.␊ |
199 | *␊ |
200 | * Because we build against modern headers with kBootArgsRevision 4 we␊ |
201 | * also take care to set efiMode = 32.␊ |
202 | */␊ |
203 | void setupEfiTables32(void)␊ |
204 | {␊ |
205 | ␉// We use the fake_efi_pages struct so that we only need to do one kernel␊ |
206 | ␉// memory allocation for all needed EFI data. Otherwise, small allocations␊ |
207 | ␉// like the FIRMWARE_VENDOR string would take up an entire page.␊ |
208 | ␉// NOTE WELL: Do NOT assume this struct has any particular layout within itself.␊ |
209 | ␉// It is absolutely not intended to be publicly exposed anywhere␊ |
210 | ␉// We say pages (plural) although right now we are well within the 1 page size␊ |
211 | ␉// and probably will stay that way.␊ |
212 | ␉struct fake_efi_pages␊ |
213 | ␉{␊ |
214 | ␉␉EFI_SYSTEM_TABLE_32 efiSystemTable;␊ |
215 | ␉␉EFI_RUNTIME_SERVICES_32 efiRuntimeServices;␊ |
216 | ␉␉EFI_CONFIGURATION_TABLE_32 efiConfigurationTable[MAX_CONFIGURATION_TABLE_ENTRIES];␊ |
217 | ␉␉EFI_CHAR16 firmwareVendor[sizeof(FIRMWARE_VENDOR)/sizeof(EFI_CHAR16)];␊ |
218 | ␉␉uint8_t voidret_instructions[sizeof(VOIDRET_INSTRUCTIONS)/sizeof(uint8_t)];␊ |
219 | ␉␉uint8_t unsupportedret_instructions[sizeof(UNSUPPORTEDRET_INSTRUCTIONS_32)/sizeof(uint8_t)];␊ |
220 | ␉};␊ |
221 | ␉␊ |
222 | ␉struct fake_efi_pages *fakeEfiPages = (struct fake_efi_pages*)AllocateKernelMemory(sizeof(struct fake_efi_pages));␊ |
223 | ␉␊ |
224 | ␉// Zero out all the tables in case fields are added later␊ |
225 | ␉//bzero(fakeEfiPages, sizeof(struct fake_efi_pages));␊ |
226 | ␉␊ |
227 | ␉// --------------------------------------------------------------------␊ |
228 | ␉// Initialize some machine code that will return EFI_UNSUPPORTED for␊ |
229 | ␉// functions returning int and simply return for void functions.␊ |
230 | ␉memcpy(fakeEfiPages->voidret_instructions, VOIDRET_INSTRUCTIONS, sizeof(VOIDRET_INSTRUCTIONS));␊ |
231 | ␉memcpy(fakeEfiPages->unsupportedret_instructions, UNSUPPORTEDRET_INSTRUCTIONS_32, sizeof(UNSUPPORTEDRET_INSTRUCTIONS_32));␊ |
232 | ␉␊ |
233 | ␉// --------------------------------------------------------------------␊ |
234 | ␉// System table␊ |
235 | ␉EFI_SYSTEM_TABLE_32 *efiSystemTable = gST32 = &fakeEfiPages->efiSystemTable;␊ |
236 | ␉efiSystemTable->Hdr.Signature = EFI_SYSTEM_TABLE_SIGNATURE;␊ |
237 | ␉efiSystemTable->Hdr.Revision = EFI_SYSTEM_TABLE_REVISION;␊ |
238 | ␉efiSystemTable->Hdr.HeaderSize = sizeof(EFI_SYSTEM_TABLE_32);␊ |
239 | ␉efiSystemTable->Hdr.CRC32 = 0; // Initialize to zero and then do CRC32␊ |
240 | ␉efiSystemTable->Hdr.Reserved = 0;␊ |
241 | ␉␊ |
242 | ␉efiSystemTable->FirmwareVendor = (EFI_PTR32)&fakeEfiPages->firmwareVendor;␊ |
243 | ␉memcpy(fakeEfiPages->firmwareVendor, FIRMWARE_VENDOR, sizeof(FIRMWARE_VENDOR));␊ |
244 | ␉efiSystemTable->FirmwareRevision = FIRMWARE_REVISION;␊ |
245 | ␉␊ |
246 | ␉// XXX: We may need to have basic implementations of ConIn/ConOut/StdErr␊ |
247 | ␉// The EFI spec states that all handles are invalid after boot services have been␊ |
248 | ␉// exited so we can probably get by with leaving the handles as zero.␊ |
249 | ␉efiSystemTable->ConsoleInHandle = 0;␊ |
250 | ␉efiSystemTable->ConIn = 0;␊ |
251 | ␊ |
252 | ␉efiSystemTable->ConsoleOutHandle = 0;␊ |
253 | ␉efiSystemTable->ConOut = 0;␊ |
254 | ␊ |
255 | ␉efiSystemTable->StandardErrorHandle = 0;␊ |
256 | ␉efiSystemTable->StdErr = 0;␊ |
257 | ␊ |
258 | ␉efiSystemTable->RuntimeServices = (EFI_PTR32)&fakeEfiPages->efiRuntimeServices;␊ |
259 | ␊ |
260 | ␉// According to the EFI spec, BootServices aren't valid after the␊ |
261 | ␉// boot process is exited so we can probably do without it.␊ |
262 | ␉// Apple didn't provide a definition for it in pexpert/i386/efi.h␊ |
263 | ␉// so I'm guessing they don't use it.␊ |
264 | ␉efiSystemTable->BootServices = 0;␊ |
265 | ␊ |
266 | ␉efiSystemTable->NumberOfTableEntries = 0;␊ |
267 | ␉efiSystemTable->ConfigurationTable = (EFI_PTR32)fakeEfiPages->efiConfigurationTable;␊ |
268 | ␊ |
269 | ␉// We're done. Now CRC32 the thing so the kernel will accept it.␊ |
270 | ␉// Must be initialized to zero before CRC32, done above.␊ |
271 | ␉gST32->Hdr.CRC32 = crc32(0L, gST32, gST32->Hdr.HeaderSize);␊ |
272 | ␊ |
273 | ␉// --------------------------------------------------------------------␊ |
274 | ␉// Runtime services␊ |
275 | ␉EFI_RUNTIME_SERVICES_32 *efiRuntimeServices = &fakeEfiPages->efiRuntimeServices;␊ |
276 | ␉efiRuntimeServices->Hdr.Signature = EFI_RUNTIME_SERVICES_SIGNATURE;␊ |
277 | ␉efiRuntimeServices->Hdr.Revision = EFI_RUNTIME_SERVICES_REVISION;␊ |
278 | ␉efiRuntimeServices->Hdr.HeaderSize = sizeof(EFI_RUNTIME_SERVICES_32);␊ |
279 | ␉efiRuntimeServices->Hdr.CRC32 = 0;␊ |
280 | ␉efiRuntimeServices->Hdr.Reserved = 0;␊ |
281 | ␊ |
282 | ␉// There are a number of function pointers in the efiRuntimeServices table.␊ |
283 | ␉// These are the Foundation (e.g. core) services and are expected to be present on␊ |
284 | ␉// all EFI-compliant machines.␉Some kernel extensions (notably AppleEFIRuntime)␊ |
285 | ␉// will call these without checking to see if they are null.␊ |
286 | ␉//␊ |
287 | ␉// We don't really feel like doing an EFI implementation in the bootloader␊ |
288 | ␉// but it is nice if we can at least prevent a complete crash by␊ |
289 | ␉// at least providing some sort of implementation until one can be provided␊ |
290 | ␉// nicely in a kext.␊ |
291 | ␉void (*voidret_fp)() = (void*)fakeEfiPages->voidret_instructions;␊ |
292 | ␉void (*unsupportedret_fp)() = (void*)fakeEfiPages->unsupportedret_instructions;␊ |
293 | ␉efiRuntimeServices->GetTime = (EFI_PTR32)unsupportedret_fp;␊ |
294 | ␉efiRuntimeServices->SetTime = (EFI_PTR32)unsupportedret_fp;␊ |
295 | ␉efiRuntimeServices->GetWakeupTime = (EFI_PTR32)unsupportedret_fp;␊ |
296 | ␉efiRuntimeServices->SetWakeupTime = (EFI_PTR32)unsupportedret_fp;␊ |
297 | ␉efiRuntimeServices->SetVirtualAddressMap = (EFI_PTR32)unsupportedret_fp;␊ |
298 | ␉efiRuntimeServices->ConvertPointer = (EFI_PTR32)unsupportedret_fp;␊ |
299 | ␉efiRuntimeServices->GetVariable = (EFI_PTR32)unsupportedret_fp;␊ |
300 | ␉efiRuntimeServices->GetNextVariableName = (EFI_PTR32)unsupportedret_fp;␊ |
301 | ␉efiRuntimeServices->SetVariable = (EFI_PTR32)unsupportedret_fp;␊ |
302 | ␉efiRuntimeServices->GetNextHighMonotonicCount = (EFI_PTR32)unsupportedret_fp;␊ |
303 | ␉efiRuntimeServices->ResetSystem = (EFI_PTR32)voidret_fp;␊ |
304 | ␊ |
305 | ␉// We're done.␉Now CRC32 the thing so the kernel will accept it␊ |
306 | ␉efiRuntimeServices->Hdr.CRC32 = crc32(0L, efiRuntimeServices, efiRuntimeServices->Hdr.HeaderSize);␊ |
307 | ␊ |
308 | ␉// --------------------------------------------------------------------␊ |
309 | ␉// Finish filling in the rest of the boot args that we need.␊ |
310 | ␉bootArgs->efiSystemTable = (uint32_t)efiSystemTable;␊ |
311 | ␉bootArgs->efiMode = kBootArgsEfiMode32;␊ |
312 | ␊ |
313 | ␉// The bootArgs structure as a whole is bzero'd so we don't need to fill in␊ |
314 | ␉// things like efiRuntimeServices* and what not.␊ |
315 | ␉//␊ |
316 | ␉// In fact, the only code that seems to use that is the hibernate code so it␊ |
317 | ␉// knows not to save the pages.␉ It even checks to make sure its nonzero.␊ |
318 | }␊ |
319 | ␊ |
320 | void setupEfiTables64(void)␊ |
321 | {␊ |
322 | ␉struct fake_efi_pages␊ |
323 | ␉{␊ |
324 | ␉␉EFI_SYSTEM_TABLE_64 efiSystemTable;␊ |
325 | ␉␉EFI_RUNTIME_SERVICES_64 efiRuntimeServices;␊ |
326 | ␉␉EFI_CONFIGURATION_TABLE_64 efiConfigurationTable[MAX_CONFIGURATION_TABLE_ENTRIES];␊ |
327 | ␉␉EFI_CHAR16 firmwareVendor[sizeof(FIRMWARE_VENDOR)/sizeof(EFI_CHAR16)];␊ |
328 | ␉␉uint8_t voidret_instructions[sizeof(VOIDRET_INSTRUCTIONS)/sizeof(uint8_t)];␊ |
329 | ␉␉uint8_t unsupportedret_instructions[sizeof(UNSUPPORTEDRET_INSTRUCTIONS_64)/sizeof(uint8_t)];␊ |
330 | ␉};␊ |
331 | ␊ |
332 | ␉struct fake_efi_pages *fakeEfiPages = (struct fake_efi_pages*)AllocateKernelMemory(sizeof(struct fake_efi_pages));␊ |
333 | ␊ |
334 | ␉// Zero out all the tables in case fields are added later␊ |
335 | ␉//bzero(fakeEfiPages, sizeof(struct fake_efi_pages));␊ |
336 | ␊ |
337 | ␉// --------------------------------------------------------------------␊ |
338 | ␉// Initialize some machine code that will return EFI_UNSUPPORTED for␊ |
339 | ␉// functions returning int and simply return for void functions.␊ |
340 | ␉memcpy(fakeEfiPages->voidret_instructions, VOIDRET_INSTRUCTIONS, sizeof(VOIDRET_INSTRUCTIONS));␊ |
341 | ␉memcpy(fakeEfiPages->unsupportedret_instructions, UNSUPPORTEDRET_INSTRUCTIONS_64, sizeof(UNSUPPORTEDRET_INSTRUCTIONS_64));␊ |
342 | ␊ |
343 | ␉// --------------------------------------------------------------------␊ |
344 | ␉// System table␊ |
345 | ␉EFI_SYSTEM_TABLE_64 *efiSystemTable = gST64 = &fakeEfiPages->efiSystemTable;␊ |
346 | ␉efiSystemTable->Hdr.Signature = EFI_SYSTEM_TABLE_SIGNATURE;␊ |
347 | ␉efiSystemTable->Hdr.Revision = EFI_SYSTEM_TABLE_REVISION;␊ |
348 | ␉efiSystemTable->Hdr.HeaderSize = sizeof(EFI_SYSTEM_TABLE_64);␊ |
349 | ␉efiSystemTable->Hdr.CRC32 = 0; // Initialize to zero and then do CRC32␊ |
350 | ␉efiSystemTable->Hdr.Reserved = 0;␊ |
351 | ␊ |
352 | ␉efiSystemTable->FirmwareVendor = ptov64((EFI_PTR32)&fakeEfiPages->firmwareVendor);␊ |
353 | ␉memcpy(fakeEfiPages->firmwareVendor, FIRMWARE_VENDOR, sizeof(FIRMWARE_VENDOR));␊ |
354 | ␉efiSystemTable->FirmwareRevision = FIRMWARE_REVISION;␊ |
355 | ␊ |
356 | ␉// XXX: We may need to have basic implementations of ConIn/ConOut/StdErr␊ |
357 | ␉// The EFI spec states that all handles are invalid after boot services have been␊ |
358 | ␉// exited so we can probably get by with leaving the handles as zero.␊ |
359 | ␉efiSystemTable->ConsoleInHandle = 0;␊ |
360 | ␉efiSystemTable->ConIn = 0;␊ |
361 | ␊ |
362 | ␉efiSystemTable->ConsoleOutHandle = 0;␊ |
363 | ␉efiSystemTable->ConOut = 0;␊ |
364 | ␊ |
365 | ␉efiSystemTable->StandardErrorHandle = 0;␊ |
366 | ␉efiSystemTable->StdErr = 0;␊ |
367 | ␊ |
368 | ␉efiSystemTable->RuntimeServices = ptov64((EFI_PTR32)&fakeEfiPages->efiRuntimeServices);␊ |
369 | ␉// According to the EFI spec, BootServices aren't valid after the␊ |
370 | ␉// boot process is exited so we can probably do without it.␊ |
371 | ␉// Apple didn't provide a definition for it in pexpert/i386/efi.h␊ |
372 | ␉// so I'm guessing they don't use it.␊ |
373 | ␉efiSystemTable->BootServices = 0;␊ |
374 | ␊ |
375 | ␉efiSystemTable->NumberOfTableEntries = 0;␊ |
376 | ␉efiSystemTable->ConfigurationTable = ptov64((EFI_PTR32)fakeEfiPages->efiConfigurationTable);␊ |
377 | ␊ |
378 | ␉// We're done.␉Now CRC32 the thing so the kernel will accept it␊ |
379 | ␉gST64->Hdr.CRC32 = crc32(0L, gST64, gST64->Hdr.HeaderSize);␊ |
380 | ␊ |
381 | ␉// --------------------------------------------------------------------␊ |
382 | ␉// Runtime services␊ |
383 | ␉EFI_RUNTIME_SERVICES_64 *efiRuntimeServices = &fakeEfiPages->efiRuntimeServices;␊ |
384 | ␉efiRuntimeServices->Hdr.Signature = EFI_RUNTIME_SERVICES_SIGNATURE;␊ |
385 | ␉efiRuntimeServices->Hdr.Revision = EFI_RUNTIME_SERVICES_REVISION;␊ |
386 | ␉efiRuntimeServices->Hdr.HeaderSize = sizeof(EFI_RUNTIME_SERVICES_64);␊ |
387 | ␉efiRuntimeServices->Hdr.CRC32 = 0;␊ |
388 | ␉efiRuntimeServices->Hdr.Reserved = 0;␊ |
389 | ␊ |
390 | ␉// There are a number of function pointers in the efiRuntimeServices table.␊ |
391 | ␉// These are the Foundation (e.g. core) services and are expected to be present on␊ |
392 | ␉// all EFI-compliant machines.␉Some kernel extensions (notably AppleEFIRuntime)␊ |
393 | ␉// will call these without checking to see if they are null.␊ |
394 | ␉//␊ |
395 | ␉// We don't really feel like doing an EFI implementation in the bootloader␊ |
396 | ␉// but it is nice if we can at least prevent a complete crash by␊ |
397 | ␉// at least providing some sort of implementation until one can be provided␊ |
398 | ␉// nicely in a kext.␊ |
399 | ␊ |
400 | ␉void (*voidret_fp)() = (void*)fakeEfiPages->voidret_instructions;␊ |
401 | ␉void (*unsupportedret_fp)() = (void*)fakeEfiPages->unsupportedret_instructions;␊ |
402 | ␉efiRuntimeServices->GetTime = ptov64((EFI_PTR32)unsupportedret_fp);␊ |
403 | ␉efiRuntimeServices->SetTime = ptov64((EFI_PTR32)unsupportedret_fp);␊ |
404 | ␉efiRuntimeServices->GetWakeupTime = ptov64((EFI_PTR32)unsupportedret_fp);␊ |
405 | ␉efiRuntimeServices->SetWakeupTime = ptov64((EFI_PTR32)unsupportedret_fp);␊ |
406 | ␉efiRuntimeServices->SetVirtualAddressMap = ptov64((EFI_PTR32)unsupportedret_fp);␊ |
407 | ␉efiRuntimeServices->ConvertPointer = ptov64((EFI_PTR32)unsupportedret_fp);␊ |
408 | ␉efiRuntimeServices->GetVariable = ptov64((EFI_PTR32)unsupportedret_fp);␊ |
409 | ␉efiRuntimeServices->GetNextVariableName = ptov64((EFI_PTR32)unsupportedret_fp);␊ |
410 | ␉efiRuntimeServices->SetVariable = ptov64((EFI_PTR32)unsupportedret_fp);␊ |
411 | ␉efiRuntimeServices->GetNextHighMonotonicCount = ptov64((EFI_PTR32)unsupportedret_fp);␊ |
412 | ␉efiRuntimeServices->ResetSystem = ptov64((EFI_PTR32)voidret_fp);␊ |
413 | ␊ |
414 | ␉// We're done.␉Now CRC32 the thing so the kernel will accept it␊ |
415 | ␉efiRuntimeServices->Hdr.CRC32 = crc32(0L, efiRuntimeServices, efiRuntimeServices->Hdr.HeaderSize);␊ |
416 | ␊ |
417 | ␉// --------------------------------------------------------------------␊ |
418 | ␉// Finish filling in the rest of the boot args that we need.␊ |
419 | ␉bootArgs->efiSystemTable = (uint32_t)efiSystemTable;␊ |
420 | ␉bootArgs->efiMode = kBootArgsEfiMode64;␊ |
421 | ␊ |
422 | ␉// The bootArgs structure as a whole is bzero'd so we don't need to fill in␊ |
423 | ␉// things like efiRuntimeServices* and what not.␊ |
424 | ␉//␊ |
425 | ␉// In fact, the only code that seems to use that is the hibernate code so it␊ |
426 | ␉// knows not to save the pages.␉ It even checks to make sure its nonzero.␊ |
427 | }␊ |
428 | ␊ |
429 | /*␊ |
430 | * In addition to the EFI tables there is also the EFI device tree node.␊ |
431 | * In particular, we need /efi/platform to have an FSBFrequency key. Without it,␊ |
432 | * the tsc_init function will panic very early on in kernel startup, before␊ |
433 | * the console is available.␊ |
434 | */␊ |
435 | ␊ |
436 | /*==========================================================================␊ |
437 | * FSB Frequency detection␊ |
438 | */␊ |
439 | ␊ |
440 | /* These should be const but DT__AddProperty takes char* */␊ |
441 | static const char TSC_Frequency_prop[] = "TSCFrequency";␊ |
442 | static const char FSB_Frequency_prop[] = "FSBFrequency";␊ |
443 | static const char CPU_Frequency_prop[] = "CPUFrequency";␊ |
444 | ␊ |
445 | /*==========================================================================␊ |
446 | * Fake EFI implementation␊ |
447 | */␊ |
448 | ␊ |
449 | /* These should be const but DT__AddProperty takes char* */␊ |
450 | static const char FIRMWARE_REVISION_PROP[] = "firmware-revision";␊ |
451 | static const char FIRMWARE_ABI_PROP[] = "firmware-abi";␊ |
452 | static const char FIRMWARE_VENDOR_PROP[] = "firmware-vendor";␊ |
453 | //static const char FIRMWARE_ABI_32_PROP_VALUE[] = "EFI32";␊ |
454 | static const char FIRMWARE_ABI_64_PROP_VALUE[] = "EFI64";␊ |
455 | static const char EFI_MODE_PROP[] = "efi-mode"; //Bungo␊ |
456 | static const char SYSTEM_ID_PROP[] = "system-id";␊ |
457 | static const char SYSTEM_SERIAL_PROP[] = "SystemSerialNumber";␊ |
458 | static const char SYSTEM_TYPE_PROP[] = "system-type";␊ |
459 | static const char MODEL_PROP[] = "Model";␊ |
460 | static const char BOARDID_PROP[] = "board-id";␊ |
461 | static const char DEV_PATHS_SUP_PROP[] = "DevicePathsSupported";␊ |
462 | static const char MACHINE_SIG_PROP[] = "machine-signature";␊ |
463 | //static EFI_UINT32 const ZERO_U32 = 0;␊ |
464 | static EFI_UINT32 const ONE_U32 = 1;␊ |
465 | //static EFI_UINT32 const *VALUE[] = { &ZERO_U32 , &ONE_U32 };␊ |
466 | static const char RANDOM_SEED_PROP[] = "random-seed";␊ |
467 | /*␊ |
468 | static EFI_UINT8 const RANDOM_SEED_PROP_VALUE[] =␊ |
469 | {␊ |
470 | 0x40, 0x00, 0x50, 0x00, 0x5c, 0x00, 0x53, 0x00, 0x79, 0x00, 0x73, 0x00, 0x74, 0x00, 0x65, 0x00,␊ |
471 | 0x6d, 0x00, 0x5c, 0x00, 0x4c, 0x00, 0x69, 0x00, 0x62, 0x00, 0x72, 0x00, 0x61, 0x00, 0x72, 0x00,␊ |
472 | 0x79, 0x00, 0x5c, 0x00, 0x43, 0x00, 0x6f, 0x00, 0x72, 0x00, 0x65, 0x00, 0x53, 0x00, 0x65, 0x00,␊ |
473 | 0x72, 0x00, 0x76, 0x00, 0x69, 0x00, 0x63, 0x00, 0x65, 0x00, 0x73, 0x00, 0x5c, 0x00, 0x62, 0x00␊ |
474 | };␊ |
475 | */␊ |
476 | static EFI_UINT8 RANDOM_SEED_PROP_VALUE[64];␊ |
477 | ␊ |
478 | /*␊ |
479 | * Get an smbios option string option to convert to EFI_CHAR16 string␊ |
480 | */␊ |
481 | static EFI_CHAR16* getSmbiosChar16(const char * key, size_t* len)␊ |
482 | {␊ |
483 | ␉const char␉*src = getStringForKey(key, &bootInfo->smbiosConfig);␊ |
484 | ␉EFI_CHAR16*␉ dst = 0;␊ |
485 | ␉size_t␉␉ i = 0;␊ |
486 | ␊ |
487 | ␉if (!key || !(*key) || !len || !src)␊ |
488 | ␉{␊ |
489 | ␉␉return 0;␊ |
490 | ␉}␊ |
491 | ␉␊ |
492 | ␉*len = strlen(src);␊ |
493 | ␉dst = (EFI_CHAR16*) malloc( ((*len)+1) * 2 );␊ |
494 | ␉for (; i < (*len); i++)␊ |
495 | ␉{␊ |
496 | ␉␉dst[i] = src[i];␊ |
497 | ␉}␊ |
498 | ␉dst[(*len)] = '\0';␊ |
499 | ␉*len = ((*len)+1)*2; // return the CHAR16 bufsize including zero terminated CHAR16␊ |
500 | ␉return dst;␊ |
501 | }␊ |
502 | ␊ |
503 | // Bungo␊ |
504 | /*␊ |
505 | * Get the SystemID from the bios dmi info␊ |
506 | ␊ |
507 | static␉EFI_CHAR8* getSmbiosUUID()␊ |
508 | {␊ |
509 | ␉static EFI_CHAR8␉␉ uuid[UUID_LEN];␊ |
510 | ␉int␉␉␉␉␉␉ i, isZero, isOnes;␊ |
511 | ␉SMBByte␉␉␉␉␉*p;␊ |
512 | ␊ |
513 | ␉p = (SMBByte*)Platform.UUID;␊ |
514 | ␊ |
515 | ␉for (i=0, isZero=1, isOnes=1; i<UUID_LEN; i++)␊ |
516 | ␉{␊ |
517 | ␉␉if (p[i] != 0x00)␊ |
518 | ␉␉{␊ |
519 | ␉␉␉isZero = 0;␊ |
520 | ␉␉}␊ |
521 | ␊ |
522 | ␉␉if (p[i] != 0xff)␊ |
523 | ␉␉{␊ |
524 | ␉␉␉isOnes = 0;␊ |
525 | ␉␉}␊ |
526 | ␉}␊ |
527 | ␊ |
528 | ␉if (isZero || isOnes) // empty or setable means: no uuid present␊ |
529 | ␉{␊ |
530 | ␉␉verbose("No UUID present in SMBIOS System Information Table\n");␊ |
531 | ␉␉return 0;␊ |
532 | ␉}␊ |
533 | ␊ |
534 | ␉memcpy(uuid, p, UUID_LEN);␊ |
535 | ␉return uuid;␊ |
536 | }␊ |
537 | ␊ |
538 | ␊ |
539 | // return a binary UUID value from the overriden SystemID and SMUUID if found, ␊ |
540 | // or from the bios if not, or from a fixed value if no bios value is found ␊ |
541 | ␊ |
542 | static EFI_CHAR8* getSystemID()␊ |
543 | {␊ |
544 | ␉// unable to determine UUID for host. Error: 35 fix␊ |
545 | ␉// Rek: new SMsystemid option conforming to smbios notation standards, this option should␊ |
546 | ␉// belong to smbios config only ...␊ |
547 | ␉const char *sysId = getStringForKey(kSystemID, &bootInfo->chameleonConfig);␊ |
548 | ␉EFI_CHAR8*␉ret = getUUIDFromString(sysId);␊ |
549 | ␊ |
550 | ␉if (!sysId || !ret) // try bios dmi info UUID extraction␊ |
551 | ␉{␊ |
552 | ␉␉ret = getSmbiosUUID();␊ |
553 | ␉␉sysId = 0;␊ |
554 | ␉}␊ |
555 | ␊ |
556 | ␉if (!ret)␊ |
557 | ␉{␊ |
558 | ␉␉// no bios dmi UUID available, set a fixed value for system-id␊ |
559 | ␉␉ret=getUUIDFromString((sysId = (const char*) SYSTEM_ID));␊ |
560 | ␉}␊ |
561 | ␉verbose("Customizing SystemID with : %s\n", getStringFromUUID(ret)); // apply a nice formatting to the displayed output␊ |
562 | ␉return ret;␊ |
563 | }␊ |
564 | */␊ |
565 | ␊ |
566 | /*␊ |
567 | * Must be called AFTER setupAcpi because we need to take care of correct␊ |
568 | * FACP content to reflect in ioregs␊ |
569 | */␊ |
570 | void setupSystemType()␊ |
571 | {␊ |
572 | ␉Node *node = DT__FindNode("/", false);␊ |
573 | ␉if (node == 0)␊ |
574 | ␉{␊ |
575 | ␉␉stop("Couldn't get root '/' node");␊ |
576 | ␉}␊ |
577 | ␉// we need to write this property after facp parsing␊ |
578 | ␉// Export system-type only if it has been overrriden by the SystemType option␊ |
579 | ␉DT__AddProperty(node, SYSTEM_TYPE_PROP, sizeof(Platform.Type), &Platform.Type);␊ |
580 | }␊ |
581 | ␊ |
582 | bool getKernelCompat(EFI_UINT8 *compat)␊ |
583 | {␊ |
584 | ␉int kernelFileRef;␊ |
585 | ␉EFI_UINT8 readBytes;␊ |
586 | ␉char kernelFilePath[512], kernelHeaderBuf[sizeof(struct fat_header) + 4*sizeof(struct fat_arch)];␊ |
587 | ␊ |
588 | ␉//strlcpy(kernelFilePath, bootInfo->bootFile, sizeof(kernelFilePath)); // user defined path␊ |
589 | ␉snprintf(kernelFilePath, sizeof(kernelFilePath), "%s", bootInfo->bootFile); // user defined path␊ |
590 | ␉if ((kernelFileRef = open(kernelFilePath, 0)) >= 0)␊ |
591 | ␉{␊ |
592 | ␉}␊ |
593 | ␉else␊ |
594 | ␉{␊ |
595 | ␉␉snprintf(kernelFilePath, sizeof(kernelFilePath), "/%s", bootInfo->bootFile); // append a leading '/'␊ |
596 | ␉␉if ((kernelFileRef = open(kernelFilePath, 0)) >= 0)␊ |
597 | ␉␉{␊ |
598 | ␉␉}␊ |
599 | ␉␉else␊ |
600 | ␉␉{␊ |
601 | ␉␉␉snprintf(kernelFilePath, sizeof(kernelFilePath), "/System/Library/Kernels/%s", bootInfo->bootFile); // Yosemite path␊ |
602 | ␉␉␉if ((kernelFileRef = open(kernelFilePath, 0)) >= 0)␊ |
603 | ␉␉␉{␊ |
604 | ␉␉␉}␊ |
605 | ␉␉␉else␊ |
606 | ␉␉␉{␊ |
607 | ␉␉␉␉verbose("EfiKernelCompat: can't find any kernel file!\n");␊ |
608 | ␉␉␉␉return false;␊ |
609 | ␉␉␉}␊ |
610 | ␉␉}␊ |
611 | ␉}␊ |
612 | ␊ |
613 | ␉verbose("EfiKernelCompat: reading kernel header from file: %s ... ", kernelFilePath);␊ |
614 | ␉if ((readBytes = read(kernelFileRef, kernelHeaderBuf, sizeof(struct fat_header) + 4*sizeof(struct fat_arch))) > 0) {␊ |
615 | ␉␉verbose("OK, read %d bytes.\n", readBytes);␊ |
616 | ␉}␊ |
617 | ␉else␊ |
618 | ␉{␊ |
619 | ␉␉verbose("EROR, can't read kernel file!\n");␊ |
620 | ␉␉return false;␊ |
621 | ␉}␊ |
622 | ␊ |
623 | ␉struct fat_header *fatHeaderPtr = (struct fat_header *)kernelHeaderBuf;␊ |
624 | ␉struct fat_arch *fatArchPtr = (struct fat_arch *)(kernelHeaderBuf + sizeof(struct fat_header));␊ |
625 | ␉struct mach_header *thinHeaderPtr = (struct mach_header *)kernelHeaderBuf;␊ |
626 | ␉bool swapit = false;␊ |
627 | ␊ |
628 | ␉switch (fatHeaderPtr->magic)␊ |
629 | ␉{␊ |
630 | ␉␉case FAT_CIGAM:␊ |
631 | ␉␉␉swapit = true;␊ |
632 | ␉␉␉fatHeaderPtr->nfat_arch = OSSwapInt32(fatHeaderPtr->nfat_arch);␊ |
633 | ␉␉case FAT_MAGIC:␊ |
634 | ␉␉␉*compat = 0;␊ |
635 | ␉␉␉verbose("EfiKernelCompat: kernel file is a fat binary: %d archs compatibility [", fatHeaderPtr->nfat_arch);␊ |
636 | ␉␉␉if (fatHeaderPtr->nfat_arch > 4)␊ |
637 | ␉␉␉{␊ |
638 | ␉␉␉␉fatHeaderPtr->nfat_arch = 4;␊ |
639 | ␉␉␉}␊ |
640 | ␊ |
641 | ␉␉␉for (; fatHeaderPtr->nfat_arch > 0; fatHeaderPtr->nfat_arch--, fatArchPtr++)␊ |
642 | ␉␉␉{␊ |
643 | ␉␉␉␉if (swapit)␊ |
644 | ␉␉␉␉{␊ |
645 | ␉␉␉␉␉fatArchPtr->cputype = OSSwapInt32(fatArchPtr->cputype);␊ |
646 | ␉␉␉␉}␊ |
647 | ␊ |
648 | ␉␉␉␉switch(fatArchPtr->cputype)␊ |
649 | ␉␉␉␉{␊ |
650 | ␉␉␉␉␉case CPU_TYPE_I386:␊ |
651 | ␉␉␉␉␉␉verbose(" i386");␊ |
652 | ␉␉␉␉␉␉break;␊ |
653 | ␉␉␉␉␉case CPU_TYPE_X86_64:␊ |
654 | ␉␉␉␉␉␉verbose(" x86_64");␊ |
655 | ␉␉␉␉␉␉break;␊ |
656 | ␉␉␉␉␉case CPU_TYPE_POWERPC:␊ |
657 | ␉␉␉␉␉␉verbose(" PPC");␊ |
658 | ␉␉␉␉␉␉break;␊ |
659 | ␉␉␉␉␉case CPU_TYPE_POWERPC64:␊ |
660 | ␉␉␉␉␉␉verbose(" PPC64");␊ |
661 | ␉␉␉␉␉␉break;␊ |
662 | ␉␉␉␉␉default:␊ |
663 | ␉␉␉␉␉␉verbose(" 0x%x", fatArchPtr->cputype);␊ |
664 | ␉␉␉␉}␊ |
665 | ␊ |
666 | ␉␉␉␉if (fatHeaderPtr->nfat_arch - 1 > 0)␊ |
667 | ␉␉␉␉{␊ |
668 | ␉␉␉␉␉verbose(" | ");␊ |
669 | ␉␉␉␉}␊ |
670 | ␊ |
671 | ␉␉␉␉*compat |= (!(fatArchPtr->cputype ^ CPU_TYPE_I386) << 0) | (!(fatArchPtr->cputype ^ CPU_TYPE_X86_64) << 1) | (!(fatArchPtr->cputype ^ CPU_TYPE_POWERPC) << 2) | (!(fatArchPtr->cputype ^ CPU_TYPE_POWERPC64) << 3);␊ |
672 | ␉␉␉}␊ |
673 | ␉␉␉verbose(" ]\n");␊ |
674 | ␉␉␉break;␊ |
675 | ␉␉case MH_CIGAM:␊ |
676 | ␉␉case MH_CIGAM_64:␊ |
677 | ␉␉␉thinHeaderPtr->cputype = OSSwapInt32(thinHeaderPtr->cputype);␊ |
678 | ␉␉case MH_MAGIC:␊ |
679 | ␉␉case MH_MAGIC_64:␊ |
680 | ␉␉␉*compat = (!(thinHeaderPtr->cputype ^ CPU_TYPE_I386) << 0) | (!(thinHeaderPtr->cputype ^ CPU_TYPE_X86_64) << 1) | (!(thinHeaderPtr->cputype ^ CPU_TYPE_POWERPC) << 2) | (!(thinHeaderPtr->cputype ^ CPU_TYPE_POWERPC64) << 3);␊ |
681 | ␉␉␉verbose("EfiKernelCompat: kernel file is a thin binary: 1 arch compatibility found [ %s ].\n", !((thinHeaderPtr->cputype & 0x000000FF) ^ 0x00000007) ? (!((thinHeaderPtr->cputype & 0xFF000000) ^ 0x01000000) ? "x86_64" : "i386") : (!((thinHeaderPtr->cputype & 0xFF000000) ^ 0x01000000) ? "PPC64" : "PPC"));␊ |
682 | ␉␉␉break;␊ |
683 | ␉␉default:␊ |
684 | ␉␉␉verbose("EfiKernelCompat: unknown kernel file '%s'. Can't determine arch compatibility!\n", kernelFilePath);␊ |
685 | ␉␉␉return false;␊ |
686 | ␉}␊ |
687 | ␊ |
688 | ␉return true;␊ |
689 | }␊ |
690 | ␊ |
691 | /*␊ |
692 | * Installs all the needed configuration table entries␊ |
693 | */␊ |
694 | static void setupEfiConfigurationTable()␊ |
695 | {␊ |
696 | ␉// smbios_p = (EFI_PTR32)getSmbios(SMBIOS_PATCHED);␊ |
697 | ␉if (smbios_p)␊ |
698 | ␉{␊ |
699 | ␉␉if (EFI_SUCCESS == addConfigurationTable(&gEfiSmbiosTableGuid, &smbios_p, NULL))␊ |
700 | ␉␉{␊ |
701 | ␉␉␉verbose("Fake EFI: sucesfuly added %sbit configuration table for SMBIOS: guid {EB9D2D31-2D88-11D3-9A16-0090273FC14D}.\n", (archCpuType == CPU_TYPE_I386) ? "32":"64");␊ |
702 | ␉␉}␊ |
703 | ␉}␊ |
704 | ␊ |
705 | ␉// Setup ACPI with DSDT overrides (mackerintel's patch)␊ |
706 | ␉//setupAcpi();␊ |
707 | ␊ |
708 | ␉if (acpi10_p)␊ |
709 | ␉{␊ |
710 | ␉␉if (EFI_SUCCESS == addConfigurationTable(&gEfiAcpiTableGuid, &acpi10_p, "ACPI"))␊ |
711 | ␉␉{␊ |
712 | ␉␉␉verbose("Fake EFI: sucesfuly added %sbit configuration table for ACPI: guid {EB9D2D30-2D88-11D3-9A16-0090273FC14D}.\n", (archCpuType == CPU_TYPE_I386) ? "32":"64");␊ |
713 | ␉␉}␊ |
714 | ␉}␊ |
715 | ␊ |
716 | ␉if (acpi20_p)␊ |
717 | ␉{␊ |
718 | ␉␉if (EFI_SUCCESS == addConfigurationTable(&gEfiAcpi20TableGuid, &acpi20_p, "ACPI_20")) {␊ |
719 | ␉␉␉verbose("Fake EFI: sucesfuly added %sbit configuration table for ACPI_20: guid {8868E871-E4F1-11D3-BC22-0080C73C8881}.\n", (archCpuType == CPU_TYPE_I386) ? "32":"64");␊ |
720 | ␉␉}␊ |
721 | ␉}␊ |
722 | ␊ |
723 | ␉// We've obviously changed the count.. so fix up the CRC32␊ |
724 | ␉if (archCpuType == CPU_TYPE_I386)␊ |
725 | ␉{␊ |
726 | ␉␉gST32->Hdr.CRC32 = 0;␊ |
727 | ␉␉gST32->Hdr.CRC32 = crc32(0L, gST32, gST32->Hdr.HeaderSize);␊ |
728 | ␉}␊ |
729 | ␉else␊ |
730 | ␉{␊ |
731 | ␉␉gST64->Hdr.CRC32 = 0;␊ |
732 | ␉␉gST64->Hdr.CRC32 = crc32(0L, gST64, gST64->Hdr.HeaderSize);␊ |
733 | ␉}␊ |
734 | }␊ |
735 | ␊ |
736 | void setupEfiNode(void)␊ |
737 | {␊ |
738 | ␉EFI_CHAR16*␉ ret16 = 0;␊ |
739 | ␉size_t␉␉ len = 0;␊ |
740 | ␊ |
741 | ␉Node *efiNode = DT__FindNode("/efi", true);␊ |
742 | ␉if (efiNode == 0)␊ |
743 | ␉{␊ |
744 | ␉␉stop("Couldn't get '/efi' node");␊ |
745 | ␉}␊ |
746 | ␊ |
747 | /* Bungo: we have 64 bit ability fake efi but mode may be changed 32/64, like Macs␊ |
748 | ␉if (archCpuType == CPU_TYPE_I386)␊ |
749 | ␉{␊ |
750 | ␉␉DT__AddProperty(efiNode, FIRMWARE_ABI_PROP, sizeof(FIRMWARE_ABI_32_PROP_VALUE), (EFI_CHAR8 *)FIRMWARE_ABI_32_PROP_VALUE);␊ |
751 | ␉}␊ |
752 | ␉else␊ |
753 | ␉{␊ |
754 | */␊ |
755 | ␉␉DT__AddProperty(efiNode, FIRMWARE_ABI_PROP, sizeof(FIRMWARE_ABI_64_PROP_VALUE), (EFI_CHAR8 *)FIRMWARE_ABI_64_PROP_VALUE);␊ |
756 | //␉}␊ |
757 | // So, added 'efi-mode' property to tell us what mode we use 32 or 64 bit␊ |
758 | ␉DT__AddProperty(efiNode, EFI_MODE_PROP, sizeof(EFI_UINT8), (EFI_UINT8 *)&bootArgs->efiMode);␊ |
759 | ␊ |
760 | ␉DT__AddProperty(efiNode, FIRMWARE_REVISION_PROP, sizeof(FIRMWARE_REVISION), (EFI_UINT32 *)&FIRMWARE_REVISION);␊ |
761 | ␉DT__AddProperty(efiNode, FIRMWARE_VENDOR_PROP, sizeof(FIRMWARE_VENDOR), (EFI_CHAR16 *)&FIRMWARE_VENDOR);␊ |
762 | ␊ |
763 | ␉// TODO: Fill in other efi properties if necessary␊ |
764 | ␊ |
765 | ␉// Set up the /efi/runtime-services table node similar to the way a child node of configuration-table␊ |
766 | ␉// is set up. That is, name and table properties␊ |
767 | ␉Node *runtimeServicesNode = DT__AddChild(efiNode, "runtime-services");␊ |
768 | ␊ |
769 | ␉if (archCpuType == CPU_TYPE_I386)␊ |
770 | ␉{␊ |
771 | ␉␉// The value of the table property is the 32-bit physical address for the RuntimeServices table.␊ |
772 | ␉␉// Since the EFI system table already has a pointer to it, we simply use the address of that pointer␊ |
773 | ␉␉// for the pointer to the property data. Warning.. DT finalization calls free on that but we're not␊ |
774 | ␉␉// the only thing to use a non-malloc'd pointer for something in the DT␊ |
775 | ␉␉DT__AddProperty(runtimeServicesNode, "table", sizeof(EFI_UINT64), &gST32->RuntimeServices);␊ |
776 | ␉}␊ |
777 | ␉else␊ |
778 | ␉{␊ |
779 | ␉␉DT__AddProperty(runtimeServicesNode, "table", sizeof(EFI_UINT64), &gST64->RuntimeServices);␊ |
780 | ␉}␊ |
781 | ␊ |
782 | ␉// Set up the /efi/configuration-table node which will eventually have several child nodes for␊ |
783 | ␉// all of the configuration tables needed by various kernel extensions.␊ |
784 | ␉gEfiConfigurationTableNode = DT__AddChild(efiNode, "configuration-table");␊ |
785 | ␊ |
786 | ␉// Set up the /efi/kernel-compatibility node only if 10.7 or better␊ |
787 | ␉if (MacOSVerCurrent >= MacOSVer2Int("10.7"))␊ |
788 | ␉{␊ |
789 | ␉␉Node *EfiKernelCompatNode = DT__AddChild(efiNode, "kernel-compatibility");␊ |
790 | ␉␉EFI_UINT8 compat = (archCpuType == CPU_TYPE_I386) ? 0b00000001 : 0b00000010;␊ |
791 | ␉␉getKernelCompat(&compat);␊ |
792 | ␉␉if (compat & 0b00000001)␊ |
793 | ␉␉{␊ |
794 | ␉␉␉DT__AddProperty(EfiKernelCompatNode, "i386", sizeof(EFI_UINT32), (EFI_UINT32 *)&ONE_U32);␊ |
795 | ␉␉}␊ |
796 | ␊ |
797 | ␉␉if (compat & 0b00000010)␊ |
798 | ␉␉{␊ |
799 | ␉␉␉DT__AddProperty(EfiKernelCompatNode, "x86_64", sizeof(EFI_UINT32), (EFI_UINT32 *)&ONE_U32);␊ |
800 | ␉␉}␊ |
801 | ␊ |
802 | ␉␉if (compat & 0b00000100)␊ |
803 | ␉␉{␊ |
804 | ␉␉␉DT__AddProperty(EfiKernelCompatNode, "PPC", sizeof(EFI_UINT32), (EFI_UINT32 *)&ONE_U32);␊ |
805 | ␉␉}␊ |
806 | ␊ |
807 | ␉␉if (compat & 0b00001000)␊ |
808 | ␉␉{␊ |
809 | ␉␉␉DT__AddProperty(EfiKernelCompatNode, "PPC64", sizeof(EFI_UINT32), (EFI_UINT32 *)&ONE_U32);␊ |
810 | ␉␉}␊ |
811 | ␉}␊ |
812 | ␊ |
813 | ␉// Now fill in the /efi/platform Node␊ |
814 | ␉Node *efiPlatformNode = DT__AddChild(efiNode, "platform");␊ |
815 | ␊ |
816 | ␉// NOTE WELL: If you do add FSB Frequency detection, make sure to store␊ |
817 | ␉// the value in the fsbFrequency global and not an malloc'd pointer␊ |
818 | ␉// because the DT_AddProperty function does not copy its args.␊ |
819 | ␊ |
820 | ␉if (Platform.CPU.FSBFrequency != 0)␊ |
821 | ␉{␊ |
822 | ␉␉DT__AddProperty(efiPlatformNode, FSB_Frequency_prop, sizeof(EFI_UINT64), (EFI_UINT64 *)&Platform.CPU.FSBFrequency);␊ |
823 | ␉}␊ |
824 | ␊ |
825 | ␉// Export TSC and CPU frequencies for use by the kernel or KEXTs␊ |
826 | ␉if (Platform.CPU.TSCFrequency != 0)␊ |
827 | ␉{␊ |
828 | ␉␉DT__AddProperty(efiPlatformNode, TSC_Frequency_prop, sizeof(EFI_UINT64), (EFI_UINT64 *)&Platform.CPU.TSCFrequency);␊ |
829 | ␉}␊ |
830 | ␊ |
831 | ␉if (Platform.CPU.CPUFrequency != 0)␊ |
832 | ␉{␊ |
833 | ␉␉DT__AddProperty(efiPlatformNode, CPU_Frequency_prop, sizeof(EFI_UINT64), (EFI_UINT64 *)&Platform.CPU.CPUFrequency);␊ |
834 | ␉}␊ |
835 | ␊ |
836 | ␉DT__AddProperty(efiPlatformNode, DEV_PATHS_SUP_PROP, sizeof(EFI_UINT32), (EFI_UINT32 *)&ONE_U32);␊ |
837 | ␊ |
838 | ␉// Bungo␊ |
839 | ␉/* Export system-id. Can be disabled with SystemId=No in com.apple.Boot.plist␊ |
840 | ␉if ((ret=getSystemID()))␊ |
841 | ␉{␊ |
842 | ␉␉DT__AddProperty(efiPlatformNode, SYSTEM_ID_PROP, UUID_LEN, (EFI_UINT32*) ret);␊ |
843 | ␉}␊ |
844 | ␉*/␊ |
845 | ␉DT__AddProperty(efiPlatformNode, SYSTEM_ID_PROP, UUID_LEN, Platform.UUID);␊ |
846 | ␊ |
847 | ␉// Export SystemSerialNumber if present␊ |
848 | ␉if ((ret16=getSmbiosChar16("SMserial", &len)))␊ |
849 | ␉{␊ |
850 | ␉␉DT__AddProperty(efiPlatformNode, SYSTEM_SERIAL_PROP, len, ret16);␊ |
851 | ␉}␊ |
852 | ␊ |
853 | ␉// Export Model if present␊ |
854 | ␉if ((ret16=getSmbiosChar16("SMproductname", &len)))␊ |
855 | ␉{␊ |
856 | ␉␉DT__AddProperty(efiPlatformNode, MODEL_PROP, len, ret16);␊ |
857 | ␉}␊ |
858 | ␊ |
859 | ␉// Fill /efi/device-properties.␊ |
860 | ␉setupDeviceProperties(efiNode);␊ |
861 | ␊ |
862 | ␉// Add configuration table entries to both the services table and the device tree␊ |
863 | ␉setupEfiConfigurationTable();␊ |
864 | }␊ |
865 | ␊ |
866 | /*␊ |
867 | * Must be called AFTER getSmbios␊ |
868 | */␊ |
869 | void setupBoardId()␊ |
870 | {␊ |
871 | ␉Node *node;␊ |
872 | ␉node = DT__FindNode("/", false);␊ |
873 | ␉if (node == 0)␊ |
874 | ␉{␊ |
875 | ␉␉stop("Couldn't get root '/' node");␊ |
876 | ␉}␊ |
877 | ␉const char *boardid = getStringForKey("SMboardproduct", &bootInfo->smbiosConfig);␊ |
878 | ␉if (boardid)␊ |
879 | ␉{␊ |
880 | ␉␉DT__AddProperty(node, BOARDID_PROP, strlen(boardid)+1, (EFI_CHAR16*)boardid);␊ |
881 | ␉}␊ |
882 | }␊ |
883 | ␊ |
884 | /*␊ |
885 | * Fill up the root node␊ |
886 | *␊ |
887 | setupRootNode()␊ |
888 | {␊ |
889 | ␊ |
890 | }␊ |
891 | */␊ |
892 | /*␊ |
893 | * Fill up the chosen node␊ |
894 | */␊ |
895 | void setupChosenNode()␊ |
896 | {␊ |
897 | ␉Node *chosenNode = DT__FindNode("/chosen", false);␊ |
898 | ␉if (chosenNode == NULL)␊ |
899 | ␉{␊ |
900 | ␉␉stop("setupChosenNode: Couldn't get '/chosen' node");␊ |
901 | ␉}␊ |
902 | ␊ |
903 | ␉int length = strlen(gBootUUIDString);␊ |
904 | ␉if (length)␊ |
905 | ␉{␊ |
906 | ␉␉DT__AddProperty(chosenNode, "boot-uuid", length + 1, gBootUUIDString);␊ |
907 | ␉}␊ |
908 | ␊ |
909 | ␉length = strlen(bootArgs->CommandLine);␊ |
910 | ␉DT__AddProperty(chosenNode, "boot-args", length + 1, bootArgs->CommandLine);␊ |
911 | ␊ |
912 | ␉length = strlen(bootInfo->bootFile);␊ |
913 | ␉if (length)␊ |
914 | ␉{␊ |
915 | ␉␉DT__AddProperty(chosenNode, "boot-file", length + 1, bootInfo->bootFile);␊ |
916 | ␉}␊ |
917 | // TODO:␊ |
918 | //␉DT__AddProperty(chosenNode, "boot-device-path", bootDPsize, gBootDP);␊ |
919 | //␉DT__AddProperty(chosenNode, "boot-file-path", bootFPsize, gBootFP);␊ |
920 | //␉DT__AddProperty(chosenNode, "boot-kernelchache-adler32", sizeof(adler32), adler32);␊ |
921 | ␊ |
922 | ␉DT__AddProperty(chosenNode, MACHINE_SIG_PROP, sizeof(Platform.HWSignature), (EFI_UINT32 *)&Platform.HWSignature);␊ |
923 | ␊ |
924 | ␉// add if Yosemite or better only␊ |
925 | ␉if (MacOSVerCurrent >= MacOSVer2Int("10.10"))␊ |
926 | ␉{␊ |
927 | ␉␉//␊ |
928 | ␉␉// Pike R. Alpha - 12 October 2014␊ |
929 | ␉␉//␊ |
930 | ␉␉UInt8 index = 0;␊ |
931 | ␉␉EFI_UINT16 PMTimerValue = 0;␊ |
932 | ␉␉EFI_UINT32 randomValue, tempValue, cpuTick;␊ |
933 | ␉␉EFI_UINT32 ecx, esi, edi;␊ |
934 | ␉␉EFI_UINT32 rcx, rdx, rsi, rdi;␊ |
935 | ␊ |
936 | ␉␉randomValue = tempValue = ecx = esi = edi = 0;␉␉␉␉␉// xor␉␉%ecx,␉%ecx␊ |
937 | ␉␉cpuTick = rcx = rdx = rsi = rdi = 0;␊ |
938 | ␊ |
939 | ␉␉// LEAF_1 - Feature Information (Function 01h).␊ |
940 | ␉␉if (Platform.CPU.CPUID[CPUID_1][2] & 0x40000000)␉␉␉␉// Checking ecx:bit-30␊ |
941 | ␉␉{␊ |
942 | ␉␉␉//␊ |
943 | ␉␉␉// i5/i7 Ivy Bridge and Haswell processors with RDRAND support.␊ |
944 | ␉␉␉//␊ |
945 | ␉␉␉// EFI_UINT32 seedBuffer[16] = {0};␊ |
946 | ␉␉␉//␊ |
947 | ␉␉␉// Main loop to get 16 qwords (four bytes each).␊ |
948 | ␉␉␉//␊ |
949 | ␉␉␉EFI_UINT32 *seedPtr = (EFI_UINT32 *)RANDOM_SEED_PROP_VALUE;␊ |
950 | ␊ |
951 | ␉␉␉for (index = 0; index < 16; index++)␉␉␉␉␉// 0x17e12:␊ |
952 | ␉␉␉{␊ |
953 | ␉␉␉␉randomValue = computeRand();␉␉␉␉␉// callq␉0x18e20␊ |
954 | ␉␉␉␉cpuTick = getCPUTick();␉␉␉␉␉␉// callq␉0x121a7␊ |
955 | ␉␉␉␉randomValue = (randomValue ^ cpuTick);␉␉␉␉// xor␉␉%rdi,␉%rax␊ |
956 | ␉␉␉␉seedPtr[index] = randomValue;␉␉␉␉␉// mov␉␉%rax,(%r15,%rsi,8)␊ |
957 | ␉␉␉}␉␉␉␉␉␉␉␉␉// jb␉␉0x17e12␊ |
958 | ␉␉}␊ |
959 | ␉␉else␊ |
960 | ␉␉{␊ |
961 | ␉␉␉//␊ |
962 | ␉␉␉// All other processors without RDRAND support.␊ |
963 | ␉␉␉//␊ |
964 | ␉␉␉//EFI_UINT8 seedBuffer[64] = {0};␊ |
965 | ␉␉␉//␊ |
966 | ␉␉␉// Main loop to get the 64 bytes.␊ |
967 | ␉␉␉//␊ |
968 | ␉␉␉EFI_UINT8 *seedPtr = (EFI_UINT8 *)RANDOM_SEED_PROP_VALUE;␊ |
969 | ␊ |
970 | ␉␉␉do␉␉␉␉␉␉␉␉␉// 0x17e55:␊ |
971 | ␉␉␉{␊ |
972 | ␉␉␉␉PMTimerValue = inw(0x408);␉␉␉␉␉// in␉␉(%dx),␉%ax␊ |
973 | ␉␉␉␉esi = PMTimerValue;␉␉␉␉␉␉// movzwl␉%ax,␉%esi␊ |
974 | ␊ |
975 | ␉␉␉␉if (esi < ecx)␉␉␉␉␉␉␉// cmp␉␉%ecx,␉%esi␊ |
976 | ␉␉␉␉{␊ |
977 | ␉␉␉␉␉continue;␉␉␉␉␉␉// jb␉␉0x17e55␉␉(retry)␊ |
978 | ␉␉␉␉}␊ |
979 | ␊ |
980 | ␉␉␉␉cpuTick = getCPUTick();␉␉␉␉␉␉// callq␉0x121a7␊ |
981 | //␉␉␉␉printf("value: 0x%llx\n", getCPUTick());␊ |
982 | ␉␉␉␉rcx = (cpuTick >> 8);␉␉␉␉␉␉// mov␉␉%rax,␉%rcx␊ |
983 | ␉␉␉␉// shr␉␉$0x8,␉%rcx␊ |
984 | ␉␉␉␉rdx = (cpuTick >> 10);␉␉␉␉␉␉// mov␉␉%rax,␉%rdx␊ |
985 | ␉␉␉␉// shr␉␉$0x10,␉%rdx␊ |
986 | ␉␉␉␉rdi = rsi;␉␉␉␉␉␉␉// mov␉␉%rsi,␉%rdi␊ |
987 | ␉␉␉␉rdi = (rdi ^ cpuTick);␉␉␉␉␉␉// xor␉␉%rax,␉%rdi␊ |
988 | ␉␉␉␉rdi = (rdi ^ rcx);␉␉␉␉␉␉// xor␉␉%rcx,␉%rdi␊ |
989 | ␉␉␉␉rdi = (rdi ^ rdx);␉␉␉␉␉␉// xor␉␉%rdx,␉%rdi␊ |
990 | ␊ |
991 | ␉␉␉␉//RANDOM_SEED_PROP_VALUE[index] = (EFI_UINT8)(rdi & 0xff);␉// mov␉␉%dil,␉(%r15,%r12,1)␊ |
992 | ␉␉␉␉seedPtr[index] = (EFI_UINT8)(rdi & 0xff);␊ |
993 | ␊ |
994 | ␉␉␉␉edi = (edi & 0x2f);␉␉␉␉␉␉// and␉␉$0x2f,␉%edi␊ |
995 | ␉␉␉␉edi = (edi + esi);␉␉␉␉␉␉// add␉␉%esi,␉%edi␊ |
996 | ␉␉␉␉index++;␉␉␉␉␉␉␉// inc␉␉r12␊ |
997 | ␉␉␉␉ecx = (edi & 0xffff);␉␉␉␉␉␉// movzwl␉%di,␉%ecx␊ |
998 | ␊ |
999 | ␉␉␉} while (index < 64);␉␉␉␉␉␉␉// cmp␉␉%r14d,␉%r12d␊ |
1000 | ␉␉␉// jne␉␉0x17e55␉␉(next)␊ |
1001 | ␉␉}␊ |
1002 | ␉␉DT__AddProperty(chosenNode, RANDOM_SEED_PROP, sizeof(RANDOM_SEED_PROP_VALUE), (EFI_UINT8 *)RANDOM_SEED_PROP_VALUE);␊ |
1003 | ␉}␊ |
1004 | ␊ |
1005 | ␉// setup '/chosen/memory-map' node␊ |
1006 | ␉Node *memoryMapNode = DT__FindNode("/chosen/memory-map", false);␊ |
1007 | ␉if (memoryMapNode == NULL)␊ |
1008 | ␉{␊ |
1009 | ␉␉verbose("setupChosenNode:Couldn't get '/chosen/memory-map' node\n");␊ |
1010 | ␉}␊ |
1011 | ␉else␊ |
1012 | ␉{␊ |
1013 | ␉/*␊ |
1014 | ␉␉static EFI_UINT64 BootClutPropValue = 0;␊ |
1015 | ␉␉static EFI_UINT64 FailedBootPictPropValue = 0;␊ |
1016 | ␉␉BootClutPropValue = ((EFI_UINT64)sizeof(appleClut8) << 32) | (EFI_UINT64)(EFI_UINT8 *)&appleClut8;␊ |
1017 | ␉␉FailedBootPictPropValue = ((EFI_UINT64)(sizeof(gFailedBootPict) + 32) << 32) | (EFI_UINT64)(EFI_UINT8 *)&gFailedBootPict;␊ |
1018 | ␉␉if (MacOSVerCurrent < MacOSVer2Int("10.7.3")) {␊ |
1019 | ␉␉␉DT__AddProperty(node, "BootCLUT", sizeof(EFI_UINT64), (EFI_UINT64 *)&BootClutPropValue);␊ |
1020 | ␉␉␉DT__AddProperty(node, "Pict-FailedBoot", sizeof(EFI_UINT64), (EFI_UINT64 *)&FailedBootPictPropValue);␊ |
1021 | ␉␉}␊ |
1022 | ␉␉else␊ |
1023 | ␉␉{␊ |
1024 | ␉␉␉DT__AddProperty(node, "FailedCLUT", sizeof(EFI_UINT64), (EFI_UINT64 *)&BootClutPropValue);␊ |
1025 | ␉␉␉DT__AddProperty(node, "FailedImage", sizeof(EFI_UINT64), (EFI_UINT64 *)&FailedBootPictPropValue);␊ |
1026 | ␉␉}␊ |
1027 | ␉*/␊ |
1028 | ␉}␊ |
1029 | }␊ |
1030 | ␊ |
1031 | /*␊ |
1032 | * Load the smbios.plist override config file if any␊ |
1033 | */␊ |
1034 | static void setupSmbiosConfigFile()␊ |
1035 | {␊ |
1036 | ␉//char␉␉dirSpecSMBIOS[256];␊ |
1037 | ␉const char␉*override_pathname = NULL;␊ |
1038 | ␉int␉␉len = 0, err = 0;␊ |
1039 | ␉extern void scan_mem();␊ |
1040 | ␊ |
1041 | ␉// Take in account user overriding␊ |
1042 | ␉if (getValueForKey(kSMBIOSKey, &override_pathname, &len, &bootInfo->chameleonConfig) && len > 0)␊ |
1043 | ␉{␊ |
1044 | ␉␉// Specify a path to a file, e.g. SMBIOS=/Settings/macProXY.plist␊ |
1045 | ␉␉//sprintf(dirSpecSMBIOS, override_pathname);␊ |
1046 | ␉␉err = loadConfigFile(override_pathname, &bootInfo->smbiosConfig);␊ |
1047 | ␉}␊ |
1048 | ␉else␊ |
1049 | ␉{␊ |
1050 | ␉␉// Check selected volume's Extra.␊ |
1051 | ␉␉//sprintf(dirSpecSMBIOS, "/Extra/%s", filename);␊ |
1052 | ␉␉//if ( (err = loadConfigFile(dirSpecSMBIOS, &bootInfo->smbiosConfig)) )␊ |
1053 | ␉␉{␊ |
1054 | ␉␉␉// Check booter volume/rdbt Extra.␊ |
1055 | ␉␉␉//sprintf(dirSpecSMBIOS, "bt(0,0)/Extra/%s", filename);␊ |
1056 | ␉␉␉err = loadConfigFile("/Extra/smbios.plist", &bootInfo->smbiosConfig);␊ |
1057 | ␉␉}␊ |
1058 | ␉}␊ |
1059 | ␊ |
1060 | ␉if (err)␊ |
1061 | ␉{␊ |
1062 | ␉␉verbose("setupSmbiosConfigFile: No SMBIOS replacement found.\n");␊ |
1063 | ␉}␊ |
1064 | ␊ |
1065 | ␉// get a chance to scan mem dynamically if user asks for it while having the config options␊ |
1066 | ␉// loaded as well, as opposed to when it was in scan_platform(); also load the orig. smbios␊ |
1067 | ␉// so that we can access dmi info, without patching the smbios yet.␊ |
1068 | ␉scan_mem(); ␊ |
1069 | }␊ |
1070 | ␊ |
1071 | void saveOriginalSMBIOS(void)␊ |
1072 | {␊ |
1073 | ␉Node *node;␊ |
1074 | ␉SMBEntryPoint *origeps;␊ |
1075 | ␉void *tableAddress;␊ |
1076 | ␊ |
1077 | ␉node = DT__FindNode("/efi/platform", false);␊ |
1078 | ␉if (!node)␊ |
1079 | ␉{␊ |
1080 | ␉␉verbose("saveOriginalSMBIOS: '/efi/platform' node not found\n");␊ |
1081 | ␉␉return;␊ |
1082 | ␉}␊ |
1083 | ␊ |
1084 | ␉origeps = getSmbios(SMBIOS_ORIGINAL);␊ |
1085 | ␉if (!origeps)␊ |
1086 | ␉{␊ |
1087 | ␉␉verbose("saveOriginalSMBIOS: original SMBIOS not found\n");␊ |
1088 | ␉␉return;␊ |
1089 | ␉}␊ |
1090 | ␊ |
1091 | ␉tableAddress = (void *)AllocateKernelMemory(origeps->dmi.tableLength);␊ |
1092 | ␉if (!tableAddress)␊ |
1093 | ␉{␊ |
1094 | ␉␉verbose("saveOriginalSMBIOS: can not allocate memory for original SMBIOS\n");␊ |
1095 | ␉␉return;␊ |
1096 | ␉}␊ |
1097 | ␊ |
1098 | ␉memcpy(tableAddress, (void *)origeps->dmi.tableAddress, origeps->dmi.tableLength);␊ |
1099 | ␉DT__AddProperty(node, "SMBIOS", origeps->dmi.tableLength, tableAddress);␊ |
1100 | }␊ |
1101 | ␊ |
1102 | char saveOriginalACPI()␊ |
1103 | {␊ |
1104 | ␉verbose("\nsaveOriginalACPI: Saving OEM tables into IODT:/chosen/acpi...\n");␊ |
1105 | ␊ |
1106 | ␉Node *node = DT__FindNode("/chosen/acpi", true);␊ |
1107 | ␉if (!node)␊ |
1108 | ␉{␊ |
1109 | ␉␉verbose("saveOriginalACPI: node '/chosen/acpi' not found, can't save any OEM tables.\n\n");␊ |
1110 | ␉␉return 0;␊ |
1111 | ␉}␊ |
1112 | ␊ |
1113 | ␉struct acpi_2_rsdp *RSDP = getRSDPaddress();␊ |
1114 | ␊ |
1115 | ␉if (!RSDP)␊ |
1116 | ␉{␊ |
1117 | ␉␉verbose("saveOriginalACPI: OEM RSDP not found or incorrect, can't save any OEM tables.\n\n");␊ |
1118 | ␉␉return 0;␊ |
1119 | ␉}␊ |
1120 | ␊ |
1121 | ␉uint8_t r;␊ |
1122 | ␉uint8_t total_number = 1;␊ |
1123 | ␉uint8_t ssdt_number = 0;␊ |
1124 | ␉uint8_t nameLen = strlen("XXXX@XXXXXXXX");␊ |
1125 | ␉uint32_t length = RSDP->Revision ? RSDP->Length : 20;␊ |
1126 | ␉char *nameBuf = malloc(nameLen);␊ |
1127 | ␊ |
1128 | ␉sprintf(nameBuf, "RSDP@%08X", (uint32_t)RSDP);␊ |
1129 | ␉verbose("saveOriginalACPI: OEM table %s found, length=%d: saving.\n", nameBuf, length);␊ |
1130 | ␉DT__AddProperty(node, nameBuf, length, RSDP);␊ |
1131 | ␉uint32_t total_length = length;␊ |
1132 | ␊ |
1133 | ␉struct acpi_2_header *RSDT = (struct acpi_2_header *)(RSDP->RsdtAddress);␊ |
1134 | ␉struct acpi_2_header *XSDT = (struct acpi_2_header *)(uint32_t)(RSDP->XsdtAddress);␊ |
1135 | ␊ |
1136 | ␉void *origTable = NULL;␊ |
1137 | ␉void *origTable2 = NULL;␊ |
1138 | ␉void *origTable3 = NULL;␊ |
1139 | ␉void *origTable4 = NULL;␊ |
1140 | ␊ |
1141 | ␉if ((RSDP->RsdtAddress > 0) && (RSDP->RsdtAddress < 0xFFFFFFFF) && tableSign(RSDT->Signature, "RSDT"))␊ |
1142 | ␉{␊ |
1143 | ␉␉origTable = (void *)(RSDT + 1);␊ |
1144 | ␉␉nameBuf = malloc(nameLen + 1);␊ |
1145 | ␉␉sprintf(nameBuf, "RSDT@%08X", (uint32_t)RSDT);␊ |
1146 | ␉␉verbose("saveOriginalACPI: OEM table %s found, lenght=%d: saving.\n", nameBuf, RSDT->Length);␊ |
1147 | ␉␉DT__AddProperty(node, nameBuf, RSDT->Length, RSDT);␊ |
1148 | ␉␉total_length += RSDT->Length;␊ |
1149 | ␉␉total_number++;␊ |
1150 | ␉␉for ( ; origTable < ((void *)RSDT + RSDT->Length); origTable += 4)␊ |
1151 | ␉␉{␊ |
1152 | ␉␉␉origTable2 = (void *)(*(uint32_t *)origTable);␊ |
1153 | ␉␉␉length = ((struct acpi_2_header *)origTable2)->Length;␊ |
1154 | ␉␉␉total_length += length;␊ |
1155 | ␉␉␉total_number++;␊ |
1156 | ␉␉␉if (tableSign(((struct acpi_2_header *)origTable2)->Signature, "SSDT"))␊ |
1157 | ␉␉␉{␊ |
1158 | ␉␉␉␉ssdt_number++;␊ |
1159 | ␉␉␉␉if (strcmp(((struct acpi_2_header *)origTable2)->OEMTableId, "CpuPm") == 0)␊ |
1160 | ␉␉␉␉{␊ |
1161 | ␉␉␉␉␉nameLen = strlen("SSDT@XXXXXXXX");␊ |
1162 | ␉␉␉␉␉nameBuf = malloc(nameLen + 1);␊ |
1163 | ␉␉␉␉␉sprintf(nameBuf, "SSDT@%08X", (uint32_t)origTable2);␊ |
1164 | ␉␉␉␉␉verbose("saveOriginalACPI: OEM table %s found, lenght=%d: saving.\n", nameBuf, length);␊ |
1165 | ␉␉␉␉␉DT__AddProperty(node, nameBuf, length, origTable2);␊ |
1166 | ␉␉␉␉␉origTable2 += sizeof(struct acpi_2_header) + 15;␊ |
1167 | ␉␉␉␉␉r = *((uint8_t *)origTable2 - 2) / 3; // e.g: Name (SSDT, Package (0x0C) -> 0x0C / 3 = 4 is number of sub SSDTs␊ |
1168 | ␉␉␉␉␉for (; r > 0; r--, origTable2 += sizeof(struct ssdt_pmref))␊ |
1169 | ␉␉␉␉␉{␊ |
1170 | ␉␉␉␉␉␉origTable3 = (void *)(((struct ssdt_pmref *)origTable2)->addr);␊ |
1171 | ␉␉␉␉␉␉if (!((uint32_t)origTable3 > 0) && !((uint32_t)origTable3 < 0xFFFFFFFF)) // incorrect, dropping␊ |
1172 | ␉␉␉␉␉␉{␊ |
1173 | ␉␉␉␉␉␉␉continue;␊ |
1174 | ␉␉␉␉␉␉}␊ |
1175 | ␊ |
1176 | ␉␉␉␉␉␉length = ((struct acpi_2_header *)origTable3)->Length;␊ |
1177 | ␉␉␉␉␉␉nameLen = strlen("SSDT_@XXXXXXXX") + strlen((char *)((struct acpi_2_header *)origTable3)->OEMTableId);␊ |
1178 | ␉␉␉␉␉␉nameBuf = malloc(nameLen + 1);␊ |
1179 | ␉␉␉␉␉␉sprintf(nameBuf, "SSDT_%s@%08X", (char *)((struct acpi_2_header *)origTable3)->OEMTableId, (uint32_t)origTable3);␊ |
1180 | ␉␉␉␉␉␉verbose("saveOriginalACPI: OEM table %s found, lenght=%d: saving.\n", nameBuf, length);␊ |
1181 | ␉␉␉␉␉␉DT__AddProperty(node, nameBuf, length, origTable3);␊ |
1182 | ␉␉␉␉␉␉total_length += length;␊ |
1183 | ␉␉␉␉␉␉total_number++;␊ |
1184 | ␉␉␉␉␉}␊ |
1185 | ␉␉␉␉}␊ |
1186 | ␉␉␉␉else␊ |
1187 | ␉␉␉␉{␊ |
1188 | ␉␉␉␉␉nameLen = strlen("SSDT-@XXXXXXXX") + ((ssdt_number < 10)? 1:2);␊ |
1189 | ␉␉␉␉␉nameBuf = malloc(nameLen + 1);␊ |
1190 | ␉␉␉␉␉sprintf(nameBuf, "SSDT-%d@%08X", ssdt_number, (uint32_t)origTable2);␊ |
1191 | ␉␉␉␉␉verbose("saveOriginalACPI: OEM table %s found, lenght=%d: saving.\n", nameBuf, length);␊ |
1192 | ␉␉␉␉␉DT__AddProperty(node, nameBuf, length, origTable2);␊ |
1193 | ␉␉␉␉}␊ |
1194 | ␉␉␉}␊ |
1195 | ␉␉␉else␊ |
1196 | ␉␉␉{␊ |
1197 | ␉␉␉␉nameLen = strlen("XXXX@XXXXXXXX");␊ |
1198 | ␉␉␉␉nameBuf = malloc(nameLen + 1);␊ |
1199 | ␉␉␉␉sprintf(nameBuf, "%c%c%c%c@%08X", ((char *)origTable2)[0], ((char *)origTable2)[1], ((char *)origTable2)[2], ((char *)origTable2)[3], (uint32_t)origTable2);␊ |
1200 | ␉␉␉␉verbose("saveOriginalACPI: OEM table %s found, lenght=%d: saving.\n", nameBuf, length);␊ |
1201 | ␉␉␉␉DT__AddProperty(node, nameBuf, length, origTable2);␊ |
1202 | ␉␉␉␉if (tableSign(((struct acpi_2_header *)origTable2)->Signature, "FACP"))␊ |
1203 | ␉␉␉␉{␊ |
1204 | ␉␉␉␉␉origTable3 = (void *)(((struct acpi_2_fadt *)origTable2)->FACS);␊ |
1205 | ␉␉␉␉␉length = ((struct acpi_2_header *)origTable3)->Length;␊ |
1206 | ␉␉␉␉␉nameLen = strlen("FACS@XXXXXXXX");␊ |
1207 | ␉␉␉␉␉nameBuf = malloc(nameLen + 1);␊ |
1208 | ␉␉␉␉␉sprintf(nameBuf, "FACS@%08X", (uint32_t)origTable3);␊ |
1209 | ␉␉␉␉␉verbose("saveOriginalACPI: OEM table %s found, lenght=%d: saving.\n", nameBuf, length);␊ |
1210 | ␉␉␉␉␉DT__AddProperty(node, nameBuf, length, origTable3);␊ |
1211 | ␉␉␉␉␉total_length += length;␊ |
1212 | ␉␉␉␉␉total_number++;␊ |
1213 | ␉␉␉␉␉origTable3 = (void *)(((struct acpi_2_fadt *)origTable2)->DSDT);␊ |
1214 | ␉␉␉␉␉length = ((struct acpi_2_header *)origTable3)->Length;␊ |
1215 | ␉␉␉␉␉nameLen = strlen("DSDT@XXXXXXXX");␊ |
1216 | ␉␉␉␉␉nameBuf = malloc(nameLen + 1);␊ |
1217 | ␉␉␉␉␉sprintf(nameBuf, "DSDT@%08X", (uint32_t)origTable3);␊ |
1218 | ␉␉␉␉␉verbose("saveOriginalACPI: OEM table %s found, lenght=%d: saving.\n", nameBuf, length);␊ |
1219 | ␉␉␉␉␉DT__AddProperty(node, nameBuf, length, origTable3);␊ |
1220 | ␉␉␉␉␉total_length += length;␊ |
1221 | ␉␉␉␉␉total_number++;␊ |
1222 | ␉␉␉␉}␊ |
1223 | ␉␉␉}␊ |
1224 | ␉␉}␊ |
1225 | ␉}␊ |
1226 | ␉else␊ |
1227 | ␉{␊ |
1228 | ␉␉verbose("saveOriginalACPI: OEM table RSDT@%08x not found or incorrect.\n", RSDP->RsdtAddress);␊ |
1229 | ␉}␊ |
1230 | ␊ |
1231 | #if DEBUG␊ |
1232 | pause("\n[DEBUG_FAKEEFI] ");␊ |
1233 | #endif␊ |
1234 | ␊ |
1235 | ␉if (RSDP->Revision > 0)␊ |
1236 | ␉{␊ |
1237 | ␉␉verbose("\n");␊ |
1238 | ␉␉if ((RSDP->XsdtAddress > 0) && (RSDP->XsdtAddress < 0xFFFFFFFF) && tableSign(XSDT->Signature, "XSDT"))␊ |
1239 | ␉␉{␊ |
1240 | ␉␉␉verbose("saveOriginalACPI: OEM table XSDT@%016X found, lenght=%d: saving.\n", (uint32_t)XSDT, XSDT->Length);␊ |
1241 | ␉␉␉nameLen = strlen("XSDT@XXXXXXXX");␊ |
1242 | ␉␉␉nameBuf = malloc(nameLen + 1);␊ |
1243 | ␉␉␉sprintf(nameBuf, "XSDT@%08X", (uint32_t)XSDT);␊ |
1244 | ␉␉␉DT__AddProperty(node, nameBuf, XSDT->Length, XSDT);␊ |
1245 | ␉␉␉total_number++;␊ |
1246 | ␉␉␉total_length += XSDT->Length;␊ |
1247 | ␉␉␉for (origTable = (void *)(RSDT + 1), origTable4 = (void *)(XSDT + 1); origTable4 < ((void *)XSDT + XSDT->Length); origTable += 4, origTable4 += 8)␊ |
1248 | ␉␉␉{␊ |
1249 | ␉␉␉␉origTable2 = (void *)(uint32_t)(*(uint64_t *)origTable4);␊ |
1250 | ␉␉␉␉length = ((struct acpi_2_header *)origTable2)->Length;␊ |
1251 | ␉␉␉␉verbose("saveOriginalACPI: OEM table X_%c%c%c%c@%016X found, lenght=%d: ", ((char *)origTable2)[0], ((char *)origTable2)[1], ((char *)origTable2)[2], ((char *)origTable2)[3], (uint32_t)origTable2, length);␊ |
1252 | ␉␉␉␉if (*(uint32_t *)origTable != (uint32_t)origTable2) // already saved?␊ |
1253 | ␉␉␉␉{␊ |
1254 | ␉␉␉␉␉verbose("saving.\n");␊ |
1255 | ␉␉␉␉␉nameLen = strlen("X_XXXX@XXXXXXXX");␊ |
1256 | ␉␉␉␉␉nameBuf = malloc(nameLen + 1);␊ |
1257 | ␉␉␉␉␉sprintf(nameBuf, "X_%c%c%c%c@%08X", ((char *)origTable2)[0], ((char *)origTable2)[1], ((char *)origTable2)[2], ((char *)origTable2)[3], (uint32_t)origTable2);␊ |
1258 | ␉␉␉␉␉DT__AddProperty(node, nameBuf, length, origTable2);␊ |
1259 | ␉␉␉␉␉total_length += length;␊ |
1260 | ␉␉␉␉␉total_number++;␊ |
1261 | ␊ |
1262 | ␉␉␉␉␉if (tableSign(((struct acpi_2_header *)origTable2)->Signature, "SSDT") && (strcmp(((struct acpi_2_header *)origTable2)->OEMTableId, "CpuPm") == 0))␊ |
1263 | ␉␉␉␉␉{␊ |
1264 | ␉␉␉␉␉␉// Get rest of ssdts from ssdt_pmref␊ |
1265 | ␉␉␉␉␉␉r = *((uint8_t *)origTable2 - 2) / 3; // e.g: Name (SSDT, Package (0x0C) -> 0x0C / 3 = 4 is number of sub SSDTs␊ |
1266 | ␉␉␉␉␉␉for (; r > 0; r--, origTable2 += sizeof(struct ssdt_pmref))␊ |
1267 | ␉␉␉␉␉␉{␊ |
1268 | ␉␉␉␉␉␉␉origTable3 = (void *)(((struct ssdt_pmref *)origTable2)->addr);␊ |
1269 | ␉␉␉␉␉␉␉if (!((uint32_t)origTable3 > 0) && !((uint32_t)origTable3 < 0xFFFFFFFF)) // incorrect, dropping␊ |
1270 | ␉␉␉␉␉␉␉{␊ |
1271 | ␉␉␉␉␉␉␉␉continue;␊ |
1272 | ␉␉␉␉␉␉␉}␊ |
1273 | ␊ |
1274 | ␉␉␉␉␉␉␉length = ((struct acpi_2_header *)origTable3)->Length;␊ |
1275 | ␉␉␉␉␉␉␉nameLen = strlen("SSDT_@XXXXXXXX") + strlen((char *)((struct acpi_2_header *)origTable3)->OEMTableId);␊ |
1276 | ␉␉␉␉␉␉␉nameBuf = malloc(nameLen + 1);␊ |
1277 | ␉␉␉␉␉␉␉sprintf(nameBuf, "SSDT_%s@%08X", (char *)((struct acpi_2_header *)origTable3)->OEMTableId, (uint32_t)origTable3);␊ |
1278 | ␉␉␉␉␉␉␉verbose("saveOriginalACPI: OEM table %s found, lenght=%d: saving.\n", nameBuf, length);␊ |
1279 | ␉␉␉␉␉␉␉DT__AddProperty(node, nameBuf, length, origTable3);␊ |
1280 | ␉␉␉␉␉␉␉total_length += length;␊ |
1281 | ␉␉␉␉␉␉␉total_number++;␊ |
1282 | ␉␉␉␉␉␉}␊ |
1283 | ␉␉␉␉␉␉continue;␊ |
1284 | ␉␉␉␉␉}␊ |
1285 | ␊ |
1286 | ␉␉␉␉␉if (tableSign(((struct acpi_2_header *)origTable2)->Signature, "FACP"))␊ |
1287 | ␉␉␉␉␉{␊ |
1288 | ␉␉␉␉␉␉origTable3 = (void *)(((struct acpi_2_fadt *)origTable2)->X_FACS); // take x_facs assuming facs (from x_facp) should be equal to it␊ |
1289 | ␉␉␉␉␉␉length = ((struct acpi_2_rsdt *)origTable3)->Length;␊ |
1290 | ␉␉␉␉␉␉verbose("saveOriginalACPI: OEM table X_FACS@%016X found, lenght=%d: ", (uint32_t)origTable3, length);␊ |
1291 | ␉␉␉␉␉␉if (origTable3 != (void *)(((struct acpi_2_fadt *)origTable2)->FACS))␊ |
1292 | ␉␉␉␉␉␉{␊ |
1293 | ␉␉␉␉␉␉␉verbose("saving.\n");␊ |
1294 | ␉␉␉␉␉␉␉nameLen = strlen("X_FACS@XXXXXXXX");␊ |
1295 | ␉␉␉␉␉␉␉nameBuf = malloc(nameLen + 1);␊ |
1296 | ␉␉␉␉␉␉␉sprintf(nameBuf, "X_FACS@%08X", (uint32_t)origTable3);␊ |
1297 | ␉␉␉␉␉␉␉DT__AddProperty(node, nameBuf, length, origTable3);␊ |
1298 | ␉␉␉␉␉␉␉total_length += length;␊ |
1299 | ␉␉␉␉␉␉␉total_number++;␊ |
1300 | ␉␉␉␉␉␉}␊ |
1301 | ␉␉␉␉␉␉else␊ |
1302 | ␉␉␉␉␉␉{␊ |
1303 | ␉␉␉␉␉␉␉verbose("already saved.\n");␊ |
1304 | ␉␉␉␉␉␉}␊ |
1305 | ␊ |
1306 | ␉␉␉␉␉␉// assuming only one dsdt in system, so x_facp should contain pointer to it same as facp␊ |
1307 | ␉␉␉␉␉␉origTable3 = (void *)(((struct acpi_2_fadt *)origTable2)->X_DSDT);␊ |
1308 | ␉␉␉␉␉␉length = ((struct acpi_2_rsdt *)origTable3)->Length;␊ |
1309 | ␉␉␉␉␉␉verbose("saveOriginalACPI: OEM table X_DSDT@%016X found, lenght=%d: ", origTable3, length);␊ |
1310 | ␉␉␉␉␉␉if (origTable3 != (void *)(((struct acpi_2_fadt *)origTable2)->DSDT))␊ |
1311 | ␉␉␉␉␉␉{␊ |
1312 | ␉␉␉␉␉␉␉verbose("saving.\n");␊ |
1313 | ␉␉␉␉␉␉␉nameLen = strlen("X_DSDT@XXXXXXXX");␊ |
1314 | ␉␉␉␉␉␉␉nameBuf = malloc(nameLen + 1);␊ |
1315 | ␉␉␉␉␉␉␉sprintf(nameBuf, "X_DSDT@%08X", origTable3);␊ |
1316 | ␉␉␉␉␉␉␉DT__AddProperty(node, nameBuf, length, origTable3);␊ |
1317 | ␉␉␉␉␉␉␉total_length += length;␊ |
1318 | ␉␉␉␉␉␉␉total_number++;␊ |
1319 | ␉␉␉␉␉␉}␊ |
1320 | ␉␉␉␉␉␉else␊ |
1321 | ␉␉␉␉␉␉{␊ |
1322 | ␉␉␉␉␉␉␉verbose("already saved.\n");␊ |
1323 | ␉␉␉␉␉␉}␊ |
1324 | ␉␉␉␉␉␉continue;␊ |
1325 | ␉␉␉␉␉}␊ |
1326 | ␉␉␉␉}␊ |
1327 | ␉␉␉␉else␊ |
1328 | ␉␉␉␉{␊ |
1329 | ␉␉␉␉␉verbose("already saved.\n");␊ |
1330 | ␉␉␉␉}␊ |
1331 | ␉␉␉}␊ |
1332 | ␉␉}␊ |
1333 | ␉␉else␊ |
1334 | ␉␉{␊ |
1335 | ␉␉␉verbose("saveOriginalACPI: OEM table XSDT@%08X%08X not found or incorrect.\n", (uint32_t)(RSDP->XsdtAddress >> 32), (uint32_t)(RSDP->XsdtAddress & 0xFFFFFFFF));␊ |
1336 | ␉␉}␊ |
1337 | ␉}␊ |
1338 | ␊ |
1339 | ␉if (!RSDT && !XSDT)␊ |
1340 | ␉{␊ |
1341 | ␉␉verbose("saveOriginalACPI: OEM RSDT & XSDT not found or incorrect, can't save any tables.\n\n");␊ |
1342 | ␉␉return 0;␊ |
1343 | ␉}␊ |
1344 | ␊ |
1345 | ␉verbose("saveOriginalACPI: %d OEM table%s found and saved, total lenght=%d.\n\n", total_number, (total_number != 1) ? "s" : "", total_length);␊ |
1346 | #if DEBUG␊ |
1347 | pause("\n[DEBUG_FAKEEFI] ");␊ |
1348 | #endif␊ |
1349 | ␊ |
1350 | ␉return total_number;␊ |
1351 | }␊ |
1352 | ␊ |
1353 | /*␊ |
1354 | * Entrypoint from boot.c␊ |
1355 | */␊ |
1356 | void setupFakeEfi(void)␊ |
1357 | {␊ |
1358 | ␉// Generate efi device strings␊ |
1359 | ␉setup_pci_devs(root_pci_dev);␊ |
1360 | ␊ |
1361 | ␉readSMBIOSInfo(getSmbios(SMBIOS_ORIGINAL));␊ |
1362 | ␊ |
1363 | ␉// load smbios.plist file if any␊ |
1364 | ␉setupSmbiosConfigFile();␊ |
1365 | ␊ |
1366 | ␉// Setup ACPI with DSDT overrides (mackerintel's patch)␊ |
1367 | ␉setupAcpi();␊ |
1368 | ␊ |
1369 | ␉setupSMBIOS();␊ |
1370 | ␊ |
1371 | ␉// Setup board-id: need to be called after getSmbios!␊ |
1372 | ␉setupBoardId();␊ |
1373 | ␊ |
1374 | ␉// Setup system-type: We now have to write the systemm-type in ioregs: we cannot do it before in setupDeviceTree()␊ |
1375 | ␉// because we need to take care of FACP original content, if it is correct.␊ |
1376 | ␉setupSystemType();␊ |
1377 | ␊ |
1378 | ␉// Setup the '/' node␊ |
1379 | ␉//setupRootNode();␊ |
1380 | ␊ |
1381 | ␉// Setup the '/chosen' node␊ |
1382 | ␉setupChosenNode();␊ |
1383 | ␊ |
1384 | ␉// Initialize the base table␊ |
1385 | ␉if (archCpuType == CPU_TYPE_I386)␊ |
1386 | ␉{␊ |
1387 | ␉␉setupEfiTables32();␊ |
1388 | ␉}␊ |
1389 | ␉else␊ |
1390 | ␉{␊ |
1391 | ␉␉setupEfiTables64();␊ |
1392 | ␉}␊ |
1393 | ␊ |
1394 | ␉// Setup efi node␊ |
1395 | ␉setupEfiNode();␊ |
1396 | ␊ |
1397 | ␉saveOriginalSMBIOS();␊ |
1398 | ␊ |
1399 | ␉saveOriginalACPI();␊ |
1400 | }␊ |
1401 | |