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)␊ |
384 | ␉{␊ |
385 | ␉␉/* XXX AsereBLN handle error */␊ |
386 | ␉␉initGUI();␊ |
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 | ␉␉␉drawBackground(); //Azi: just seems repeated and less complete than the next!? though to the eye,␊ |
420 | ␉␉␉updateVRAM();␉//the next seems to do exactly the same??! testing␊ |
421 | ␉␉}␊ |
422 | ␉␉␉␉␊ |
423 | ␉␉// Turn off any GUI elements␊ |
424 | ␉␉/*if ( bootArgs->Video.v_display == GRAPHICS_MODE )␊ |
425 | ␉␉{␊ |
426 | ␉␉␉gui.devicelist.draw = false; // doesn't seem needed␊ |
427 | ␉␉␉gui.bootprompt.draw = false; // same as above␊ |
428 | ␉␉␉gui.menu.draw = false; // same as above␊ |
429 | ␉␉␉gui.infobox.draw = false; // Enter doesn't work with this drawn so...␊ |
430 | ␉␉␉drawBackground();␊ |
431 | ␉␉␉updateVRAM(); // don't know about this␊ |
432 | ␉␉}*/␊ |
433 | ␉␉␊ |
434 | //Azi:autoresolution begin␊ |
435 | ␉␉/*␊ |
436 | ␉␉ * AutoResolution - Reapply the patch or cancel if Graphics Mode was incorrect␊ |
437 | ␉␉ *␉␉␉␉␉or EDID Info was insane␊ |
438 | ␉␉ */ ␊ |
439 | ␉␉ getBoolForKey(kAutoResolutionKey, &gAutoResolution, &bootInfo->bootConfig);␊ |
440 | ␉␉␊ |
441 | ␉␉//Restore the vbios for Cancelation␊ |
442 | ␉␉if ((gAutoResolution == false) && map)␊ |
443 | ␉␉{␊ |
444 | ␉␉␉restoreVbios(map);␊ |
445 | ␉␉␉closeVbios(map);␉␊ |
446 | ␉␉}␊ |
447 | ␉␉␊ |
448 | ␉␉if ((gAutoResolution == true) && map)␊ |
449 | ␉␉{␊ |
450 | ␉␉␉// If mode has been switched during boot menu␊ |
451 | ␉␉␉// use the new resolution␊ |
452 | ␉␉␉if (map->hasSwitched == true)␊ |
453 | ␉␉␉{␊ |
454 | ␉␉␉␉params[0] = map->currentX;␊ |
455 | ␉␉␉␉params[1] = map->currentY;␊ |
456 | ␉␉␉␉params[2] = 32;␊ |
457 | ␉␉␉}␊ |
458 | ␉␉␉else␊ |
459 | ␉␉␉{␊ |
460 | ␉␉␉␉//or get resolution from Graphics Mode or EDID␊ |
461 | ␉␉␉␉int count = getNumberArrayFromProperty(kGraphicsModeKey, params, 4);␊ |
462 | ␉␉␉␉if (count < 3)␊ |
463 | ␉␉␉␉␉getResolution(params);␊ |
464 | ␉␉␉␉else␊ |
465 | ␉␉␉␉{␊ |
466 | ␉␉␉␉␉if ( params[2] == 256 ) params[2] = 8;␊ |
467 | ␉␉␉␉␉if ( params[2] == 555 ) params[2] = 16;␊ |
468 | ␉␉␉␉␉if ( params[2] == 888 ) params[2] = 32;␊ |
469 | ␉␉␉␉}␊ |
470 | ␉␉␉}␊ |
471 | ␉␉␉␊ |
472 | ␉␉␉//Resolution has changed, reapply the patch␊ |
473 | ␉␉␉if ((params[0] != 0) && (params[1] != 0) && (params[0] != map->currentX) &&␊ |
474 | ␉␉␉␉(params[1] != map->currentY))␊ |
475 | ␉␉␉{␊ |
476 | ␉␉␉␉patchVbios(map, params[0], params[1], params[2], 0, 0);␊ |
477 | ␉␉␉}␊ |
478 | ␉␉␉closeVbios(map); // doesn't print to screen from here␊ |
479 | ␉␉}␊ |
480 | //Azi:autoresolution end␊ |
481 | ␉␉␊ |
482 | ␉␉status = processBootOptions();␊ |
483 | ␉␉␊ |
484 | ␉␉// Status == 1 means to chainboot␊ |
485 | ␉␉if ( status ==␉1 ) break;␊ |
486 | ␉␉␊ |
487 | ␉␉// Status == -1 means that gBootVolume is NULL - Azi: little edit to reflect current status.␊ |
488 | ␉␉if ( status == -1 )␊ |
489 | ␉␉{␊ |
490 | ␉␉␉// gBootVolume == NULL usually means the user hit escape.␊ |
491 | ␉␉␉if (gBootVolume == NULL) //Azi: hitting escape makes me boot when "at" boot prompt.␊ |
492 | ␉␉␉{␊ |
493 | ␉␉␉␉freeFilteredBVChain(bvChain);␊ |
494 | ␉␉␉␉␊ |
495 | ␉␉␉␉if (gEnableCDROMRescan)␊ |
496 | ␉␉␉␉␉rescanBIOSDevice(gBIOSDev);␊ |
497 | ␉␉␉␉␊ |
498 | ␉␉␉␉bvChain = newFilteredBVChain(0x80, 0xFF, allowBVFlags, denyBVFlags, &gDeviceCount);␊ |
499 | ␉␉␉␉setBootGlobals(bvChain);␊ |
500 | ␉␉␉}␊ |
501 | ␉␉␉continue;␊ |
502 | ␉␉}␊ |
503 | ␉␉␊ |
504 | ␉␉// Other status (e.g. 0) means that we should proceed with boot.␊ |
505 | ␉␉// Found and loaded a config file (Azi: not mandatory anymore).␊ |
506 | ␉␉␊ |
507 | //Azi:autoresolution old - testing␊ |
508 | ␉␉␊ |
509 | ␉␉// Find out which version mac os we're booting. Azi:sysversion␊ |
510 | ␉␉// To avoid call loadOverrideConfig from here too and since moving this before calling␊ |
511 | ␉␉// processBootOptions() (which worked on a brief test) doesn't make sense,␊ |
512 | ␉␉// tried to move it to processBootOptions() on options.c (check there).␊ |
513 | ␉␉if (!loadConfigFile("/System/Library/CoreServices/SystemVersion.plist", &systemVersion))␊ |
514 | ␉␉{ //Azi: shouldn't this path start with / ?␊ |
515 | ␉␉␉if (getValueForKey(kProductVersion, &val, &len, &systemVersion))␊ |
516 | ␉␉␉{␊ |
517 | ␉␉␉␉// getValueForKey uses const char for val␊ |
518 | ␉␉␉␉// so copy it and trim␊ |
519 | ␉␉␉␉strncpy(sysVersion, val, MIN(len, 4));␊ |
520 | ␉␉␉␉sysVersion[MIN(len, 4)] = '\0';␊ |
521 | ␉␉␉}␊ |
522 | ␉␉}␊ |
523 | ␉␉␊ |
524 | ␉␉//Azi:sysversion - gMacOSVersion is only initialized above so, this call is only to get␊ |
525 | ␉␉// system version so we can override Boot.plist from specific OS folders; another plus is verbose.␊ |
526 | ␉␉// It seems to work fine though i'm not sure how sane is to call it twice?!␊ |
527 | ␉␉// Can't be called only from here! Need advice. Check above.␊ |
528 | ␉␉//loadOverrideConfig(&bootInfo->overrideConfig); // call 2␊ |
529 | ␉␉␊ |
530 | ␉␉// If cpu does not understand 64 bit instructions,...␊ |
531 | ␉␉if ( !platformCPUFeature(CPU_FEATURE_EM64T) ||␊ |
532 | ␉␉␉// ... user forced i386 kernel architecture on cpu with em64t...␊ |
533 | ␉␉␉getValueForKey(kArchI386Flag, &val, &len, &bootInfo->bootConfig) ||␊ |
534 | ␉␉␉// ... or forced Legacy Mode... (not needed!)␊ |
535 | ␉␉␉getValueForKey(kLegacyModeFlag, &val, &len, &bootInfo->bootConfig) )␊ |
536 | ␉␉{␊ |
537 | ␉␉␉// ... use i386 kernel arch!␊ |
538 | ␉␉␉archCpuType = CPU_TYPE_I386;␊ |
539 | ␉␉}␊ |
540 | ␉␉else␊ |
541 | ␉␉{␊ |
542 | ␉␉␉// Else use x86_64 kernel arch!␊ |
543 | ␉␉␉archCpuType = CPU_TYPE_X86_64;␊ |
544 | ␉␉}␊ |
545 | ␉␉// Force x86_64 kernel arch if i386/-legacy are flagged on Boot.plist.␊ |
546 | ␉␉if (getValueForKey(kArchX86_64Flag, &val, &len, &bootInfo->bootConfig))␊ |
547 | ␉␉{␊ |
548 | ␉␉␉archCpuType = CPU_TYPE_X86_64;␊ |
549 | ␉␉}␊ |
550 | ␉␉␊ |
551 | ␉␉if (!getBoolForKey (kWakeKey, &tryresume, &bootInfo->bootConfig))␊ |
552 | ␉␉{␊ |
553 | ␉␉␉tryresume = true;␊ |
554 | ␉␉␉tryresumedefault = true;␊ |
555 | ␉␉}␊ |
556 | ␉␉else␊ |
557 | ␉␉{␊ |
558 | ␉␉␉tryresumedefault = false;␊ |
559 | ␉␉}␊ |
560 | ␉␉␊ |
561 | ␉␉if (!getBoolForKey (kForceWakeKey, &forceresume, &bootInfo->bootConfig))␊ |
562 | ␉␉{␊ |
563 | ␉␉␉forceresume = false;␊ |
564 | ␉␉}␊ |
565 | ␉␉␊ |
566 | ␉␉if (forceresume)␊ |
567 | ␉␉{␊ |
568 | ␉␉␉tryresume = true;␊ |
569 | ␉␉␉tryresumedefault = false;␊ |
570 | ␉␉}␊ |
571 | ␉␉␊ |
572 | ␉␉while (tryresume)␊ |
573 | ␉␉{␊ |
574 | ␉␉␉const char *tmp;␊ |
575 | ␉␉␉BVRef bvr;␊ |
576 | ␉␉␉if (!getValueForKey(kWakeImageKey, &val, &len, &bootInfo->bootConfig))␊ |
577 | ␉␉␉␉val="/private/var/vm/sleepimage";␊ |
578 | ␉␉␉␊ |
579 | ␉␉␉// Do this first to be sure that root volume is mounted␊ |
580 | ␉␉␉ret = GetFileInfo(0, val, &flags, &sleeptime);␊ |
581 | ␉␉␉␊ |
582 | ␉␉␉if ((bvr = getBootVolumeRef(val, &tmp)) == NULL)␊ |
583 | ␉␉␉␉break;␊ |
584 | ␉␉␉␊ |
585 | ␉␉␉// Can't check if it was hibernation Wake=y is required␊ |
586 | ␉␉␉if (bvr->modTime == 0 && tryresumedefault)␊ |
587 | ␉␉␉␉break;␊ |
588 | ␉␉␉␊ |
589 | ␉␉␉if ((ret != 0) || ((flags & kFileTypeMask) != kFileTypeFlat))␊ |
590 | ␉␉␉␉break;␊ |
591 | ␉␉␉␊ |
592 | ␉␉␉if (!forceresume && ((sleeptime+3)<bvr->modTime))␊ |
593 | ␉␉␉{␊ |
594 | ␉␉␉␉printf("Hibernate image is too old by %d seconds. Use ForceWake=y to override\n",␊ |
595 | ␉␉␉␉␉␉bvr->modTime-sleeptime);␊ |
596 | ␉␉␉␉break;␊ |
597 | ␉␉␉}␊ |
598 | ␉␉␉HibernateBoot((char *)val);␊ |
599 | ␉␉␉break;␊ |
600 | ␉␉}␊ |
601 | ␉␉␊ |
602 | ␉␉// Reset cache name.␊ |
603 | ␉␉bzero(gCacheNameAdler + 64, sizeof(gCacheNameAdler) - 64);␊ |
604 | ␉␉␊ |
605 | ␉␉sprintf(gCacheNameAdler + 64, "%s,%s", gRootDevice, bootInfo->bootFile);␊ |
606 | ␉␉␊ |
607 | ␉␉adler32 = Adler32((unsigned char *)gCacheNameAdler, sizeof(gCacheNameAdler));␊ |
608 | ␉␉␊ |
609 | ␉␉if (getValueForKey(kKernelCacheKey, &val, &len, &bootInfo->bootConfig))␊ |
610 | ␉␉{␊ |
611 | ␉␉␉strlcpy(gBootKernelCacheFile, val, len+1);␊ |
612 | ␉␉}␊ |
613 | ␉␉else␊ |
614 | ␉␉{␊ |
615 | ␉␉␉sprintf(gBootKernelCacheFile, "%s.%08lX", kDefaultCachePath, adler32);␊ |
616 | ␉␉}␊ |
617 | ␉␉␊ |
618 | ␉␉// Check for cache file.␊ |
619 | ␉␉trycache = (((gBootMode & kBootModeSafe) == 0) &&␊ |
620 | ␉␉␉␉␉!gOverrideKernel &&␊ |
621 | ␉␉␉␉␉(gBootFileType == kBlockDeviceType) &&␊ |
622 | ␉␉␉␉␉(gMKextName[0] == '\0') &&␊ |
623 | ␉␉␉␉␉(gBootKernelCacheFile[0] != '\0'));␊ |
624 | ␊ |
625 | ␉␉verbose("Loading Darwin %s\n", sysVersion); //Azi:sysversion␊ |
626 | ␉␉␊ |
627 | ␉␉if (trycache) do␊ |
628 | ␉␉{␊ |
629 | ␉␉␉// if we haven't found the kernel yet, don't use the cache␊ |
630 | ␉␉␉ret = GetFileInfo(NULL, bootInfo->bootFile, &flags, &kerneltime);␊ |
631 | ␉␉␉if ((ret != 0) || ((flags & kFileTypeMask) != kFileTypeFlat))␊ |
632 | ␉␉␉{␊ |
633 | ␉␉␉␉trycache = 0;␊ |
634 | ␉␉␉␉break;␊ |
635 | ␉␉␉}␊ |
636 | ␉␉␉␊ |
637 | ␉␉␉ret = GetFileInfo(NULL, gBootKernelCacheFile, &flags, &cachetime);␊ |
638 | ␉␉␉if ((ret != 0) || ((flags & kFileTypeMask) != kFileTypeFlat)␊ |
639 | ␉␉␉␉|| (cachetime < kerneltime))␊ |
640 | ␉␉␉{␊ |
641 | ␉␉␉␉trycache = 0;␊ |
642 | ␉␉␉␉break;␊ |
643 | ␉␉␉}␊ |
644 | ␉␉␉␊ |
645 | ␉␉␉ret = GetFileInfo("/System/Library/", "Extensions", &flags, &exttime);␊ |
646 | ␉␉␉if ((ret == 0) && ((flags & kFileTypeMask) == kFileTypeDirectory)␊ |
647 | ␉␉␉␉&& (cachetime < exttime))␊ |
648 | ␉␉␉{␊ |
649 | ␉␉␉␉trycache = 0;␊ |
650 | ␉␉␉␉break;␊ |
651 | ␉␉␉}␊ |
652 | ␉␉␉␊ |
653 | ␉␉␉if (kerneltime > exttime)␊ |
654 | ␉␉␉{␊ |
655 | ␉␉␉␉exttime = kerneltime;␊ |
656 | ␉␉␉}␊ |
657 | ␉␉␉␊ |
658 | ␉␉␉if (cachetime != (exttime + 1))␊ |
659 | ␉␉␉{␊ |
660 | ␉␉␉␉trycache = 0;␊ |
661 | ␉␉␉␉break;␊ |
662 | ␉␉␉}␊ |
663 | ␉␉} while (0);␊ |
664 | ␉␉␊ |
665 | ␉␉do␊ |
666 | ␉␉{␊ |
667 | ␉␉␉if (trycache)␊ |
668 | ␉␉␉{␊ |
669 | ␉␉␉␉bootFile = gBootKernelCacheFile;␊ |
670 | ␉␉␉␉verbose("Loading kernel cache %s\n", bootFile); //Azi: i never saw this!! check!!!␊ |
671 | ␉␉␉␉ret = LoadFile(bootFile);␊ |
672 | ␉␉␉␉binary = (void *)kLoadAddr;␊ |
673 | ␉␉␉␉if (ret >= 0)␊ |
674 | ␉␉␉␉{␊ |
675 | ␉␉␉␉␉break;␊ |
676 | ␉␉␉␉}␊ |
677 | ␉␉␉}␊ |
678 | ␉␉␉␊ |
679 | ␉␉␉bootFile = bootInfo->bootFile;␊ |
680 | ␉␉␉␊ |
681 | ␉␉␉// Try to load kernel image from alternate locations on boot helper partitions.␊ |
682 | ␉␉␉sprintf(bootFileSpec, "com.apple.boot.P/%s", bootFile); //Azi:HelperConfig - kernel␊ |
683 | ␉␉␉␊ |
684 | ␉␉␉ret = GetFileInfo(NULL, bootFileSpec, &flags, &time); ␊ |
685 | ␉␉␉if (ret == -1)␊ |
686 | ␉␉␉{␊ |
687 | ␉␉␉␉sprintf(bootFileSpec, "com.apple.boot.R/%s", bootFile);␊ |
688 | ␉␉␉␉␊ |
689 | ␉␉␉␉ret = GetFileInfo(NULL, bootFileSpec, &flags, &time); ␊ |
690 | ␉␉␉␉if (ret == -1)␊ |
691 | ␉␉␉␉{␊ |
692 | ␉␉␉␉␉sprintf(bootFileSpec, "com.apple.boot.S/%s", bootFile);␊ |
693 | ␉␉␉␉␉␊ |
694 | ␉␉␉␉␉ret = GetFileInfo(NULL, bootFileSpec, &flags, &time); ␊ |
695 | ␉␉␉␉␉if (ret == -1)␊ |
696 | ␉␉␉␉␉{␊ |
697 | ␉␉␉␉␉␉// Not found any alternate locations, using the original kernel image path.␊ |
698 | ␉␉␉␉␉␉strcpy(bootFileSpec, bootFile);␊ |
699 | ␉␉␉␉␉}␊ |
700 | ␉␉␉␉}␊ |
701 | ␉␉␉}␊ |
702 | ␉␉␉␉␉␉␊ |
703 | ␉␉␉verbose("Loading kernel %s\n", bootFileSpec);␊ |
704 | ␉␉␉␊ |
705 | ␉␉␉ret = LoadThinFatFile(bootFileSpec, &binary);␊ |
706 | ␉␉␉if (ret <= 0 && archCpuType == CPU_TYPE_X86_64)␊ |
707 | ␉␉␉{␊ |
708 | ␉␉␉␉archCpuType = CPU_TYPE_I386;␊ |
709 | ␉␉␉␉ret = LoadThinFatFile(bootFileSpec, &binary);␉␉␉␉␊ |
710 | ␉␉␉}␊ |
711 | ␉␉␊ |
712 | ␉␉} while (0);␊ |
713 | ␉␉␊ |
714 | ␉␉clearActivityIndicator();␊ |
715 | /*#if DEBUG␊ |
716 | ␉␉printf("Pausing...");␊ |
717 | ␉␉sleep(8);␊ |
718 | #endif Azi: annoying! Can't see the point atm... */␊ |
719 | ␉␉␊ |
720 | ␉␉if (ret <= 0)␊ |
721 | ␉␉{␊ |
722 | ␉␉␉printf("Can't find %s\n", bootFile);␊ |
723 | ␉␉␉␊ |
724 | ␉␉␉if(gui.initialised)␊ |
725 | ␉␉␉{␊ |
726 | ␉␉␉␉sleep(1);␊ |
727 | ␉␉␉␉drawBackground();␊ |
728 | ␉␉␉␉gui.devicelist.draw = true;␊ |
729 | ␉␉␉␉gui.redraw = true;␊ |
730 | ␉␉␉}␊ |
731 | ␉␉␉␊ |
732 | ␉␉␉if (gBootFileType == kNetworkDeviceType) {␊ |
733 | ␉␉␉␉// Return control back to PXE. Don't unload PXE base code.␊ |
734 | ␉␉␉␉gUnloadPXEOnExit = false;␊ |
735 | ␉␉␉␉break;␊ |
736 | ␉␉␉}␊ |
737 | ␉␉}␊ |
738 | ␉␉else␊ |
739 | ␉␉{␊ |
740 | ␉␉␉/* Won't return if successful. */␊ |
741 | ␉␉␉ret = ExecKernel(binary);␊ |
742 | ␉␉}␊ |
743 | ␉}␊ |
744 | ␉␊ |
745 | ␉// chainboot␊ |
746 | ␉if (status==1)␊ |
747 | ␉{␊ |
748 | ␉␉if (getVideoMode() == GRAPHICS_MODE)␊ |
749 | ␉␉{␉// if we are already in graphics-mode,␊ |
750 | ␉␉␉setVideoMode(VGA_TEXT_MODE, 0); // switch back to text mode␊ |
751 | ␉␉}␊ |
752 | ␉}␊ |
753 | ␉␊ |
754 | ␉if ((gBootFileType == kNetworkDeviceType) && gUnloadPXEOnExit)␊ |
755 | ␉{␊ |
756 | ␉␉nbpUnloadBaseCode();␊ |
757 | ␉}␊ |
758 | }␊ |
759 | ␊ |
760 | /*!␊ |
761 | Selects a new BIOS device, taking care to update the global state appropriately.␊ |
762 | */␊ |
763 | /*␊ |
764 | static void selectBiosDevice(void)␊ |
765 | {␊ |
766 | struct DiskBVMap *oldMap = diskResetBootVolumes(gBIOSDev);␊ |
767 | CacheReset();␊ |
768 | diskFreeMap(oldMap);␊ |
769 | oldMap = NULL;␊ |
770 | ␊ |
771 | int dev = selectAlternateBootDevice(gBIOSDev);␊ |
772 | ␊ |
773 | BVRef bvchain = scanBootVolumes(dev, 0);␊ |
774 | BVRef bootVol = selectBootVolume(bvchain);␊ |
775 | gBootVolume = bootVol;␊ |
776 | setRootVolume(bootVol);␊ |
777 | gBIOSDev = dev;␊ |
778 | }␊ |
779 | */␊ |
780 | ␊ |
781 | #define BASE 65521L /* largest prime smaller than 65536 */␊ |
782 | #define NMAX 5000␊ |
783 | // NMAX (was 5521) the largest n such that 255n(n+1)/2 + (n+1)(BASE-1) <= 2^32-1␊ |
784 | ␊ |
785 | #define DO1(buf,i) {s1 += buf[i]; s2 += s1;}␊ |
786 | #define DO2(buf,i) DO1(buf,i); DO1(buf,i+1);␊ |
787 | #define DO4(buf,i) DO2(buf,i); DO2(buf,i+2);␊ |
788 | #define DO8(buf,i) DO4(buf,i); DO4(buf,i+4);␊ |
789 | #define DO16(buf) DO8(buf,0); DO8(buf,8);␊ |
790 | ␊ |
791 | unsigned long Adler32(unsigned char *buf, long len)␊ |
792 | {␊ |
793 | unsigned long s1 = 1; // adler & 0xffff;␊ |
794 | unsigned long s2 = 0; // (adler >> 16) & 0xffff;␊ |
795 | unsigned long result;␊ |
796 | int k;␊ |
797 | ␊ |
798 | while (len > 0) {␊ |
799 | k = len < NMAX ? len : NMAX;␊ |
800 | len -= k;␊ |
801 | while (k >= 16) {␊ |
802 | DO16(buf);␊ |
803 | buf += 16;␊ |
804 | k -= 16;␊ |
805 | }␊ |
806 | if (k != 0) do {␊ |
807 | s1 += *buf++;␊ |
808 | s2 += s1;␊ |
809 | } while (--k);␊ |
810 | s1 %= BASE;␊ |
811 | s2 %= BASE;␊ |
812 | }␊ |
813 | result = (s2 << 16) | s1;␊ |
814 | return OSSwapHostToBigInt32(result);␊ |
815 | }␊ |
816 | |