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