desc_defs.h 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  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: 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 {
  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. enum {
  33. GATE_INTERRUPT = 0xE,
  34. GATE_TRAP = 0xF,
  35. GATE_CALL = 0xC,
  36. GATE_TASK = 0x5,
  37. };
  38. /* 16byte gate */
  39. struct gate_struct64 {
  40. u16 offset_low;
  41. u16 segment;
  42. unsigned ist : 3, zero0 : 5, type : 5, dpl : 2, p : 1;
  43. u16 offset_middle;
  44. u32 offset_high;
  45. u32 zero1;
  46. } __attribute__((packed));
  47. #define PTR_LOW(x) ((unsigned long long)(x) & 0xFFFF)
  48. #define PTR_MIDDLE(x) (((unsigned long long)(x) >> 16) & 0xFFFF)
  49. #define PTR_HIGH(x) ((unsigned long long)(x) >> 32)
  50. enum {
  51. DESC_TSS = 0x9,
  52. DESC_LDT = 0x2,
  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. #define gate_offset(g) ((g).offset_low | ((unsigned long)(g).offset_middle << 16) | ((unsigned long)(g).offset_high << 32))
  69. #define gate_segment(g) ((g).segment)
  70. #else
  71. typedef struct desc_struct gate_desc;
  72. typedef struct desc_struct ldt_desc;
  73. typedef struct desc_struct tss_desc;
  74. #define gate_offset(g) (((g).b & 0xffff0000) | ((g).a & 0x0000ffff))
  75. #define gate_segment(g) ((g).a >> 16)
  76. #endif
  77. struct desc_ptr {
  78. unsigned short size;
  79. unsigned long address;
  80. } __attribute__((packed)) ;
  81. #endif /* !__ASSEMBLY__ */
  82. #endif /* _ASM_X86_DESC_DEFS_H */