desc_defs.h 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. /* Written 2000 by Andi Kleen */
  2. #ifndef __ARCH_DESC_DEFS_H
  3. #define __ARCH_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: Acessing 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 acessors, 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 { unsigned int a, b; };
  21. struct {
  22. u16 limit0;
  23. u16 base0;
  24. unsigned base1: 8, type: 4, s: 1, dpl: 2, p: 1;
  25. unsigned limit: 4, avl: 1, l: 1, d: 1, g: 1, base2: 8;
  26. };
  27. };
  28. } __attribute__((packed));
  29. enum {
  30. GATE_INTERRUPT = 0xE,
  31. GATE_TRAP = 0xF,
  32. GATE_CALL = 0xC,
  33. GATE_TASK = 0x5,
  34. };
  35. // 16byte gate
  36. struct gate_struct64 {
  37. u16 offset_low;
  38. u16 segment;
  39. unsigned ist : 3, zero0 : 5, type : 5, dpl : 2, p : 1;
  40. u16 offset_middle;
  41. u32 offset_high;
  42. u32 zero1;
  43. } __attribute__((packed));
  44. #define PTR_LOW(x) ((unsigned long long)(x) & 0xFFFF)
  45. #define PTR_MIDDLE(x) (((unsigned long long)(x) >> 16) & 0xFFFF)
  46. #define PTR_HIGH(x) ((unsigned long long)(x) >> 32)
  47. enum {
  48. DESC_TSS = 0x9,
  49. DESC_LDT = 0x2,
  50. DESCTYPE_S = 0x10, /* !system */
  51. };
  52. // LDT or TSS descriptor in the GDT. 16 bytes.
  53. struct ldttss_desc64 {
  54. u16 limit0;
  55. u16 base0;
  56. unsigned base1 : 8, type : 5, dpl : 2, p : 1;
  57. unsigned limit1 : 4, zero0 : 3, g : 1, base2 : 8;
  58. u32 base3;
  59. u32 zero1;
  60. } __attribute__((packed));
  61. #ifdef CONFIG_X86_64
  62. typedef struct gate_struct64 gate_desc;
  63. typedef struct ldttss_desc64 ldt_desc;
  64. typedef struct ldttss_desc64 tss_desc;
  65. #else
  66. typedef struct desc_struct gate_desc;
  67. typedef struct desc_struct ldt_desc;
  68. typedef struct desc_struct tss_desc;
  69. #endif
  70. struct desc_ptr {
  71. unsigned short size;
  72. unsigned long address;
  73. } __attribute__((packed)) ;
  74. #endif /* !__ASSEMBLY__ */
  75. #endif