logo.c revision 198b40cdcd5b9fb744dceda00e1b429c6bb611ae
/* $Id$ */
/** @file
* Stuff for drawing the BIOS logo.
*/
/*
* Copyright (C) 2004-2012 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.
*/
#include <stdint.h>
#include "biosint.h"
#include "inlines.h"
#include "ebda.h"
#define WAIT_HZ 64
#define WAIT_MS 16
#define F12_SCAN_CODE 0x86
#include <VBox/bioslogo.h>
/**
* Set video mode (VGA).
* @params New video mode.
*/
"mov ah, 0" \
"int 10h" \
/**
* Set VESA video mode.
* @params New video mode.
*/
#pragma aux vesa_set_mode = \
"mov ax, 4F02h" \
"int 10h" \
/**
* Get current VESA video mode.
* @params New video mode.
*/
#pragma aux vesa_get_mode = \
"mov ax, 4F03h" \
"int 10h" \
"mov es:[di], bx" \
/**
* Check for keystroke.
* @returns True if keystroke available, False if not.
*/
//@todo: INT 16h should already be returning the right value in al; could also use setz
uint8_t check_for_keystroke(void);
#pragma aux check_for_keystroke = \
"mov ax, 100h" \
"int 16h" \
"jz no_key" \
"mov al, 1" \
"jmp done" \
"no_key:" \
"xor al, al" \
"done:" \
/**
* Get keystroke.
* @returns BIOS scan code.
*/
uint8_t get_keystroke(void);
#pragma aux get_keystroke = \
"xor ax, ax" \
"int 16h" \
"xchg ah, al" \
//@todo: This whole business with reprogramming the PIT is rather suspect.
// The BIOS already has waiting facilities in INT 15h (fn 83h, 86h) which
// should be utilized instead.
// Set the timer to 16ms ticks (64K / (Hz / (PIT_HZ / 64K)) = count).
void wait_init(void);
"mov al, 34h" \
"out 43h, al" \
"mov al, 0D3h" \
"out 40h, al" \
"mov al, 048h" \
"out 40h, al" \
//@todo: using this private interface is not great
extern void rtc_post(void);
/* Restore the timer to the default 18.2Hz. Reinitialize the tick
* and rollover counts since we've screwed them up by running the
* timer at WAIT_HZ for a while.
*/
void wait_uninit(void);
#pragma aux wait_uninit = \
".386" \
"mov al, 34h" \
"out 43h, al" \
"xor ax, ax" \
"out 40h, al" \
"out 40h, al" \
"pushad" \
"push ds" \
"mov ds, ax" \
"call rtc_post" \
"pop ds" \
"popad" \
/**
* Waits (sleeps) for the given number of ticks.
* Checks for keystroke.
*
* @returns BIOS scan code if available, 0 if not.
* @param ticks Number of ticks to sleep.
* @param stop_on_key Whether to stop immediately upon keypress.
*/
{
long ticks_to_wait, delta;
uint32_t prev_ticks, t;
/*
* We may or may not be called with interrupts disabled. For the duration
* of this function, interrupts must be enabled.
*/
int_enable();
/*
* The 0:046c wraps around at 'midnight' according to a 18.2Hz clock.
* We also have to be careful about interrupt storms.
*/
do
{
halt();
if (t > prev_ticks)
{
ticks_to_wait -= delta;
}
else if (t < prev_ticks)
ticks_to_wait -= t; /* wrapped */
prev_ticks = t;
if (check_for_keystroke())
{
scan_code = get_keystroke();
if (stop_on_key)
return scan_code;
}
} while (ticks_to_wait > 0);
return scan_code;
}
{
return inb(LOGO_IO_PORT);
}
{
return inw(LOGO_IO_PORT);
}
// Hide cursor, clear screen and move cursor to starting position
void clear_screen(void);
#pragma aux clear_screen = \
"mov ax, 100h" \
"mov cx, 1000h" \
"int 10h" \
"mov ax, 700h" \
"mov bh, 7" \
"xor cx, cx" \
"mov dx, 184Fh" \
"int 10h" \
"mov ax, 200h" \
"xor bx, bx" \
"xor dx, dx" \
"int 10h" \
void print_detected_harddisks(void)
{
uint8_t ide_ctrl_printed = 0;
uint8_t sata_ctrl_printed = 0;
uint8_t scsi_ctrl_printed = 0;
{
#ifdef VBOX_WITH_AHCI
if (VBOX_IS_AHCI_DEVICE(device))
{
if (sata_ctrl_printed == 0)
{
printf("\n\n AHCI controller:");
sata_ctrl_printed = 1;
}
}
else
#endif
#ifdef VBOX_WITH_SCSI
if (VBOX_IS_SCSI_DEVICE(device))
{
if (scsi_ctrl_printed == 0)
{
printf("\n\n SCSI controller:");
scsi_ctrl_printed = 1;
}
}
else
#endif
{
{
printf(" IDE controller:");
ide_ctrl_printed = 1;
}
{
printf("\n\nAHCI controller:\n");
sata_ctrl_printed = 1;
}
/*
* If actual_device is bigger than or equal 4
* this is the next controller and
* the positions start at the beginning.
*/
if (device >= 4)
device -= 4;
if (device / 2)
printf("Secondary ");
else
printf("Primary ");
if (device % 2)
printf("Slave");
else
printf("Master");
}
}
if ( (ide_ctrl_printed == 0)
&& (sata_ctrl_printed == 0)
&& (scsi_ctrl_printed == 0))
printf("No hard disks found");
printf("\n");
}
{
/* Check that the scan code is in the range of detected hard disks. */
/* The key '1' has scancode 0x02 which represents the first disk */
scode -= 2;
return scode;
/* Scancode is higher than number of available devices */
return 0xff;
}
void show_logo(void)
{
uint8_t f12_pressed = 0;
// Set PIT to 1ms ticks
wait_init();
// Get main signature
if (tmp != 0x66BB)
goto done;
// If there is no VBE, just skip this
goto done;
// Get options
// Is Logo disabled?
goto done;
// Set video mode #0x142 640x480x32bpp
vesa_set_mode(0x142);
if (is_fade_in)
{
for (i = 0; i <= LOGO_SHOW_STEPS; i++)
{
if (scode == F12_SCAN_CODE)
{
f12_pressed = 1;
break;
}
}
}
else
// Wait (interval in milliseconds)
if (!f12_pressed)
{
if (scode == F12_SCAN_CODE)
f12_pressed = 1;
}
// Fade out (only if F12 was not pressed)
if (is_fade_out && !f12_pressed)
{
for (i = LOGO_SHOW_STEPS; i > 0 ; i--)
{
if (scode == F12_SCAN_CODE)
{
f12_pressed = 1;
break;
}
}
}
done:
// Clear forced boot drive setting.
// Don't restore previous video mode
// The default text mode should be set up. (defect @bugref{1235})
set_mode(0x0003);
// If Setup menu enabled
if (uBootMenu)
{
// If the graphics logo disabled
{
if (uBootMenu == 2)
printf("Press F12 to select boot device.\n");
// if the user has pressed F12 don't wait here
if (!f12_pressed)
{
// Wait for timeout or keystroke
if (scode == F12_SCAN_CODE)
f12_pressed = 1;
}
}
// If F12 pressed, show boot menu
if (f12_pressed)
{
uint8_t boot_device = 0;
uint8_t boot_drive = 0;
clear_screen();
// Show menu. Note that some versions of bcc freak out if we split these strings.
printf("\nVirtualBox temporary boot device selection\n\nDetected Hard disks:\n\n");
printf("\nOther boot devices:\n f) Floppy\n c) CD-ROM\n l) LAN\n\n b) Continue booting\n");
// Wait for keystroke
for (;;)
{
do
{
} while (scode == 0);
if (scode == 0x30)
{
// 'b' ... continue
break;
}
// Check if hard disk was selected
{
/*
* 0xff indicates that there is no mapping
* from the scan code to a hard drive.
* Wait for next keystroke.
*/
if (boot_drive == 0xff)
continue;
boot_device = 0x02;
break;
}
switch (scode)
{
case 0x21:
// Floppy
boot_device = 0x01;
break;
case 0x2e:
// CD-ROM
boot_device = 0x03;
break;
case 0x26:
// LAN
boot_device = 0x04;
break;
}
if (boot_device != 0)
break;
}
// Switch to text mode. Clears screen and enables cursor again.
set_mode(0x0003);
}
}
// Restore PIT ticks
wait_uninit();
return;
}
{
uint16_t i;
if (!secs)
return;
// Set PIT to 1ms ticks
wait_init();
for (i = secs; i > 0; i--)
{
printf(" %d", i);
}
printf("\n");
// Restore PIT ticks
wait_uninit();
}