From b1b71cd91a12ade3ecda15a882ff9e25025ef530 Mon Sep 17 00:00:00 2001 From: Cyrill Gorcunov Date: Sun, 28 Mar 2010 18:45:51 +0400 Subject: [PATCH] kvm: Introduce IVT handling Introduce procedures for handling IVT (Interrupt Vector Table) to be used int real mode bootstrap procedure. Signed-off-by: Cyrill Gorcunov Signed-off-by: Pekka Enberg --- Makefile | 1 + ivt.c | 38 ++++++++++++++++++++++++++++++++++++++ ivt.h | 15 +++++++++++++++ 3 files changed, 54 insertions(+) create mode 100644 ivt.c create mode 100644 ivt.h diff --git a/Makefile b/Makefile index bd1488a..7776a89 100644 --- a/Makefile +++ b/Makefile @@ -4,6 +4,7 @@ OBJS += cpu.o OBJS += kvm.o OBJS += main.o OBJS += util.o +OBJS += ivt.o CFLAGS += $(CPPFLAGS) -Iinclude diff --git a/ivt.c b/ivt.c new file mode 100644 index 0000000..e5e8503 --- /dev/null +++ b/ivt.c @@ -0,0 +1,38 @@ +#include +#include +#include +#include +#include +#include +#include + +#include "util.h" +#include "ivt.h" + +static struct ivt_entry ivt_table[IVT_VECTORS]; + +void ivt_reset(void) +{ + memset(ivt_table, 0x0, sizeof(ivt_table)); +} + +void ivt_copy_table(void *dst, unsigned int size) +{ + if (size < sizeof(ivt_table)) + die("An attempt to overwrite host memory"); + memcpy(dst, ivt_table, sizeof(ivt_table)); +} + +struct ivt_entry * const ivt_get_entry(unsigned int n) +{ + struct ivt_entry *v = NULL; + if (n < IVT_VECTORS) + v = &ivt_table[n]; + return (struct ivt_entry * const)v; +} + +void ivt_set_entry(struct ivt_entry e, unsigned int n) +{ + if (n < IVT_VECTORS) + ivt_table[n] = e; +} diff --git a/ivt.h b/ivt.h new file mode 100644 index 0000000..3b31cac --- /dev/null +++ b/ivt.h @@ -0,0 +1,15 @@ +#include +#include + +#define IVT_BASE 0x0000 +#define IVT_VECTORS 256 + +struct ivt_entry { + uint16_t segment; + uint16_t offset; +} __attribute__((packed)); + +void ivt_reset(void); +void ivt_copy_table(void *dst, unsigned int size); +struct ivt_entry * const ivt_get_entry(unsigned int n); +void ivt_set_entry(struct ivt_entry e, unsigned int n);