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