segment_32.h 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148
  1. #ifndef _ASM_SEGMENT_H
  2. #define _ASM_SEGMENT_H
  3. /*
  4. * The layout of the per-CPU GDT under Linux:
  5. *
  6. * 0 - null
  7. * 1 - reserved
  8. * 2 - reserved
  9. * 3 - reserved
  10. *
  11. * 4 - unused <==== new cacheline
  12. * 5 - unused
  13. *
  14. * ------- start of TLS (Thread-Local Storage) segments:
  15. *
  16. * 6 - TLS segment #1 [ glibc's TLS segment ]
  17. * 7 - TLS segment #2 [ Wine's %fs Win32 segment ]
  18. * 8 - TLS segment #3
  19. * 9 - reserved
  20. * 10 - reserved
  21. * 11 - reserved
  22. *
  23. * ------- start of kernel segments:
  24. *
  25. * 12 - kernel code segment <==== new cacheline
  26. * 13 - kernel data segment
  27. * 14 - default user CS
  28. * 15 - default user DS
  29. * 16 - TSS
  30. * 17 - LDT
  31. * 18 - PNPBIOS support (16->32 gate)
  32. * 19 - PNPBIOS support
  33. * 20 - PNPBIOS support
  34. * 21 - PNPBIOS support
  35. * 22 - PNPBIOS support
  36. * 23 - APM BIOS support
  37. * 24 - APM BIOS support
  38. * 25 - APM BIOS support
  39. *
  40. * 26 - ESPFIX small SS
  41. * 27 - per-cpu [ offset to per-cpu data area ]
  42. * 28 - unused
  43. * 29 - unused
  44. * 30 - unused
  45. * 31 - TSS for double fault handler
  46. */
  47. #define GDT_ENTRY_TLS_ENTRIES 3
  48. #define GDT_ENTRY_TLS_MIN 6
  49. #define GDT_ENTRY_TLS_MAX (GDT_ENTRY_TLS_MIN + GDT_ENTRY_TLS_ENTRIES - 1)
  50. #define TLS_SIZE (GDT_ENTRY_TLS_ENTRIES * 8)
  51. #define GDT_ENTRY_DEFAULT_USER_CS 14
  52. #define __USER_CS (GDT_ENTRY_DEFAULT_USER_CS * 8 + 3)
  53. #define GDT_ENTRY_DEFAULT_USER_DS 15
  54. #define __USER_DS (GDT_ENTRY_DEFAULT_USER_DS * 8 + 3)
  55. #define GDT_ENTRY_KERNEL_BASE 12
  56. #define GDT_ENTRY_KERNEL_CS (GDT_ENTRY_KERNEL_BASE + 0)
  57. #define __KERNEL_CS (GDT_ENTRY_KERNEL_CS * 8)
  58. #define GDT_ENTRY_KERNEL_DS (GDT_ENTRY_KERNEL_BASE + 1)
  59. #define __KERNEL_DS (GDT_ENTRY_KERNEL_DS * 8)
  60. #define GDT_ENTRY_TSS (GDT_ENTRY_KERNEL_BASE + 4)
  61. #define GDT_ENTRY_LDT (GDT_ENTRY_KERNEL_BASE + 5)
  62. #define GDT_ENTRY_PNPBIOS_BASE (GDT_ENTRY_KERNEL_BASE + 6)
  63. #define GDT_ENTRY_APMBIOS_BASE (GDT_ENTRY_KERNEL_BASE + 11)
  64. #define GDT_ENTRY_ESPFIX_SS (GDT_ENTRY_KERNEL_BASE + 14)
  65. #define __ESPFIX_SS (GDT_ENTRY_ESPFIX_SS * 8)
  66. #define GDT_ENTRY_PERCPU (GDT_ENTRY_KERNEL_BASE + 15)
  67. #ifdef CONFIG_SMP
  68. #define __KERNEL_PERCPU (GDT_ENTRY_PERCPU * 8)
  69. #else
  70. #define __KERNEL_PERCPU 0
  71. #endif
  72. #define GDT_ENTRY_DOUBLEFAULT_TSS 31
  73. /*
  74. * The GDT has 32 entries
  75. */
  76. #define GDT_ENTRIES 32
  77. #define GDT_SIZE (GDT_ENTRIES * 8)
  78. /* Simple and small GDT entries for booting only */
  79. #define GDT_ENTRY_BOOT_CS 2
  80. #define __BOOT_CS (GDT_ENTRY_BOOT_CS * 8)
  81. #define GDT_ENTRY_BOOT_DS (GDT_ENTRY_BOOT_CS + 1)
  82. #define __BOOT_DS (GDT_ENTRY_BOOT_DS * 8)
  83. /* The PnP BIOS entries in the GDT */
  84. #define GDT_ENTRY_PNPBIOS_CS32 (GDT_ENTRY_PNPBIOS_BASE + 0)
  85. #define GDT_ENTRY_PNPBIOS_CS16 (GDT_ENTRY_PNPBIOS_BASE + 1)
  86. #define GDT_ENTRY_PNPBIOS_DS (GDT_ENTRY_PNPBIOS_BASE + 2)
  87. #define GDT_ENTRY_PNPBIOS_TS1 (GDT_ENTRY_PNPBIOS_BASE + 3)
  88. #define GDT_ENTRY_PNPBIOS_TS2 (GDT_ENTRY_PNPBIOS_BASE + 4)
  89. /* The PnP BIOS selectors */
  90. #define PNP_CS32 (GDT_ENTRY_PNPBIOS_CS32 * 8) /* segment for calling fn */
  91. #define PNP_CS16 (GDT_ENTRY_PNPBIOS_CS16 * 8) /* code segment for BIOS */
  92. #define PNP_DS (GDT_ENTRY_PNPBIOS_DS * 8) /* data segment for BIOS */
  93. #define PNP_TS1 (GDT_ENTRY_PNPBIOS_TS1 * 8) /* transfer data segment */
  94. #define PNP_TS2 (GDT_ENTRY_PNPBIOS_TS2 * 8) /* another data segment */
  95. /*
  96. * The interrupt descriptor table has room for 256 idt's,
  97. * the global descriptor table is dependent on the number
  98. * of tasks we can have..
  99. */
  100. #define IDT_ENTRIES 256
  101. /* Bottom two bits of selector give the ring privilege level */
  102. #define SEGMENT_RPL_MASK 0x3
  103. /* Bit 2 is table indicator (LDT/GDT) */
  104. #define SEGMENT_TI_MASK 0x4
  105. /* User mode is privilege level 3 */
  106. #define USER_RPL 0x3
  107. /* LDT segment has TI set, GDT has it cleared */
  108. #define SEGMENT_LDT 0x4
  109. #define SEGMENT_GDT 0x0
  110. #ifndef CONFIG_PARAVIRT
  111. #define get_kernel_rpl() 0
  112. #endif
  113. /*
  114. * Matching rules for certain types of segments.
  115. */
  116. /* Matches only __KERNEL_CS, ignoring PnP / USER / APM segments */
  117. #define SEGMENT_IS_KERNEL_CODE(x) (((x) & 0xfc) == GDT_ENTRY_KERNEL_CS * 8)
  118. /* Matches __KERNEL_CS and __USER_CS (they must be 2 entries apart) */
  119. #define SEGMENT_IS_FLAT_CODE(x) (((x) & 0xec) == GDT_ENTRY_KERNEL_CS * 8)
  120. /* Matches PNP_CS32 and PNP_CS16 (they must be consecutive) */
  121. #define SEGMENT_IS_PNP_CODE(x) (((x) & 0xf4) == GDT_ENTRY_PNPBIOS_BASE * 8)
  122. #endif