x86, setup: "glove box" BIOS calls -- infrastructure
Impact: new interfaces (not yet used) For all the platforms out there, there is an infinite number of buggy BIOSes. This adds infrastructure to treat BIOS interrupts more like toxic waste and "glove box" them -- we switch out the register set, perform the BIOS interrupt, and then restore the previous state. 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>
This commit is contained in:
parent
62b8e680e6
commit
7a734e7dd9
9 changed files with 172 additions and 4 deletions
|
@ -26,9 +26,10 @@ targets := vmlinux.bin setup.bin setup.elf bzImage
|
|||
targets += fdimage fdimage144 fdimage288 image.iso mtools.conf
|
||||
subdir- := compressed
|
||||
|
||||
setup-y += a20.o cmdline.o copy.o cpu.o cpucheck.o edd.o
|
||||
setup-y += a20.o bioscall.o cmdline.o copy.o cpu.o cpucheck.o edd.o
|
||||
setup-y += header.o main.o mca.o memory.o pm.o pmjump.o
|
||||
setup-y += printf.o string.o tty.o video.o video-mode.o version.o
|
||||
setup-y += printf.o regs.o string.o tty.o video.o video-mode.o
|
||||
setup-y += version.o
|
||||
setup-$(CONFIG_X86_APM_BOOT) += apm.o
|
||||
|
||||
# The link order of the video-*.o modules can matter. In particular,
|
||||
|
|
82
arch/x86/boot/bioscall.S
Normal file
82
arch/x86/boot/bioscall.S
Normal file
|
@ -0,0 +1,82 @@
|
|||
/* -----------------------------------------------------------------------
|
||||
*
|
||||
* 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 or (at your
|
||||
* option) any later version; incorporated herein by reference.
|
||||
*
|
||||
* ----------------------------------------------------------------------- */
|
||||
|
||||
/*
|
||||
* "Glove box" for BIOS calls. Avoids the constant problems with BIOSes
|
||||
* touching memory they shouldn't be.
|
||||
*/
|
||||
|
||||
.code16
|
||||
.text
|
||||
.globl intcall
|
||||
.type intcall, @function
|
||||
intcall:
|
||||
/* Self-modify the INT instruction. Ugly, but works. */
|
||||
cmpb %al, 3f
|
||||
je 1f
|
||||
movb %al, 3f
|
||||
jmp 1f /* Synchronize pipeline */
|
||||
1:
|
||||
/* Save state */
|
||||
pushfl
|
||||
pushw %fs
|
||||
pushw %gs
|
||||
pushal
|
||||
|
||||
/* Copy input state to stack frame */
|
||||
subw $44, %sp
|
||||
movw %dx, %si
|
||||
movw %sp, %di
|
||||
movw $11, %cx
|
||||
rep; movsd
|
||||
|
||||
/* Pop full state from the stack */
|
||||
popal
|
||||
popw %gs
|
||||
popw %fs
|
||||
popw %es
|
||||
popw %ds
|
||||
popfl
|
||||
|
||||
/* Actual INT */
|
||||
.byte 0xcd /* INT opcode */
|
||||
3: .byte 0
|
||||
|
||||
/* Push full state to the stack */
|
||||
pushfl
|
||||
pushw %ds
|
||||
pushw %es
|
||||
pushw %fs
|
||||
pushw %gs
|
||||
pushal
|
||||
|
||||
/* Re-establish C environment invariants */
|
||||
cld
|
||||
movzwl %sp, %esp
|
||||
movw %cs, %ax
|
||||
movw %ax, %ds
|
||||
movw %ax, %es
|
||||
|
||||
/* Copy output state from stack frame */
|
||||
movw 68(%esp), %di /* Original %cx == 3rd argument */
|
||||
andw %di, %di
|
||||
jz 4f
|
||||
movw %sp, %si
|
||||
movw $11, %cx
|
||||
rep; movsd
|
||||
4: addw $44, %sp
|
||||
|
||||
/* Restore state and return */
|
||||
popal
|
||||
popw %gs
|
||||
popw %fs
|
||||
popfl
|
||||
retl
|
||||
.size intcall, .-intcall
|
|
@ -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.
|
||||
|
@ -26,6 +27,7 @@
|
|||
#include <asm/setup.h>
|
||||
#include "bitops.h"
|
||||
#include <asm/cpufeature.h>
|
||||
#include <asm/processor-flags.h>
|
||||
|
||||
/* Useful macros */
|
||||
#define BUILD_BUG_ON(condition) ((void)sizeof(char[1 - 2*!!(condition)]))
|
||||
|
@ -241,6 +243,49 @@ int enable_a20(void);
|
|||
/* apm.c */
|
||||
int query_apm_bios(void);
|
||||
|
||||
/* bioscall.c */
|
||||
struct biosregs {
|
||||
union {
|
||||
struct {
|
||||
u32 edi;
|
||||
u32 esi;
|
||||
u32 ebp;
|
||||
u32 _esp;
|
||||
u32 ebx;
|
||||
u32 edx;
|
||||
u32 ecx;
|
||||
u32 eax;
|
||||
u32 _fsgs;
|
||||
u32 _dses;
|
||||
u32 eflags;
|
||||
};
|
||||
struct {
|
||||
u16 di, hdi;
|
||||
u16 si, hsi;
|
||||
u16 bp, hbp;
|
||||
u16 _sp, _hsp;
|
||||
u16 bx, hbx;
|
||||
u16 dx, hdx;
|
||||
u16 cx, hcx;
|
||||
u16 ax, hax;
|
||||
u16 gs, fs;
|
||||
u16 es, ds;
|
||||
u16 flags, hflags;
|
||||
};
|
||||
struct {
|
||||
u8 dil, dih, edi2, edi3;
|
||||
u8 sil, sih, esi2, esi3;
|
||||
u8 bpl, bph, ebp2, ebp3;
|
||||
u8 _spl, _sph, _esp2, _esp3;
|
||||
u8 bl, bh, ebx2, ebx3;
|
||||
u8 dl, dh, edx2, edx3;
|
||||
u8 cl, ch, ecx2, ecx3;
|
||||
u8 al, ah, eax2, eax3;
|
||||
};
|
||||
};
|
||||
};
|
||||
void intcall(u8 int_no, const struct biosregs *ireg, struct biosregs *oreg);
|
||||
|
||||
/* cmdline.c */
|
||||
int cmdline_find_option(const char *option, char *buffer, int bufsize);
|
||||
int cmdline_find_option_bool(const char *option);
|
||||
|
@ -279,6 +324,9 @@ int sprintf(char *buf, const char *fmt, ...);
|
|||
int vsprintf(char *buf, const char *fmt, va_list args);
|
||||
int printf(const char *fmt, ...);
|
||||
|
||||
/* regs.c */
|
||||
void initregs(struct biosregs *regs);
|
||||
|
||||
/* string.c */
|
||||
int strcmp(const char *str1, const char *str2);
|
||||
size_t strnlen(const char *s, size_t maxlen);
|
||||
|
|
|
@ -221,7 +221,7 @@ setup_data: .quad 0 # 64-bit physical pointer to
|
|||
|
||||
# End of setup header #####################################################
|
||||
|
||||
.section ".inittext", "ax"
|
||||
.section ".entrytext", "ax"
|
||||
start_of_setup:
|
||||
#ifdef SAFE_RESET_DISK_CONTROLLER
|
||||
# Reset the disk controller.
|
||||
|
|
29
arch/x86/boot/regs.c
Normal file
29
arch/x86/boot/regs.c
Normal file
|
@ -0,0 +1,29 @@
|
|||
/* -----------------------------------------------------------------------
|
||||
*
|
||||
* 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 or (at your
|
||||
* option) any later version; incorporated herein by reference.
|
||||
*
|
||||
* ----------------------------------------------------------------------- */
|
||||
|
||||
/*
|
||||
* Simple helper function for initializing a register set.
|
||||
*
|
||||
* Note that this sets EFLAGS_CF in the input register set; this
|
||||
* makes it easier to catch functions which do nothing but don't
|
||||
* explicitly set CF.
|
||||
*/
|
||||
|
||||
#include "boot.h"
|
||||
|
||||
void initregs(struct biosregs *reg)
|
||||
{
|
||||
memset(reg, 0, sizeof *reg);
|
||||
reg->eflags |= X86_EFLAGS_CF;
|
||||
reg->ds = ds();
|
||||
reg->es = ds();
|
||||
reg->fs = fs();
|
||||
reg->gs = gs();
|
||||
}
|
|
@ -15,8 +15,11 @@ SECTIONS
|
|||
|
||||
. = 497;
|
||||
.header : { *(.header) }
|
||||
.entrytext : { *(.entrytext) }
|
||||
.inittext : { *(.inittext) }
|
||||
.initdata : { *(.initdata) }
|
||||
__end_init = .;
|
||||
|
||||
.text : { *(.text) }
|
||||
.text32 : { *(.text32) }
|
||||
|
||||
|
@ -52,4 +55,7 @@ SECTIONS
|
|||
|
||||
. = ASSERT(_end <= 0x8000, "Setup too big!");
|
||||
. = ASSERT(hdr == 0x1f1, "The setup header has the wrong offset!");
|
||||
/* Necessary for the very-old-loader check to work... */
|
||||
. = ASSERT(__end_init <= 5*512, "init sections too big!");
|
||||
|
||||
}
|
||||
|
|
|
@ -9,7 +9,7 @@
|
|||
always := wakeup.bin
|
||||
targets := wakeup.elf wakeup.lds
|
||||
|
||||
wakeup-y += wakeup.o wakemain.o video-mode.o copy.o
|
||||
wakeup-y += wakeup.o wakemain.o video-mode.o copy.o bioscall.o regs.o
|
||||
|
||||
# The link order of the video-*.o modules can matter. In particular,
|
||||
# video-vga.o *must* be listed first, followed by video-vesa.o.
|
||||
|
|
1
arch/x86/kernel/acpi/realmode/bioscall.S
Normal file
1
arch/x86/kernel/acpi/realmode/bioscall.S
Normal file
|
@ -0,0 +1 @@
|
|||
#include "../../../boot/bioscall.S"
|
1
arch/x86/kernel/acpi/realmode/regs.c
Normal file
1
arch/x86/kernel/acpi/realmode/regs.c
Normal file
|
@ -0,0 +1 @@
|
|||
#include "../../../boot/regs.c"
|
Loading…
Reference in a new issue