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 | * Mach Operating System␊ |
26 | * Copyright (c) 1990 Carnegie-Mellon University␊ |
27 | * Copyright (c) 1989 Carnegie-Mellon University␊ |
28 | * All rights reserved. The CMU software License Agreement specifies␊ |
29 | * the terms and conditions for use and redistribution.␊ |
30 | */␊ |
31 | ␊ |
32 | /*␊ |
33 | * INTEL CORPORATION PROPRIETARY INFORMATION␊ |
34 | *␊ |
35 | * This software is supplied under the terms of a license agreement or ␊ |
36 | * nondisclosure agreement with Intel Corporation and may not be copied ␊ |
37 | * nor disclosed except in accordance with the terms of that agreement.␊ |
38 | *␊ |
39 | * Copyright 1988, 1989 by Intel Corporation␊ |
40 | */␊ |
41 | ␊ |
42 | /*␊ |
43 | * Copyright 1993 NeXT Computer, Inc.␊ |
44 | * All rights reserved.␊ |
45 | */␊ |
46 | ␊ |
47 | /*␊ |
48 | * Completely reworked by Sam Streeper (sam_s@NeXT.com)␊ |
49 | * Reworked again by Curtis Galloway (galloway@NeXT.com)␊ |
50 | */␊ |
51 | ␊ |
52 | //#define DEBUG 1 //Azi:temp␊ |
53 | ␊ |
54 | //Azi:include␊ |
55 | //#include "boot.h" - included on graphics.h, which is included on gui.h␊ |
56 | //#include "bootstruct.h" - same as above␊ |
57 | #include "fake_efi.h"␊ |
58 | #include "gui.h"␊ |
59 | //#include "libsa.h" - included on libsaio.h, which is included on sl.h␊ |
60 | #include "platform.h"␊ |
61 | #include "ramdisk.h"␊ |
62 | #include "sl.h"␊ |
63 | ␊ |
64 | #include "edid.h" // Autoresolution␊ |
65 | #include "autoresolution.h" // "was" included on boot.h, which is everywere!! -> gui.h -> graphics.h␊ |
66 | ␊ |
67 | long gBootMode; /* defaults to 0 == kBootModeNormal */␊ |
68 | bool gOverrideKernel;␊ |
69 | static char gBootKernelCacheFile[512];␊ |
70 | static char gCacheNameAdler[64 + 256];␊ |
71 | //char *gPlatformName = gCacheNameAdler; Azi: not in use␊ |
72 | char gRootDevice[512];␊ |
73 | char gMKextName[512];␊ |
74 | //char gMacOSVersion[8]; //Azi:sysversion - TODO: check why doesn't work here.␊ |
75 | bool gEnableCDROMRescan;␊ |
76 | bool gScanSingleDrive;␊ |
77 | ␊ |
78 | int bvCount = 0;␊ |
79 | //int␉␉menucount = 0;␊ |
80 | int gDeviceCount = 0;␊ |
81 | ␊ |
82 | BVRef bvr;␊ |
83 | BVRef menuBVR;␊ |
84 | BVRef bvChain;␊ |
85 | bool useGUI;␊ |
86 | ␊ |
87 | //static void selectBiosDevice(void);␊ |
88 | static unsigned long Adler32(unsigned char *buffer, long length);␊ |
89 | ␊ |
90 | static bool gUnloadPXEOnExit = false;␊ |
91 | ␊ |
92 | /*␊ |
93 | * How long to wait (in seconds) to load the␊ |
94 | * kernel after displaying the "boot:" prompt.␊ |
95 | */␊ |
96 | #define kBootErrorTimeout 5␊ |
97 | ␊ |
98 | /*␊ |
99 | * Default path to kernel cache file␊ |
100 | */␊ |
101 | #define kDefaultCachePath "/System/Library/Caches/com.apple.kernelcaches/kernelcache"␊ |
102 | ␊ |
103 | //==========================================================================␊ |
104 | // Zero the BSS.␊ |
105 | ␊ |
106 | static void zeroBSS(void)␊ |
107 | {␊ |
108 | ␉extern char _DATA__bss__begin, _DATA__bss__end;␊ |
109 | ␉extern char _DATA__common__begin, _DATA__common__end;␊ |
110 | ␊ |
111 | ␉bzero(&_DATA__bss__begin, (&_DATA__bss__end - &_DATA__bss__begin));␊ |
112 | ␉bzero(&_DATA__common__begin, (&_DATA__common__end - &_DATA__common__begin));␊ |
113 | }␊ |
114 | ␊ |
115 | //==========================================================================␊ |
116 | // Malloc error function␊ |
117 | ␊ |
118 | static void malloc_error(char *addr, size_t size, const char *file, int line)␊ |
119 | {␊ |
120 | ␉stop("\nMemory allocation error! Addr=0x%x, Size=0x%x, File=%s, Line=%d\n", (unsigned)addr, (unsigned)size, file, line);␊ |
121 | }␊ |
122 | ␊ |
123 | //==========================================================================␊ |
124 | //Initializes the runtime. Right now this means zeroing the BSS and initializing malloc.␊ |
125 | //␊ |
126 | void initialize_runtime(void)␊ |
127 | {␊ |
128 | ␉zeroBSS();␊ |
129 | ␉malloc_init(0, 0, 0, malloc_error);␊ |
130 | }␊ |
131 | ␊ |
132 | //==========================================================================␊ |
133 | // execKernel - Load the kernel image (mach-o) and jump to its entry point.␊ |
134 | ␊ |
135 | static int ExecKernel(void *binary)␊ |
136 | {␊ |
137 | entry_t kernelEntry;␊ |
138 | int ret;␊ |
139 | ␊ |
140 | bootArgs->kaddr = bootArgs->ksize = 0;␊ |
141 | ␊ |
142 | ret = DecodeKernel(binary,␊ |
143 | &kernelEntry,␊ |
144 | (char **) &bootArgs->kaddr,␊ |
145 | (int *)&bootArgs->ksize );␊ |
146 | ␊ |
147 | if ( ret != 0 )␊ |
148 | return ret;␊ |
149 | ␊ |
150 | // Reserve space for boot args␊ |
151 | reserveKernBootStruct();␊ |
152 | ␊ |
153 | // Load boot drivers from the specifed root path.␊ |
154 | ␊ |
155 | if (!gHaveKernelCache) {␊ |
156 | LoadDrivers("/");␊ |
157 | }␊ |
158 | ␊ |
159 | clearActivityIndicator();␊ |
160 | ␊ |
161 | if (gErrors) {␊ |
162 | printf("Errors encountered while starting up the computer.\n");␊ |
163 | printf("Pausing %d seconds...\n", kBootErrorTimeout);␊ |
164 | sleep(kBootErrorTimeout);␊ |
165 | }␊ |
166 | ␊ |
167 | setupFakeEfi();␊ |
168 | ␊ |
169 | md0Ramdisk();␊ |
170 | ␊ |
171 | verbose("Starting Darwin %s\n",( archCpuType == CPU_TYPE_I386 ) ? "x86" : "x86_64");␊ |
172 | ␊ |
173 | // Cleanup the PXE base code.␊ |
174 | ␊ |
175 | if ( (gBootFileType == kNetworkDeviceType) && gUnloadPXEOnExit ) {␊ |
176 | ␉␉if ( (ret = nbpUnloadBaseCode()) != nbpStatusSuccess )␊ |
177 | {␊ |
178 | ␉printf("nbpUnloadBaseCode error %d\n", (int) ret);␊ |
179 | sleep(2);␊ |
180 | }␊ |
181 | }␊ |
182 | ␊ |
183 | bool dummyVal;␊ |
184 | ␊ |
185 | ␉//Azi: Wait=y or any other pause makes my boot hang here, when using UHCIReset fix.␊ |
186 | ␉// (see graphics.c 432, AUTORES_DEBUG/patch). (fixed with usb_loop)␊ |
187 | ␉␊ |
188 | ␉// It's also breaking other keys when typed "after them" at boot prompt.␊ |
189 | ␉// Works properly if Wait=y is typed in first place or used on Boot.plist.␊ |
190 | if (getBoolForKey(kWaitForKeypressKey, &dummyVal, &bootInfo->bootConfig) && dummyVal) {␊ |
191 | ␉␉pause();␊ |
192 | }␊ |
193 | ␊ |
194 | ␉usb_loop();␊ |
195 | ␊ |
196 | // If we were in text mode, switch to graphics mode.␊ |
197 | // This will draw the boot graphics unless we are in␊ |
198 | // verbose mode.␊ |
199 | ␊ |
200 | if(gVerboseMode)␊ |
201 | setVideoMode( GRAPHICS_MODE, 0 );␊ |
202 | else␊ |
203 | drawBootGraphics();␊ |
204 | ␉␊ |
205 | finalizeBootStruct();␊ |
206 | ␊ |
207 | // Jump to kernel's entry point. There's no going back now.␊ |
208 | ␊ |
209 | startprog( kernelEntry, bootArgs );␊ |
210 | ␊ |
211 | // Not reached␊ |
212 | ␊ |
213 | return 0;␊ |
214 | }␊ |
215 | ␊ |
216 | //==========================================================================␊ |
217 | // This is the entrypoint from real-mode which functions exactly as it did␊ |
218 | // before. Multiboot does its own runtime initialization, does some of its␊ |
219 | // own things, and then calls common_boot.␊ |
220 | void boot(int biosdev)␊ |
221 | {␊ |
222 | ␉initialize_runtime();␊ |
223 | ␉// Enable A20 gate before accessing memory above 1Mb.␊ |
224 | ␉enableA20();␊ |
225 | ␉common_boot(biosdev);␊ |
226 | }␊ |
227 | ␊ |
228 | //==========================================================================␊ |
229 | // The 'main' function for the booter. Called by boot0 when booting␊ |
230 | // from a block device, or by the network booter.␊ |
231 | //␊ |
232 | // arguments:␊ |
233 | // biosdev - Value passed from boot1/NBP to specify the device␊ |
234 | // that the booter was loaded from.␊ |
235 | //␊ |
236 | // If biosdev is kBIOSDevNetwork, then this function will return if␊ |
237 | // booting was unsuccessful. This allows the PXE firmware to try the␊ |
238 | // next boot device on its list.␊ |
239 | void common_boot(int biosdev)␊ |
240 | {␊ |
241 | ␉bool␉␉␉instantMenu, quiet, rescanPrompt;␊ |
242 | ␉bool␉␉␉firstRun = true;␊ |
243 | ␉char␉␉␉*bootFile;␊ |
244 | ␉int␉␉␉␉status;␊ |
245 | ␉unsigned int␉allowBVFlags = kBVFlagSystemVolume|kBVFlagForeignBoot;␊ |
246 | ␉unsigned int␉denyBVFlags = kBVFlagEFISystem;␊ |
247 | ␉unsigned long␉adler32;␊ |
248 | ␉␊ |
249 | ␉// Set reminder to unload the PXE base code. Neglect to unload␊ |
250 | ␉// the base code will result in a hang or kernel panic.␊ |
251 | ␉gUnloadPXEOnExit = true;␊ |
252 | ␉␊ |
253 | ␉// Record the device that the booter was loaded from.␊ |
254 | ␉gBIOSDev = biosdev & kBIOSDevMask;␊ |
255 | ␉␊ |
256 | ␉// Initialize boot info structure.␊ |
257 | ␉initKernBootStruct();␊ |
258 | ␉␊ |
259 | ␉// Setup VGA text mode.␊ |
260 | ␉// Not sure if it is safe to call setVideoMode() before the␊ |
261 | ␉// config table has been loaded. Call video_mode() instead.␊ |
262 | #if DEBUG␊ |
263 | ␉printf("before video_mode\n");␊ |
264 | #endif␊ |
265 | ␉video_mode( 2 ); // 80x25 mono text mode.␊ |
266 | #if DEBUG␊ |
267 | ␉printf("after video_mode\n");␊ |
268 | #endif␊ |
269 | ␉␊ |
270 | ␉// Scan and record the system's hardware information.␊ |
271 | ␉scan_platform();␊ |
272 | ␉␊ |
273 | ␉// First get info for boot volume.␊ |
274 | ␉scanBootVolumes(gBIOSDev, 0);␊ |
275 | ␉bvChain = getBVChainForBIOSDev(gBIOSDev);␊ |
276 | ␉setBootGlobals(bvChain);␊ |
277 | ␉␊ |
278 | ␉// Load boot.plist config file␊ |
279 | ␉status = loadSystemConfig(&bootInfo->bootConfig);␊ |
280 | ␉␊ |
281 | ␉if (getBoolForKey(kQuietBootKey, &quiet, &bootInfo->bootConfig) && quiet)␊ |
282 | ␉{␊ |
283 | ␉␉gBootMode |= kBootModeQuiet;␊ |
284 | ␉}␊ |
285 | ␉␊ |
286 | ␉// Override firstRun to get to the boot menu instantly by setting "Instant Menu"=y in system config␊ |
287 | ␉if (getBoolForKey(kInstantMenuKey, &instantMenu, &bootInfo->bootConfig) && instantMenu)␊ |
288 | ␉{␊ |
289 | ␉␉firstRun = false;␊ |
290 | ␉}␊ |
291 | ␉␊ |
292 | ␉// Loading preboot ramdisk if exists.␊ |
293 | ␉loadPrebootRAMDisk();␊ |
294 | ␉␊ |
295 | ␉// Disable rescan option by default␊ |
296 | ␉gEnableCDROMRescan = false;␊ |
297 | ␉␊ |
298 | ␉// Enable it with Rescan=y in system config␊ |
299 | ␉if (getBoolForKey(kRescanKey, &gEnableCDROMRescan, &bootInfo->bootConfig) && gEnableCDROMRescan)␊ |
300 | ␉{␊ |
301 | ␉␉gEnableCDROMRescan = true;␊ |
302 | ␉}␊ |
303 | ␉␊ |
304 | ␉// Ask the user for Rescan option by setting "Rescan Prompt"=y in system config.␊ |
305 | ␉rescanPrompt = false;␊ |
306 | ␉if (getBoolForKey(kRescanPromptKey, &rescanPrompt , &bootInfo->bootConfig)␊ |
307 | ␉␉&& rescanPrompt && biosDevIsCDROM(gBIOSDev))␊ |
308 | ␉{␊ |
309 | ␉␉gEnableCDROMRescan = promptForRescanOption();␊ |
310 | ␉}␊ |
311 | ␉␊ |
312 | ␉// Enable touching a single BIOS device only if "Scan Single Drive"=y is set in system config.␊ |
313 | ␉if (getBoolForKey(kScanSingleDriveKey, &gScanSingleDrive, &bootInfo->bootConfig) && gScanSingleDrive)␊ |
314 | ␉{␊ |
315 | ␉␉gScanSingleDrive = true;␊ |
316 | ␉}␊ |
317 | ␉␊ |
318 | ␉// Create a list of partitions on device(s).␊ |
319 | ␉if (gScanSingleDrive)␊ |
320 | ␉{␊ |
321 | ␉␉scanBootVolumes(gBIOSDev, &bvCount);␊ |
322 | ␉}␊ |
323 | ␉else␊ |
324 | ␉{␊ |
325 | ␉␉scanDisks(gBIOSDev, &bvCount);␊ |
326 | ␉}␊ |
327 | ␉␊ |
328 | ␉// Create a separated bvr chain using the specified filters.␊ |
329 | ␉bvChain = newFilteredBVChain(0x80, 0xFF, allowBVFlags, denyBVFlags, &gDeviceCount);␊ |
330 | ␉␊ |
331 | ␉gBootVolume = selectBootVolume(bvChain);␊ |
332 | ␉␊ |
333 | #if DEBUG␊ |
334 | ␉printf(" Default: %d, ->biosdev: %d, ->part_no: %d ->flags: %d\n",␊ |
335 | ␉␉␉gBootVolume, gBootVolume->biosdev, gBootVolume->part_no, gBootVolume->flags);␊ |
336 | ␉printf(" bt(0,0): %d, ->biosdev: %d, ->part_no: %d ->flags: %d\n",␊ |
337 | ␉␉␉gBIOSBootVolume, gBIOSBootVolume->biosdev, gBIOSBootVolume->part_no, gBIOSBootVolume->flags);␊ |
338 | ␉pause(); //getc();␊ |
339 | #endif␊ |
340 | ␉␊ |
341 | ␉useGUI = true;␊ |
342 | ␉␊ |
343 | ␉// Override useGUI default␊ |
344 | ␉getBoolForKey(kGUIKey, &useGUI, &bootInfo->bootConfig);␊ |
345 | ␊ |
346 | //Azi:autoresolution begin␊ |
347 | ␉// Before initGui, patch the video bios with the correct resolution␊ |
348 | ␉UInt32 params[4];␊ |
349 | ␉params[3] = 0;␊ |
350 | ␉␊ |
351 | ␉// default to "false" as it doesn't work for everyone atm.␊ |
352 | ␉// http://forum.voodooprojects.org/index.php/topic,1227.0.html␊ |
353 | ␉gAutoResolution = false;␊ |
354 | ␉␊ |
355 | ␉getBoolForKey(kAutoResolutionKey, &gAutoResolution, &bootInfo->bootConfig);␊ |
356 | ␉␊ |
357 | ␉//Open the VBios and store VBios or Tables␊ |
358 | ␉map = openVbios(CT_UNKWN);␊ |
359 | ␉␊ |
360 | ␉if (gAutoResolution == true)␊ |
361 | ␉{␊ |
362 | ␉␉//Get Resolution from Graphics Mode key or EDID␊ |
363 | ␉␉int count = getNumberArrayFromProperty(kGraphicsModeKey, params, 4);␊ |
364 | ␉␉if (count < 3)␊ |
365 | ␉␉␉getResolution(params);␊ |
366 | ␉␉else␊ |
367 | ␉␉{␊ |
368 | ␉␉␉if ( params[2] == 256 ) params[2] = 8;␊ |
369 | ␉␉␉if ( params[2] == 555 ) params[2] = 16;␊ |
370 | ␉␉␉if ( params[2] == 888 ) params[2] = 32;␊ |
371 | ␉␉}␊ |
372 | ␉␉␊ |
373 | #ifdef AUTORES_DEBUG␊ |
374 | ␉printf("Resolution: %dx%d\n",params[0], params[1]);␊ |
375 | #endif␉␊ |
376 | ␉␉␊ |
377 | ␉␉//perfom the actual VBIOS patching␊ |
378 | ␉␉if (params[0] != 0 && params[1] != 0)␊ |
379 | ␉␉␉patchVbios(map, params[0], params[1], params[2], 0, 0);␊ |
380 | ␉}␊ |
381 | //Azi:autoresolution end␊ |
382 | ␊ |
383 | ␉if (useGUI && initGUI())␊ |
384 | ␉{␊ |
385 | ␉␉// initGUI() returned with an error, disabling GUI.␊ |
386 | ␉␉useGUI = false;␊ |
387 | ␉}␊ |
388 | ␉␊ |
389 | ␉setBootGlobals(bvChain);␊ |
390 | ␉␊ |
391 | ␉// Parse args, load and start kernel.␊ |
392 | ␉while (1)␊ |
393 | ␉{␊ |
394 | ␉␉bool␉␉forceresume, tryresume, tryresumedefault; ␊ |
395 | ␉␉const char␉*val;␊ |
396 | ␉␉int␉␉␉len, trycache;␊ |
397 | ␉␉int␉␉␉ret = -1;␊ |
398 | ␉␉long␉␉flags, cachetime, kerneltime, exttime, sleeptime, time;␊ |
399 | ␉␉void␉␉*binary = (void *)kLoadAddr;␊ |
400 | ␉␉␊ |
401 | ␉␉config_file_t␉ systemVersion;␉␉// system.plist of booting partition - Azi:sysversion␊ |
402 | ␉␉char␉␉sysVersion[8]; // replaces gMacOSVersion here, for now.␊ |
403 | ␉␉␊ |
404 | ␉␉// additional variable for testing alternate kernel image locations on boot helper partitions.␊ |
405 | ␉␉char␉␉bootFileSpec[512]; //Azi:HelperConfig - kernel␊ |
406 | ␉␉␊ |
407 | ␉␉// Initialize globals.␊ |
408 | ␉␉␊ |
409 | ␉␉sysConfigValid = false;␊ |
410 | ␉␉gErrors␉␉ = false;␊ |
411 | ␉␉␊ |
412 | ␉␉status = getBootOptions(firstRun);␊ |
413 | ␉␉firstRun = false;␊ |
414 | ␉␉if ( status == -1 ) continue;␊ |
415 | ␉␉␊ |
416 | ␉␉//Azi:sysversion related test ␊ |
417 | ␉␉if( bootArgs->Video.v_display == GRAPHICS_MODE )␊ |
418 | ␉␉{␊ |
419 | ␉␉␉gui.devicelist.draw = false; // Needed for when the verbose flips the screen.␊ |
420 | ␉␉␉drawBackground();␊ |
421 | ␉␉␉updateVRAM();␊ |
422 | ␉␉}␊ |
423 | ␉␉␉␉␊ |
424 | ␉␉// Turn off any GUI elements␊ |
425 | ␉␉/*if ( bootArgs->Video.v_display == GRAPHICS_MODE )␊ |
426 | ␉␉{␊ |
427 | ␉␉␉gui.devicelist.draw = false;␊ |
428 | ␉␉␉gui.bootprompt.draw = false; // doesn't seem needed␊ |
429 | ␉␉␉gui.menu.draw = false; // same as above␊ |
430 | ␉␉␉gui.infobox.draw = false; // Enter doesn't work with this drawn so...␊ |
431 | ␉␉␉drawBackground();␊ |
432 | ␉␉␉updateVRAM(); // don't know about this␊ |
433 | ␉␉}*/␊ |
434 | ␉␉␊ |
435 | //Azi:autoresolution begin␊ |
436 | ␉␉/*␊ |
437 | ␉␉ * AutoResolution - Reapply the patch or cancel if Graphics Mode was incorrect␊ |
438 | ␉␉ *␉␉␉␉␉or EDID Info was insane␊ |
439 | ␉␉ */ ␊ |
440 | ␉␉ getBoolForKey(kAutoResolutionKey, &gAutoResolution, &bootInfo->bootConfig);␊ |
441 | ␉␉␊ |
442 | ␉␉//Restore the vbios for Cancelation␊ |
443 | ␉␉if ((gAutoResolution == false) && map)␊ |
444 | ␉␉{␊ |
445 | ␉␉␉restoreVbios(map);␊ |
446 | ␉␉␉closeVbios(map);␉␊ |
447 | ␉␉}␊ |
448 | ␉␉␊ |
449 | ␉␉if ((gAutoResolution == true) && map)␊ |
450 | ␉␉{␊ |
451 | ␉␉␉// If mode has been switched during boot menu␊ |
452 | ␉␉␉// use the new resolution␊ |
453 | ␉␉␉if (map->hasSwitched == true)␊ |
454 | ␉␉␉{␊ |
455 | ␉␉␉␉params[0] = map->currentX;␊ |
456 | ␉␉␉␉params[1] = map->currentY;␊ |
457 | ␉␉␉␉params[2] = 32;␊ |
458 | ␉␉␉}␊ |
459 | ␉␉␉else␊ |
460 | ␉␉␉{␊ |
461 | ␉␉␉␉//or get resolution from Graphics Mode or EDID␊ |
462 | ␉␉␉␉int count = getNumberArrayFromProperty(kGraphicsModeKey, params, 4);␊ |
463 | ␉␉␉␉if (count < 3)␊ |
464 | ␉␉␉␉␉getResolution(params);␊ |
465 | ␉␉␉␉else␊ |
466 | ␉␉␉␉{␊ |
467 | ␉␉␉␉␉if ( params[2] == 256 ) params[2] = 8;␊ |
468 | ␉␉␉␉␉if ( params[2] == 555 ) params[2] = 16;␊ |
469 | ␉␉␉␉␉if ( params[2] == 888 ) params[2] = 32;␊ |
470 | ␉␉␉␉}␊ |
471 | ␉␉␉}␊ |
472 | ␉␉␉␊ |
473 | ␉␉␉//Resolution has changed, reapply the patch␊ |
474 | ␉␉␉if ((params[0] != 0) && (params[1] != 0) && (params[0] != map->currentX) &&␊ |
475 | ␉␉␉␉(params[1] != map->currentY))␊ |
476 | ␉␉␉{␊ |
477 | ␉␉␉␉patchVbios(map, params[0], params[1], params[2], 0, 0);␊ |
478 | ␉␉␉}␊ |
479 | ␉␉␉closeVbios(map); // doesn't print to screen from here␊ |
480 | ␉␉}␊ |
481 | //Azi:autoresolution end␊ |
482 | ␉␉␊ |
483 | ␉␉status = processBootOptions();␊ |
484 | ␉␉␊ |
485 | ␉␉// Status == 1 means to chainboot␊ |
486 | ␉␉if ( status ==␉1 ) break;␊ |
487 | ␉␉␊ |
488 | ␉␉// Status == -1 means that gBootVolume is NULL - Azi: little edit to reflect current status.␊ |
489 | ␉␉if ( status == -1 )␊ |
490 | ␉␉{␊ |
491 | ␉␉␉// gBootVolume == NULL usually means the user hit escape.␊ |
492 | ␉␉␉if (gBootVolume == NULL) //Azi: hitting escape makes me boot when "at" boot prompt.␊ |
493 | ␉␉␉{␊ |
494 | ␉␉␉␉freeFilteredBVChain(bvChain);␊ |
495 | ␉␉␉␉␊ |
496 | ␉␉␉␉if (gEnableCDROMRescan)␊ |
497 | ␉␉␉␉␉rescanBIOSDevice(gBIOSDev);␊ |
498 | ␉␉␉␉␊ |
499 | ␉␉␉␉bvChain = newFilteredBVChain(0x80, 0xFF, allowBVFlags, denyBVFlags, &gDeviceCount);␊ |
500 | ␉␉␉␉setBootGlobals(bvChain);␊ |
501 | ␉␉␉}␊ |
502 | ␉␉␉continue;␊ |
503 | ␉␉}␊ |
504 | ␉␉␊ |
505 | ␉␉// Other status (e.g. 0) means that we should proceed with boot.␊ |
506 | ␉␉// Found and loaded a config file (Azi: not mandatory anymore).␊ |
507 | ␉␉␊ |
508 | //Azi:autoresolution old - testing␊ |
509 | ␉␉␊ |
510 | ␉␉// Find out which version mac os we're booting. Azi:sysversion␊ |
511 | ␉␉// To avoid call loadOverrideConfig from here too and since moving this before calling␊ |
512 | ␉␉// processBootOptions() (which worked on a brief test) doesn't make sense,␊ |
513 | ␉␉// tried to move it to processBootOptions() on options.c (check there).␊ |
514 | ␉␉if (!loadConfigFile("/System/Library/CoreServices/SystemVersion.plist", &systemVersion))␊ |
515 | ␉␉{ //Azi: shouldn't this path start with / ?␊ |
516 | ␉␉␉if (getValueForKey(kProductVersion, &val, &len, &systemVersion))␊ |
517 | ␉␉␉{␊ |
518 | ␉␉␉␉// getValueForKey uses const char for val␊ |
519 | ␉␉␉␉// so copy it and trim␊ |
520 | ␉␉␉␉strncpy(sysVersion, val, MIN(len, 4));␊ |
521 | ␉␉␉␉sysVersion[MIN(len, 4)] = '\0';␊ |
522 | ␉␉␉}␊ |
523 | ␉␉}␊ |
524 | ␉␉␊ |
525 | ␉␉//Azi:sysversion - gMacOSVersion is only initialized above so, this call is only to get␊ |
526 | ␉␉// system version so we can override Boot.plist from specific OS folders; another plus is verbose.␊ |
527 | ␉␉// It seems to work fine though i'm not sure how sane is to call it twice?!␊ |
528 | ␉␉// Can't be called only from here! Need advice. Check above.␊ |
529 | ␉␉//loadOverrideConfig(&bootInfo->overrideConfig); // call 2␊ |
530 | ␉␉␊ |
531 | ␉␉//Azi: default to x86_64 arch␊ |
532 | ␉␉// If cpu doesn't handle 64 bit instructions,...␊ |
533 | ␉␉if (!platformCPUFeature(CPU_FEATURE_EM64T) ||␊ |
534 | ␉␉␉// ... user forced i386 kernel architecture on cpu with "em64t"...␊ |
535 | ␉␉␉getValueForKey(kArchI386Flag, &val, &len, &bootInfo->bootConfig) ||␊ |
536 | ␉␉␉// ... or forced Legacy Mode... (not needed! but handy for some processors/situations)␊ |
537 | ␉␉␉getValueForKey(kLegacyModeFlag, &val, &len, &bootInfo->bootConfig))␊ |
538 | ␉␉{␊ |
539 | ␉␉␉// ... use i386 kernel arch.␊ |
540 | ␉␉␉archCpuType = CPU_TYPE_I386;␊ |
541 | ␉␉}␊ |
542 | ␉␉else␊ |
543 | ␉␉{␊ |
544 | ␉␉␉// Else use x86_64 kernel arch.␊ |
545 | ␉␉␉archCpuType = CPU_TYPE_X86_64;␊ |
546 | ␉␉}␊ |
547 | ␉␉// Override i386/-legacy, if flagged on Boot.plist.␊ |
548 | ␉␉if (getValueForKey(kArchX86_64Flag, &val, &len, &bootInfo->bootConfig))␊ |
549 | ␉␉{␊ |
550 | ␉␉␉archCpuType = CPU_TYPE_X86_64;␊ |
551 | ␉␉}␊ |
552 | ␉␉␊ |
553 | ␉␉if (!getBoolForKey (kWakeKey, &tryresume, &bootInfo->bootConfig))␊ |
554 | ␉␉{␊ |
555 | ␉␉␉tryresume = true;␊ |
556 | ␉␉␉tryresumedefault = true;␊ |
557 | ␉␉}␊ |
558 | ␉␉else␊ |
559 | ␉␉{␊ |
560 | ␉␉␉tryresumedefault = false;␊ |
561 | ␉␉}␊ |
562 | ␉␉␊ |
563 | ␉␉if (!getBoolForKey (kForceWakeKey, &forceresume, &bootInfo->bootConfig))␊ |
564 | ␉␉{␊ |
565 | ␉␉␉forceresume = false;␊ |
566 | ␉␉}␊ |
567 | ␉␉␊ |
568 | ␉␉if (forceresume)␊ |
569 | ␉␉{␊ |
570 | ␉␉␉tryresume = true;␊ |
571 | ␉␉␉tryresumedefault = false;␊ |
572 | ␉␉}␊ |
573 | ␉␉␊ |
574 | ␉␉while (tryresume)␊ |
575 | ␉␉{␊ |
576 | ␉␉␉const char *tmp;␊ |
577 | ␉␉␉BVRef bvr;␊ |
578 | ␉␉␉if (!getValueForKey(kWakeImageKey, &val, &len, &bootInfo->bootConfig))␊ |
579 | ␉␉␉␉val="/private/var/vm/sleepimage";␊ |
580 | ␉␉␉␊ |
581 | ␉␉␉// Do this first to be sure that root volume is mounted␊ |
582 | ␉␉␉ret = GetFileInfo(0, val, &flags, &sleeptime);␊ |
583 | ␉␉␉␊ |
584 | ␉␉␉if ((bvr = getBootVolumeRef(val, &tmp)) == NULL)␊ |
585 | ␉␉␉␉break;␊ |
586 | ␉␉␉␊ |
587 | ␉␉␉// Can't check if it was hibernation Wake=y is required␊ |
588 | ␉␉␉if (bvr->modTime == 0 && tryresumedefault)␊ |
589 | ␉␉␉␉break;␊ |
590 | ␉␉␉␊ |
591 | ␉␉␉if ((ret != 0) || ((flags & kFileTypeMask) != kFileTypeFlat))␊ |
592 | ␉␉␉␉break;␊ |
593 | ␉␉␉␊ |
594 | ␉␉␉if (!forceresume && ((sleeptime+3)<bvr->modTime))␊ |
595 | ␉␉␉{␊ |
596 | ␉␉␉␉printf("Hibernate image is too old by %d seconds. Use ForceWake=y to override\n",␊ |
597 | ␉␉␉␉␉␉bvr->modTime-sleeptime);␊ |
598 | ␉␉␉␉break;␊ |
599 | ␉␉␉}␊ |
600 | ␉␉␉HibernateBoot((char *)val);␊ |
601 | ␉␉␉break;␊ |
602 | ␉␉}␊ |
603 | ␉␉␊ |
604 | ␉␉// Reset cache name.␊ |
605 | ␉␉bzero(gCacheNameAdler + 64, sizeof(gCacheNameAdler) - 64);␊ |
606 | ␉␉␊ |
607 | ␉␉sprintf(gCacheNameAdler + 64, "%s,%s", gRootDevice, bootInfo->bootFile);␊ |
608 | ␉␉␊ |
609 | ␉␉adler32 = Adler32((unsigned char *)gCacheNameAdler, sizeof(gCacheNameAdler));␊ |
610 | ␉␉␊ |
611 | ␉␉if (getValueForKey(kKernelCacheKey, &val, &len, &bootInfo->bootConfig))␊ |
612 | ␉␉{␊ |
613 | ␉␉␉strlcpy(gBootKernelCacheFile, val, len+1);␊ |
614 | ␉␉}␊ |
615 | ␉␉else␊ |
616 | ␉␉{␊ |
617 | ␉␉␉sprintf(gBootKernelCacheFile, "%s.%08lX", kDefaultCachePath, adler32);␊ |
618 | ␉␉}␊ |
619 | ␉␉␊ |
620 | ␉␉// Check for cache file.␊ |
621 | ␉␉trycache = (((gBootMode & kBootModeSafe) == 0) &&␊ |
622 | ␉␉␉␉␉!gOverrideKernel &&␊ |
623 | ␉␉␉␉␉(gBootFileType == kBlockDeviceType) &&␊ |
624 | ␉␉␉␉␉(gMKextName[0] == '\0') &&␊ |
625 | ␉␉␉␉␉(gBootKernelCacheFile[0] != '\0'));␊ |
626 | ␊ |
627 | ␉␉verbose("Loading Darwin %s\n", sysVersion); //Azi:sysversion␊ |
628 | ␉␉␊ |
629 | ␉␉if (trycache) do␊ |
630 | ␉␉{␊ |
631 | ␉␉␉// if we haven't found the kernel yet, don't use the cache␊ |
632 | ␉␉␉ret = GetFileInfo(NULL, bootInfo->bootFile, &flags, &kerneltime);␊ |
633 | ␉␉␉if ((ret != 0) || ((flags & kFileTypeMask) != kFileTypeFlat))␊ |
634 | ␉␉␉{␊ |
635 | ␉␉␉␉trycache = 0;␊ |
636 | ␉␉␉␉break;␊ |
637 | ␉␉␉}␊ |
638 | ␉␉␉␊ |
639 | ␉␉␉ret = GetFileInfo(NULL, gBootKernelCacheFile, &flags, &cachetime);␊ |
640 | ␉␉␉if ((ret != 0) || ((flags & kFileTypeMask) != kFileTypeFlat)␊ |
641 | ␉␉␉␉|| (cachetime < kerneltime))␊ |
642 | ␉␉␉{␊ |
643 | ␉␉␉␉trycache = 0;␊ |
644 | ␉␉␉␉break;␊ |
645 | ␉␉␉}␊ |
646 | ␉␉␉␊ |
647 | ␉␉␉ret = GetFileInfo("/System/Library/", "Extensions", &flags, &exttime);␊ |
648 | ␉␉␉if ((ret == 0) && ((flags & kFileTypeMask) == kFileTypeDirectory)␊ |
649 | ␉␉␉␉&& (cachetime < exttime))␊ |
650 | ␉␉␉{␊ |
651 | ␉␉␉␉trycache = 0;␊ |
652 | ␉␉␉␉break;␊ |
653 | ␉␉␉}␊ |
654 | ␉␉␉␊ |
655 | ␉␉␉if (kerneltime > exttime)␊ |
656 | ␉␉␉{␊ |
657 | ␉␉␉␉exttime = kerneltime;␊ |
658 | ␉␉␉}␊ |
659 | ␉␉␉␊ |
660 | ␉␉␉if (cachetime != (exttime + 1))␊ |
661 | ␉␉␉{␊ |
662 | ␉␉␉␉trycache = 0;␊ |
663 | ␉␉␉␉break;␊ |
664 | ␉␉␉}␊ |
665 | ␉␉} while (0);␊ |
666 | ␉␉␊ |
667 | ␉␉do␊ |
668 | ␉␉{␊ |
669 | ␉␉␉if (trycache)␊ |
670 | ␉␉␉{␊ |
671 | ␉␉␉␉bootFile = gBootKernelCacheFile;␊ |
672 | ␉␉␉␉verbose("Loading kernel cache %s\n", bootFile); //Azi: i never saw this!! check!!!␊ |
673 | ␉␉␉␉ret = LoadFile(bootFile);␊ |
674 | ␉␉␉␉binary = (void *)kLoadAddr;␊ |
675 | ␉␉␉␉if (ret >= 0)␊ |
676 | ␉␉␉␉{␊ |
677 | ␉␉␉␉␉break;␊ |
678 | ␉␉␉␉}␊ |
679 | ␉␉␉}␊ |
680 | ␉␉␉␊ |
681 | ␉␉␉bootFile = bootInfo->bootFile;␊ |
682 | ␉␉␉␊ |
683 | ␉␉␉// Try to load kernel image from alternate locations on boot helper partitions.␊ |
684 | ␉␉␉sprintf(bootFileSpec, "com.apple.boot.P/%s", bootFile); //Azi:HelperConfig - kernel␊ |
685 | ␉␉␉␊ |
686 | ␉␉␉ret = GetFileInfo(NULL, bootFileSpec, &flags, &time); ␊ |
687 | ␉␉␉if (ret == -1)␊ |
688 | ␉␉␉{␊ |
689 | ␉␉␉␉sprintf(bootFileSpec, "com.apple.boot.R/%s", bootFile);␊ |
690 | ␉␉␉␉␊ |
691 | ␉␉␉␉ret = GetFileInfo(NULL, bootFileSpec, &flags, &time); ␊ |
692 | ␉␉␉␉if (ret == -1)␊ |
693 | ␉␉␉␉{␊ |
694 | ␉␉␉␉␉sprintf(bootFileSpec, "com.apple.boot.S/%s", bootFile);␊ |
695 | ␉␉␉␉␉␊ |
696 | ␉␉␉␉␉ret = GetFileInfo(NULL, bootFileSpec, &flags, &time); ␊ |
697 | ␉␉␉␉␉if (ret == -1)␊ |
698 | ␉␉␉␉␉{␊ |
699 | ␉␉␉␉␉␉// Not found any alternate locations, using the original kernel image path.␊ |
700 | ␉␉␉␉␉␉strcpy(bootFileSpec, bootFile);␊ |
701 | ␉␉␉␉␉}␊ |
702 | ␉␉␉␉}␊ |
703 | ␉␉␉}␊ |
704 | ␉␉␉␉␉␉␊ |
705 | ␉␉␉verbose("Loading kernel %s\n", bootFileSpec);␊ |
706 | ␉␉␉␊ |
707 | ␉␉␉ret = LoadThinFatFile(bootFileSpec, &binary);␊ |
708 | ␉␉␉if (ret <= 0 && archCpuType == CPU_TYPE_X86_64)␊ |
709 | ␉␉␉{␊ |
710 | ␉␉␉␉archCpuType = CPU_TYPE_I386;␊ |
711 | ␉␉␉␉ret = LoadThinFatFile(bootFileSpec, &binary);␉␉␉␉␊ |
712 | ␉␉␉}␊ |
713 | ␉␉␊ |
714 | ␉␉} while (0);␊ |
715 | ␉␉␊ |
716 | ␉␉clearActivityIndicator();␊ |
717 | /*#if DEBUG␊ |
718 | ␉␉printf("Pausing...");␊ |
719 | ␉␉sleep(8);␊ |
720 | #endif Azi: annoying! Can't see the point atm... */␊ |
721 | ␉␉␊ |
722 | ␉␉if (ret <= 0)␊ |
723 | ␉␉{␊ |
724 | ␉␉␉printf("Can't find %s\n", bootFile);␊ |
725 | ␉␉␉␊ |
726 | ␉␉␉if(gui.initialised)␊ |
727 | ␉␉␉{␊ |
728 | ␉␉␉␉sleep(1);␊ |
729 | ␉␉␉␉drawBackground();␊ |
730 | ␉␉␉␉gui.devicelist.draw = true;␊ |
731 | ␉␉␉␉gui.redraw = true;␊ |
732 | ␉␉␉}␊ |
733 | ␉␉␉␊ |
734 | ␉␉␉if (gBootFileType == kNetworkDeviceType) {␊ |
735 | ␉␉␉␉// Return control back to PXE. Don't unload PXE base code.␊ |
736 | ␉␉␉␉gUnloadPXEOnExit = false;␊ |
737 | ␉␉␉␉break;␊ |
738 | ␉␉␉}␊ |
739 | ␉␉}␊ |
740 | ␉␉else␊ |
741 | ␉␉{␊ |
742 | ␉␉␉/* Won't return if successful. */␊ |
743 | ␉␉␉ret = ExecKernel(binary);␊ |
744 | ␉␉}␊ |
745 | ␉}␊ |
746 | ␉␊ |
747 | ␉// chainboot␊ |
748 | ␉if (status==1)␊ |
749 | ␉{␊ |
750 | ␉␉if (getVideoMode() == GRAPHICS_MODE)␊ |
751 | ␉␉{␉// if we are already in graphics-mode,␊ |
752 | ␉␉␉setVideoMode(VGA_TEXT_MODE, 0); // switch back to text mode␊ |
753 | ␉␉}␊ |
754 | ␉}␊ |
755 | ␉␊ |
756 | ␉if ((gBootFileType == kNetworkDeviceType) && gUnloadPXEOnExit)␊ |
757 | ␉{␊ |
758 | ␉␉nbpUnloadBaseCode();␊ |
759 | ␉}␊ |
760 | }␊ |
761 | ␊ |
762 | /*!␊ |
763 | Selects a new BIOS device, taking care to update the global state appropriately.␊ |
764 | */␊ |
765 | /*␊ |
766 | static void selectBiosDevice(void)␊ |
767 | {␊ |
768 | struct DiskBVMap *oldMap = diskResetBootVolumes(gBIOSDev);␊ |
769 | CacheReset();␊ |
770 | diskFreeMap(oldMap);␊ |
771 | oldMap = NULL;␊ |
772 | ␊ |
773 | int dev = selectAlternateBootDevice(gBIOSDev);␊ |
774 | ␊ |
775 | BVRef bvchain = scanBootVolumes(dev, 0);␊ |
776 | BVRef bootVol = selectBootVolume(bvchain);␊ |
777 | gBootVolume = bootVol;␊ |
778 | setRootVolume(bootVol);␊ |
779 | gBIOSDev = dev;␊ |
780 | }␊ |
781 | */␊ |
782 | ␊ |
783 | #define BASE 65521L /* largest prime smaller than 65536 */␊ |
784 | #define NMAX 5000␊ |
785 | // NMAX (was 5521) the largest n such that 255n(n+1)/2 + (n+1)(BASE-1) <= 2^32-1␊ |
786 | ␊ |
787 | #define DO1(buf,i) {s1 += buf[i]; s2 += s1;}␊ |
788 | #define DO2(buf,i) DO1(buf,i); DO1(buf,i+1);␊ |
789 | #define DO4(buf,i) DO2(buf,i); DO2(buf,i+2);␊ |
790 | #define DO8(buf,i) DO4(buf,i); DO4(buf,i+4);␊ |
791 | #define DO16(buf) DO8(buf,0); DO8(buf,8);␊ |
792 | ␊ |
793 | unsigned long Adler32(unsigned char *buf, long len)␊ |
794 | {␊ |
795 | unsigned long s1 = 1; // adler & 0xffff;␊ |
796 | unsigned long s2 = 0; // (adler >> 16) & 0xffff;␊ |
797 | unsigned long result;␊ |
798 | int k;␊ |
799 | ␊ |
800 | while (len > 0) {␊ |
801 | k = len < NMAX ? len : NMAX;␊ |
802 | len -= k;␊ |
803 | while (k >= 16) {␊ |
804 | DO16(buf);␊ |
805 | buf += 16;␊ |
806 | k -= 16;␊ |
807 | }␊ |
808 | if (k != 0) do {␊ |
809 | s1 += *buf++;␊ |
810 | s2 += s1;␊ |
811 | } while (--k);␊ |
812 | s1 %= BASE;␊ |
813 | s2 %= BASE;␊ |
814 | }␊ |
815 | result = (s2 << 16) | s1;␊ |
816 | return OSSwapHostToBigInt32(result);␊ |
817 | }␊ |
818 | |