Home | History | Annotate | Line # | Download | only in include
      1  1.38    rillig /*	$NetBSD: segments.h,v 1.38 2021/04/17 20:12:55 rillig Exp $	*/
      2   1.2       agc 
      3  1.32      maxv /*
      4   1.2       agc  * Copyright (c) 1990 The Regents of the University of California.
      5   1.2       agc  * All rights reserved.
      6   1.2       agc  *
      7   1.2       agc  * This code is derived from software contributed to Berkeley by
      8   1.2       agc  * William Jolitz.
      9   1.2       agc  *
     10   1.2       agc  * Redistribution and use in source and binary forms, with or without
     11   1.2       agc  * modification, are permitted provided that the following conditions
     12   1.2       agc  * are met:
     13   1.2       agc  * 1. Redistributions of source code must retain the above copyright
     14   1.2       agc  *    notice, this list of conditions and the following disclaimer.
     15   1.2       agc  * 2. Redistributions in binary form must reproduce the above copyright
     16   1.2       agc  *    notice, this list of conditions and the following disclaimer in the
     17   1.2       agc  *    documentation and/or other materials provided with the distribution.
     18   1.2       agc  * 3. Neither the name of the University nor the names of its contributors
     19   1.2       agc  *    may be used to endorse or promote products derived from this software
     20   1.2       agc  *    without specific prior written permission.
     21   1.2       agc  *
     22   1.2       agc  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
     23   1.2       agc  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
     24   1.2       agc  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
     25   1.2       agc  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
     26   1.2       agc  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
     27   1.2       agc  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
     28   1.2       agc  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     29   1.2       agc  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
     30   1.2       agc  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
     31   1.2       agc  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
     32   1.2       agc  * SUCH DAMAGE.
     33   1.2       agc  *
     34   1.2       agc  *	@(#)segments.h	7.1 (Berkeley) 5/9/91
     35   1.2       agc  */
     36   1.1      fvdl 
     37  1.32      maxv /*
     38   1.1      fvdl  * Copyright (c) 1995, 1997
     39   1.1      fvdl  *	Charles M. Hannum.  All rights reserved.
     40   1.1      fvdl  * Copyright (c) 1989, 1990 William F. Jolitz
     41   1.1      fvdl  *
     42   1.1      fvdl  * This code is derived from software contributed to Berkeley by
     43   1.1      fvdl  * William Jolitz.
     44   1.1      fvdl  *
     45   1.1      fvdl  * Redistribution and use in source and binary forms, with or without
     46   1.1      fvdl  * modification, are permitted provided that the following conditions
     47   1.1      fvdl  * are met:
     48   1.1      fvdl  * 1. Redistributions of source code must retain the above copyright
     49   1.1      fvdl  *    notice, this list of conditions and the following disclaimer.
     50   1.1      fvdl  * 2. Redistributions in binary form must reproduce the above copyright
     51   1.1      fvdl  *    notice, this list of conditions and the following disclaimer in the
     52   1.1      fvdl  *    documentation and/or other materials provided with the distribution.
     53   1.1      fvdl  * 3. All advertising materials mentioning features or use of this software
     54   1.1      fvdl  *    must display the following acknowledgement:
     55   1.1      fvdl  *	This product includes software developed by the University of
     56   1.1      fvdl  *	California, Berkeley and its contributors.
     57   1.1      fvdl  * 4. Neither the name of the University nor the names of its contributors
     58   1.1      fvdl  *    may be used to endorse or promote products derived from this software
     59   1.1      fvdl  *    without specific prior written permission.
     60   1.1      fvdl  *
     61   1.1      fvdl  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
     62   1.1      fvdl  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
     63   1.1      fvdl  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
     64   1.1      fvdl  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
     65   1.1      fvdl  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
     66   1.1      fvdl  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
     67   1.1      fvdl  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     68   1.1      fvdl  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
     69   1.1      fvdl  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
     70   1.1      fvdl  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
     71   1.1      fvdl  * SUCH DAMAGE.
     72   1.1      fvdl  *
     73   1.1      fvdl  *	@(#)segments.h	7.1 (Berkeley) 5/9/91
     74   1.1      fvdl  */
     75   1.1      fvdl 
     76   1.1      fvdl /*
     77   1.1      fvdl  * Adapted for NetBSD/amd64 by fvdl (at) wasabisystems.com.
     78   1.1      fvdl  */
     79   1.1      fvdl 
     80   1.1      fvdl /*
     81   1.1      fvdl  * 386 Segmentation Data Structures and definitions
     82   1.1      fvdl  *	William F. Jolitz (william (at) ernie.berkeley.edu) 6/20/1989
     83   1.1      fvdl  */
     84   1.1      fvdl 
     85   1.1      fvdl #ifndef _AMD64_SEGMENTS_H_
     86   1.1      fvdl #define _AMD64_SEGMENTS_H_
     87  1.19       mrg 
     88  1.19       mrg #ifdef __x86_64__
     89  1.19       mrg 
     90  1.14    bouyer #ifdef _KERNEL_OPT
     91  1.11    bouyer #include "opt_xen.h"
     92  1.12    bouyer #endif
     93   1.1      fvdl 
     94   1.1      fvdl /*
     95   1.1      fvdl  * Selectors
     96   1.1      fvdl  */
     97   1.1      fvdl 
     98  1.25      maxv #define ISPL(s)		((s) & SEL_RPL)	/* what is the priority level of a selector */
     99  1.36    cherry #ifdef XENPV
    100  1.25      maxv #define SEL_KPL		3		/* kernel privilege level */
    101  1.25      maxv #define SEL_XPL		0		/* Xen Hypervisor privilege level */
    102  1.11    bouyer #else
    103  1.25      maxv #define SEL_KPL		0		/* kernel privilege level */
    104  1.11    bouyer #endif
    105  1.25      maxv #define SEL_UPL		3		/* user privilege level */
    106  1.25      maxv #define SEL_RPL		3		/* requester's privilege level mask */
    107  1.25      maxv #define ISLDT(s)	((s) & SEL_LDT)	/* is it local or global */
    108  1.25      maxv #define SEL_LDT		4		/* local descriptor table */
    109   1.1      fvdl 
    110  1.36    cherry #ifdef XENPV
    111  1.34      maxv #define IOPL_KPL	1
    112  1.34      maxv #else
    113  1.34      maxv #define IOPL_KPL	SEL_KPL
    114  1.34      maxv #endif
    115  1.34      maxv 
    116   1.1      fvdl /* Dynamically allocated TSSs and LDTs start (byte offset) */
    117   1.1      fvdl #define SYSSEL_START	(NGDT_MEM << 3)
    118   1.1      fvdl #define DYNSEL_START	(SYSSEL_START + (NGDT_SYS << 4))
    119   1.1      fvdl 
    120   1.1      fvdl /*
    121   1.1      fvdl  * These define the index not from the start of the GDT, but from
    122   1.1      fvdl  * the part of the GDT that they're allocated from.
    123   1.1      fvdl  * First NGDT_MEM entries are 8-byte descriptors for CS and DS.
    124   1.1      fvdl  * Next NGDT_SYS entries are 16-byte descriptors defining LDTs.
    125   1.1      fvdl  *
    126   1.1      fvdl  * The rest is 16-byte descriptors for TSS and LDT.
    127   1.1      fvdl  */
    128   1.1      fvdl 
    129  1.25      maxv #define IDXSEL(s)	(((s) >> 3) & 0x1fff)
    130   1.1      fvdl #define IDXDYNSEL(s)	((((s) & ~SEL_RPL) - DYNSEL_START) >> 4)
    131   1.1      fvdl 
    132  1.25      maxv #define GSEL(s,r)	(((s) << 3) | r)
    133  1.25      maxv #define GSYSSEL(s,r)	((((s) << 4) + SYSSEL_START) | r)
    134   1.1      fvdl #define GDYNSEL(s,r)	((((s) << 4) + DYNSEL_START) | r | SEL_KPL)
    135   1.1      fvdl 
    136   1.1      fvdl #define LSEL(s,r)	((s) | r | SEL_LDT)
    137   1.1      fvdl 
    138  1.30      maxv #define USERMODE(c)		(ISPL(c) == SEL_UPL)
    139  1.36    cherry #ifdef XENPV
    140  1.11    bouyer /*
    141  1.11    bouyer  * As KPL == UPL, Xen emulate interrupt in kernel context by pushing
    142  1.11    bouyer  * a fake CS with XPL privilege
    143  1.11    bouyer  */
    144  1.30      maxv #define KERNELMODE(c)		(ISPL(c) == SEL_XPL)
    145  1.11    bouyer #else
    146  1.30      maxv #define KERNELMODE(c)		(ISPL(c) == SEL_KPL)
    147  1.11    bouyer #endif
    148   1.1      fvdl 
    149   1.1      fvdl #ifndef _LOCORE
    150   1.1      fvdl 
    151   1.1      fvdl /*
    152   1.1      fvdl  * Memory and System segment descriptors
    153   1.1      fvdl  */
    154   1.1      fvdl 
    155   1.1      fvdl /*
    156  1.28      maxv  * System segment descriptor (16 bytes): used for TSS and LDT.
    157   1.1      fvdl  */
    158   1.1      fvdl struct sys_segment_descriptor {
    159  1.25      maxv 	uint64_t sd_lolimit:16;	/* segment extent (lsb) */
    160  1.25      maxv 	uint64_t sd_lobase:24;	/* segment base address (lsb) */
    161  1.25      maxv 	uint64_t sd_type:5;	/* segment type */
    162  1.25      maxv 	uint64_t sd_dpl:2;	/* segment descriptor priority level */
    163  1.25      maxv 	uint64_t sd_p:1;	/* segment descriptor present */
    164  1.25      maxv 	uint64_t sd_hilimit:4;	/* segment extent (msb) */
    165  1.25      maxv 	uint64_t sd_xx1:3;	/* avl, long and def32 (not used) */
    166  1.25      maxv 	uint64_t sd_gran:1;	/* limit granularity (byte/page) */
    167  1.25      maxv 	uint64_t sd_hibase:40;	/* segment base address (msb) */
    168  1.25      maxv 	uint64_t sd_xx2:8;	/* reserved */
    169  1.25      maxv 	uint64_t sd_zero:5;	/* must be zero */
    170  1.25      maxv 	uint64_t sd_xx3:19;	/* reserved */
    171  1.15     perry } __packed;
    172   1.1      fvdl 
    173   1.1      fvdl /*
    174  1.28      maxv  * Memory segment descriptor (8 bytes): used for cs, ds, etc.
    175   1.1      fvdl  */
    176   1.1      fvdl struct mem_segment_descriptor {
    177  1.25      maxv 	unsigned sd_lolimit:16;	/* segment extent (lsb) */
    178  1.25      maxv 	unsigned sd_lobase:24;	/* segment base address (lsb) */
    179  1.25      maxv 	unsigned sd_type:5;	/* segment type */
    180  1.25      maxv 	unsigned sd_dpl:2;	/* segment descriptor priority level */
    181  1.25      maxv 	unsigned sd_p:1;	/* segment descriptor present */
    182  1.25      maxv 	unsigned sd_hilimit:4;	/* segment extent (msb) */
    183  1.25      maxv 	unsigned sd_avl:1;	/* available */
    184  1.25      maxv 	unsigned sd_long:1;	/* long mode */
    185  1.25      maxv 	unsigned sd_def32:1;	/* default 32 vs 16 bit size */
    186  1.25      maxv 	unsigned sd_gran:1;	/* limit granularity (byte/page) */
    187  1.25      maxv 	unsigned sd_hibase:8;	/* segment base address (msb) */
    188  1.15     perry } __packed;
    189   1.1      fvdl 
    190   1.1      fvdl /*
    191   1.5      fvdl  * Common part of the above structures. Used to walk descriptor tables.
    192   1.5      fvdl  */
    193   1.5      fvdl struct common_segment_descriptor {
    194   1.5      fvdl 	unsigned sdc_lolimit:16;
    195   1.5      fvdl 	unsigned sdc_lobase:24;
    196   1.5      fvdl 	unsigned sdc_type:5;
    197   1.5      fvdl 	unsigned sdc_other:19;
    198  1.15     perry } __packed;
    199   1.5      fvdl 
    200   1.5      fvdl /*
    201  1.28      maxv  * Gate descriptors (16 bytes).
    202   1.1      fvdl  */
    203   1.1      fvdl struct gate_descriptor {
    204  1.25      maxv 	uint64_t gd_looffset:16;/* gate offset (lsb) */
    205  1.25      maxv 	uint64_t gd_selector:16;/* gate segment selector */
    206  1.25      maxv 	uint64_t gd_ist:3;	/* IST select */
    207  1.25      maxv 	uint64_t gd_xx1:5;	/* reserved */
    208  1.25      maxv 	uint64_t gd_type:5;	/* segment type */
    209  1.25      maxv 	uint64_t gd_dpl:2;	/* segment descriptor priority level */
    210  1.25      maxv 	uint64_t gd_p:1;	/* segment descriptor present */
    211  1.25      maxv 	uint64_t gd_hioffset:48;/* gate offset (msb) */
    212  1.25      maxv 	uint64_t gd_xx2:8;	/* reserved */
    213  1.25      maxv 	uint64_t gd_zero:5;	/* must be zero */
    214  1.25      maxv 	uint64_t gd_xx3:19;	/* reserved */
    215  1.15     perry } __packed;
    216   1.1      fvdl 
    217   1.1      fvdl /*
    218  1.28      maxv  * Generic descriptor (8 bytes). Note: it does not include system segment
    219  1.28      maxv  * descriptors and gate descriptors, since these are 16-byte-long.
    220  1.20       chs  */
    221  1.20       chs union descriptor {
    222  1.20       chs 	struct mem_segment_descriptor sd;
    223  1.20       chs 	uint32_t raw[2];
    224  1.20       chs 	uint64_t raw64;
    225  1.20       chs } __packed;
    226  1.20       chs 
    227  1.20       chs /*
    228  1.28      maxv  * Region descriptors, used to load gdt/idt tables before segments yet exist.
    229   1.1      fvdl  */
    230   1.1      fvdl struct region_descriptor {
    231  1.25      maxv 	uint16_t rd_limit;	/* segment extent */
    232  1.25      maxv 	uint64_t rd_base;	/* base address  */
    233  1.15     perry } __packed;
    234   1.1      fvdl 
    235   1.1      fvdl #ifdef _KERNEL
    236  1.36    cherry #ifdef XENPV
    237  1.35    cherry typedef struct trap_info idt_descriptor_t;
    238  1.11    bouyer #else
    239  1.38    rillig typedef struct gate_descriptor idt_descriptor_t;
    240  1.36    cherry #endif /* XENPV */
    241   1.1      fvdl extern char *gdtstore;
    242   1.1      fvdl extern char *ldtstore;
    243   1.1      fvdl 
    244   1.7       dsl void setgate(struct gate_descriptor *, void *, int, int, int, int);
    245   1.7       dsl void unsetgate(struct gate_descriptor *);
    246  1.35    cherry void set_idtgate(idt_descriptor_t *, void *, int, int, int, int);
    247  1.35    cherry void unset_idtgate(idt_descriptor_t *);
    248  1.17    cegger void setregion(struct region_descriptor *, void *, uint16_t);
    249   1.7       dsl void set_sys_segment(struct sys_segment_descriptor *, void *, size_t,
    250  1.25      maxv     int, int, int);
    251   1.7       dsl void set_mem_segment(struct mem_segment_descriptor *, void *, size_t,
    252  1.25      maxv     int, int, int, int, int);
    253  1.20       chs void update_descriptor(void *, void *);
    254  1.16      yamt 
    255  1.37  yamaguch struct idt_vec;
    256  1.37  yamaguch void idt_vec_reserve(struct idt_vec *, int);
    257  1.37  yamaguch int idt_vec_alloc(struct idt_vec *, int, int);
    258  1.37  yamaguch void idt_vec_set(struct idt_vec *, int, void (*)(void));
    259  1.37  yamaguch void idt_vec_free(struct idt_vec *, int);
    260  1.37  yamaguch void idt_vec_init_cpu_md(struct idt_vec *, cpuid_t);
    261  1.37  yamaguch bool idt_vec_is_pcpu(void);
    262  1.37  yamaguch struct idt_vec * idt_vec_ref(struct idt_vec *);
    263  1.33    cherry 
    264   1.1      fvdl 
    265   1.5      fvdl struct lwp;
    266  1.31      maxv void cpu_segregs64_zero(struct lwp *);
    267  1.31      maxv void cpu_segregs32_zero(struct lwp *);
    268  1.20       chs void cpu_fsgs_reload(struct lwp *, int, int);
    269   1.5      fvdl 
    270   1.1      fvdl #endif /* _KERNEL */
    271   1.1      fvdl 
    272   1.1      fvdl #endif /* !_LOCORE */
    273   1.1      fvdl 
    274   1.1      fvdl /* system segments and gate types */
    275  1.25      maxv #define SDT_SYSNULL	 0	/* system null */
    276  1.25      maxv #define SDT_SYS286TSS	 1	/* system 286 TSS available */
    277  1.25      maxv #define SDT_SYSLDT	 2	/* system local descriptor table */
    278  1.25      maxv #define SDT_SYS286BSY	 3	/* system 286 TSS busy */
    279  1.25      maxv #define SDT_SYS286CGT	 4	/* system 286 call gate */
    280  1.25      maxv #define SDT_SYSTASKGT	 5	/* system task gate */
    281  1.25      maxv #define SDT_SYS286IGT	 6	/* system 286 interrupt gate */
    282  1.25      maxv #define SDT_SYS286TGT	 7	/* system 286 trap gate */
    283  1.25      maxv #define SDT_SYSNULL2	 8	/* system null again */
    284  1.25      maxv #define SDT_SYS386TSS	 9	/* system 386 TSS available */
    285  1.25      maxv #define SDT_SYSNULL3	10	/* system null again */
    286  1.25      maxv #define SDT_SYS386BSY	11	/* system 386 TSS busy */
    287  1.25      maxv #define SDT_SYS386CGT	12	/* system 386 call gate */
    288  1.25      maxv #define SDT_SYSNULL4	13	/* system null again */
    289  1.25      maxv #define SDT_SYS386IGT	14	/* system 386 interrupt gate */
    290  1.25      maxv #define SDT_SYS386TGT	15	/* system 386 trap gate */
    291   1.1      fvdl 
    292   1.1      fvdl /* memory segment types */
    293  1.25      maxv #define SDT_MEMRO	16	/* memory read only */
    294  1.25      maxv #define SDT_MEMROA	17	/* memory read only accessed */
    295  1.25      maxv #define SDT_MEMRW	18	/* memory read write */
    296  1.25      maxv #define SDT_MEMRWA	19	/* memory read write accessed */
    297  1.25      maxv #define SDT_MEMROD	20	/* memory read only expand dwn limit */
    298  1.25      maxv #define SDT_MEMRODA	21	/* memory read only expand dwn limit accessed */
    299  1.25      maxv #define SDT_MEMRWD	22	/* memory read write expand dwn limit */
    300  1.25      maxv #define SDT_MEMRWDA	23	/* memory read write expand dwn limit accessed */
    301  1.25      maxv #define SDT_MEME	24	/* memory execute only */
    302  1.25      maxv #define SDT_MEMEA	25	/* memory execute only accessed */
    303  1.25      maxv #define SDT_MEMER	26	/* memory execute read */
    304  1.25      maxv #define SDT_MEMERA	27	/* memory execute read accessed */
    305  1.25      maxv #define SDT_MEMEC	28	/* memory execute only conforming */
    306  1.25      maxv #define SDT_MEMEAC	29	/* memory execute only accessed conforming */
    307  1.25      maxv #define SDT_MEMERC	30	/* memory execute read conforming */
    308  1.25      maxv #define SDT_MEMERAC	31	/* memory execute read accessed conforming */
    309   1.1      fvdl 
    310   1.1      fvdl /*
    311   1.1      fvdl  * Segment Protection Exception code bits
    312   1.1      fvdl  */
    313  1.25      maxv #define SEGEX_EXT	0x01	/* recursive or externally induced */
    314  1.25      maxv #define SEGEX_IDT	0x02	/* interrupt descriptor table */
    315  1.25      maxv #define SEGEX_TI	0x04	/* local descriptor table */
    316   1.1      fvdl 
    317   1.1      fvdl /*
    318   1.1      fvdl  * Entries in the Interrupt Descriptor Table (IDT)
    319   1.1      fvdl  */
    320  1.25      maxv #define NIDT	256
    321  1.26      maxv #define NCPUIDT	32		/* reserved entries for CPU exceptions */
    322   1.1      fvdl 
    323   1.1      fvdl /*
    324   1.1      fvdl  * Entries in the Global Descriptor Table (GDT)
    325   1.1      fvdl  * The code and data descriptors must come first. There
    326   1.1      fvdl  * are NGDT_MEM of them.
    327   1.1      fvdl  *
    328   1.1      fvdl  * Then come the predefined LDT (and possibly TSS) descriptors.
    329   1.1      fvdl  * There are NGDT_SYS of them.
    330   1.1      fvdl  */
    331  1.25      maxv #define GNULL_SEL	0	/* Null descriptor */
    332  1.25      maxv #define GCODE_SEL	1	/* Kernel code descriptor */
    333  1.25      maxv #define GDATA_SEL	2	/* Kernel data descriptor */
    334  1.25      maxv #define GUCODE_SEL	3	/* User code descriptor */
    335  1.25      maxv #define GUDATA_SEL	4	/* User data descriptor */
    336  1.25      maxv #define GAPM32CODE_SEL	5
    337  1.25      maxv #define GAPM16CODE_SEL	6
    338  1.25      maxv #define GAPMDATA_SEL	7
    339  1.25      maxv #define GBIOSCODE_SEL	8
    340  1.25      maxv #define GBIOSDATA_SEL	9
    341   1.1      fvdl #define GPNPBIOSCODE_SEL 10
    342   1.1      fvdl #define GPNPBIOSDATA_SEL 11
    343   1.1      fvdl #define GPNPBIOSSCRATCH_SEL 12
    344   1.1      fvdl #define GPNPBIOSTRAMP_SEL 13
    345   1.1      fvdl #define GUCODE32_SEL	14
    346   1.1      fvdl #define GUDATA32_SEL	15
    347  1.20       chs #define GUFS_SEL	16	/* 32-bit Per-thread %fs */
    348  1.20       chs #define GUGS_SEL	17	/* 32-bit Per-thread %gs */
    349  1.25      maxv #define NGDT_MEM	18
    350   1.1      fvdl 
    351  1.25      maxv #define GLDT_SEL	0	/* Default LDT descriptor */
    352   1.1      fvdl #define NGDT_SYS	1
    353   1.1      fvdl 
    354   1.1      fvdl #define GDT_ADDR_MEM(s,i)	\
    355   1.1      fvdl     ((struct mem_segment_descriptor *)((s) + ((i) << 3)))
    356   1.1      fvdl #define GDT_ADDR_SYS(s,i)	\
    357  1.32      maxv     ((struct sys_segment_descriptor *)((s) + (((i) << 4) + SYSSEL_START)))
    358   1.1      fvdl 
    359   1.1      fvdl /*
    360   1.1      fvdl  * Byte offsets in the Local Descriptor Table (LDT)
    361   1.1      fvdl  * Strange order because of syscall/sysret insns
    362   1.1      fvdl  */
    363  1.24       chs #define LUCODE32_SEL	48	/* 32 bit user code descriptor */
    364  1.25      maxv #define LUDATA_SEL	56	/* User data descriptor */
    365  1.25      maxv #define LUCODE_SEL	64	/* User code descriptor */
    366  1.24       chs #define LUDATA32_SEL	72	/* 32 bit user data descriptor (needed?)*/
    367   1.1      fvdl 
    368  1.32      maxv #define LDT_SIZE	80
    369   1.1      fvdl 
    370   1.1      fvdl #define LSYSRETBASE_SEL	LUCODE32_SEL
    371   1.3      fvdl 
    372   1.3      fvdl /*
    373  1.29      maxv  * Checks for valid user selectors.
    374   1.3      fvdl  */
    375   1.3      fvdl #define VALID_USER_DSEL32(s) \
    376   1.8       mrg     (((s) & 0xffff) == GSEL(GUDATA32_SEL, SEL_UPL) || \
    377   1.8       mrg      ((s) & 0xffff) == LSEL(LUDATA32_SEL, SEL_UPL))
    378   1.3      fvdl #define VALID_USER_CSEL32(s) \
    379   1.3      fvdl     ((s) == GSEL(GUCODE32_SEL, SEL_UPL) || (s) == LSEL(LUCODE32_SEL, SEL_UPL))
    380  1.22       chs #define VALID_USER_FSEL32(s) \
    381  1.22       chs     (((s) & 0xffff) == GSEL(GUFS_SEL, SEL_UPL))
    382  1.22       chs #define VALID_USER_GSEL32(s) \
    383  1.22       chs     (((s) & 0xffff) == GSEL(GUGS_SEL, SEL_UPL))
    384   1.3      fvdl 
    385   1.3      fvdl #define VALID_USER_CSEL(s) \
    386   1.3      fvdl     ((s) == GSEL(GUCODE_SEL, SEL_UPL) || (s) == LSEL(LUCODE_SEL, SEL_UPL))
    387   1.3      fvdl #define VALID_USER_DSEL(s) \
    388   1.3      fvdl     ((s) == GSEL(GUDATA_SEL, SEL_UPL) || (s) == LSEL(LUDATA_SEL, SEL_UPL))
    389   1.1      fvdl 
    390  1.19       mrg #else	/*	__x86_64__	*/
    391  1.19       mrg 
    392  1.19       mrg #include <i386/segments.h>
    393  1.19       mrg 
    394  1.19       mrg #endif	/*	__x86_64__	*/
    395  1.19       mrg 
    396   1.1      fvdl #endif /* _AMD64_SEGMENTS_H_ */
    397