xref: /openbsd-src/sys/arch/amd64/include/cpu_full.h (revision d9ff679e897778e4bbfb04d7040d7d7d06b28db0)
1*d9ff679eSguenther /*	$OpenBSD: cpu_full.h,v 1.5 2019/05/17 19:07:47 guenther Exp $	*/
2b767b017Sguenther /*
3*d9ff679eSguenther  * Copyright (c) 2018 Philip Guenther <guenther@openbsd.org>
4b767b017Sguenther  *
5b767b017Sguenther  * Permission to use, copy, modify, and distribute this software for any
6b767b017Sguenther  * purpose with or without fee is hereby granted, provided that the above
7b767b017Sguenther  * copyright notice and this permission notice appear in all copies.
8b767b017Sguenther  *
9b767b017Sguenther  * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
10b767b017Sguenther  * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
11b767b017Sguenther  * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
12b767b017Sguenther  * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
13b767b017Sguenther  * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
14b767b017Sguenther  * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
15b767b017Sguenther  * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
16b767b017Sguenther  */
17b767b017Sguenther 
18b767b017Sguenther #ifndef _MACHINE_CPU_FULL_H_
19b767b017Sguenther #define _MACHINE_CPU_FULL_H_
20b767b017Sguenther 
21b767b017Sguenther #include <sys/param.h>			/* offsetof, PAGE_SIZE */
22b767b017Sguenther #include <machine/segments.h>
23b767b017Sguenther #include <machine/tss.h>
24b767b017Sguenther 
25b767b017Sguenther /*
26b767b017Sguenther  * The layout of the full per-CPU information, including TSS, GDT,
27b767b017Sguenther  * trampoline stacks, and cpu_info described in <machine/cpu.h>
28b767b017Sguenther  */
29b767b017Sguenther struct cpu_info_full {
30b767b017Sguenther 	/* page mapped kRO in u-k */
31b767b017Sguenther 	union {
328a7a62cbSguenther 		struct {
338a7a62cbSguenther 			struct x86_64_tss	uu_tss;
348a7a62cbSguenther 			uint64_t		uu_gdt[GDT_SIZE / 8];
358a7a62cbSguenther 		} u_tssgdt;
36b767b017Sguenther 		char			u_align[PAGE_SIZE];
37b767b017Sguenther 	} cif_RO;
388a7a62cbSguenther #define cif_tss	cif_RO.u_tssgdt.uu_tss
398a7a62cbSguenther #define cif_gdt	cif_RO.u_tssgdt.uu_gdt
40b767b017Sguenther 
41b767b017Sguenther 	/* start of page mapped kRW in u-k */
42b767b017Sguenther 	uint64_t cif_tramp_stack[(PAGE_SIZE / 4
43b767b017Sguenther 		- offsetof(struct cpu_info, ci_PAGEALIGN)) / sizeof(uint64_t)];
44b767b017Sguenther 	uint64_t cif_dblflt_stack[(PAGE_SIZE / 4) / sizeof(uint64_t)];
45b767b017Sguenther 	uint64_t cif_nmi_stack[(2 * PAGE_SIZE / 4) / sizeof(uint64_t)];
46b767b017Sguenther 
47b767b017Sguenther 	/*
48b767b017Sguenther 	 * Beginning of this hangs over into the kRW page; rest is
49b767b017Sguenther 	 * unmapped in u-k
50b767b017Sguenther 	 */
51b767b017Sguenther 	struct cpu_info cif_cpu;
52b767b017Sguenther } __aligned(PAGE_SIZE);
53b767b017Sguenther 
54b767b017Sguenther /* tss, align shim, and gdt must fit in a page */
55b767b017Sguenther CTASSERT(_ALIGN(sizeof(struct x86_64_tss)) +
56b767b017Sguenther 	 sizeof(struct mem_segment_descriptor) * (NGDT_MEM + 2*NGDT_SYS)
57b767b017Sguenther 	 < PAGE_SIZE);
58b767b017Sguenther 
59b767b017Sguenther /* verify expected alignment */
60b767b017Sguenther CTASSERT(offsetof(struct cpu_info_full, cif_cpu.ci_PAGEALIGN) % PAGE_SIZE == 0);
61b767b017Sguenther 
62b767b017Sguenther /* verify total size is multiple of page size */
63b767b017Sguenther CTASSERT(sizeof(struct cpu_info_full) % PAGE_SIZE == 0);
64b767b017Sguenther 
65b767b017Sguenther extern struct cpu_info_full cpu_info_full_primary;
66b767b017Sguenther 
67b767b017Sguenther /* Now make sure the cpu_info_primary macro is correct */
68e6ef12fbSbluhm CTASSERT(&cpu_info_primary - &cpu_info_full_primary.cif_cpu == 0);
69b767b017Sguenther 
70b767b017Sguenther #endif /* _MACHINE_CPU_FULL_H_ */
71