Commit d54ea252 authored by H. Peter Anvin's avatar H. Peter Anvin Committed by H. Peter Anvin

x86, setup: "glove box" BIOS interrupts in the APM code

Impact: BIOS proofing

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

LKML-Reference: <49DE7F79.4030106@zytor.com>
Signed-off-by: default avatarH. Peter Anvin <hpa@linux.intel.com>
Cc: Stephen Rothwell <sfr@canb.auug.org.au>
parent df7699c5
...@@ -2,6 +2,7 @@ ...@@ -2,6 +2,7 @@
* *
* Copyright (C) 1991, 1992 Linus Torvalds * Copyright (C) 1991, 1992 Linus Torvalds
* Copyright 2007 rPath, Inc. - All Rights Reserved * Copyright 2007 rPath, Inc. - All Rights Reserved
* Copyright 2009 Intel Corporation; author H. Peter Anvin
* *
* Original APM BIOS checking by Stephen Rothwell, May 1994 * Original APM BIOS checking by Stephen Rothwell, May 1994
* (sfr@canb.auug.org.au) * (sfr@canb.auug.org.au)
...@@ -19,75 +20,56 @@ ...@@ -19,75 +20,56 @@
int query_apm_bios(void) int query_apm_bios(void)
{ {
u16 ax, bx, cx, dx, di; struct biosregs ireg, oreg;
u32 ebx, esi;
u8 err;
/* APM BIOS installation check */ /* APM BIOS installation check */
ax = 0x5300; initregs(&ireg);
bx = cx = 0; ireg.ah = 0x53;
asm volatile("pushl %%ebp ; int $0x15 ; popl %%ebp ; setc %0" intcall(0x15, &ireg, &oreg);
: "=d" (err), "+a" (ax), "+b" (bx), "+c" (cx)
: : "esi", "edi");
if (err) if (oreg.flags & X86_EFLAGS_CF)
return -1; /* No APM BIOS */ return -1; /* No APM BIOS */
if (bx != 0x504d) /* "PM" signature */ if (oreg.bx != 0x504d) /* "PM" signature */
return -1; return -1;
if (!(cx & 0x02)) /* 32 bits supported? */ if (!(oreg.cx & 0x02)) /* 32 bits supported? */
return -1; return -1;
/* Disconnect first, just in case */ /* Disconnect first, just in case */
ax = 0x5304; ireg.al = 0x04;
bx = 0; intcall(0x15, &ireg, NULL);
asm volatile("pushl %%ebp ; int $0x15 ; popl %%ebp"
: "+a" (ax), "+b" (bx)
: : "ecx", "edx", "esi", "edi");
/* Paranoia */
ebx = esi = 0;
cx = dx = di = 0;
/* 32-bit connect */ /* 32-bit connect */
asm volatile("pushl %%ebp ; int $0x15 ; popl %%ebp ; setc %6" ireg.al = 0x03;
: "=a" (ax), "+b" (ebx), "+c" (cx), "+d" (dx), intcall(0x15, &ireg, &oreg);
"+S" (esi), "+D" (di), "=m" (err)
: "a" (0x5303)); boot_params.apm_bios_info.cseg = oreg.ax;
boot_params.apm_bios_info.offset = oreg.ebx;
boot_params.apm_bios_info.cseg = ax; boot_params.apm_bios_info.cseg_16 = oreg.cx;
boot_params.apm_bios_info.offset = ebx; boot_params.apm_bios_info.dseg = oreg.dx;
boot_params.apm_bios_info.cseg_16 = cx; boot_params.apm_bios_info.cseg_len = oreg.si;
boot_params.apm_bios_info.dseg = dx; boot_params.apm_bios_info.cseg_16_len = oreg.hsi;
boot_params.apm_bios_info.cseg_len = (u16)esi; boot_params.apm_bios_info.dseg_len = oreg.di;
boot_params.apm_bios_info.cseg_16_len = esi >> 16;
boot_params.apm_bios_info.dseg_len = di; if (oreg.flags & X86_EFLAGS_CF)
if (err)
return -1; return -1;
/* Redo the installation check as the 32-bit connect; /* Redo the installation check as the 32-bit connect;
some BIOSes return different flags this way... */ some BIOSes return different flags this way... */
ax = 0x5300; ireg.al = 0x00;
bx = cx = 0; intcall(0x15, &ireg, &oreg);
asm volatile("pushl %%ebp ; int $0x15 ; popl %%ebp ; setc %0"
: "=d" (err), "+a" (ax), "+b" (bx), "+c" (cx)
: : "esi", "edi");
if (err || bx != 0x504d) { if ((oreg.eflags & X86_EFLAGS_CF) || oreg.bx != 0x504d) {
/* Failure with 32-bit connect, try to disconect and ignore */ /* Failure with 32-bit connect, try to disconect and ignore */
ax = 0x5304; ireg.al = 0x04;
bx = 0; intcall(0x15, &ireg, NULL);
asm volatile("pushl %%ebp ; int $0x15 ; popl %%ebp"
: "+a" (ax), "+b" (bx)
: : "ecx", "edx", "esi", "edi");
return -1; return -1;
} }
boot_params.apm_bios_info.version = ax; boot_params.apm_bios_info.version = oreg.ax;
boot_params.apm_bios_info.flags = cx; boot_params.apm_bios_info.flags = oreg.cx;
return 0; return 0;
} }
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment