proof of concept interrupt wrapping

This commit is contained in:
Vladimir 'phcoder' Serbinenko 2009-12-31 13:07:51 +01:00
parent f5a513064c
commit eb3f57d3c4
5 changed files with 176 additions and 78 deletions

View file

@ -64,7 +64,7 @@ kernel_img_HEADERS = boot.h cache.h device.h disk.h dl.h elf.h elfload.h \
partition.h msdos_partition.h reader.h symbol.h term.h time.h types.h \ partition.h msdos_partition.h reader.h symbol.h term.h time.h types.h \
machine/biosdisk.h machine/boot.h machine/console.h machine/init.h \ machine/biosdisk.h machine/boot.h machine/console.h machine/init.h \
machine/memory.h machine/loader.h machine/vga.h machine/vbe.h \ machine/memory.h machine/loader.h machine/vga.h machine/vbe.h \
machine/kernel.h machine/pxe.h i386/pit.h list.h handler.h command.h i18n.h machine/kernel.h machine/pxe.h i386/pit.h list.h handler.h command.h i18n.h machine/int.h
kernel_img_CFLAGS = $(COMMON_CFLAGS) $(TARGET_IMG_CFLAGS) kernel_img_CFLAGS = $(COMMON_CFLAGS) $(TARGET_IMG_CFLAGS)
kernel_img_ASFLAGS = $(COMMON_ASFLAGS) kernel_img_ASFLAGS = $(COMMON_ASFLAGS)
kernel_img_LDFLAGS = $(COMMON_LDFLAGS) $(TARGET_IMG_LDFLAGS)$(GRUB_KERNEL_MACHINE_LINK_ADDR) $(COMMON_CFLAGS) kernel_img_LDFLAGS = $(COMMON_LDFLAGS) $(TARGET_IMG_LDFLAGS)$(GRUB_KERNEL_MACHINE_LINK_ADDR) $(COMMON_CFLAGS)

View file

@ -19,6 +19,7 @@
#include <grub/machine/biosdisk.h> #include <grub/machine/biosdisk.h>
#include <grub/machine/memory.h> #include <grub/machine/memory.h>
#include <grub/machine/kernel.h> #include <grub/machine/kernel.h>
#include <grub/machine/int.h>
#include <grub/disk.h> #include <grub/disk.h>
#include <grub/dl.h> #include <grub/dl.h>
#include <grub/mm.h> #include <grub/mm.h>
@ -28,6 +29,59 @@
#include <grub/term.h> #include <grub/term.h>
static int cd_drive = 0; static int cd_drive = 0;
static int grub_biosdisk_rw_int13_extensions (int ah, int drive, void *dap);
static int grub_biosdisk_get_num_floppies (void)
{
struct grub_cpu_int_registers regs;
int drive;
/* reset the disk system first */
regs.ax = 0;
regs.dx = 0;
regs.flags = GRUB_CPU_INT_FLAGS_DEFAULT;
grub_cpu_interrupt (0x13, &regs);
for (drive = 0; drive < 2; drive++)
{
regs.flags = GRUB_CPU_INT_FLAGS_DEFAULT | GRUB_CPU_INT_FLAGS_CARRY;
regs.dx = drive;
/* call GET DISK TYPE */
regs.ax = 0x1500;
grub_cpu_interrupt (0x13, &regs);
if (regs.flags & GRUB_CPU_INT_FLAGS_CARRY)
break;
/* check if this drive exists */
if (!(regs.ax & 0x300))
break;
}
return drive;
}
/*
* Call IBM/MS INT13 Extensions (int 13 %ah=AH) for DRIVE. DAP
* is passed for disk address packet. If an error occurs, return
* non-zero, otherwise zero.
*/
static int
grub_biosdisk_rw_int13_extensions (int ah, int drive, void *dap)
{
struct grub_cpu_int_registers regs;
regs.ax = ah << 8;
/* compute the address of disk_address_packet */
regs.ds = (((grub_addr_t) dap) & 0xffff0000) >> 4;
regs.si = (((grub_addr_t) dap) & 0xffff);
regs.dx = drive;
regs.flags = GRUB_CPU_INT_FLAGS_DEFAULT;
grub_cpu_interrupt (0x13, &regs);
return regs.ax >> 8;
}
static int static int
grub_biosdisk_get_drive (const char *name) grub_biosdisk_get_drive (const char *name)

View file

@ -106,7 +106,6 @@ struct grub_biosdisk_dap
grub_uint64_t block; grub_uint64_t block;
} __attribute__ ((packed)); } __attribute__ ((packed));
int EXPORT_FUNC(grub_biosdisk_rw_int13_extensions) (int ah, int drive, void *dap);
int EXPORT_FUNC(grub_biosdisk_rw_standard) (int ah, int drive, int coff, int hoff, int EXPORT_FUNC(grub_biosdisk_rw_standard) (int ah, int drive, int coff, int hoff,
int soff, int nsec, int segment); int soff, int nsec, int segment);
int EXPORT_FUNC(grub_biosdisk_check_int13_extensions) (int drive); int EXPORT_FUNC(grub_biosdisk_check_int13_extensions) (int drive);
@ -118,7 +117,6 @@ int EXPORT_FUNC(grub_biosdisk_get_diskinfo_standard) (int drive,
unsigned long *cylinders, unsigned long *cylinders,
unsigned long *heads, unsigned long *heads,
unsigned long *sectors); unsigned long *sectors);
int EXPORT_FUNC(grub_biosdisk_get_num_floppies) (void);
void grub_biosdisk_init (void); void grub_biosdisk_init (void);
void grub_biosdisk_fini (void); void grub_biosdisk_fini (void);

