1b2441318SGreg Kroah-Hartman /* SPDX-License-Identifier: GPL-2.0 */ 21965aae3SH. Peter Anvin #ifndef _ASM_X86_SEGMENT_H 31965aae3SH. Peter Anvin #define _ASM_X86_SEGMENT_H 4bb898558SAl Viro 5014eea51SH. Peter Anvin #include <linux/const.h> 645e876f7SAndy Lutomirski #include <asm/alternative.h> 7014eea51SH. Peter Anvin 872d64cc7SIngo Molnar /* 972d64cc7SIngo Molnar * Constructor for a conventional segment GDT (or LDT) entry. 1072d64cc7SIngo Molnar * This is a macro so it can be used in initializers. 1172d64cc7SIngo Molnar */ 12bb898558SAl Viro #define GDT_ENTRY(flags, base, limit) \ 13014eea51SH. Peter Anvin ((((base) & _AC(0xff000000,ULL)) << (56-24)) | \ 14014eea51SH. Peter Anvin (((flags) & _AC(0x0000f0ff,ULL)) << 40) | \ 15014eea51SH. Peter Anvin (((limit) & _AC(0x000f0000,ULL)) << (48-16)) | \ 16014eea51SH. Peter Anvin (((base) & _AC(0x00ffffff,ULL)) << 16) | \ 17014eea51SH. Peter Anvin (((limit) & _AC(0x0000ffff,ULL)))) 18bb898558SAl Viro 1972d64cc7SIngo Molnar /* Simple and small GDT entries for booting only: */ 20bb898558SAl Viro 21bb898558SAl Viro #define GDT_ENTRY_BOOT_CS 2 2284f53788SDenys Vlasenko #define GDT_ENTRY_BOOT_DS 3 2384f53788SDenys Vlasenko #define GDT_ENTRY_BOOT_TSS 4 24bb898558SAl Viro #define __BOOT_CS (GDT_ENTRY_BOOT_CS*8) 25bb898558SAl Viro #define __BOOT_DS (GDT_ENTRY_BOOT_DS*8) 26bb898558SAl Viro #define __BOOT_TSS (GDT_ENTRY_BOOT_TSS*8) 27bb898558SAl Viro 2872d64cc7SIngo Molnar /* 29be9d1738SBorislav Petkov * Bottom two bits of selector give the ring 30be9d1738SBorislav Petkov * privilege level 31be9d1738SBorislav Petkov */ 3272d64cc7SIngo Molnar #define SEGMENT_RPL_MASK 0x3 3372d64cc7SIngo Molnar 3472d64cc7SIngo Molnar /* User mode is privilege level 3: */ 3572d64cc7SIngo Molnar #define USER_RPL 0x3 3672d64cc7SIngo Molnar 3772d64cc7SIngo Molnar /* Bit 2 is Table Indicator (TI): selects between LDT or GDT */ 3872d64cc7SIngo Molnar #define SEGMENT_TI_MASK 0x4 3972d64cc7SIngo Molnar /* LDT segment has TI set ... */ 4072d64cc7SIngo Molnar #define SEGMENT_LDT 0x4 4172d64cc7SIngo Molnar /* ... GDT has it cleared */ 4272d64cc7SIngo Molnar #define SEGMENT_GDT 0x0 43be9d1738SBorislav Petkov 446b51311cSBorislav Petkov #define GDT_ENTRY_INVALID_SEG 0 456b51311cSBorislav Petkov 46bb898558SAl Viro #ifdef CONFIG_X86_32 47bb898558SAl Viro /* 48bb898558SAl Viro * The layout of the per-CPU GDT under Linux: 49bb898558SAl Viro * 5072d64cc7SIngo Molnar * 0 - null <=== cacheline #1 51bb898558SAl Viro * 1 - reserved 52bb898558SAl Viro * 2 - reserved 53bb898558SAl Viro * 3 - reserved 54bb898558SAl Viro * 5572d64cc7SIngo Molnar * 4 - unused <=== cacheline #2 56bb898558SAl Viro * 5 - unused 57bb898558SAl Viro * 58bb898558SAl Viro * ------- start of TLS (Thread-Local Storage) segments: 59bb898558SAl Viro * 60bb898558SAl Viro * 6 - TLS segment #1 [ glibc's TLS segment ] 61bb898558SAl Viro * 7 - TLS segment #2 [ Wine's %fs Win32 segment ] 6272d64cc7SIngo Molnar * 8 - TLS segment #3 <=== cacheline #3 63bb898558SAl Viro * 9 - reserved 64bb898558SAl Viro * 10 - reserved 65bb898558SAl Viro * 11 - reserved 66bb898558SAl Viro * 67bb898558SAl Viro * ------- start of kernel segments: 68bb898558SAl Viro * 6972d64cc7SIngo Molnar * 12 - kernel code segment <=== cacheline #4 70bb898558SAl Viro * 13 - kernel data segment 71bb898558SAl Viro * 14 - default user CS 72bb898558SAl Viro * 15 - default user DS 7372d64cc7SIngo Molnar * 16 - TSS <=== cacheline #5 74bb898558SAl Viro * 17 - LDT 75bb898558SAl Viro * 18 - PNPBIOS support (16->32 gate) 76bb898558SAl Viro * 19 - PNPBIOS support 7772d64cc7SIngo Molnar * 20 - PNPBIOS support <=== cacheline #6 78bb898558SAl Viro * 21 - PNPBIOS support 79bb898558SAl Viro * 22 - PNPBIOS support 80bb898558SAl Viro * 23 - APM BIOS support 8172d64cc7SIngo Molnar * 24 - APM BIOS support <=== cacheline #7 82bb898558SAl Viro * 25 - APM BIOS support 83bb898558SAl Viro * 84bb898558SAl Viro * 26 - ESPFIX small SS 85bb898558SAl Viro * 27 - per-cpu [ offset to per-cpu data area ] 8672d64cc7SIngo Molnar * 28 - stack_canary-20 [ for stack protector ] <=== cacheline #8 87bb898558SAl Viro * 29 - unused 88bb898558SAl Viro * 30 - unused 89bb898558SAl Viro * 31 - TSS for double fault handler 90bb898558SAl Viro */ 91bb898558SAl Viro #define GDT_ENTRY_TLS_MIN 6 92bb898558SAl Viro #define GDT_ENTRY_TLS_MAX (GDT_ENTRY_TLS_MIN + GDT_ENTRY_TLS_ENTRIES - 1) 93bb898558SAl Viro 9484f53788SDenys Vlasenko #define GDT_ENTRY_KERNEL_CS 12 9584f53788SDenys Vlasenko #define GDT_ENTRY_KERNEL_DS 13 96bb898558SAl Viro #define GDT_ENTRY_DEFAULT_USER_CS 14 97bb898558SAl Viro #define GDT_ENTRY_DEFAULT_USER_DS 15 9884f53788SDenys Vlasenko #define GDT_ENTRY_TSS 16 9984f53788SDenys Vlasenko #define GDT_ENTRY_LDT 17 10084f53788SDenys Vlasenko #define GDT_ENTRY_PNPBIOS_CS32 18 10184f53788SDenys Vlasenko #define GDT_ENTRY_PNPBIOS_CS16 19 10284f53788SDenys Vlasenko #define GDT_ENTRY_PNPBIOS_DS 20 10384f53788SDenys Vlasenko #define GDT_ENTRY_PNPBIOS_TS1 21 10484f53788SDenys Vlasenko #define GDT_ENTRY_PNPBIOS_TS2 22 10584f53788SDenys Vlasenko #define GDT_ENTRY_APMBIOS_BASE 23 106bb898558SAl Viro 10784f53788SDenys Vlasenko #define GDT_ENTRY_ESPFIX_SS 26 10884f53788SDenys Vlasenko #define GDT_ENTRY_PERCPU 27 10984f53788SDenys Vlasenko #define GDT_ENTRY_STACK_CANARY 28 110bb898558SAl Viro 11184f53788SDenys Vlasenko #define GDT_ENTRY_DOUBLEFAULT_TSS 31 112bb898558SAl Viro 11372d64cc7SIngo Molnar /* 11472d64cc7SIngo Molnar * Number of entries in the GDT table: 11572d64cc7SIngo Molnar */ 11672d64cc7SIngo Molnar #define GDT_ENTRIES 32 11772d64cc7SIngo Molnar 11872d64cc7SIngo Molnar /* 11972d64cc7SIngo Molnar * Segment selector values corresponding to the above entries: 12072d64cc7SIngo Molnar */ 12172d64cc7SIngo Molnar 12284f53788SDenys Vlasenko #define __KERNEL_CS (GDT_ENTRY_KERNEL_CS*8) 12384f53788SDenys Vlasenko #define __KERNEL_DS (GDT_ENTRY_KERNEL_DS*8) 12484f53788SDenys Vlasenko #define __USER_DS (GDT_ENTRY_DEFAULT_USER_DS*8 + 3) 12584f53788SDenys Vlasenko #define __USER_CS (GDT_ENTRY_DEFAULT_USER_CS*8 + 3) 126bb898558SAl Viro #define __ESPFIX_SS (GDT_ENTRY_ESPFIX_SS*8) 12772d64cc7SIngo Molnar 12872d64cc7SIngo Molnar /* segment for calling fn: */ 12972d64cc7SIngo Molnar #define PNP_CS32 (GDT_ENTRY_PNPBIOS_CS32*8) 13072d64cc7SIngo Molnar /* code segment for BIOS: */ 13172d64cc7SIngo Molnar #define PNP_CS16 (GDT_ENTRY_PNPBIOS_CS16*8) 13272d64cc7SIngo Molnar 13384f53788SDenys Vlasenko /* "Is this PNP code selector (PNP_CS32 or PNP_CS16)?" */ 13484f53788SDenys Vlasenko #define SEGMENT_IS_PNP_CODE(x) (((x) & 0xf4) == PNP_CS32) 13572d64cc7SIngo Molnar 13672d64cc7SIngo Molnar /* data segment for BIOS: */ 13772d64cc7SIngo Molnar #define PNP_DS (GDT_ENTRY_PNPBIOS_DS*8) 13872d64cc7SIngo Molnar /* transfer data segment: */ 13972d64cc7SIngo Molnar #define PNP_TS1 (GDT_ENTRY_PNPBIOS_TS1*8) 14072d64cc7SIngo Molnar /* another data segment: */ 14172d64cc7SIngo Molnar #define PNP_TS2 (GDT_ENTRY_PNPBIOS_TS2*8) 14272d64cc7SIngo Molnar 143bb898558SAl Viro #ifdef CONFIG_SMP 144bb898558SAl Viro # define __KERNEL_PERCPU (GDT_ENTRY_PERCPU*8) 145bb898558SAl Viro #else 146bb898558SAl Viro # define __KERNEL_PERCPU 0 147bb898558SAl Viro #endif 14872d64cc7SIngo Molnar 149050e9baaSLinus Torvalds #ifdef CONFIG_STACKPROTECTOR 15060a5317fSTejun Heo # define __KERNEL_STACK_CANARY (GDT_ENTRY_STACK_CANARY*8) 15160a5317fSTejun Heo #else 15260a5317fSTejun Heo # define __KERNEL_STACK_CANARY 0 15360a5317fSTejun Heo #endif 15460a5317fSTejun Heo 15584f53788SDenys Vlasenko #else /* 64-bit: */ 156bb898558SAl Viro 157bb898558SAl Viro #include <asm/cache.h> 158bb898558SAl Viro 159bb898558SAl Viro #define GDT_ENTRY_KERNEL32_CS 1 160bb898558SAl Viro #define GDT_ENTRY_KERNEL_CS 2 161bb898558SAl Viro #define GDT_ENTRY_KERNEL_DS 3 16272d64cc7SIngo Molnar 163bb898558SAl Viro /* 16472d64cc7SIngo Molnar * We cannot use the same code segment descriptor for user and kernel mode, 16572d64cc7SIngo Molnar * not even in long flat mode, because of different DPL. 16672d64cc7SIngo Molnar * 16772d64cc7SIngo Molnar * GDT layout to get 64-bit SYSCALL/SYSRET support right. SYSRET hardcodes 16872d64cc7SIngo Molnar * selectors: 16972d64cc7SIngo Molnar * 17084f53788SDenys Vlasenko * if returning to 32-bit userspace: cs = STAR.SYSRET_CS, 17184f53788SDenys Vlasenko * if returning to 64-bit userspace: cs = STAR.SYSRET_CS+16, 17272d64cc7SIngo Molnar * 17384f53788SDenys Vlasenko * ss = STAR.SYSRET_CS+8 (in either case) 17472d64cc7SIngo Molnar * 17584f53788SDenys Vlasenko * thus USER_DS should be between 32-bit and 64-bit code selectors: 176bb898558SAl Viro */ 177bb898558SAl Viro #define GDT_ENTRY_DEFAULT_USER32_CS 4 178bb898558SAl Viro #define GDT_ENTRY_DEFAULT_USER_DS 5 179bb898558SAl Viro #define GDT_ENTRY_DEFAULT_USER_CS 6 180bb898558SAl Viro 18172d64cc7SIngo Molnar /* Needs two entries */ 18272d64cc7SIngo Molnar #define GDT_ENTRY_TSS 8 18372d64cc7SIngo Molnar /* Needs two entries */ 18472d64cc7SIngo Molnar #define GDT_ENTRY_LDT 10 18572d64cc7SIngo Molnar 186bb898558SAl Viro #define GDT_ENTRY_TLS_MIN 12 187bb898558SAl Viro #define GDT_ENTRY_TLS_MAX 14 188bb898558SAl Viro 189c4755613SChang S. Bae #define GDT_ENTRY_CPU_NUMBER 15 19084f53788SDenys Vlasenko 19172d64cc7SIngo Molnar /* 19272d64cc7SIngo Molnar * Number of entries in the GDT table: 19372d64cc7SIngo Molnar */ 19472d64cc7SIngo Molnar #define GDT_ENTRIES 16 19572d64cc7SIngo Molnar 19672d64cc7SIngo Molnar /* 19772d64cc7SIngo Molnar * Segment selector values corresponding to the above entries: 19872d64cc7SIngo Molnar * 19972d64cc7SIngo Molnar * Note, selectors also need to have a correct RPL, 20072d64cc7SIngo Molnar * expressed with the +3 value for user-space selectors: 20172d64cc7SIngo Molnar */ 20272d64cc7SIngo Molnar #define __KERNEL32_CS (GDT_ENTRY_KERNEL32_CS*8) 20384f53788SDenys Vlasenko #define __KERNEL_CS (GDT_ENTRY_KERNEL_CS*8) 20484f53788SDenys Vlasenko #define __KERNEL_DS (GDT_ENTRY_KERNEL_DS*8) 20584f53788SDenys Vlasenko #define __USER32_CS (GDT_ENTRY_DEFAULT_USER32_CS*8 + 3) 20672d64cc7SIngo Molnar #define __USER_DS (GDT_ENTRY_DEFAULT_USER_DS*8 + 3) 20784f53788SDenys Vlasenko #define __USER32_DS __USER_DS 20872d64cc7SIngo Molnar #define __USER_CS (GDT_ENTRY_DEFAULT_USER_CS*8 + 3) 209c4755613SChang S. Bae #define __CPU_NUMBER_SEG (GDT_ENTRY_CPU_NUMBER*8 + 3) 210bb898558SAl Viro 211bb898558SAl Viro #endif 212bb898558SAl Viro 213bb898558SAl Viro #ifndef CONFIG_PARAVIRT 214bb898558SAl Viro # define get_kernel_rpl() 0 215bb898558SAl Viro #endif 216bb898558SAl Viro 217bb898558SAl Viro #define IDT_ENTRIES 256 218bb898558SAl Viro #define NUM_EXCEPTION_VECTORS 32 21972d64cc7SIngo Molnar 22072d64cc7SIngo Molnar /* Bitmask of exception vectors which push an error code on the stack: */ 22184f4fc52SH. Peter Anvin #define EXCEPTION_ERRCODE_MASK 0x00027d00 22272d64cc7SIngo Molnar 223bb898558SAl Viro #define GDT_SIZE (GDT_ENTRIES*8) 224bb898558SAl Viro #define GDT_ENTRY_TLS_ENTRIES 3 225bb898558SAl Viro #define TLS_SIZE (GDT_ENTRY_TLS_ENTRIES* 8) 226bb898558SAl Viro 227*ffebbaedSChang S. Bae #ifdef CONFIG_X86_64 228*ffebbaedSChang S. Bae 229*ffebbaedSChang S. Bae /* Bit size and mask of CPU number stored in the per CPU data (and TSC_AUX) */ 230*ffebbaedSChang S. Bae #define VDSO_CPU_SIZE 12 231*ffebbaedSChang S. Bae #define VDSO_CPU_MASK 0xfff 232*ffebbaedSChang S. Bae 233*ffebbaedSChang S. Bae #ifndef __ASSEMBLY__ 234*ffebbaedSChang S. Bae 235*ffebbaedSChang S. Bae /* Helper functions to store/load CPU and node numbers */ 236*ffebbaedSChang S. Bae 237*ffebbaedSChang S. Bae static inline unsigned long vdso_encode_cpu_node(int cpu, unsigned long node) 238*ffebbaedSChang S. Bae { 239*ffebbaedSChang S. Bae return ((node << VDSO_CPU_SIZE) | cpu); 240*ffebbaedSChang S. Bae } 241*ffebbaedSChang S. Bae 242*ffebbaedSChang S. Bae static inline void vdso_read_cpu_node(unsigned *cpu, unsigned *node) 243*ffebbaedSChang S. Bae { 244*ffebbaedSChang S. Bae unsigned int p; 245*ffebbaedSChang S. Bae 246*ffebbaedSChang S. Bae /* 247*ffebbaedSChang S. Bae * Load CPU and node number from GDT. LSL is faster than RDTSCP 248*ffebbaedSChang S. Bae * and works on all CPUs. This is volatile so that it orders 249*ffebbaedSChang S. Bae * correctly with respect to barrier() and to keep GCC from cleverly 250*ffebbaedSChang S. Bae * hoisting it out of the calling function. 251*ffebbaedSChang S. Bae * 252*ffebbaedSChang S. Bae * If RDPID is available, use it. 253*ffebbaedSChang S. Bae */ 254*ffebbaedSChang S. Bae alternative_io ("lsl %[seg],%[p]", 255*ffebbaedSChang S. Bae ".byte 0xf3,0x0f,0xc7,0xf8", /* RDPID %eax/rax */ 256*ffebbaedSChang S. Bae X86_FEATURE_RDPID, 257*ffebbaedSChang S. Bae [p] "=a" (p), [seg] "r" (__CPU_NUMBER_SEG)); 258*ffebbaedSChang S. Bae 259*ffebbaedSChang S. Bae if (cpu) 260*ffebbaedSChang S. Bae *cpu = (p & VDSO_CPU_MASK); 261*ffebbaedSChang S. Bae if (node) 262*ffebbaedSChang S. Bae *node = (p >> VDSO_CPU_SIZE); 263*ffebbaedSChang S. Bae } 264*ffebbaedSChang S. Bae 265*ffebbaedSChang S. Bae #endif /* !__ASSEMBLY__ */ 266*ffebbaedSChang S. Bae #endif /* CONFIG_X86_64 */ 267*ffebbaedSChang S. Bae 268bb898558SAl Viro #ifdef __KERNEL__ 269425be567SAndy Lutomirski 270425be567SAndy Lutomirski /* 271425be567SAndy Lutomirski * early_idt_handler_array is an array of entry points referenced in the 272425be567SAndy Lutomirski * early IDT. For simplicity, it's a real array with one entry point 273425be567SAndy Lutomirski * every nine bytes. That leaves room for an optional 'push $0' if the 274425be567SAndy Lutomirski * vector has no error code (two bytes), a 'push $vector_number' (two 275425be567SAndy Lutomirski * bytes), and a jump to the common entry code (up to five bytes). 276425be567SAndy Lutomirski */ 277425be567SAndy Lutomirski #define EARLY_IDT_HANDLER_SIZE 9 278425be567SAndy Lutomirski 27942b3a4cbSJuergen Gross /* 28042b3a4cbSJuergen Gross * xen_early_idt_handler_array is for Xen pv guests: for each entry in 28142b3a4cbSJuergen Gross * early_idt_handler_array it contains a prequel in the form of 28242b3a4cbSJuergen Gross * pop %rcx; pop %r11; jmp early_idt_handler_array[i]; summing up to 28342b3a4cbSJuergen Gross * max 8 bytes. 28442b3a4cbSJuergen Gross */ 28542b3a4cbSJuergen Gross #define XEN_EARLY_IDT_HANDLER_SIZE 8 28642b3a4cbSJuergen Gross 287bb898558SAl Viro #ifndef __ASSEMBLY__ 28872d64cc7SIngo Molnar 289425be567SAndy Lutomirski extern const char early_idt_handler_array[NUM_EXCEPTION_VECTORS][EARLY_IDT_HANDLER_SIZE]; 29087e81786SThomas Gleixner extern void early_ignore_irq(void); 291f05e798aSDavid Howells 29242b3a4cbSJuergen Gross #if defined(CONFIG_X86_64) && defined(CONFIG_XEN_PV) 29342b3a4cbSJuergen Gross extern const char xen_early_idt_handler_array[NUM_EXCEPTION_VECTORS][XEN_EARLY_IDT_HANDLER_SIZE]; 29442b3a4cbSJuergen Gross #endif 29542b3a4cbSJuergen Gross 296f05e798aSDavid Howells /* 29745e876f7SAndy Lutomirski * Load a segment. Fall back on loading the zero segment if something goes 29845e876f7SAndy Lutomirski * wrong. This variant assumes that loading zero fully clears the segment. 29945e876f7SAndy Lutomirski * This is always the case on Intel CPUs and, even on 64-bit AMD CPUs, any 30045e876f7SAndy Lutomirski * failure to fully clear the cached descriptor is only observable for 30145e876f7SAndy Lutomirski * FS and GS. 302f05e798aSDavid Howells */ 30345e876f7SAndy Lutomirski #define __loadsegment_simple(seg, value) \ 304f05e798aSDavid Howells do { \ 305f05e798aSDavid Howells unsigned short __val = (value); \ 306f05e798aSDavid Howells \ 307f05e798aSDavid Howells asm volatile(" \n" \ 308f05e798aSDavid Howells "1: movl %k0,%%" #seg " \n" \ 309f05e798aSDavid Howells \ 310f05e798aSDavid Howells ".section .fixup,\"ax\" \n" \ 311f05e798aSDavid Howells "2: xorl %k0,%k0 \n" \ 312f05e798aSDavid Howells " jmp 1b \n" \ 313f05e798aSDavid Howells ".previous \n" \ 314f05e798aSDavid Howells \ 315f05e798aSDavid Howells _ASM_EXTABLE(1b, 2b) \ 316f05e798aSDavid Howells \ 317f05e798aSDavid Howells : "+r" (__val) : : "memory"); \ 318f05e798aSDavid Howells } while (0) 319f05e798aSDavid Howells 32045e876f7SAndy Lutomirski #define __loadsegment_ss(value) __loadsegment_simple(ss, (value)) 32145e876f7SAndy Lutomirski #define __loadsegment_ds(value) __loadsegment_simple(ds, (value)) 32245e876f7SAndy Lutomirski #define __loadsegment_es(value) __loadsegment_simple(es, (value)) 32345e876f7SAndy Lutomirski 32445e876f7SAndy Lutomirski #ifdef CONFIG_X86_32 32545e876f7SAndy Lutomirski 32645e876f7SAndy Lutomirski /* 32745e876f7SAndy Lutomirski * On 32-bit systems, the hidden parts of FS and GS are unobservable if 32845e876f7SAndy Lutomirski * the selector is NULL, so there's no funny business here. 32945e876f7SAndy Lutomirski */ 33045e876f7SAndy Lutomirski #define __loadsegment_fs(value) __loadsegment_simple(fs, (value)) 33145e876f7SAndy Lutomirski #define __loadsegment_gs(value) __loadsegment_simple(gs, (value)) 33245e876f7SAndy Lutomirski 33345e876f7SAndy Lutomirski #else 33445e876f7SAndy Lutomirski 33545e876f7SAndy Lutomirski static inline void __loadsegment_fs(unsigned short value) 33645e876f7SAndy Lutomirski { 33745e876f7SAndy Lutomirski asm volatile(" \n" 33845e876f7SAndy Lutomirski "1: movw %0, %%fs \n" 33945e876f7SAndy Lutomirski "2: \n" 34045e876f7SAndy Lutomirski 34145e876f7SAndy Lutomirski _ASM_EXTABLE_HANDLE(1b, 2b, ex_handler_clear_fs) 34245e876f7SAndy Lutomirski 34345e876f7SAndy Lutomirski : : "rm" (value) : "memory"); 34445e876f7SAndy Lutomirski } 34545e876f7SAndy Lutomirski 34645e876f7SAndy Lutomirski /* __loadsegment_gs is intentionally undefined. Use load_gs_index instead. */ 34745e876f7SAndy Lutomirski 34845e876f7SAndy Lutomirski #endif 34945e876f7SAndy Lutomirski 35045e876f7SAndy Lutomirski #define loadsegment(seg, value) __loadsegment_ ## seg (value) 35145e876f7SAndy Lutomirski 352f05e798aSDavid Howells /* 35372d64cc7SIngo Molnar * Save a segment register away: 354f05e798aSDavid Howells */ 355f05e798aSDavid Howells #define savesegment(seg, value) \ 356f05e798aSDavid Howells asm("mov %%" #seg ",%0":"=r" (value) : : "memory") 357f05e798aSDavid Howells 358f05e798aSDavid Howells /* 35972d64cc7SIngo Molnar * x86-32 user GS accessors: 360f05e798aSDavid Howells */ 361f05e798aSDavid Howells #ifdef CONFIG_X86_32 362f05e798aSDavid Howells # ifdef CONFIG_X86_32_LAZY_GS 363f05e798aSDavid Howells # define get_user_gs(regs) (u16)({ unsigned long v; savesegment(gs, v); v; }) 364f05e798aSDavid Howells # define set_user_gs(regs, v) loadsegment(gs, (unsigned long)(v)) 365f05e798aSDavid Howells # define task_user_gs(tsk) ((tsk)->thread.gs) 366f05e798aSDavid Howells # define lazy_save_gs(v) savesegment(gs, (v)) 367f05e798aSDavid Howells # define lazy_load_gs(v) loadsegment(gs, (v)) 368f05e798aSDavid Howells # else /* X86_32_LAZY_GS */ 369f05e798aSDavid Howells # define get_user_gs(regs) (u16)((regs)->gs) 370f05e798aSDavid Howells # define set_user_gs(regs, v) do { (regs)->gs = (v); } while (0) 371f05e798aSDavid Howells # define task_user_gs(tsk) (task_pt_regs(tsk)->gs) 372f05e798aSDavid Howells # define lazy_save_gs(v) do { } while (0) 373f05e798aSDavid Howells # define lazy_load_gs(v) do { } while (0) 374f05e798aSDavid Howells # endif /* X86_32_LAZY_GS */ 375f05e798aSDavid Howells #endif /* X86_32 */ 376f05e798aSDavid Howells 377f05e798aSDavid Howells #endif /* !__ASSEMBLY__ */ 378f05e798aSDavid Howells #endif /* __KERNEL__ */ 379bb898558SAl Viro 3801965aae3SH. Peter Anvin #endif /* _ASM_X86_SEGMENT_H */ 381