desc_defs.h 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  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. };
  34. // 16byte gate
  35. struct gate_struct64 {
  36. u16 offset_low;
  37. u16 segment;
  38. unsigned ist : 3, zero0 : 5, type : 5, dpl : 2, p : 1;
  39. u16 offset_middle;
  40. u32 offset_high;
  41. u32 zero1;
  42. } __attribute__((packed));
  43. #define PTR_LOW(x) ((unsigned long long)(x) & 0xFFFF)
  44. #define PTR_MIDDLE(x) (((unsigned long long)(x) >> 16) & 0xFFFF)
  45. #define PTR_HIGH(x) ((unsigned long long)(x) >> 32)
  46. enum {
  47. DESC_TSS = 0x9,
  48. DESC_LDT = 0x2,
  49. DESCTYPE_TASK = 0x85, /* present, system, DPL-0, task gate */
  50. DESCTYPE_INT = 0x8e, /* present, system, DPL-0, interrupt gate */
  51. DESCTYPE_TRAP = 0x8f, /* present, system, DPL-0, trap gate */
  52. DESCTYPE_DPL3 = 0x60, /* DPL-3 */
  53. DESCTYPE_S = 0x10, /* !system */
  54. };
  55. // LDT or TSS descriptor in the GDT. 16 bytes.
  56. struct ldttss_desc64 {
  57. u16 limit0;
  58. u16 base0;
  59. unsigned base1 : 8, type : 5, dpl : 2, p : 1;
  60. unsigned limit1 : 4, zero0 : 3, g : 1, base2 : 8;
  61. u32 base3;
  62. u32 zero1;
  63. } __attribute__((packed));
  64. #ifdef CONFIG_X86_64
  65. typedef struct gate_struct64 gate_desc;
  66. typedef struct ldttss_desc64 ldt_desc;
  67. typedef struct ldttss_desc64 tss_desc;
  68. #else
  69. typedef struct desc_struct gate_desc;
  70. typedef struct desc_struct ldt_desc;
  71. typedef struct desc_struct tss_desc;
  72. #endif
  73. struct desc_ptr {
  74. unsigned short size;
  75. unsigned long address;
  76. } __attribute__((packed)) ;
  77. #endif /* !__ASSEMBLY__ */
  78. #endif