xref: /illumos-gate/usr/src/uts/i86pc/boot/boot_gdt.s (revision 075343cb)
1/*
2 * CDDL HEADER START
3 *
4 * The contents of this file are subject to the terms of the
5 * Common Development and Distribution License (the "License").
6 * You may not use this file except in compliance with the License.
7 *
8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9 * or http://www.opensolaris.org/os/licensing.
10 * See the License for the specific language governing permissions
11 * and limitations under the License.
12 *
13 * When distributing Covered Code, include this CDDL HEADER in each
14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15 * If applicable, add the following below this CDDL HEADER, with the
16 * fields enclosed by brackets "[]" replaced with your own identifying
17 * information: Portions Copyright [yyyy] [name of copyright owner]
18 *
19 * CDDL HEADER END
20 */
21
22/*
23 * Copyright 2010 Sun Microsystems, Inc.  All rights reserved.
24 * Use is subject to license terms.
25 *
26 * Copyright 2020 Joyent, Inc.
27 * Copyright 2022 Oxide Computer Company
28 */
29
30
31/*
32 * The boot GDT must remain in sync with the entries in intel/sys/segments.h; in
33 * particular kmdb uses B64CODE_SEL or B32CODE_SEL in perpetuity for its IDT
34 * entries (they're copied to the kernel's GDT in init_idt()).
35 *
36 * The GDT is effectively an array of user_desc_t entries.
37 */
38
39	.align 16
40	.data
41
42global_descriptor_table:
43	.long   0
44	.long   0
45
46	/* GDT_B32DATA: 32 bit flat data descriptor */
47	.value  0xFFFF	/* segment limit 0..15 */
48	.value  0x0000	/* segment base 0..15 */
49	.byte   0x0	/* segment base 16..23 */
50	.byte   0x92	/* P = 1, read/write data */
51	.byte   0xCF	/* G=1, B=1, Limit (16..19)=1111 */
52	.byte   0x0	/* segment base 24..32 */
53
54	/* GDT_B32CODE 32 bit flat code descriptor */
55	.value  0xFFFF	/* segment limit 0..15 */
56	.value  0x0000	/* segment base 0..15 */
57	.byte   0x0	/* segment base 16..23 */
58	.byte   0x9A	/* P=1, code, exec, readable */
59	.byte   0xCF	/* G=1, D=1, Limit (16..19)=1111 */
60	.byte   0x0	/* segment base 24..32 */
61
62	/*
63	 * GDT_B16CODE 16 bit code descriptor for doing BIOS calls
64	 */
65	.value  0xFFFF	/* segment limit 0..15 */
66	.value  0x0000	/* segment base 0..15 */
67	.byte   0x0	/* segment base 16..23 */
68	.byte   0x9A	/* P=1, code, exec, readable */
69	.byte   0x0F	/* G=0, D=0, Limit (16..19)=1111 */
70	.byte   0x0	/* segment base 24..32 */
71
72	/*
73	 * GDT_B16DATA 16 bit data descriptor for doing BIOS calls
74	 * XXX: Note that this sets the B flag, which is not supposed to be
75	 * set for a 16-bit data segment that is not expand-down (Intel SDM
76	 * vol 3A sec 3.4.5).  AMD does not seem to care (AMD APM vol 2 sec
77	 * 2.7.4).  It is likely this is here for use with stack segments,
78	 * where it effects 32-bit operations.  Conceivably, we could be more
79	 * conservative and specify a 16-bit stack segment, but leave it for
80	 * now.
81	 */
82	.value  0xFFFF	/* segment limit 0..15 */
83	.value  0x0000	/* segment base 0..15 */
84	.byte   0x0	/* segment base 16..23 */
85	.byte   0x92	/* P = 1, read/write data */
86	.byte   0x4F	/* G=0, B=1, Limit (16..19)=1111 */
87	.byte   0x0	/* segment base 24..32 */
88
89	/* GDT_B64CODE: 64 bit flat code descriptor - only L bit has meaning */
90	.value  0xFFFF	/* segment limit 0..15 */
91	.value  0x0000	/* segment base 0..15 */
92	.byte   0x0	/* segment base 16..23 */
93	.byte   0x9A	/* P=1, code, exec, readable */
94	.byte   0xAF	/* G=1, D=0, L=1, Limit (16..19)=1111 */
95	.byte   0x0	/* segment base 24..32 */
96
97	/*
98	 * unused
99	 */
100	.long	0
101	.long	0
102
103        /*
104         * GDT_BGSTMP -- an entry for kmdb to use during boot
105         * the fast reboot code uses this entry for memory copies, too.
106         */
107	.value  0x0001	/* segment limit 0..15 */
108
109	.globl fake_cpu_gdt_base_0_15
110fake_cpu_gdt_base_0_15:
111
112	.value  0x0000	/* segment base 0..15 */
113
114	.globl fake_cpu_gdt_base_16_23
115fake_cpu_gdt_base_16_23:
116	.byte   0x0	/* segment base 16..23 */
117	.byte   0x9A	/* P=1, code, exec, readable */
118	.byte   0xC0	/* G=1, D=1, Limit (16..19)=0000 */
119
120	.globl fake_cpu_gdt_base_24_31
121fake_cpu_gdt_base_24_31:
122	.byte   0x0	/* segment base 24..32 */
123
124/	.long	0
125/	.long	0
126
127
128/*
129 * This is a desctbr_t.
130 */
131gdt_info:
132	.value	gdt_info - global_descriptor_table - 1
133	.long	global_descriptor_table
134	.long   0		/* needed for 64 bit */
135
136fake_cpu:
137	.4byte 0
138	.4byte 0
139	.4byte 0
140	.globl fake_cpu_ptr
141fake_cpu_ptr:
142	.4byte 0
143	.skip 0x6c0, 0
144
145