xref: /freebsd/sys/amd64/include/segments.h (revision 6e393973f57e7b6f632b763cd588b79c84ab63d1)
15b81b6b3SRodney W. Grimes /*-
25b81b6b3SRodney W. Grimes  * Copyright (c) 1989, 1990 William F. Jolitz
35b81b6b3SRodney W. Grimes  * Copyright (c) 1990 The Regents of the University of California.
45b81b6b3SRodney W. Grimes  * All rights reserved.
55b81b6b3SRodney W. Grimes  *
65b81b6b3SRodney W. Grimes  * This code is derived from software contributed to Berkeley by
75b81b6b3SRodney W. Grimes  * William Jolitz.
85b81b6b3SRodney W. Grimes  *
95b81b6b3SRodney W. Grimes  * Redistribution and use in source and binary forms, with or without
105b81b6b3SRodney W. Grimes  * modification, are permitted provided that the following conditions
115b81b6b3SRodney W. Grimes  * are met:
125b81b6b3SRodney W. Grimes  * 1. Redistributions of source code must retain the above copyright
135b81b6b3SRodney W. Grimes  *    notice, this list of conditions and the following disclaimer.
145b81b6b3SRodney W. Grimes  * 2. Redistributions in binary form must reproduce the above copyright
155b81b6b3SRodney W. Grimes  *    notice, this list of conditions and the following disclaimer in the
165b81b6b3SRodney W. Grimes  *    documentation and/or other materials provided with the distribution.
175b81b6b3SRodney W. Grimes  * 3. All advertising materials mentioning features or use of this software
185b81b6b3SRodney W. Grimes  *    must display the following acknowledgement:
195b81b6b3SRodney W. Grimes  *	This product includes software developed by the University of
205b81b6b3SRodney W. Grimes  *	California, Berkeley and its contributors.
215b81b6b3SRodney W. Grimes  * 4. Neither the name of the University nor the names of its contributors
225b81b6b3SRodney W. Grimes  *    may be used to endorse or promote products derived from this software
235b81b6b3SRodney W. Grimes  *    without specific prior written permission.
245b81b6b3SRodney W. Grimes  *
255b81b6b3SRodney W. Grimes  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
265b81b6b3SRodney W. Grimes  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
275b81b6b3SRodney W. Grimes  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
285b81b6b3SRodney W. Grimes  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
295b81b6b3SRodney W. Grimes  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
305b81b6b3SRodney W. Grimes  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
315b81b6b3SRodney W. Grimes  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
325b81b6b3SRodney W. Grimes  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
335b81b6b3SRodney W. Grimes  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
345b81b6b3SRodney W. Grimes  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
355b81b6b3SRodney W. Grimes  * SUCH DAMAGE.
365b81b6b3SRodney W. Grimes  *
3734a8ed1bSRodney W. Grimes  *	from: @(#)segments.h	7.1 (Berkeley) 5/9/91
386e393973SGarrett Wollman  *	$Id: segments.h,v 1.2 1993/10/16 14:39:30 rgrimes Exp $
395b81b6b3SRodney W. Grimes  */
405b81b6b3SRodney W. Grimes 
416e393973SGarrett Wollman #ifndef _MACHINE_SEGMENTS_H_
426e393973SGarrett Wollman #define _MACHINE_SEGMENTS_H_ 1
436e393973SGarrett Wollman 
445b81b6b3SRodney W. Grimes /*
455b81b6b3SRodney W. Grimes  * 386 Segmentation Data Structures and definitions
465b81b6b3SRodney W. Grimes  *	William F. Jolitz (william@ernie.berkeley.edu) 6/20/1989
475b81b6b3SRodney W. Grimes  */
485b81b6b3SRodney W. Grimes 
495b81b6b3SRodney W. Grimes /*
505b81b6b3SRodney W. Grimes  * Selectors
515b81b6b3SRodney W. Grimes  */
525b81b6b3SRodney W. Grimes 
535b81b6b3SRodney W. Grimes #define	ISPL(s)	((s)&3)		/* what is the priority level of a selector */
545b81b6b3SRodney W. Grimes #define	SEL_KPL	0		/* kernel priority level */
555b81b6b3SRodney W. Grimes #define	SEL_UPL	3		/* user priority level */
565b81b6b3SRodney W. Grimes #define	ISLDT(s)	((s)&SEL_LDT)	/* is it local or global */
575b81b6b3SRodney W. Grimes #define	SEL_LDT	4		/* local descriptor table */
585b81b6b3SRodney W. Grimes #define	IDXSEL(s)	(((s)>>3) & 0x1fff)		/* index of selector */
595b81b6b3SRodney W. Grimes #define	LSEL(s,r)	(((s)<<3) | SEL_LDT | r)	/* a local selector */
605b81b6b3SRodney W. Grimes #define	GSEL(s,r)	(((s)<<3) | r)			/* a global selector */
615b81b6b3SRodney W. Grimes 
625b81b6b3SRodney W. Grimes /*
635b81b6b3SRodney W. Grimes  * Memory and System segment descriptors
645b81b6b3SRodney W. Grimes  */
655b81b6b3SRodney W. Grimes struct	segment_descriptor	{
665b81b6b3SRodney W. Grimes 	unsigned sd_lolimit:16 ;	/* segment extent (lsb) */
675b81b6b3SRodney W. Grimes 	unsigned sd_lobase:24 ;		/* segment base address (lsb) */
685b81b6b3SRodney W. Grimes 	unsigned sd_type:5 ;		/* segment type */
695b81b6b3SRodney W. Grimes 	unsigned sd_dpl:2 ;		/* segment descriptor priority level */
705b81b6b3SRodney W. Grimes 	unsigned sd_p:1 ;		/* segment descriptor present */
715b81b6b3SRodney W. Grimes 	unsigned sd_hilimit:4 ;		/* segment extent (msb) */
725b81b6b3SRodney W. Grimes 	unsigned sd_xx:2 ;		/* unused */
735b81b6b3SRodney W. Grimes 	unsigned sd_def32:1 ;		/* default 32 vs 16 bit size */
745b81b6b3SRodney W. Grimes 	unsigned sd_gran:1 ;		/* limit granularity (byte/page units)*/
755b81b6b3SRodney W. Grimes 	unsigned sd_hibase:8 ;		/* segment base address  (msb) */
765b81b6b3SRodney W. Grimes } ;
775b81b6b3SRodney W. Grimes 
785b81b6b3SRodney W. Grimes /*
795b81b6b3SRodney W. Grimes  * Gate descriptors (e.g. indirect descriptors)
805b81b6b3SRodney W. Grimes  */
815b81b6b3SRodney W. Grimes struct	gate_descriptor	{
825b81b6b3SRodney W. Grimes 	unsigned gd_looffset:16 ;	/* gate offset (lsb) */
835b81b6b3SRodney W. Grimes 	unsigned gd_selector:16 ;	/* gate segment selector */
845b81b6b3SRodney W. Grimes 	unsigned gd_stkcpy:5 ;		/* number of stack wds to cpy */
855b81b6b3SRodney W. Grimes 	unsigned gd_xx:3 ;		/* unused */
865b81b6b3SRodney W. Grimes 	unsigned gd_type:5 ;		/* segment type */
875b81b6b3SRodney W. Grimes 	unsigned gd_dpl:2 ;		/* segment descriptor priority level */
885b81b6b3SRodney W. Grimes 	unsigned gd_p:1 ;		/* segment descriptor present */
895b81b6b3SRodney W. Grimes 	unsigned gd_hioffset:16 ;	/* gate offset (msb) */
905b81b6b3SRodney W. Grimes } ;
915b81b6b3SRodney W. Grimes 
925b81b6b3SRodney W. Grimes /*
935b81b6b3SRodney W. Grimes  * Generic descriptor
945b81b6b3SRodney W. Grimes  */
955b81b6b3SRodney W. Grimes union	descriptor	{
965b81b6b3SRodney W. Grimes 	struct	segment_descriptor sd;
975b81b6b3SRodney W. Grimes 	struct	gate_descriptor gd;
985b81b6b3SRodney W. Grimes };
995b81b6b3SRodney W. Grimes 
1005b81b6b3SRodney W. Grimes 	/* system segments and gate types */
1015b81b6b3SRodney W. Grimes #define	SDT_SYSNULL	 0	/* system null */
1025b81b6b3SRodney W. Grimes #define	SDT_SYS286TSS	 1	/* system 286 TSS available */
1035b81b6b3SRodney W. Grimes #define	SDT_SYSLDT	 2	/* system local descriptor table */
1045b81b6b3SRodney W. Grimes #define	SDT_SYS286BSY	 3	/* system 286 TSS busy */
1055b81b6b3SRodney W. Grimes #define	SDT_SYS286CGT	 4	/* system 286 call gate */
1065b81b6b3SRodney W. Grimes #define	SDT_SYSTASKGT	 5	/* system task gate */
1075b81b6b3SRodney W. Grimes #define	SDT_SYS286IGT	 6	/* system 286 interrupt gate */
1085b81b6b3SRodney W. Grimes #define	SDT_SYS286TGT	 7	/* system 286 trap gate */
1095b81b6b3SRodney W. Grimes #define	SDT_SYSNULL2	 8	/* system null again */
1105b81b6b3SRodney W. Grimes #define	SDT_SYS386TSS	 9	/* system 386 TSS available */
1115b81b6b3SRodney W. Grimes #define	SDT_SYSNULL3	10	/* system null again */
1125b81b6b3SRodney W. Grimes #define	SDT_SYS386BSY	11	/* system 386 TSS busy */
1135b81b6b3SRodney W. Grimes #define	SDT_SYS386CGT	12	/* system 386 call gate */
1145b81b6b3SRodney W. Grimes #define	SDT_SYSNULL4	13	/* system null again */
1155b81b6b3SRodney W. Grimes #define	SDT_SYS386IGT	14	/* system 386 interrupt gate */
1165b81b6b3SRodney W. Grimes #define	SDT_SYS386TGT	15	/* system 386 trap gate */
1175b81b6b3SRodney W. Grimes 
1185b81b6b3SRodney W. Grimes 	/* memory segment types */
1195b81b6b3SRodney W. Grimes #define	SDT_MEMRO	16	/* memory read only */
1205b81b6b3SRodney W. Grimes #define	SDT_MEMROA	17	/* memory read only accessed */
1215b81b6b3SRodney W. Grimes #define	SDT_MEMRW	18	/* memory read write */
1225b81b6b3SRodney W. Grimes #define	SDT_MEMRWA	19	/* memory read write accessed */
1235b81b6b3SRodney W. Grimes #define	SDT_MEMROD	20	/* memory read only expand dwn limit */
1245b81b6b3SRodney W. Grimes #define	SDT_MEMRODA	21	/* memory read only expand dwn limit accessed */
1255b81b6b3SRodney W. Grimes #define	SDT_MEMRWD	22	/* memory read write expand dwn limit */
1265b81b6b3SRodney W. Grimes #define	SDT_MEMRWDA	23	/* memory read write expand dwn limit acessed */
1275b81b6b3SRodney W. Grimes #define	SDT_MEME	24	/* memory execute only */
1285b81b6b3SRodney W. Grimes #define	SDT_MEMEA	25	/* memory execute only accessed */
1295b81b6b3SRodney W. Grimes #define	SDT_MEMER	26	/* memory execute read */
1305b81b6b3SRodney W. Grimes #define	SDT_MEMERA	27	/* memory execute read accessed */
1315b81b6b3SRodney W. Grimes #define	SDT_MEMEC	28	/* memory execute only conforming */
1325b81b6b3SRodney W. Grimes #define	SDT_MEMEAC	29	/* memory execute only accessed conforming */
1335b81b6b3SRodney W. Grimes #define	SDT_MEMERC	30	/* memory execute read conforming */
1345b81b6b3SRodney W. Grimes #define	SDT_MEMERAC	31	/* memory execute read accessed conforming */
1355b81b6b3SRodney W. Grimes 
1365b81b6b3SRodney W. Grimes /* is memory segment descriptor pointer ? */
1375b81b6b3SRodney W. Grimes #define ISMEMSDP(s)	((s->d_type) >= SDT_MEMRO && (s->d_type) <= SDT_MEMERAC)
1385b81b6b3SRodney W. Grimes 
1395b81b6b3SRodney W. Grimes /* is 286 gate descriptor pointer ? */
1405b81b6b3SRodney W. Grimes #define IS286GDP(s)	(((s->d_type) >= SDT_SYS286CGT \
1415b81b6b3SRodney W. Grimes 				 && (s->d_type) < SDT_SYS286TGT))
1425b81b6b3SRodney W. Grimes 
1435b81b6b3SRodney W. Grimes /* is 386 gate descriptor pointer ? */
1445b81b6b3SRodney W. Grimes #define IS386GDP(s)	(((s->d_type) >= SDT_SYS386CGT \
1455b81b6b3SRodney W. Grimes 				&& (s->d_type) < SDT_SYS386TGT))
1465b81b6b3SRodney W. Grimes 
1475b81b6b3SRodney W. Grimes /* is gate descriptor pointer ? */
1485b81b6b3SRodney W. Grimes #define ISGDP(s)	(IS286GDP(s) || IS386GDP(s))
1495b81b6b3SRodney W. Grimes 
1505b81b6b3SRodney W. Grimes /* is segment descriptor pointer ? */
1515b81b6b3SRodney W. Grimes #define ISSDP(s)	(ISMEMSDP(s) || !ISGDP(s))
1525b81b6b3SRodney W. Grimes 
1535b81b6b3SRodney W. Grimes /* is system segment descriptor pointer ? */
1545b81b6b3SRodney W. Grimes #define ISSYSSDP(s)	(!ISMEMSDP(s) && !ISGDP(s))
1555b81b6b3SRodney W. Grimes 
1565b81b6b3SRodney W. Grimes /*
1575b81b6b3SRodney W. Grimes  * Software definitions are in this convenient format,
1585b81b6b3SRodney W. Grimes  * which are translated into inconvenient segment descriptors
1595b81b6b3SRodney W. Grimes  * when needed to be used by the 386 hardware
1605b81b6b3SRodney W. Grimes  */
1615b81b6b3SRodney W. Grimes 
1625b81b6b3SRodney W. Grimes struct	soft_segment_descriptor	{
1635b81b6b3SRodney W. Grimes 	unsigned ssd_base ;		/* segment base address  */
1645b81b6b3SRodney W. Grimes 	unsigned ssd_limit ;		/* segment extent */
1655b81b6b3SRodney W. Grimes 	unsigned ssd_type:5 ;		/* segment type */
1665b81b6b3SRodney W. Grimes 	unsigned ssd_dpl:2 ;		/* segment descriptor priority level */
1675b81b6b3SRodney W. Grimes 	unsigned ssd_p:1 ;		/* segment descriptor present */
1685b81b6b3SRodney W. Grimes 	unsigned ssd_xx:4 ;		/* unused */
1695b81b6b3SRodney W. Grimes 	unsigned ssd_xx1:2 ;		/* unused */
1705b81b6b3SRodney W. Grimes 	unsigned ssd_def32:1 ;		/* default 32 vs 16 bit size */
1715b81b6b3SRodney W. Grimes 	unsigned ssd_gran:1 ;		/* limit granularity (byte/page units)*/
1725b81b6b3SRodney W. Grimes };
1735b81b6b3SRodney W. Grimes 
1745b81b6b3SRodney W. Grimes extern ssdtosd() ;	/* to decode a ssd */
1755b81b6b3SRodney W. Grimes extern sdtossd() ;	/* to encode a sd */
1765b81b6b3SRodney W. Grimes 
1775b81b6b3SRodney W. Grimes /*
1785b81b6b3SRodney W. Grimes  * region descriptors, used to load gdt/idt tables before segments yet exist.
1795b81b6b3SRodney W. Grimes  */
1805b81b6b3SRodney W. Grimes struct region_descriptor {
1815b81b6b3SRodney W. Grimes 	unsigned rd_limit:16;		/* segment extent */
1825b81b6b3SRodney W. Grimes 	unsigned rd_base:32;		/* base address  */
1835b81b6b3SRodney W. Grimes };
1845b81b6b3SRodney W. Grimes 
1855b81b6b3SRodney W. Grimes /*
1865b81b6b3SRodney W. Grimes  * Segment Protection Exception code bits
1875b81b6b3SRodney W. Grimes  */
1885b81b6b3SRodney W. Grimes 
1895b81b6b3SRodney W. Grimes #define	SEGEX_EXT	0x01	/* recursive or externally induced */
1905b81b6b3SRodney W. Grimes #define	SEGEX_IDT	0x02	/* interrupt descriptor table */
1915b81b6b3SRodney W. Grimes #define	SEGEX_TI	0x04	/* local descriptor table */
1925b81b6b3SRodney W. Grimes 				/* other bits are affected descriptor index */
1935b81b6b3SRodney W. Grimes #define SEGEX_IDX(s)	((s)>>3)&0x1fff)
1945b81b6b3SRodney W. Grimes 
1955b81b6b3SRodney W. Grimes /*
1965b81b6b3SRodney W. Grimes  * Size of IDT table
1975b81b6b3SRodney W. Grimes  */
1985b81b6b3SRodney W. Grimes 
1995b81b6b3SRodney W. Grimes #define	NIDT	256
2005b81b6b3SRodney W. Grimes #define	NRSVIDT	32		/* reserved entries for cpu exceptions */
2016e393973SGarrett Wollman #endif /* _MACHINE_SEGMENTS_H_ */
202