H. Peter Anvin | 1965aae | 2008-10-22 22:26:29 -0700 | [diff] [blame] | 1 | #ifndef _ASM_X86_SEGMENT_H |
| 2 | #define _ASM_X86_SEGMENT_H |
Glauber de Oliveira Costa | cef1895 | 2008-01-30 13:31:09 +0100 | [diff] [blame] | 3 | |
H. Peter Anvin | 014eea5 | 2011-02-14 18:33:55 -0800 | [diff] [blame] | 4 | #include <linux/const.h> |
| 5 | |
Ingo Molnar | 72d64cc | 2015-03-24 20:45:42 +0100 | [diff] [blame] | 6 | /* |
| 7 | * Constructor for a conventional segment GDT (or LDT) entry. |
| 8 | * This is a macro so it can be used in initializers. |
| 9 | */ |
H. Peter Anvin | 4fdf08b | 2008-07-17 11:29:24 -0700 | [diff] [blame] | 10 | #define GDT_ENTRY(flags, base, limit) \ |
H. Peter Anvin | 014eea5 | 2011-02-14 18:33:55 -0800 | [diff] [blame] | 11 | ((((base) & _AC(0xff000000,ULL)) << (56-24)) | \ |
| 12 | (((flags) & _AC(0x0000f0ff,ULL)) << 40) | \ |
| 13 | (((limit) & _AC(0x000f0000,ULL)) << (48-16)) | \ |
| 14 | (((base) & _AC(0x00ffffff,ULL)) << 16) | \ |
| 15 | (((limit) & _AC(0x0000ffff,ULL)))) |
H. Peter Anvin | 4fdf08b | 2008-07-17 11:29:24 -0700 | [diff] [blame] | 16 | |
Ingo Molnar | 72d64cc | 2015-03-24 20:45:42 +0100 | [diff] [blame] | 17 | /* Simple and small GDT entries for booting only: */ |
H. Peter Anvin | 2a6648e | 2008-01-30 13:33:01 +0100 | [diff] [blame] | 18 | |
| 19 | #define GDT_ENTRY_BOOT_CS 2 |
Denys Vlasenko | 84f5378 | 2015-03-22 22:01:12 +0100 | [diff] [blame] | 20 | #define GDT_ENTRY_BOOT_DS 3 |
| 21 | #define GDT_ENTRY_BOOT_TSS 4 |
Ingo Molnar | 72d64cc | 2015-03-24 20:45:42 +0100 | [diff] [blame] | 22 | #define __BOOT_CS (GDT_ENTRY_BOOT_CS*8) |
| 23 | #define __BOOT_DS (GDT_ENTRY_BOOT_DS*8) |
| 24 | #define __BOOT_TSS (GDT_ENTRY_BOOT_TSS*8) |
H. Peter Anvin | 8808951 | 2008-01-30 13:33:02 +0100 | [diff] [blame] | 25 | |
Ingo Molnar | 72d64cc | 2015-03-24 20:45:42 +0100 | [diff] [blame] | 26 | /* |
| 27 | * Bottom two bits of selector give the ring |
| 28 | * privilege level |
| 29 | */ |
| 30 | #define SEGMENT_RPL_MASK 0x3 |
| 31 | |
| 32 | /* User mode is privilege level 3: */ |
| 33 | #define USER_RPL 0x3 |
| 34 | |
| 35 | /* Bit 2 is Table Indicator (TI): selects between LDT or GDT */ |
| 36 | #define SEGMENT_TI_MASK 0x4 |
| 37 | /* LDT segment has TI set ... */ |
| 38 | #define SEGMENT_LDT 0x4 |
| 39 | /* ... GDT has it cleared */ |
| 40 | #define SEGMENT_GDT 0x0 |
Borislav Petkov | be9d173 | 2014-12-09 13:25:59 +0100 | [diff] [blame] | 41 | |
Borislav Petkov | 6b51311 | 2015-04-03 14:25:28 +0200 | [diff] [blame] | 42 | #define GDT_ENTRY_INVALID_SEG 0 |
| 43 | |
Thomas Gleixner | 96a388d | 2007-10-11 11:20:03 +0200 | [diff] [blame] | 44 | #ifdef CONFIG_X86_32 |
Glauber de Oliveira Costa | b23be39 | 2008-01-30 13:31:09 +0100 | [diff] [blame] | 45 | /* |
| 46 | * The layout of the per-CPU GDT under Linux: |
| 47 | * |
Ingo Molnar | 72d64cc | 2015-03-24 20:45:42 +0100 | [diff] [blame] | 48 | * 0 - null <=== cacheline #1 |
Glauber de Oliveira Costa | b23be39 | 2008-01-30 13:31:09 +0100 | [diff] [blame] | 49 | * 1 - reserved |
| 50 | * 2 - reserved |
| 51 | * 3 - reserved |
| 52 | * |
Ingo Molnar | 72d64cc | 2015-03-24 20:45:42 +0100 | [diff] [blame] | 53 | * 4 - unused <=== cacheline #2 |
Glauber de Oliveira Costa | b23be39 | 2008-01-30 13:31:09 +0100 | [diff] [blame] | 54 | * 5 - unused |
| 55 | * |
| 56 | * ------- start of TLS (Thread-Local Storage) segments: |
| 57 | * |
| 58 | * 6 - TLS segment #1 [ glibc's TLS segment ] |
| 59 | * 7 - TLS segment #2 [ Wine's %fs Win32 segment ] |
Ingo Molnar | 72d64cc | 2015-03-24 20:45:42 +0100 | [diff] [blame] | 60 | * 8 - TLS segment #3 <=== cacheline #3 |
Glauber de Oliveira Costa | b23be39 | 2008-01-30 13:31:09 +0100 | [diff] [blame] | 61 | * 9 - reserved |
| 62 | * 10 - reserved |
| 63 | * 11 - reserved |
| 64 | * |
| 65 | * ------- start of kernel segments: |
| 66 | * |
Ingo Molnar | 72d64cc | 2015-03-24 20:45:42 +0100 | [diff] [blame] | 67 | * 12 - kernel code segment <=== cacheline #4 |
Glauber de Oliveira Costa | b23be39 | 2008-01-30 13:31:09 +0100 | [diff] [blame] | 68 | * 13 - kernel data segment |
| 69 | * 14 - default user CS |
| 70 | * 15 - default user DS |
Ingo Molnar | 72d64cc | 2015-03-24 20:45:42 +0100 | [diff] [blame] | 71 | * 16 - TSS <=== cacheline #5 |
Glauber de Oliveira Costa | b23be39 | 2008-01-30 13:31:09 +0100 | [diff] [blame] | 72 | * 17 - LDT |
| 73 | * 18 - PNPBIOS support (16->32 gate) |
| 74 | * 19 - PNPBIOS support |
Ingo Molnar | 72d64cc | 2015-03-24 20:45:42 +0100 | [diff] [blame] | 75 | * 20 - PNPBIOS support <=== cacheline #6 |
Glauber de Oliveira Costa | b23be39 | 2008-01-30 13:31:09 +0100 | [diff] [blame] | 76 | * 21 - PNPBIOS support |
| 77 | * 22 - PNPBIOS support |
| 78 | * 23 - APM BIOS support |
Ingo Molnar | 72d64cc | 2015-03-24 20:45:42 +0100 | [diff] [blame] | 79 | * 24 - APM BIOS support <=== cacheline #7 |
Glauber de Oliveira Costa | b23be39 | 2008-01-30 13:31:09 +0100 | [diff] [blame] | 80 | * 25 - APM BIOS support |
| 81 | * |
| 82 | * 26 - ESPFIX small SS |
| 83 | * 27 - per-cpu [ offset to per-cpu data area ] |
Ingo Molnar | 72d64cc | 2015-03-24 20:45:42 +0100 | [diff] [blame] | 84 | * 28 - stack_canary-20 [ for stack protector ] <=== cacheline #8 |
Glauber de Oliveira Costa | b23be39 | 2008-01-30 13:31:09 +0100 | [diff] [blame] | 85 | * 29 - unused |
| 86 | * 30 - unused |
| 87 | * 31 - TSS for double fault handler |
| 88 | */ |
Ingo Molnar | 72d64cc | 2015-03-24 20:45:42 +0100 | [diff] [blame] | 89 | #define GDT_ENTRY_TLS_MIN 6 |
| 90 | #define GDT_ENTRY_TLS_MAX (GDT_ENTRY_TLS_MIN + GDT_ENTRY_TLS_ENTRIES - 1) |
Glauber de Oliveira Costa | b23be39 | 2008-01-30 13:31:09 +0100 | [diff] [blame] | 91 | |
Denys Vlasenko | 84f5378 | 2015-03-22 22:01:12 +0100 | [diff] [blame] | 92 | #define GDT_ENTRY_KERNEL_CS 12 |
| 93 | #define GDT_ENTRY_KERNEL_DS 13 |
Glauber de Oliveira Costa | b23be39 | 2008-01-30 13:31:09 +0100 | [diff] [blame] | 94 | #define GDT_ENTRY_DEFAULT_USER_CS 14 |
Glauber de Oliveira Costa | b23be39 | 2008-01-30 13:31:09 +0100 | [diff] [blame] | 95 | #define GDT_ENTRY_DEFAULT_USER_DS 15 |
Denys Vlasenko | 84f5378 | 2015-03-22 22:01:12 +0100 | [diff] [blame] | 96 | #define GDT_ENTRY_TSS 16 |
| 97 | #define GDT_ENTRY_LDT 17 |
| 98 | #define GDT_ENTRY_PNPBIOS_CS32 18 |
| 99 | #define GDT_ENTRY_PNPBIOS_CS16 19 |
| 100 | #define GDT_ENTRY_PNPBIOS_DS 20 |
| 101 | #define GDT_ENTRY_PNPBIOS_TS1 21 |
| 102 | #define GDT_ENTRY_PNPBIOS_TS2 22 |
| 103 | #define GDT_ENTRY_APMBIOS_BASE 23 |
Glauber de Oliveira Costa | b23be39 | 2008-01-30 13:31:09 +0100 | [diff] [blame] | 104 | |
Denys Vlasenko | 84f5378 | 2015-03-22 22:01:12 +0100 | [diff] [blame] | 105 | #define GDT_ENTRY_ESPFIX_SS 26 |
| 106 | #define GDT_ENTRY_PERCPU 27 |
| 107 | #define GDT_ENTRY_STACK_CANARY 28 |
Glauber de Oliveira Costa | b23be39 | 2008-01-30 13:31:09 +0100 | [diff] [blame] | 108 | |
Denys Vlasenko | 84f5378 | 2015-03-22 22:01:12 +0100 | [diff] [blame] | 109 | #define GDT_ENTRY_DOUBLEFAULT_TSS 31 |
Glauber de Oliveira Costa | b23be39 | 2008-01-30 13:31:09 +0100 | [diff] [blame] | 110 | |
Ingo Molnar | 72d64cc | 2015-03-24 20:45:42 +0100 | [diff] [blame] | 111 | /* |
| 112 | * Number of entries in the GDT table: |
| 113 | */ |
| 114 | #define GDT_ENTRIES 32 |
| 115 | |
| 116 | /* |
| 117 | * Segment selector values corresponding to the above entries: |
| 118 | */ |
| 119 | |
Denys Vlasenko | 84f5378 | 2015-03-22 22:01:12 +0100 | [diff] [blame] | 120 | #define __KERNEL_CS (GDT_ENTRY_KERNEL_CS*8) |
| 121 | #define __KERNEL_DS (GDT_ENTRY_KERNEL_DS*8) |
Ingo Molnar | 72d64cc | 2015-03-24 20:45:42 +0100 | [diff] [blame] | 122 | #define __USER_DS (GDT_ENTRY_DEFAULT_USER_DS*8 + 3) |
| 123 | #define __USER_CS (GDT_ENTRY_DEFAULT_USER_CS*8 + 3) |
Jan Beulich | 3234282 | 2010-10-19 14:52:26 +0100 | [diff] [blame] | 124 | #define __ESPFIX_SS (GDT_ENTRY_ESPFIX_SS*8) |
Ingo Molnar | 72d64cc | 2015-03-24 20:45:42 +0100 | [diff] [blame] | 125 | |
| 126 | /* segment for calling fn: */ |
| 127 | #define PNP_CS32 (GDT_ENTRY_PNPBIOS_CS32*8) |
| 128 | /* code segment for BIOS: */ |
| 129 | #define PNP_CS16 (GDT_ENTRY_PNPBIOS_CS16*8) |
| 130 | |
Denys Vlasenko | 84f5378 | 2015-03-22 22:01:12 +0100 | [diff] [blame] | 131 | /* "Is this PNP code selector (PNP_CS32 or PNP_CS16)?" */ |
Ingo Molnar | 72d64cc | 2015-03-24 20:45:42 +0100 | [diff] [blame] | 132 | #define SEGMENT_IS_PNP_CODE(x) (((x) & 0xf4) == PNP_CS32) |
| 133 | |
| 134 | /* data segment for BIOS: */ |
| 135 | #define PNP_DS (GDT_ENTRY_PNPBIOS_DS*8) |
| 136 | /* transfer data segment: */ |
| 137 | #define PNP_TS1 (GDT_ENTRY_PNPBIOS_TS1*8) |
| 138 | /* another data segment: */ |
| 139 | #define PNP_TS2 (GDT_ENTRY_PNPBIOS_TS2*8) |
| 140 | |
Glauber de Oliveira Costa | b23be39 | 2008-01-30 13:31:09 +0100 | [diff] [blame] | 141 | #ifdef CONFIG_SMP |
Ingo Molnar | 72d64cc | 2015-03-24 20:45:42 +0100 | [diff] [blame] | 142 | # define __KERNEL_PERCPU (GDT_ENTRY_PERCPU*8) |
Thomas Gleixner | 96a388d | 2007-10-11 11:20:03 +0200 | [diff] [blame] | 143 | #else |
Ingo Molnar | 72d64cc | 2015-03-24 20:45:42 +0100 | [diff] [blame] | 144 | # define __KERNEL_PERCPU 0 |
Tejun Heo | 60a5317 | 2009-02-09 22:17:40 +0900 | [diff] [blame] | 145 | #endif |
| 146 | |
Ingo Molnar | 72d64cc | 2015-03-24 20:45:42 +0100 | [diff] [blame] | 147 | #ifdef CONFIG_CC_STACKPROTECTOR |
| 148 | # define __KERNEL_STACK_CANARY (GDT_ENTRY_STACK_CANARY*8) |
| 149 | #else |
| 150 | # define __KERNEL_STACK_CANARY 0 |
| 151 | #endif |
Glauber de Oliveira Costa | b23be39 | 2008-01-30 13:31:09 +0100 | [diff] [blame] | 152 | |
Denys Vlasenko | 84f5378 | 2015-03-22 22:01:12 +0100 | [diff] [blame] | 153 | #else /* 64-bit: */ |
Glauber de Oliveira Costa | b23be39 | 2008-01-30 13:31:09 +0100 | [diff] [blame] | 154 | |
Glauber de Oliveira Costa | b23be39 | 2008-01-30 13:31:09 +0100 | [diff] [blame] | 155 | #include <asm/cache.h> |
| 156 | |
Ingo Molnar | 72d64cc | 2015-03-24 20:45:42 +0100 | [diff] [blame] | 157 | #define GDT_ENTRY_KERNEL32_CS 1 |
| 158 | #define GDT_ENTRY_KERNEL_CS 2 |
| 159 | #define GDT_ENTRY_KERNEL_DS 3 |
| 160 | |
Glauber de Oliveira Costa | b23be39 | 2008-01-30 13:31:09 +0100 | [diff] [blame] | 161 | /* |
Ingo Molnar | 72d64cc | 2015-03-24 20:45:42 +0100 | [diff] [blame] | 162 | * We cannot use the same code segment descriptor for user and kernel mode, |
| 163 | * not even in long flat mode, because of different DPL. |
| 164 | * |
| 165 | * GDT layout to get 64-bit SYSCALL/SYSRET support right. SYSRET hardcodes |
| 166 | * selectors: |
| 167 | * |
| 168 | * if returning to 32-bit userspace: cs = STAR.SYSRET_CS, |
| 169 | * if returning to 64-bit userspace: cs = STAR.SYSRET_CS+16, |
| 170 | * |
Denys Vlasenko | 84f5378 | 2015-03-22 22:01:12 +0100 | [diff] [blame] | 171 | * ss = STAR.SYSRET_CS+8 (in either case) |
Ingo Molnar | 72d64cc | 2015-03-24 20:45:42 +0100 | [diff] [blame] | 172 | * |
Denys Vlasenko | 84f5378 | 2015-03-22 22:01:12 +0100 | [diff] [blame] | 173 | * thus USER_DS should be between 32-bit and 64-bit code selectors: |
Glauber de Oliveira Costa | b23be39 | 2008-01-30 13:31:09 +0100 | [diff] [blame] | 174 | */ |
Ingo Molnar | 72d64cc | 2015-03-24 20:45:42 +0100 | [diff] [blame] | 175 | #define GDT_ENTRY_DEFAULT_USER32_CS 4 |
| 176 | #define GDT_ENTRY_DEFAULT_USER_DS 5 |
| 177 | #define GDT_ENTRY_DEFAULT_USER_CS 6 |
Denys Vlasenko | 84f5378 | 2015-03-22 22:01:12 +0100 | [diff] [blame] | 178 | |
Ingo Molnar | 72d64cc | 2015-03-24 20:45:42 +0100 | [diff] [blame] | 179 | /* Needs two entries */ |
| 180 | #define GDT_ENTRY_TSS 8 |
| 181 | /* Needs two entries */ |
| 182 | #define GDT_ENTRY_LDT 10 |
Denys Vlasenko | 84f5378 | 2015-03-22 22:01:12 +0100 | [diff] [blame] | 183 | |
Ingo Molnar | 72d64cc | 2015-03-24 20:45:42 +0100 | [diff] [blame] | 184 | #define GDT_ENTRY_TLS_MIN 12 |
| 185 | #define GDT_ENTRY_TLS_MAX 14 |
Denys Vlasenko | 84f5378 | 2015-03-22 22:01:12 +0100 | [diff] [blame] | 186 | |
Ingo Molnar | 72d64cc | 2015-03-24 20:45:42 +0100 | [diff] [blame] | 187 | /* Abused to load per CPU data from limit */ |
| 188 | #define GDT_ENTRY_PER_CPU 15 |
Glauber de Oliveira Costa | b23be39 | 2008-01-30 13:31:09 +0100 | [diff] [blame] | 189 | |
Ingo Molnar | 72d64cc | 2015-03-24 20:45:42 +0100 | [diff] [blame] | 190 | /* |
| 191 | * Number of entries in the GDT table: |
| 192 | */ |
| 193 | #define GDT_ENTRIES 16 |
Glauber de Oliveira Costa | b23be39 | 2008-01-30 13:31:09 +0100 | [diff] [blame] | 194 | |
Ingo Molnar | 72d64cc | 2015-03-24 20:45:42 +0100 | [diff] [blame] | 195 | /* |
| 196 | * Segment selector values corresponding to the above entries: |
| 197 | * |
| 198 | * Note, selectors also need to have a correct RPL, |
| 199 | * expressed with the +3 value for user-space selectors: |
| 200 | */ |
| 201 | #define __KERNEL32_CS (GDT_ENTRY_KERNEL32_CS*8) |
| 202 | #define __KERNEL_CS (GDT_ENTRY_KERNEL_CS*8) |
| 203 | #define __KERNEL_DS (GDT_ENTRY_KERNEL_DS*8) |
| 204 | #define __USER32_CS (GDT_ENTRY_DEFAULT_USER32_CS*8 + 3) |
| 205 | #define __USER_DS (GDT_ENTRY_DEFAULT_USER_DS*8 + 3) |
| 206 | #define __USER32_DS __USER_DS |
| 207 | #define __USER_CS (GDT_ENTRY_DEFAULT_USER_CS*8 + 3) |
| 208 | #define __PER_CPU_SEG (GDT_ENTRY_PER_CPU*8 + 3) |
Glauber de Oliveira Costa | b23be39 | 2008-01-30 13:31:09 +0100 | [diff] [blame] | 209 | |
Ingo Molnar | 72d64cc | 2015-03-24 20:45:42 +0100 | [diff] [blame] | 210 | /* TLS indexes for 64-bit - hardcoded in arch_prctl(): */ |
| 211 | #define FS_TLS 0 |
| 212 | #define GS_TLS 1 |
| 213 | |
| 214 | #define GS_TLS_SEL ((GDT_ENTRY_TLS_MIN+GS_TLS)*8 + 3) |
| 215 | #define FS_TLS_SEL ((GDT_ENTRY_TLS_MIN+FS_TLS)*8 + 3) |
Glauber de Oliveira Costa | b23be39 | 2008-01-30 13:31:09 +0100 | [diff] [blame] | 216 | |
Thomas Gleixner | 96a388d | 2007-10-11 11:20:03 +0200 | [diff] [blame] | 217 | #endif |
Glauber de Oliveira Costa | cef1895 | 2008-01-30 13:31:09 +0100 | [diff] [blame] | 218 | |
| 219 | #ifndef CONFIG_PARAVIRT |
Ingo Molnar | 72d64cc | 2015-03-24 20:45:42 +0100 | [diff] [blame] | 220 | # define get_kernel_rpl() 0 |
Glauber de Oliveira Costa | cef1895 | 2008-01-30 13:31:09 +0100 | [diff] [blame] | 221 | #endif |
| 222 | |
Ingo Molnar | 72d64cc | 2015-03-24 20:45:42 +0100 | [diff] [blame] | 223 | #define IDT_ENTRIES 256 |
| 224 | #define NUM_EXCEPTION_VECTORS 32 |
| 225 | |
| 226 | /* Bitmask of exception vectors which push an error code on the stack: */ |
| 227 | #define EXCEPTION_ERRCODE_MASK 0x00027d00 |
| 228 | |
| 229 | #define GDT_SIZE (GDT_ENTRIES*8) |
| 230 | #define GDT_ENTRY_TLS_ENTRIES 3 |
| 231 | #define TLS_SIZE (GDT_ENTRY_TLS_ENTRIES* 8) |
Glauber de Oliveira Costa | 15ee09b | 2008-01-30 13:31:09 +0100 | [diff] [blame] | 232 | |
Roland McGrath | 8866cd9 | 2008-01-30 13:33:06 +0100 | [diff] [blame] | 233 | #ifdef __KERNEL__ |
Andy Lutomirski | 425be56 | 2015-05-22 16:15:47 -0700 | [diff] [blame] | 234 | |
| 235 | /* |
| 236 | * early_idt_handler_array is an array of entry points referenced in the |
| 237 | * early IDT. For simplicity, it's a real array with one entry point |
| 238 | * every nine bytes. That leaves room for an optional 'push $0' if the |
| 239 | * vector has no error code (two bytes), a 'push $vector_number' (two |
| 240 | * bytes), and a jump to the common entry code (up to five bytes). |
| 241 | */ |
| 242 | #define EARLY_IDT_HANDLER_SIZE 9 |
| 243 | |
Roland McGrath | 8866cd9 | 2008-01-30 13:33:06 +0100 | [diff] [blame] | 244 | #ifndef __ASSEMBLY__ |
Ingo Molnar | 72d64cc | 2015-03-24 20:45:42 +0100 | [diff] [blame] | 245 | |
Andy Lutomirski | 425be56 | 2015-05-22 16:15:47 -0700 | [diff] [blame] | 246 | extern const char early_idt_handler_array[NUM_EXCEPTION_VECTORS][EARLY_IDT_HANDLER_SIZE]; |
Seiji Aguchi | 25c74b1 | 2013-10-30 16:37:00 -0400 | [diff] [blame] | 247 | #ifdef CONFIG_TRACING |
Andy Lutomirski | 425be56 | 2015-05-22 16:15:47 -0700 | [diff] [blame] | 248 | # define trace_early_idt_handler_array early_idt_handler_array |
Seiji Aguchi | 25c74b1 | 2013-10-30 16:37:00 -0400 | [diff] [blame] | 249 | #endif |
David Howells | f05e798 | 2012-03-28 18:11:12 +0100 | [diff] [blame] | 250 | |
| 251 | /* |
| 252 | * Load a segment. Fall back on loading the zero |
| 253 | * segment if something goes wrong.. |
| 254 | */ |
| 255 | #define loadsegment(seg, value) \ |
| 256 | do { \ |
| 257 | unsigned short __val = (value); \ |
| 258 | \ |
| 259 | asm volatile(" \n" \ |
| 260 | "1: movl %k0,%%" #seg " \n" \ |
| 261 | \ |
| 262 | ".section .fixup,\"ax\" \n" \ |
| 263 | "2: xorl %k0,%k0 \n" \ |
| 264 | " jmp 1b \n" \ |
| 265 | ".previous \n" \ |
| 266 | \ |
| 267 | _ASM_EXTABLE(1b, 2b) \ |
| 268 | \ |
| 269 | : "+r" (__val) : : "memory"); \ |
| 270 | } while (0) |
| 271 | |
| 272 | /* |
Ingo Molnar | 72d64cc | 2015-03-24 20:45:42 +0100 | [diff] [blame] | 273 | * Save a segment register away: |
David Howells | f05e798 | 2012-03-28 18:11:12 +0100 | [diff] [blame] | 274 | */ |
| 275 | #define savesegment(seg, value) \ |
| 276 | asm("mov %%" #seg ",%0":"=r" (value) : : "memory") |
| 277 | |
| 278 | /* |
Ingo Molnar | 72d64cc | 2015-03-24 20:45:42 +0100 | [diff] [blame] | 279 | * x86-32 user GS accessors: |
David Howells | f05e798 | 2012-03-28 18:11:12 +0100 | [diff] [blame] | 280 | */ |
| 281 | #ifdef CONFIG_X86_32 |
Ingo Molnar | 72d64cc | 2015-03-24 20:45:42 +0100 | [diff] [blame] | 282 | # ifdef CONFIG_X86_32_LAZY_GS |
| 283 | # define get_user_gs(regs) (u16)({ unsigned long v; savesegment(gs, v); v; }) |
| 284 | # define set_user_gs(regs, v) loadsegment(gs, (unsigned long)(v)) |
| 285 | # define task_user_gs(tsk) ((tsk)->thread.gs) |
| 286 | # define lazy_save_gs(v) savesegment(gs, (v)) |
| 287 | # define lazy_load_gs(v) loadsegment(gs, (v)) |
| 288 | # else /* X86_32_LAZY_GS */ |
| 289 | # define get_user_gs(regs) (u16)((regs)->gs) |
| 290 | # define set_user_gs(regs, v) do { (regs)->gs = (v); } while (0) |
| 291 | # define task_user_gs(tsk) (task_pt_regs(tsk)->gs) |
| 292 | # define lazy_save_gs(v) do { } while (0) |
| 293 | # define lazy_load_gs(v) do { } while (0) |
| 294 | # endif /* X86_32_LAZY_GS */ |
David Howells | f05e798 | 2012-03-28 18:11:12 +0100 | [diff] [blame] | 295 | #endif /* X86_32 */ |
| 296 | |
David Howells | f05e798 | 2012-03-28 18:11:12 +0100 | [diff] [blame] | 297 | #endif /* !__ASSEMBLY__ */ |
| 298 | #endif /* __KERNEL__ */ |
Roland McGrath | 8866cd9 | 2008-01-30 13:33:06 +0100 | [diff] [blame] | 299 | |
H. Peter Anvin | 1965aae | 2008-10-22 22:26:29 -0700 | [diff] [blame] | 300 | #endif /* _ASM_X86_SEGMENT_H */ |