1 | /*␊ |
2 | * Copyright (c) 1999-2003 Apple Computer, Inc. All rights reserved.␊ |
3 | *␊ |
4 | * @APPLE_LICENSE_HEADER_START@␊ |
5 | * ␊ |
6 | * Portions Copyright (c) 1999-2003 Apple Computer, Inc. All Rights␊ |
7 | * Reserved. This file contains Original Code and/or Modifications of␊ |
8 | * Original Code as defined in and that are subject to the Apple Public␊ |
9 | * Source License Version 2.0 (the "License").␉You may not use this file␊ |
10 | * except in compliance with the License. Please obtain a copy of the␊ |
11 | * License at http://www.apple.com/publicsource and read it before using␊ |
12 | * this file.␊ |
13 | * ␊ |
14 | * The Original Code and all software distributed under the License are␊ |
15 | * distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, EITHER␊ |
16 | * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,␊ |
17 | * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,␊ |
18 | * FITNESS FOR A PARTICULAR PURPOSE OR NON- INFRINGEMENT. Please see the␊ |
19 | * License for the specific language governing rights and limitations␊ |
20 | * under the License.␊ |
21 | * ␊ |
22 | * @APPLE_LICENSE_HEADER_END@␊ |
23 | */␊ |
24 | ␊ |
25 | /* ␊ |
26 | * Mach Operating System␊ |
27 | * Copyright (c) 1990 Carnegie-Mellon University␊ |
28 | * Copyright (c) 1989 Carnegie-Mellon University␊ |
29 | * All rights reserved.␉ The CMU software License Agreement specifies␊ |
30 | * the terms and conditions for use and redistribution.␊ |
31 | *␊ |
32 | * INTEL CORPORATION PROPRIETARY INFORMATION␊ |
33 | *␊ |
34 | * This software is supplied under the terms of a license agreement or ␊ |
35 | * nondisclosure agreement with Intel Corporation and may not be copied ␊ |
36 | * nor disclosed except in accordance with the terms of that agreement.␊ |
37 | *␊ |
38 | *␉Copyright 1988, 1989 by Intel Corporation␊ |
39 | *␊ |
40 | *␊ |
41 | * Copyright 1993 NeXT Computer, Inc.␊ |
42 | * All rights reserved.␊ |
43 | *␊ |
44 | * Completely reworked by Sam Streeper (sam_s@NeXT.com)␊ |
45 | * Reworked again by Curtis Galloway (galloway@NeXT.com)␊ |
46 | */␊ |
47 | ␊ |
48 | #include "boot.h"␊ |
49 | #include "bootstruct.h"␊ |
50 | #include "fake_efi.h"␊ |
51 | #include "sl.h"␊ |
52 | #include "libsa.h"␊ |
53 | #include "ramdisk.h"␊ |
54 | #include "gui.h"␊ |
55 | #include "platform.h"␊ |
56 | #include "modules.h"␊ |
57 | #include "device_tree.h"␊ |
58 | ␊ |
59 | #ifndef DEBUG_BOOT2␊ |
60 | ␉#define DEBUG_BOOT2 0␊ |
61 | #endif␊ |
62 | ␊ |
63 | #ifndef DEBUG_INTERRUPTS␊ |
64 | ␉#define DEBUG_INTERRUPTS 0␊ |
65 | #endif␊ |
66 | ␊ |
67 | #if DEBUG_BOOT2␊ |
68 | ␉#define DBG(x...)␉printf(x)␊ |
69 | #else␊ |
70 | ␉#define DBG(x...)␉msglog(x)␊ |
71 | #endif␊ |
72 | ␊ |
73 | /*␊ |
74 | * How long to wait (in seconds) to load the␊ |
75 | * kernel after displaying the "boot:" prompt.␊ |
76 | */␊ |
77 | #define kBootErrorTimeout 5␊ |
78 | ␊ |
79 | bool␉␉gOverrideKernel;␊ |
80 | bool␉␉gEnableCDROMRescan;␊ |
81 | bool␉␉gScanSingleDrive;␊ |
82 | bool␉␉useGUI;␊ |
83 | ␊ |
84 | #if DEBUG_INTERRUPTS␊ |
85 | ␉static int␉interruptsAvailable = 0;␊ |
86 | #endif␊ |
87 | ␊ |
88 | static bool␉gUnloadPXEOnExit = false;␊ |
89 | ␊ |
90 | static char␉gCacheNameAdler[64 + 256];␊ |
91 | char␉␉*gPlatformName = gCacheNameAdler;␊ |
92 | ␊ |
93 | char␉␉gRootDevice[ROOT_DEVICE_SIZE];␊ |
94 | char␉␉gMKextName[512];␊ |
95 | int␉␉bvCount = 0;␊ |
96 | int␉␉gDeviceCount = 0;␊ |
97 | //int␉␉menucount = 0;␊ |
98 | long␉␉gBootMode; /* defaults to 0 == kBootModeNormal */␊ |
99 | ␊ |
100 | BVRef␉␉bvr;␊ |
101 | BVRef␉␉menuBVR;␊ |
102 | BVRef␉␉bvChain;␊ |
103 | ␊ |
104 | static unsigned long␉Adler32(unsigned char *buffer, long length);␊ |
105 | //static void␉␉␉selectBiosDevice(void);␊ |
106 | ␊ |
107 | /** options.c **/␊ |
108 | extern char *msgbuf;␊ |
109 | void showTextBuffer(char *buf, int size);␊ |
110 | ␊ |
111 | //==========================================================================␊ |
112 | // Zero the BSS.␊ |
113 | ␊ |
114 | static void zeroBSS(void)␊ |
115 | {␊ |
116 | ␉extern char bss_start __asm("section$start$__DATA$__bss");␊ |
117 | ␉extern char bss_end __asm("section$end$__DATA$__bss");␊ |
118 | ␉extern char common_start __asm("section$start$__DATA$__common");␊ |
119 | ␉extern char common_end __asm("section$end$__DATA$__common");␊ |
120 | ␊ |
121 | ␉bzero(&bss_start, (&bss_end - &bss_start));␊ |
122 | ␉bzero(&common_start, (&common_end - &common_start));␊ |
123 | }␊ |
124 | ␊ |
125 | //==========================================================================␊ |
126 | // Malloc error function␊ |
127 | ␊ |
128 | static void malloc_error(char *addr, size_t size, const char *file, int line)␊ |
129 | {␊ |
130 | ␉stop("\nMemory allocation error! Addr: 0x%x, Size: 0x%x, File: %s, Line: %d\n",␊ |
131 | ␉␉␉␉␉␉␉␉␉ (unsigned)addr, (unsigned)size, file, line);␊ |
132 | }␊ |
133 | ␊ |
134 | //==========================================================================␊ |
135 | //Initializes the runtime. Right now this means zeroing the BSS and initializing malloc.␊ |
136 | //␊ |
137 | void initialize_runtime(void)␊ |
138 | {␊ |
139 | ␉zeroBSS();␊ |
140 | ␉malloc_init(0, 0, 0, malloc_error);␊ |
141 | }␊ |
142 | ␊ |
143 | //==========================================================================␊ |
144 | // ExecKernel - Load the kernel image (mach-o) and jump to its entry point.␊ |
145 | ␊ |
146 | static int ExecKernel(void *binary)␊ |
147 | {␊ |
148 | ␉int␉␉␉ret;␊ |
149 | ␉entry_t␉␉kernelEntry;␊ |
150 | ␊ |
151 | ␉bootArgs->kaddr = bootArgs->ksize = 0;␊ |
152 | ␉execute_hook("ExecKernel", (void *)binary, NULL, NULL, NULL);␊ |
153 | ␊ |
154 | ␉ret = DecodeKernel(binary,␊ |
155 | ␉␉␉␉␉ &kernelEntry,␊ |
156 | ␉␉␉␉␉ (char **) &bootArgs->kaddr,␊ |
157 | ␉␉␉␉␉ (int *)&bootArgs->ksize);␊ |
158 | ␊ |
159 | ␉if ( ret != 0 )␊ |
160 | ␉{␊ |
161 | ␉␉printf("Decoding kernel failed.\n");␊ |
162 | ␉␉pause();␊ |
163 | ␉␉return ret;␊ |
164 | ␉}␊ |
165 | ␊ |
166 | ␉// Reserve space for boot args␊ |
167 | ␉reserveKernBootStruct();␊ |
168 | ␊ |
169 | ␉// Notify modules that the kernel has been decoded␊ |
170 | ␉execute_hook("DecodedKernel", (void *)binary, (void *)bootArgs->kaddr, (void *)bootArgs->ksize, NULL);␊ |
171 | ␊ |
172 | ␉setupFakeEfi();␊ |
173 | ␊ |
174 | ␉// Load boot drivers from the specifed root path.␊ |
175 | ␉//if (!gHaveKernelCache)␊ |
176 | ␉{␊ |
177 | ␉␉LoadDrivers("/");␊ |
178 | ␉}␊ |
179 | ␊ |
180 | ␉execute_hook("DriversLoaded", (void *)binary, NULL, NULL, NULL);␊ |
181 | ␊ |
182 | ␉clearActivityIndicator();␊ |
183 | ␊ |
184 | ␉if (gErrors)␊ |
185 | ␉{␊ |
186 | ␉␉printf("Errors encountered while starting up the computer.\n");␊ |
187 | ␉␉printf("Pausing %d seconds...\n", kBootErrorTimeout);␊ |
188 | ␉␉sleep(kBootErrorTimeout);␊ |
189 | ␉}␊ |
190 | ␊ |
191 | ␉md0Ramdisk();␊ |
192 | ␊ |
193 | ␉// Cleanup the PXE base code.␊ |
194 | ␊ |
195 | ␉if ( (gBootFileType == kNetworkDeviceType) && gUnloadPXEOnExit )␊ |
196 | ␉{␊ |
197 | ␉␉if ( (ret = nbpUnloadBaseCode()) != nbpStatusSuccess )␊ |
198 | ␉␉{␊ |
199 | ␉␉␉printf("nbpUnloadBaseCode error %d\n", (int)ret);␊ |
200 | ␉␉␉sleep(2);␊ |
201 | ␉␉}␊ |
202 | ␉}␊ |
203 | ␊ |
204 | ␉bool dummyVal;␊ |
205 | ␉if (getBoolForKey(kWaitForKeypressKey, &dummyVal, &bootInfo->chameleonConfig) && dummyVal)␊ |
206 | ␉{␊ |
207 | ␉␉showTextBuffer(msgbuf, strlen(msgbuf));␊ |
208 | ␉}␊ |
209 | ␊ |
210 | ␉usb_loop();␊ |
211 | ␊ |
212 | #if DEBUG␊ |
213 | ␉if (interruptsAvailable) ShowInterruptCounters();␊ |
214 | #endif␊ |
215 | ␊ |
216 | ␉// If we were in text mode, switch to graphics mode.␊ |
217 | ␉// This will draw the boot graphics unless we are in␊ |
218 | ␉// verbose mode.␊ |
219 | ␉if (gVerboseMode)␊ |
220 | ␉{␊ |
221 | ␉␉setVideoMode( GRAPHICS_MODE );␊ |
222 | ␉}␊ |
223 | ␉else␊ |
224 | ␉{␊ |
225 | ␉␉drawBootGraphics();␊ |
226 | ␉}␊ |
227 | ␊ |
228 | ␉DBG("Starting Darwin/%s [%s]\n",( archCpuType == CPU_TYPE_I386 ) ? "x86" : "x86_64", gDarwinBuildVerStr);␊ |
229 | ␉DBG("Boot Args: %s\n", bootArgs->CommandLine);␊ |
230 | ␊ |
231 | ␉setupBooterLog();␊ |
232 | ␊ |
233 | ␉finalizeBootStruct();␊ |
234 | ␊ |
235 | ␉// Jump to kernel's entry point. There's no going back now.␊ |
236 | ␉if ( TIGER || LEOPARD || SNOW_LEOPARD )␊ |
237 | ␉{␊ |
238 | ␉␉// Notify modules that the kernel is about to be started␊ |
239 | ␉␉execute_hook("Kernel Start", (void *)kernelEntry, (void *)bootArgsLegacy, NULL, NULL);␊ |
240 | ␊ |
241 | ␉␉startprog( kernelEntry, bootArgsLegacy );␊ |
242 | ␉}␊ |
243 | ␉else␊ |
244 | ␉{␊ |
245 | ␉␉// Notify modules that the kernel is about to be started␊ |
246 | ␉␉execute_hook("Kernel Start", (void *)kernelEntry, (void *)bootArgs, NULL, NULL);␊ |
247 | ␊ |
248 | ␉␉startprog( kernelEntry, bootArgs );␊ |
249 | ␉}␊ |
250 | ␊ |
251 | ␉// Not reached␊ |
252 | ␉__builtin_unreachable();␊ |
253 | }␊ |
254 | ␊ |
255 | //==========================================================================␊ |
256 | // LoadKernelCache - Try to load Kernel Cache.␊ |
257 | // return the length of the loaded cache file or -1 on error␊ |
258 | long LoadKernelCache(const char *cacheFile, void **binary)␊ |
259 | {␊ |
260 | ␉char␉␉kernelCacheFile[512];␊ |
261 | ␉char␉␉kernelCachePath[512];␊ |
262 | ␉long␉␉flags, ret=-1;␊ |
263 | ␉unsigned long adler32;␊ |
264 | ␉u_int32_t time, cachetime, kerneltime, exttime;␊ |
265 | ␊ |
266 | ␉if((gBootMode & kBootModeSafe) != 0)␊ |
267 | ␉{␊ |
268 | ␉␉DBG("Kernel Cache ignored.\n");␊ |
269 | ␉␉return -1;␊ |
270 | ␉}␊ |
271 | ␊ |
272 | ␉// Use specify kernel cache file if not empty␊ |
273 | ␉if (cacheFile[0] != 0)␊ |
274 | ␉{␊ |
275 | ␉␉strlcpy(kernelCacheFile, cacheFile, sizeof(kernelCacheFile));␊ |
276 | ␉␉verbose("Specified kernel cache file path: %s\n", cacheFile);␊ |
277 | ␉}␊ |
278 | ␉else␊ |
279 | ␉{␊ |
280 | ␉␉// Leopard prelink kernel cache file␊ |
281 | ␉␉if ( TIGER || LEOPARD ) // OSX is 10.4 or 10.5␊ |
282 | ␉␉{␊ |
283 | ␉␉␉// Reset cache name.␊ |
284 | ␉␉␉bzero(gCacheNameAdler + 64, sizeof(gCacheNameAdler) - 64);␊ |
285 | ␉␉␉snprintf(gCacheNameAdler + 64, sizeof(gCacheNameAdler) - 64, "%s,%s", gRootDevice, bootInfo->bootFile);␊ |
286 | ␉␉␉adler32 = Adler32((unsigned char *)gCacheNameAdler, sizeof(gCacheNameAdler));␊ |
287 | ␉␉␉snprintf(kernelCacheFile, sizeof(kernelCacheFile), "%s.%08lX", kDefaultCachePathLeo, adler32);␊ |
288 | ␉␉␉verbose("Reseted kernel cache file path: %s\n", kernelCacheFile);␊ |
289 | ␊ |
290 | ␉␉}␊ |
291 | ␉␉// Snow Leopard prelink kernel cache file␊ |
292 | ␉␉else if ( SNOW_LEOPARD )␊ |
293 | ␉␉{␊ |
294 | ␉␉␉snprintf(kernelCacheFile, sizeof(kernelCacheFile), "kernelcache_%s",␊ |
295 | ␉␉␉␉(archCpuType == CPU_TYPE_I386) ? "i386" : "x86_64");␊ |
296 | ␊ |
297 | ␉␉␉int␉␉lnam = strlen(kernelCacheFile) + 9; //with adler32␊ |
298 | ␉␉␉char␉␉*name;␊ |
299 | ␉␉␉u_int32_t␉prev_time = 0;␊ |
300 | ␊ |
301 | ␉␉␉struct dirstuff *cacheDir = opendir(kDefaultCachePathSnow);␊ |
302 | ␊ |
303 | ␉␉␉/* TODO: handle error? */␊ |
304 | ␉␉␉if (cacheDir)␊ |
305 | ␉␉␉{␊ |
306 | ␉␉␉␉while(readdir(cacheDir, (const char**)&name, &flags, &time) >= 0)␊ |
307 | ␉␉␉␉{␊ |
308 | ␉␉␉␉␉if (((flags & kFileTypeMask) != kFileTypeDirectory) && time > prev_time␊ |
309 | ␉␉␉␉␉␉&& strstr(name, kernelCacheFile) && (name[lnam] != '.'))␊ |
310 | ␉␉␉␉␉{␊ |
311 | ␉␉␉␉␉␉snprintf(kernelCacheFile, sizeof(kernelCacheFile), "%s%s", kDefaultCachePathSnow, name);␊ |
312 | ␉␉␉␉␉␉prev_time = time;␊ |
313 | ␉␉␉␉␉}␊ |
314 | ␉␉␉␉}␊ |
315 | ␉␉␉␉verbose("Kernel Cache file path (Mac OS X 10.6): %s\n", kernelCachePath);␊ |
316 | ␉␉␉}␊ |
317 | ␉␉␉closedir(cacheDir);␊ |
318 | ␉␉}␊ |
319 | ␉␉else␊ |
320 | ␉␉{␊ |
321 | ␉␉␉// Lion, Mountain Lion, Mavericks, Yosemite and El Capitan prelink kernel cache file␊ |
322 | ␉␉␉// for 10.7 10.8 10.9 10.10 10.11␊ |
323 | ␉␉␉snprintf(kernelCacheFile, sizeof(kernelCacheFile), "%skernelcache", kDefaultCachePathSnow);␊ |
324 | ␉␉␉verbose("Kernel Cache file path (Mac OS X 10.7 and newer): %s\n", kernelCachePath);␊ |
325 | ␊ |
326 | ␉␉}␊ |
327 | ␉}␊ |
328 | ␊ |
329 | ␉// Check if the kernel cache file exists␊ |
330 | ␉ret = -1;␊ |
331 | ␊ |
332 | ␉// If boot from a boot helper partition check the kernel cache file on it␊ |
333 | ␉if (gBootVolume->flags & kBVFlagBooter)␊ |
334 | ␉{␊ |
335 | ␉␉snprintf(kernelCachePath, sizeof(kernelCachePath), "/com.apple.boot.P/%s", kernelCacheFile);␊ |
336 | ␉␉ret = GetFileInfo(NULL, kernelCachePath, &flags, &cachetime);␊ |
337 | ␊ |
338 | ␉␉if ((ret == -1) || ((flags & kFileTypeMask) != kFileTypeFlat))␊ |
339 | ␉␉{␊ |
340 | ␉␉␉snprintf(kernelCachePath, sizeof(kernelCachePath), "/com.apple.boot.R/%s", kernelCacheFile);␊ |
341 | ␉␉␉ret = GetFileInfo(NULL, kernelCachePath, &flags, &cachetime);␊ |
342 | ␊ |
343 | ␉␉␉if ((ret == -1) || ((flags & kFileTypeMask) != kFileTypeFlat))␊ |
344 | ␉␉␉{␊ |
345 | ␉␉␉␉snprintf(kernelCachePath, sizeof(kernelCachePath), "/com.apple.boot.S/%s", kernelCacheFile);␊ |
346 | ␉␉␉␉ret = GetFileInfo(NULL, kernelCachePath, &flags, &cachetime);␊ |
347 | ␊ |
348 | ␉␉␉␉if ((ret == -1) || ((flags & kFileTypeMask) != kFileTypeFlat))␊ |
349 | ␉␉␉␉{␊ |
350 | ␉␉␉␉␉strncpy(kernelCachePath, "/com.apple.recovery.boot/kernelcache", sizeof(kernelCachePath) );␊ |
351 | ␉␉␉␉␉ret = GetFileInfo(NULL, kernelCachePath, &flags, &cachetime);␊ |
352 | ␊ |
353 | ␉␉␉␉␉if ((flags & kFileTypeMask) != kFileTypeFlat)␊ |
354 | ␉␉␉␉␉{␊ |
355 | ␉␉␉␉␉␉ret = -1;␊ |
356 | ␉␉␉␉␉}␊ |
357 | ␉␉␉␉}␊ |
358 | ␉␉␉}␊ |
359 | ␉␉}␊ |
360 | ␉}␊ |
361 | ␊ |
362 | ␉// If not found, use the original kernel cache path.␊ |
363 | ␉if (ret == -1)␊ |
364 | ␉{␊ |
365 | ␉␉strlcpy(kernelCachePath, kernelCacheFile, sizeof(kernelCachePath));␊ |
366 | ␉␉ret = GetFileInfo(NULL, kernelCachePath, &flags, &cachetime);␊ |
367 | ␊ |
368 | ␉␉if ((flags & kFileTypeMask) != kFileTypeFlat)␊ |
369 | ␉␉{␊ |
370 | ␉␉␉ret = -1;␊ |
371 | ␉␉}␊ |
372 | ␉}␊ |
373 | ␊ |
374 | ␉// Exit if kernel cache file wasn't found␊ |
375 | ␉if (ret == -1)␊ |
376 | ␉{␊ |
377 | ␉␉DBG("No Kernel Cache File '%s' found\n", kernelCacheFile);␊ |
378 | ␉␉return -1;␊ |
379 | ␉}␊ |
380 | ␊ |
381 | ␉// Check if the kernel cache file is more recent (mtime)␊ |
382 | ␉// than the kernel file or the S/L/E directory␊ |
383 | ␉ret = GetFileInfo(NULL, bootInfo->bootFile, &flags, &kerneltime);␊ |
384 | ␊ |
385 | ␉// Check if the kernel file is more recent than the cache file␊ |
386 | ␉if ((ret == 0) && ((flags & kFileTypeMask) == kFileTypeFlat) && (kerneltime > cachetime))␊ |
387 | ␉{␊ |
388 | ␉␉DBG("Kernel file '%s' is more recent than Kernel Cache '%s'! Ignoring Kernel Cache.\n", bootInfo->bootFile, kernelCacheFile);␊ |
389 | ␉␉return -1;␊ |
390 | ␉}␊ |
391 | ␊ |
392 | ␉ret = GetFileInfo("/System/Library/", "Extensions", &flags, &exttime);␊ |
393 | ␊ |
394 | ␉// Check if the S/L/E directory time is more recent than the cache file␊ |
395 | ␉if ((ret == 0) && ((flags & kFileTypeMask) == kFileTypeDirectory) && (exttime > cachetime))␊ |
396 | ␉{␊ |
397 | ␉␉DBG("Folder '/System/Library/Extensions' is more recent than Kernel Cache file '%s'! Ignoring Kernel Cache.\n", kernelCacheFile);␊ |
398 | ␉␉return -1;␊ |
399 | ␉}␊ |
400 | ␊ |
401 | ␉// Since the kernel cache file exists and is the most recent try to load it␊ |
402 | ␉DBG("Loading Kernel Cache from: '%s%s' (%s)\n", gBootVolume->label, gBootVolume->altlabel, gBootVolume->type_name);␊ |
403 | ␊ |
404 | ␉ret = LoadThinFatFile(kernelCachePath, binary);␊ |
405 | ␉return ret; // ret contain the length of the binary␊ |
406 | }␊ |
407 | ␊ |
408 | //==========================================================================␊ |
409 | // This is the entrypoint from real-mode which functions exactly as it did␊ |
410 | // before. Multiboot does its own runtime initialization, does some of its␊ |
411 | // own things, and then calls common_boot.␊ |
412 | void boot(int biosdev)␊ |
413 | {␊ |
414 | ␉initialize_runtime();␊ |
415 | ␉// Enable A20 gate before accessing memory above 1Mb.␊ |
416 | ␉enableA20();␊ |
417 | ␉common_boot(biosdev);␊ |
418 | }␊ |
419 | ␊ |
420 | //==========================================================================␊ |
421 | // The 'main' function for the booter. Called by boot0 when booting␊ |
422 | // from a block device, or by the network booter.␊ |
423 | //␊ |
424 | // arguments:␊ |
425 | //␉ biosdev - Value passed from boot1/NBP to specify the device␊ |
426 | //␉␉␉ that the booter was loaded from.␊ |
427 | //␊ |
428 | // If biosdev is kBIOSDevNetwork, then this function will return if␊ |
429 | // booting was unsuccessful. This allows the PXE firmware to try the␊ |
430 | // next boot device on its list.␊ |
431 | void common_boot(int biosdev)␊ |
432 | {␊ |
433 | ␉bool␉ ␉␉quiet;␊ |
434 | ␉bool␉ ␉␉firstRun = true;␊ |
435 | ␉bool␉ ␉␉instantMenu;␊ |
436 | ␉bool␉ ␉␉rescanPrompt;␊ |
437 | ␉int␉␉␉status;␊ |
438 | ␉unsigned int␉␉allowBVFlags = kBVFlagSystemVolume | kBVFlagForeignBoot;␊ |
439 | ␉unsigned int␉␉denyBVFlags = kBVFlagEFISystem;␊ |
440 | ␊ |
441 | ␉// Set reminder to unload the PXE base code. Neglect to unload␊ |
442 | ␉// the base code will result in a hang or kernel panic.␊ |
443 | ␉gUnloadPXEOnExit = true;␊ |
444 | ␊ |
445 | ␉// Record the device that the booter was loaded from.␊ |
446 | ␉gBIOSDev = biosdev & kBIOSDevMask;␊ |
447 | ␊ |
448 | ␉// Initialize boot-log␊ |
449 | ␉initBooterLog();␊ |
450 | ␊ |
451 | #if DEBUG_INTERRUPTS␊ |
452 | ␉// Enable interrupts␊ |
453 | ␉interruptsAvailable = SetupInterrupts();␊ |
454 | ␉if (interruptsAvailable)␊ |
455 | ␉{␊ |
456 | ␉␉EnableInterrupts();␊ |
457 | ␉}␊ |
458 | #endif␊ |
459 | ␊ |
460 | ␉// Initialize boot info structure.␊ |
461 | ␉initKernBootStruct();␊ |
462 | ␊ |
463 | ␉// Setup VGA text mode.␊ |
464 | ␉// Not sure if it is safe to call setVideoMode() before the␊ |
465 | ␉// config table has been loaded. Call video_mode() instead.␊ |
466 | #if DEBUG␊ |
467 | ␉printf("before video_mode\n");␊ |
468 | #endif␊ |
469 | ␉video_mode( 2 ); // 80x25 mono text mode.␊ |
470 | #if DEBUG␊ |
471 | ␉printf("after video_mode\n");␊ |
472 | #endif␊ |
473 | ␊ |
474 | ␉// Scan and record the system's hardware information.␊ |
475 | ␉scan_platform();␊ |
476 | ␊ |
477 | ␉// First get info for boot volume.␊ |
478 | ␉scanBootVolumes(gBIOSDev, 0);␊ |
479 | ␉bvChain = getBVChainForBIOSDev(gBIOSDev);␊ |
480 | ␉setBootGlobals(bvChain);␊ |
481 | ␊ |
482 | ␉// Load boot.plist config file␊ |
483 | ␉status = loadChameleonConfig(&bootInfo->chameleonConfig, bvChain);␊ |
484 | ␊ |
485 | ␉if (getBoolForKey(kQuietBootKey, &quiet, &bootInfo->chameleonConfig) && quiet)␊ |
486 | ␉{␊ |
487 | ␉␉gBootMode |= kBootModeQuiet;␊ |
488 | ␉}␊ |
489 | ␊ |
490 | ␉// Override firstRun to get to the boot menu instantly by setting "Instant Menu"=y in system config␊ |
491 | ␉if (getBoolForKey(kInstantMenuKey, &instantMenu, &bootInfo->chameleonConfig) && instantMenu)␊ |
492 | ␉{␊ |
493 | ␉␉firstRun = false;␊ |
494 | ␉}␊ |
495 | ␊ |
496 | ␉// Loading preboot ramdisk if exists.␊ |
497 | ␉loadPrebootRAMDisk();␊ |
498 | ␊ |
499 | ␉// Disable rescan option by default␊ |
500 | ␉gEnableCDROMRescan = false;␊ |
501 | ␊ |
502 | ␉// Enable it with Rescan=y in system config␊ |
503 | ␉if (getBoolForKey(kRescanKey, &gEnableCDROMRescan, &bootInfo->chameleonConfig)␉&& gEnableCDROMRescan)␊ |
504 | ␉{␊ |
505 | ␉␉gEnableCDROMRescan = true;␊ |
506 | ␉}␊ |
507 | ␊ |
508 | ␉// Disable rescanPrompt option by default␊ |
509 | ␉rescanPrompt = false;␊ |
510 | ␊ |
511 | ␉// Ask the user for Rescan option by setting "Rescan Prompt"=y in system config.␊ |
512 | ␉if (getBoolForKey(kRescanPromptKey, &rescanPrompt , &bootInfo->chameleonConfig) && rescanPrompt && biosDevIsCDROM(gBIOSDev))␊ |
513 | ␉{␊ |
514 | ␉␉gEnableCDROMRescan = promptForRescanOption();␊ |
515 | ␉}␊ |
516 | ␊ |
517 | ␉// Enable touching a single BIOS device only if "Scan Single Drive"=y is set in system config.␊ |
518 | ␉if (getBoolForKey(kScanSingleDriveKey, &gScanSingleDrive, &bootInfo->chameleonConfig) && gScanSingleDrive)␊ |
519 | ␉{␊ |
520 | ␉␉gScanSingleDrive = true;␊ |
521 | ␉}␊ |
522 | ␊ |
523 | ␉// Create a list of partitions on device(s).␊ |
524 | ␉if (gScanSingleDrive)␊ |
525 | ␉{␊ |
526 | ␉␉scanBootVolumes(gBIOSDev, &bvCount);␊ |
527 | ␉}␊ |
528 | ␉else␊ |
529 | ␉{␊ |
530 | ␉␉scanDisks(gBIOSDev, &bvCount);␊ |
531 | ␉}␊ |
532 | ␊ |
533 | ␉// Create a separated bvr chain using the specified filters.␊ |
534 | ␉bvChain = newFilteredBVChain(0x80, 0xFF, allowBVFlags, denyBVFlags, &gDeviceCount);␊ |
535 | ␊ |
536 | ␉gBootVolume = selectBootVolume(bvChain);␊ |
537 | ␊ |
538 | ␉// Intialize module system␊ |
539 | ␉init_module_system();␊ |
540 | ␊ |
541 | #if DEBUG␊ |
542 | ␉printf("Default: %d, ->biosdev: %d, ->part_no: %d ->flags: 0x%08X\n",␊ |
543 | ␉␉gBootVolume, gBootVolume->biosdev, gBootVolume->part_no, gBootVolume->flags);␊ |
544 | ␉printf("bt(0,0): %d, ->biosdev: %d, ->part_no: %d ->flags: 0x%08X\n",␊ |
545 | ␉␉gBIOSBootVolume, gBIOSBootVolume->biosdev, gBIOSBootVolume->part_no, gBIOSBootVolume->flags);␊ |
546 | ␉getchar();␊ |
547 | #endif␊ |
548 | ␊ |
549 | ␉useGUI = true;␊ |
550 | ␉// Override useGUI default␊ |
551 | ␉getBoolForKey(kGUIKey, &useGUI, &bootInfo->chameleonConfig);␊ |
552 | ␉if (useGUI && initGUI())␊ |
553 | ␉{␊ |
554 | ␉␉// initGUI() returned with an error, disabling GUI.␊ |
555 | ␉␉useGUI = false;␊ |
556 | ␉}␊ |
557 | ␊ |
558 | ␉setBootGlobals(bvChain);␊ |
559 | ␊ |
560 | ␉// Parse args, load and start kernel.␊ |
561 | ␉while (1)␊ |
562 | ␉{␊ |
563 | ␉␉bool␉␉tryresume, tryresumedefault, forceresume;␊ |
564 | ␉␉bool␉␉useKernelCache = true; // by default try to use the prelinked kernel␊ |
565 | ␉␉const char␉*val;␊ |
566 | ␉␉int␉␉␉len, ret = -1;␊ |
567 | ␉␉long␉␉flags;␊ |
568 | ␉␉u_int32_t␉sleeptime, time;␊ |
569 | ␉␉void␉␉*binary = (void *)kLoadAddr;␊ |
570 | ␊ |
571 | ␉␉char␉␉bootFile[sizeof(bootInfo->bootFile)];␊ |
572 | ␉␉char␉␉bootFilePath[512];␊ |
573 | ␉␉char␉␉kernelCacheFile[512];␊ |
574 | ␊ |
575 | ␉␉// Initialize globals.␊ |
576 | ␉␉sysConfigValid = false;␊ |
577 | ␉␉gErrors␉␉ = false;␊ |
578 | ␊ |
579 | ␉␉status = getBootOptions(firstRun);␊ |
580 | ␉␉firstRun = false;␊ |
581 | ␉␉if (status == -1) continue;␊ |
582 | ␊ |
583 | ␉␉status = processBootOptions();␊ |
584 | ␉␉// Status == 1 means to chainboot␊ |
585 | ␉␉if ( status ==␉1 ) break;␊ |
586 | ␉␉// Status == -1 means that the config file couldn't be loaded or that gBootVolume is NULL␊ |
587 | ␉␉if ( status == -1 )␊ |
588 | ␉␉{␊ |
589 | ␉␉␉// gBootVolume == NULL usually means the user hit escape.␊ |
590 | ␉␉␉if (gBootVolume == NULL)␊ |
591 | ␉␉␉{␊ |
592 | ␉␉␉␉freeFilteredBVChain(bvChain);␊ |
593 | ␊ |
594 | ␉␉␉␉if (gEnableCDROMRescan)␊ |
595 | ␉␉␉␉␉rescanBIOSDevice(gBIOSDev);␊ |
596 | ␊ |
597 | ␉␉␉␉bvChain = newFilteredBVChain(0x80, 0xFF, allowBVFlags, denyBVFlags, &gDeviceCount);␊ |
598 | ␉␉␉␉setBootGlobals(bvChain);␊ |
599 | ␉␉␉␉setupDeviceList(&bootInfo->themeConfig);␊ |
600 | ␉␉␉}␊ |
601 | ␉␉␉continue;␊ |
602 | ␉␉}␊ |
603 | ␊ |
604 | ␉␉// Other status (e.g. 0) means that we should proceed with boot.␊ |
605 | ␊ |
606 | ␉␉// Turn off any GUI elements␊ |
607 | ␉␉if ( bootArgs->Video.v_display == GRAPHICS_MODE )␊ |
608 | ␉␉{␊ |
609 | ␉␉␉gui.devicelist.draw = false;␊ |
610 | ␉␉␉gui.bootprompt.draw = false;␊ |
611 | ␉␉␉gui.menu.draw = false;␊ |
612 | ␉␉␉gui.infobox.draw = false;␊ |
613 | ␉␉␉gui.logo.draw = false;␊ |
614 | ␉␉␉drawBackground();␊ |
615 | ␉␉␉updateVRAM();␊ |
616 | ␉␉}␊ |
617 | ␊ |
618 | ␉␉if (platformCPUFeature(CPU_FEATURE_EM64T))␊ |
619 | ␉␉{␊ |
620 | ␉␉␉archCpuType = CPU_TYPE_X86_64;␊ |
621 | ␉␉}␊ |
622 | ␉␉else␊ |
623 | ␉␉{␊ |
624 | ␉␉␉archCpuType = CPU_TYPE_I386;␊ |
625 | ␉␉}␊ |
626 | ␊ |
627 | ␉␉if (getValueForKey(karch, &val, &len, &bootInfo->chameleonConfig))␊ |
628 | ␉␉{␊ |
629 | ␉␉␉if (strncmp(val, "x86_64", sizeof("x86_64") ) == 0)␊ |
630 | ␉␉␉{␊ |
631 | ␉␉␉␉archCpuType = CPU_TYPE_X86_64;␊ |
632 | ␉␉␉}␊ |
633 | ␉␉␉else if (strncmp(val, "i386", sizeof("i386") ) == 0)␊ |
634 | ␉␉␉{␊ |
635 | ␉␉␉␉archCpuType = CPU_TYPE_I386;␊ |
636 | ␉␉␉}␊ |
637 | ␉␉␉else␊ |
638 | ␉␉␉{␊ |
639 | ␉␉␉␉DBG("Incorrect parameter for option 'arch =' , please use x86_64 or i386\n");␊ |
640 | ␉␉␉}␊ |
641 | ␉␉}␊ |
642 | ␊ |
643 | ␉␉if (getValueForKey(kKernelArchKey, &val, &len, &bootInfo->chameleonConfig))␊ |
644 | ␉␉{␊ |
645 | ␉␉␉if (strncmp(val, "i386", sizeof("i386") ) == 0)␊ |
646 | ␉␉␉{␊ |
647 | ␉␉␉␉archCpuType = CPU_TYPE_I386;␊ |
648 | ␉␉␉}␊ |
649 | ␉␉}␊ |
650 | ␊ |
651 | ␉␉// Notify modules that we are attempting to boot␊ |
652 | ␉␉execute_hook("PreBoot", NULL, NULL, NULL, NULL);␊ |
653 | ␊ |
654 | ␉␉if (!getBoolForKey (kWake, &tryresume, &bootInfo->chameleonConfig))␊ |
655 | ␉␉{␊ |
656 | ␉␉␉tryresume = true;␊ |
657 | ␉␉␉tryresumedefault = true;␊ |
658 | ␉␉}␊ |
659 | ␉␉else␊ |
660 | ␉␉{␊ |
661 | ␉␉␉tryresumedefault = false;␊ |
662 | ␉␉}␊ |
663 | ␊ |
664 | ␉␉if (!getBoolForKey (kForceWake, &forceresume, &bootInfo->chameleonConfig)) {␊ |
665 | ␉␉␉forceresume = false;␊ |
666 | ␉␉}␊ |
667 | ␊ |
668 | ␉␉if (forceresume)␊ |
669 | ␉␉{␊ |
670 | ␉␉␉tryresume = true;␊ |
671 | ␉␉␉tryresumedefault = false;␊ |
672 | ␉␉}␊ |
673 | ␊ |
674 | ␉␉while (tryresume)␊ |
675 | ␉␉{␊ |
676 | ␉␉␉const char *tmp;␊ |
677 | ␉␉␉BVRef bvr;␊ |
678 | ␉␉␉if (!getValueForKey(kWakeImage, &val, &len, &bootInfo->chameleonConfig))␊ |
679 | ␉␉␉␉val = "/private/var/vm/sleepimage";␊ |
680 | ␊ |
681 | ␉␉␉// Do this first to be sure that root volume is mounted␊ |
682 | ␉␉␉ret = GetFileInfo(0, val, &flags, &sleeptime);␊ |
683 | ␊ |
684 | ␉␉␉if ((bvr = getBootVolumeRef(val, &tmp)) == NULL)␊ |
685 | ␉␉␉␉break;␊ |
686 | ␊ |
687 | ␉␉␉// Can't check if it was hibernation Wake=y is required␊ |
688 | ␉␉␉if (bvr->modTime == 0 && tryresumedefault)␊ |
689 | ␉␉␉␉break;␊ |
690 | ␊ |
691 | ␉␉␉if ((ret != 0) || ((flags & kFileTypeMask) != kFileTypeFlat))␊ |
692 | ␉␉␉␉break;␊ |
693 | ␊ |
694 | ␉␉␉if (!forceresume && ((sleeptime+3)<bvr->modTime))␊ |
695 | ␉␉␉{␊ |
696 | #if DEBUG␊ |
697 | ␉␉␉␉printf ("Hibernate image is too old by %d seconds. Use ForceWake=y to override\n",␊ |
698 | ␉␉␉␉␉␉bvr->modTime-sleeptime);␊ |
699 | #endif␊ |
700 | ␉␉␉␉break;␊ |
701 | ␉␉␉}␊ |
702 | ␊ |
703 | ␉␉␉HibernateBoot((char *)val);␊ |
704 | ␉␉␉break;␊ |
705 | ␉␉}␊ |
706 | ␊ |
707 | ␉␉getBoolForKey(kUseKernelCache, &useKernelCache, &bootInfo->chameleonConfig);␊ |
708 | ␉␉if (useKernelCache)␊ |
709 | ␉␉{␊ |
710 | ␉␉␉do␊ |
711 | ␉␉␉{␊ |
712 | ␉␉␉␉// Determine the name of the Kernel Cache␊ |
713 | ␉␉␉␉if (getValueForKey(kKernelCacheKey, &val, &len, &bootInfo->bootConfig))␊ |
714 | ␉␉␉␉{␊ |
715 | ␉␉␉␉␉if (val[0] == '\\')␊ |
716 | ␉␉␉␉␉{␊ |
717 | ␉␉␉␉␉␉len--;␊ |
718 | ␉␉␉␉␉␉val++;␊ |
719 | ␉␉␉␉␉}␊ |
720 | ␉␉␉␉␉/* FIXME: check len vs sizeof(kernelCacheFile) */␊ |
721 | ␉␉␉␉␉strlcpy(kernelCacheFile, val, len + 1);␊ |
722 | ␉␉␉␉}␊ |
723 | ␉␉␉␉else␊ |
724 | ␉␉␉␉{␊ |
725 | ␉␉␉␉␉kernelCacheFile[0] = 0; // Use default kernel cache file␊ |
726 | ␉␉␉␉}␊ |
727 | ␊ |
728 | ␉␉␉␉if (gOverrideKernel && kernelCacheFile[0] == 0)␊ |
729 | ␉␉␉␉{␊ |
730 | ␉␉␉␉␉DBG("Using a non default kernel (%s) without specifying 'Kernel Cache' path, KernelCache will not be used\n", bootInfo->bootFile);␊ |
731 | ␉␉␉␉␉useKernelCache = false;␊ |
732 | ␉␉␉␉␉break;␊ |
733 | ␉␉␉␉}␊ |
734 | ␊ |
735 | ␉␉␉␉if (gMKextName[0] != 0)␊ |
736 | ␉␉␉␉{␊ |
737 | ␉␉␉␉␉DBG("Using a specific MKext Cache (%s), KernelCache will not be used\n", gMKextName);␊ |
738 | ␉␉␉␉␉useKernelCache = false;␊ |
739 | ␉␉␉␉␉break;␊ |
740 | ␉␉␉␉}␊ |
741 | ␊ |
742 | ␉␉␉␉if (gBootFileType != kBlockDeviceType)␊ |
743 | ␉␉␉␉{␊ |
744 | ␉␉␉␉␉useKernelCache = false;␊ |
745 | ␉␉␉␉}␊ |
746 | ␊ |
747 | ␉␉␉} while(0);␊ |
748 | ␉␉}␊ |
749 | ␉␉else␊ |
750 | ␉␉{␊ |
751 | ␉␉␉DBG("Kernel Cache using disabled by user.\n");␊ |
752 | ␉␉}␊ |
753 | ␊ |
754 | ␉␉do␊ |
755 | ␉␉{␊ |
756 | ␉␉␉if (useKernelCache)␊ |
757 | ␉␉␉{␊ |
758 | ␉␉␉␉ret = LoadKernelCache(kernelCacheFile, &binary);␊ |
759 | ␉␉␉␉if (ret >= 0)␊ |
760 | ␉␉␉␉{␊ |
761 | ␉␉␉␉␉break;␊ |
762 | ␉␉␉␉}␊ |
763 | ␉␉␉}␊ |
764 | ␊ |
765 | ␉␉␉bool bootFileWithDevice = false;␊ |
766 | ␉␉␉// Check if bootFile start with a device ex: bt(0,0)/Extra/mach_kernel␊ |
767 | ␉␉␉if (strncmp(bootInfo->bootFile, "bt(", sizeof("bt(") ) == 0 ||␊ |
768 | ␉␉␉␉strncmp(bootInfo->bootFile, "hd(", sizeof("hd(") ) == 0 ||␊ |
769 | ␉␉␉␉strncmp(bootInfo->bootFile, "rd(", sizeof("rd(") ) == 0)␊ |
770 | ␉␉␉{␊ |
771 | ␉␉␉␉bootFileWithDevice = true;␊ |
772 | ␉␉␉}␊ |
773 | ␊ |
774 | ␉␉␉// bootFile must start with a / if it not start with a device name␊ |
775 | ␉␉␉if (!bootFileWithDevice && (bootInfo->bootFile)[0] != '/')␊ |
776 | ␉␉␉{␊ |
777 | ␉␉␉␉if ( !YOSEMITE || !ELCAPITAN ) //Is not Yosemite 10.10 or El Capitan 10.11␊ |
778 | ␉␉␉␉{␊ |
779 | ␉␉␉␉␉snprintf(bootFile, sizeof(bootFile), "/%s", bootInfo->bootFile); // append a leading /␊ |
780 | ␉␉␉␉}␊ |
781 | ␉␉␉␉else␊ |
782 | ␉␉␉␉{␊ |
783 | ␉␉␉␉␉snprintf(bootFile, sizeof(bootFile), kDefaultKernelPathForYos"%s", bootInfo->bootFile); // Yosemite or El Capitan␊ |
784 | ␉␉␉␉}␊ |
785 | ␉␉␉}␊ |
786 | ␉␉␉else␊ |
787 | ␉␉␉{␊ |
788 | ␉␉␉␉strlcpy(bootFile, bootInfo->bootFile, sizeof(bootFile));␊ |
789 | ␉␉␉}␊ |
790 | ␊ |
791 | ␉␉␉// Try to load kernel image from alternate locations on boot helper partitions.␊ |
792 | ␉␉␉ret = -1;␊ |
793 | ␉␉␉if ((gBootVolume->flags & kBVFlagBooter) && !bootFileWithDevice)␊ |
794 | ␉␉␉{␊ |
795 | ␉␉␉␉snprintf(bootFilePath, sizeof(bootFilePath), "com.apple.boot.P%s", bootFile);␊ |
796 | ␉␉␉␉ret = GetFileInfo(NULL, bootFilePath, &flags, &time);␊ |
797 | ␉␉␉␉if (ret == -1)␊ |
798 | ␉␉␉␉{␊ |
799 | ␉␉␉␉␉snprintf(bootFilePath, sizeof(bootFilePath), "com.apple.boot.R%s", bootFile);␊ |
800 | ␉␉␉␉␉ret = GetFileInfo(NULL, bootFilePath, &flags, &time);␊ |
801 | ␉␉␉␉␉if (ret == -1)␊ |
802 | ␉␉␉␉␉{␊ |
803 | ␉␉␉␉␉␉snprintf(bootFilePath, sizeof(bootFilePath), "com.apple.boot.S%s", bootFile);␊ |
804 | ␉␉␉␉␉␉ret = GetFileInfo(NULL, bootFilePath, &flags, &time);␊ |
805 | ␉␉␉␉␉}␊ |
806 | ␉␉␉␉}␊ |
807 | ␉␉␉}␊ |
808 | ␉␉␉if (ret == -1)␊ |
809 | ␉␉␉{␊ |
810 | ␉␉␉␉// No alternate location found, using the original kernel image path.␊ |
811 | ␉␉␉␉strlcpy(bootFilePath, bootFile, sizeof(bootFilePath));␊ |
812 | ␉␉␉}␊ |
813 | ␊ |
814 | ␉␉␉DBG("Loading kernel from: '%s' (%s)\n", gBootVolume->label, gBootVolume->type_name);␊ |
815 | ␉␉␉ret = LoadThinFatFile(bootFilePath, &binary);␊ |
816 | ␉␉␉if (ret <= 0 && archCpuType == CPU_TYPE_X86_64)␊ |
817 | ␉␉␉{␊ |
818 | ␉␉␉␉archCpuType = CPU_TYPE_I386;␊ |
819 | ␉␉␉␉ret = LoadThinFatFile(bootFilePath, &binary);␊ |
820 | ␉␉␉}␊ |
821 | ␉␉} while (0);␊ |
822 | ␊ |
823 | ␉␉clearActivityIndicator();␊ |
824 | ␊ |
825 | #if DEBUG␊ |
826 | ␉␉printf("Pausing...");␊ |
827 | ␉␉sleep(8);␊ |
828 | #endif␊ |
829 | ␊ |
830 | ␉␉if (ret <= 0)␊ |
831 | ␉␉{␊ |
832 | ␉␉␉printf("Can't find boot file: '%s'\n", bootFile);␊ |
833 | ␉␉␉sleep(1);␊ |
834 | ␊ |
835 | ␉␉␉if (gBootFileType == kNetworkDeviceType)␊ |
836 | ␉␉␉{␊ |
837 | ␉␉␉␉// Return control back to PXE. Don't unload PXE base code.␊ |
838 | ␉␉␉␉gUnloadPXEOnExit = false;␊ |
839 | ␉␉␉␉break;␊ |
840 | ␉␉␉}␊ |
841 | ␉␉␉pause();␊ |
842 | ␊ |
843 | ␉␉}␊ |
844 | ␉␉else␊ |
845 | ␉␉{␊ |
846 | ␉␉␉/* Won't return if successful. */␊ |
847 | ␉␉␉ret = ExecKernel(binary);␊ |
848 | ␉␉}␊ |
849 | ␉}␊ |
850 | ␊ |
851 | ␉// chainboot␊ |
852 | ␉if (status == 1)␊ |
853 | ␉{␊ |
854 | ␉␉// if we are already in graphics-mode,␊ |
855 | ␉␉if (getVideoMode() == GRAPHICS_MODE)␊ |
856 | ␉␉{␊ |
857 | ␉␉␉setVideoMode( VGA_TEXT_MODE ); // switch back to text mode.␊ |
858 | ␉␉}␊ |
859 | ␉}␊ |
860 | ␊ |
861 | ␉if ((gBootFileType == kNetworkDeviceType) && gUnloadPXEOnExit)␊ |
862 | ␉{␊ |
863 | ␉␉nbpUnloadBaseCode();␊ |
864 | ␉}␊ |
865 | ␊ |
866 | #if DEBUG_INTERRUPTS␊ |
867 | ␉if (interruptsAvailable)␊ |
868 | ␉{␊ |
869 | ␉␉DisableInterrupts();␊ |
870 | ␉}␊ |
871 | #endif␊ |
872 | ␊ |
873 | }␊ |
874 | ␊ |
875 | /*!␊ |
876 | ␉Selects a new BIOS device, taking care to update the global state appropriately.␊ |
877 | */␊ |
878 | /*␊ |
879 | static void selectBiosDevice(void)␊ |
880 | {␊ |
881 | ␉struct DiskBVMap *oldMap = diskResetBootVolumes(gBIOSDev);␊ |
882 | ␉CacheReset();␊ |
883 | ␉diskFreeMap(oldMap);␊ |
884 | ␉oldMap = NULL;␊ |
885 | ␊ |
886 | ␉int dev = selectAlternateBootDevice(gBIOSDev);␊ |
887 | ␊ |
888 | ␉BVRef bvchain = scanBootVolumes(dev, 0);␊ |
889 | ␉BVRef bootVol = selectBootVolume(bvchain);␊ |
890 | ␉gBootVolume = bootVol;␊ |
891 | ␉setRootVolume(bootVol);␊ |
892 | ␉gBIOSDev = dev;␊ |
893 | }␊ |
894 | */␊ |
895 | ␊ |
896 | bool checkOSVersion(const char * version)␊ |
897 | {␊ |
898 | ␉if ( (sizeof(version) > 4) && ('.' != version[4]) && ('\0' != version[4]) )␊ |
899 | ␉{␊ |
900 | ␉␉return ((gMacOSVersion[0] == version[0]) && (gMacOSVersion[1] == version[1])␊ |
901 | ␉␉&& (gMacOSVersion[2] == version[2]) && (gMacOSVersion[3] == version[3])␊ |
902 | ␉␉&& (gMacOSVersion[4] == version[4]));␊ |
903 | ␉}␊ |
904 | ␉else␊ |
905 | ␉{␊ |
906 | ␉␉return ((gMacOSVersion[0] == version[0]) && (gMacOSVersion[1] == version[1])␊ |
907 | ␉␉&& (gMacOSVersion[2] == version[2]) && (gMacOSVersion[3] == version[3]));␊ |
908 | ␉}␊ |
909 | ␊ |
910 | }␊ |
911 | ␊ |
912 | uint32_t getMacOSVerCurrent()␊ |
913 | {␊ |
914 | ␉MacOSVerCurrent = MacOSVer2Int(gBootVolume->OSVersion);␊ |
915 | ␉return MacOSVerCurrent;␊ |
916 | }␊ |
917 | ␊ |
918 | #define BASE 65521L /* largest prime smaller than 65536 */␊ |
919 | #define NMAX 5000␊ |
920 | // NMAX (was 5521) the largest n such that 255n(n+1)/2 + (n+1)(BASE-1) <= 2^32-1␊ |
921 | ␊ |
922 | #define DO1(buf, i)␉{s1 += buf[i]; s2 += s1;}␊ |
923 | #define DO2(buf, i)␉DO1(buf, i); DO1(buf, i + 1);␊ |
924 | #define DO4(buf, i)␉DO2(buf, i); DO2(buf, i + 2);␊ |
925 | #define DO8(buf, i)␉DO4(buf, i); DO4(buf, i + 4);␊ |
926 | #define DO16(buf)␉DO8(buf, 0); DO8(buf, 8);␊ |
927 | ␊ |
928 | unsigned long Adler32(unsigned char *buf, long len)␊ |
929 | {␊ |
930 | ␉unsigned long s1 = 1; // adler & 0xffff;␊ |
931 | ␉unsigned long s2 = 0; // (adler >> 16) & 0xffff;␊ |
932 | ␉unsigned long result;␊ |
933 | ␉int k;␊ |
934 | ␊ |
935 | ␉while (len > 0) {␊ |
936 | ␉␉k = len < NMAX ? len : NMAX;␊ |
937 | ␉␉len -= k;␊ |
938 | ␉␉while (k >= 16) {␊ |
939 | ␉␉␉DO16(buf);␊ |
940 | ␉␉␉buf += 16;␊ |
941 | ␉␉␉k -= 16;␊ |
942 | ␉␉}␊ |
943 | ␉␉if (k != 0) do {␊ |
944 | ␉␉␉s1 += *buf++;␊ |
945 | ␉␉␉s2 += s1;␊ |
946 | ␉␉} while (--k);␊ |
947 | ␉␉s1 %= BASE;␊ |
948 | ␉␉s2 %= BASE;␊ |
949 | ␉}␊ |
950 | ␉result = (s2 << 16) | s1;␊ |
951 | ␉return OSSwapHostToBigInt32(result);␊ |
952 | }␊ |
953 | |