Avi Kivity | 249e83f | 2006-12-07 02:14:04 +0100 | [diff] [blame] | 1 | /* Written 2000 by Andi Kleen */ |
Vegard Nossum | 77ef50a | 2008-06-18 17:08:48 +0200 | [diff] [blame] | 2 | #ifndef ASM_X86__DESC_DEFS_H |
| 3 | #define ASM_X86__DESC_DEFS_H |
Avi Kivity | 249e83f | 2006-12-07 02:14:04 +0100 | [diff] [blame] | 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 | */ |
Joe Perches | b776190 | 2008-03-23 01:01:57 -0700 | [diff] [blame] | 21 | /* 8 byte segment descriptor */ |
Avi Kivity | 249e83f | 2006-12-07 02:14:04 +0100 | [diff] [blame] | 22 | struct desc_struct { |
Glauber de Oliveira Costa | 6842ef0 | 2008-01-30 13:31:11 +0100 | [diff] [blame] | 23 | union { |
Joe Perches | b776190 | 2008-03-23 01:01:57 -0700 | [diff] [blame] | 24 | struct { |
| 25 | unsigned int a; |
| 26 | unsigned int b; |
| 27 | }; |
Glauber de Oliveira Costa | 6842ef0 | 2008-01-30 13:31:11 +0100 | [diff] [blame] | 28 | struct { |
| 29 | u16 limit0; |
| 30 | u16 base0; |
| 31 | unsigned base1: 8, type: 4, s: 1, dpl: 2, p: 1; |
| 32 | unsigned limit: 4, avl: 1, l: 1, d: 1, g: 1, base2: 8; |
| 33 | }; |
Glauber de Oliveira Costa | 6842ef0 | 2008-01-30 13:31:11 +0100 | [diff] [blame] | 34 | }; |
| 35 | } __attribute__((packed)); |
Avi Kivity | 249e83f | 2006-12-07 02:14:04 +0100 | [diff] [blame] | 36 | |
| 37 | enum { |
| 38 | GATE_INTERRUPT = 0xE, |
| 39 | GATE_TRAP = 0xF, |
| 40 | GATE_CALL = 0xC, |
Glauber de Oliveira Costa | 507f90c | 2008-01-30 13:31:14 +0100 | [diff] [blame] | 41 | GATE_TASK = 0x5, |
Avi Kivity | 249e83f | 2006-12-07 02:14:04 +0100 | [diff] [blame] | 42 | }; |
| 43 | |
Joe Perches | b776190 | 2008-03-23 01:01:57 -0700 | [diff] [blame] | 44 | /* 16byte gate */ |
Glauber de Oliveira Costa | 010d4f8 | 2008-01-30 13:31:12 +0100 | [diff] [blame] | 45 | struct gate_struct64 { |
Avi Kivity | 249e83f | 2006-12-07 02:14:04 +0100 | [diff] [blame] | 46 | u16 offset_low; |
| 47 | u16 segment; |
| 48 | unsigned ist : 3, zero0 : 5, type : 5, dpl : 2, p : 1; |
| 49 | u16 offset_middle; |
| 50 | u32 offset_high; |
| 51 | u32 zero1; |
| 52 | } __attribute__((packed)); |
| 53 | |
Glauber de Oliveira Costa | 54cd0ea | 2008-01-30 13:31:14 +0100 | [diff] [blame] | 54 | #define PTR_LOW(x) ((unsigned long long)(x) & 0xFFFF) |
| 55 | #define PTR_MIDDLE(x) (((unsigned long long)(x) >> 16) & 0xFFFF) |
| 56 | #define PTR_HIGH(x) ((unsigned long long)(x) >> 32) |
Avi Kivity | 249e83f | 2006-12-07 02:14:04 +0100 | [diff] [blame] | 57 | |
| 58 | enum { |
| 59 | DESC_TSS = 0x9, |
| 60 | DESC_LDT = 0x2, |
Joe Perches | b776190 | 2008-03-23 01:01:57 -0700 | [diff] [blame] | 61 | DESCTYPE_S = 0x10, /* !system */ |
Avi Kivity | 249e83f | 2006-12-07 02:14:04 +0100 | [diff] [blame] | 62 | }; |
| 63 | |
Joe Perches | b776190 | 2008-03-23 01:01:57 -0700 | [diff] [blame] | 64 | /* LDT or TSS descriptor in the GDT. 16 bytes. */ |
Glauber de Oliveira Costa | 25deca5 | 2008-01-30 13:31:13 +0100 | [diff] [blame] | 65 | struct ldttss_desc64 { |
Avi Kivity | 249e83f | 2006-12-07 02:14:04 +0100 | [diff] [blame] | 66 | u16 limit0; |
| 67 | u16 base0; |
| 68 | unsigned base1 : 8, type : 5, dpl : 2, p : 1; |
| 69 | unsigned limit1 : 4, zero0 : 3, g : 1, base2 : 8; |
| 70 | u32 base3; |
| 71 | u32 zero1; |
| 72 | } __attribute__((packed)); |
| 73 | |
Glauber de Oliveira Costa | 010d4f8 | 2008-01-30 13:31:12 +0100 | [diff] [blame] | 74 | #ifdef CONFIG_X86_64 |
| 75 | typedef struct gate_struct64 gate_desc; |
Glauber de Oliveira Costa | 25deca5 | 2008-01-30 13:31:13 +0100 | [diff] [blame] | 76 | typedef struct ldttss_desc64 ldt_desc; |
Glauber de Oliveira Costa | 18245d5 | 2008-01-30 13:31:13 +0100 | [diff] [blame] | 77 | typedef struct ldttss_desc64 tss_desc; |
Jeremy Fitzhardinge | 43adfc2 | 2008-06-25 00:19:04 -0400 | [diff] [blame] | 78 | #define gate_offset(g) ((g).offset_low | ((unsigned long)(g).offset_middle << 16) | ((unsigned long)(g).offset_high << 32)) |
| 79 | #define gate_segment(g) ((g).segment) |
Glauber de Oliveira Costa | 010d4f8 | 2008-01-30 13:31:12 +0100 | [diff] [blame] | 80 | #else |
| 81 | typedef struct desc_struct gate_desc; |
Glauber de Oliveira Costa | 25deca5 | 2008-01-30 13:31:13 +0100 | [diff] [blame] | 82 | typedef struct desc_struct ldt_desc; |
Glauber de Oliveira Costa | 18245d5 | 2008-01-30 13:31:13 +0100 | [diff] [blame] | 83 | typedef struct desc_struct tss_desc; |
Jeremy Fitzhardinge | 43adfc2 | 2008-06-25 00:19:04 -0400 | [diff] [blame] | 84 | #define gate_offset(g) (((g).b & 0xffff0000) | ((g).a & 0x0000ffff)) |
| 85 | #define gate_segment(g) ((g).a >> 16) |
Glauber de Oliveira Costa | 010d4f8 | 2008-01-30 13:31:12 +0100 | [diff] [blame] | 86 | #endif |
| 87 | |
Avi Kivity | 249e83f | 2006-12-07 02:14:04 +0100 | [diff] [blame] | 88 | struct desc_ptr { |
| 89 | unsigned short size; |
| 90 | unsigned long address; |
| 91 | } __attribute__((packed)) ; |
| 92 | |
Avi Kivity | 249e83f | 2006-12-07 02:14:04 +0100 | [diff] [blame] | 93 | #endif /* !__ASSEMBLY__ */ |
| 94 | |
Vegard Nossum | 77ef50a | 2008-06-18 17:08:48 +0200 | [diff] [blame] | 95 | #endif /* ASM_X86__DESC_DEFS_H */ |