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