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