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