xref: /freebsd/sys/amd64/include/segments.h (revision 291bfc8d24f8d246afdf48d22088e8ef31eb9172)
15b81b6b3SRodney W. Grimes /*-
25b81b6b3SRodney W. Grimes  * Copyright (c) 1989, 1990 William F. Jolitz
35b81b6b3SRodney W. Grimes  * Copyright (c) 1990 The Regents of the University of California.
45b81b6b3SRodney W. Grimes  * All rights reserved.
55b81b6b3SRodney W. Grimes  *
65b81b6b3SRodney W. Grimes  * This code is derived from software contributed to Berkeley by
75b81b6b3SRodney W. Grimes  * William Jolitz.
85b81b6b3SRodney W. Grimes  *
95b81b6b3SRodney W. Grimes  * Redistribution and use in source and binary forms, with or without
105b81b6b3SRodney W. Grimes  * modification, are permitted provided that the following conditions
115b81b6b3SRodney W. Grimes  * are met:
125b81b6b3SRodney W. Grimes  * 1. Redistributions of source code must retain the above copyright
135b81b6b3SRodney W. Grimes  *    notice, this list of conditions and the following disclaimer.
145b81b6b3SRodney W. Grimes  * 2. Redistributions in binary form must reproduce the above copyright
155b81b6b3SRodney W. Grimes  *    notice, this list of conditions and the following disclaimer in the
165b81b6b3SRodney W. Grimes  *    documentation and/or other materials provided with the distribution.
175b81b6b3SRodney W. Grimes  * 4. Neither the name of the University nor the names of its contributors
185b81b6b3SRodney W. Grimes  *    may be used to endorse or promote products derived from this software
195b81b6b3SRodney W. Grimes  *    without specific prior written permission.
205b81b6b3SRodney W. Grimes  *
215b81b6b3SRodney W. Grimes  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
225b81b6b3SRodney W. Grimes  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
235b81b6b3SRodney W. Grimes  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
245b81b6b3SRodney W. Grimes  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
255b81b6b3SRodney W. Grimes  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
265b81b6b3SRodney W. Grimes  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
275b81b6b3SRodney W. Grimes  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
285b81b6b3SRodney W. Grimes  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
295b81b6b3SRodney W. Grimes  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
305b81b6b3SRodney W. Grimes  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
315b81b6b3SRodney W. Grimes  * SUCH DAMAGE.
325b81b6b3SRodney W. Grimes  *
3334a8ed1bSRodney W. Grimes  *	from: @(#)segments.h	7.1 (Berkeley) 5/9/91
34c3aac50fSPeter Wemm  * $FreeBSD$
355b81b6b3SRodney W. Grimes  */
365b81b6b3SRodney W. Grimes 
376e393973SGarrett Wollman #ifndef _MACHINE_SEGMENTS_H_
38b0d1e6deSBruce Evans #define	_MACHINE_SEGMENTS_H_
396e393973SGarrett Wollman 
405b81b6b3SRodney W. Grimes /*
41afa88623SPeter Wemm  * AMD64 Segmentation Data Structures and definitions
425b81b6b3SRodney W. Grimes  */
435b81b6b3SRodney W. Grimes 
44bcde3b9fSTijl Coosemans #include <x86/segments.h>
458923c96eSRui Paulo 
465b81b6b3SRodney W. Grimes /*
47afa88623SPeter Wemm  * System segment descriptors (128 bit wide)
48afa88623SPeter Wemm  */
49afa88623SPeter Wemm struct	system_segment_descriptor {
50afa88623SPeter Wemm 	u_int64_t sd_lolimit:16;	/* segment extent (lsb) */
51afa88623SPeter Wemm 	u_int64_t sd_lobase:24;		/* segment base address (lsb) */
52afa88623SPeter Wemm 	u_int64_t sd_type:5;		/* segment type */
53afa88623SPeter Wemm 	u_int64_t sd_dpl:2;		/* segment descriptor priority level */
54afa88623SPeter Wemm 	u_int64_t sd_p:1;		/* segment descriptor present */
55afa88623SPeter Wemm 	u_int64_t sd_hilimit:4;		/* segment extent (msb) */
56afa88623SPeter Wemm 	u_int64_t sd_xx0:3;		/* unused */
57afa88623SPeter Wemm 	u_int64_t sd_gran:1;		/* limit granularity (byte/page units)*/
58afa88623SPeter Wemm 	u_int64_t sd_hibase:40 __packed;/* segment base address  (msb) */
59afa88623SPeter Wemm 	u_int64_t sd_xx1:8;
60afa88623SPeter Wemm 	u_int64_t sd_mbz:5;		/* MUST be zero */
61afa88623SPeter Wemm 	u_int64_t sd_xx2:19;
62afa88623SPeter Wemm } __packed;
63afa88623SPeter Wemm 
64afa88623SPeter Wemm /*
655b81b6b3SRodney W. Grimes  * Software definitions are in this convenient format,
665b81b6b3SRodney W. Grimes  * which are translated into inconvenient segment descriptors
675b81b6b3SRodney W. Grimes  * when needed to be used by the 386 hardware
685b81b6b3SRodney W. Grimes  */
695b81b6b3SRodney W. Grimes 
705b81b6b3SRodney W. Grimes struct	soft_segment_descriptor {
71afa88623SPeter Wemm 	unsigned long ssd_base;		/* segment base address  */
72afa88623SPeter Wemm 	unsigned long ssd_limit;	/* segment extent */
73afa88623SPeter Wemm 	unsigned long ssd_type:5;	/* segment type */
74afa88623SPeter Wemm 	unsigned long ssd_dpl:2;	/* segment descriptor priority level */
75afa88623SPeter Wemm 	unsigned long ssd_p:1;		/* segment descriptor present */
76afa88623SPeter Wemm 	unsigned long ssd_long:1;	/* long mode (for %cs) */
77afa88623SPeter Wemm 	unsigned long ssd_def32:1;	/* default 32 vs 16 bit size */
78afa88623SPeter Wemm 	unsigned long ssd_gran:1;	/* limit granularity (byte/page units)*/
79afa88623SPeter Wemm } __packed;
805b81b6b3SRodney W. Grimes 
815b81b6b3SRodney W. Grimes /*
825b81b6b3SRodney W. Grimes  * region descriptors, used to load gdt/idt tables before segments yet exist.
835b81b6b3SRodney W. Grimes  */
845b81b6b3SRodney W. Grimes struct region_descriptor {
85*291bfc8dSKonstantin Belousov 	uint64_t rd_limit:16;		/* segment extent */
86*291bfc8dSKonstantin Belousov 	uint64_t rd_base:64 __packed;	/* base address  */
87afa88623SPeter Wemm } __packed;
885b81b6b3SRodney W. Grimes 
89664a31e4SPeter Wemm #ifdef _KERNEL
90afa88623SPeter Wemm extern struct user_segment_descriptor gdt[];
91b0d1e6deSBruce Evans extern struct soft_segment_descriptor gdt_segs[];
9250045fbcSBruce Evans extern struct gate_descriptor *idt;
930d2a2989SPeter Wemm extern struct region_descriptor r_gdt, r_idt;
94da59a31cSDavid Greenman 
95b63dc6adSAlfred Perlstein void	lgdt(struct region_descriptor *rdp);
96afa88623SPeter Wemm void	sdtossd(struct user_segment_descriptor *sdp,
97b63dc6adSAlfred Perlstein 	    struct soft_segment_descriptor *ssdp);
98b63dc6adSAlfred Perlstein void	ssdtosd(struct soft_segment_descriptor *ssdp,
99afa88623SPeter Wemm 	    struct user_segment_descriptor *sdp);
100afa88623SPeter Wemm void	ssdtosyssd(struct soft_segment_descriptor *ssdp,
101afa88623SPeter Wemm 	    struct system_segment_descriptor *sdp);
1022c66cccaSKonstantin Belousov void	update_gdt_gsbase(struct thread *td, uint32_t base);
1032c66cccaSKonstantin Belousov void	update_gdt_fsbase(struct thread *td, uint32_t base);
104664a31e4SPeter Wemm #endif /* _KERNEL */
105040f1000SBruce Evans 
106040f1000SBruce Evans #endif /* !_MACHINE_SEGMENTS_H_ */
107