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