15b81b6b3SRodney W. Grimes /*- 2*51369649SPedro F. Giffuni * SPDX-License-Identifier: BSD-3-Clause 3*51369649SPedro 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 * 3534a8ed1bSRodney W. Grimes * from: @(#)segments.h 7.1 (Berkeley) 5/9/91 36c3aac50fSPeter Wemm * $FreeBSD$ 375b81b6b3SRodney W. Grimes */ 385b81b6b3SRodney W. Grimes 396e393973SGarrett Wollman #ifndef _MACHINE_SEGMENTS_H_ 40b0d1e6deSBruce Evans #define _MACHINE_SEGMENTS_H_ 416e393973SGarrett Wollman 425b81b6b3SRodney W. Grimes /* 43afa88623SPeter Wemm * AMD64 Segmentation Data Structures and definitions 445b81b6b3SRodney W. Grimes */ 455b81b6b3SRodney W. Grimes 46bcde3b9fSTijl Coosemans #include <x86/segments.h> 478923c96eSRui Paulo 485b81b6b3SRodney W. Grimes /* 49afa88623SPeter Wemm * System segment descriptors (128 bit wide) 50afa88623SPeter Wemm */ 51afa88623SPeter Wemm struct system_segment_descriptor { 52afa88623SPeter Wemm u_int64_t sd_lolimit:16; /* segment extent (lsb) */ 53afa88623SPeter Wemm u_int64_t sd_lobase:24; /* segment base address (lsb) */ 54afa88623SPeter Wemm u_int64_t sd_type:5; /* segment type */ 55afa88623SPeter Wemm u_int64_t sd_dpl:2; /* segment descriptor priority level */ 56afa88623SPeter Wemm u_int64_t sd_p:1; /* segment descriptor present */ 57afa88623SPeter Wemm u_int64_t sd_hilimit:4; /* segment extent (msb) */ 58afa88623SPeter Wemm u_int64_t sd_xx0:3; /* unused */ 59afa88623SPeter Wemm u_int64_t sd_gran:1; /* limit granularity (byte/page units)*/ 60afa88623SPeter Wemm u_int64_t sd_hibase:40 __packed;/* segment base address (msb) */ 61afa88623SPeter Wemm u_int64_t sd_xx1:8; 62afa88623SPeter Wemm u_int64_t sd_mbz:5; /* MUST be zero */ 63afa88623SPeter Wemm u_int64_t sd_xx2:19; 64afa88623SPeter Wemm } __packed; 65afa88623SPeter Wemm 66afa88623SPeter Wemm /* 675b81b6b3SRodney W. Grimes * Software definitions are in this convenient format, 685b81b6b3SRodney W. Grimes * which are translated into inconvenient segment descriptors 695b81b6b3SRodney W. Grimes * when needed to be used by the 386 hardware 705b81b6b3SRodney W. Grimes */ 715b81b6b3SRodney W. Grimes 725b81b6b3SRodney W. Grimes struct soft_segment_descriptor { 73afa88623SPeter Wemm unsigned long ssd_base; /* segment base address */ 74afa88623SPeter Wemm unsigned long ssd_limit; /* segment extent */ 75afa88623SPeter Wemm unsigned long ssd_type:5; /* segment type */ 76afa88623SPeter Wemm unsigned long ssd_dpl:2; /* segment descriptor priority level */ 77afa88623SPeter Wemm unsigned long ssd_p:1; /* segment descriptor present */ 78afa88623SPeter Wemm unsigned long ssd_long:1; /* long mode (for %cs) */ 79afa88623SPeter Wemm unsigned long ssd_def32:1; /* default 32 vs 16 bit size */ 80afa88623SPeter Wemm unsigned long ssd_gran:1; /* limit granularity (byte/page units)*/ 81afa88623SPeter Wemm } __packed; 825b81b6b3SRodney W. Grimes 835b81b6b3SRodney W. Grimes /* 845b81b6b3SRodney W. Grimes * region descriptors, used to load gdt/idt tables before segments yet exist. 855b81b6b3SRodney W. Grimes */ 865b81b6b3SRodney W. Grimes struct region_descriptor { 87291bfc8dSKonstantin Belousov uint64_t rd_limit:16; /* segment extent */ 88291bfc8dSKonstantin Belousov uint64_t rd_base:64 __packed; /* base address */ 89afa88623SPeter Wemm } __packed; 905b81b6b3SRodney W. Grimes 91664a31e4SPeter Wemm #ifdef _KERNEL 92afa88623SPeter Wemm extern struct user_segment_descriptor gdt[]; 93b0d1e6deSBruce Evans extern struct soft_segment_descriptor gdt_segs[]; 9450045fbcSBruce Evans extern struct gate_descriptor *idt; 950d2a2989SPeter Wemm extern struct region_descriptor r_gdt, r_idt; 96da59a31cSDavid Greenman 97b63dc6adSAlfred Perlstein void lgdt(struct region_descriptor *rdp); 98afa88623SPeter Wemm void sdtossd(struct user_segment_descriptor *sdp, 99b63dc6adSAlfred Perlstein struct soft_segment_descriptor *ssdp); 100b63dc6adSAlfred Perlstein void ssdtosd(struct soft_segment_descriptor *ssdp, 101afa88623SPeter Wemm struct user_segment_descriptor *sdp); 102afa88623SPeter Wemm void ssdtosyssd(struct soft_segment_descriptor *ssdp, 103afa88623SPeter Wemm struct system_segment_descriptor *sdp); 1042c66cccaSKonstantin Belousov void update_gdt_gsbase(struct thread *td, uint32_t base); 1052c66cccaSKonstantin Belousov void update_gdt_fsbase(struct thread *td, uint32_t base); 106664a31e4SPeter Wemm #endif /* _KERNEL */ 107040f1000SBruce Evans 108040f1000SBruce Evans #endif /* !_MACHINE_SEGMENTS_H_ */ 109