xref: /titanic_52/usr/src/boot/sys/amd64/include/segments.h (revision 8ede96251e3dca657102f3a32187d4382bda2ba4)
1*8ede9625SToomas Soome /*-
2*8ede9625SToomas Soome  * Copyright (c) 1989, 1990 William F. Jolitz
3*8ede9625SToomas Soome  * Copyright (c) 1990 The Regents of the University of California.
4*8ede9625SToomas Soome  * All rights reserved.
5*8ede9625SToomas Soome  *
6*8ede9625SToomas Soome  * This code is derived from software contributed to Berkeley by
7*8ede9625SToomas Soome  * William Jolitz.
8*8ede9625SToomas Soome  *
9*8ede9625SToomas Soome  * Redistribution and use in source and binary forms, with or without
10*8ede9625SToomas Soome  * modification, are permitted provided that the following conditions
11*8ede9625SToomas Soome  * are met:
12*8ede9625SToomas Soome  * 1. Redistributions of source code must retain the above copyright
13*8ede9625SToomas Soome  *    notice, this list of conditions and the following disclaimer.
14*8ede9625SToomas Soome  * 2. Redistributions in binary form must reproduce the above copyright
15*8ede9625SToomas Soome  *    notice, this list of conditions and the following disclaimer in the
16*8ede9625SToomas Soome  *    documentation and/or other materials provided with the distribution.
17*8ede9625SToomas Soome  * 3. Neither the name of the University nor the names of its contributors
18*8ede9625SToomas Soome  *    may be used to endorse or promote products derived from this software
19*8ede9625SToomas Soome  *    without specific prior written permission.
20*8ede9625SToomas Soome  *
21*8ede9625SToomas Soome  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
22*8ede9625SToomas Soome  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23*8ede9625SToomas Soome  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
24*8ede9625SToomas Soome  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
25*8ede9625SToomas Soome  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
26*8ede9625SToomas Soome  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
27*8ede9625SToomas Soome  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
28*8ede9625SToomas Soome  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
29*8ede9625SToomas Soome  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
30*8ede9625SToomas Soome  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
31*8ede9625SToomas Soome  * SUCH DAMAGE.
32*8ede9625SToomas Soome  *
33*8ede9625SToomas Soome  *	from: @(#)segments.h	7.1 (Berkeley) 5/9/91
34*8ede9625SToomas Soome  */
35*8ede9625SToomas Soome 
36*8ede9625SToomas Soome #ifndef _MACHINE_SEGMENTS_H_
37*8ede9625SToomas Soome #define	_MACHINE_SEGMENTS_H_
38*8ede9625SToomas Soome 
39*8ede9625SToomas Soome /*
40*8ede9625SToomas Soome  * AMD64 Segmentation Data Structures and definitions
41*8ede9625SToomas Soome  */
42*8ede9625SToomas Soome 
43*8ede9625SToomas Soome #include <x86/segments.h>
44*8ede9625SToomas Soome 
45*8ede9625SToomas Soome /*
46*8ede9625SToomas Soome  * System segment descriptors (128 bit wide)
47*8ede9625SToomas Soome  */
48*8ede9625SToomas Soome struct	system_segment_descriptor {
49*8ede9625SToomas Soome 	u_int64_t sd_lolimit:16;	/* segment extent (lsb) */
50*8ede9625SToomas Soome 	u_int64_t sd_lobase:24;		/* segment base address (lsb) */
51*8ede9625SToomas Soome 	u_int64_t sd_type:5;		/* segment type */
52*8ede9625SToomas Soome 	u_int64_t sd_dpl:2;		/* segment descriptor priority level */
53*8ede9625SToomas Soome 	u_int64_t sd_p:1;		/* segment descriptor present */
54*8ede9625SToomas Soome 	u_int64_t sd_hilimit:4;		/* segment extent (msb) */
55*8ede9625SToomas Soome 	u_int64_t sd_xx0:3;		/* unused */
56*8ede9625SToomas Soome 	u_int64_t sd_gran:1;		/* limit granularity (byte/page units)*/
57*8ede9625SToomas Soome 	u_int64_t sd_hibase:40 __packed;/* segment base address  (msb) */
58*8ede9625SToomas Soome 	u_int64_t sd_xx1:8;
59*8ede9625SToomas Soome 	u_int64_t sd_mbz:5;		/* MUST be zero */
60*8ede9625SToomas Soome 	u_int64_t sd_xx2:19;
61*8ede9625SToomas Soome } __packed;
62*8ede9625SToomas Soome 
63*8ede9625SToomas Soome /*
64*8ede9625SToomas Soome  * Software definitions are in this convenient format,
65*8ede9625SToomas Soome  * which are translated into inconvenient segment descriptors
66*8ede9625SToomas Soome  * when needed to be used by the 386 hardware
67*8ede9625SToomas Soome  */
68*8ede9625SToomas Soome 
69*8ede9625SToomas Soome struct	soft_segment_descriptor {
70*8ede9625SToomas Soome 	unsigned long ssd_base;		/* segment base address  */
71*8ede9625SToomas Soome 	unsigned long ssd_limit;	/* segment extent */
72*8ede9625SToomas Soome 	unsigned long ssd_type:5;	/* segment type */
73*8ede9625SToomas Soome 	unsigned long ssd_dpl:2;	/* segment descriptor priority level */
74*8ede9625SToomas Soome 	unsigned long ssd_p:1;		/* segment descriptor present */
75*8ede9625SToomas Soome 	unsigned long ssd_long:1;	/* long mode (for %cs) */
76*8ede9625SToomas Soome 	unsigned long ssd_def32:1;	/* default 32 vs 16 bit size */
77*8ede9625SToomas Soome 	unsigned long ssd_gran:1;	/* limit granularity (byte/page units)*/
78*8ede9625SToomas Soome } __packed;
79*8ede9625SToomas Soome 
80*8ede9625SToomas Soome /*
81*8ede9625SToomas Soome  * region descriptors, used to load gdt/idt tables before segments yet exist.
82*8ede9625SToomas Soome  */
83*8ede9625SToomas Soome struct region_descriptor {
84*8ede9625SToomas Soome 	uint64_t rd_limit:16;		/* segment extent */
85*8ede9625SToomas Soome 	uint64_t rd_base:64 __packed;	/* base address  */
86*8ede9625SToomas Soome } __packed;
87*8ede9625SToomas Soome 
88*8ede9625SToomas Soome #ifdef _KERNEL
89*8ede9625SToomas Soome extern struct user_segment_descriptor gdt[];
90*8ede9625SToomas Soome extern struct soft_segment_descriptor gdt_segs[];
91*8ede9625SToomas Soome extern struct gate_descriptor *idt;
92*8ede9625SToomas Soome extern struct region_descriptor r_gdt, r_idt;
93*8ede9625SToomas Soome 
94*8ede9625SToomas Soome void	lgdt(struct region_descriptor *rdp);
95*8ede9625SToomas Soome void	sdtossd(struct user_segment_descriptor *sdp,
96*8ede9625SToomas Soome 	    struct soft_segment_descriptor *ssdp);
97*8ede9625SToomas Soome void	ssdtosd(struct soft_segment_descriptor *ssdp,
98*8ede9625SToomas Soome 	    struct user_segment_descriptor *sdp);
99*8ede9625SToomas Soome void	ssdtosyssd(struct soft_segment_descriptor *ssdp,
100*8ede9625SToomas Soome 	    struct system_segment_descriptor *sdp);
101*8ede9625SToomas Soome void	update_gdt_gsbase(struct thread *td, uint32_t base);
102*8ede9625SToomas Soome void	update_gdt_fsbase(struct thread *td, uint32_t base);
103*8ede9625SToomas Soome #endif /* _KERNEL */
104*8ede9625SToomas Soome 
105*8ede9625SToomas Soome #endif /* !_MACHINE_SEGMENTS_H_ */
106