Glauber de Oliveira Costa | 80fbb69 | 2008-01-30 13:31:13 +0100 | [diff] [blame] | 1 | #ifndef _ASM_DESC_H_ |
| 2 | #define _ASM_DESC_H_ |
| 3 | |
| 4 | #ifndef __ASSEMBLY__ |
| 5 | #include <asm/desc_defs.h> |
| 6 | #include <asm/ldt.h> |
Glauber de Oliveira Costa | 881c297 | 2008-01-30 13:31:14 +0100 | [diff] [blame] | 7 | #include <asm/mmu.h> |
Glauber de Oliveira Costa | 80fbb69 | 2008-01-30 13:31:13 +0100 | [diff] [blame] | 8 | |
| 9 | static inline void fill_ldt(struct desc_struct *desc, struct user_desc *info) |
| 10 | { |
| 11 | desc->limit0 = info->limit & 0x0ffff; |
| 12 | desc->base0 = info->base_addr & 0x0000ffff; |
| 13 | |
| 14 | desc->base1 = (info->base_addr & 0x00ff0000) >> 16; |
| 15 | desc->type = (info->read_exec_only ^ 1) << 1; |
| 16 | desc->type |= info->contents << 2; |
| 17 | desc->s = 1; |
| 18 | desc->dpl = 0x3; |
| 19 | desc->p = info->seg_not_present ^ 1; |
| 20 | desc->limit = (info->limit & 0xf0000) >> 16; |
| 21 | desc->avl = info->useable; |
| 22 | desc->d = info->seg_32bit; |
| 23 | desc->g = info->limit_in_pages; |
| 24 | desc->base2 = (info->base_addr & 0xff000000) >> 24; |
| 25 | } |
| 26 | |
Glauber de Oliveira Costa | 881c297 | 2008-01-30 13:31:14 +0100 | [diff] [blame] | 27 | extern struct desc_ptr idt_descr; |
| 28 | extern gate_desc idt_table[]; |
Glauber de Oliveira Costa | 80fbb69 | 2008-01-30 13:31:13 +0100 | [diff] [blame] | 29 | |
Thomas Gleixner | 96a388d | 2007-10-11 11:20:03 +0200 | [diff] [blame] | 30 | #ifdef CONFIG_X86_32 |
| 31 | # include "desc_32.h" |
| 32 | #else |
| 33 | # include "desc_64.h" |
| 34 | #endif |
Glauber de Oliveira Costa | 80fbb69 | 2008-01-30 13:31:13 +0100 | [diff] [blame] | 35 | |
Glauber de Oliveira Costa | 881c297 | 2008-01-30 13:31:14 +0100 | [diff] [blame] | 36 | #define _LDT_empty(info) (\ |
| 37 | (info)->base_addr == 0 && \ |
| 38 | (info)->limit == 0 && \ |
| 39 | (info)->contents == 0 && \ |
| 40 | (info)->read_exec_only == 1 && \ |
| 41 | (info)->seg_32bit == 0 && \ |
| 42 | (info)->limit_in_pages == 0 && \ |
| 43 | (info)->seg_not_present == 1 && \ |
| 44 | (info)->useable == 0) |
| 45 | |
| 46 | #ifdef CONFIG_X86_64 |
| 47 | #define LDT_empty(info) (_LDT_empty(info) && ((info)->lm == 0)) |
| 48 | #else |
| 49 | #define LDT_empty(info) (_LDT_empty(info)) |
| 50 | #endif |
| 51 | |
| 52 | static inline void clear_LDT(void) |
| 53 | { |
| 54 | set_ldt(NULL, 0); |
| 55 | } |
| 56 | |
| 57 | /* |
| 58 | * load one particular LDT into the current CPU |
| 59 | */ |
| 60 | static inline void load_LDT_nolock(mm_context_t *pc) |
| 61 | { |
| 62 | set_ldt(pc->ldt, pc->size); |
| 63 | } |
| 64 | |
| 65 | static inline void load_LDT(mm_context_t *pc) |
| 66 | { |
| 67 | preempt_disable(); |
| 68 | load_LDT_nolock(pc); |
| 69 | preempt_enable(); |
| 70 | } |
| 71 | |
Glauber de Oliveira Costa | cc69785 | 2008-01-30 13:31:14 +0100 | [diff] [blame^] | 72 | static inline unsigned long get_desc_base(struct desc_struct *desc) |
| 73 | { |
| 74 | return desc->base0 | ((desc->base1) << 16) | ((desc->base2) << 24); |
| 75 | } |
| 76 | |
Glauber de Oliveira Costa | 881c297 | 2008-01-30 13:31:14 +0100 | [diff] [blame] | 77 | #else |
| 78 | /* |
| 79 | * GET_DESC_BASE reads the descriptor base of the specified segment. |
| 80 | * |
| 81 | * Args: |
| 82 | * idx - descriptor index |
| 83 | * gdt - GDT pointer |
| 84 | * base - 32bit register to which the base will be written |
| 85 | * lo_w - lo word of the "base" register |
| 86 | * lo_b - lo byte of the "base" register |
| 87 | * hi_b - hi byte of the low word of the "base" register |
| 88 | * |
| 89 | * Example: |
| 90 | * GET_DESC_BASE(GDT_ENTRY_ESPFIX_SS, %ebx, %eax, %ax, %al, %ah) |
| 91 | * Will read the base address of GDT_ENTRY_ESPFIX_SS and put it into %eax. |
| 92 | */ |
| 93 | #define GET_DESC_BASE(idx, gdt, base, lo_w, lo_b, hi_b) \ |
| 94 | movb idx*8+4(gdt), lo_b; \ |
| 95 | movb idx*8+7(gdt), hi_b; \ |
| 96 | shll $16, base; \ |
| 97 | movw idx*8+2(gdt), lo_w; |
| 98 | |
| 99 | |
| 100 | #endif /* __ASSEMBLY__ */ |
| 101 | |
Glauber de Oliveira Costa | 80fbb69 | 2008-01-30 13:31:13 +0100 | [diff] [blame] | 102 | #endif |