15b81b6b3SRodney W. Grimes /*- 251369649SPedro F. Giffuni * SPDX-License-Identifier: BSD-3-Clause 351369649SPedro F. Giffuni * 45b81b6b3SRodney W. Grimes * Copyright (c) 1989, 1990 William F. Jolitz 55b81b6b3SRodney W. Grimes * Copyright (c) 1990 The Regents of the University of California. 65b81b6b3SRodney W. Grimes * All rights reserved. 75b81b6b3SRodney W. Grimes * 85b81b6b3SRodney W. Grimes * This code is derived from software contributed to Berkeley by 95b81b6b3SRodney W. Grimes * William Jolitz. 105b81b6b3SRodney W. Grimes * 115b81b6b3SRodney W. Grimes * Redistribution and use in source and binary forms, with or without 125b81b6b3SRodney W. Grimes * modification, are permitted provided that the following conditions 135b81b6b3SRodney W. Grimes * are met: 145b81b6b3SRodney W. Grimes * 1. Redistributions of source code must retain the above copyright 155b81b6b3SRodney W. Grimes * notice, this list of conditions and the following disclaimer. 165b81b6b3SRodney W. Grimes * 2. Redistributions in binary form must reproduce the above copyright 175b81b6b3SRodney W. Grimes * notice, this list of conditions and the following disclaimer in the 185b81b6b3SRodney W. Grimes * documentation and/or other materials provided with the distribution. 19fbbd9655SWarner Losh * 3. Neither the name of the University nor the names of its contributors 205b81b6b3SRodney W. Grimes * may be used to endorse or promote products derived from this software 215b81b6b3SRodney W. Grimes * without specific prior written permission. 225b81b6b3SRodney W. Grimes * 235b81b6b3SRodney W. Grimes * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 245b81b6b3SRodney W. Grimes * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 255b81b6b3SRodney W. Grimes * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 265b81b6b3SRodney W. Grimes * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 275b81b6b3SRodney W. Grimes * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 285b81b6b3SRodney W. Grimes * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 295b81b6b3SRodney W. Grimes * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 305b81b6b3SRodney W. Grimes * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 315b81b6b3SRodney W. Grimes * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 325b81b6b3SRodney W. Grimes * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 335b81b6b3SRodney W. Grimes * SUCH DAMAGE. 345b81b6b3SRodney W. Grimes */ 355b81b6b3SRodney W. Grimes 366e393973SGarrett Wollman #ifndef _MACHINE_SEGMENTS_H_ 37b0d1e6deSBruce Evans #define _MACHINE_SEGMENTS_H_ 386e393973SGarrett Wollman 395b81b6b3SRodney W. Grimes /* 405b81b6b3SRodney W. Grimes * 386 Segmentation Data Structures and definitions 415b81b6b3SRodney W. Grimes * William F. Jolitz (william@ernie.berkeley.edu) 6/20/1989 425b81b6b3SRodney W. Grimes */ 435b81b6b3SRodney W. Grimes 44bcde3b9fSTijl Coosemans #include <x86/segments.h> 455b81b6b3SRodney W. Grimes 465b81b6b3SRodney W. Grimes /* 475b81b6b3SRodney W. Grimes * Software definitions are in this convenient format, 485b81b6b3SRodney W. Grimes * which are translated into inconvenient segment descriptors 495b81b6b3SRodney W. Grimes * when needed to be used by the 386 hardware 505b81b6b3SRodney W. Grimes */ 515b81b6b3SRodney W. Grimes 525b81b6b3SRodney W. Grimes struct soft_segment_descriptor { 535b81b6b3SRodney W. Grimes unsigned ssd_base ; /* segment base address */ 545b81b6b3SRodney W. Grimes unsigned ssd_limit ; /* segment extent */ 555b81b6b3SRodney W. Grimes unsigned ssd_type:5 ; /* segment type */ 565b81b6b3SRodney W. Grimes unsigned ssd_dpl:2 ; /* segment descriptor priority level */ 575b81b6b3SRodney W. Grimes unsigned ssd_p:1 ; /* segment descriptor present */ 585b81b6b3SRodney W. Grimes unsigned ssd_xx:4 ; /* unused */ 595b81b6b3SRodney W. Grimes unsigned ssd_xx1:2 ; /* unused */ 605b81b6b3SRodney W. Grimes unsigned ssd_def32:1 ; /* default 32 vs 16 bit size */ 615b81b6b3SRodney W. Grimes unsigned ssd_gran:1 ; /* limit granularity (byte/page units)*/ 625b81b6b3SRodney W. Grimes }; 635b81b6b3SRodney W. Grimes 645b81b6b3SRodney W. Grimes /* 655b81b6b3SRodney W. Grimes * region descriptors, used to load gdt/idt tables before segments yet exist. 665b81b6b3SRodney W. Grimes */ 675b81b6b3SRodney W. Grimes struct region_descriptor { 685b81b6b3SRodney W. Grimes unsigned rd_limit:16; /* segment extent */ 69691cb905SPeter Wemm unsigned rd_base:32 __packed; /* base address */ 705b81b6b3SRodney W. Grimes }; 715b81b6b3SRodney W. Grimes 725b81b6b3SRodney W. Grimes /* 735b81b6b3SRodney W. Grimes * Segment Protection Exception code bits 745b81b6b3SRodney W. Grimes */ 755b81b6b3SRodney W. Grimes 765b81b6b3SRodney W. Grimes #define SEGEX_EXT 0x01 /* recursive or externally induced */ 775b81b6b3SRodney W. Grimes #define SEGEX_IDT 0x02 /* interrupt descriptor table */ 785b81b6b3SRodney W. Grimes #define SEGEX_TI 0x04 /* local descriptor table */ 795b81b6b3SRodney W. Grimes /* other bits are affected descriptor index */ 809b37da13SJohn Baldwin #define SEGEX_IDX(s) (((s)>>3)&0x1fff) 815b81b6b3SRodney W. Grimes 82664a31e4SPeter Wemm #ifdef _KERNEL 83b0d1e6deSBruce Evans extern int _default_ldt; 84*d86c1f0dSKonstantin Belousov extern union descriptor *gdt; 85*d86c1f0dSKonstantin Belousov extern union descriptor *ldt; 86b0d1e6deSBruce Evans extern struct soft_segment_descriptor gdt_segs[]; 8750045fbcSBruce Evans extern struct gate_descriptor *idt; 88da59a31cSDavid Greenman 89b63dc6adSAlfred Perlstein void lgdt(struct region_descriptor *rdp); 90b63dc6adSAlfred Perlstein void sdtossd(struct segment_descriptor *sdp, 91b63dc6adSAlfred Perlstein struct soft_segment_descriptor *ssdp); 92b63dc6adSAlfred Perlstein void ssdtosd(struct soft_segment_descriptor *ssdp, 93b63dc6adSAlfred Perlstein struct segment_descriptor *sdp); 94664a31e4SPeter Wemm #endif /* _KERNEL */ 95040f1000SBruce Evans 96040f1000SBruce Evans #endif /* !_MACHINE_SEGMENTS_H_ */ 97