Root/
Source at commit HEAD created 5 years 6 days ago. By ifabio, Few update to kernelPatcher (Credits to CrazyBirdy) | |
---|---|
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 | * Copyright 1993 NeXT Computer, Inc.␊ |
26 | * All rights reserved.␊ |
27 | */␊ |
28 | ␊ |
29 | /* Copyright 2007 David Elliott␊ |
30 | 2007-12-30 dfe␊ |
31 | - Enhanced code to normalize segment/offset to huge pointers so that any␊ |
32 | linear address within the first MB of memory can be passed to BIOS␊ |
33 | functions. This allows some of the __DATA sections to span into the␊ |
34 | next segment and also allows stack variables to be used whereas the␊ |
35 | old code could only operate on static data in the first 64k.␊ |
36 | NOTE: Requires bios.s change to respect DS.␊ |
37 | */␊ |
38 | /* Copyright 2007 VMware Inc.␊ |
39 | 2007-12-29 dfe␊ |
40 | - Added ebiosEjectMedia␊ |
41 | */␊ |
42 | ␊ |
43 | #include "config.h"␊ |
44 | #include "bootstruct.h"␊ |
45 | #include "libsaio.h"␊ |
46 | ␊ |
47 | ␊ |
48 | #if MEMRANGE␊ |
49 | ␉#define DBG(x...)␉printf(x)␊ |
50 | #else␊ |
51 | ␉#define DBG(x...)␉msglog(x)␊ |
52 | #endif␊ |
53 | ␊ |
54 | #define MAX_DRIVES 8␊ |
55 | ␊ |
56 | static biosBuf_t bb;␊ |
57 | ␊ |
58 | ␊ |
59 | //==============================================================================␊ |
60 | ␊ |
61 | int bgetc(void)␊ |
62 | {␊ |
63 | #if 0␊ |
64 | ␉/* Poll for the next character. Most real BIOS do not need this as the␊ |
65 | ␉ INT 16h,AH=0h function will block until one is received.␊ |
66 | ␉ Unfortunately, Apple's EFI CSM will never wake up. This idea is lifted␊ |
67 | ␉ from the grub-a20.patch to GRUB's stage2/asm.S file.␊ |
68 | ␉*/␊ |
69 | ␉while(!readKeyboardStatus());␊ |
70 | ␉// Apple's EFI CSM???? Who cares - Zenith432␊ |
71 | #endif␊ |
72 | ␊ |
73 | ␉bb.intno = 0x16;␊ |
74 | ␉bb.eax.r.h = 0x00;␊ |
75 | ␉bios(&bb);␊ |
76 | ␊ |
77 | ␉return bb.eax.rr;␊ |
78 | }␊ |
79 | ␊ |
80 | ␊ |
81 | //==============================================================================␊ |
82 | ␊ |
83 | int readKeyboardStatus(void)␊ |
84 | {␊ |
85 | ␉bb.intno = 0x16;␊ |
86 | ␉bb.eax.r.h = 0x01;␊ |
87 | ␉bios(&bb);␊ |
88 | ␊ |
89 | ␉if (bb.flags.zf) {␊ |
90 | ␉␉return 0;␊ |
91 | ␉} else ␉{␊ |
92 | ␉␉return bb.eax.rr;␊ |
93 | ␉}␊ |
94 | }␊ |
95 | ␊ |
96 | int readKeyboardShiftFlags(void)␊ |
97 | {␊ |
98 | #if 0␊ |
99 | ␉bb.intno = 0x16;␊ |
100 | ␉bb.eax.r.h = 0x02;␊ |
101 | ␉bios(&bb);␊ |
102 | ␉return bb.eax.r.l;␊ |
103 | #else␊ |
104 | ␉return *(uint8_t const volatile*) 0x417U;␊ |
105 | #endif␊ |
106 | }␊ |
107 | ␊ |
108 | ␊ |
109 | //==============================================================================␊ |
110 | ␊ |
111 | unsigned int time18(void)␊ |
112 | {␊ |
113 | #if 0␊ |
114 | ␉union {␊ |
115 | ␉␉struct {␊ |
116 | ␉␉␉unsigned int low:16;␊ |
117 | ␉␉␉unsigned int high:16;␊ |
118 | ␉␉} s;␊ |
119 | ␊ |
120 | ␉␉unsigned int i;␊ |
121 | ␉} time;␊ |
122 | ␊ |
123 | ␉bb.intno = 0x1a;␊ |
124 | ␉bb.eax.r.h = 0x00;␊ |
125 | ␉bios(&bb);␊ |
126 | ␉time.s.low = bb.edx.rr;␊ |
127 | ␉time.s.high = bb.ecx.rr;␊ |
128 | ␊ |
129 | ␉return time.i;␊ |
130 | #else␊ |
131 | ␉(void) __sync_lock_test_and_set((uint8_t volatile*) 0x470U, (uint8_t) 0U);␊ |
132 | ␉return *(uint32_t const volatile*) 0x46CU;␊ |
133 | #endif␊ |
134 | }␊ |
135 | ␊ |
136 | #if MEMRANGE␊ |
137 | ␊ |
138 | static unsigned long rerangeMemoryMap(unsigned long count);␊ |
139 | static unsigned long rerangeMemoryMap(unsigned long count)␊ |
140 | {␊ |
141 | ␉int i, still_changing, newcount = count;␊ |
142 | ␊ |
143 | ␉MemoryRange * range = (MemoryRange *)BIOS_ADDR;␊ |
144 | ␉struct MemoryRange change_tmp;␊ |
145 | ␊ |
146 | ␉/* sort map list by memory addresses (low -> high) */␊ |
147 | ␉still_changing = 1;␊ |
148 | ␉while (still_changing) {␊ |
149 | ␉␉still_changing = 0;␊ |
150 | ␉␉for (i=1; i<count; i++) {␊ |
151 | ␉␉␉/* if <current_addr> > <last_addr>, swap */␊ |
152 | ␉␉␉if (range[i].base < range[i-1].base) {␊ |
153 | ␉␉␉␉change_tmp.base = range[i].base;␊ |
154 | ␉␉␉␉change_tmp.length = range[i].length;␊ |
155 | ␉␉␉␉change_tmp.type = range[i].type;␊ |
156 | ␊ |
157 | ␉␉␉␉range[i].base = range[i-1].base;␊ |
158 | ␉␉␉␉range[i].length = range[i-1].length;␊ |
159 | ␉␉␉␉range[i].type = range[i-1].type;␊ |
160 | ␊ |
161 | ␉␉␉␉range[i-1].base = change_tmp.base;␊ |
162 | ␉␉␉␉range[i-1].length = change_tmp.length;␊ |
163 | ␉␉␉␉range[i-1].type = change_tmp.type;␊ |
164 | ␊ |
165 | ␉␉␉␉still_changing=1;␊ |
166 | ␉␉␉}␊ |
167 | ␉␉}␊ |
168 | ␉}␊ |
169 | ␊ |
170 | ␉/* clear overlaps */␊ |
171 | ␉/* linux's arch/i386/kern/setup.c may have better algorithm */␊ |
172 | ␉for (i=1; i<count; i++) {␊ |
173 | ␉␉if ( range[i-1].base + range[i-1].length > range[i].base ) {␊ |
174 | ␉␉␉range[newcount].base = range[i].base + range[i].length;␊ |
175 | ␉␉␉range[newcount].length = range[i-1].base + range[i-1].length - range[newcount].base;␊ |
176 | ␉␉␉range[newcount].type = range[i-1].type;␊ |
177 | ␉␉␉newcount++;␊ |
178 | ␊ |
179 | ␉␉␉range[i-1].length = range[i].base - range[i-1].base;␊ |
180 | ␉␉}␊ |
181 | ␉}␊ |
182 | ␊ |
183 | ␉/*␊ |
184 | ␉ * 0xb0000000 : 0x10000000 NG␊ |
185 | ␉ * 0xc0000400 NG␊ |
186 | ␉ * 0xf2000000 NG␊ |
187 | ␉ */␊ |
188 | ␉range[newcount].base = 0xb0000000;␊ |
189 | ␉range[newcount].length = 0x0f000000;␊ |
190 | ␉range[newcount].type = kMemoryRangeUsable;␊ |
191 | ␉newcount++;␊ |
192 | ␊ |
193 | ␉return newcount;␊ |
194 | }␊ |
195 | #endif␊ |
196 | ␊ |
197 | unsigned long getMemoryMap( MemoryRange * rangeArray,␊ |
198 | unsigned long maxRangeCount,␊ |
199 | unsigned long * conMemSizePtr,␊ |
200 | unsigned long * extMemSizePtr )␊ |
201 | {␊ |
202 | ␉#define kMemoryMapSignature 'SMAP'␊ |
203 | ␉#define kDescriptorSizeMin 20␊ |
204 | ␊ |
205 | ␉MemoryRange *␉range = (MemoryRange *)BIOS_ADDR;␊ |
206 | ␉unsigned long␉count = 0;␊ |
207 | #if MEMRANGE␊ |
208 | ␉unsigned long␉rerangedCount;␊ |
209 | #endif␊ |
210 | ␉unsigned long long␉conMemSize = 0;␊ |
211 | ␉unsigned long long␉extMemSize = 0;␊ |
212 | ␊ |
213 | ␉// Prepare for the INT15 E820h call. Each call returns a single␊ |
214 | ␉// memory range. A continuation value is returned that must be␊ |
215 | ␉// provided on a subsequent call to fetch the next range.␊ |
216 | ␉//␊ |
217 | ␉// Certain BIOSes (Award 6.00PG) expect the upper word in EAX␊ |
218 | ␉// to be cleared on entry, otherwise only a single range will␊ |
219 | ␉// be reported.␊ |
220 | ␉//␊ |
221 | ␉// Some BIOSes will simply ignore the value of ECX on entry.␊ |
222 | ␉// Probably best to keep its value at 20 to avoid surprises.␊ |
223 | ␊ |
224 | ␉//printf("Get memory map 0x%x, %d\n", rangeArray); getchar();␊ |
225 | ␉if (maxRangeCount > (BIOS_LEN / sizeof(MemoryRange))) {␊ |
226 | ␉␉maxRangeCount = (BIOS_LEN / sizeof(MemoryRange));␊ |
227 | ␉}␊ |
228 | ␉bb.ebx.rx = 0; // Initial continuation value must be zero.␊ |
229 | ␊ |
230 | ␉while (count < maxRangeCount)␊ |
231 | ␉{␊ |
232 | ␉␉bb.intno = 0x15;␊ |
233 | ␉␉bb.eax.rx = 0xe820;␊ |
234 | ␉␉bb.ecx.rx = kDescriptorSizeMin;␊ |
235 | ␉␉bb.edx.rx = kMemoryMapSignature;␊ |
236 | ␉␉bb.edi.rr = NORMALIZED_OFFSET( (unsigned long) range );␊ |
237 | ␉␉bb.es = NORMALIZED_SEGMENT( (unsigned long) range );␊ |
238 | ␉␉bios(&bb);␊ |
239 | ␊ |
240 | ␉␉// Check for errors.␊ |
241 | ␊ |
242 | ␉␉if ( bb.flags.cf || bb.eax.rx != kMemoryMapSignature || bb.ecx.rx != kDescriptorSizeMin )␊ |
243 | ␉␉{␊ |
244 | ␉␉␉//printf("Got an error %x %x %x\n", bb.flags.cf,␊ |
245 | ␉␉␉// bb.eax.rx, bb.ecx.rx);␊ |
246 | ␉␉␉break;␊ |
247 | ␉␉}␊ |
248 | ␊ |
249 | ␉␉// Tally up the conventional/extended memory sizes.␊ |
250 | ␊ |
251 | ␉␉if ( range->type == kMemoryRangeUsable || range->type == kMemoryRangeACPI || range->type == kMemoryRangeNVS ) {␊ |
252 | ␉␉␉// Tally the conventional memory ranges.␊ |
253 | ␉␉␉if ( range->base + range->length <= 0xa0000 )␊ |
254 | ␉␉␉{␊ |
255 | ␉␉␉␉conMemSize += range->length;␊ |
256 | ␉␉␉}␊ |
257 | ␊ |
258 | ␉␉␉// Record the top of extended memory.␊ |
259 | ␉␉␉if (range->base >= EXTENDED_ADDR)␊ |
260 | ␉␉␉{␊ |
261 | ␉␉␉␉extMemSize += range->length;␊ |
262 | ␉␉␉}␊ |
263 | ␉␉}␊ |
264 | ␊ |
265 | ␉␉range++;␊ |
266 | ␉␉count++;␊ |
267 | ␊ |
268 | ␉␉// Is this the last address range?␊ |
269 | ␊ |
270 | ␉␉if ( bb.ebx.rx == 0 )␊ |
271 | ␉␉{␊ |
272 | ␉␉␉//printf("last range\n");␊ |
273 | ␉␉␉break;␊ |
274 | ␉␉}␊ |
275 | ␉}␊ |
276 | ␊ |
277 | ␉*conMemSizePtr = (conMemSize / 1024); // size in KB␊ |
278 | ␉*extMemSizePtr = (extMemSize / 1024); // size in KB␊ |
279 | ␊ |
280 | #if MEMRANGE␊ |
281 | ␉rerangedCount = rerangeMemoryMap(count);␊ |
282 | ␉range += rerangedCount - count;␊ |
283 | #endif␊ |
284 | ␊ |
285 | ␉// Copy out data␊ |
286 | ␉bcopy((char *)BIOS_ADDR, rangeArray, ((char *)range - (char *)BIOS_ADDR));␊ |
287 | ␊ |
288 | #if DEBUG␊ |
289 | ␉{␊ |
290 | ␉int i;␊ |
291 | printf("%d total ranges\n", count);␊ |
292 | ␊ |
293 | ␉␉getchar();␊ |
294 | ␊ |
295 | ␉␉for (i = 0, range = rangeArray; i<count; i++, range++)␊ |
296 | ␉␉{␊ |
297 | ␉␉␉printf("range: type %d, base 0x%x, length 0x%x\n",␊ |
298 | ␉␉␉range->type, (unsigned int)range->base, (unsigned int)range->length);␊ |
299 | ␉␉␉getchar();␊ |
300 | ␉␉}␊ |
301 | ␉}␊ |
302 | #endif␊ |
303 | ␊ |
304 | ␉return count;␊ |
305 | }␊ |
306 | ␊ |
307 | ␊ |
308 | //==============================================================================␊ |
309 | ␊ |
310 | ␊ |
311 | unsigned long getExtendedMemorySize()␊ |
312 | {␊ |
313 | ␉// Get extended memory size for large configurations. Not used unless␊ |
314 | ␉// the INT15, E820H call (Get System Address Map) failed.␊ |
315 | ␉//␊ |
316 | ␉// Input:␊ |
317 | ␉//␊ |
318 | ␉// AX Function Code E801h␊ |
319 | ␉//␊ |
320 | ␉// Outputs:␊ |
321 | ␉//␊ |
322 | ␉// CF Carry Flag Carry cleared indicates no error.␊ |
323 | ␉// AX Extended 1 Number of contiguous KB between 1 and 16 MB,␊ |
324 | ␉// maximum 0x3C00 = 15 MB.␊ |
325 | ␉// BX Extended 2 Number of contiguous 64 KB blocks between␊ |
326 | ␉// 16 MB and 4 GB.␊ |
327 | ␉// CX Configured 1 Number of contiguous KB between 1 and 16 MB,␊ |
328 | ␉// maximum 0x3C00 = 15 MB.␊ |
329 | ␉// DX Configured 2 Number of contiguous 64 KB blocks between␊ |
330 | ␉// 16 MB and 4 GB.␊ |
331 | ␊ |
332 | ␉bb.intno = 0x15;␊ |
333 | ␉bb.eax.rx = 0xe801;␊ |
334 | ␉bios(&bb);␊ |
335 | ␊ |
336 | ␉// Return the size of memory above 1MB (extended memory) in kilobytes.␊ |
337 | ␊ |
338 | ␉if (bb.flags.cf == 0)␊ |
339 | ␉{␊ |
340 | ␉␉return (bb.ebx.rr * 64 + bb.eax.rr);␊ |
341 | ␉}␊ |
342 | ␊ |
343 | ␉// Get Extended memory size. Called on last resort since the return␊ |
344 | ␉// value is limited to 16-bits (a little less than 64MB max). May␊ |
345 | ␉// not be supported by modern BIOSes.␊ |
346 | ␉//␊ |
347 | ␉// Input:␊ |
348 | ␉//␊ |
349 | ␉// AX Function Code E801h␊ |
350 | ␉//␊ |
351 | ␉// Outputs:␊ |
352 | ␉//␊ |
353 | ␉// CF Carry Flag Carry cleared indicates no error.␊ |
354 | ␉// AX Memory Count Number of contiguous KB above 1MB.␊ |
355 | ␊ |
356 | ␉bb.intno = 0x15;␊ |
357 | ␉bb.eax.rx = 0x88;␊ |
358 | ␉bios(&bb);␊ |
359 | ␊ |
360 | ␉// Return the size of memory above 1MB (extended memory) in kilobytes.␊ |
361 | ␊ |
362 | ␉return bb.flags.cf ? 0 : bb.eax.rr;␊ |
363 | }␊ |
364 | ␊ |
365 | ␊ |
366 | //==============================================================================␊ |
367 | ␊ |
368 | ␊ |
369 | unsigned long getConventionalMemorySize()␊ |
370 | {␊ |
371 | ␉bb.intno = 0x12;␊ |
372 | ␉bios(&bb);␊ |
373 | ␊ |
374 | ␉return bb.eax.rr; // kilobytes␊ |
375 | }␊ |
376 | ␊ |
377 | ␊ |
378 | //==============================================================================␊ |
379 | ␊ |
380 | ␊ |
381 | void video_mode(int mode)␊ |
382 | {␊ |
383 | ␉bb.intno = 0x10;␊ |
384 | ␉bb.eax.r.h = 0x00;␊ |
385 | ␉bb.eax.r.l = mode;␊ |
386 | ␉bios(&bb);␊ |
387 | }␊ |
388 | ␊ |
389 | ␊ |
390 | //==============================================================================␊ |
391 | ␊ |
392 | int biosread(int dev, int cyl, int head, int sec, int num)␊ |
393 | {␊ |
394 | ␉int i;␊ |
395 | ␊ |
396 | ␉bb.intno = 0x13;␊ |
397 | ␉sec += 1; // sector numbers start at 1.␊ |
398 | ␊ |
399 | ␉for (i = 0; ;)␊ |
400 | ␉{␊ |
401 | ␉␉bb.ecx.r.h = cyl;␊ |
402 | ␉␉bb.ecx.r.l = ((cyl & 0x300) >> 2) | (sec & 0x3F);␊ |
403 | ␉␉bb.edx.r.h = head;␊ |
404 | ␉␉bb.edx.r.l = dev;␊ |
405 | ␉␉bb.eax.r.l = num;␊ |
406 | ␉␉bb.ebx.rr = OFFSET(ptov(BIOS_ADDR));␊ |
407 | ␉␉bb.es = SEGMENT(ptov(BIOS_ADDR));␊ |
408 | ␊ |
409 | ␉␉bb.eax.r.h = 0x02;␊ |
410 | ␉␉bios(&bb);␊ |
411 | ␊ |
412 | ␉␉// In case of a successful call, make sure we set AH (return code) to zero.␊ |
413 | ␉␉if (bb.flags.cf == 0)␊ |
414 | ␉␉{␊ |
415 | ␉␉␉bb.eax.r.h = 0;␊ |
416 | ␉␉}␊ |
417 | ␊ |
418 | ␉␉// Now we can really check for the return code (AH) value.␊ |
419 | ␉␉if ((bb.eax.r.h == 0x00) || (i++ >= 5))␊ |
420 | ␉␉{␊ |
421 | ␉␉␉break;␊ |
422 | ␉␉}␊ |
423 | ␊ |
424 | // Reset disk subsystem and try again.␊ |
425 | ␉␉bb.eax.r.h = 0x00;␊ |
426 | ␉␉bios(&bb);␊ |
427 | ␉}␊ |
428 | ␊ |
429 | ␉return bb.eax.r.h;␊ |
430 | }␊ |
431 | ␊ |
432 | ␊ |
433 | //==============================================================================␊ |
434 | ␊ |
435 | int ebiosread(int dev, unsigned long long sec, int count)␊ |
436 | {␊ |
437 | ␉int i;␊ |
438 | ␊ |
439 | ␉static struct␊ |
440 | ␉{␊ |
441 | ␉␉unsigned char size;␊ |
442 | ␉␉unsigned char reserved;␊ |
443 | ␉␉unsigned char numblocks;␊ |
444 | ␉␉unsigned char reserved2;␊ |
445 | ␉␉unsigned short bufferOffset;␊ |
446 | ␉␉unsigned short bufferSegment;␊ |
447 | ␉␉unsigned long long startblock;␊ |
448 | ␉} addrpacket __attribute__((aligned(16))) = {0};␊ |
449 | ␉addrpacket.size = sizeof(addrpacket);␊ |
450 | ␊ |
451 | ␉for (i = 0; ;)␊ |
452 | ␉{␊ |
453 | ␉␉bb.intno = 0x13;␊ |
454 | ␉␉bb.eax.r.h = 0x42;␊ |
455 | ␉␉bb.edx.r.l = dev;␊ |
456 | ␉␉bb.esi.rr = NORMALIZED_OFFSET((unsigned)&addrpacket);␊ |
457 | ␉␉bb.ds = NORMALIZED_SEGMENT((unsigned)&addrpacket);␊ |
458 | ␉␉addrpacket.reserved = addrpacket.reserved2 = 0;␊ |
459 | ␉␉addrpacket.numblocks = count;␊ |
460 | ␉␉addrpacket.bufferOffset = OFFSET(ptov(BIOS_ADDR));␊ |
461 | ␉␉addrpacket.bufferSegment = SEGMENT(ptov(BIOS_ADDR));␊ |
462 | ␉␉addrpacket.startblock = sec;␊ |
463 | ␉␉bios(&bb);␊ |
464 | ␊ |
465 | ␉␉// In case of a successful call, make sure we set AH (return code) to zero.␊ |
466 | ␉␉if (bb.flags.cf == 0)␊ |
467 | ␉␉{␊ |
468 | ␉␉␉bb.eax.r.h = 0;␊ |
469 | ␉␉}␊ |
470 | ␉␉␊ |
471 | ␉␉// Now we can really check for the return code (AH) value.␊ |
472 | ␉␉if ((bb.eax.r.h == 0x00) || (i++ >= 5))␊ |
473 | ␉␉{␊ |
474 | ␉␉␉break;␊ |
475 | ␉␉}␊ |
476 | ␊ |
477 | ␉␉// Reset disk subsystem and try again.␊ |
478 | ␉␉bb.eax.r.h = 0x00;␊ |
479 | ␉␉bios(&bb);␊ |
480 | ␉}␊ |
481 | ␊ |
482 | ␉return bb.eax.r.h;␊ |
483 | }␊ |
484 | ␊ |
485 | //==============================================================================␊ |
486 | ␊ |
487 | int ebioswrite(int dev, long sec, int count)␊ |
488 | {␊ |
489 | ␉int i;␊ |
490 | ␉static struct {␊ |
491 | ␉␉unsigned char size;␊ |
492 | ␉␉unsigned char reserved;␊ |
493 | ␉␉unsigned char numblocks;␊ |
494 | ␉␉unsigned char reserved2;␊ |
495 | ␉␉unsigned short bufferOffset;␊ |
496 | ␉␉unsigned short bufferSegment;␊ |
497 | ␉␉unsigned long long startblock;␊ |
498 | ␉} addrpacket __attribute__((aligned(16))) = {0};␊ |
499 | ␉addrpacket.size = sizeof(addrpacket);␊ |
500 | ␊ |
501 | ␉for (i=0;;) {␊ |
502 | ␉␉bb.intno = 0x13;␊ |
503 | ␉␉bb.eax.r.l = 0; /* Don't verify */␊ |
504 | ␉␉bb.eax.r.h = 0x43;␊ |
505 | ␉␉bb.edx.r.l = dev;␊ |
506 | ␉␉bb.esi.rr = NORMALIZED_OFFSET((unsigned)&addrpacket);␊ |
507 | ␉␉bb.ds = NORMALIZED_SEGMENT((unsigned)&addrpacket);␊ |
508 | ␉␉addrpacket.reserved = addrpacket.reserved2 = 0;␊ |
509 | ␉␉addrpacket.numblocks = count;␊ |
510 | ␉␉addrpacket.bufferOffset = OFFSET(ptov(BIOS_ADDR));␊ |
511 | ␉␉addrpacket.bufferSegment = SEGMENT(ptov(BIOS_ADDR));␊ |
512 | ␉␉addrpacket.startblock = sec;␊ |
513 | ␉␉bios(&bb);␊ |
514 | ␊ |
515 | ␉␉/* In case of a successful call, make sure we set AH (return code) to zero. */␊ |
516 | ␉␉if (bb.flags.cf == 0)␊ |
517 | ␉␉␉bb.eax.r.h = 0;␊ |
518 | ␊ |
519 | ␉␉/* Now we can really check for the return code (AH) value. */␊ |
520 | ␉␉if ((bb.eax.r.h == 0x00) || (i++ >= 5))␊ |
521 | ␉␉break;␊ |
522 | ␊ |
523 | ␉␉/* reset disk subsystem and try again */␊ |
524 | ␉␉bb.eax.r.h = 0x00;␊ |
525 | ␉␉bios(&bb);␊ |
526 | ␉}␊ |
527 | ␉return bb.eax.r.h;␊ |
528 | }␊ |
529 | ␊ |
530 | void bios_putchar(int ch)␊ |
531 | {␊ |
532 | ␉bb.intno␉= 0x10;␊ |
533 | ␉bb.ebx.r.h␉= 0x00; /* background black */␊ |
534 | ␉bb.ebx.r.l␉= 0x0F; /* foreground white */␊ |
535 | ␉bb.eax.r.h␉= 0x0e;␊ |
536 | ␉bb.eax.r.l␉= ch;␊ |
537 | ␉bios(&bb);␊ |
538 | }␊ |
539 | ␊ |
540 | ␊ |
541 | //==============================================================================␊ |
542 | ␊ |
543 | void putca(int ch, int attr, int repeat)␊ |
544 | {␊ |
545 | ␉bb.intno = 0x10;␊ |
546 | ␉bb.ebx.r.h = 0x00; /* page number */␊ |
547 | ␉bb.ebx.r.l = attr; /* attribute */␊ |
548 | ␉bb.eax.r.h = 0x9;␊ |
549 | ␉bb.eax.r.l = ch;␊ |
550 | ␉bb.ecx.rx = repeat; /* repeat count */ ␊ |
551 | ␉bios(&bb);␊ |
552 | }␊ |
553 | ␊ |
554 | ␊ |
555 | //==============================================================================␊ |
556 | // Check to see if the passed-in drive is in El Torito no-emulation mode.␊ |
557 | ␊ |
558 | int is_no_emulation(int drive)␊ |
559 | {␊ |
560 | ␉struct packet␊ |
561 | ␉{␊ |
562 | ␉␉unsigned char packet_size;␊ |
563 | ␉␉unsigned char media_type;␊ |
564 | ␉␉unsigned char drive_num;␊ |
565 | ␉␉unsigned char ctrlr_index;␊ |
566 | ␉␉unsigned long lba;␊ |
567 | ␉␉unsigned short device_spec;␊ |
568 | ␉␉unsigned short buffer_segment;␊ |
569 | ␉␉unsigned short load_segment;␊ |
570 | ␉␉unsigned short sector_count;␊ |
571 | ␉␉unsigned char cyl_count;␊ |
572 | ␉␉unsigned char sec_count;␊ |
573 | ␉␉unsigned char head_count;␊ |
574 | ␉␉unsigned char reseved;␊ |
575 | ␉} __attribute__((packed));␊ |
576 | ␉static struct packet pkt;␊ |
577 | ␊ |
578 | ␉bzero(&pkt, sizeof(pkt));␊ |
579 | ␉pkt.packet_size = 0x13;␊ |
580 | ␊ |
581 | ␉bb.intno = 0x13;␊ |
582 | ␉bb.eax.r.h = 0x4b;␊ |
583 | ␉bb.eax.r.l = 0x01; // subfunc: get info␊ |
584 | ␉bb.edx.r.l = drive;␊ |
585 | ␉bb.esi.rr = NORMALIZED_OFFSET((unsigned)&pkt);␊ |
586 | ␉bb.ds = NORMALIZED_SEGMENT((unsigned)&pkt);␊ |
587 | ␊ |
588 | ␉bios(&bb);␊ |
589 | ␊ |
590 | #if DEBUG␊ |
591 | ␉printf("el_torito info drive %x\n", drive);␊ |
592 | ␉printf("--> cf %x, eax %x\n", bb.flags.cf, bb.eax.rr);␊ |
593 | ␉printf("pkt_size: %x\n", pkt.packet_size);␊ |
594 | ␉printf("media_type: %x\n", pkt.media_type);␊ |
595 | ␉printf("drive_num: %x\n", pkt.drive_num);␊ |
596 | ␉printf("device_spec: %x\n", pkt.device_spec);␊ |
597 | ␊ |
598 | ␉pause();␊ |
599 | #endif␊ |
600 | ␊ |
601 | ␉/* Some BIOSes erroneously return cf = 1 */␊ |
602 | ␉/* Just check to see if the drive number is the same. */␊ |
603 | ␉if (pkt.drive_num == drive && (pkt.media_type & 0x0F) == 0)␊ |
604 | ␉{␊ |
605 | ␉␉return 1; // We are in no-emulation mode.␊ |
606 | ␉}␊ |
607 | ␊ |
608 | ␉return 0;␊ |
609 | }␊ |
610 | ␊ |
611 | #if DEBUG␊ |
612 | /*␊ |
613 | * BIOS drive information.␊ |
614 | */␊ |
615 | static void print_drive_info(boot_drive_info_t *dp)␊ |
616 | {␊ |
617 | //␉printf("buf_size = %x\n", dp->params.buf_size);␊ |
618 | ␉printf("info_flags = %x\n", dp->params.info_flags);␊ |
619 | ␉printf("phys_cyls = %lx\n", dp->params. phys_cyls);␊ |
620 | ␉printf("phys_heads = %lx\n", dp->params. phys_heads);␊ |
621 | ␉printf("phys_spt = %lx\n", dp->params. phys_spt);␊ |
622 | ␉printf("phys_sectors = %lx%lx\n", ((unsigned long *)(&dp->params.phys_sectors))[1],␊ |
623 | ␉␉ ((unsigned long *)(&dp->params.phys_sectors))[0]);␊ |
624 | ␉printf("phys_nbps = %x\n", dp->params.phys_nbps);␊ |
625 | //␉printf("dpte_offset = %x\n", dp->params.dpte_offset);␊ |
626 | //␉printf("dpte_segment = %x\n", dp->params.dpte_segment);␊ |
627 | //␉printf("key = %x\n", dp->params.key);␊ |
628 | //␉printf("path_len = %x\n", dp->params. path_len);␊ |
629 | //␉printf("reserved1 = %x\n", dp->params. reserved1);␊ |
630 | //␉printf("reserved2 = %x\n", dp->params.reserved2);␊ |
631 | //␉printf("bus_type[4] = %x\n", dp->params. bus_type[4]);␊ |
632 | //␉printf("interface_type[8] = %x\n", dp->params. interface_type[8]);␊ |
633 | //␉printf("interface_path[8] = %x\n", dp->params. interface_path[8]);␊ |
634 | //␉printf("dev_path[16] = %x\n", dp->params. dev_path[16]);␊ |
635 | //␉printf("reserved3 = %x\n", dp->params. reserved3);␊ |
636 | //␉printf("checksum = %x\n", dp->params. checksum);␊ |
637 | ␉printf("io_port_base = %x\n", dp->dpte.io_port_base);␊ |
638 | ␉printf("control_port_base = %x\n", dp->dpte.control_port_base);␊ |
639 | ␉printf("head_flags = %x\n", dp->dpte. head_flags);␊ |
640 | ␉printf("vendor_info = %x\n", dp->dpte. vendor_info);␊ |
641 | ␉printf("irq = %x\n", dp->dpte. irq);␊ |
642 | //␉printf("irq_unused = %x\n", dp->dpte. irq_unused);␊ |
643 | ␉printf("block_count = %x\n", dp->dpte. block_count);␊ |
644 | ␉printf("dma_channe = %x\n", dp->dpte. dma_channel);␊ |
645 | ␉printf("dma_type = %x\n", dp->dpte. dma_type);␊ |
646 | ␉printf("pio_type = %x\n", dp->dpte. pio_type);␊ |
647 | ␉printf("pio_unused = %x\n", dp->dpte. pio_unused);␊ |
648 | ␉printf("option_flags = %x\n", dp->dpte.option_flags);␊ |
649 | //␉printf("reserved = %x\n", dp->dpte.reserved);␊ |
650 | ␉printf("revision = %x\n", dp->dpte. revision);␊ |
651 | //␉printf("checksum = %x\n", dp->dpte. checksum);␊ |
652 | }␊ |
653 | ␊ |
654 | #endif␊ |
655 | ␊ |
656 | //==============================================================================␊ |
657 | ␊ |
658 | int get_drive_info(int drive, struct driveInfo *dp)␊ |
659 | {␊ |
660 | ␉int ret = 0;␊ |
661 | ␊ |
662 | ␉boot_drive_info_t *di = &dp->di;␊ |
663 | ␊ |
664 | #if UNUSED␊ |
665 | ␉if (maxhd == 0) {␊ |
666 | ␉␉bb.intno = 0x13;␊ |
667 | ␉␉bb.eax.r.h = 0x08;␊ |
668 | ␉␉bb.edx.r.l = 0x80;␊ |
669 | ␉␉bios(&bb);␊ |
670 | ␊ |
671 | ␉␉if (bb.flags.cf == 0) {␊ |
672 | ␉␉␉maxhd = 0x7f + bb.edx.r.l;␊ |
673 | ␉␉}␊ |
674 | ␉};␊ |
675 | ␊ |
676 | ␉if (drive > maxhd) {␊ |
677 | ␉␉return 0;␊ |
678 | ␉}␊ |
679 | #endif␊ |
680 | ␊ |
681 | ␉bzero(dp, sizeof(struct driveInfo));␊ |
682 | ␉dp->biosdev = drive;␊ |
683 | ␊ |
684 | ␉/* Check for El Torito no-emulation mode. */␊ |
685 | ␉dp->no_emulation = is_no_emulation(drive);␊ |
686 | ␊ |
687 | ␉/* Check drive for EBIOS support. */␊ |
688 | ␉bb.intno = 0x13;␊ |
689 | ␉bb.eax.r.h = 0x41;␊ |
690 | ␉bb.edx.r.l = drive;␊ |
691 | ␉bb.ebx.rr = 0x55aa;␊ |
692 | ␉bios(&bb);␊ |
693 | ␉␊ |
694 | ␉if ((bb.ebx.rr == 0xaa55) && (bb.flags.cf == 0))␊ |
695 | ␉{␊ |
696 | ␉␉/* Get flags for supported operations. */␊ |
697 | ␉␉dp->uses_ebios = bb.ecx.r.l;␊ |
698 | ␉}␊ |
699 | ␊ |
700 | ␉if (dp->uses_ebios & (EBIOS_ENHANCED_DRIVE_INFO | EBIOS_LOCKING_ACCESS | EBIOS_FIXED_DISK_ACCESS))␊ |
701 | ␉{␊ |
702 | ␉␉/* Get EBIOS drive info. */␊ |
703 | ␉␉static struct drive_params params;␊ |
704 | ␉␉␊ |
705 | ␉␉params.buf_size = sizeof(params);␊ |
706 | ␉␉bb.intno = 0x13;␊ |
707 | ␉␉bb.eax.r.h = 0x48;␊ |
708 | ␉␉bb.edx.r.l = drive;␊ |
709 | ␉␉bb.esi.rr = NORMALIZED_OFFSET((unsigned)¶ms);␊ |
710 | ␉␉bb.ds␉ = NORMALIZED_SEGMENT((unsigned)¶ms);␊ |
711 | ␉␉bios(&bb);␊ |
712 | ␉␉␊ |
713 | ␉␉if (bb.flags.cf != 0 /* || params.phys_sectors < 2097152 */)␊ |
714 | ␉␉{␊ |
715 | ␉␉␉dp->uses_ebios = 0;␊ |
716 | ␉␉␉di->params.buf_size = 1;␊ |
717 | ␉␉}␊ |
718 | ␉␉else␊ |
719 | ␉␉{␊ |
720 | ␉␉␉bcopy(¶ms, &di->params, sizeof(params));␊ |
721 | ␉␉␉␊ |
722 | ␉␉␉if (drive >= BASE_HD_DRIVE &&␊ |
723 | ␉␉␉␉(dp->uses_ebios & EBIOS_ENHANCED_DRIVE_INFO) &&␊ |
724 | ␉␉␉␉di->params.buf_size >= 30 &&␊ |
725 | ␉␉␉␉!(di->params.dpte_offset == 0xFFFF && di->params.dpte_segment == 0xFFFF))␊ |
726 | ␉␉␉{␊ |
727 | ␉␉␉␉␉void *ptr = (void *)(di->params.dpte_offset + ((unsigned int)di->params.dpte_segment << 4));␊ |
728 | ␉␉␉␉␉bcopy(ptr, &di->dpte, sizeof(di->dpte));␊ |
729 | ␉␉␉}␊ |
730 | ␉␉}␊ |
731 | ␉}␊ |
732 | ␊ |
733 | /*␊ |
734 | * zef: This code will fail on recent JMicron and Intel option ROMs␊ |
735 | */ ␊ |
736 | //␉if (di->params.phys_heads == 0 || di->params.phys_spt == 0) {␊ |
737 | //␉␉/* Either it's not EBIOS, or EBIOS didn't tell us. */␊ |
738 | //␉␉bb.intno = 0x13;␊ |
739 | //␉␉bb.eax.r.h = 0x08;␊ |
740 | //␉␉bb.edx.r.l = drive;␊ |
741 | //␉␉bios(&bb);␊ |
742 | //␉␉if (bb.flags.cf == 0 && bb.eax.r.h == 0) {␊ |
743 | //␉␉␉unsigned long cyl;␊ |
744 | //␉␉␉unsigned long sec;␊ |
745 | //␉␉␉unsigned long hds;␊ |
746 | //␊ |
747 | //␉␉␉hds = bb.edx.r.h;␊ |
748 | //␉␉␉sec = bb.ecx.r.l & 0x3F;␊ |
749 | //␉␉␉if ((dp->uses_ebios & EBIOS_ENHANCED_DRIVE_INFO) && (sec != 0)) {␊ |
750 | //␉␉␉␉cyl = (di->params.phys_sectors / ((hds + 1) * sec)) - 1;␊ |
751 | //␉␉␉} else {␊ |
752 | //␉␉␉␉cyl = bb.ecx.r.h | ((bb.ecx.r.l & 0xC0) << 2);␊ |
753 | //␉␉␉}␊ |
754 | //␉␉␉di->params.phys_heads = hds; ␊ |
755 | //␉␉␉di->params.phys_spt = sec;␊ |
756 | //␉␉␉di->params.phys_cyls = cyl;␊ |
757 | //␉␉} else {␊ |
758 | //␉␉␉ret = -1;␊ |
759 | //␉␉}␊ |
760 | //␉}␊ |
761 | ␊ |
762 | ␉if (dp->no_emulation)␊ |
763 | ␉{␊ |
764 | ␉␉/* Some BIOSes give us erroneous EBIOS support information.␊ |
765 | ␉ ␉ * Assume that if you're on a CD, then you can use␊ |
766 | ␉ ␉ * EBIOS disk calls.␊ |
767 | ␉ ␉ */␊ |
768 | ␉␉dp->uses_ebios |= EBIOS_FIXED_DISK_ACCESS;␊ |
769 | ␉}␊ |
770 | #if DEBUG␊ |
771 | ␉print_drive_info(di);␊ |
772 | ␉printf("uses_ebios = 0x%x\n", dp->uses_ebios);␊ |
773 | ␉printf("result %d\n", ret);␊ |
774 | ␉pause();␊ |
775 | #endif␊ |
776 | ␊ |
777 | ␉if (ret == 0)␊ |
778 | ␉{␊ |
779 | ␉␉dp->valid = 1;␊ |
780 | ␉}␊ |
781 | ␉return ret;␊ |
782 | }␊ |
783 | ␊ |
784 | //==============================================================================␊ |
785 | ␊ |
786 | #if UNUSED␊ |
787 | int ebiosEjectMedia(int biosdev)␊ |
788 | {␊ |
789 | ␉bb.intno = 0x13;␊ |
790 | ␉bb.eax.r.h = 0x46;␊ |
791 | ␉bb.eax.r.l = 0;␊ |
792 | ␉bb.edx.rx = biosdev;␊ |
793 | ␉bios(&bb);␊ |
794 | ␉return bb.eax.r.h;␊ |
795 | }␊ |
796 | #endif␊ |
797 | ␊ |
798 | void setCursorPosition(int x, int y, int page)␊ |
799 | {␊ |
800 | ␉bb.intno = 0x10;␊ |
801 | ␉bb.eax.r.h = 0x02;␊ |
802 | ␉bb.ebx.r.h = page; /* page 0 for graphics */␊ |
803 | ␉bb.edx.r.l = x;␊ |
804 | ␉bb.edx.r.h = y;␊ |
805 | ␉bios(&bb);␊ |
806 | }␊ |
807 | ␊ |
808 | void setCursorType(int type)␊ |
809 | {␊ |
810 | ␉bb.intno = 0x10;␊ |
811 | ␉bb.eax.r.h = 0x01;␊ |
812 | ␉bb.ecx.rr = type;␊ |
813 | ␉bios(&bb);␊ |
814 | }␊ |
815 | ␊ |
816 | void getCursorPositionAndType(int * x, int * y, int * type)␊ |
817 | {␊ |
818 | ␉bb.intno = 0x10;␊ |
819 | ␉bb.eax.r.h = 0x03;␊ |
820 | ␉bios(&bb);␊ |
821 | ␉*x = bb.edx.r.l;␊ |
822 | ␉*y = bb.edx.r.h;␊ |
823 | ␉*type = bb.ecx.rr;␊ |
824 | }␊ |
825 | ␊ |
826 | void scollPage(int x1, int y1, int x2, int y2, int attr, int rows, int dir)␊ |
827 | {␊ |
828 | ␉bb.intno = 0x10;␊ |
829 | ␉bb.eax.r.h = (dir > 0) ? 0x06 : 0x07;␊ |
830 | ␉bb.eax.r.l = rows;␊ |
831 | ␉bb.ebx.r.h = attr;␊ |
832 | ␉bb.ecx.r.h = y1;␊ |
833 | ␉bb.ecx.r.l = x1;␊ |
834 | ␉bb.edx.r.h = y2;␊ |
835 | ␉bb.edx.r.l = x2;␊ |
836 | ␉bios(&bb);␊ |
837 | }␊ |
838 | ␊ |
839 | void clearScreenRows( int y1, int y2 )␊ |
840 | {␊ |
841 | ␉scollPage( 0, y1, 80 - 1, y2, 0x07, y2 - y1 + 1, 1 );␊ |
842 | }␊ |
843 | ␊ |
844 | void setActiveDisplayPage( int page )␊ |
845 | {␊ |
846 | ␉bb.intno = 0x10;␊ |
847 | ␉bb.eax.r.h = 5;␊ |
848 | ␉bb.eax.r.l = page;␊ |
849 | ␉bios(&bb);␊ |
850 | }␊ |
851 | ␊ |
852 | #if DEBUG␊ |
853 | ␊ |
854 | static int terminateDiskEmulation()␊ |
855 | {␊ |
856 | ␉static char cd_spec[0x13];␊ |
857 | ␊ |
858 | ␉bb.intno = 0x13;␊ |
859 | ␉bb.eax.r.h = 0x4b;␊ |
860 | ␉bb.eax.r.l = 0; // subfunc: terminate emulation ␊ |
861 | ␉bb.esi.rr = NORMALIZED_OFFSET((unsigned)&cd_spec);␊ |
862 | ␉bb.ds = NORMALIZED_SEGMENT((unsigned)&cd_spec);␊ |
863 | ␉bios(&bb);␊ |
864 | ␉return bb.eax.r.h;␊ |
865 | }␊ |
866 | ␊ |
867 | static int readDriveParameters(int drive, struct driveParameters *dp)␊ |
868 | {␊ |
869 | ␉bb.intno = 0x13;␊ |
870 | ␉bb.edx.r.l = drive;␊ |
871 | ␉bb.eax.r.h = 0x08;␊ |
872 | ␉bios(&bb);␊ |
873 | ␉if (bb.eax.r.h == 0) {␊ |
874 | ␉␉dp->heads = bb.edx.r.h;␊ |
875 | ␉␉dp->sectors = bb.ecx.r.l & 0x3F;␊ |
876 | ␉␉dp->cylinders = bb.ecx.r.h | ((bb.ecx.r.l & 0xC0) << 2);␊ |
877 | ␉␉dp->totalDrives = bb.edx.r.l;␊ |
878 | ␉} else {␊ |
879 | ␉␉bzero(dp, sizeof(*dp));␊ |
880 | ␉}␊ |
881 | ␉return bb.eax.r.h;␊ |
882 | }␊ |
883 | #endif␊ |
884 | ␊ |
885 | #ifdef APM_SUPPORT␊ |
886 | ␊ |
887 | #define APM_INTNO 0x15␊ |
888 | #define APM_INTCODE 0x53␊ |
889 | ␊ |
890 | int␊ |
891 | APMPresent(void)␊ |
892 | {␊ |
893 | ␉bb.intno = APM_INTNO;␊ |
894 | ␉bb.eax.r.h = APM_INTCODE;␊ |
895 | ␉bb.eax.r.l = 0x00;␊ |
896 | ␉bb.ebx.rr = 0x0000;␊ |
897 | ␉bios(&bb);␊ |
898 | ␉if ((bb.flags.cf == 0) && (bb.ebx.r.h == 'P') && (bb.ebx.r.l == 'M')) {␊ |
899 | ␉␉/* Success */␊ |
900 | ␉␉bootArgs->apmConfig.major_vers = bb.eax.r.h;␊ |
901 | ␉␉bootArgs->apmConfig.minor_vers = bb.eax.r.l;␊ |
902 | ␉␉bootArgs->apmConfig.flags.data = bb.ecx.rr;␊ |
903 | ␉␉return 1;␊ |
904 | ␉}␊ |
905 | ␉return 0;␊ |
906 | }␊ |
907 | ␊ |
908 | int␊ |
909 | APMConnect32(void)␊ |
910 | {␊ |
911 | ␉bb.intno = APM_INTNO;␊ |
912 | ␉bb.eax.r.h = APM_INTCODE;␊ |
913 | ␉bb.eax.r.l = 0x03;␊ |
914 | ␉bb.ebx.rr = 0x0000;␊ |
915 | ␉bios(&bb);␊ |
916 | ␉if (bb.flags.cf == 0) {␊ |
917 | ␉␉/* Success */␊ |
918 | ␉␉bootArgs->apmConfig.cs32_base = (bb.eax.rr) << 4;␊ |
919 | ␉␉bootArgs->apmConfig.entry_offset = bb.ebx.rx;␊ |
920 | ␉␉bootArgs->apmConfig.cs16_base = (bb.ecx.rr) << 4;␊ |
921 | ␉␉bootArgs->apmConfig.ds_base = (bb.edx.rr) << 4;␊ |
922 | ␉␉if (bootArgs->apmConfig.major_vers >= 1 && bootArgs->apmConfig.minor_vers >= 1) {␊ |
923 | ␉␉␉bootArgs->apmConfig.cs_length = bb.esi.rr;␊ |
924 | ␉␉␉bootArgs->apmConfig.ds_length = bb.edi.rr;␊ |
925 | ␉␉} else {␊ |
926 | ␉␉␉bootArgs->apmConfig.cs_length = ␊ |
927 | ␉␉␉bootArgs->apmConfig.ds_length = 64 * 1024;␊ |
928 | ␉␉}␊ |
929 | ␉␉bootArgs->apmConfig.connected = 1;␊ |
930 | ␉␉return 1;␊ |
931 | ␉}␊ |
932 | ␉return 0;␊ |
933 | }␊ |
934 | ␊ |
935 | #endif /* APM_SUPPORT */␊ |
936 | ␊ |
937 | #ifdef EISA_SUPPORT␊ |
938 | bool eisa_present(void)␊ |
939 | {␊ |
940 | ␉static bool checked = false;␊ |
941 | ␉static bool isEISA;␊ |
942 | ␊ |
943 | ␉if (!checked) {␊ |
944 | ␉␉if (strncmp((char *)0xfffd9, "EISA", 4) == 0) {␊ |
945 | ␉␉␉isEISA = true;␊ |
946 | ␉␉}␊ |
947 | ␉␉checked = true;␊ |
948 | ␉}␊ |
949 | ␉return (isEISA);␊ |
950 | }␊ |
951 | ␊ |
952 | int␊ |
953 | ReadEISASlotInfo(EISA_slot_info_t *ep, int slot)␊ |
954 | {␊ |
955 | ␉union␊ |
956 | ␉{␊ |
957 | ␉␉struct␊ |
958 | ␉␉{␊ |
959 | ␉␉␉unsigned char char2h :2;␊ |
960 | ␉␉␉unsigned char char1 :5;␊ |
961 | ␉␉␉unsigned char char3 :5;␊ |
962 | ␉␉␉unsigned char char2l :3;␊ |
963 | ␉␉␉unsigned char d2 :4;␊ |
964 | ␉␉␉unsigned char d1 :4;␊ |
965 | ␉␉␉unsigned char d4 :4;␊ |
966 | ␉␉␉unsigned char d3 :4;␊ |
967 | ␉␉} s;␊ |
968 | ␉␉unsigned char data[4];␊ |
969 | ␉} u;␊ |
970 | ␉static char hex[0x10] = "0123456789ABCDEF";␊ |
971 | ␊ |
972 | ␊ |
973 | ␉bb.intno = 0x15;␊ |
974 | ␉bb.eax.r.h = 0xd8;␊ |
975 | ␉bb.eax.r.l = 0x00;␊ |
976 | ␉bb.ecx.r.l = slot;␊ |
977 | ␉bios(&bb);␊ |
978 | ␉if (bb.flags.cf)␊ |
979 | ␉␉return bb.eax.r.h;␊ |
980 | ␉ep->u_ID.d = bb.eax.r.l;␊ |
981 | ␉ep->configMajor = bb.ebx.r.h;␊ |
982 | ␉ep->configMinor = bb.ebx.r.l;␊ |
983 | ␉ep->checksum = bb.ecx.rr;␊ |
984 | ␉ep->numFunctions = bb.edx.r.h;␊ |
985 | ␉ep->u_resources.d = bb.edx.r.l;␊ |
986 | ␉u.data[0] = bb.edi.r.l;␊ |
987 | ␉u.data[1] = bb.edi.r.h;␊ |
988 | ␉u.data[2] = bb.esi.r.l;␊ |
989 | ␉u.data[3] = bb.esi.r.h;␊ |
990 | ␉ep->id[0] = u.s.char1 + ('A' - 1);␊ |
991 | ␉ep->id[1] = (u.s.char2l | (u.s.char2h << 3)) + ('A' - 1);␊ |
992 | ␉ep->id[2] = u.s.char3 + ('A' - 1);␊ |
993 | ␉ep->id[3] = hex[u.s.d1];␊ |
994 | ␉ep->id[4] = hex[u.s.d2];␊ |
995 | ␉ep->id[5] = hex[u.s.d3];␊ |
996 | ␉ep->id[6] = hex[u.s.d4];␊ |
997 | ␉ep->id[7] = 0;␊ |
998 | ␉return 0;␊ |
999 | }␊ |
1000 | ␊ |
1001 | /*␊ |
1002 | * Note: ep must point to an address below 64k.␊ |
1003 | */␊ |
1004 | ␊ |
1005 | int␊ |
1006 | ReadEISAFuncInfo(EISA_func_info_t *ep, int slot, int function)␊ |
1007 | {␊ |
1008 | ␉bb.intno = 0x15;␊ |
1009 | ␉bb.eax.r.h = 0xd8;␊ |
1010 | ␉bb.eax.r.l = 0x01;␊ |
1011 | ␉bb.ecx.r.l = slot;␊ |
1012 | ␉bb.ecx.r.h = function;␊ |
1013 | ␉bb.esi.rr = (unsigned int)ep->data;␊ |
1014 | ␉bios(&bb);␊ |
1015 | ␉if (bb.eax.r.h == 0)␊ |
1016 | ␉{␊ |
1017 | ␉␉ep->slot = slot;␊ |
1018 | ␉␉ep->function = function;␊ |
1019 | ␉}␊ |
1020 | ␉return bb.eax.r.h;␊ |
1021 | }␊ |
1022 | #endif /* EISA_SUPPORT */␊ |
1023 | ␊ |
1024 | #if UNUSED␊ |
1025 | #define PCI_SIGNATURE 0x20494350 /* "PCI " */␊ |
1026 | ␊ |
1027 | int␊ |
1028 | ReadPCIBusInfo(PCI_bus_info_t *pp)␊ |
1029 | {␊ |
1030 | ␉bb.intno = 0x1a;␊ |
1031 | ␉bb.eax.r.h = 0xb1;␊ |
1032 | ␉bb.eax.r.l = 0x01;␊ |
1033 | ␉bios(&bb);␊ |
1034 | ␉if ((bb.eax.r.h == 0) && (bb.edx.rx == PCI_SIGNATURE))␊ |
1035 | ␉{␊ |
1036 | ␉␉pp->BIOSPresent = 1;␊ |
1037 | ␉␉pp->u_bus.d = bb.eax.r.l;␊ |
1038 | ␉␉pp->majorVersion = bb.ebx.r.h;␊ |
1039 | ␉␉pp->minorVersion = bb.ebx.r.l;␊ |
1040 | ␉␉pp->maxBusNum = bb.ecx.r.l;␊ |
1041 | ␉␉return 0;␊ |
1042 | ␉}␊ |
1043 | ␉return -1;␊ |
1044 | }␊ |
1045 | #endif␊ |
1046 | ␊ |
1047 | void sleep(int n)␊ |
1048 | {␊ |
1049 | ␉while (n >= 2048)␊ |
1050 | ␉{␊ |
1051 | ␉␉delay(2048000000);␊ |
1052 | ␉␉n -= 2048;␊ |
1053 | ␉}␊ |
1054 | ␉if (n > 0)␊ |
1055 | ␉{␊ |
1056 | ␉␉delay(n * 1000000);␊ |
1057 | ␉}␊ |
1058 | }␊ |
1059 | ␊ |
1060 | ␊ |
1061 | //==============================================================================␊ |
1062 | ␊ |
1063 | void delay(int us)␊ |
1064 | {␊ |
1065 | bb.intno = 0x15;␊ |
1066 | bb.eax.r.h = 0x86;␊ |
1067 | bb.ecx.rr = us >> 16;␊ |
1068 | bb.edx.rr = us & 0xFFFF;␊ |
1069 | bios(&bb);␊ |
1070 | }␊ |
1071 | /* // reverted from commit 2602␊ |
1072 | void enableA20(void)␊ |
1073 | {␊ |
1074 | bzero(&bb, sizeof bb); // Note: may be called before BSS section is initialized␊ |
1075 | bb.intno = 0x15;␊ |
1076 | bb.eax.rr = 0x2401;␊ |
1077 | bios(&bb);␊ |
1078 | // return !bb.flags.cf;␊ |
1079 | }␊ |
1080 | */␊ |
1081 |