system.c revision 94fde0b66aced35ee31b2218ab4371f2a48888c1
/*
* Copyright (C) 2006-2011 Oracle Corporation
*
* This file is part of VirtualBox Open Source Edition (OSE), as
* available from http://www.virtualbox.org. This file is free software;
* General Public License (GPL) as published by the Free Software
* Foundation, in version 2 as it comes in the "COPYING" file of the
* VirtualBox OSE distribution. VirtualBox OSE is distributed in the
* hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
* --------------------------------------------------------------------
*
* This code is based on:
*
*
* Copyright (C) 2002 MandrakeSoft S.A.
*
* MandrakeSoft S.A.
* 43, rue d'Aboukir
* 75002 Paris - France
*
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*
*/
#include <stdint.h>
#include "biosint.h"
#include "inlines.h"
#if DEBUG_INT15
#else
# define BX_DEBUG_INT15(...)
#endif
#define BX_CPU 3
extern int pmode_IDT;
extern int rmode_IDT;
#pragma aux pm_stack_save = \
".386" \
"push ds" \
"push eax" \
"xor eax, eax" \
"mov ds, ax" \
"mov ds:[467h], sp" \
"mov ds:[469h], ss" \
/* Uses position independent code... because it was too hard to figure
* out how to code the far call in inline assembler.
*/
void pm_enter(void);
".386p" \
"call pentry" \
"pentry:" \
"pop di" \
"add di, 1Bh" \
"push 20h" \
"push di" \
"lgdt fword ptr es:[si+8]" \
"lidt fword ptr cs:pmode_IDT" \
"mov eax, cr0" \
"or al, 1" \
"mov cr0, eax" \
"retf" \
"pm_pm:" \
"mov ax, 28h" \
"mov ss, ax" \
"mov ax, 10h" \
"mov ds, ax" \
"mov ax, 18h" \
"mov es, ax" \
void pm_copy(void);
"xor si, si" \
"xor di, di" \
"cld" \
"rep movsw" \
/* Restore segment limits to real mode compatible values and
* return to real mode.
*/
void pm_exit(void);
".386p" \
"call pexit" \
"pexit:" \
"pop ax" \
"push 0F000h" \
"add ax, 18h" \
"push ax" \
"mov ax, 28h" \
"mov ds, ax" \
"mov es, ax" \
"mov eax, cr0" \
"and al, 0FEh" \
"mov cr0, eax" \
"retf" \
"real_mode:" \
"lidt fword ptr cs:rmode_IDT" \
/* Restore stack and reload segment registers in real mode to ensure
* real mode compatible selector+base.
*/
void pm_stack_restore(void);
#pragma aux pm_stack_restore = \
".386" \
"xor ax, ax" \
"mov ds, ax" \
"mov es, ax" \
"lss sp, ds:[467h]" \
"pop eax" \
"pop ds" \
/* The pm_switch has a few crucial differences from pm_enter, hence
* it is replicated here. Uses LMSW to avoid trashing high word of eax.
*/
".286p" \
"call pentry" \
"pentry:" \
"pop di" \
"add di, 18h" \
"push 38h" \
"push di" \
"lgdt fword ptr es:[si+08h]" \
"lidt fword ptr es:[si+10h]" \
"mov ax, 1" \
"lmsw ax" \
"retf" \
"pm_pm:" \
"mov ax, 28h" \
"mov ss, ax" \
"mov ax, 18h" \
"mov ds, ax" \
"mov ax, 20h" \
"mov es, ax" \
/* Return to caller - we do not use IRET because we should not enable
* interrupts. Note that AH must be zero on exit.
* WARNING: Needs to be adapted if calling sequence is modified!
*/
".286" \
"mov sp, ax" \
"popa" \
"add sp, 6" \
"pop cx" \
"pop ax" \
"pop ax" \
"mov ax, 30h" \
"push ax" \
"push cx" \
"retf" \
// @todo: This method is silly. The RTC should be programmed to fire an interrupt
// instead of hogging the CPU with inaccurate code.
#pragma aux timer_wait = \
".386" \
"shl eax, 16" \
"mov ax, dx" \
"mov ebx, 15" \
"xor edx, edx" \
"div ebx" \
"mov ecx, eax" \
"in al, 61h" \
"and al, 10h" \
"mov ah, al" \
"or ecx, ecx" \
"je int1586_tick_end" \
"int1586_tick:" \
"in al, 61h" \
"and al, 10h" \
"cmp al, ah" \
"je int1586_tick" \
"mov ah, al" \
"dec ecx" \
"jnz int1586_tick" \
"int1586_tick_end:" \
{
// Use PS/2 System Control port A to set A20 enable
// get current setting first
// change A20 status
if (val)
else
return((oldval & 0x02) != 0);
}
typedef struct {
} mem_range_t;
{
extra_end -= extra_start;
}
// @todo: move elsewhere?
{
switch (GET_AH()) {
case 0x00: /* assorted functions */
if (GET_AL() != 0xc0)
goto undecoded;
/* GRUB calls int15 with ax=0x00c0 to get the ROM configuration table,
* which we don't support, but logging that event is annoying. In fact
* it is likely that they just misread some specs, because there is a
* int15 BIOS function AH=0xc0 which sounds quite similar to what GRUB
* wants to achieve. */
SET_CF();
break;
case 0x24: /* A20 Control */
switch (GET_AL()) {
case 0x00:
set_enable_a20(0);
CLEAR_CF();
SET_AH(0);
break;
case 0x01:
set_enable_a20(1);
CLEAR_CF();
SET_AH(0);
break;
case 0x02:
CLEAR_CF();
SET_AH(0);
break;
case 0x03:
CLEAR_CF();
SET_AH(0);
BX = 3;
break;
default:
SET_CF();
}
break;
case 0x41:
SET_CF();
break;
//@todo: Why does this need special handling? All we need is to set CF
// but not handle this as an unknown function (regardless of CPU type).
case 0x4f:
/* keyboard intercept */
#if BX_CPU < 2
#else
// nop
#endif
SET_CF();
break;
case 0x52: // removable media eject
CLEAR_CF();
SET_AH(0); // "ok ejection may proceed"
break;
case 0x83: {
if( GET_AL() ) {
// Set Interval requested.
// Interval not already set.
CLEAR_CF( );
} else {
// Interval already set.
BX_DEBUG_INT15("int15: Func 83h, failed, already waiting.\n" );
SET_CF();
}
} else if( GET_AL() == 1 ) {
// Clear Interval requested
CLEAR_CF( );
} else {
BX_DEBUG_INT15("int15: Func 83h, failed.\n" );
SET_CF();
}
break;
}
case 0x87:
#if BX_CPU < 3
SET_CF();
#endif
// +++ should probably have descriptor checks
// +++ should have exception handlers
// turn off interrupts
int_disable(); //@todo: aren't they disabled already?
// 128K max of transfer on 386+ ???
// source == destination ???
// ES:SI points to descriptor table
// offset use initially comments
// ==============================================
// 00..07 Unused zeros Null descriptor
// 08..0f GDT zeros filled in by BIOS
// 10..17 source ssssssss source of data
// 18..1f dest dddddddd destination of data
// 20..27 CS zeros filled in by BIOS
// 28..2f SS zeros filled in by BIOS
//es:si
//eeee0
//0ssss
//-----
// check for access rights of source & dest here
// Initialize GDT descriptor
base23_16++;
// Initialize CS descriptor
// Initialize SS descriptor
pm_enter();
pm_copy();
pm_exit();
// turn interrupts back on
int_enable();
SET_AH(0);
CLEAR_CF();
break;
case 0x88:
// Get the amount of extended memory (above 1M)
#if BX_CPU < 2
SET_CF();
#else
// According to Ralf Brown's interrupt the limit should be 15M,
// but real machines mostly return max. 63M.
if(AX > 0xffc0)
AX = 0xffc0;
CLEAR_CF();
#endif
break;
case 0x89:
// Switch to Protected Mode.
// ES:DI points to user-supplied GDT
// This subfunction does not return!
// turn off interrupts
int_disable(); //@todo: aren't they off already?
// Initialize CS descriptor for BIOS
/* Reprogram the PICs. */
/* Mask all IRQs, user must re-enable. */
break;
case 0x90:
/* Device busy interrupt. Called by Int 16h when no key available */
break;
case 0x91:
/* Interrupt complete. Called by Int 16h when key becomes available */
break;
case 0xbf:
BX_INFO("*** int 15h function AH=bf not yet supported!\n");
SET_CF();
break;
case 0xC0:
CLEAR_CF();
SET_AH(0);
ES = 0xF000;
break;
case 0xc1:
CLEAR_CF();
break;
case 0xd8:
SET_CF();
break;
/* Make the BIOS warning for pretty much every Linux kernel start
* disappear - it calls with ax=0xe980 to figure out SMI info. */
case 0xe9: /* SMI functions (SpeedStep and similar things) */
SET_CF();
break;
case 0xec: /* AMD64 target operating mode callback */
if (GET_AL() != 0)
goto undecoded;
SET_AH(0);
CLEAR_CF(); /* Accepted value. */
else
SET_CF(); /* Reserved, error. */
break;
default:
BX_INFO("*** int 15h function AX=%04x, BX=%04x not yet supported!\n",
SET_CF();
break;
}
}
{
switch (GET_AH()) {
case 0x86:
// Wait for CX:DX microseconds. currently using the
// refresh request port 0x61 bit4, toggling every 15usec
int_enable();
break;
case 0xe8:
switch(GET_AL()) {
case 0x20: // coded by osmaker aka K.J.
if(EDX == 0x534D4150) {
extended_memory_size <<= 8;
extended_memory_size *= 64;
#ifndef VBOX /* The following excludes 0xf0000000 thru 0xffffffff. Trust DevPcBios.cpp to get this right. */
// greater than EFF00000???
if(extended_memory_size > 0x3bc000) {
extended_memory_size = 0x3bc000; // everything after this is reserved memory until we get to 0x100000000
}
#endif /* !VBOX */
extended_memory_size *= 1024;
extended_memory_size <<= 8;
extended_memory_size *= 1024;
}
#ifdef VBOX /* We've already used the CMOS entries for SATA.
BTW. This is the amount of memory above 4GB measured in 64KB units. */
extra_lowbits_memory_size <<= 8;
extra_lowbits_memory_size <<= 16;
/* 0x64 and 0x65 can be used if we need to dig 1 TB or more at a later point. */
#else
extra_lowbits_memory_size <<= 8;
extra_lowbits_memory_size *= 64;
extra_lowbits_memory_size *= 1024;
#endif /* !VBOX */
mcfgStart = 0;
mcfgSize = 0;
switch(BX)
{
case 0:
#ifndef VBOX /** @todo Upstream suggests the following, needs checking. (see next as well) */
0x0000000L, 0x0009f000L, 0, 0, 1);
#else
0x0000000L, 0x0009fc00L, 0, 0, 1);
#endif
EBX = 1;
break;
case 1:
#ifndef VBOX /** @todo Upstream suggests the following, needs checking. (see next as well) */
0x0009f000L, 0x000a0000L, 0, 0, 2);
#else
0x0009fc00L, 0x000a0000L, 0, 0, 2);
#endif
EBX = 2;
break;
case 2:
#ifdef VBOX
/* Mark the BIOS as reserved. VBox doesn't currently
* use the 0xe0000-0xeffff area. It does use the
* 0xd0000-0xdffff area for the BIOS logo, but it's
* not worth marking it as reserved. (this is not
* true anymore because the VGA adapter handles the logo stuff)
* The whole 0xe0000-0xfffff can be used for the BIOS.
* Note that various
* Windows versions don't accept (read: in debug builds
* they trigger the "Too many similar traps" assertion)
* a single reserved range from 0xd0000 to 0xffffff.
* A 128K area starting from 0xd0000 works. */
0x000f0000L, 0x00100000L, 0, 0, 2);
#else /* !VBOX */
0x000e8000L, 0x00100000L, 0, 0, 2);
#endif /* !VBOX */
EBX = 3;
break;
case 3:
#if BX_ROMBIOS32 || defined(VBOX)
0x00100000L,
EBX = 4;
#else
0x00100000L,
extended_memory_size, 1);
EBX = 5;
#endif
break;
case 4:
EBX = 5;
break;
case 5:
/* 256KB BIOS area at the end of 4 GB */
#ifdef VBOX
/* We don't set the end to 1GB here and rely on the 32-bit
unsigned wrap around effect (0-0xfffc0000L). */
#endif
0xfffc0000L, 0x00000000L, 0, 0, 2);
if (mcfgStart != 0)
EBX = 6;
else
{
EBX = 7;
else
EBX = 0;
}
break;
case 6:
/* PCI MMIO config space (MCFG) */
EBX = 7;
else
EBX = 0;
break;
case 7:
#ifdef VBOX /* Don't succeeded if no memory above 4 GB. */
/* Mapping of memory above 4 GB if present.
Note: set_e820_range needs do no borrowing in the
subtraction because of the nice numbers. */
{
0x00000000L, extra_lowbits_memory_size,
EBX = 0;
}
break;
/* fall thru */
#else /* !VBOX */
/* Mapping of memory above 4 GB */
+ 1, 1);
EBX = 0;
break;
#endif /* !VBOX */
default: /* AX=E820, DX=534D4150, BX unrecognized */
goto int15_unimplemented;
break;
}
EAX = 0x534D4150;
ECX = 0x14;
CLEAR_CF();
} else {
// if DX != 0x534D4150)
goto int15_unimplemented;
}
break;
case 0x01:
// do we have any reason to fail here ?
CLEAR_CF();
// my real system sets ax and bx to 0
// this is confirmed by Ralph Brown list
// but syslinux v1.48 is known to behave
// strangely if ax is set to 0
// regs.u.r16.ax = 0;
// regs.u.r16.bx = 0;
// Get the amount of extended memory (above 1M)
// limit to 15M
if(CX > 0x3c00)
CX = 0x3c00;
// Get the amount of extended memory above 16M in 64k blocks
// Set configured memory equal to extended memory
break;
default: /* AH=0xE8?? but not implemented */
goto int15_unimplemented;
}
break;
// fall into the default case
default:
BX_INFO("*** int 15h function AX=%04x, BX=%04x not yet supported!\n",
SET_CF();
break;
}
}