VirtualBox

source: vbox/trunk/src/VBox/Devices/PC/BIOS/system.c@ 63495

Last change on this file since 63495 was 60887, checked in by vboxsync, 9 years ago

BIOS: Avoid 386-specific assembly in generic function.

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

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette