desc.h 2.2 KB

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