vbe.c revision 5bfd3ff4ec71e7a1dcbece7cf56c59177da30f99
// ============================================================================================
//
// Copyright (C) 2002 Jeroen Janssen
//
// 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
//
// ============================================================================================
//
// You can NOT drive any physical vga card with it.
//
// ============================================================================================
//
// This VBE Bios is based on information taken from :
// - VESA BIOS EXTENSION (VBE) Core Functions Standard Version 3.0 located at www.vesa.org
//
// ============================================================================================
/*
* Oracle LGPL Disclaimer: For the avoidance of doubt, except that if any license choice
* other than GPL or LGPL is available it will apply instead, Oracle elects to use only
* the Lesser General Public License version 2.1 (LGPLv2) at this time for any software where
* a choice of LGPL license versions is made available with the language indicating
* that LGPLv2 or any later version may be used, or where a choice of which version
* of the LGPL is applied is otherwise unspecified.
*/
// Use VBE new dynamic mode list. Note that without this option, no
// checks are currently done to make sure that modes fit into the
// framebuffer!
#define VBE_NEW_DYN_LIST
#include <inttypes.h>
#include <stddef.h>
#include "vbe.h"
#include "vgadefs.h"
#include "inlines.h"
//#define VBE2_NO_VESA_CHECK
// use bytewise i/o (Longhorn beta issue, not in released Vista)
//#define VBE_BYTEWISE_IO
#ifdef VBE_BYTEWISE_IO
extern void do_out_dx_ax();
"call do_out_dx_ax" \
extern void do_in_ax_dx();
"call do_in_ax_dx" \
#else
#endif
/* VESA signatures as integer constants. */
/* Implemented in assembler. */
extern void __cdecl vga_compat_setup(void);
extern void __cdecl dispi_set_bank_farcall(void);
// The current OEM Software Revision of this VBE Bios
#define VBE_OEM_SOFTWARE_REV 0x0003
// FIXME: 'merge' these (c) etc strings with the vgabios.c strings?
char vbebios_copyright[] = "VirtualBox VESA BIOS";
char vbebios_vendor_name[] = VBOX_VENDOR;
char vbebios_info_string[] = "VirtualBox VBE Display Adapter enabled\r\n\r\n";
char no_vbebios_info_string[] = "No VirtualBox VBE support available!\r\n\r\n";
#ifdef VGA_DEBUG
#endif
{
#ifdef VGA_DEBUG
#endif
}
{
#ifdef VGA_DEBUG
#endif
}
{
#ifdef VGA_DEBUG
#endif
}
{
}
#ifdef VBE_NEW_DYN_LIST
{
}
#endif
/* Display "chip" identification helpers. */
static uint16_t dispi_get_id(void)
{
return inw(VBE_DISPI_IOPORT_DATA);
}
{
}
/* VBE Init - Initialise the VESA BIOS Extension (VBE) support
* This function does a sanity check on the host side display code interface.
*/
void vbe_init(void)
{
if (dispi_get_id() == VBE_DISPI_ID0) {
/* VBE support was detected. */
}
#ifdef DEBUG_VGA
#endif
}
/* Find the offset of the desired mode, given its number. */
#ifdef VBE_NEW_DYN_LIST
{
/* Read and check the VBE Extra Data signature. */
if (sig != VBEHEADER_MAGIC) {
#ifdef DEBUG_VGA
#endif
return 0;
}
cur_info_ofs = sizeof(VBEHeader);
vmode = in_word(VBE_EXTRA_PORT, cur_info_ofs + offsetof(ModeInfoListItem, mode)/*&cur_info->mode*/);
while (vmode != VBE_VESA_MODE_END_OF_LIST)
{
attrs = in_word(VBE_EXTRA_PORT, /*&cur_info->info.ModeAttributes*/cur_info_ofs + offsetof(ModeInfoListItem, info.ModeAttributes) );
{
if (!using_lfb)
return cur_info_ofs;
else if (attrs & VBE_MODE_ATTRIBUTE_LINEAR_FRAME_BUFFER_MODE)
return cur_info_ofs;
else {
cur_info_ofs += sizeof(ModeInfoListItem);
vmode = in_word(VBE_EXTRA_PORT, /*&cur_info->mode*/cur_info_ofs + offsetof(ModeInfoListItem, mode));
}
} else {
cur_info_ofs += sizeof(ModeInfoListItem);
vmode = in_word(VBE_EXTRA_PORT, /*&cur_info->mode*/cur_info_ofs + offsetof(ModeInfoListItem, mode));
}
}
return 0;
}
#else
{
{
{
if (!using_lfb)
return cur_info;
return cur_info;
else
cur_info++;
} else
cur_info++;
}
return 0;
}
#endif
#ifndef VBOX
#endif
/** Function 00h - Return VBE Controller Information
*
* Input:
* AX = 4F00h
* ES:DI = Pointer to buffer in which to place VbeInfoBlock structure
* (VbeSignature should be VBE2 when VBE 2.0 information is desired and
* the info block is 512 bytes in size)
* Output:
* AX = VBE Return Status
*
*/
{
#ifdef VBE_NEW_DYN_LIST
#else
#endif
#ifdef VBE_NEW_DYN_LIST
/* Read VBE Extra Data signature */
if (sig != VBEHEADER_MAGIC)
{
*AX = 0x0100;
#ifdef DEBUG_VGA
printf("Signature NOT found\n");
#endif
return;
}
cur_info_ofs = sizeof(VBEHeader);
#endif
#ifdef VGA_DEBUG
#endif
vbe2_info = 0;
/* Don't use a local copy of VbeInfoBlock on the stack; it's too big.
* The Ubuntu 8.04 64 bits splash screen emulator can't handle this.
*/
#ifdef VBE2_NO_VESA_CHECK
#else /* !VBE2_NO_VESA_CHECK */
// check for VBE2 signature
{
vbe2_info = 1;
#ifdef VGA_DEBUG
#endif
}
#endif /* !VBE2_NO_VESA_CHECK */
/* VBE Signature - the compiler will optimize this into something sane. */
/* VBE Version supported. */
/* OEM String. */
/* Capabilities if this implementation. */
/* Video mode list pointer (dynamically generated). */
/* Total controller memory in 64K units. */
if (vbe2_info)
{
/* OEM information. */
}
#ifdef VBE_NEW_DYN_LIST
do
{
data_b = in_byte(VBE_EXTRA_PORT, cur_info_ofs + offsetof(ModeInfoListItem, info.BitsPerPixel) /*&cur_info->info.BitsPerPixel*/);
{
vmode = in_word(VBE_EXTRA_PORT, cur_info_ofs + offsetof(ModeInfoListItem, mode)/*&cur_info->mode*/);
#ifdef VGA_DEBUG
#endif
cur_mode++;
cur_ptr+=2;
}
cur_info_ofs += sizeof(ModeInfoListItem);
vmode = in_word(VBE_EXTRA_PORT, cur_info_ofs + offsetof(ModeInfoListItem, mode)/*&cur_info->mode*/);
} while (vmode != VBE_VESA_MODE_END_OF_LIST);
// Add vesa mode list terminator
#else
do
{
#ifdef VGA_DEBUG
#endif
cur_mode++;
cur_ptr += 2;
}
cur_info++;
// Add vesa mode list terminator
#endif // VBE_NEW_DYN_LIST
*AX = 0x004F;
}
/** Function 01h - Return VBE Mode Information
*
* Input:
* AX = 4F01h
* CX = Mode Number
* ES:DI = Pointer to buffer in which to place ModeInfoBlock structure
* Output:
* AX = VBE Return Status
*
*/
void vbe_biosfn_return_mode_information(uint16_t STACK_BASED *AX, uint16_t CX, uint16_t ES, uint16_t DI)
{
#ifdef VBE_NEW_DYN_LIST
#else
#endif
#ifdef VGA_DEBUG
#endif
#ifdef VBE_NEW_DYN_LIST
if (cur_info_ofs) {
uint16_t i;
#else
if (cur_info != 0) {
#endif
#ifdef VGA_DEBUG
#endif
#ifdef VBE_NEW_DYN_LIST
for (i = 0; i < sizeof(ModeInfoBlockCompact); i++) {
uint8_t b;
b = in_byte(VBE_EXTRA_PORT, cur_info_ofs + offsetof(ModeInfoListItem, info) + i/*(char *)(&(cur_info->info)) + i*/);
}
#else
#endif
if (win_attr & VBE_WINDOW_ATTRIBUTE_RELOCATABLE) {
// If BIOS not at 0xC000 -> boom
}
// Update the LFB physical address which may change at runtime
result = 0x4f;
} else {
#ifdef VGA_DEBUG
#endif
result = 0x100;
}
}
/** Function 02h - Set VBE Mode
*
* Input:
* AX = 4F02h
* BX = Desired Mode to set
* ES:DI = Pointer to CRTCInfoBlock structure
* Output:
* AX = VBE Return Status
*
*/
{
#ifdef VBE_NEW_DYN_LIST
#else
#endif
no_clear = ((BX & VBE_MODE_PRESERVE_DISPLAY_MEMORY) == VBE_MODE_PRESERVE_DISPLAY_MEMORY) ? VBE_DISPI_NOCLEARMEM : 0;
// check for non vesa mode
if (BX < VBE_MODE_VESA_DEFINED)
{
// call the vgabios in order to set the video mode
// this allows for going back to textmode with a VBE call (some applications expect that to work)
result = 0x4f;
goto leave;
}
#ifdef VBE_NEW_DYN_LIST
if (cur_info_ofs != 0)
{
xres = in_word(VBE_EXTRA_PORT, cur_info_ofs + offsetof(ModeInfoListItem, info.XResolution) /*&cur_info->info.XResolution*/);
yres = in_word(VBE_EXTRA_PORT, cur_info_ofs + offsetof(ModeInfoListItem, info.YResolution) /*&cur_info->info.YResolution*/);
bpp = in_byte(VBE_EXTRA_PORT, cur_info_ofs + offsetof(ModeInfoListItem, info.BitsPerPixel) /*&cur_info->info.BitsPerPixel*/);
#ifdef VGA_DEBUG
#endif
#else
if (cur_info != 0)
{
#ifdef VGA_DEBUG
printf("\txres%x yres%x bpp%x\n",
#endif
#endif // VBE_NEW_DYN_LIST
// first disable current mode (when switching between vesa modi)
#ifdef VBE_NEW_DYN_LIST
if (bpp == 4)
#else
#endif
{
biosfn_set_video_mode(0x6a);
}
#ifdef VBE_NEW_DYN_LIST
#else
#endif
dispi_set_bank(0);
result = 0x4f;
}
else
{
#ifdef VGA_DEBUG
#endif
result = 0x100;
}
}
{
return 9 * 2;
}
{
BX += 2;
if (!(enable & VBE_DISPI_ENABLED))
return;
for(i = VBE_DISPI_INDEX_XRES; i <= VBE_DISPI_INDEX_Y_OFFSET; i++) {
if (i != VBE_DISPI_INDEX_ENABLE) {
BX += 2;
}
}
}
{
BX += 2;
if (!(enable & VBE_DISPI_ENABLED)) {
} else {
BX += 2;
BX += 2;
BX += 2;
for(i = VBE_DISPI_INDEX_BANK; i <= VBE_DISPI_INDEX_Y_OFFSET; i++) {
BX += 2;
}
}
}
*
* Input:
* AX = 4F04h
* 01h Save State
* 02h Restore State
* CX = Requested states
* ES:BX = Pointer to buffer (if DL <> 00h)
* Output:
* AX = VBE Return Status
* BX = Number of 64-byte blocks to hold the state buffer (if DL=00h)
*
*/
{
result = 0x004F;
switch(GET_DL()) {
case 0x00:
#ifdef VGA_DEBUG
#endif
if (CX & 8)
break;
case 0x01:
#ifdef VGA_DEBUG
#endif
if (CX & 8)
break;
case 0x02:
#ifdef VGA_DEBUG
#endif
if (CX & 8)
break;
default:
// function failed
result = 0x100;
break;
}
}