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