| Avi Kivity | 249e83f | 2006-12-07 02:14:04 +0100 | [diff] [blame] | 1 | /* Written 2000 by Andi Kleen */ | 
 | 2 | #ifndef __ARCH_DESC_DEFS_H | 
 | 3 | #define __ARCH_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 |  | 
| Glauber de Oliveira Costa | 6842ef0 | 2008-01-30 13:31:11 +0100 | [diff] [blame] | 14 | /* | 
 | 15 |  * FIXME: Acessing the desc_struct through its fields is more elegant, | 
 | 16 |  * and should be the one valid thing to do. However, a lot of open code | 
 | 17 |  * still touches the a and b acessors, and doing this allow us to do it | 
 | 18 |  * incrementally. We keep the signature as a struct, rather than an union, | 
 | 19 |  * so we can get rid of it transparently in the future -- glommer | 
 | 20 |  */ | 
| Avi Kivity | 249e83f | 2006-12-07 02:14:04 +0100 | [diff] [blame] | 21 | // 8 byte segment descriptor | 
 | 22 | struct desc_struct { | 
| Glauber de Oliveira Costa | 6842ef0 | 2008-01-30 13:31:11 +0100 | [diff] [blame] | 23 | 	union { | 
 | 24 | 		struct { unsigned int a, b; }; | 
 | 25 | 		struct { | 
 | 26 | 			u16 limit0; | 
 | 27 | 			u16 base0; | 
 | 28 | 			unsigned base1: 8, type: 4, s: 1, dpl: 2, p: 1; | 
 | 29 | 			unsigned limit: 4, avl: 1, l: 1, d: 1, g: 1, base2: 8; | 
 | 30 | 		}; | 
| Avi Kivity | 249e83f | 2006-12-07 02:14:04 +0100 | [diff] [blame] | 31 |  | 
| Glauber de Oliveira Costa | 6842ef0 | 2008-01-30 13:31:11 +0100 | [diff] [blame] | 32 | 	}; | 
 | 33 | } __attribute__((packed)); | 
| Avi Kivity | 249e83f | 2006-12-07 02:14:04 +0100 | [diff] [blame] | 34 |  | 
 | 35 | enum { | 
 | 36 | 	GATE_INTERRUPT = 0xE, | 
 | 37 | 	GATE_TRAP = 0xF, | 
 | 38 | 	GATE_CALL = 0xC, | 
| Glauber de Oliveira Costa | 507f90c | 2008-01-30 13:31:14 +0100 | [diff] [blame] | 39 | 	GATE_TASK = 0x5, | 
| Avi Kivity | 249e83f | 2006-12-07 02:14:04 +0100 | [diff] [blame] | 40 | }; | 
 | 41 |  | 
 | 42 | // 16byte gate | 
| Glauber de Oliveira Costa | 010d4f8 | 2008-01-30 13:31:12 +0100 | [diff] [blame] | 43 | struct gate_struct64 { | 
| Avi Kivity | 249e83f | 2006-12-07 02:14:04 +0100 | [diff] [blame] | 44 | 	u16 offset_low; | 
 | 45 | 	u16 segment; | 
 | 46 | 	unsigned ist : 3, zero0 : 5, type : 5, dpl : 2, p : 1; | 
 | 47 | 	u16 offset_middle; | 
 | 48 | 	u32 offset_high; | 
 | 49 | 	u32 zero1; | 
 | 50 | } __attribute__((packed)); | 
 | 51 |  | 
| Glauber de Oliveira Costa | 54cd0ea | 2008-01-30 13:31:14 +0100 | [diff] [blame] | 52 | #define PTR_LOW(x) ((unsigned long long)(x) & 0xFFFF) | 
 | 53 | #define PTR_MIDDLE(x) (((unsigned long long)(x) >> 16) & 0xFFFF) | 
 | 54 | #define PTR_HIGH(x) ((unsigned long long)(x) >> 32) | 
| Avi Kivity | 249e83f | 2006-12-07 02:14:04 +0100 | [diff] [blame] | 55 |  | 
 | 56 | enum { | 
 | 57 | 	DESC_TSS = 0x9, | 
 | 58 | 	DESC_LDT = 0x2, | 
| Glauber de Oliveira Costa | 59fbed7 | 2008-01-30 13:31:14 +0100 | [diff] [blame] | 59 | 	DESCTYPE_S =	0x10,	/* !system */ | 
| Avi Kivity | 249e83f | 2006-12-07 02:14:04 +0100 | [diff] [blame] | 60 | }; | 
 | 61 |  | 
 | 62 | // LDT or TSS descriptor in the GDT. 16 bytes. | 
| Glauber de Oliveira Costa | 25deca5 | 2008-01-30 13:31:13 +0100 | [diff] [blame] | 63 | struct ldttss_desc64 { | 
| Avi Kivity | 249e83f | 2006-12-07 02:14:04 +0100 | [diff] [blame] | 64 | 	u16 limit0; | 
 | 65 | 	u16 base0; | 
 | 66 | 	unsigned base1 : 8, type : 5, dpl : 2, p : 1; | 
 | 67 | 	unsigned limit1 : 4, zero0 : 3, g : 1, base2 : 8; | 
 | 68 | 	u32 base3; | 
 | 69 | 	u32 zero1; | 
 | 70 | } __attribute__((packed)); | 
 | 71 |  | 
| Glauber de Oliveira Costa | 010d4f8 | 2008-01-30 13:31:12 +0100 | [diff] [blame] | 72 | #ifdef CONFIG_X86_64 | 
 | 73 | typedef struct gate_struct64 gate_desc; | 
| Glauber de Oliveira Costa | 25deca5 | 2008-01-30 13:31:13 +0100 | [diff] [blame] | 74 | typedef struct ldttss_desc64 ldt_desc; | 
| Glauber de Oliveira Costa | 18245d5 | 2008-01-30 13:31:13 +0100 | [diff] [blame] | 75 | typedef struct ldttss_desc64 tss_desc; | 
| Glauber de Oliveira Costa | 010d4f8 | 2008-01-30 13:31:12 +0100 | [diff] [blame] | 76 | #else | 
 | 77 | typedef struct desc_struct gate_desc; | 
| Glauber de Oliveira Costa | 25deca5 | 2008-01-30 13:31:13 +0100 | [diff] [blame] | 78 | typedef struct desc_struct ldt_desc; | 
| Glauber de Oliveira Costa | 18245d5 | 2008-01-30 13:31:13 +0100 | [diff] [blame] | 79 | typedef struct desc_struct tss_desc; | 
| Glauber de Oliveira Costa | 010d4f8 | 2008-01-30 13:31:12 +0100 | [diff] [blame] | 80 | #endif | 
 | 81 |  | 
| Avi Kivity | 249e83f | 2006-12-07 02:14:04 +0100 | [diff] [blame] | 82 | struct desc_ptr { | 
 | 83 | 	unsigned short size; | 
 | 84 | 	unsigned long address; | 
 | 85 | } __attribute__((packed)) ; | 
 | 86 |  | 
 | 87 |  | 
 | 88 | #endif /* !__ASSEMBLY__ */ | 
 | 89 |  | 
 | 90 | #endif |