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> 78f93402bSPeter Zijlstra #include <asm/ibt.h> 8014eea51SH. Peter Anvin 972d64cc7SIngo Molnar /* 1072d64cc7SIngo Molnar * Constructor for a conventional segment GDT (or LDT) entry. 1172d64cc7SIngo Molnar * This is a macro so it can be used in initializers. 1272d64cc7SIngo Molnar */ 13bb898558SAl Viro #define GDT_ENTRY(flags, base, limit) \ 14014eea51SH. Peter Anvin ((((base) & _AC(0xff000000,ULL)) << (56-24)) | \ 15014eea51SH. Peter Anvin (((flags) & _AC(0x0000f0ff,ULL)) << 40) | \ 16014eea51SH. Peter Anvin (((limit) & _AC(0x000f0000,ULL)) << (48-16)) | \ 17014eea51SH. Peter Anvin (((base) & _AC(0x00ffffff,ULL)) << 16) | \ 18014eea51SH. Peter Anvin (((limit) & _AC(0x0000ffff,ULL)))) 19bb898558SAl Viro 2072d64cc7SIngo Molnar /* Simple and small GDT entries for booting only: */ 21bb898558SAl Viro 22bb898558SAl Viro #define GDT_ENTRY_BOOT_CS 2 2384f53788SDenys Vlasenko #define GDT_ENTRY_BOOT_DS 3 2484f53788SDenys Vlasenko #define GDT_ENTRY_BOOT_TSS 4 25bb898558SAl Viro #define __BOOT_CS (GDT_ENTRY_BOOT_CS*8) 26bb898558SAl Viro #define __BOOT_DS (GDT_ENTRY_BOOT_DS*8) 27bb898558SAl Viro #define __BOOT_TSS (GDT_ENTRY_BOOT_TSS*8) 28bb898558SAl Viro 2972d64cc7SIngo Molnar /* 30be9d1738SBorislav Petkov * Bottom two bits of selector give the ring 31be9d1738SBorislav Petkov * privilege level 32be9d1738SBorislav Petkov */ 3372d64cc7SIngo Molnar #define SEGMENT_RPL_MASK 0x3 3472d64cc7SIngo Molnar 3581ff2c37SJan Beulich /* 3681ff2c37SJan Beulich * When running on Xen PV, the actual privilege level of the kernel is 1, 3781ff2c37SJan Beulich * not 0. Testing the Requested Privilege Level in a segment selector to 3881ff2c37SJan Beulich * determine whether the context is user mode or kernel mode with 3981ff2c37SJan Beulich * SEGMENT_RPL_MASK is wrong because the PV kernel's privilege level 4081ff2c37SJan Beulich * matches the 0x3 mask. 4181ff2c37SJan Beulich * 4281ff2c37SJan Beulich * Testing with USER_SEGMENT_RPL_MASK is valid for both native and Xen PV 4381ff2c37SJan Beulich * kernels because privilege level 2 is never used. 4481ff2c37SJan Beulich */ 4581ff2c37SJan Beulich #define USER_SEGMENT_RPL_MASK 0x2 4681ff2c37SJan Beulich 4772d64cc7SIngo Molnar /* User mode is privilege level 3: */ 4872d64cc7SIngo Molnar #define USER_RPL 0x3 4972d64cc7SIngo Molnar 5072d64cc7SIngo Molnar /* Bit 2 is Table Indicator (TI): selects between LDT or GDT */ 5172d64cc7SIngo Molnar #define SEGMENT_TI_MASK 0x4 5272d64cc7SIngo Molnar /* LDT segment has TI set ... */ 5372d64cc7SIngo Molnar #define SEGMENT_LDT 0x4 5472d64cc7SIngo Molnar /* ... GDT has it cleared */ 5572d64cc7SIngo Molnar #define SEGMENT_GDT 0x0 56be9d1738SBorislav Petkov 576b51311cSBorislav Petkov #define GDT_ENTRY_INVALID_SEG 0 586b51311cSBorislav Petkov 59bb898558SAl Viro #ifdef CONFIG_X86_32 60bb898558SAl Viro /* 61bb898558SAl Viro * The layout of the per-CPU GDT under Linux: 62bb898558SAl Viro * 6372d64cc7SIngo Molnar * 0 - null <=== cacheline #1 64bb898558SAl Viro * 1 - reserved 65bb898558SAl Viro * 2 - reserved 66bb898558SAl Viro * 3 - reserved 67bb898558SAl Viro * 6872d64cc7SIngo Molnar * 4 - unused <=== cacheline #2 69bb898558SAl Viro * 5 - unused 70bb898558SAl Viro * 71bb898558SAl Viro * ------- start of TLS (Thread-Local Storage) segments: 72bb898558SAl Viro * 73bb898558SAl Viro * 6 - TLS segment #1 [ glibc's TLS segment ] 74bb898558SAl Viro * 7 - TLS segment #2 [ Wine's %fs Win32 segment ] 7572d64cc7SIngo Molnar * 8 - TLS segment #3 <=== cacheline #3 76bb898558SAl Viro * 9 - reserved 77bb898558SAl Viro * 10 - reserved 78bb898558SAl Viro * 11 - reserved 79bb898558SAl Viro * 80bb898558SAl Viro * ------- start of kernel segments: 81bb898558SAl Viro * 8272d64cc7SIngo Molnar * 12 - kernel code segment <=== cacheline #4 83bb898558SAl Viro * 13 - kernel data segment 84bb898558SAl Viro * 14 - default user CS 85bb898558SAl Viro * 15 - default user DS 8672d64cc7SIngo Molnar * 16 - TSS <=== cacheline #5 87bb898558SAl Viro * 17 - LDT 88bb898558SAl Viro * 18 - PNPBIOS support (16->32 gate) 89bb898558SAl Viro * 19 - PNPBIOS support 9072d64cc7SIngo Molnar * 20 - PNPBIOS support <=== cacheline #6 91bb898558SAl Viro * 21 - PNPBIOS support 92bb898558SAl Viro * 22 - PNPBIOS support 93bb898558SAl Viro * 23 - APM BIOS support 9472d64cc7SIngo Molnar * 24 - APM BIOS support <=== cacheline #7 95bb898558SAl Viro * 25 - APM BIOS support 96bb898558SAl Viro * 97bb898558SAl Viro * 26 - ESPFIX small SS 98bb898558SAl Viro * 27 - per-cpu [ offset to per-cpu data area ] 99*717cce3bSSebastian Andrzej Siewior * 28 - VDSO getcpu 100bb898558SAl Viro * 29 - unused 101bb898558SAl Viro * 30 - unused 102bb898558SAl Viro * 31 - TSS for double fault handler 103bb898558SAl Viro */ 104bb898558SAl Viro #define GDT_ENTRY_TLS_MIN 6 105bb898558SAl Viro #define GDT_ENTRY_TLS_MAX (GDT_ENTRY_TLS_MIN + GDT_ENTRY_TLS_ENTRIES - 1) 106bb898558SAl Viro 10784f53788SDenys Vlasenko #define GDT_ENTRY_KERNEL_CS 12 10884f53788SDenys Vlasenko #define GDT_ENTRY_KERNEL_DS 13 109bb898558SAl Viro #define GDT_ENTRY_DEFAULT_USER_CS 14 110bb898558SAl Viro #define GDT_ENTRY_DEFAULT_USER_DS 15 11184f53788SDenys Vlasenko #define GDT_ENTRY_TSS 16 11284f53788SDenys Vlasenko #define GDT_ENTRY_LDT 17 11384f53788SDenys Vlasenko #define GDT_ENTRY_PNPBIOS_CS32 18 11484f53788SDenys Vlasenko #define GDT_ENTRY_PNPBIOS_CS16 19 11584f53788SDenys Vlasenko #define GDT_ENTRY_PNPBIOS_DS 20 11684f53788SDenys Vlasenko #define GDT_ENTRY_PNPBIOS_TS1 21 11784f53788SDenys Vlasenko #define GDT_ENTRY_PNPBIOS_TS2 22 11884f53788SDenys Vlasenko #define GDT_ENTRY_APMBIOS_BASE 23 119bb898558SAl Viro 12084f53788SDenys Vlasenko #define GDT_ENTRY_ESPFIX_SS 26 12184f53788SDenys Vlasenko #define GDT_ENTRY_PERCPU 27 122*717cce3bSSebastian Andrzej Siewior #define GDT_ENTRY_CPUNODE 28 123bb898558SAl Viro 12484f53788SDenys Vlasenko #define GDT_ENTRY_DOUBLEFAULT_TSS 31 125bb898558SAl Viro 12672d64cc7SIngo Molnar /* 12772d64cc7SIngo Molnar * Number of entries in the GDT table: 12872d64cc7SIngo Molnar */ 12972d64cc7SIngo Molnar #define GDT_ENTRIES 32 13072d64cc7SIngo Molnar 13172d64cc7SIngo Molnar /* 13272d64cc7SIngo Molnar * Segment selector values corresponding to the above entries: 13372d64cc7SIngo Molnar */ 13472d64cc7SIngo Molnar 13584f53788SDenys Vlasenko #define __KERNEL_CS (GDT_ENTRY_KERNEL_CS*8) 13684f53788SDenys Vlasenko #define __KERNEL_DS (GDT_ENTRY_KERNEL_DS*8) 13784f53788SDenys Vlasenko #define __USER_DS (GDT_ENTRY_DEFAULT_USER_DS*8 + 3) 13884f53788SDenys Vlasenko #define __USER_CS (GDT_ENTRY_DEFAULT_USER_CS*8 + 3) 13924e6dc35SBrian Gerst #define __USER32_CS __USER_CS 140bb898558SAl Viro #define __ESPFIX_SS (GDT_ENTRY_ESPFIX_SS*8) 14172d64cc7SIngo Molnar 14272d64cc7SIngo Molnar /* segment for calling fn: */ 14372d64cc7SIngo Molnar #define PNP_CS32 (GDT_ENTRY_PNPBIOS_CS32*8) 14472d64cc7SIngo Molnar /* code segment for BIOS: */ 14572d64cc7SIngo Molnar #define PNP_CS16 (GDT_ENTRY_PNPBIOS_CS16*8) 14672d64cc7SIngo Molnar 14784f53788SDenys Vlasenko /* "Is this PNP code selector (PNP_CS32 or PNP_CS16)?" */ 14884f53788SDenys Vlasenko #define SEGMENT_IS_PNP_CODE(x) (((x) & 0xf4) == PNP_CS32) 14972d64cc7SIngo Molnar 15072d64cc7SIngo Molnar /* data segment for BIOS: */ 15172d64cc7SIngo Molnar #define PNP_DS (GDT_ENTRY_PNPBIOS_DS*8) 15272d64cc7SIngo Molnar /* transfer data segment: */ 15372d64cc7SIngo Molnar #define PNP_TS1 (GDT_ENTRY_PNPBIOS_TS1*8) 15472d64cc7SIngo Molnar /* another data segment: */ 15572d64cc7SIngo Molnar #define PNP_TS2 (GDT_ENTRY_PNPBIOS_TS2*8) 15672d64cc7SIngo Molnar 157bb898558SAl Viro #ifdef CONFIG_SMP 158bb898558SAl Viro # define __KERNEL_PERCPU (GDT_ENTRY_PERCPU*8) 159bb898558SAl Viro #else 160bb898558SAl Viro # define __KERNEL_PERCPU 0 161bb898558SAl Viro #endif 16272d64cc7SIngo Molnar 163*717cce3bSSebastian Andrzej Siewior #define __CPUNODE_SEG (GDT_ENTRY_CPUNODE*8 + 3) 164*717cce3bSSebastian Andrzej Siewior 16584f53788SDenys Vlasenko #else /* 64-bit: */ 166bb898558SAl Viro 167bb898558SAl Viro #include <asm/cache.h> 168bb898558SAl Viro 169bb898558SAl Viro #define GDT_ENTRY_KERNEL32_CS 1 170bb898558SAl Viro #define GDT_ENTRY_KERNEL_CS 2 171bb898558SAl Viro #define GDT_ENTRY_KERNEL_DS 3 17272d64cc7SIngo Molnar 173bb898558SAl Viro /* 17472d64cc7SIngo Molnar * We cannot use the same code segment descriptor for user and kernel mode, 17572d64cc7SIngo Molnar * not even in long flat mode, because of different DPL. 17672d64cc7SIngo Molnar * 17772d64cc7SIngo Molnar * GDT layout to get 64-bit SYSCALL/SYSRET support right. SYSRET hardcodes 17872d64cc7SIngo Molnar * selectors: 17972d64cc7SIngo Molnar * 18084f53788SDenys Vlasenko * if returning to 32-bit userspace: cs = STAR.SYSRET_CS, 18184f53788SDenys Vlasenko * if returning to 64-bit userspace: cs = STAR.SYSRET_CS+16, 18272d64cc7SIngo Molnar * 18384f53788SDenys Vlasenko * ss = STAR.SYSRET_CS+8 (in either case) 18472d64cc7SIngo Molnar * 18584f53788SDenys Vlasenko * thus USER_DS should be between 32-bit and 64-bit code selectors: 186bb898558SAl Viro */ 187bb898558SAl Viro #define GDT_ENTRY_DEFAULT_USER32_CS 4 188bb898558SAl Viro #define GDT_ENTRY_DEFAULT_USER_DS 5 189bb898558SAl Viro #define GDT_ENTRY_DEFAULT_USER_CS 6 190bb898558SAl Viro 19172d64cc7SIngo Molnar /* Needs two entries */ 19272d64cc7SIngo Molnar #define GDT_ENTRY_TSS 8 19372d64cc7SIngo Molnar /* Needs two entries */ 19472d64cc7SIngo Molnar #define GDT_ENTRY_LDT 10 19572d64cc7SIngo Molnar 196bb898558SAl Viro #define GDT_ENTRY_TLS_MIN 12 197bb898558SAl Viro #define GDT_ENTRY_TLS_MAX 14 198bb898558SAl Viro 19922245bdfSIngo Molnar #define GDT_ENTRY_CPUNODE 15 20084f53788SDenys Vlasenko 20172d64cc7SIngo Molnar /* 20272d64cc7SIngo Molnar * Number of entries in the GDT table: 20372d64cc7SIngo Molnar */ 20472d64cc7SIngo Molnar #define GDT_ENTRIES 16 20572d64cc7SIngo Molnar 20672d64cc7SIngo Molnar /* 20772d64cc7SIngo Molnar * Segment selector values corresponding to the above entries: 20872d64cc7SIngo Molnar * 20972d64cc7SIngo Molnar * Note, selectors also need to have a correct RPL, 21072d64cc7SIngo Molnar * expressed with the +3 value for user-space selectors: 21172d64cc7SIngo Molnar */ 21272d64cc7SIngo Molnar #define __KERNEL32_CS (GDT_ENTRY_KERNEL32_CS*8) 21384f53788SDenys Vlasenko #define __KERNEL_CS (GDT_ENTRY_KERNEL_CS*8) 21484f53788SDenys Vlasenko #define __KERNEL_DS (GDT_ENTRY_KERNEL_DS*8) 21584f53788SDenys Vlasenko #define __USER32_CS (GDT_ENTRY_DEFAULT_USER32_CS*8 + 3) 21672d64cc7SIngo Molnar #define __USER_DS (GDT_ENTRY_DEFAULT_USER_DS*8 + 3) 21772d64cc7SIngo Molnar #define __USER_CS (GDT_ENTRY_DEFAULT_USER_CS*8 + 3) 21822245bdfSIngo Molnar #define __CPUNODE_SEG (GDT_ENTRY_CPUNODE*8 + 3) 219bb898558SAl Viro 220bb898558SAl Viro #endif 221bb898558SAl Viro 222bb898558SAl Viro #define IDT_ENTRIES 256 223bb898558SAl Viro #define NUM_EXCEPTION_VECTORS 32 22472d64cc7SIngo Molnar 22572d64cc7SIngo Molnar /* Bitmask of exception vectors which push an error code on the stack: */ 2261aa9aa8eSJoerg Roedel #define EXCEPTION_ERRCODE_MASK 0x20027d00 22772d64cc7SIngo Molnar 228bb898558SAl Viro #define GDT_SIZE (GDT_ENTRIES*8) 229bb898558SAl Viro #define GDT_ENTRY_TLS_ENTRIES 3 230bb898558SAl Viro #define TLS_SIZE (GDT_ENTRY_TLS_ENTRIES* 8) 231bb898558SAl Viro 232ffebbaedSChang S. Bae /* Bit size and mask of CPU number stored in the per CPU data (and TSC_AUX) */ 23322245bdfSIngo Molnar #define VDSO_CPUNODE_BITS 12 23422245bdfSIngo Molnar #define VDSO_CPUNODE_MASK 0xfff 235ffebbaedSChang S. Bae 236ffebbaedSChang S. Bae #ifndef __ASSEMBLY__ 237ffebbaedSChang S. Bae 238ffebbaedSChang S. Bae /* Helper functions to store/load CPU and node numbers */ 239ffebbaedSChang S. Bae 24022245bdfSIngo Molnar static inline unsigned long vdso_encode_cpunode(int cpu, unsigned long node) 241ffebbaedSChang S. Bae { 24222245bdfSIngo Molnar return (node << VDSO_CPUNODE_BITS) | cpu; 243ffebbaedSChang S. Bae } 244ffebbaedSChang S. Bae 24522245bdfSIngo Molnar static inline void vdso_read_cpunode(unsigned *cpu, unsigned *node) 246ffebbaedSChang S. Bae { 247ffebbaedSChang S. Bae unsigned int p; 248ffebbaedSChang S. Bae 249ffebbaedSChang S. Bae /* 25022245bdfSIngo Molnar * Load CPU and node number from the GDT. LSL is faster than RDTSCP 251ffebbaedSChang S. Bae * and works on all CPUs. This is volatile so that it orders 252ffebbaedSChang S. Bae * correctly with respect to barrier() and to keep GCC from cleverly 253ffebbaedSChang S. Bae * hoisting it out of the calling function. 254ffebbaedSChang S. Bae * 255ffebbaedSChang S. Bae * If RDPID is available, use it. 256ffebbaedSChang S. Bae */ 257ffebbaedSChang S. Bae alternative_io ("lsl %[seg],%[p]", 258ffebbaedSChang S. Bae ".byte 0xf3,0x0f,0xc7,0xf8", /* RDPID %eax/rax */ 259ffebbaedSChang S. Bae X86_FEATURE_RDPID, 26022245bdfSIngo Molnar [p] "=a" (p), [seg] "r" (__CPUNODE_SEG)); 261ffebbaedSChang S. Bae 262ffebbaedSChang S. Bae if (cpu) 26322245bdfSIngo Molnar *cpu = (p & VDSO_CPUNODE_MASK); 264ffebbaedSChang S. Bae if (node) 26522245bdfSIngo Molnar *node = (p >> VDSO_CPUNODE_BITS); 266ffebbaedSChang S. Bae } 267ffebbaedSChang S. Bae 268ffebbaedSChang S. Bae #endif /* !__ASSEMBLY__ */ 269ffebbaedSChang S. Bae 270bb898558SAl Viro #ifdef __KERNEL__ 271425be567SAndy Lutomirski 272425be567SAndy Lutomirski /* 273425be567SAndy Lutomirski * early_idt_handler_array is an array of entry points referenced in the 274425be567SAndy Lutomirski * early IDT. For simplicity, it's a real array with one entry point 275425be567SAndy Lutomirski * every nine bytes. That leaves room for an optional 'push $0' if the 276425be567SAndy Lutomirski * vector has no error code (two bytes), a 'push $vector_number' (two 277425be567SAndy Lutomirski * bytes), and a jump to the common entry code (up to five bytes). 278425be567SAndy Lutomirski */ 2798f93402bSPeter Zijlstra #define EARLY_IDT_HANDLER_SIZE (9 + ENDBR_INSN_SIZE) 280425be567SAndy Lutomirski 28142b3a4cbSJuergen Gross /* 28242b3a4cbSJuergen Gross * xen_early_idt_handler_array is for Xen pv guests: for each entry in 28342b3a4cbSJuergen Gross * early_idt_handler_array it contains a prequel in the form of 28442b3a4cbSJuergen Gross * pop %rcx; pop %r11; jmp early_idt_handler_array[i]; summing up to 28542b3a4cbSJuergen Gross * max 8 bytes. 28642b3a4cbSJuergen Gross */ 2875b2fc515SPeter Zijlstra #define XEN_EARLY_IDT_HANDLER_SIZE (8 + ENDBR_INSN_SIZE) 28842b3a4cbSJuergen Gross 289bb898558SAl Viro #ifndef __ASSEMBLY__ 29072d64cc7SIngo Molnar 291425be567SAndy Lutomirski extern const char early_idt_handler_array[NUM_EXCEPTION_VECTORS][EARLY_IDT_HANDLER_SIZE]; 29287e81786SThomas Gleixner extern void early_ignore_irq(void); 293f05e798aSDavid Howells 294a13f2ef1SJuergen Gross #ifdef CONFIG_XEN_PV 29542b3a4cbSJuergen Gross extern const char xen_early_idt_handler_array[NUM_EXCEPTION_VECTORS][XEN_EARLY_IDT_HANDLER_SIZE]; 29642b3a4cbSJuergen Gross #endif 29742b3a4cbSJuergen Gross 298f05e798aSDavid Howells /* 29945e876f7SAndy Lutomirski * Load a segment. Fall back on loading the zero segment if something goes 30045e876f7SAndy Lutomirski * wrong. This variant assumes that loading zero fully clears the segment. 30145e876f7SAndy Lutomirski * This is always the case on Intel CPUs and, even on 64-bit AMD CPUs, any 30245e876f7SAndy Lutomirski * failure to fully clear the cached descriptor is only observable for 30345e876f7SAndy Lutomirski * FS and GS. 304f05e798aSDavid Howells */ 30545e876f7SAndy Lutomirski #define __loadsegment_simple(seg, value) \ 306f05e798aSDavid Howells do { \ 307f05e798aSDavid Howells unsigned short __val = (value); \ 308f05e798aSDavid Howells \ 309f05e798aSDavid Howells asm volatile(" \n" \ 310f05e798aSDavid Howells "1: movl %k0,%%" #seg " \n" \ 3115fc77b91SPeter Zijlstra _ASM_EXTABLE_TYPE_REG(1b, 1b, EX_TYPE_ZERO_REG, %k0)\ 312f05e798aSDavid Howells : "+r" (__val) : : "memory"); \ 313f05e798aSDavid Howells } while (0) 314f05e798aSDavid Howells 31545e876f7SAndy Lutomirski #define __loadsegment_ss(value) __loadsegment_simple(ss, (value)) 31645e876f7SAndy Lutomirski #define __loadsegment_ds(value) __loadsegment_simple(ds, (value)) 31745e876f7SAndy Lutomirski #define __loadsegment_es(value) __loadsegment_simple(es, (value)) 31845e876f7SAndy Lutomirski 31945e876f7SAndy Lutomirski #ifdef CONFIG_X86_32 32045e876f7SAndy Lutomirski 32145e876f7SAndy Lutomirski /* 32245e876f7SAndy Lutomirski * On 32-bit systems, the hidden parts of FS and GS are unobservable if 32345e876f7SAndy Lutomirski * the selector is NULL, so there's no funny business here. 32445e876f7SAndy Lutomirski */ 32545e876f7SAndy Lutomirski #define __loadsegment_fs(value) __loadsegment_simple(fs, (value)) 32645e876f7SAndy Lutomirski #define __loadsegment_gs(value) __loadsegment_simple(gs, (value)) 32745e876f7SAndy Lutomirski 32845e876f7SAndy Lutomirski #else 32945e876f7SAndy Lutomirski 33045e876f7SAndy Lutomirski static inline void __loadsegment_fs(unsigned short value) 33145e876f7SAndy Lutomirski { 33245e876f7SAndy Lutomirski asm volatile(" \n" 33345e876f7SAndy Lutomirski "1: movw %0, %%fs \n" 33445e876f7SAndy Lutomirski "2: \n" 33545e876f7SAndy Lutomirski 33646d28947SThomas Gleixner _ASM_EXTABLE_TYPE(1b, 2b, EX_TYPE_CLEAR_FS) 33745e876f7SAndy Lutomirski 33845e876f7SAndy Lutomirski : : "rm" (value) : "memory"); 33945e876f7SAndy Lutomirski } 34045e876f7SAndy Lutomirski 34145e876f7SAndy Lutomirski /* __loadsegment_gs is intentionally undefined. Use load_gs_index instead. */ 34245e876f7SAndy Lutomirski 34345e876f7SAndy Lutomirski #endif 34445e876f7SAndy Lutomirski 34545e876f7SAndy Lutomirski #define loadsegment(seg, value) __loadsegment_ ## seg (value) 34645e876f7SAndy Lutomirski 347f05e798aSDavid Howells /* 34872d64cc7SIngo Molnar * Save a segment register away: 349f05e798aSDavid Howells */ 350f05e798aSDavid Howells #define savesegment(seg, value) \ 351f05e798aSDavid Howells asm("mov %%" #seg ",%0":"=r" (value) : : "memory") 352f05e798aSDavid Howells 353f05e798aSDavid Howells #endif /* !__ASSEMBLY__ */ 354f05e798aSDavid Howells #endif /* __KERNEL__ */ 355bb898558SAl Viro 3561965aae3SH. Peter Anvin #endif /* _ASM_X86_SEGMENT_H */ 357