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