desc.h 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144
  1. #ifndef __ARCH_DESC_H
  2. #define __ARCH_DESC_H
  3. #include <asm/ldt.h>
  4. #include <asm/segment.h>
  5. #define CPU_16BIT_STACK_SIZE 1024
  6. #ifndef __ASSEMBLY__
  7. #include <linux/preempt.h>
  8. #include <linux/smp.h>
  9. #include <linux/percpu.h>
  10. #include <asm/mmu.h>
  11. extern struct desc_struct cpu_gdt_table[GDT_ENTRIES];
  12. DECLARE_PER_CPU(struct desc_struct, cpu_gdt_table[GDT_ENTRIES]);
  13. DECLARE_PER_CPU(unsigned char, cpu_16bit_stack[CPU_16BIT_STACK_SIZE]);
  14. struct Xgt_desc_struct {
  15. unsigned short size;
  16. unsigned long address __attribute__((packed));
  17. unsigned short pad;
  18. } __attribute__ ((packed));
  19. extern struct Xgt_desc_struct idt_descr, cpu_gdt_descr[NR_CPUS];
  20. #define load_TR_desc() __asm__ __volatile__("ltr %%ax"::"a" (GDT_ENTRY_TSS*8))
  21. #define load_LDT_desc() __asm__ __volatile__("lldt %%ax"::"a" (GDT_ENTRY_LDT*8))
  22. /*
  23. * This is the ldt that every process will get unless we need
  24. * something other than this.
  25. */
  26. extern struct desc_struct default_ldt[];
  27. extern void set_intr_gate(unsigned int irq, void * addr);
  28. #define _set_tssldt_desc(n,addr,limit,type) \
  29. __asm__ __volatile__ ("movw %w3,0(%2)\n\t" \
  30. "movw %%ax,2(%2)\n\t" \
  31. "rorl $16,%%eax\n\t" \
  32. "movb %%al,4(%2)\n\t" \
  33. "movb %4,5(%2)\n\t" \
  34. "movb $0,6(%2)\n\t" \
  35. "movb %%ah,7(%2)\n\t" \
  36. "rorl $16,%%eax" \
  37. : "=m"(*(n)) : "a" (addr), "r"(n), "ir"(limit), "i"(type))
  38. static inline void __set_tss_desc(unsigned int cpu, unsigned int entry, void *addr)
  39. {
  40. _set_tssldt_desc(&per_cpu(cpu_gdt_table, cpu)[entry], (int)addr,
  41. offsetof(struct tss_struct, __cacheline_filler) - 1, 0x89);
  42. }
  43. #define set_tss_desc(cpu,addr) __set_tss_desc(cpu, GDT_ENTRY_TSS, addr)
  44. static inline void set_ldt_desc(unsigned int cpu, void *addr, unsigned int size)
  45. {
  46. _set_tssldt_desc(&per_cpu(cpu_gdt_table, cpu)[GDT_ENTRY_LDT], (int)addr, ((size << 3)-1), 0x82);
  47. }
  48. #define LDT_entry_a(info) \
  49. ((((info)->base_addr & 0x0000ffff) << 16) | ((info)->limit & 0x0ffff))
  50. #define LDT_entry_b(info) \
  51. (((info)->base_addr & 0xff000000) | \
  52. (((info)->base_addr & 0x00ff0000) >> 16) | \
  53. ((info)->limit & 0xf0000) | \
  54. (((info)->read_exec_only ^ 1) << 9) | \
  55. ((info)->contents << 10) | \
  56. (((info)->seg_not_present ^ 1) << 15) | \
  57. ((info)->seg_32bit << 22) | \
  58. ((info)->limit_in_pages << 23) | \
  59. ((info)->useable << 20) | \
  60. 0x7000)
  61. #define LDT_empty(info) (\
  62. (info)->base_addr == 0 && \
  63. (info)->limit == 0 && \
  64. (info)->contents == 0 && \
  65. (info)->read_exec_only == 1 && \
  66. (info)->seg_32bit == 0 && \
  67. (info)->limit_in_pages == 0 && \
  68. (info)->seg_not_present == 1 && \
  69. (info)->useable == 0 )
  70. #if TLS_SIZE != 24
  71. # error update this code.
  72. #endif
  73. static inline void load_TLS(struct thread_struct *t, unsigned int cpu)
  74. {
  75. #define C(i) per_cpu(cpu_gdt_table, cpu)[GDT_ENTRY_TLS_MIN + i] = t->tls_array[i]
  76. C(0); C(1); C(2);
  77. #undef C
  78. }
  79. static inline void clear_LDT(void)
  80. {
  81. int cpu = get_cpu();
  82. set_ldt_desc(cpu, &default_ldt[0], 5);
  83. load_LDT_desc();
  84. put_cpu();
  85. }
  86. /*
  87. * load one particular LDT into the current CPU
  88. */
  89. static inline void load_LDT_nolock(mm_context_t *pc, int cpu)
  90. {
  91. void *segments = pc->ldt;
  92. int count = pc->size;
  93. if (likely(!count)) {
  94. segments = &default_ldt[0];
  95. count = 5;
  96. }
  97. set_ldt_desc(cpu, segments, count);
  98. load_LDT_desc();
  99. }
  100. static inline void load_LDT(mm_context_t *pc)
  101. {
  102. int cpu = get_cpu();
  103. load_LDT_nolock(pc, cpu);
  104. put_cpu();
  105. }
  106. static inline unsigned long get_desc_base(unsigned long *desc)
  107. {
  108. unsigned long base;
  109. base = ((desc[0] >> 16) & 0x0000ffff) |
  110. ((desc[1] << 16) & 0x00ff0000) |
  111. (desc[1] & 0xff000000);
  112. return base;
  113. }
  114. #endif /* !__ASSEMBLY__ */
  115. #endif