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