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