xref: /freebsd/lib/libthr/arch/i386/include/pthread_md.h (revision 5670b8cc3672d5a6bc2c41eb48d7d01343c43ad0)
1a091d823SDavid Xu /*-
24d846d26SWarner Losh  * SPDX-License-Identifier: BSD-2-Clause
35e53a4f9SPedro F. Giffuni  *
4a091d823SDavid Xu  * Copyright (c) 2002 Daniel Eischen <deischen@freebsd.org>.
5a091d823SDavid Xu  * Copyright (c) 2005 David Xu <davidxu@freebsd.org>.
6a091d823SDavid Xu  * All rights reserved.
7a091d823SDavid Xu  *
8a091d823SDavid Xu  * Redistribution and use in source and binary forms, with or without
9a091d823SDavid Xu  * modification, are permitted provided that the following conditions
10a091d823SDavid Xu  * are met:
11a091d823SDavid Xu  * 1. Redistributions of source code must retain the above copyright
12a091d823SDavid Xu  *    notice, this list of conditions and the following disclaimer.
13a091d823SDavid Xu  * 2. Redistributions in binary form must reproduce the above copyright
14a091d823SDavid Xu  *    notice, this list of conditions and the following disclaimer in the
15a091d823SDavid Xu  *    documentation and/or other materials provided with the distribution.
16a091d823SDavid Xu  *
17a091d823SDavid Xu  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
18a091d823SDavid Xu  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19a091d823SDavid Xu  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20a091d823SDavid Xu  * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
21a091d823SDavid Xu  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
22a091d823SDavid Xu  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
23a091d823SDavid Xu  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
24a091d823SDavid Xu  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
25a091d823SDavid Xu  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
26a091d823SDavid Xu  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
27a091d823SDavid Xu  * SUCH DAMAGE.
28a091d823SDavid Xu  */
29a091d823SDavid Xu 
30a091d823SDavid Xu /*
31a091d823SDavid Xu  * Machine-dependent thread prototypes/definitions.
32a091d823SDavid Xu  */
33a091d823SDavid Xu #ifndef _PTHREAD_MD_H_
34a091d823SDavid Xu #define	_PTHREAD_MD_H_
35a091d823SDavid Xu 
36a091d823SDavid Xu #include <stddef.h>
37a091d823SDavid Xu #include <sys/types.h>
3875395023SJohn Baldwin #include <machine/tls.h>
39a091d823SDavid Xu 
40d99f6dacSDavid Xu #define	CPU_SPINWAIT		__asm __volatile("pause")
41d99f6dacSDavid Xu 
42c7904405SAndrew Turner /* For use in _Static_assert to check structs will fit in a page */
43c7904405SAndrew Turner #define	THR_PAGE_SIZE_MIN	PAGE_SIZE
44c7904405SAndrew Turner 
45a091d823SDavid Xu static __inline struct pthread *
46a091d823SDavid Xu _get_curthread(void)
47a091d823SDavid Xu {
4875395023SJohn Baldwin 	struct pthread *thr;
4975395023SJohn Baldwin 
507b1c7703SRyan Libby 	__asm __volatile("movl %%gs:%c1, %0" : "=r" (thr)
517b1c7703SRyan Libby 	    : "i" (offsetof(struct tcb, tcb_thread)));
5275395023SJohn Baldwin 	return (thr);
53a091d823SDavid Xu }
54d6e0eb0aSDavid Xu 
55*5670b8ccSMichal Meloun static __inline void
56*5670b8ccSMichal Meloun _thr_resolve_machdep(void)
57*5670b8ccSMichal Meloun {
58*5670b8ccSMichal Meloun }
59*5670b8ccSMichal Meloun 
60a091d823SDavid Xu #endif
61