Skip to content

Commit

Permalink
x86, setup: "glove box" BIOS interrupts in the video code
Browse files Browse the repository at this point in the history
Impact: BIOS proofing

"Glove box" off BIOS interrupts in the video code.

LKML-Reference: <49DE7F79.4030106@zytor.com>
Signed-off-by: H. Peter Anvin <hpa@linux.intel.com>
Cc: Pavel Machek <pavel@ucw.cz>
Cc: Rafael J. Wysocki <rjw@sisk.pl>
  • Loading branch information
H. Peter Anvin authored and H. Peter Anvin committed Apr 9, 2009
1 parent 0a706db commit cf06de7
Show file tree
Hide file tree
Showing 5 changed files with 151 additions and 164 deletions.
27 changes: 13 additions & 14 deletions arch/x86/boot/video-bios.c
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
*
* Copyright (C) 1991, 1992 Linus Torvalds
* Copyright 2007 rPath, Inc. - All Rights Reserved
* Copyright 2009 Intel Corporation; author H. Peter Anvin
*
* This file is part of the Linux kernel, and is made available under
* the terms of the GNU General Public License version 2.
Expand Down Expand Up @@ -29,21 +30,21 @@ static int bios_set_mode(struct mode_info *mi)

static int set_bios_mode(u8 mode)
{
u16 ax;
struct biosregs ireg, oreg;
u8 new_mode;

ax = mode; /* AH=0x00 Set Video Mode */
asm volatile(INT10
: "+a" (ax)
: : "ebx", "ecx", "edx", "esi", "edi");
initregs(&ireg);
ireg.al = mode; /* AH=0x00 Set Video Mode */
intcall(0x10, &ireg, NULL);

ax = 0x0f00; /* Get Current Video Mode */
asm volatile(INT10
: "+a" (ax)
: : "ebx", "ecx", "edx", "esi", "edi");

ireg.ah = 0x0f; /* Get Current Video Mode */
intcall(0x10, &ireg, &oreg);

do_restore = 1; /* Assume video contents were lost */
new_mode = ax & 0x7f; /* Not all BIOSes are clean with the top bit */

/* Not all BIOSes are clean with the top bit */
new_mode = ireg.al & 0x7f;

if (new_mode == mode)
return 0; /* Mode change OK */
Expand All @@ -53,10 +54,8 @@ static int set_bios_mode(u8 mode)
/* Mode setting failed, but we didn't end up where we
started. That's bad. Try to revert to the original
video mode. */
ax = boot_params.screen_info.orig_video_mode;
asm volatile(INT10
: "+a" (ax)
: : "ebx", "ecx", "edx", "esi", "edi");
ireg.ax = boot_params.screen_info.orig_video_mode;
intcall(0x10, &ireg, NULL);
}
#endif
return -1;
Expand Down
137 changes: 60 additions & 77 deletions arch/x86/boot/video-vesa.c
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
*
* Copyright (C) 1991, 1992 Linus Torvalds
* Copyright 2007 rPath, Inc. - All Rights Reserved
* Copyright 2009 Intel Corporation; author H. Peter Anvin
*
* This file is part of the Linux kernel, and is made available under
* the terms of the GNU General Public License version 2.
Expand Down Expand Up @@ -31,21 +32,20 @@ static inline void vesa_store_mode_params_graphics(void) {}
static int vesa_probe(void)
{
#if defined(CONFIG_VIDEO_VESA) || defined(CONFIG_FIRMWARE_EDID)
u16 ax, cx, di;
struct biosregs ireg, oreg;
u16 mode;
addr_t mode_ptr;
struct mode_info *mi;
int nmodes = 0;

video_vesa.modes = GET_HEAP(struct mode_info, 0);

ax = 0x4f00;
di = (size_t)&vginfo;
asm(INT10
: "+a" (ax), "+D" (di), "=m" (vginfo)
: : "ebx", "ecx", "edx", "esi");
initregs(&ireg);
ireg.ax = 0x4f00;
ireg.di = (size_t)&vginfo;
intcall(0x10, &ireg, &oreg);

if (ax != 0x004f ||
if (ireg.ax != 0x004f ||
vginfo.signature != VESA_MAGIC ||
vginfo.version < 0x0102)
return 0; /* Not present */
Expand All @@ -65,14 +65,12 @@ static int vesa_probe(void)

memset(&vminfo, 0, sizeof vminfo); /* Just in case... */

ax = 0x4f01;
cx = mode;
di = (size_t)&vminfo;
asm(INT10
: "+a" (ax), "+c" (cx), "+D" (di), "=m" (vminfo)
: : "ebx", "edx", "esi");
ireg.ax = 0x4f01;
ireg.cx = mode;
ireg.di = (size_t)&vminfo;
intcall(0x10, &ireg, &oreg);

if (ax != 0x004f)
if (ireg.ax != 0x004f)
continue;

if ((vminfo.mode_attr & 0x15) == 0x05) {
Expand Down Expand Up @@ -111,20 +109,19 @@ static int vesa_probe(void)

static int vesa_set_mode(struct mode_info *mode)
{
u16 ax, bx, cx, di;
struct biosregs ireg, oreg;
int is_graphic;
u16 vesa_mode = mode->mode - VIDEO_FIRST_VESA;

memset(&vminfo, 0, sizeof vminfo); /* Just in case... */

ax = 0x4f01;
cx = vesa_mode;
di = (size_t)&vminfo;
asm(INT10
: "+a" (ax), "+c" (cx), "+D" (di), "=m" (vminfo)
: : "ebx", "edx", "esi");
initregs(&ireg);
ireg.ax = 0x4f01;
ireg.cx = vesa_mode;
ireg.di = (size_t)&vminfo;
intcall(0x10, &ireg, &oreg);

if (ax != 0x004f)
if (oreg.ax != 0x004f)
return -1;

if ((vminfo.mode_attr & 0x15) == 0x05) {
Expand All @@ -141,14 +138,12 @@ static int vesa_set_mode(struct mode_info *mode)
}


ax = 0x4f02;
bx = vesa_mode;
di = 0;
asm volatile(INT10
: "+a" (ax), "+b" (bx), "+D" (di)
: : "ecx", "edx", "esi");
initregs(&ireg);
ireg.ax = 0x4f02;
ireg.bx = vesa_mode;
intcall(0x10, &ireg, &oreg);

if (ax != 0x004f)
if (oreg.ax != 0x004f)
return -1;

graphic_mode = is_graphic;
Expand All @@ -171,50 +166,45 @@ static int vesa_set_mode(struct mode_info *mode)
/* Switch DAC to 8-bit mode */
static void vesa_dac_set_8bits(void)
{
struct biosregs ireg, oreg;
u8 dac_size = 6;

/* If possible, switch the DAC to 8-bit mode */
if (vginfo.capabilities & 1) {
u16 ax, bx;

ax = 0x4f08;
bx = 0x0800;
asm volatile(INT10
: "+a" (ax), "+b" (bx)
: : "ecx", "edx", "esi", "edi");

if (ax == 0x004f)
dac_size = bx >> 8;
initregs(&ireg);
ireg.ax = 0x4f08;
ireg.bh = 0x08;
intcall(0x10, &ireg, &oreg);
if (oreg.ax == 0x004f)
dac_size = oreg.bh;
}

/* Set the color sizes to the DAC size, and offsets to 0 */
boot_params.screen_info.red_size = dac_size;
boot_params.screen_info.red_size = dac_size;
boot_params.screen_info.green_size = dac_size;
boot_params.screen_info.blue_size = dac_size;
boot_params.screen_info.rsvd_size = dac_size;
boot_params.screen_info.blue_size = dac_size;
boot_params.screen_info.rsvd_size = dac_size;

boot_params.screen_info.red_pos = 0;
boot_params.screen_info.green_pos = 0;
boot_params.screen_info.blue_pos = 0;
boot_params.screen_info.rsvd_pos = 0;
boot_params.screen_info.red_pos = 0;
boot_params.screen_info.green_pos = 0;
boot_params.screen_info.blue_pos = 0;
boot_params.screen_info.rsvd_pos = 0;
}

/* Save the VESA protected mode info */
static void vesa_store_pm_info(void)
{
u16 ax, bx, di, es;
struct biosregs ireg, oreg;

ax = 0x4f0a;
bx = di = 0;
asm("pushw %%es; "INT10"; movw %%es,%0; popw %%es"
: "=d" (es), "+a" (ax), "+b" (bx), "+D" (di)
: : "ecx", "esi");
initregs(&ireg);
ireg.ax = 0x4f0a;
intcall(0x10, &ireg, &oreg);

if (ax != 0x004f)
if (oreg.ax != 0x004f)
return;

boot_params.screen_info.vesapm_seg = es;
boot_params.screen_info.vesapm_off = di;
boot_params.screen_info.vesapm_seg = oreg.es;
boot_params.screen_info.vesapm_off = oreg.di;
}

/*
Expand Down Expand Up @@ -252,41 +242,34 @@ static void vesa_store_mode_params_graphics(void)
void vesa_store_edid(void)
{
#ifdef CONFIG_FIRMWARE_EDID
u16 ax, bx, cx, dx, di;
struct biosregs ireg, oreg;

/* Apparently used as a nonsense token... */
memset(&boot_params.edid_info, 0x13, sizeof boot_params.edid_info);

if (vginfo.version < 0x0200)
return; /* EDID requires VBE 2.0+ */

ax = 0x4f15; /* VBE DDC */
bx = 0x0000; /* Report DDC capabilities */
cx = 0; /* Controller 0 */
di = 0; /* ES:DI must be 0 by spec */

/* Note: The VBE DDC spec is different from the main VESA spec;
we genuinely have to assume all registers are destroyed here. */

asm("pushw %%es; movw %2,%%es; "INT10"; popw %%es"
: "+a" (ax), "+b" (bx), "+c" (cx), "+D" (di)
: : "esi", "edx");
initregs(&ireg);
ireg.ax = 0x4f15; /* VBE DDC */
/* ireg.bx = 0x0000; */ /* Report DDC capabilities */
/* ireg.cx = 0; */ /* Controller 0 */
ireg.es = 0; /* ES:DI must be 0 by spec */
intcall(0x10, &ireg, &oreg);

if (ax != 0x004f)
if (oreg.ax != 0x004f)
return; /* No EDID */

/* BH = time in seconds to transfer EDD information */
/* BL = DDC level supported */

ax = 0x4f15; /* VBE DDC */
bx = 0x0001; /* Read EDID */
cx = 0; /* Controller 0 */
dx = 0; /* EDID block number */
di =(size_t) &boot_params.edid_info; /* (ES:)Pointer to block */
asm(INT10
: "+a" (ax), "+b" (bx), "+d" (dx), "=m" (boot_params.edid_info),
"+c" (cx), "+D" (di)
: : "esi");
ireg.ax = 0x4f15; /* VBE DDC */
ireg.bx = 0x0001; /* Read EDID */
/* ireg.cx = 0; */ /* Controller 0 */
/* ireg.dx = 0; */ /* EDID block number */
ireg.es = ds();
ireg.di =(size_t)&boot_params.edid_info; /* (ES:)Pointer to block */
intcall(0x10, &ireg, &oreg);
#endif /* CONFIG_FIRMWARE_EDID */
}

Expand Down
Loading

0 comments on commit cf06de7

Please sign in to comment.