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