View file

@ -0,0 +1,50 @@
/*
* GRUB -- GRand Unified Bootloader
* Copyright (C) 2009 Free Software Foundation, Inc.
*
* GRUB is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* GRUB is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with GRUB. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef GRUB_INTERRUPT_MACHINE_HEADER
#define GRUB_INTERRUPT_MACHINE_HEADER 1
#include <grub/symbol.h>
struct grub_cpu_int_registers
{
grub_uint16_t bx;
grub_uint16_t es;
grub_uint16_t cx;
grub_uint16_t ax;
grub_uint16_t dx;
grub_uint16_t ds;
grub_uint16_t di;
grub_uint16_t flags;
grub_uint16_t si;
};
#define GRUB_CPU_INT_FLAGS_CARRY 0x1
#define GRUB_CPU_INT_FLAGS_PARITY 0x4
#define GRUB_CPU_INT_FLAGS_ADJUST 0x10
#define GRUB_CPU_INT_FLAGS_ZERO 0x40
#define GRUB_CPU_INT_FLAGS_SIGN 0x80
#define GRUB_CPU_INT_FLAGS_TRAP 0x100
#define GRUB_CPU_INT_FLAGS_INTERRUPT 0x200
#define GRUB_CPU_INT_FLAGS_DIRECTION 0x400
#define GRUB_CPU_INT_FLAGS_OVERFLOW 0x800
#define GRUB_CPU_INT_FLAGS_DEFAULT GRUB_CPU_INT_FLAGS_INTERRUPT
void EXPORT_FUNC (grub_cpu_interrupt) (grub_uint8_t intno, struct grub_cpu_int_registers *regs);
#endif

View file

@ -566,44 +566,6 @@ FUNCTION(grub_chainloader_real_boot)
#include "../loader.S" #include "../loader.S"
/*
* int grub_biosdisk_rw_int13_extensions (int ah, int drive, void *dap)
*
* Call IBM/MS INT13 Extensions (int 13 %ah=AH) for DRIVE. DAP
* is passed for disk address packet. If an error occurs, return
* non-zero, otherwise zero.
*/
FUNCTION(grub_biosdisk_rw_int13_extensions)
pushl %ebp
pushl %esi
/* compute the address of disk_address_packet */
movw %cx, %si
xorw %cx, %cx
shrl $4, %ecx /* save the segment to cx */
/* ah */
movb %al, %dh
/* enter real mode */
call prot_to_real
.code16
movb %dh, %ah
movw %cx, %ds
int $0x13 /* do the operation */
movb %ah, %dl /* save return value */
/* back to protected mode */
DATA32 call real_to_prot
.code32
movb %dl, %al /* return value in %eax */
popl %esi
popl %ebp
ret
/* /*
* int grub_biosdisk_rw_standard (int ah, int drive, int coff, int hoff, * int grub_biosdisk_rw_standard (int ah, int drive, int coff, int hoff,
* int soff, int nsec, int segment) * int soff, int nsec, int segment)
@ -861,43 +823,6 @@ noclean2:
ret $4 ret $4
/*
* int grub_biosdisk_get_num_floppies (void)
*/
FUNCTION(grub_biosdisk_get_num_floppies)
pushl %ebp
xorl %edx, %edx
call prot_to_real
.code16
/* reset the disk system first */
int $0x13
1:
stc
/* call GET DISK TYPE */
movb $0x15, %ah
int $0x13
jc 2f
/* check if this drive exists */
testb $0x3, %ah
jz 2f
incb %dl
cmpb $2, %dl
jne 1b
2:
DATA32 call real_to_prot
.code32
movl %edx, %eax
popl %ebp
ret
/* /*
* *
* grub_get_memsize(i) : return the memory size in KB. i == 0 for conventional * grub_get_memsize(i) : return the memory size in KB. i == 0 for conventional
@ -2142,3 +2067,74 @@ FUNCTION(grub_pxe_call)
popl %esi popl %esi
popl %ebp popl %ebp
ret ret
FUNCTION(grub_cpu_interrupt)
pushl %ebp
pushl %esi
pushl %edi
pushl %ebx
pushl %edx
movb %al, intno
movl %edx, %esi
movl 0(%esi), %ebx
movl 4(%esi), %ecx
movl 8(%esi), %edx
movl 12(%esi), %edi
movw 16(%esi), %si
call prot_to_real
.code16
movl %edi, %eax
shrl $16, %eax
push %ax
movl %ebx, %eax
shrl $16, %eax
movw %ax, %es
movl %edx, %eax
shrl $16, %eax
movw %ax, %ds
movl %ecx, %eax
shrl $16, %eax
popf
.byte 0xcd
intno:
.byte 0
pushf
andl $0xffff, %ebx
andl $0xffff, %ecx
andl $0xffff, %edx
andl $0xffff, %edi
shll $16, %eax
orl %eax, %ecx
movw %ds, %ax
shll $16, %eax
orl %eax, %edx
pop %ax
shll $16, %eax
orl %eax, %edi
DATA32 call real_to_prot
.code32
pushl %esi
movl 4(%esp), %esi
movl %ebx, 0(%esi)
movl %ecx, 4(%esi)
movl %edx, 8(%esi)
movl %edi, 12(%esi)
popl %eax
movw %ax, 16(%esi)
popl %eax
popl %ebx
popl %edi
popl %esi
popl %ebp
ret