1 /* 2 * Copyright (C) 2018-2022 Intel Corporation. 3 * 4 * SPDX-License-Identifier: BSD-3-Clause 5 */ 6 7 #ifndef IDT_H 8 #define IDT_H 9 10 /* 11 * IDT is defined in assembly so we handle exceptions as early as possible. 12 */ 13 14 #ifndef ASSEMBLER 15 16 /* Number of the HOST IDT entries */ 17 #define HOST_IDT_ENTRIES (0x100U) 18 19 /* 20 * Definition of an 16 byte IDT selector. 21 */ 22 struct idt_64_descriptor { 23 union { 24 uint32_t value; 25 struct { 26 uint32_t offset_15_0:16; 27 uint32_t seg_sel:16; 28 } bits; 29 } low32; 30 union { 31 uint32_t value; 32 struct { 33 uint32_t ist:3; 34 uint32_t bit_3_clr:1; 35 uint32_t bit_4_clr:1; 36 uint32_t bits_5_7_clr:3; 37 uint32_t type:4; 38 uint32_t bit_12_clr:1; 39 uint32_t dpl:2; 40 uint32_t present:1; 41 uint32_t offset_31_16:16; 42 } bits; 43 } high32; 44 uint32_t offset_63_32; 45 uint32_t rsvd; 46 } __aligned(8); 47 48 /***************************************************************************** 49 * 50 * Definition of the IDT. 51 * 52 *****************************************************************************/ 53 struct host_idt { 54 struct idt_64_descriptor host_idt_descriptors[HOST_IDT_ENTRIES]; 55 } __aligned(8); 56 57 /* 58 * Definition of the IDT descriptor. 59 */ 60 struct host_idt_descriptor { 61 uint16_t len; 62 struct host_idt *idt; 63 } __packed; 64 65 extern struct host_idt HOST_IDT; 66 extern struct host_idt_descriptor HOST_IDTR; 67 68 #else /* ASSEMBLER */ 69 70 /* Interrupt Descriptor Table (LDT) selectors are 16 bytes on x86-64 instead of 8 bytes. */ 71 #define X64_IDT_DESC_SIZE (0x10) 72 /* Number of the HOST IDT entries */ 73 #define HOST_IDT_ENTRIES (0x100) 74 /* Size of the IDT */ 75 #define HOST_IDT_SIZE (HOST_IDT_ENTRIES * X64_IDT_DESC_SIZE) 76 77 #endif /* end #ifndef ASSEMBLER */ 78 79 #endif /* IDT_H */ 80