master
1/*-
2 * SPDX-License-Identifier: BSD-3-Clause
3 *
4 * Copyright (c) 1989, 1990 William F. Jolitz
5 * Copyright (c) 1990 The Regents of the University of California.
6 * All rights reserved.
7 *
8 * This code is derived from software contributed to Berkeley by
9 * William Jolitz.
10 *
11 * Redistribution and use in source and binary forms, with or without
12 * modification, are permitted provided that the following conditions
13 * are met:
14 * 1. Redistributions of source code must retain the above copyright
15 * notice, this list of conditions and the following disclaimer.
16 * 2. Redistributions in binary form must reproduce the above copyright
17 * notice, this list of conditions and the following disclaimer in the
18 * documentation and/or other materials provided with the distribution.
19 * 3. Neither the name of the University nor the names of its contributors
20 * may be used to endorse or promote products derived from this software
21 * without specific prior written permission.
22 *
23 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
24 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
25 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
26 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
27 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
28 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
29 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
30 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
31 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
32 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
33 * SUCH DAMAGE.
34 *
35 * from: @(#)segments.h 7.1 (Berkeley) 5/9/91
36 */
37
38#ifndef _MACHINE_SEGMENTS_H_
39#define _MACHINE_SEGMENTS_H_
40
41/*
42 * 386 Segmentation Data Structures and definitions
43 * William F. Jolitz (william@ernie.berkeley.edu) 6/20/1989
44 */
45
46#include <x86/segments.h>
47
48/*
49 * Software definitions are in this convenient format,
50 * which are translated into inconvenient segment descriptors
51 * when needed to be used by the 386 hardware
52 */
53
54struct soft_segment_descriptor {
55 unsigned ssd_base ; /* segment base address */
56 unsigned ssd_limit ; /* segment extent */
57 unsigned ssd_type:5 ; /* segment type */
58 unsigned ssd_dpl:2 ; /* segment descriptor priority level */
59 unsigned ssd_p:1 ; /* segment descriptor present */
60 unsigned ssd_xx:4 ; /* unused */
61 unsigned ssd_xx1:2 ; /* unused */
62 unsigned ssd_def32:1 ; /* default 32 vs 16 bit size */
63 unsigned ssd_gran:1 ; /* limit granularity (byte/page units)*/
64};
65
66/*
67 * region descriptors, used to load gdt/idt tables before segments yet exist.
68 */
69struct region_descriptor {
70 unsigned rd_limit:16; /* segment extent */
71 unsigned rd_base:32 __packed; /* base address */
72};
73
74/*
75 * Segment Protection Exception code bits
76 */
77
78#define SEGEX_EXT 0x01 /* recursive or externally induced */
79#define SEGEX_IDT 0x02 /* interrupt descriptor table */
80#define SEGEX_TI 0x04 /* local descriptor table */
81 /* other bits are affected descriptor index */
82#define SEGEX_IDX(s) (((s)>>3)&0x1fff)
83
84#ifdef _KERNEL
85extern int _default_ldt;
86extern union descriptor *gdt;
87extern union descriptor *ldt;
88extern struct soft_segment_descriptor gdt_segs[];
89extern struct gate_descriptor *idt;
90
91void lgdt(struct region_descriptor *rdp);
92void sdtossd(struct segment_descriptor *sdp,
93 struct soft_segment_descriptor *ssdp);
94void ssdtosd(struct soft_segment_descriptor *ssdp,
95 struct segment_descriptor *sdp);
96#endif /* _KERNEL */
97
98#endif /* !_MACHINE_SEGMENTS_H_ */