1 /* Written 2000 by Andi Kleen */ 2 #ifndef _ASM_X86_DESC_DEFS_H 3 #define _ASM_X86_DESC_DEFS_H 4 5 /* 6 * Segment descriptor structure definitions, usable from both x86_64 and i386 7 * archs. 8 */ 9 10 #ifndef __ASSEMBLY__ 11 12 #include <linux/types.h> 13 14 /* 8 byte segment descriptor */ 15 struct desc_struct { 16 u16 limit0; 17 u16 base0; 18 u16 base1: 8, type: 4, s: 1, dpl: 2, p: 1; 19 u16 limit1: 4, avl: 1, l: 1, d: 1, g: 1, base2: 8; 20 } __attribute__((packed)); 21 22 #define GDT_ENTRY_INIT(flags, base, limit) \ 23 { \ 24 .limit0 = (u16) (limit), \ 25 .limit1 = ((limit) >> 16) & 0x0F, \ 26 .base0 = (u16) (base), \ 27 .base1 = ((base) >> 16) & 0xFF, \ 28 .base2 = ((base) >> 24) & 0xFF, \ 29 .type = (flags & 0x0f), \ 30 .s = (flags >> 4) & 0x01, \ 31 .dpl = (flags >> 5) & 0x03, \ 32 .p = (flags >> 7) & 0x01, \ 33 .avl = (flags >> 12) & 0x01, \ 34 .l = (flags >> 13) & 0x01, \ 35 .d = (flags >> 14) & 0x01, \ 36 .g = (flags >> 15) & 0x01, \ 37 } 38 39 enum { 40 GATE_INTERRUPT = 0xE, 41 GATE_TRAP = 0xF, 42 GATE_CALL = 0xC, 43 GATE_TASK = 0x5, 44 }; 45 46 enum { 47 DESC_TSS = 0x9, 48 DESC_LDT = 0x2, 49 DESCTYPE_S = 0x10, /* !system */ 50 }; 51 52 /* LDT or TSS descriptor in the GDT. */ 53 struct ldttss_desc { 54 u16 limit0; 55 u16 base0; 56 57 u16 base1 : 8, type : 5, dpl : 2, p : 1; 58 u16 limit1 : 4, zero0 : 3, g : 1, base2 : 8; 59 #ifdef CONFIG_X86_64 60 u32 base3; 61 u32 zero1; 62 #endif 63 } __attribute__((packed)); 64 65 typedef struct ldttss_desc ldt_desc; 66 typedef struct ldttss_desc tss_desc; 67 68 struct idt_bits { 69 u16 ist : 3, 70 zero : 5, 71 type : 5, 72 dpl : 2, 73 p : 1; 74 } __attribute__((packed)); 75 76 struct gate_struct { 77 u16 offset_low; 78 u16 segment; 79 struct idt_bits bits; 80 u16 offset_middle; 81 #ifdef CONFIG_X86_64 82 u32 offset_high; 83 u32 reserved; 84 #endif 85 } __attribute__((packed)); 86 87 typedef struct gate_struct gate_desc; 88 89 static inline unsigned long gate_offset(const gate_desc *g) 90 { 91 #ifdef CONFIG_X86_64 92 return g->offset_low | ((unsigned long)g->offset_middle << 16) | 93 ((unsigned long) g->offset_high << 32); 94 #else 95 return g->offset_low | ((unsigned long)g->offset_middle << 16); 96 #endif 97 } 98 99 static inline unsigned long gate_segment(const gate_desc *g) 100 { 101 return g->segment; 102 } 103 104 struct desc_ptr { 105 unsigned short size; 106 unsigned long address; 107 } __attribute__((packed)) ; 108 109 #endif /* !__ASSEMBLY__ */ 110 111 /* Access rights as returned by LAR */ 112 #define AR_TYPE_RODATA (0 * (1 << 9)) 113 #define AR_TYPE_RWDATA (1 * (1 << 9)) 114 #define AR_TYPE_RODATA_EXPDOWN (2 * (1 << 9)) 115 #define AR_TYPE_RWDATA_EXPDOWN (3 * (1 << 9)) 116 #define AR_TYPE_XOCODE (4 * (1 << 9)) 117 #define AR_TYPE_XRCODE (5 * (1 << 9)) 118 #define AR_TYPE_XOCODE_CONF (6 * (1 << 9)) 119 #define AR_TYPE_XRCODE_CONF (7 * (1 << 9)) 120 #define AR_TYPE_MASK (7 * (1 << 9)) 121 122 #define AR_DPL0 (0 * (1 << 13)) 123 #define AR_DPL3 (3 * (1 << 13)) 124 #define AR_DPL_MASK (3 * (1 << 13)) 125 126 #define AR_A (1 << 8) /* "Accessed" */ 127 #define AR_S (1 << 12) /* If clear, "System" segment */ 128 #define AR_P (1 << 15) /* "Present" */ 129 #define AR_AVL (1 << 20) /* "AVaiLable" (no HW effect) */ 130 #define AR_L (1 << 21) /* "Long mode" for code segments */ 131 #define AR_DB (1 << 22) /* D/B, effect depends on type */ 132 #define AR_G (1 << 23) /* "Granularity" (limit in pages) */ 133 134 #endif /* _ASM_X86_DESC_DEFS_H */ 135