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

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

Impact: BIOS proofing

"Glove box" off BIOS interrupts in the core boot code.

LKML-Reference: <49DE7F79.4030106@zytor.com>
Signed-off-by: default avatarH. Peter Anvin <hpa@linux.intel.com>
parent 7a734e7d
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
* *
* Copyright (C) 1991, 1992 Linus Torvalds * Copyright (C) 1991, 1992 Linus Torvalds
* Copyright 2007-2008 rPath, Inc. - All Rights Reserved * Copyright 2007-2008 rPath, Inc. - All Rights Reserved
* Copyright 2009 Intel Corporation * Copyright 2009 Intel Corporation; author H. Peter Anvin
* *
* This file is part of the Linux kernel, and is made available under * This file is part of the Linux kernel, and is made available under
* the terms of the GNU General Public License version 2. * the terms of the GNU General Public License version 2.
...@@ -90,8 +90,11 @@ static int a20_test_long(void) ...@@ -90,8 +90,11 @@ static int a20_test_long(void)
static void enable_a20_bios(void) static void enable_a20_bios(void)
{ {
asm volatile("pushfl; int $0x15; popfl" struct biosregs ireg;
: : "a" ((u16)0x2401));
initregs(&ireg);
ireg.ax = 0x2401;
intcall(0x15, &ireg, NULL);
} }
static void enable_a20_kbc(void) static void enable_a20_kbc(void)
......
...@@ -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
* *
* This file is part of the Linux kernel, and is made available under * This file is part of the Linux kernel, and is made available under
* the terms of the GNU General Public License version 2. * the terms of the GNU General Public License version 2.
...@@ -61,11 +62,10 @@ static void copy_boot_params(void) ...@@ -61,11 +62,10 @@ static void copy_boot_params(void)
*/ */
static void keyboard_set_repeat(void) static void keyboard_set_repeat(void)
{ {
u16 ax = 0x0305; struct biosregs ireg;
u16 bx = 0; initregs(&ireg);
asm volatile("int $0x16" ireg.ax = 0x0305;
: "+a" (ax), "+b" (bx) intcall(0x16, &ireg, NULL);
: : "ecx", "edx", "esi", "edi");
} }
/* /*
...@@ -73,18 +73,22 @@ static void keyboard_set_repeat(void) ...@@ -73,18 +73,22 @@ static void keyboard_set_repeat(void)
*/ */
static void query_ist(void) static void query_ist(void)
{ {
struct biosregs ireg, oreg;
/* Some older BIOSes apparently crash on this call, so filter /* Some older BIOSes apparently crash on this call, so filter
it from machines too old to have SpeedStep at all. */ it from machines too old to have SpeedStep at all. */
if (cpu.level < 6) if (cpu.level < 6)
return; return;
asm("int $0x15" initregs(&ireg);
: "=a" (boot_params.ist_info.signature), ireg.ax = 0xe980; /* IST Support */
"=b" (boot_params.ist_info.command), ireg.edx = 0x47534943; /* Request value */
"=c" (boot_params.ist_info.event), intcall(0x15, &ireg, &oreg);
"=d" (boot_params.ist_info.perf_level)
: "a" (0x0000e980), /* IST Support */ boot_params.ist_info.signature = oreg.eax;
"d" (0x47534943)); /* Request value */ boot_params.ist_info.command = oreg.ebx;
boot_params.ist_info.event = oreg.ecx;
boot_params.ist_info.perf_level = oreg.edx;
} }
/* /*
...@@ -93,13 +97,12 @@ static void query_ist(void) ...@@ -93,13 +97,12 @@ static void query_ist(void)
static void set_bios_mode(void) static void set_bios_mode(void)
{ {
#ifdef CONFIG_X86_64 #ifdef CONFIG_X86_64
u32 eax, ebx; struct biosregs ireg;
eax = 0xec00; initregs(&ireg);
ebx = 2; ireg.ax = 0xec00;
asm volatile("int $0x15" ireg.bx = 2;
: "+a" (eax), "+b" (ebx) intcall(0x15, &ireg, NULL);
: : "ecx", "edx", "esi", "edi");
#endif #endif
} }
......
...@@ -25,12 +25,16 @@ struct e820_ext_entry { ...@@ -25,12 +25,16 @@ struct e820_ext_entry {
static int detect_memory_e820(void) static int detect_memory_e820(void)
{ {
int count = 0; int count = 0;
u32 next = 0; struct biosregs ireg, oreg;
u32 size, id, edi;
u8 err;
struct e820entry *desc = boot_params.e820_map; struct e820entry *desc = boot_params.e820_map;
static struct e820_ext_entry buf; /* static so it is zeroed */ static struct e820_ext_entry buf; /* static so it is zeroed */
initregs(&ireg);
ireg.ax = 0xe820;
ireg.cx = sizeof buf;
ireg.edx = SMAP;
ireg.di = (size_t)&buf;
/* /*
* Set this here so that if the BIOS doesn't change this field * Set this here so that if the BIOS doesn't change this field
* but still doesn't change %ecx, we're still okay... * but still doesn't change %ecx, we're still okay...
...@@ -38,22 +42,13 @@ static int detect_memory_e820(void) ...@@ -38,22 +42,13 @@ static int detect_memory_e820(void)
buf.ext_flags = 1; buf.ext_flags = 1;
do { do {
size = sizeof buf; intcall(0x15, &ireg, &oreg);
ireg.ebx = oreg.ebx; /* for next iteration... */
/* Important: %edx and %esi are clobbered by some BIOSes,
so they must be either used for the error output
or explicitly marked clobbered. Given that, assume there
is something out there clobbering %ebp and %edi, too. */
asm("pushl %%ebp; int $0x15; popl %%ebp; setc %0"
: "=d" (err), "+b" (next), "=a" (id), "+c" (size),
"=D" (edi), "+m" (buf)
: "D" (&buf), "d" (SMAP), "a" (0xe820)
: "esi");
/* BIOSes which terminate the chain with CF = 1 as opposed /* BIOSes which terminate the chain with CF = 1 as opposed
to %ebx = 0 don't always report the SMAP signature on to %ebx = 0 don't always report the SMAP signature on
the final, failing, probe. */ the final, failing, probe. */
if (err) if (oreg.eflags & X86_EFLAGS_CF)
break; break;
/* Some BIOSes stop returning SMAP in the middle of /* Some BIOSes stop returning SMAP in the middle of
...@@ -61,7 +56,7 @@ static int detect_memory_e820(void) ...@@ -61,7 +56,7 @@ static int detect_memory_e820(void)
screwed up the map at that point, we might have a screwed up the map at that point, we might have a
partial map, the full map, or complete garbage, so partial map, the full map, or complete garbage, so
just return failure. */ just return failure. */
if (id != SMAP) { if (oreg.eax != SMAP) {
count = 0; count = 0;
break; break;
} }
...@@ -69,58 +64,62 @@ static int detect_memory_e820(void) ...@@ -69,58 +64,62 @@ static int detect_memory_e820(void)
/* ACPI 3.0 added the extended flags support. If bit 0 /* ACPI 3.0 added the extended flags support. If bit 0
in the extended flags is zero, we're supposed to simply in the extended flags is zero, we're supposed to simply
ignore the entry -- a backwards incompatible change! */ ignore the entry -- a backwards incompatible change! */
if (size > 20 && !(buf.ext_flags & 1)) if (oreg.cx > 20 && !(buf.ext_flags & 1))
continue; continue;
*desc++ = buf.std; *desc++ = buf.std;
count++; count++;
} while (next && count < ARRAY_SIZE(boot_params.e820_map)); } while (ireg.ebx && count < ARRAY_SIZE(boot_params.e820_map));
return boot_params.e820_entries = count; return boot_params.e820_entries = count;
} }
static int detect_memory_e801(void) static int detect_memory_e801(void)
{ {
u16 ax, bx, cx, dx; struct biosregs ireg, oreg;
u8 err;
bx = cx = dx = 0; initregs(&ireg);
ax = 0xe801; ireg.ax = 0xe801;
asm("stc; int $0x15; setc %0" intcall(0x15, &ireg, &oreg);
: "=m" (err), "+a" (ax), "+b" (bx), "+c" (cx), "+d" (dx));
if (err) if (oreg.eflags & X86_EFLAGS_CF)
return -1; return -1;
/* Do we really need to do this? */ /* Do we really need to do this? */
if (cx || dx) { if (oreg.cx || oreg.dx) {
ax = cx; oreg.ax = oreg.cx;
bx = dx; oreg.bx = oreg.dx;
} }
if (ax > 15*1024) if (oreg.ax > 15*1024) {
return -1; /* Bogus! */ return -1; /* Bogus! */
} else if (oreg.ax == 15*1024) {
/* This ignores memory above 16MB if we have a memory hole boot_params.alt_mem_k = (oreg.dx << 6) + oreg.ax;
there. If someone actually finds a machine with a memory } else {
hole at 16MB and no support for 0E820h they should probably /*
generate a fake e820 map. */ * This ignores memory above 16MB if we have a memory
boot_params.alt_mem_k = (ax == 15*1024) ? (dx << 6)+ax : ax; * hole there. If someone actually finds a machine
* with a memory hole at 16MB and no support for
* 0E820h they should probably generate a fake e820
* map.
*/
boot_params.alt_mem_k = oreg.ax;
}
return 0; return 0;
} }
static int detect_memory_88(void) static int detect_memory_88(void)
{ {
u16 ax; struct biosregs ireg, oreg;
u8 err;
ax = 0x8800; initregs(&ireg);
asm("stc; int $0x15; setc %0" : "=bcdm" (err), "+a" (ax)); ireg.ah = 0x88;
intcall(0x15, &ireg, &oreg);
boot_params.screen_info.ext_mem_k = ax; boot_params.screen_info.ext_mem_k = oreg.ax;
return -err; return -(oreg.eflags & X86_EFLAGS_CF); /* 0 or -1 */
} }
int detect_memory(void) int detect_memory(void)
......
...@@ -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
* *
* This file is part of the Linux kernel, and is made available under * This file is part of the Linux kernel, and is made available under
* the terms of the GNU General Public License version 2. * the terms of the GNU General Public License version 2.
...@@ -22,24 +23,23 @@ ...@@ -22,24 +23,23 @@
void __attribute__((section(".inittext"))) putchar(int ch) void __attribute__((section(".inittext"))) putchar(int ch)
{ {
unsigned char c = ch; struct biosregs ireg;
if (c == '\n') if (ch == '\n')
putchar('\r'); /* \n -> \r\n */ putchar('\r'); /* \n -> \r\n */
/* int $0x10 is known to have bugs involving touching registers initregs(&ireg);
it shouldn't. Be extra conservative... */ ireg.bx = 0x0007;
asm volatile("pushal; pushw %%ds; int $0x10; popw %%ds; popal" ireg.cx = 0x0001;
: : "b" (0x0007), "c" (0x0001), "a" (0x0e00|ch)); ireg.ah = 0x0e;
ireg.al = ch;
intcall(0x10, &ireg, NULL);
} }
void __attribute__((section(".inittext"))) puts(const char *str) void __attribute__((section(".inittext"))) puts(const char *str)
{ {
int n = 0; while (*str)
while (*str) {
putchar(*str++); putchar(*str++);
n++;
}
} }
/* /*
...@@ -49,14 +49,13 @@ void __attribute__((section(".inittext"))) puts(const char *str) ...@@ -49,14 +49,13 @@ void __attribute__((section(".inittext"))) puts(const char *str)
static u8 gettime(void) static u8 gettime(void)
{ {
u16 ax = 0x0200; struct biosregs ireg, oreg;
u16 cx, dx;
asm volatile("int $0x1a" initregs(&ireg);
: "+a" (ax), "=c" (cx), "=d" (dx) ireg.ah = 0x02;
: : "ebx", "esi", "edi"); intcall(0x1a, &ireg, &oreg);
return dx >> 8; return oreg.dh;
} }
/* /*
...@@ -64,19 +63,24 @@ static u8 gettime(void) ...@@ -64,19 +63,24 @@ static u8 gettime(void)
*/ */
int getchar(void) int getchar(void)
{ {
u16 ax = 0; struct biosregs ireg, oreg;
asm volatile("int $0x16" : "+a" (ax));
initregs(&ireg);
/* ireg.ah = 0x00; */
intcall(0x16, &ireg, &oreg);
return ax & 0xff; return oreg.al;
} }
static int kbd_pending(void) static int kbd_pending(void)
{ {
u8 pending; struct biosregs ireg, oreg;
asm volatile("int $0x16; setnz %0"
: "=qm" (pending) initregs(&ireg);
: "a" (0x0100)); ireg.ah = 0x01;
return pending; intcall(0x16, &ireg, &oreg);
return !(oreg.eflags & X86_EFLAGS_ZF);
} }
void kbd_flush(void) void kbd_flush(void)
......
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