1 | /*
|
---|
2 | * Copyright (C) 2006-2011 Oracle Corporation
|
---|
3 | *
|
---|
4 | * This file is part of VirtualBox Open Source Edition (OSE), as
|
---|
5 | * available from http://www.virtualbox.org. This file is free software;
|
---|
6 | * you can redistribute it and/or modify it under the terms of the GNU
|
---|
7 | * General Public License (GPL) as published by the Free Software
|
---|
8 | * Foundation, in version 2 as it comes in the "COPYING" file of the
|
---|
9 | * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
|
---|
10 | * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
|
---|
11 | * --------------------------------------------------------------------
|
---|
12 | *
|
---|
13 | * This code is based on:
|
---|
14 | *
|
---|
15 | * ROM BIOS for use with Bochs/Plex86/QEMU emulation environment
|
---|
16 | *
|
---|
17 | * Copyright (C) 2002 MandrakeSoft S.A.
|
---|
18 | *
|
---|
19 | * MandrakeSoft S.A.
|
---|
20 | * 43, rue d'Aboukir
|
---|
21 | * 75002 Paris - France
|
---|
22 | * http://www.linux-mandrake.com/
|
---|
23 | * http://www.mandrakesoft.com/
|
---|
24 | *
|
---|
25 | * This library is free software; you can redistribute it and/or
|
---|
26 | * modify it under the terms of the GNU Lesser General Public
|
---|
27 | * License as published by the Free Software Foundation; either
|
---|
28 | * version 2 of the License, or (at your option) any later version.
|
---|
29 | *
|
---|
30 | * This library is distributed in the hope that it will be useful,
|
---|
31 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
---|
32 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
---|
33 | * Lesser General Public License for more details.
|
---|
34 | *
|
---|
35 | * You should have received a copy of the GNU Lesser General Public
|
---|
36 | * License along with this library; if not, write to the Free Software
|
---|
37 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
---|
38 | *
|
---|
39 | */
|
---|
40 |
|
---|
41 |
|
---|
42 | #include <stdint.h>
|
---|
43 | #include "biosint.h"
|
---|
44 | #include "inlines.h"
|
---|
45 |
|
---|
46 | #if DEBUG_INT15
|
---|
47 | # define BX_DEBUG_INT15(...) BX_DEBUG(__VA_ARGS__)
|
---|
48 | #else
|
---|
49 | # define BX_DEBUG_INT15(...)
|
---|
50 | #endif
|
---|
51 |
|
---|
52 |
|
---|
53 | #define UNSUPPORTED_FUNCTION 0x86 /* Specific to INT 15h. */
|
---|
54 |
|
---|
55 | #define BIOS_CONFIG_TABLE 0xe6f5 /* TODO: configurable? put elsewhere? */
|
---|
56 |
|
---|
57 | #define ACPI_DATA_SIZE 0x00010000L /* TODO: configurable? put elsewhere? */
|
---|
58 |
|
---|
59 | #define BX_CPU 3
|
---|
60 |
|
---|
61 | extern int pmode_IDT;
|
---|
62 | extern int rmode_IDT;
|
---|
63 |
|
---|
64 | uint16_t read_ss(void);
|
---|
65 | #pragma aux read_ss = "mov ax, ss" modify exact [ax] nomemory;
|
---|
66 |
|
---|
67 | void pm_stack_save(uint16_t cx, uint16_t es, uint16_t si);
|
---|
68 | #pragma aux pm_stack_save = \
|
---|
69 | ".386" \
|
---|
70 | "push ds" \
|
---|
71 | "push eax" \
|
---|
72 | "xor eax, eax" \
|
---|
73 | "mov ds, ax" \
|
---|
74 | "mov ds:[467h], sp" \
|
---|
75 | "mov ds:[469h], ss" \
|
---|
76 | parm [cx] [es] [si] modify nomemory;
|
---|
77 |
|
---|
78 | /* Uses position independent code... because it was too hard to figure
|
---|
79 | * out how to code the far call in inline assembler.
|
---|
80 | */
|
---|
81 | void pm_enter(void);
|
---|
82 | #pragma aux pm_enter = \
|
---|
83 | ".386p" \
|
---|
84 | "call pentry" \
|
---|
85 | "pentry:" \
|
---|
86 | "pop di" \
|
---|
87 | "add di, 1Bh" \
|
---|
88 | "push 20h" \
|
---|
89 | "push di" \
|
---|
90 | "lgdt fword ptr es:[si+8]" \
|
---|
91 | "lidt fword ptr cs:pmode_IDT" \
|
---|
92 | "mov eax, cr0" \
|
---|
93 | "or al, 1" \
|
---|
94 | "mov cr0, eax" \
|
---|
95 | "retf" \
|
---|
96 | "pm_pm:" \
|
---|
97 | "mov ax, 28h" \
|
---|
98 | "mov ss, ax" \
|
---|
99 | "mov ax, 10h" \
|
---|
100 | "mov ds, ax" \
|
---|
101 | "mov ax, 18h" \
|
---|
102 | "mov es, ax" \
|
---|
103 | modify nomemory;
|
---|
104 |
|
---|
105 | void pm_copy(void);
|
---|
106 | #pragma aux pm_copy = \
|
---|
107 | "xor si, si" \
|
---|
108 | "xor di, di" \
|
---|
109 | "cld" \
|
---|
110 | "rep movsw" \
|
---|
111 | modify nomemory;
|
---|
112 |
|
---|
113 | /* Restore segment limits to real mode compatible values and
|
---|
114 | * return to real mode.
|
---|
115 | */
|
---|
116 | void pm_exit(void);
|
---|
117 | #pragma aux pm_exit = \
|
---|
118 | ".386p" \
|
---|
119 | "call pexit" \
|
---|
120 | "pexit:" \
|
---|
121 | "pop ax" \
|
---|
122 | "push 0F000h" \
|
---|
123 | "add ax, 18h" \
|
---|
124 | "push ax" \
|
---|
125 | "mov ax, 28h" \
|
---|
126 | "mov ds, ax" \
|
---|
127 | "mov es, ax" \
|
---|
128 | "mov eax, cr0" \
|
---|
129 | "and al, 0FEh" \
|
---|
130 | "mov cr0, eax" \
|
---|
131 | "retf" \
|
---|
132 | "real_mode:" \
|
---|
133 | "lidt fword ptr cs:rmode_IDT" \
|
---|
134 | modify nomemory;
|
---|
135 |
|
---|
136 | /* Restore stack and reload segment registers in real mode to ensure
|
---|
137 | * real mode compatible selector+base.
|
---|
138 | */
|
---|
139 | void pm_stack_restore(void);
|
---|
140 | #pragma aux pm_stack_restore = \
|
---|
141 | ".386" \
|
---|
142 | "xor ax, ax" \
|
---|
143 | "mov ds, ax" \
|
---|
144 | "mov es, ax" \
|
---|
145 | "lss sp, ds:[467h]" \
|
---|
146 | "pop eax" \
|
---|
147 | "pop ds" \
|
---|
148 | modify nomemory;
|
---|
149 |
|
---|
150 | /* The pm_switch has a few crucial differences from pm_enter, hence
|
---|
151 | * it is replicated here. Uses LMSW to avoid trashing high word of eax.
|
---|
152 | */
|
---|
153 | void pm_switch(uint16_t reg_si);
|
---|
154 | #pragma aux pm_switch = \
|
---|
155 | ".286p" \
|
---|
156 | "call pentry" \
|
---|
157 | "pentry:" \
|
---|
158 | "pop di" \
|
---|
159 | "add di, 18h" \
|
---|
160 | "push 38h" \
|
---|
161 | "push di" \
|
---|
162 | "lgdt fword ptr es:[si+08h]" \
|
---|
163 | "lidt fword ptr es:[si+10h]" \
|
---|
164 | "mov ax, 1" \
|
---|
165 | "lmsw ax" \
|
---|
166 | "retf" \
|
---|
167 | "pm_pm:" \
|
---|
168 | "mov ax, 28h" \
|
---|
169 | "mov ss, ax" \
|
---|
170 | "mov ax, 18h" \
|
---|
171 | "mov ds, ax" \
|
---|
172 | "mov ax, 20h" \
|
---|
173 | "mov es, ax" \
|
---|
174 | parm [si] modify nomemory;
|
---|
175 |
|
---|
176 | /* Return to caller - we do not use IRET because we should not enable
|
---|
177 | * interrupts. Note that AH must be zero on exit.
|
---|
178 | * WARNING: Needs to be adapted if calling sequence is modified!
|
---|
179 | */
|
---|
180 | void pm_unwind(uint16_t args);
|
---|
181 | #pragma aux pm_unwind = \
|
---|
182 | ".286" \
|
---|
183 | "mov sp, ax" \
|
---|
184 | "popa" \
|
---|
185 | "add sp, 6" \
|
---|
186 | "pop cx" \
|
---|
187 | "pop ax" \
|
---|
188 | "pop ax" \
|
---|
189 | "mov ax, 30h" \
|
---|
190 | "push ax" \
|
---|
191 | "push cx" \
|
---|
192 | "retf" \
|
---|
193 | parm [ax] modify nomemory aborts;
|
---|
194 |
|
---|
195 | // @todo: This method is silly. The RTC should be programmed to fire an interrupt
|
---|
196 | // instead of hogging the CPU with inaccurate code.
|
---|
197 | void timer_wait(uint16_t lo, uint16_t hi);
|
---|
198 | #pragma aux timer_wait = \
|
---|
199 | ".386" \
|
---|
200 | "shl eax, 16" \
|
---|
201 | "mov ax, dx" \
|
---|
202 | "mov ebx, 15" \
|
---|
203 | "xor edx, edx" \
|
---|
204 | "div ebx" \
|
---|
205 | "mov ecx, eax" \
|
---|
206 | "in al, 61h" \
|
---|
207 | "and al, 10h" \
|
---|
208 | "mov ah, al" \
|
---|
209 | "or ecx, ecx" \
|
---|
210 | "je int1586_tick_end" \
|
---|
211 | "int1586_tick:" \
|
---|
212 | "in al, 61h" \
|
---|
213 | "and al, 10h" \
|
---|
214 | "cmp al, ah" \
|
---|
215 | "je int1586_tick" \
|
---|
216 | "mov ah, al" \
|
---|
217 | "dec ecx" \
|
---|
218 | "jnz int1586_tick" \
|
---|
219 | "int1586_tick_end:" \
|
---|
220 | parm [dx] [ax] modify [bx cx] nomemory;
|
---|
221 |
|
---|
222 |
|
---|
223 | bx_bool set_enable_a20(bx_bool val)
|
---|
224 | {
|
---|
225 | uint8_t oldval;
|
---|
226 |
|
---|
227 | // Use PS/2 System Control port A to set A20 enable
|
---|
228 |
|
---|
229 | // get current setting first
|
---|
230 | oldval = inb(0x92);
|
---|
231 |
|
---|
232 | // change A20 status
|
---|
233 | if (val)
|
---|
234 | outb(0x92, oldval | 0x02);
|
---|
235 | else
|
---|
236 | outb(0x92, oldval & 0xfd);
|
---|
237 |
|
---|
238 | return((oldval & 0x02) != 0);
|
---|
239 | }
|
---|
240 |
|
---|
241 | typedef struct {
|
---|
242 | uint32_t start;
|
---|
243 | uint32_t xstart;
|
---|
244 | uint32_t len;
|
---|
245 | uint32_t xlen;
|
---|
246 | uint32_t type;
|
---|
247 | } mem_range_t;
|
---|
248 |
|
---|
249 | void set_e820_range(uint16_t ES, uint16_t DI, uint32_t start, uint32_t end,
|
---|
250 | uint8_t extra_start, uint8_t extra_end, uint16_t type)
|
---|
251 | {
|
---|
252 | mem_range_t __far *range;
|
---|
253 |
|
---|
254 | range = ES :> (mem_range_t *)DI;
|
---|
255 | range->start = start;
|
---|
256 | range->xstart = extra_start;
|
---|
257 | end -= start;
|
---|
258 | extra_end -= extra_start;
|
---|
259 | range->len = end;
|
---|
260 | range->xlen = extra_end;
|
---|
261 | range->type = type;
|
---|
262 | }
|
---|
263 |
|
---|
264 | // @todo: move elsewhere?
|
---|
265 | #define AX r.gr.u.r16.ax
|
---|
266 | #define BX r.gr.u.r16.bx
|
---|
267 | #define CX r.gr.u.r16.cx
|
---|
268 | #define DX r.gr.u.r16.dx
|
---|
269 | #define SI r.gr.u.r16.si
|
---|
270 | #define DI r.gr.u.r16.di
|
---|
271 | #define BP r.gr.u.r16.bp
|
---|
272 | #define SP r.gr.u.r16.sp
|
---|
273 | #define FLAGS r.fl.u.r16.flags
|
---|
274 | #define EAX r.gr.u.r32.eax
|
---|
275 | #define EBX r.gr.u.r32.ebx
|
---|
276 | #define ECX r.gr.u.r32.ecx
|
---|
277 | #define EDX r.gr.u.r32.edx
|
---|
278 | #define ES r.es
|
---|
279 |
|
---|
280 |
|
---|
281 | void BIOSCALL int15_function(sys_regs_t r)
|
---|
282 | {
|
---|
283 | bx_bool prev_a20_enable;
|
---|
284 | uint16_t base15_00;
|
---|
285 | uint8_t base23_16;
|
---|
286 | uint16_t ss;
|
---|
287 | uint16_t bRegister;
|
---|
288 | uint8_t irqDisable;
|
---|
289 |
|
---|
290 | BX_DEBUG_INT15("int15 AX=%04x\n",AX);
|
---|
291 |
|
---|
292 | switch (GET_AH()) {
|
---|
293 | case 0x00: /* assorted functions */
|
---|
294 | if (GET_AL() != 0xc0)
|
---|
295 | goto undecoded;
|
---|
296 | /* GRUB calls int15 with ax=0x00c0 to get the ROM configuration table,
|
---|
297 | * which we don't support, but logging that event is annoying. In fact
|
---|
298 | * it is likely that they just misread some specs, because there is a
|
---|
299 | * int15 BIOS function AH=0xc0 which sounds quite similar to what GRUB
|
---|
300 | * wants to achieve. */
|
---|
301 | SET_CF();
|
---|
302 | SET_AH(UNSUPPORTED_FUNCTION);
|
---|
303 | break;
|
---|
304 | case 0x24: /* A20 Control */
|
---|
305 | switch (GET_AL()) {
|
---|
306 | case 0x00:
|
---|
307 | set_enable_a20(0);
|
---|
308 | CLEAR_CF();
|
---|
309 | SET_AH(0);
|
---|
310 | break;
|
---|
311 | case 0x01:
|
---|
312 | set_enable_a20(1);
|
---|
313 | CLEAR_CF();
|
---|
314 | SET_AH(0);
|
---|
315 | break;
|
---|
316 | case 0x02:
|
---|
317 | SET_AL( (inb(0x92) >> 1) & 0x01 );
|
---|
318 | CLEAR_CF();
|
---|
319 | SET_AH(0);
|
---|
320 | break;
|
---|
321 | case 0x03:
|
---|
322 | CLEAR_CF();
|
---|
323 | SET_AH(0);
|
---|
324 | BX = 3;
|
---|
325 | break;
|
---|
326 | default:
|
---|
327 | BX_INFO("int15: Func 24h, subfunc %02xh, A20 gate control not supported\n", (unsigned) GET_AL());
|
---|
328 | SET_CF();
|
---|
329 | SET_AH(UNSUPPORTED_FUNCTION);
|
---|
330 | }
|
---|
331 | break;
|
---|
332 |
|
---|
333 | case 0x41:
|
---|
334 | SET_CF();
|
---|
335 | SET_AH(UNSUPPORTED_FUNCTION);
|
---|
336 | break;
|
---|
337 |
|
---|
338 | //@todo: Why does this need special handling? All we need is to set CF
|
---|
339 | // but not handle this as an unknown function (regardless of CPU type).
|
---|
340 | case 0x4f:
|
---|
341 | /* keyboard intercept */
|
---|
342 | #if BX_CPU < 2
|
---|
343 | SET_AH(UNSUPPORTED_FUNCTION);
|
---|
344 | #else
|
---|
345 | // nop
|
---|
346 | #endif
|
---|
347 | SET_CF();
|
---|
348 | break;
|
---|
349 |
|
---|
350 | case 0x52: // removable media eject
|
---|
351 | CLEAR_CF();
|
---|
352 | SET_AH(0); // "ok ejection may proceed"
|
---|
353 | break;
|
---|
354 |
|
---|
355 | case 0x83: {
|
---|
356 | if( GET_AL() ) {
|
---|
357 | // Set Interval requested.
|
---|
358 | if( ( read_byte( 0x40, 0xA0 ) & 1 ) == 0 ) {
|
---|
359 | // Interval not already set.
|
---|
360 | write_byte( 0x40, 0xA0, 1 ); // Set status byte.
|
---|
361 | write_word( 0x40, 0x98, ES ); // Byte location, segment
|
---|
362 | write_word( 0x40, 0x9A, BX ); // Byte location, offset
|
---|
363 | write_word( 0x40, 0x9C, DX ); // Low word, delay
|
---|
364 | write_word( 0x40, 0x9E, CX ); // High word, delay.
|
---|
365 | CLEAR_CF( );
|
---|
366 | irqDisable = inb( 0xA1 );
|
---|
367 | outb( 0xA1, irqDisable & 0xFE );
|
---|
368 | bRegister = inb_cmos( 0xB ); // Unmask IRQ8 so INT70 will get through.
|
---|
369 | outb_cmos( 0xB, bRegister | 0x40 ); // Turn on the Periodic Interrupt timer
|
---|
370 | } else {
|
---|
371 | // Interval already set.
|
---|
372 | BX_DEBUG_INT15("int15: Func 83h, failed, already waiting.\n" );
|
---|
373 | SET_CF();
|
---|
374 | SET_AH(UNSUPPORTED_FUNCTION);
|
---|
375 | }
|
---|
376 | } else if( GET_AL() == 1 ) {
|
---|
377 | // Clear Interval requested
|
---|
378 | write_byte( 0x40, 0xA0, 0 ); // Clear status byte
|
---|
379 | CLEAR_CF( );
|
---|
380 | bRegister = inb_cmos( 0xB );
|
---|
381 | outb_cmos( 0xB, bRegister & ~0x40 ); // Turn off the Periodic Interrupt timer
|
---|
382 | } else {
|
---|
383 | BX_DEBUG_INT15("int15: Func 83h, failed.\n" );
|
---|
384 | SET_CF();
|
---|
385 | SET_AH(UNSUPPORTED_FUNCTION);
|
---|
386 | SET_AL(GET_AL() - 1);
|
---|
387 | }
|
---|
388 |
|
---|
389 | break;
|
---|
390 | }
|
---|
391 |
|
---|
392 | case 0x87:
|
---|
393 | #if BX_CPU < 3
|
---|
394 | SET_AH(UNSUPPORTED_FUNCTION);
|
---|
395 | SET_CF();
|
---|
396 | #endif
|
---|
397 | // +++ should probably have descriptor checks
|
---|
398 | // +++ should have exception handlers
|
---|
399 |
|
---|
400 | // turn off interrupts
|
---|
401 | int_disable(); //@todo: aren't they disabled already?
|
---|
402 |
|
---|
403 | prev_a20_enable = set_enable_a20(1); // enable A20 line
|
---|
404 |
|
---|
405 | // 128K max of transfer on 386+ ???
|
---|
406 | // source == destination ???
|
---|
407 |
|
---|
408 | // ES:SI points to descriptor table
|
---|
409 | // offset use initially comments
|
---|
410 | // ==============================================
|
---|
411 | // 00..07 Unused zeros Null descriptor
|
---|
412 | // 08..0f GDT zeros filled in by BIOS
|
---|
413 | // 10..17 source ssssssss source of data
|
---|
414 | // 18..1f dest dddddddd destination of data
|
---|
415 | // 20..27 CS zeros filled in by BIOS
|
---|
416 | // 28..2f SS zeros filled in by BIOS
|
---|
417 |
|
---|
418 | //es:si
|
---|
419 | //eeee0
|
---|
420 | //0ssss
|
---|
421 | //-----
|
---|
422 |
|
---|
423 | // check for access rights of source & dest here
|
---|
424 |
|
---|
425 | // Initialize GDT descriptor
|
---|
426 | base15_00 = (ES << 4) + SI;
|
---|
427 | base23_16 = ES >> 12;
|
---|
428 | if (base15_00 < (ES<<4))
|
---|
429 | base23_16++;
|
---|
430 | write_word(ES, SI+0x08+0, 47); // limit 15:00 = 6 * 8bytes/descriptor
|
---|
431 | write_word(ES, SI+0x08+2, base15_00);// base 15:00
|
---|
432 | write_byte(ES, SI+0x08+4, base23_16);// base 23:16
|
---|
433 | write_byte(ES, SI+0x08+5, 0x93); // access
|
---|
434 | write_word(ES, SI+0x08+6, 0x0000); // base 31:24/reserved/limit 19:16
|
---|
435 |
|
---|
436 | // Initialize CS descriptor
|
---|
437 | write_word(ES, SI+0x20+0, 0xffff);// limit 15:00 = normal 64K limit
|
---|
438 | write_word(ES, SI+0x20+2, 0x0000);// base 15:00
|
---|
439 | write_byte(ES, SI+0x20+4, 0x000f);// base 23:16
|
---|
440 | write_byte(ES, SI+0x20+5, 0x9b); // access
|
---|
441 | write_word(ES, SI+0x20+6, 0x0000);// base 31:24/reserved/limit 19:16
|
---|
442 |
|
---|
443 | // Initialize SS descriptor
|
---|
444 | ss = read_ss();
|
---|
445 | base15_00 = ss << 4;
|
---|
446 | base23_16 = ss >> 12;
|
---|
447 | write_word(ES, SI+0x28+0, 0xffff); // limit 15:00 = normal 64K limit
|
---|
448 | write_word(ES, SI+0x28+2, base15_00);// base 15:00
|
---|
449 | write_byte(ES, SI+0x28+4, base23_16);// base 23:16
|
---|
450 | write_byte(ES, SI+0x28+5, 0x93); // access
|
---|
451 | write_word(ES, SI+0x28+6, 0x0000); // base 31:24/reserved/limit 19:16
|
---|
452 |
|
---|
453 | pm_stack_save(CX, ES, SI);
|
---|
454 | pm_enter();
|
---|
455 | pm_copy();
|
---|
456 | pm_exit();
|
---|
457 | pm_stack_restore();
|
---|
458 |
|
---|
459 | set_enable_a20(prev_a20_enable);
|
---|
460 |
|
---|
461 | // turn interrupts back on
|
---|
462 | int_enable();
|
---|
463 |
|
---|
464 | SET_AH(0);
|
---|
465 | CLEAR_CF();
|
---|
466 | break;
|
---|
467 |
|
---|
468 | case 0x88:
|
---|
469 | // Get the amount of extended memory (above 1M)
|
---|
470 | #if BX_CPU < 2
|
---|
471 | SET_AH(UNSUPPORTED_FUNCTION);
|
---|
472 | SET_CF();
|
---|
473 | #else
|
---|
474 | AX = (inb_cmos(0x31) << 8) | inb_cmos(0x30);
|
---|
475 |
|
---|
476 | // According to Ralf Brown's interrupt the limit should be 15M,
|
---|
477 | // but real machines mostly return max. 63M.
|
---|
478 | if(AX > 0xffc0)
|
---|
479 | AX = 0xffc0;
|
---|
480 |
|
---|
481 | CLEAR_CF();
|
---|
482 | #endif
|
---|
483 | break;
|
---|
484 |
|
---|
485 | case 0x89:
|
---|
486 | // Switch to Protected Mode.
|
---|
487 | // ES:DI points to user-supplied GDT
|
---|
488 | // BH/BL contains starting interrupt numbers for PIC0/PIC1
|
---|
489 | // This subfunction does not return!
|
---|
490 |
|
---|
491 | // turn off interrupts
|
---|
492 | int_disable(); //@todo: aren't they off already?
|
---|
493 |
|
---|
494 | set_enable_a20(1); // enable A20 line; we're supposed to fail if that fails
|
---|
495 |
|
---|
496 | // Initialize CS descriptor for BIOS
|
---|
497 | write_word(ES, SI+0x38+0, 0xffff);// limit 15:00 = normal 64K limit
|
---|
498 | write_word(ES, SI+0x38+2, 0x0000);// base 15:00
|
---|
499 | write_byte(ES, SI+0x38+4, 0x000f);// base 23:16 (hardcoded to f000:0000)
|
---|
500 | write_byte(ES, SI+0x38+5, 0x9b); // access
|
---|
501 | write_word(ES, SI+0x38+6, 0x0000);// base 31:24/reserved/limit 19:16
|
---|
502 |
|
---|
503 | /* Reprogram the PICs. */
|
---|
504 | outb(PIC_MASTER, PIC_CMD_INIT);
|
---|
505 | outb(PIC_SLAVE, PIC_CMD_INIT);
|
---|
506 | outb(PIC_MASTER + 1, GET_BH());
|
---|
507 | outb(PIC_SLAVE + 1, GET_BL());
|
---|
508 | outb(PIC_MASTER + 1, 4);
|
---|
509 | outb(PIC_SLAVE + 1, 2);
|
---|
510 | outb(PIC_MASTER + 1, 1);
|
---|
511 | outb(PIC_SLAVE + 1, 1);
|
---|
512 | /* Mask all IRQs, user must re-enable. */
|
---|
513 | outb(PIC_MASTER_MASK, 0xff);
|
---|
514 | outb(PIC_SLAVE_MASK, 0xff);
|
---|
515 |
|
---|
516 | pm_switch(SI);
|
---|
517 | pm_unwind((uint16_t)&r);
|
---|
518 |
|
---|
519 | break;
|
---|
520 |
|
---|
521 | case 0x90:
|
---|
522 | /* Device busy interrupt. Called by Int 16h when no key available */
|
---|
523 | break;
|
---|
524 |
|
---|
525 | case 0x91:
|
---|
526 | /* Interrupt complete. Called by Int 16h when key becomes available */
|
---|
527 | break;
|
---|
528 |
|
---|
529 | case 0xbf:
|
---|
530 | BX_INFO("*** int 15h function AH=bf not yet supported!\n");
|
---|
531 | SET_CF();
|
---|
532 | SET_AH(UNSUPPORTED_FUNCTION);
|
---|
533 | break;
|
---|
534 |
|
---|
535 | case 0xC0:
|
---|
536 | CLEAR_CF();
|
---|
537 | SET_AH(0);
|
---|
538 | BX = BIOS_CONFIG_TABLE;
|
---|
539 | ES = 0xF000;
|
---|
540 | break;
|
---|
541 |
|
---|
542 | case 0xc1:
|
---|
543 | ES = read_word(0x0040, 0x000E);
|
---|
544 | CLEAR_CF();
|
---|
545 | break;
|
---|
546 |
|
---|
547 | case 0xd8:
|
---|
548 | bios_printf(BIOS_PRINTF_DEBUG, "EISA BIOS not present\n");
|
---|
549 | SET_CF();
|
---|
550 | SET_AH(UNSUPPORTED_FUNCTION);
|
---|
551 | break;
|
---|
552 |
|
---|
553 | /* Make the BIOS warning for pretty much every Linux kernel start
|
---|
554 | * disappear - it calls with ax=0xe980 to figure out SMI info. */
|
---|
555 | case 0xe9: /* SMI functions (SpeedStep and similar things) */
|
---|
556 | SET_CF();
|
---|
557 | SET_AH(UNSUPPORTED_FUNCTION);
|
---|
558 | break;
|
---|
559 | case 0xec: /* AMD64 target operating mode callback */
|
---|
560 | if (GET_AL() != 0)
|
---|
561 | goto undecoded;
|
---|
562 | SET_AH(0);
|
---|
563 | if (GET_BL() >= 1 && GET_BL() <= 3)
|
---|
564 | CLEAR_CF(); /* Accepted value. */
|
---|
565 | else
|
---|
566 | SET_CF(); /* Reserved, error. */
|
---|
567 | break;
|
---|
568 | undecoded:
|
---|
569 | default:
|
---|
570 | BX_INFO("*** int 15h function AX=%04x, BX=%04x not yet supported!\n",
|
---|
571 | (unsigned) AX, (unsigned) BX);
|
---|
572 | SET_CF();
|
---|
573 | SET_AH(UNSUPPORTED_FUNCTION);
|
---|
574 | break;
|
---|
575 | }
|
---|
576 | }
|
---|
577 |
|
---|
578 | void BIOSCALL int15_function32(sys32_regs_t r)
|
---|
579 | {
|
---|
580 | uint32_t extended_memory_size=0; // 64bits long
|
---|
581 | uint32_t extra_lowbits_memory_size=0;
|
---|
582 | uint8_t extra_highbits_memory_size=0;
|
---|
583 | uint32_t mcfgStart, mcfgSize;
|
---|
584 |
|
---|
585 | BX_DEBUG_INT15("int15 AX=%04x\n",AX);
|
---|
586 |
|
---|
587 | switch (GET_AH()) {
|
---|
588 | case 0x86:
|
---|
589 | // Wait for CX:DX microseconds. currently using the
|
---|
590 | // refresh request port 0x61 bit4, toggling every 15usec
|
---|
591 | int_enable();
|
---|
592 | timer_wait(DX, CX);
|
---|
593 | break;
|
---|
594 |
|
---|
595 | case 0xe8:
|
---|
596 | switch(GET_AL()) {
|
---|
597 | case 0x20: // coded by osmaker aka K.J.
|
---|
598 | if(EDX == 0x534D4150) {
|
---|
599 | extended_memory_size = inb_cmos(0x35);
|
---|
600 | extended_memory_size <<= 8;
|
---|
601 | extended_memory_size |= inb_cmos(0x34);
|
---|
602 | extended_memory_size *= 64;
|
---|
603 | #ifndef VBOX /* The following excludes 0xf0000000 thru 0xffffffff. Trust DevPcBios.cpp to get this right. */
|
---|
604 | // greater than EFF00000???
|
---|
605 | if(extended_memory_size > 0x3bc000) {
|
---|
606 | extended_memory_size = 0x3bc000; // everything after this is reserved memory until we get to 0x100000000
|
---|
607 | }
|
---|
608 | #endif /* !VBOX */
|
---|
609 | extended_memory_size *= 1024;
|
---|
610 | extended_memory_size += (16L * 1024 * 1024);
|
---|
611 |
|
---|
612 | if(extended_memory_size <= (16L * 1024 * 1024)) {
|
---|
613 | extended_memory_size = inb_cmos(0x31);
|
---|
614 | extended_memory_size <<= 8;
|
---|
615 | extended_memory_size |= inb_cmos(0x30);
|
---|
616 | extended_memory_size *= 1024;
|
---|
617 | extended_memory_size += (1L * 1024 * 1024);
|
---|
618 | }
|
---|
619 |
|
---|
620 | #ifdef VBOX /* We've already used the CMOS entries for SATA.
|
---|
621 | BTW. This is the amount of memory above 4GB measured in 64KB units. */
|
---|
622 | extra_lowbits_memory_size = inb_cmos(0x62);
|
---|
623 | extra_lowbits_memory_size <<= 8;
|
---|
624 | extra_lowbits_memory_size |= inb_cmos(0x61);
|
---|
625 | extra_lowbits_memory_size <<= 16;
|
---|
626 | extra_highbits_memory_size = inb_cmos(0x63);
|
---|
627 | /* 0x64 and 0x65 can be used if we need to dig 1 TB or more at a later point. */
|
---|
628 | #else
|
---|
629 | extra_lowbits_memory_size = inb_cmos(0x5c);
|
---|
630 | extra_lowbits_memory_size <<= 8;
|
---|
631 | extra_lowbits_memory_size |= inb_cmos(0x5b);
|
---|
632 | extra_lowbits_memory_size *= 64;
|
---|
633 | extra_lowbits_memory_size *= 1024;
|
---|
634 | extra_highbits_memory_size = inb_cmos(0x5d);
|
---|
635 | #endif /* !VBOX */
|
---|
636 |
|
---|
637 | mcfgStart = 0;
|
---|
638 | mcfgSize = 0;
|
---|
639 |
|
---|
640 | switch(BX)
|
---|
641 | {
|
---|
642 | case 0:
|
---|
643 | set_e820_range(ES, DI,
|
---|
644 | #ifndef VBOX /** @todo Upstream suggests the following, needs checking. (see next as well) */
|
---|
645 | 0x0000000L, 0x0009f000L, 0, 0, 1);
|
---|
646 | #else
|
---|
647 | 0x0000000L, 0x0009fc00L, 0, 0, 1);
|
---|
648 | #endif
|
---|
649 | EBX = 1;
|
---|
650 | break;
|
---|
651 | case 1:
|
---|
652 | set_e820_range(ES, DI,
|
---|
653 | #ifndef VBOX /** @todo Upstream suggests the following, needs checking. (see next as well) */
|
---|
654 | 0x0009f000L, 0x000a0000L, 0, 0, 2);
|
---|
655 | #else
|
---|
656 | 0x0009fc00L, 0x000a0000L, 0, 0, 2);
|
---|
657 | #endif
|
---|
658 | EBX = 2;
|
---|
659 | break;
|
---|
660 | case 2:
|
---|
661 | #ifdef VBOX
|
---|
662 | /* Mark the BIOS as reserved. VBox doesn't currently
|
---|
663 | * use the 0xe0000-0xeffff area. It does use the
|
---|
664 | * 0xd0000-0xdffff area for the BIOS logo, but it's
|
---|
665 | * not worth marking it as reserved. (this is not
|
---|
666 | * true anymore because the VGA adapter handles the logo stuff)
|
---|
667 | * The whole 0xe0000-0xfffff can be used for the BIOS.
|
---|
668 | * Note that various
|
---|
669 | * Windows versions don't accept (read: in debug builds
|
---|
670 | * they trigger the "Too many similar traps" assertion)
|
---|
671 | * a single reserved range from 0xd0000 to 0xffffff.
|
---|
672 | * A 128K area starting from 0xd0000 works. */
|
---|
673 | set_e820_range(ES, DI,
|
---|
674 | 0x000f0000L, 0x00100000L, 0, 0, 2);
|
---|
675 | #else /* !VBOX */
|
---|
676 | set_e820_range(ES, DI,
|
---|
677 | 0x000e8000L, 0x00100000L, 0, 0, 2);
|
---|
678 | #endif /* !VBOX */
|
---|
679 | EBX = 3;
|
---|
680 | break;
|
---|
681 | case 3:
|
---|
682 | #if BX_ROMBIOS32 || defined(VBOX)
|
---|
683 | set_e820_range(ES, DI,
|
---|
684 | 0x00100000L,
|
---|
685 | extended_memory_size - ACPI_DATA_SIZE, 0, 0, 1);
|
---|
686 | EBX = 4;
|
---|
687 | #else
|
---|
688 | set_e820_range(ES, DI,
|
---|
689 | 0x00100000L,
|
---|
690 | extended_memory_size, 1);
|
---|
691 | EBX = 5;
|
---|
692 | #endif
|
---|
693 | break;
|
---|
694 | case 4:
|
---|
695 | set_e820_range(ES, DI,
|
---|
696 | extended_memory_size - ACPI_DATA_SIZE,
|
---|
697 | extended_memory_size, 0, 0, 3); // ACPI RAM
|
---|
698 | EBX = 5;
|
---|
699 | break;
|
---|
700 | case 5:
|
---|
701 | /* 256KB BIOS area at the end of 4 GB */
|
---|
702 | #ifdef VBOX
|
---|
703 | /* We don't set the end to 1GB here and rely on the 32-bit
|
---|
704 | unsigned wrap around effect (0-0xfffc0000L). */
|
---|
705 | #endif
|
---|
706 | set_e820_range(ES, DI,
|
---|
707 | 0xfffc0000L, 0x00000000L, 0, 0, 2);
|
---|
708 | if (mcfgStart != 0)
|
---|
709 | EBX = 6;
|
---|
710 | else
|
---|
711 | {
|
---|
712 | if (extra_highbits_memory_size || extra_lowbits_memory_size)
|
---|
713 | EBX = 7;
|
---|
714 | else
|
---|
715 | EBX = 0;
|
---|
716 | }
|
---|
717 | break;
|
---|
718 | case 6:
|
---|
719 | /* PCI MMIO config space (MCFG) */
|
---|
720 | set_e820_range(ES, DI,
|
---|
721 | mcfgStart, mcfgStart + mcfgSize, 0, 0, 2);
|
---|
722 |
|
---|
723 | if (extra_highbits_memory_size || extra_lowbits_memory_size)
|
---|
724 | EBX = 7;
|
---|
725 | else
|
---|
726 | EBX = 0;
|
---|
727 | break;
|
---|
728 | case 7:
|
---|
729 | #ifdef VBOX /* Don't succeeded if no memory above 4 GB. */
|
---|
730 | /* Mapping of memory above 4 GB if present.
|
---|
731 | Note: set_e820_range needs do no borrowing in the
|
---|
732 | subtraction because of the nice numbers. */
|
---|
733 | if (extra_highbits_memory_size || extra_lowbits_memory_size)
|
---|
734 | {
|
---|
735 | set_e820_range(ES, DI,
|
---|
736 | 0x00000000L, extra_lowbits_memory_size,
|
---|
737 | 1 /*GB*/, extra_highbits_memory_size + 1 /*GB*/, 1);
|
---|
738 | EBX = 0;
|
---|
739 | }
|
---|
740 | break;
|
---|
741 | /* fall thru */
|
---|
742 | #else /* !VBOX */
|
---|
743 | /* Mapping of memory above 4 GB */
|
---|
744 | set_e820_range(ES, DI, 0x00000000L,
|
---|
745 | extra_lowbits_memory_size, 1, extra_highbits_memory_size
|
---|
746 | + 1, 1);
|
---|
747 | EBX = 0;
|
---|
748 | break;
|
---|
749 | #endif /* !VBOX */
|
---|
750 | default: /* AX=E820, DX=534D4150, BX unrecognized */
|
---|
751 | goto int15_unimplemented;
|
---|
752 | break;
|
---|
753 | }
|
---|
754 | EAX = 0x534D4150;
|
---|
755 | ECX = 0x14;
|
---|
756 | CLEAR_CF();
|
---|
757 | } else {
|
---|
758 | // if DX != 0x534D4150)
|
---|
759 | goto int15_unimplemented;
|
---|
760 | }
|
---|
761 | break;
|
---|
762 |
|
---|
763 | case 0x01:
|
---|
764 | // do we have any reason to fail here ?
|
---|
765 | CLEAR_CF();
|
---|
766 |
|
---|
767 | // my real system sets ax and bx to 0
|
---|
768 | // this is confirmed by Ralph Brown list
|
---|
769 | // but syslinux v1.48 is known to behave
|
---|
770 | // strangely if ax is set to 0
|
---|
771 | // regs.u.r16.ax = 0;
|
---|
772 | // regs.u.r16.bx = 0;
|
---|
773 |
|
---|
774 | // Get the amount of extended memory (above 1M)
|
---|
775 | CX = (inb_cmos(0x31) << 8) | inb_cmos(0x30);
|
---|
776 |
|
---|
777 | // limit to 15M
|
---|
778 | if(CX > 0x3c00)
|
---|
779 | CX = 0x3c00;
|
---|
780 |
|
---|
781 | // Get the amount of extended memory above 16M in 64k blocks
|
---|
782 | DX = (inb_cmos(0x35) << 8) | inb_cmos(0x34);
|
---|
783 |
|
---|
784 | // Set configured memory equal to extended memory
|
---|
785 | AX = CX;
|
---|
786 | BX = DX;
|
---|
787 | break;
|
---|
788 | default: /* AH=0xE8?? but not implemented */
|
---|
789 | goto int15_unimplemented;
|
---|
790 | }
|
---|
791 | break;
|
---|
792 | int15_unimplemented:
|
---|
793 | // fall into the default case
|
---|
794 | default:
|
---|
795 | BX_INFO("*** int 15h function AX=%04x, BX=%04x not yet supported!\n",
|
---|
796 | (unsigned) AX, (unsigned) BX);
|
---|
797 | SET_CF();
|
---|
798 | SET_AL(UNSUPPORTED_FUNCTION);
|
---|
799 | break;
|
---|
800 | }
|
---|
801 | }
|
---|