1a2a0f906SKonstantin Belousov /*-
24d846d26SWarner Losh * SPDX-License-Identifier: BSD-2-Clause
3a2a0f906SKonstantin Belousov *
4a2a0f906SKonstantin Belousov * Copyright (c) 2019 The FreeBSD Foundation
5a2a0f906SKonstantin Belousov *
6a2a0f906SKonstantin Belousov * This software was developed by Konstantin Belousov <kib@FreeBSD.org>
7a2a0f906SKonstantin Belousov * under sponsorship from the FreeBSD Foundation.
8a2a0f906SKonstantin Belousov *
9a2a0f906SKonstantin Belousov * Redistribution and use in source and binary forms, with or without
10a2a0f906SKonstantin Belousov * modification, are permitted provided that the following conditions
11a2a0f906SKonstantin Belousov * are met:
12a2a0f906SKonstantin Belousov * 1. Redistributions of source code must retain the above copyright
13a2a0f906SKonstantin Belousov * notice, this list of conditions and the following disclaimer.
14a2a0f906SKonstantin Belousov * 2. Redistributions in binary form must reproduce the above copyright
15a2a0f906SKonstantin Belousov * notice, this list of conditions and the following disclaimer in the
16a2a0f906SKonstantin Belousov * documentation and/or other materials provided with the distribution.
17a2a0f906SKonstantin Belousov *
18a2a0f906SKonstantin Belousov * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
19a2a0f906SKonstantin Belousov * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
20a2a0f906SKonstantin Belousov * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
21a2a0f906SKonstantin Belousov * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
22a2a0f906SKonstantin Belousov * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
23a2a0f906SKonstantin Belousov * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
24a2a0f906SKonstantin Belousov * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
25a2a0f906SKonstantin Belousov * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
26a2a0f906SKonstantin Belousov * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
27a2a0f906SKonstantin Belousov * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
28a2a0f906SKonstantin Belousov * SUCH DAMAGE.
29a2a0f906SKonstantin Belousov */
30a2a0f906SKonstantin Belousov
319f7588ddSBrooks Davis #ifdef __i386__
329f7588ddSBrooks Davis #include <i386/pcpu_aux.h>
339f7588ddSBrooks Davis #else /* !__i386__ */
349f7588ddSBrooks Davis
35a2a0f906SKonstantin Belousov #ifndef _MACHINE_PCPU_AUX_H_
36a2a0f906SKonstantin Belousov #define _MACHINE_PCPU_AUX_H_
37a2a0f906SKonstantin Belousov
38a2a0f906SKonstantin Belousov #ifndef _KERNEL
39a2a0f906SKonstantin Belousov #error "Not for userspace"
40a2a0f906SKonstantin Belousov #endif
41a2a0f906SKonstantin Belousov
42a2a0f906SKonstantin Belousov #ifndef _SYS_PCPU_H_
43a2a0f906SKonstantin Belousov #error "Do not include machine/pcpu_aux.h directly"
44a2a0f906SKonstantin Belousov #endif
45a2a0f906SKonstantin Belousov
46a2a0f906SKonstantin Belousov /* Required for counters(9) to work on x86. */
47a2a0f906SKonstantin Belousov _Static_assert(sizeof(struct pcpu) == UMA_PCPU_ALLOC_SIZE, "fix pcpu size");
48a2a0f906SKonstantin Belousov
49a2a0f906SKonstantin Belousov extern struct pcpu *__pcpu;
50a2a0f906SKonstantin Belousov extern struct pcpu temp_bsp_pcpu;
51a2a0f906SKonstantin Belousov
52a2a0f906SKonstantin Belousov static __inline __pure2 struct thread *
__curthread(void)53a2a0f906SKonstantin Belousov __curthread(void)
54a2a0f906SKonstantin Belousov {
55a2a0f906SKonstantin Belousov struct thread *td;
56a2a0f906SKonstantin Belousov
57*2730f429SRyan Libby __asm("movq %%gs:%c1,%0" : "=r" (td)
58*2730f429SRyan Libby : "i" (offsetof(struct pcpu, pc_curthread)));
59a2a0f906SKonstantin Belousov return (td);
60a2a0f906SKonstantin Belousov }
61a2a0f906SKonstantin Belousov #define curthread (__curthread())
625e921ff4SKonstantin Belousov #define curpcb (&curthread->td_md.md_pcb)
63a2a0f906SKonstantin Belousov
64a2a0f906SKonstantin Belousov #endif /* _MACHINE_PCPU_AUX_H_ */
659f7588ddSBrooks Davis
669f7588ddSBrooks Davis #endif /* __i386__ */
67