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 * 4. Neither the name of the University nor the names of its contributors
184Srgrimes *    may be used to endorse or promote products derived from this software
194Srgrimes *    without specific prior written permission.
204Srgrimes *
214Srgrimes * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
224Srgrimes * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
234Srgrimes * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
244Srgrimes * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
254Srgrimes * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
264Srgrimes * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
274Srgrimes * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
284Srgrimes * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
294Srgrimes * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
304Srgrimes * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
314Srgrimes * SUCH DAMAGE.
324Srgrimes *
33621Srgrimes *	from: @(#)segments.h	7.1 (Berkeley) 5/9/91
3450477Speter * $FreeBSD$
354Srgrimes */
364Srgrimes
37719Swollman#ifndef _MACHINE_SEGMENTS_H_
384501Sbde#define	_MACHINE_SEGMENTS_H_
39719Swollman
404Srgrimes/*
414Srgrimes * 386 Segmentation Data Structures and definitions
424Srgrimes *	William F. Jolitz (william@ernie.berkeley.edu) 6/20/1989
434Srgrimes */
444Srgrimes
45233203Stijl#include <x86/segments.h>
464Srgrimes
474Srgrimes/*
484Srgrimes * Software definitions are in this convenient format,
494Srgrimes * which are translated into inconvenient segment descriptors
504Srgrimes * when needed to be used by the 386 hardware
514Srgrimes */
524Srgrimes
534Srgrimesstruct	soft_segment_descriptor	{
544Srgrimes	unsigned ssd_base ;		/* segment base address  */
554Srgrimes	unsigned ssd_limit ;		/* segment extent */
564Srgrimes	unsigned ssd_type:5 ;		/* segment type */
574Srgrimes	unsigned ssd_dpl:2 ;		/* segment descriptor priority level */
584Srgrimes	unsigned ssd_p:1 ;		/* segment descriptor present */
594Srgrimes	unsigned ssd_xx:4 ;		/* unused */
604Srgrimes	unsigned ssd_xx1:2 ;		/* unused */
614Srgrimes	unsigned ssd_def32:1 ;		/* default 32 vs 16 bit size */
624Srgrimes	unsigned ssd_gran:1 ;		/* limit granularity (byte/page units)*/
634Srgrimes};
644Srgrimes
654Srgrimes/*
664Srgrimes * region descriptors, used to load gdt/idt tables before segments yet exist.
674Srgrimes */
684Srgrimesstruct region_descriptor {
69103847Speter	unsigned rd_limit:16;		/* segment extent */
70103847Speter	unsigned rd_base:32 __packed;	/* base address  */
714Srgrimes};
724Srgrimes
734Srgrimes/*
744Srgrimes * Segment Protection Exception code bits
754Srgrimes */
764Srgrimes
774Srgrimes#define	SEGEX_EXT	0x01	/* recursive or externally induced */
784Srgrimes#define	SEGEX_IDT	0x02	/* interrupt descriptor table */
794Srgrimes#define	SEGEX_TI	0x04	/* local descriptor table */
804Srgrimes				/* other bits are affected descriptor index */
8187311Sjhb#define SEGEX_IDX(s)	(((s)>>3)&0x1fff)
824Srgrimes
8355205Speter#ifdef _KERNEL
844501Sbdeextern int	_default_ldt;
8525164Speterextern union descriptor gdt[];
86181775Skmacyextern union descriptor ldt[NLDT];
874501Sbdeextern struct soft_segment_descriptor gdt_segs[];
8848005Sbdeextern struct gate_descriptor *idt;
89121754Sjhbextern struct region_descriptor r_gdt, r_idt;
901051Sdg
9193018Sbdevoid	lgdt(struct region_descriptor *rdp);
9293018Sbdevoid	sdtossd(struct segment_descriptor *sdp,
9393018Sbde	    struct soft_segment_descriptor *ssdp);
9493018Sbdevoid	ssdtosd(struct soft_segment_descriptor *ssdp,
9593018Sbde	    struct segment_descriptor *sdp);
9655205Speter#endif /* _KERNEL */
974473Sbde
984473Sbde#endif /* !_MACHINE_SEGMENTS_H_ */
99