xref: /openbsd-src/sys/arch/i386/include/cpu_full.h (revision f5ae93cb9d508f29f3243df6d3fa1003d3ec41bf)
1 /*	$OpenBSD: cpu_full.h,v 1.3 2018/06/22 13:21:14 bluhm Exp $	*/
2 /*
3  * Copyright (c) 2018 Philip Guenther <guenther@openbsd.org>
4  * Copyright (c) 2018 Hans-Joerg Hoexer <hshoexer@genua.de>
5  *
6  * Permission to use, copy, modify, and distribute this software for any
7  * purpose with or without fee is hereby granted, provided that the above
8  * copyright notice and this permission notice appear in all copies.
9  *
10  * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
11  * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
12  * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
13  * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
14  * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
15  * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
16  * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
17  */
18 
19 #ifndef _MACHINE_CPU_FULL_H_
20 #define _MACHINE_CPU_FULL_H_
21 
22 #include <sys/param.h>		/* offsetof, PAGE_SIZE */
23 #include <machine/segments.h>
24 #include <machine/tss.h>
25 
26 struct cpu_info_full {
27 	/* page mapped kRO in u-k */
28 	union {
29 		struct {
30 			struct i386tss		uu_tss;
31 			struct i386tss		uu_nmi_tss;
32 			union descriptor	uu_gdt[NGDT];
33 		} u_tssgdt;
34 	char			u_align[PAGE_SIZE];
35 	} cif_TSS_RO;
36 #define cif_tss cif_TSS_RO.u_tssgdt.uu_tss
37 #define cif_nmi_tss cif_TSS_RO.u_tssgdt.uu_nmi_tss
38 #define cif_gdt cif_TSS_RO.u_tssgdt.uu_gdt
39 
40 	/* start of page mapped kRW in u-k */
41 	uint32_t cif_tramp_stack[(PAGE_SIZE / 4
42 	    - offsetof(struct cpu_info, ci_PAGEALIGN)) / sizeof(uint32_t)];
43 	uint32_t cif_nmi_stack[(3 * PAGE_SIZE / 4) / sizeof(uint32_t)];
44 
45 	/*
46 	 * Beginning of this hangs over into the kRW page; rest is
47 	 * unmapped in u-k
48 	 */
49 	struct cpu_info cif_cpu;
50 } __aligned(PAGE_SIZE);
51 
52 /* tss, align shim, and gdt must fit in a page */
53 CTASSERT(_ALIGN(2 * sizeof(struct i386tss)) +
54 	sizeof(struct segment_descriptor) * NGDT < PAGE_SIZE);
55 
56 /* verify expected alignment */
57 CTASSERT(offsetof(struct cpu_info_full, cif_cpu.ci_PAGEALIGN) % PAGE_SIZE == 0);
58 
59 /* verify total size is multiple of page size */
60 CTASSERT(sizeof(struct cpu_info_full) % PAGE_SIZE == 0);
61 
62 extern struct cpu_info_full cpu_info_full_primary;
63 
64 /* Now make sure the cpu_info_primary macro is correct */
65 CTASSERT(&cpu_info_primary - &cpu_info_full_primary.cif_cpu == 0);
66 
67 #endif /* _MACHINE_CPU_FULL_H_ */
68