summaryrefslogtreecommitdiff
path: root/sys/arch/i386/include/cpu_full.h
blob: da2dee89e729049737c401a97428447c521b38ab (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
/*	$OpenBSD: cpu_full.h,v 1.2 2018/05/28 20:52:44 bluhm Exp $	*/
/*
 * Copyright (c) 2018 Philip Guenther <guenther@openbsd.org>
 * Copyright (c) 2018 Hans-Joerg Hoexer <hshoexer@genua.de>
 *
 * Permission to use, copy, modify, and distribute this software for any
 * purpose with or without fee is hereby granted, provided that the above
 * copyright notice and this permission notice appear in all copies.
 *
 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
 */

#ifndef _MACHINE_CPU_FULL_H_
#define _MACHINE_CPU_FULL_H_

#include <sys/param.h>		/* offsetof, PAGE_SIZE */
#include <machine/segments.h>
#include <machine/tss.h>

struct cpu_info_full {
	/* page mapped kRO in u-k */
	union {
		struct {
			struct i386tss		uu_tss;
			union descriptor	uu_gdt[NGDT];
		} u_tssgdt;
	char			u_align[PAGE_SIZE];
	} cif_TSS_RO;
#define cif_tss cif_TSS_RO.u_tssgdt.uu_tss
#define cif_gdt cif_TSS_RO.u_tssgdt.uu_gdt

	/* start of page mapped kRW in u-k */
	uint32_t cif_tramp_stack[(PAGE_SIZE
	    - offsetof(struct cpu_info, ci_PAGEALIGN)) / sizeof(uint32_t)];

	/*
	 * Beginning of this hangs over into the kRW page; rest is
	 * unmapped in u-k
	 */
	struct cpu_info cif_cpu;
} __aligned(PAGE_SIZE);

/* tss, align shim, and gdt must fit in a page */
CTASSERT(_ALIGN(sizeof(struct i386tss)) +
	sizeof(struct segment_descriptor) * NGDT < PAGE_SIZE);

/* verify expected alignment */
CTASSERT(offsetof(struct cpu_info_full, cif_cpu.ci_PAGEALIGN) % PAGE_SIZE == 0);

/* verify total size is multiple of page size */
CTASSERT(sizeof(struct cpu_info_full) % PAGE_SIZE == 0);

extern struct cpu_info_full cpu_info_full_primary;

/* Now make sure the cpu_info_primary macro is correct */
CTASSERT(&cpu_info_primary - &cpu_info_full_primary.cif_cpu == 0);

#endif /* _MACHINE_CPU_FULL_H_ */