This patch moves the global interrupt table to struct kvm.
Signed-off-by: Pekka Enberg <penberg@cs.helsinki.fi>
uint16_t segment;
} __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);
-void ivt_set_all(struct ivt_entry e);
+struct interrupt_table {
+ struct ivt_entry entries[IVT_VECTORS];
+};
+
+void interrupt_table__copy(struct interrupt_table *self, void *dst, unsigned int size);
+void interrupt_table__setup(struct interrupt_table *self, struct ivt_entry e);
#endif /* KVM__INTERRUPT_H */
#ifndef KVM__KVM_H
#define KVM__KVM_H
+#include "kvm/interrupt.h"
+
#include <linux/kvm.h> /* for struct kvm_regs */
#include <stdbool.h>
struct kvm_regs regs;
struct kvm_sregs sregs;
+
+ struct interrupt_table interrupt_table;
};
struct kvm *kvm__init(void);
#include <string.h>
-static struct ivt_entry ivt_table[IVT_VECTORS];
-
-void ivt_reset(void)
+void interrupt_table__copy(struct interrupt_table *self, void *dst, unsigned int size)
{
- memset(ivt_table, 0x0, sizeof(ivt_table));
-}
-
-void ivt_copy_table(void *dst, unsigned int size)
-{
- if (size < sizeof(ivt_table))
+ if (size < sizeof(self->entries))
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;
+ memcpy(dst, self->entries, sizeof(self->entries));
}
-void ivt_set_all(struct ivt_entry e)
+void interrupt_table__setup(struct interrupt_table *self, struct ivt_entry e)
{
unsigned int i;
for (i = 0; i < IVT_VECTORS; i++)
- ivt_table[i] = e;
+ self->entries[i] = e;
}
.segment = nr >> 4,
.offset = (nr - (nr & ~0xf)),
};
- ivt_set_all(real_mode_irq);
+ interrupt_table__setup(&self->interrupt_table, real_mode_irq);
p = guest_flat_to_host(self, 0);
- ivt_copy_table(p, IVT_VECTORS * sizeof(real_mode_irq));
+ interrupt_table__copy(&self->interrupt_table, p, IVT_VECTORS * sizeof(real_mode_irq));
return true;
}