1 // SPDX-License-Identifier: GPL-2.0-only
2 #include <asm/trap_pf.h>
3 #include <asm/segment.h>
4 #include <asm/trapnr.h>
7 static void set_idt_entry(int vector
, void (*handler
)(void))
9 unsigned long address
= (unsigned long)handler
;
12 memset(&entry
, 0, sizeof(entry
));
14 entry
.offset_low
= (u16
)(address
& 0xffff);
15 entry
.segment
= __KERNEL_CS
;
16 entry
.bits
.type
= GATE_TRAP
;
18 entry
.offset_middle
= (u16
)((address
>> 16) & 0xffff);
19 entry
.offset_high
= (u32
)(address
>> 32);
21 memcpy(&boot_idt
[vector
], &entry
, sizeof(entry
));
24 /* Have this here so we don't need to include <asm/desc.h> */
25 static void load_boot_idt(const struct desc_ptr
*dtr
)
27 asm volatile("lidt %0"::"m" (*dtr
));
30 /* Setup IDT before kernel jumping to .Lrelocated */
31 void load_stage1_idt(void)
33 boot_idt_desc
.address
= (unsigned long)boot_idt
;
36 if (IS_ENABLED(CONFIG_AMD_MEM_ENCRYPT
))
37 set_idt_entry(X86_TRAP_VC
, boot_stage1_vc
);
39 load_boot_idt(&boot_idt_desc
);
42 /* Setup IDT after kernel jumping to .Lrelocated */
43 void load_stage2_idt(void)
45 boot_idt_desc
.address
= (unsigned long)boot_idt
;
47 set_idt_entry(X86_TRAP_PF
, boot_page_fault
);
49 #ifdef CONFIG_AMD_MEM_ENCRYPT
50 set_idt_entry(X86_TRAP_VC
, boot_stage2_vc
);
53 load_boot_idt(&boot_idt_desc
);