0001
0002
0003 #ifndef _ASM_X86_DESC_DEFS_H
0004 #define _ASM_X86_DESC_DEFS_H
0005
0006
0007
0008
0009
0010
0011 #ifndef __ASSEMBLY__
0012
0013 #include <linux/types.h>
0014
0015
0016 struct desc_struct {
0017 u16 limit0;
0018 u16 base0;
0019 u16 base1: 8, type: 4, s: 1, dpl: 2, p: 1;
0020 u16 limit1: 4, avl: 1, l: 1, d: 1, g: 1, base2: 8;
0021 } __attribute__((packed));
0022
0023 #define GDT_ENTRY_INIT(flags, base, limit) \
0024 { \
0025 .limit0 = (u16) (limit), \
0026 .limit1 = ((limit) >> 16) & 0x0F, \
0027 .base0 = (u16) (base), \
0028 .base1 = ((base) >> 16) & 0xFF, \
0029 .base2 = ((base) >> 24) & 0xFF, \
0030 .type = (flags & 0x0f), \
0031 .s = (flags >> 4) & 0x01, \
0032 .dpl = (flags >> 5) & 0x03, \
0033 .p = (flags >> 7) & 0x01, \
0034 .avl = (flags >> 12) & 0x01, \
0035 .l = (flags >> 13) & 0x01, \
0036 .d = (flags >> 14) & 0x01, \
0037 .g = (flags >> 15) & 0x01, \
0038 }
0039
0040 enum {
0041 GATE_INTERRUPT = 0xE,
0042 GATE_TRAP = 0xF,
0043 GATE_CALL = 0xC,
0044 GATE_TASK = 0x5,
0045 };
0046
0047 enum {
0048 DESC_TSS = 0x9,
0049 DESC_LDT = 0x2,
0050 DESCTYPE_S = 0x10,
0051 };
0052
0053
0054 struct ldttss_desc {
0055 u16 limit0;
0056 u16 base0;
0057
0058 u16 base1 : 8, type : 5, dpl : 2, p : 1;
0059 u16 limit1 : 4, zero0 : 3, g : 1, base2 : 8;
0060 #ifdef CONFIG_X86_64
0061 u32 base3;
0062 u32 zero1;
0063 #endif
0064 } __attribute__((packed));
0065
0066 typedef struct ldttss_desc ldt_desc;
0067 typedef struct ldttss_desc tss_desc;
0068
0069 struct idt_bits {
0070 u16 ist : 3,
0071 zero : 5,
0072 type : 5,
0073 dpl : 2,
0074 p : 1;
0075 } __attribute__((packed));
0076
0077 struct idt_data {
0078 unsigned int vector;
0079 unsigned int segment;
0080 struct idt_bits bits;
0081 const void *addr;
0082 };
0083
0084 struct gate_struct {
0085 u16 offset_low;
0086 u16 segment;
0087 struct idt_bits bits;
0088 u16 offset_middle;
0089 #ifdef CONFIG_X86_64
0090 u32 offset_high;
0091 u32 reserved;
0092 #endif
0093 } __attribute__((packed));
0094
0095 typedef struct gate_struct gate_desc;
0096
0097 static inline unsigned long gate_offset(const gate_desc *g)
0098 {
0099 #ifdef CONFIG_X86_64
0100 return g->offset_low | ((unsigned long)g->offset_middle << 16) |
0101 ((unsigned long) g->offset_high << 32);
0102 #else
0103 return g->offset_low | ((unsigned long)g->offset_middle << 16);
0104 #endif
0105 }
0106
0107 static inline unsigned long gate_segment(const gate_desc *g)
0108 {
0109 return g->segment;
0110 }
0111
0112 struct desc_ptr {
0113 unsigned short size;
0114 unsigned long address;
0115 } __attribute__((packed)) ;
0116
0117 #endif
0118
0119
0120 #define BOOT_IDT_ENTRIES 32
0121
0122
0123 #define AR_TYPE_RODATA (0 * (1 << 9))
0124 #define AR_TYPE_RWDATA (1 * (1 << 9))
0125 #define AR_TYPE_RODATA_EXPDOWN (2 * (1 << 9))
0126 #define AR_TYPE_RWDATA_EXPDOWN (3 * (1 << 9))
0127 #define AR_TYPE_XOCODE (4 * (1 << 9))
0128 #define AR_TYPE_XRCODE (5 * (1 << 9))
0129 #define AR_TYPE_XOCODE_CONF (6 * (1 << 9))
0130 #define AR_TYPE_XRCODE_CONF (7 * (1 << 9))
0131 #define AR_TYPE_MASK (7 * (1 << 9))
0132
0133 #define AR_DPL0 (0 * (1 << 13))
0134 #define AR_DPL3 (3 * (1 << 13))
0135 #define AR_DPL_MASK (3 * (1 << 13))
0136
0137 #define AR_A (1 << 8)
0138 #define AR_S (1 << 12)
0139 #define AR_P (1 << 15)
0140 #define AR_AVL (1 << 20)
0141 #define AR_L (1 << 21)
0142 #define AR_DB (1 << 22)
0143 #define AR_G (1 << 23)
0144
0145 #endif