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