1a9643ea8Slogwang /*-
2*22ce4affSfengbojiang * SPDX-License-Identifier: BSD-3-Clause
3*22ce4affSfengbojiang *
4a9643ea8Slogwang * Copyright (c) 1990 The Regents of the University of California.
5a9643ea8Slogwang * All rights reserved.
6a9643ea8Slogwang *
7a9643ea8Slogwang * This code is derived from software contributed to Berkeley by
8a9643ea8Slogwang * William Jolitz.
9a9643ea8Slogwang *
10a9643ea8Slogwang * Redistribution and use in source and binary forms, with or without
11a9643ea8Slogwang * modification, are permitted provided that the following conditions
12a9643ea8Slogwang * are met:
13a9643ea8Slogwang * 1. Redistributions of source code must retain the above copyright
14a9643ea8Slogwang * notice, this list of conditions and the following disclaimer.
15a9643ea8Slogwang * 2. Redistributions in binary form must reproduce the above copyright
16a9643ea8Slogwang * notice, this list of conditions and the following disclaimer in the
17a9643ea8Slogwang * documentation and/or other materials provided with the distribution.
18*22ce4affSfengbojiang * 3. Neither the name of the University nor the names of its contributors
19a9643ea8Slogwang * may be used to endorse or promote products derived from this software
20a9643ea8Slogwang * without specific prior written permission.
21a9643ea8Slogwang *
22a9643ea8Slogwang * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
23a9643ea8Slogwang * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
24a9643ea8Slogwang * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
25a9643ea8Slogwang * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
26a9643ea8Slogwang * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
27a9643ea8Slogwang * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
28a9643ea8Slogwang * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
29a9643ea8Slogwang * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
30a9643ea8Slogwang * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
31a9643ea8Slogwang * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
32a9643ea8Slogwang * SUCH DAMAGE.
33a9643ea8Slogwang *
34a9643ea8Slogwang * from: @(#)cpu.h 5.4 (Berkeley) 5/9/91
35a9643ea8Slogwang * $FreeBSD$
36a9643ea8Slogwang */
37a9643ea8Slogwang
38a9643ea8Slogwang #ifndef _MACHINE_CPU_H_
39a9643ea8Slogwang #define _MACHINE_CPU_H_
40a9643ea8Slogwang
41a9643ea8Slogwang /*
42a9643ea8Slogwang * Definitions unique to i386 cpu support.
43a9643ea8Slogwang */
44a9643ea8Slogwang #include <machine/psl.h>
45a9643ea8Slogwang #include <machine/frame.h>
46a9643ea8Slogwang #include <machine/segments.h>
47a9643ea8Slogwang
48a9643ea8Slogwang #define cpu_exec(p) /* nothing */
49a9643ea8Slogwang #define cpu_swapin(p) /* nothing */
50a9643ea8Slogwang #define cpu_getstack(td) ((td)->td_frame->tf_rsp)
51a9643ea8Slogwang #define cpu_setstack(td, ap) ((td)->td_frame->tf_rsp = (ap))
52a9643ea8Slogwang #define cpu_spinwait() ia32_pause()
53a9643ea8Slogwang
54a9643ea8Slogwang #define TRAPF_USERMODE(framep) \
55a9643ea8Slogwang (ISPL((framep)->tf_cs) == SEL_UPL)
56a9643ea8Slogwang #define TRAPF_PC(framep) ((framep)->tf_rip)
57a9643ea8Slogwang
58a9643ea8Slogwang #ifdef _KERNEL
59a9643ea8Slogwang /*
60a9643ea8Slogwang * Struct containing pointers to CPU management functions whose
61a9643ea8Slogwang * implementation is run time selectable. Selection can be made,
62a9643ea8Slogwang * for example, based on detection of a particular CPU variant or
63a9643ea8Slogwang * hypervisor environment.
64a9643ea8Slogwang */
65a9643ea8Slogwang struct cpu_ops {
66a9643ea8Slogwang void (*cpu_init)(void);
67a9643ea8Slogwang void (*cpu_resume)(void);
68a9643ea8Slogwang };
69a9643ea8Slogwang
70a9643ea8Slogwang extern struct cpu_ops cpu_ops;
71*22ce4affSfengbojiang extern char brwsection[];
72a9643ea8Slogwang extern char btext[];
73*22ce4affSfengbojiang extern char _end[];
74a9643ea8Slogwang extern char etext[];
75a9643ea8Slogwang
76a9643ea8Slogwang /* Resume hook for VMM. */
77a9643ea8Slogwang extern void (*vmm_resume_p)(void);
78a9643ea8Slogwang
79a9643ea8Slogwang void cpu_halt(void);
80*22ce4affSfengbojiang void cpu_lock_delay(void);
81a9643ea8Slogwang void cpu_reset(void);
82a9643ea8Slogwang void fork_trampoline(void);
83a9643ea8Slogwang void swi_vm(void *);
84a9643ea8Slogwang
85a9643ea8Slogwang /*
86a9643ea8Slogwang * Return contents of in-cpu fast counter as a sort of "bogo-time"
87a9643ea8Slogwang * for random-harvesting purposes.
88a9643ea8Slogwang */
89a9643ea8Slogwang static __inline u_int64_t
get_cyclecount(void)90a9643ea8Slogwang get_cyclecount(void)
91a9643ea8Slogwang {
92a9643ea8Slogwang
93a9643ea8Slogwang return (rdtsc());
94a9643ea8Slogwang }
95a9643ea8Slogwang
96*22ce4affSfengbojiang #define MEMSET_EARLY_FUNC memset_std
97*22ce4affSfengbojiang #define MEMCPY_EARLY_FUNC memcpy_std
98*22ce4affSfengbojiang #define MEMMOVE_EARLY_FUNC memmove_std
99*22ce4affSfengbojiang
100a9643ea8Slogwang #endif
101a9643ea8Slogwang
102a9643ea8Slogwang #endif /* !_MACHINE_CPU_H_ */
103