xref: /openbsd-src/sys/arch/i386/include/cpu_full.h (revision f5ae93cb9d508f29f3243df6d3fa1003d3ec41bf)
1*f5ae93cbSbluhm /*	$OpenBSD: cpu_full.h,v 1.3 2018/06/22 13:21:14 bluhm Exp $	*/
238d673b2Sbluhm /*
338d673b2Sbluhm  * Copyright (c) 2018 Philip Guenther <guenther@openbsd.org>
438d673b2Sbluhm  * Copyright (c) 2018 Hans-Joerg Hoexer <hshoexer@genua.de>
538d673b2Sbluhm  *
638d673b2Sbluhm  * Permission to use, copy, modify, and distribute this software for any
738d673b2Sbluhm  * purpose with or without fee is hereby granted, provided that the above
838d673b2Sbluhm  * copyright notice and this permission notice appear in all copies.
938d673b2Sbluhm  *
1038d673b2Sbluhm  * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
1138d673b2Sbluhm  * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
1238d673b2Sbluhm  * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
1338d673b2Sbluhm  * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
1438d673b2Sbluhm  * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
1538d673b2Sbluhm  * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
1638d673b2Sbluhm  * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
1738d673b2Sbluhm  */
1838d673b2Sbluhm 
1938d673b2Sbluhm #ifndef _MACHINE_CPU_FULL_H_
2038d673b2Sbluhm #define _MACHINE_CPU_FULL_H_
2138d673b2Sbluhm 
2238d673b2Sbluhm #include <sys/param.h>		/* offsetof, PAGE_SIZE */
2338d673b2Sbluhm #include <machine/segments.h>
2438d673b2Sbluhm #include <machine/tss.h>
2538d673b2Sbluhm 
2638d673b2Sbluhm struct cpu_info_full {
2738d673b2Sbluhm 	/* page mapped kRO in u-k */
2838d673b2Sbluhm 	union {
294699d0c1Sbluhm 		struct {
304699d0c1Sbluhm 			struct i386tss		uu_tss;
31*f5ae93cbSbluhm 			struct i386tss		uu_nmi_tss;
324699d0c1Sbluhm 			union descriptor	uu_gdt[NGDT];
334699d0c1Sbluhm 		} u_tssgdt;
3438d673b2Sbluhm 	char			u_align[PAGE_SIZE];
3538d673b2Sbluhm 	} cif_TSS_RO;
364699d0c1Sbluhm #define cif_tss cif_TSS_RO.u_tssgdt.uu_tss
37*f5ae93cbSbluhm #define cif_nmi_tss cif_TSS_RO.u_tssgdt.uu_nmi_tss
384699d0c1Sbluhm #define cif_gdt cif_TSS_RO.u_tssgdt.uu_gdt
3938d673b2Sbluhm 
4038d673b2Sbluhm 	/* start of page mapped kRW in u-k */
41*f5ae93cbSbluhm 	uint32_t cif_tramp_stack[(PAGE_SIZE / 4
4238d673b2Sbluhm 	    - offsetof(struct cpu_info, ci_PAGEALIGN)) / sizeof(uint32_t)];
43*f5ae93cbSbluhm 	uint32_t cif_nmi_stack[(3 * PAGE_SIZE / 4) / sizeof(uint32_t)];
4438d673b2Sbluhm 
4538d673b2Sbluhm 	/*
4638d673b2Sbluhm 	 * Beginning of this hangs over into the kRW page; rest is
4738d673b2Sbluhm 	 * unmapped in u-k
4838d673b2Sbluhm 	 */
4938d673b2Sbluhm 	struct cpu_info cif_cpu;
5038d673b2Sbluhm } __aligned(PAGE_SIZE);
5138d673b2Sbluhm 
5238d673b2Sbluhm /* tss, align shim, and gdt must fit in a page */
53*f5ae93cbSbluhm CTASSERT(_ALIGN(2 * sizeof(struct i386tss)) +
5438d673b2Sbluhm 	sizeof(struct segment_descriptor) * NGDT < PAGE_SIZE);
5538d673b2Sbluhm 
5638d673b2Sbluhm /* verify expected alignment */
5738d673b2Sbluhm CTASSERT(offsetof(struct cpu_info_full, cif_cpu.ci_PAGEALIGN) % PAGE_SIZE == 0);
5838d673b2Sbluhm 
5938d673b2Sbluhm /* verify total size is multiple of page size */
6038d673b2Sbluhm CTASSERT(sizeof(struct cpu_info_full) % PAGE_SIZE == 0);
6138d673b2Sbluhm 
6238d673b2Sbluhm extern struct cpu_info_full cpu_info_full_primary;
6338d673b2Sbluhm 
6438d673b2Sbluhm /* Now make sure the cpu_info_primary macro is correct */
6538d673b2Sbluhm CTASSERT(&cpu_info_primary - &cpu_info_full_primary.cif_cpu == 0);
6638d673b2Sbluhm 
6738d673b2Sbluhm #endif /* _MACHINE_CPU_FULL_H_ */
68