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