xref: /linux/arch/x86/kernel/idt.c (revision 588787fde7aa346f345e1a7600f84d88039fc9df)
1d8ed9d48SThomas Gleixner /*
2d8ed9d48SThomas Gleixner  * Interrupt descriptor table related code
3d8ed9d48SThomas Gleixner  *
4d8ed9d48SThomas Gleixner  * This file is licensed under the GPL V2
5d8ed9d48SThomas Gleixner  */
6d8ed9d48SThomas Gleixner #include <linux/interrupt.h>
7d8ed9d48SThomas Gleixner 
8d8ed9d48SThomas Gleixner #include <asm/desc.h>
9d8ed9d48SThomas Gleixner 
10d8ed9d48SThomas Gleixner /* Must be page-aligned because the real IDT is used in a fixmap. */
11d8ed9d48SThomas Gleixner gate_desc idt_table[IDT_ENTRIES] __page_aligned_bss;
12d8ed9d48SThomas Gleixner 
1316bc18d8SThomas Gleixner struct desc_ptr idt_descr __ro_after_init = {
1416bc18d8SThomas Gleixner 	.size		= (IDT_ENTRIES * 2 * sizeof(unsigned long)) - 1,
1516bc18d8SThomas Gleixner 	.address	= (unsigned long) idt_table,
1616bc18d8SThomas Gleixner };
1716bc18d8SThomas Gleixner 
18d8ed9d48SThomas Gleixner #ifdef CONFIG_X86_64
19d8ed9d48SThomas Gleixner /* No need to be aligned, but done to keep all IDTs defined the same way. */
20d8ed9d48SThomas Gleixner gate_desc debug_idt_table[IDT_ENTRIES] __page_aligned_bss;
21d8ed9d48SThomas Gleixner 
22d8ed9d48SThomas Gleixner const struct desc_ptr debug_idt_descr = {
23d8ed9d48SThomas Gleixner 	.size		= IDT_ENTRIES * 16 - 1,
24d8ed9d48SThomas Gleixner 	.address	= (unsigned long) debug_idt_table,
25d8ed9d48SThomas Gleixner };
26d8ed9d48SThomas Gleixner #endif
27e802a51eSThomas Gleixner 
28e802a51eSThomas Gleixner /**
29*588787fdSThomas Gleixner  * idt_setup_early_handler - Initializes the idt table with early handlers
30*588787fdSThomas Gleixner  */
31*588787fdSThomas Gleixner void __init idt_setup_early_handler(void)
32*588787fdSThomas Gleixner {
33*588787fdSThomas Gleixner 	int i;
34*588787fdSThomas Gleixner 
35*588787fdSThomas Gleixner 	for (i = 0; i < NUM_EXCEPTION_VECTORS; i++)
36*588787fdSThomas Gleixner 		set_intr_gate(i, early_idt_handler_array[i]);
37*588787fdSThomas Gleixner 	load_idt(&idt_descr);
38*588787fdSThomas Gleixner }
39*588787fdSThomas Gleixner 
40*588787fdSThomas Gleixner /**
41e802a51eSThomas Gleixner  * idt_invalidate - Invalidate interrupt descriptor table
42e802a51eSThomas Gleixner  * @addr:	The virtual address of the 'invalid' IDT
43e802a51eSThomas Gleixner  */
44e802a51eSThomas Gleixner void idt_invalidate(void *addr)
45e802a51eSThomas Gleixner {
46e802a51eSThomas Gleixner 	struct desc_ptr idt = { .address = (unsigned long) addr, .size = 0 };
47e802a51eSThomas Gleixner 
48e802a51eSThomas Gleixner 	load_idt(&idt);
49e802a51eSThomas Gleixner }
50