desc_defs.h 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. /* Written 2000 by Andi Kleen */
  2. #ifndef _ASM_X86_DESC_DEFS_H
  3. #define _ASM_X86_DESC_DEFS_H
  4. /*
  5. * Segment descriptor structure definitions, usable from both x86_64 and i386
  6. * archs.
  7. */
  8. #ifndef __ASSEMBLY__
  9. #include <linux/types.h>
  10. /*
  11. * FIXME: Accessing the desc_struct through its fields is more elegant,
  12. * and should be the one valid thing to do. However, a lot of open code
  13. * still touches the a and b accessors, and doing this allow us to do it
  14. * incrementally. We keep the signature as a struct, rather than an union,
  15. * so we can get rid of it transparently in the future -- glommer
  16. */
  17. /* 8 byte segment descriptor */
  18. struct desc_struct {
  19. union {
  20. struct {
  21. unsigned int a;
  22. unsigned int b;
  23. };
  24. struct {
  25. u16 limit0;
  26. u16 base0;
  27. unsigned base1: 8, type: 4, s: 1, dpl: 2, p: 1;
  28. unsigned limit: 4, avl: 1, l: 1, d: 1, g: 1, base2: 8;
  29. };
  30. };
  31. } __attribute__((packed));
  32. #define GDT_ENTRY_INIT(flags, base, limit) { { { \
  33. .a = ((limit) & 0xffff) | (((base) & 0xffff) << 16), \
  34. .b = (((base) & 0xff0000) >> 16) | (((flags) & 0xf0ff) << 8) | \
  35. ((limit) & 0xf0000) | ((base) & 0xff000000), \
  36. } } }
  37. enum {
  38. GATE_INTERRUPT = 0xE,
  39. GATE_TRAP = 0xF,
  40. GATE_CALL = 0xC,
  41. GATE_TASK = 0x5,
  42. };
  43. /* 16byte gate */
  44. struct gate_struct64 {
  45. u16 offset_low;
  46. u16 segment;
  47. unsigned ist : 3, zero0 : 5, type : 5, dpl : 2, p : 1;
  48. u16 offset_middle;
  49. u32 offset_high;
  50. u32 zero1;
  51. } __attribute__((packed));
  52. #define PTR_LOW(x) ((unsigned long long)(x) & 0xFFFF)
  53. #define PTR_MIDDLE(x) (((unsigned long long)(x) >> 16) & 0xFFFF)
  54. #define PTR_HIGH(x) ((unsigned long long)(x) >> 32)
  55. enum {
  56. DESC_TSS = 0x9,
  57. DESC_LDT = 0x2,
  58. DESCTYPE_S = 0x10, /* !system */
  59. };
  60. /* LDT or TSS descriptor in the GDT. 16 bytes. */
  61. struct ldttss_desc64 {
  62. u16 limit0;
  63. u16 base0;
  64. unsigned base1 : 8, type : 5, dpl : 2, p : 1;
  65. unsigned limit1 : 4, zero0 : 3, g : 1, base2 : 8;
  66. u32 base3;
  67. u32 zero1;
  68. } __attribute__((packed));
  69. #ifdef CONFIG_X86_64
  70. typedef struct gate_struct64 gate_desc;
  71. typedef struct ldttss_desc64 ldt_desc;
  72. typedef struct ldttss_desc64 tss_desc;
  73. #define gate_offset(g) ((g).offset_low | ((unsigned long)(g).offset_middle << 16) | ((unsigned long)(g).offset_high << 32))
  74. #define gate_segment(g) ((g).segment)
  75. #else
  76. typedef struct desc_struct gate_desc;
  77. typedef struct desc_struct ldt_desc;
  78. typedef struct desc_struct tss_desc;
  79. #define gate_offset(g) (((g).b & 0xffff0000) | ((g).a & 0x0000ffff))
  80. #define gate_segment(g) ((g).a >> 16)
  81. #endif
  82. struct desc_ptr {
  83. unsigned short size;
  84. unsigned long address;
  85. } __attribute__((packed)) ;
  86. #endif /* !__ASSEMBLY__ */
  87. #endif /* _ASM_X86_DESC_DEFS_H */