xref: /kvmtool/x86/interrupt.c (revision eda033194eea1276e05db94060ad222f3b54a114)
1*eda03319SPekka Enberg #include "kvm/interrupt.h"
2*eda03319SPekka Enberg 
3b1b71cd9SCyrill Gorcunov #include <stdbool.h>
4b1b71cd9SCyrill Gorcunov #include <limits.h>
5b1b71cd9SCyrill Gorcunov #include <stdarg.h>
6b1b71cd9SCyrill Gorcunov #include <stdlib.h>
7b1b71cd9SCyrill Gorcunov #include <string.h>
8b1b71cd9SCyrill Gorcunov #include <unistd.h>
9b1b71cd9SCyrill Gorcunov #include <stdio.h>
10b1b71cd9SCyrill Gorcunov 
11b1b71cd9SCyrill Gorcunov #include "util.h"
12b1b71cd9SCyrill Gorcunov 
13b1b71cd9SCyrill Gorcunov static struct ivt_entry ivt_table[IVT_VECTORS];
14b1b71cd9SCyrill Gorcunov 
15b1b71cd9SCyrill Gorcunov void ivt_reset(void)
16b1b71cd9SCyrill Gorcunov {
17b1b71cd9SCyrill Gorcunov 	memset(ivt_table, 0x0, sizeof(ivt_table));
18b1b71cd9SCyrill Gorcunov }
19b1b71cd9SCyrill Gorcunov 
20b1b71cd9SCyrill Gorcunov void ivt_copy_table(void *dst, unsigned int size)
21b1b71cd9SCyrill Gorcunov {
22b1b71cd9SCyrill Gorcunov 	if (size < sizeof(ivt_table))
23b1b71cd9SCyrill Gorcunov 		die("An attempt to overwrite host memory");
24b1b71cd9SCyrill Gorcunov 	memcpy(dst, ivt_table, sizeof(ivt_table));
25b1b71cd9SCyrill Gorcunov }
26b1b71cd9SCyrill Gorcunov 
27b1b71cd9SCyrill Gorcunov struct ivt_entry * const ivt_get_entry(unsigned int n)
28b1b71cd9SCyrill Gorcunov {
29b1b71cd9SCyrill Gorcunov 	struct ivt_entry *v = NULL;
30b1b71cd9SCyrill Gorcunov 	if (n < IVT_VECTORS)
31b1b71cd9SCyrill Gorcunov 		v = &ivt_table[n];
32b1b71cd9SCyrill Gorcunov 	return (struct ivt_entry * const)v;
33b1b71cd9SCyrill Gorcunov }
34b1b71cd9SCyrill Gorcunov 
35b1b71cd9SCyrill Gorcunov void ivt_set_entry(struct ivt_entry e, unsigned int n)
36b1b71cd9SCyrill Gorcunov {
37b1b71cd9SCyrill Gorcunov 	if (n < IVT_VECTORS)
38b1b71cd9SCyrill Gorcunov 		ivt_table[n] = e;
39b1b71cd9SCyrill Gorcunov }
40ea684828SCyrill Gorcunov 
41ea684828SCyrill Gorcunov void ivt_set_all(struct ivt_entry e)
42ea684828SCyrill Gorcunov {
43ea684828SCyrill Gorcunov 	unsigned int i;
44ea684828SCyrill Gorcunov 
45ea684828SCyrill Gorcunov 	for (i = 0; i < IVT_VECTORS; i++)
46ea684828SCyrill Gorcunov 		ivt_table[i] = e;
47ea684828SCyrill Gorcunov }
48