desc.h 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  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. static inline unsigned long get_desc_base(struct desc_struct *desc)
  62. {
  63. return desc->base0 | ((desc->base1) << 16) | ((desc->base2) << 24);
  64. }
  65. #else
  66. /*
  67. * GET_DESC_BASE reads the descriptor base of the specified segment.
  68. *
  69. * Args:
  70. * idx - descriptor index
  71. * gdt - GDT pointer
  72. * base - 32bit register to which the base will be written
  73. * lo_w - lo word of the "base" register
  74. * lo_b - lo byte of the "base" register
  75. * hi_b - hi byte of the low word of the "base" register
  76. *
  77. * Example:
  78. * GET_DESC_BASE(GDT_ENTRY_ESPFIX_SS, %ebx, %eax, %ax, %al, %ah)
  79. * Will read the base address of GDT_ENTRY_ESPFIX_SS and put it into %eax.
  80. */
  81. #define GET_DESC_BASE(idx, gdt, base, lo_w, lo_b, hi_b) \
  82. movb idx*8+4(gdt), lo_b; \
  83. movb idx*8+7(gdt), hi_b; \
  84. shll $16, base; \
  85. movw idx*8+2(gdt), lo_w;
  86. #endif /* __ASSEMBLY__ */
  87. #endif