1*63587e37Srillig /* $NetBSD: segments.h,v 1.38 2021/04/17 20:12:55 rillig Exp $ */ 2aad01611Sagc 3e1a67720Smaxv /* 4aad01611Sagc * Copyright (c) 1990 The Regents of the University of California. 5aad01611Sagc * All rights reserved. 6aad01611Sagc * 7aad01611Sagc * This code is derived from software contributed to Berkeley by 8aad01611Sagc * William Jolitz. 9aad01611Sagc * 10aad01611Sagc * Redistribution and use in source and binary forms, with or without 11aad01611Sagc * modification, are permitted provided that the following conditions 12aad01611Sagc * are met: 13aad01611Sagc * 1. Redistributions of source code must retain the above copyright 14aad01611Sagc * notice, this list of conditions and the following disclaimer. 15aad01611Sagc * 2. Redistributions in binary form must reproduce the above copyright 16aad01611Sagc * notice, this list of conditions and the following disclaimer in the 17aad01611Sagc * documentation and/or other materials provided with the distribution. 18aad01611Sagc * 3. Neither the name of the University nor the names of its contributors 19aad01611Sagc * may be used to endorse or promote products derived from this software 20aad01611Sagc * without specific prior written permission. 21aad01611Sagc * 22aad01611Sagc * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 23aad01611Sagc * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 24aad01611Sagc * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 25aad01611Sagc * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 26aad01611Sagc * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 27aad01611Sagc * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 28aad01611Sagc * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 29aad01611Sagc * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 30aad01611Sagc * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 31aad01611Sagc * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 32aad01611Sagc * SUCH DAMAGE. 33aad01611Sagc * 34aad01611Sagc * @(#)segments.h 7.1 (Berkeley) 5/9/91 35aad01611Sagc */ 3681918bf8Sfvdl 37e1a67720Smaxv /* 3881918bf8Sfvdl * Copyright (c) 1995, 1997 3981918bf8Sfvdl * Charles M. Hannum. All rights reserved. 4081918bf8Sfvdl * Copyright (c) 1989, 1990 William F. Jolitz 4181918bf8Sfvdl * 4281918bf8Sfvdl * This code is derived from software contributed to Berkeley by 4381918bf8Sfvdl * William Jolitz. 4481918bf8Sfvdl * 4581918bf8Sfvdl * Redistribution and use in source and binary forms, with or without 4681918bf8Sfvdl * modification, are permitted provided that the following conditions 4781918bf8Sfvdl * are met: 4881918bf8Sfvdl * 1. Redistributions of source code must retain the above copyright 4981918bf8Sfvdl * notice, this list of conditions and the following disclaimer. 5081918bf8Sfvdl * 2. Redistributions in binary form must reproduce the above copyright 5181918bf8Sfvdl * notice, this list of conditions and the following disclaimer in the 5281918bf8Sfvdl * documentation and/or other materials provided with the distribution. 5381918bf8Sfvdl * 3. All advertising materials mentioning features or use of this software 5481918bf8Sfvdl * must display the following acknowledgement: 5581918bf8Sfvdl * This product includes software developed by the University of 5681918bf8Sfvdl * California, Berkeley and its contributors. 5781918bf8Sfvdl * 4. Neither the name of the University nor the names of its contributors 5881918bf8Sfvdl * may be used to endorse or promote products derived from this software 5981918bf8Sfvdl * without specific prior written permission. 6081918bf8Sfvdl * 6181918bf8Sfvdl * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 6281918bf8Sfvdl * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 6381918bf8Sfvdl * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 6481918bf8Sfvdl * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 6581918bf8Sfvdl * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 6681918bf8Sfvdl * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 6781918bf8Sfvdl * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 6881918bf8Sfvdl * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 6981918bf8Sfvdl * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 7081918bf8Sfvdl * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 7181918bf8Sfvdl * SUCH DAMAGE. 7281918bf8Sfvdl * 7381918bf8Sfvdl * @(#)segments.h 7.1 (Berkeley) 5/9/91 7481918bf8Sfvdl */ 7581918bf8Sfvdl 7681918bf8Sfvdl /* 7781918bf8Sfvdl * Adapted for NetBSD/amd64 by fvdl@wasabisystems.com. 7881918bf8Sfvdl */ 7981918bf8Sfvdl 8081918bf8Sfvdl /* 8181918bf8Sfvdl * 386 Segmentation Data Structures and definitions 8281918bf8Sfvdl * William F. Jolitz (william@ernie.berkeley.edu) 6/20/1989 8381918bf8Sfvdl */ 8481918bf8Sfvdl 8581918bf8Sfvdl #ifndef _AMD64_SEGMENTS_H_ 8681918bf8Sfvdl #define _AMD64_SEGMENTS_H_ 87433b5ddeSmrg 88433b5ddeSmrg #ifdef __x86_64__ 89433b5ddeSmrg 90b378f8b2Sbouyer #ifdef _KERNEL_OPT 914e541343Sbouyer #include "opt_xen.h" 924264e84aSbouyer #endif 9381918bf8Sfvdl 9481918bf8Sfvdl /* 9581918bf8Sfvdl * Selectors 9681918bf8Sfvdl */ 9781918bf8Sfvdl 9881918bf8Sfvdl #define ISPL(s) ((s) & SEL_RPL) /* what is the priority level of a selector */ 99427af037Scherry #ifdef XENPV 1004e541343Sbouyer #define SEL_KPL 3 /* kernel privilege level */ 1014e541343Sbouyer #define SEL_XPL 0 /* Xen Hypervisor privilege level */ 1024e541343Sbouyer #else 10381918bf8Sfvdl #define SEL_KPL 0 /* kernel privilege level */ 1044e541343Sbouyer #endif 10581918bf8Sfvdl #define SEL_UPL 3 /* user privilege level */ 10681918bf8Sfvdl #define SEL_RPL 3 /* requester's privilege level mask */ 10781918bf8Sfvdl #define ISLDT(s) ((s) & SEL_LDT) /* is it local or global */ 10881918bf8Sfvdl #define SEL_LDT 4 /* local descriptor table */ 10981918bf8Sfvdl 110427af037Scherry #ifdef XENPV 11130ec1abeSmaxv #define IOPL_KPL 1 11230ec1abeSmaxv #else 11330ec1abeSmaxv #define IOPL_KPL SEL_KPL 11430ec1abeSmaxv #endif 11530ec1abeSmaxv 11681918bf8Sfvdl /* Dynamically allocated TSSs and LDTs start (byte offset) */ 11781918bf8Sfvdl #define SYSSEL_START (NGDT_MEM << 3) 11881918bf8Sfvdl #define DYNSEL_START (SYSSEL_START + (NGDT_SYS << 4)) 11981918bf8Sfvdl 12081918bf8Sfvdl /* 12181918bf8Sfvdl * These define the index not from the start of the GDT, but from 12281918bf8Sfvdl * the part of the GDT that they're allocated from. 12381918bf8Sfvdl * First NGDT_MEM entries are 8-byte descriptors for CS and DS. 12481918bf8Sfvdl * Next NGDT_SYS entries are 16-byte descriptors defining LDTs. 12581918bf8Sfvdl * 12681918bf8Sfvdl * The rest is 16-byte descriptors for TSS and LDT. 12781918bf8Sfvdl */ 12881918bf8Sfvdl 12981918bf8Sfvdl #define IDXSEL(s) (((s) >> 3) & 0x1fff) 13081918bf8Sfvdl #define IDXDYNSEL(s) ((((s) & ~SEL_RPL) - DYNSEL_START) >> 4) 13181918bf8Sfvdl 13281918bf8Sfvdl #define GSEL(s,r) (((s) << 3) | r) 13381918bf8Sfvdl #define GSYSSEL(s,r) ((((s) << 4) + SYSSEL_START) | r) 13481918bf8Sfvdl #define GDYNSEL(s,r) ((((s) << 4) + DYNSEL_START) | r | SEL_KPL) 13581918bf8Sfvdl 13681918bf8Sfvdl #define LSEL(s,r) ((s) | r | SEL_LDT) 13781918bf8Sfvdl 1387ad103f4Smaxv #define USERMODE(c) (ISPL(c) == SEL_UPL) 139427af037Scherry #ifdef XENPV 1404e541343Sbouyer /* 1414e541343Sbouyer * As KPL == UPL, Xen emulate interrupt in kernel context by pushing 1424e541343Sbouyer * a fake CS with XPL privilege 1434e541343Sbouyer */ 1447ad103f4Smaxv #define KERNELMODE(c) (ISPL(c) == SEL_XPL) 1454e541343Sbouyer #else 1467ad103f4Smaxv #define KERNELMODE(c) (ISPL(c) == SEL_KPL) 1474e541343Sbouyer #endif 14881918bf8Sfvdl 14981918bf8Sfvdl #ifndef _LOCORE 15081918bf8Sfvdl 15181918bf8Sfvdl /* 15281918bf8Sfvdl * Memory and System segment descriptors 15381918bf8Sfvdl */ 15481918bf8Sfvdl 15581918bf8Sfvdl /* 156cdf0a25fSmaxv * System segment descriptor (16 bytes): used for TSS and LDT. 15781918bf8Sfvdl */ 15881918bf8Sfvdl struct sys_segment_descriptor { 1594e73005cSmaxv uint64_t sd_lolimit:16; /* segment extent (lsb) */ 1604e73005cSmaxv uint64_t sd_lobase:24; /* segment base address (lsb) */ 1614e73005cSmaxv uint64_t sd_type:5; /* segment type */ 1624e73005cSmaxv uint64_t sd_dpl:2; /* segment descriptor priority level */ 1634e73005cSmaxv uint64_t sd_p:1; /* segment descriptor present */ 1644e73005cSmaxv uint64_t sd_hilimit:4; /* segment extent (msb) */ 1654e73005cSmaxv uint64_t sd_xx1:3; /* avl, long and def32 (not used) */ 1664e73005cSmaxv uint64_t sd_gran:1; /* limit granularity (byte/page) */ 1674e73005cSmaxv uint64_t sd_hibase:40; /* segment base address (msb) */ 1684e73005cSmaxv uint64_t sd_xx2:8; /* reserved */ 1694e73005cSmaxv uint64_t sd_zero:5; /* must be zero */ 1704e73005cSmaxv uint64_t sd_xx3:19; /* reserved */ 171b6a2ef75Sperry } __packed; 17281918bf8Sfvdl 17381918bf8Sfvdl /* 174cdf0a25fSmaxv * Memory segment descriptor (8 bytes): used for cs, ds, etc. 17581918bf8Sfvdl */ 17681918bf8Sfvdl struct mem_segment_descriptor { 17781918bf8Sfvdl unsigned sd_lolimit:16; /* segment extent (lsb) */ 17881918bf8Sfvdl unsigned sd_lobase:24; /* segment base address (lsb) */ 17981918bf8Sfvdl unsigned sd_type:5; /* segment type */ 18081918bf8Sfvdl unsigned sd_dpl:2; /* segment descriptor priority level */ 18181918bf8Sfvdl unsigned sd_p:1; /* segment descriptor present */ 18281918bf8Sfvdl unsigned sd_hilimit:4; /* segment extent (msb) */ 18381918bf8Sfvdl unsigned sd_avl:1; /* available */ 18481918bf8Sfvdl unsigned sd_long:1; /* long mode */ 18581918bf8Sfvdl unsigned sd_def32:1; /* default 32 vs 16 bit size */ 18681918bf8Sfvdl unsigned sd_gran:1; /* limit granularity (byte/page) */ 18781918bf8Sfvdl unsigned sd_hibase:8; /* segment base address (msb) */ 188b6a2ef75Sperry } __packed; 18981918bf8Sfvdl 19081918bf8Sfvdl /* 19169aa2aa9Sfvdl * Common part of the above structures. Used to walk descriptor tables. 19269aa2aa9Sfvdl */ 19369aa2aa9Sfvdl struct common_segment_descriptor { 19469aa2aa9Sfvdl unsigned sdc_lolimit:16; 19569aa2aa9Sfvdl unsigned sdc_lobase:24; 19669aa2aa9Sfvdl unsigned sdc_type:5; 19769aa2aa9Sfvdl unsigned sdc_other:19; 198b6a2ef75Sperry } __packed; 19969aa2aa9Sfvdl 20069aa2aa9Sfvdl /* 201cdf0a25fSmaxv * Gate descriptors (16 bytes). 20281918bf8Sfvdl */ 20381918bf8Sfvdl struct gate_descriptor { 2044e73005cSmaxv uint64_t gd_looffset:16;/* gate offset (lsb) */ 2054e73005cSmaxv uint64_t gd_selector:16;/* gate segment selector */ 2064e73005cSmaxv uint64_t gd_ist:3; /* IST select */ 2074e73005cSmaxv uint64_t gd_xx1:5; /* reserved */ 2084e73005cSmaxv uint64_t gd_type:5; /* segment type */ 2094e73005cSmaxv uint64_t gd_dpl:2; /* segment descriptor priority level */ 2104e73005cSmaxv uint64_t gd_p:1; /* segment descriptor present */ 2114e73005cSmaxv uint64_t gd_hioffset:48;/* gate offset (msb) */ 2124e73005cSmaxv uint64_t gd_xx2:8; /* reserved */ 2134e73005cSmaxv uint64_t gd_zero:5; /* must be zero */ 2144e73005cSmaxv uint64_t gd_xx3:19; /* reserved */ 215b6a2ef75Sperry } __packed; 21681918bf8Sfvdl 21781918bf8Sfvdl /* 218cdf0a25fSmaxv * Generic descriptor (8 bytes). Note: it does not include system segment 219cdf0a25fSmaxv * descriptors and gate descriptors, since these are 16-byte-long. 220ffa744f4Schs */ 221ffa744f4Schs union descriptor { 222ffa744f4Schs struct mem_segment_descriptor sd; 223ffa744f4Schs uint32_t raw[2]; 224ffa744f4Schs uint64_t raw64; 225ffa744f4Schs } __packed; 226ffa744f4Schs 227ffa744f4Schs /* 228cdf0a25fSmaxv * Region descriptors, used to load gdt/idt tables before segments yet exist. 22981918bf8Sfvdl */ 23081918bf8Sfvdl struct region_descriptor { 231a0fc30e9Scegger uint16_t rd_limit; /* segment extent */ 232a0fc30e9Scegger uint64_t rd_base; /* base address */ 233b6a2ef75Sperry } __packed; 23481918bf8Sfvdl 23581918bf8Sfvdl #ifdef _KERNEL 236427af037Scherry #ifdef XENPV 2374281462fScherry typedef struct trap_info idt_descriptor_t; 2384e541343Sbouyer #else 2394281462fScherry typedef struct gate_descriptor idt_descriptor_t; 240427af037Scherry #endif /* XENPV */ 24181918bf8Sfvdl extern char *gdtstore; 24281918bf8Sfvdl extern char *ldtstore; 24381918bf8Sfvdl 244a30325d3Sdsl void setgate(struct gate_descriptor *, void *, int, int, int, int); 245a30325d3Sdsl void unsetgate(struct gate_descriptor *); 2464281462fScherry void set_idtgate(idt_descriptor_t *, void *, int, int, int, int); 2474281462fScherry void unset_idtgate(idt_descriptor_t *); 248a0fc30e9Scegger void setregion(struct region_descriptor *, void *, uint16_t); 249a30325d3Sdsl void set_sys_segment(struct sys_segment_descriptor *, void *, size_t, 250a30325d3Sdsl int, int, int); 251a30325d3Sdsl void set_mem_segment(struct mem_segment_descriptor *, void *, size_t, 252a30325d3Sdsl int, int, int, int, int); 253ffa744f4Schs void update_descriptor(void *, void *); 2542cbcb46fSyamt 2556386396aSyamaguchi struct idt_vec; 2566386396aSyamaguchi void idt_vec_reserve(struct idt_vec *, int); 2576386396aSyamaguchi int idt_vec_alloc(struct idt_vec *, int, int); 2586386396aSyamaguchi void idt_vec_set(struct idt_vec *, int, void (*)(void)); 2596386396aSyamaguchi void idt_vec_free(struct idt_vec *, int); 2606386396aSyamaguchi void idt_vec_init_cpu_md(struct idt_vec *, cpuid_t); 2616386396aSyamaguchi bool idt_vec_is_pcpu(void); 2626386396aSyamaguchi struct idt_vec * idt_vec_ref(struct idt_vec *); 26303758b1fScherry 26481918bf8Sfvdl 26569aa2aa9Sfvdl struct lwp; 266f10c10f4Smaxv void cpu_segregs64_zero(struct lwp *); 267f10c10f4Smaxv void cpu_segregs32_zero(struct lwp *); 268ffa744f4Schs void cpu_fsgs_reload(struct lwp *, int, int); 26969aa2aa9Sfvdl 27081918bf8Sfvdl #endif /* _KERNEL */ 27181918bf8Sfvdl 27281918bf8Sfvdl #endif /* !_LOCORE */ 27381918bf8Sfvdl 27481918bf8Sfvdl /* system segments and gate types */ 27581918bf8Sfvdl #define SDT_SYSNULL 0 /* system null */ 27681918bf8Sfvdl #define SDT_SYS286TSS 1 /* system 286 TSS available */ 27781918bf8Sfvdl #define SDT_SYSLDT 2 /* system local descriptor table */ 27881918bf8Sfvdl #define SDT_SYS286BSY 3 /* system 286 TSS busy */ 27981918bf8Sfvdl #define SDT_SYS286CGT 4 /* system 286 call gate */ 28081918bf8Sfvdl #define SDT_SYSTASKGT 5 /* system task gate */ 28181918bf8Sfvdl #define SDT_SYS286IGT 6 /* system 286 interrupt gate */ 28281918bf8Sfvdl #define SDT_SYS286TGT 7 /* system 286 trap gate */ 28381918bf8Sfvdl #define SDT_SYSNULL2 8 /* system null again */ 28481918bf8Sfvdl #define SDT_SYS386TSS 9 /* system 386 TSS available */ 28581918bf8Sfvdl #define SDT_SYSNULL3 10 /* system null again */ 28681918bf8Sfvdl #define SDT_SYS386BSY 11 /* system 386 TSS busy */ 28781918bf8Sfvdl #define SDT_SYS386CGT 12 /* system 386 call gate */ 28881918bf8Sfvdl #define SDT_SYSNULL4 13 /* system null again */ 28981918bf8Sfvdl #define SDT_SYS386IGT 14 /* system 386 interrupt gate */ 29081918bf8Sfvdl #define SDT_SYS386TGT 15 /* system 386 trap gate */ 29181918bf8Sfvdl 29281918bf8Sfvdl /* memory segment types */ 29381918bf8Sfvdl #define SDT_MEMRO 16 /* memory read only */ 29481918bf8Sfvdl #define SDT_MEMROA 17 /* memory read only accessed */ 29581918bf8Sfvdl #define SDT_MEMRW 18 /* memory read write */ 29681918bf8Sfvdl #define SDT_MEMRWA 19 /* memory read write accessed */ 29781918bf8Sfvdl #define SDT_MEMROD 20 /* memory read only expand dwn limit */ 29881918bf8Sfvdl #define SDT_MEMRODA 21 /* memory read only expand dwn limit accessed */ 29981918bf8Sfvdl #define SDT_MEMRWD 22 /* memory read write expand dwn limit */ 3004e73005cSmaxv #define SDT_MEMRWDA 23 /* memory read write expand dwn limit accessed */ 30181918bf8Sfvdl #define SDT_MEME 24 /* memory execute only */ 30281918bf8Sfvdl #define SDT_MEMEA 25 /* memory execute only accessed */ 30381918bf8Sfvdl #define SDT_MEMER 26 /* memory execute read */ 30481918bf8Sfvdl #define SDT_MEMERA 27 /* memory execute read accessed */ 30581918bf8Sfvdl #define SDT_MEMEC 28 /* memory execute only conforming */ 30681918bf8Sfvdl #define SDT_MEMEAC 29 /* memory execute only accessed conforming */ 30781918bf8Sfvdl #define SDT_MEMERC 30 /* memory execute read conforming */ 30881918bf8Sfvdl #define SDT_MEMERAC 31 /* memory execute read accessed conforming */ 30981918bf8Sfvdl 31081918bf8Sfvdl /* 31181918bf8Sfvdl * Segment Protection Exception code bits 31281918bf8Sfvdl */ 31381918bf8Sfvdl #define SEGEX_EXT 0x01 /* recursive or externally induced */ 31481918bf8Sfvdl #define SEGEX_IDT 0x02 /* interrupt descriptor table */ 31581918bf8Sfvdl #define SEGEX_TI 0x04 /* local descriptor table */ 31681918bf8Sfvdl 31781918bf8Sfvdl /* 31881918bf8Sfvdl * Entries in the Interrupt Descriptor Table (IDT) 31981918bf8Sfvdl */ 32081918bf8Sfvdl #define NIDT 256 32135644e23Smaxv #define NCPUIDT 32 /* reserved entries for CPU exceptions */ 32281918bf8Sfvdl 32381918bf8Sfvdl /* 32481918bf8Sfvdl * Entries in the Global Descriptor Table (GDT) 32581918bf8Sfvdl * The code and data descriptors must come first. There 32681918bf8Sfvdl * are NGDT_MEM of them. 32781918bf8Sfvdl * 32881918bf8Sfvdl * Then come the predefined LDT (and possibly TSS) descriptors. 32981918bf8Sfvdl * There are NGDT_SYS of them. 33081918bf8Sfvdl */ 33181918bf8Sfvdl #define GNULL_SEL 0 /* Null descriptor */ 33281918bf8Sfvdl #define GCODE_SEL 1 /* Kernel code descriptor */ 33381918bf8Sfvdl #define GDATA_SEL 2 /* Kernel data descriptor */ 33481918bf8Sfvdl #define GUCODE_SEL 3 /* User code descriptor */ 33581918bf8Sfvdl #define GUDATA_SEL 4 /* User data descriptor */ 33681918bf8Sfvdl #define GAPM32CODE_SEL 5 33781918bf8Sfvdl #define GAPM16CODE_SEL 6 33881918bf8Sfvdl #define GAPMDATA_SEL 7 33981918bf8Sfvdl #define GBIOSCODE_SEL 8 34081918bf8Sfvdl #define GBIOSDATA_SEL 9 34181918bf8Sfvdl #define GPNPBIOSCODE_SEL 10 34281918bf8Sfvdl #define GPNPBIOSDATA_SEL 11 34381918bf8Sfvdl #define GPNPBIOSSCRATCH_SEL 12 34481918bf8Sfvdl #define GPNPBIOSTRAMP_SEL 13 34581918bf8Sfvdl #define GUCODE32_SEL 14 34681918bf8Sfvdl #define GUDATA32_SEL 15 347ffa744f4Schs #define GUFS_SEL 16 /* 32-bit Per-thread %fs */ 348ffa744f4Schs #define GUGS_SEL 17 /* 32-bit Per-thread %gs */ 349ffa744f4Schs #define NGDT_MEM 18 35081918bf8Sfvdl 35181918bf8Sfvdl #define GLDT_SEL 0 /* Default LDT descriptor */ 35281918bf8Sfvdl #define NGDT_SYS 1 35381918bf8Sfvdl 35481918bf8Sfvdl #define GDT_ADDR_MEM(s,i) \ 35581918bf8Sfvdl ((struct mem_segment_descriptor *)((s) + ((i) << 3))) 35681918bf8Sfvdl #define GDT_ADDR_SYS(s,i) \ 35781918bf8Sfvdl ((struct sys_segment_descriptor *)((s) + (((i) << 4) + SYSSEL_START))) 35881918bf8Sfvdl 35981918bf8Sfvdl /* 36081918bf8Sfvdl * Byte offsets in the Local Descriptor Table (LDT) 36181918bf8Sfvdl * Strange order because of syscall/sysret insns 36281918bf8Sfvdl */ 363d26d978fSchs #define LUCODE32_SEL 48 /* 32 bit user code descriptor */ 364d26d978fSchs #define LUDATA_SEL 56 /* User data descriptor */ 365d26d978fSchs #define LUCODE_SEL 64 /* User code descriptor */ 366d26d978fSchs #define LUDATA32_SEL 72 /* 32 bit user data descriptor (needed?)*/ 36781918bf8Sfvdl 368e1a67720Smaxv #define LDT_SIZE 80 36981918bf8Sfvdl 37081918bf8Sfvdl #define LSYSRETBASE_SEL LUCODE32_SEL 37181918bf8Sfvdl 372ef0bb541Sfvdl /* 373173e2026Smaxv * Checks for valid user selectors. 374ef0bb541Sfvdl */ 375ef0bb541Sfvdl #define VALID_USER_DSEL32(s) \ 376ceb63bd6Smrg (((s) & 0xffff) == GSEL(GUDATA32_SEL, SEL_UPL) || \ 377ceb63bd6Smrg ((s) & 0xffff) == LSEL(LUDATA32_SEL, SEL_UPL)) 378ef0bb541Sfvdl #define VALID_USER_CSEL32(s) \ 379ef0bb541Sfvdl ((s) == GSEL(GUCODE32_SEL, SEL_UPL) || (s) == LSEL(LUCODE32_SEL, SEL_UPL)) 3801bb795ffSchs #define VALID_USER_FSEL32(s) \ 3811bb795ffSchs (((s) & 0xffff) == GSEL(GUFS_SEL, SEL_UPL)) 3821bb795ffSchs #define VALID_USER_GSEL32(s) \ 3831bb795ffSchs (((s) & 0xffff) == GSEL(GUGS_SEL, SEL_UPL)) 384ef0bb541Sfvdl 385ef0bb541Sfvdl #define VALID_USER_CSEL(s) \ 386ef0bb541Sfvdl ((s) == GSEL(GUCODE_SEL, SEL_UPL) || (s) == LSEL(LUCODE_SEL, SEL_UPL)) 387ef0bb541Sfvdl #define VALID_USER_DSEL(s) \ 388ef0bb541Sfvdl ((s) == GSEL(GUDATA_SEL, SEL_UPL) || (s) == LSEL(LUDATA_SEL, SEL_UPL)) 389ef0bb541Sfvdl 390433b5ddeSmrg #else /* __x86_64__ */ 391433b5ddeSmrg 392433b5ddeSmrg #include <i386/segments.h> 393433b5ddeSmrg 394433b5ddeSmrg #endif /* __x86_64__ */ 395433b5ddeSmrg 39681918bf8Sfvdl #endif /* _AMD64_SEGMENTS_H_ */ 397