segments.h revision 719
14Srgrimes/*-
24Srgrimes * Copyright (c) 1989, 1990 William F. Jolitz
34Srgrimes * Copyright (c) 1990 The Regents of the University of California.
44Srgrimes * All rights reserved.
54Srgrimes *
64Srgrimes * This code is derived from software contributed to Berkeley by
74Srgrimes * William Jolitz.
84Srgrimes *
94Srgrimes * Redistribution and use in source and binary forms, with or without
104Srgrimes * modification, are permitted provided that the following conditions
114Srgrimes * are met:
124Srgrimes * 1. Redistributions of source code must retain the above copyright
134Srgrimes *    notice, this list of conditions and the following disclaimer.
144Srgrimes * 2. Redistributions in binary form must reproduce the above copyright
154Srgrimes *    notice, this list of conditions and the following disclaimer in the
164Srgrimes *    documentation and/or other materials provided with the distribution.
174Srgrimes * 3. All advertising materials mentioning features or use of this software
184Srgrimes *    must display the following acknowledgement:
194Srgrimes *	This product includes software developed by the University of
204Srgrimes *	California, Berkeley and its contributors.
214Srgrimes * 4. Neither the name of the University nor the names of its contributors
224Srgrimes *    may be used to endorse or promote products derived from this software
234Srgrimes *    without specific prior written permission.
244Srgrimes *
254Srgrimes * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
264Srgrimes * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
274Srgrimes * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
284Srgrimes * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
294Srgrimes * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
304Srgrimes * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
314Srgrimes * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
324Srgrimes * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
334Srgrimes * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
344Srgrimes * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
354Srgrimes * SUCH DAMAGE.
364Srgrimes *
37621Srgrimes *	from: @(#)segments.h	7.1 (Berkeley) 5/9/91
38719Swollman *	$Id: segments.h,v 1.2 1993/10/16 14:39:30 rgrimes Exp $
394Srgrimes */
404Srgrimes
41719Swollman#ifndef _MACHINE_SEGMENTS_H_
42719Swollman#define _MACHINE_SEGMENTS_H_ 1
43719Swollman
444Srgrimes/*
454Srgrimes * 386 Segmentation Data Structures and definitions
464Srgrimes *	William F. Jolitz (william@ernie.berkeley.edu) 6/20/1989
474Srgrimes */
484Srgrimes
494Srgrimes/*
504Srgrimes * Selectors
514Srgrimes */
524Srgrimes
534Srgrimes#define	ISPL(s)	((s)&3)		/* what is the priority level of a selector */
544Srgrimes#define	SEL_KPL	0		/* kernel priority level */
554Srgrimes#define	SEL_UPL	3		/* user priority level */
564Srgrimes#define	ISLDT(s)	((s)&SEL_LDT)	/* is it local or global */
574Srgrimes#define	SEL_LDT	4		/* local descriptor table */
584Srgrimes#define	IDXSEL(s)	(((s)>>3) & 0x1fff)		/* index of selector */
594Srgrimes#define	LSEL(s,r)	(((s)<<3) | SEL_LDT | r)	/* a local selector */
604Srgrimes#define	GSEL(s,r)	(((s)<<3) | r)			/* a global selector */
614Srgrimes
624Srgrimes/*
634Srgrimes * Memory and System segment descriptors
644Srgrimes */
654Srgrimesstruct	segment_descriptor	{
664Srgrimes	unsigned sd_lolimit:16 ;	/* segment extent (lsb) */
674Srgrimes	unsigned sd_lobase:24 ;		/* segment base address (lsb) */
684Srgrimes	unsigned sd_type:5 ;		/* segment type */
694Srgrimes	unsigned sd_dpl:2 ;		/* segment descriptor priority level */
704Srgrimes	unsigned sd_p:1 ;		/* segment descriptor present */
714Srgrimes	unsigned sd_hilimit:4 ;		/* segment extent (msb) */
724Srgrimes	unsigned sd_xx:2 ;		/* unused */
734Srgrimes	unsigned sd_def32:1 ;		/* default 32 vs 16 bit size */
744Srgrimes	unsigned sd_gran:1 ;		/* limit granularity (byte/page units)*/
754Srgrimes	unsigned sd_hibase:8 ;		/* segment base address  (msb) */
764Srgrimes} ;
774Srgrimes
784Srgrimes/*
794Srgrimes * Gate descriptors (e.g. indirect descriptors)
804Srgrimes */
814Srgrimesstruct	gate_descriptor	{
824Srgrimes	unsigned gd_looffset:16 ;	/* gate offset (lsb) */
834Srgrimes	unsigned gd_selector:16 ;	/* gate segment selector */
844Srgrimes	unsigned gd_stkcpy:5 ;		/* number of stack wds to cpy */
854Srgrimes	unsigned gd_xx:3 ;		/* unused */
864Srgrimes	unsigned gd_type:5 ;		/* segment type */
874Srgrimes	unsigned gd_dpl:2 ;		/* segment descriptor priority level */
884Srgrimes	unsigned gd_p:1 ;		/* segment descriptor present */
894Srgrimes	unsigned gd_hioffset:16 ;	/* gate offset (msb) */
904Srgrimes} ;
914Srgrimes
924Srgrimes/*
934Srgrimes * Generic descriptor
944Srgrimes */
954Srgrimesunion	descriptor	{
964Srgrimes	struct	segment_descriptor sd;
974Srgrimes	struct	gate_descriptor gd;
984Srgrimes};
994Srgrimes
1004Srgrimes	/* system segments and gate types */
1014Srgrimes#define	SDT_SYSNULL	 0	/* system null */
1024Srgrimes#define	SDT_SYS286TSS	 1	/* system 286 TSS available */
1034Srgrimes#define	SDT_SYSLDT	 2	/* system local descriptor table */
1044Srgrimes#define	SDT_SYS286BSY	 3	/* system 286 TSS busy */
1054Srgrimes#define	SDT_SYS286CGT	 4	/* system 286 call gate */
1064Srgrimes#define	SDT_SYSTASKGT	 5	/* system task gate */
1074Srgrimes#define	SDT_SYS286IGT	 6	/* system 286 interrupt gate */
1084Srgrimes#define	SDT_SYS286TGT	 7	/* system 286 trap gate */
1094Srgrimes#define	SDT_SYSNULL2	 8	/* system null again */
1104Srgrimes#define	SDT_SYS386TSS	 9	/* system 386 TSS available */
1114Srgrimes#define	SDT_SYSNULL3	10	/* system null again */
1124Srgrimes#define	SDT_SYS386BSY	11	/* system 386 TSS busy */
1134Srgrimes#define	SDT_SYS386CGT	12	/* system 386 call gate */
1144Srgrimes#define	SDT_SYSNULL4	13	/* system null again */
1154Srgrimes#define	SDT_SYS386IGT	14	/* system 386 interrupt gate */
1164Srgrimes#define	SDT_SYS386TGT	15	/* system 386 trap gate */
1174Srgrimes
1184Srgrimes	/* memory segment types */
1194Srgrimes#define	SDT_MEMRO	16	/* memory read only */
1204Srgrimes#define	SDT_MEMROA	17	/* memory read only accessed */
1214Srgrimes#define	SDT_MEMRW	18	/* memory read write */
1224Srgrimes#define	SDT_MEMRWA	19	/* memory read write accessed */
1234Srgrimes#define	SDT_MEMROD	20	/* memory read only expand dwn limit */
1244Srgrimes#define	SDT_MEMRODA	21	/* memory read only expand dwn limit accessed */
1254Srgrimes#define	SDT_MEMRWD	22	/* memory read write expand dwn limit */
1264Srgrimes#define	SDT_MEMRWDA	23	/* memory read write expand dwn limit acessed */
1274Srgrimes#define	SDT_MEME	24	/* memory execute only */
1284Srgrimes#define	SDT_MEMEA	25	/* memory execute only accessed */
1294Srgrimes#define	SDT_MEMER	26	/* memory execute read */
1304Srgrimes#define	SDT_MEMERA	27	/* memory execute read accessed */
1314Srgrimes#define	SDT_MEMEC	28	/* memory execute only conforming */
1324Srgrimes#define	SDT_MEMEAC	29	/* memory execute only accessed conforming */
1334Srgrimes#define	SDT_MEMERC	30	/* memory execute read conforming */
1344Srgrimes#define	SDT_MEMERAC	31	/* memory execute read accessed conforming */
1354Srgrimes
1364Srgrimes/* is memory segment descriptor pointer ? */
1374Srgrimes#define ISMEMSDP(s)	((s->d_type) >= SDT_MEMRO && (s->d_type) <= SDT_MEMERAC)
1384Srgrimes
1394Srgrimes/* is 286 gate descriptor pointer ? */
1404Srgrimes#define IS286GDP(s)	(((s->d_type) >= SDT_SYS286CGT \
1414Srgrimes				 && (s->d_type) < SDT_SYS286TGT))
1424Srgrimes
1434Srgrimes/* is 386 gate descriptor pointer ? */
1444Srgrimes#define IS386GDP(s)	(((s->d_type) >= SDT_SYS386CGT \
1454Srgrimes				&& (s->d_type) < SDT_SYS386TGT))
1464Srgrimes
1474Srgrimes/* is gate descriptor pointer ? */
1484Srgrimes#define ISGDP(s)	(IS286GDP(s) || IS386GDP(s))
1494Srgrimes
1504Srgrimes/* is segment descriptor pointer ? */
1514Srgrimes#define ISSDP(s)	(ISMEMSDP(s) || !ISGDP(s))
1524Srgrimes
1534Srgrimes/* is system segment descriptor pointer ? */
1544Srgrimes#define ISSYSSDP(s)	(!ISMEMSDP(s) && !ISGDP(s))
1554Srgrimes
1564Srgrimes/*
1574Srgrimes * Software definitions are in this convenient format,
1584Srgrimes * which are translated into inconvenient segment descriptors
1594Srgrimes * when needed to be used by the 386 hardware
1604Srgrimes */
1614Srgrimes
1624Srgrimesstruct	soft_segment_descriptor	{
1634Srgrimes	unsigned ssd_base ;		/* segment base address  */
1644Srgrimes	unsigned ssd_limit ;		/* segment extent */
1654Srgrimes	unsigned ssd_type:5 ;		/* segment type */
1664Srgrimes	unsigned ssd_dpl:2 ;		/* segment descriptor priority level */
1674Srgrimes	unsigned ssd_p:1 ;		/* segment descriptor present */
1684Srgrimes	unsigned ssd_xx:4 ;		/* unused */
1694Srgrimes	unsigned ssd_xx1:2 ;		/* unused */
1704Srgrimes	unsigned ssd_def32:1 ;		/* default 32 vs 16 bit size */
1714Srgrimes	unsigned ssd_gran:1 ;		/* limit granularity (byte/page units)*/
1724Srgrimes};
1734Srgrimes
1744Srgrimesextern ssdtosd() ;	/* to decode a ssd */
1754Srgrimesextern sdtossd() ;	/* to encode a sd */
1764Srgrimes
1774Srgrimes/*
1784Srgrimes * region descriptors, used to load gdt/idt tables before segments yet exist.
1794Srgrimes */
1804Srgrimesstruct region_descriptor {
1814Srgrimes	unsigned rd_limit:16;		/* segment extent */
1824Srgrimes	unsigned rd_base:32;		/* base address  */
1834Srgrimes};
1844Srgrimes
1854Srgrimes/*
1864Srgrimes * Segment Protection Exception code bits
1874Srgrimes */
1884Srgrimes
1894Srgrimes#define	SEGEX_EXT	0x01	/* recursive or externally induced */
1904Srgrimes#define	SEGEX_IDT	0x02	/* interrupt descriptor table */
1914Srgrimes#define	SEGEX_TI	0x04	/* local descriptor table */
1924Srgrimes				/* other bits are affected descriptor index */
1934Srgrimes#define SEGEX_IDX(s)	((s)>>3)&0x1fff)
1944Srgrimes
1954Srgrimes/*
1964Srgrimes * Size of IDT table
1974Srgrimes */
1984Srgrimes
1994Srgrimes#define	NIDT	256
2004Srgrimes#define	NRSVIDT	32		/* reserved entries for cpu exceptions */
201719Swollman#endif /* _MACHINE_SEGMENTS_H_ */
202