desc_defs.h 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145
  1. /* SPDX-License-Identifier: GPL-2.0 */
  2. /* Written 2000 by Andi Kleen */
  3. #ifndef _ASM_X86_DESC_DEFS_H
  4. #define _ASM_X86_DESC_DEFS_H
  5. /*
  6. * Segment descriptor structure definitions, usable from both x86_64 and i386
  7. * archs.
  8. */
  9. #ifndef __ASSEMBLY__
  10. #include <linux/types.h>
  11. /* 8 byte segment descriptor */
  12. struct desc_struct {
  13. u16 limit0;
  14. u16 base0;
  15. u16 base1: 8, type: 4, s: 1, dpl: 2, p: 1;
  16. u16 limit1: 4, avl: 1, l: 1, d: 1, g: 1, base2: 8;
  17. } __attribute__((packed));
  18. #define GDT_ENTRY_INIT(flags, base, limit) \
  19. { \
  20. .limit0 = (u16) (limit), \
  21. .limit1 = ((limit) >> 16) & 0x0F, \
  22. .base0 = (u16) (base), \
  23. .base1 = ((base) >> 16) & 0xFF, \
  24. .base2 = ((base) >> 24) & 0xFF, \
  25. .type = (flags & 0x0f), \
  26. .s = (flags >> 4) & 0x01, \
  27. .dpl = (flags >> 5) & 0x03, \
  28. .p = (flags >> 7) & 0x01, \
  29. .avl = (flags >> 12) & 0x01, \
  30. .l = (flags >> 13) & 0x01, \
  31. .d = (flags >> 14) & 0x01, \
  32. .g = (flags >> 15) & 0x01, \
  33. }
  34. enum {
  35. GATE_INTERRUPT = 0xE,
  36. GATE_TRAP = 0xF,
  37. GATE_CALL = 0xC,
  38. GATE_TASK = 0x5,
  39. };
  40. enum {
  41. DESC_TSS = 0x9,
  42. DESC_LDT = 0x2,
  43. DESCTYPE_S = 0x10, /* !system */
  44. };
  45. /* LDT or TSS descriptor in the GDT. */
  46. struct ldttss_desc {
  47. u16 limit0;
  48. u16 base0;
  49. u16 base1 : 8, type : 5, dpl : 2, p : 1;
  50. u16 limit1 : 4, zero0 : 3, g : 1, base2 : 8;
  51. #ifdef CONFIG_X86_64
  52. u32 base3;
  53. u32 zero1;
  54. #endif
  55. } __attribute__((packed));
  56. typedef struct ldttss_desc ldt_desc;
  57. typedef struct ldttss_desc tss_desc;
  58. struct idt_bits {
  59. u16 ist : 3,
  60. zero : 5,
  61. type : 5,
  62. dpl : 2,
  63. p : 1;
  64. } __attribute__((packed));
  65. struct idt_data {
  66. unsigned int vector;
  67. unsigned int segment;
  68. struct idt_bits bits;
  69. const void *addr;
  70. };
  71. struct gate_struct {
  72. u16 offset_low;
  73. u16 segment;
  74. struct idt_bits bits;
  75. u16 offset_middle;
  76. #ifdef CONFIG_X86_64
  77. u32 offset_high;
  78. u32 reserved;
  79. #endif
  80. } __attribute__((packed));
  81. typedef struct gate_struct gate_desc;
  82. static inline unsigned long gate_offset(const gate_desc *g)
  83. {
  84. #ifdef CONFIG_X86_64
  85. return g->offset_low | ((unsigned long)g->offset_middle << 16) |
  86. ((unsigned long) g->offset_high << 32);
  87. #else
  88. return g->offset_low | ((unsigned long)g->offset_middle << 16);
  89. #endif
  90. }
  91. static inline unsigned long gate_segment(const gate_desc *g)
  92. {
  93. return g->segment;
  94. }
  95. struct desc_ptr {
  96. unsigned short size;
  97. unsigned long address;
  98. } __attribute__((packed)) ;
  99. #endif /* !__ASSEMBLY__ */
  100. /* Boot IDT definitions */
  101. #define BOOT_IDT_ENTRIES 32
  102. /* Access rights as returned by LAR */
  103. #define AR_TYPE_RODATA (0 * (1 << 9))
  104. #define AR_TYPE_RWDATA (1 * (1 << 9))
  105. #define AR_TYPE_RODATA_EXPDOWN (2 * (1 << 9))
  106. #define AR_TYPE_RWDATA_EXPDOWN (3 * (1 << 9))
  107. #define AR_TYPE_XOCODE (4 * (1 << 9))
  108. #define AR_TYPE_XRCODE (5 * (1 << 9))
  109. #define AR_TYPE_XOCODE_CONF (6 * (1 << 9))
  110. #define AR_TYPE_XRCODE_CONF (7 * (1 << 9))
  111. #define AR_TYPE_MASK (7 * (1 << 9))
  112. #define AR_DPL0 (0 * (1 << 13))
  113. #define AR_DPL3 (3 * (1 << 13))
  114. #define AR_DPL_MASK (3 * (1 << 13))
  115. #define AR_A (1 << 8) /* "Accessed" */
  116. #define AR_S (1 << 12) /* If clear, "System" segment */
  117. #define AR_P (1 << 15) /* "Present" */
  118. #define AR_AVL (1 << 20) /* "AVaiLable" (no HW effect) */
  119. #define AR_L (1 << 21) /* "Long mode" for code segments */
  120. #define AR_DB (1 << 22) /* D/B, effect depends on type */
  121. #define AR_G (1 << 23) /* "Granularity" (limit in pages) */
  122. #endif /* _ASM_X86_DESC_DEFS_H */