1 /*-
2 * SPDX-License-Identifier: BSD-2-Clause-FreeBSD
3 *
4 * Copyright (c) 2003 Jake Burkholder <jake@freebsd.org>.
5 * Copyright (c) 2003 Marcel Moolenaar
6 * All rights reserved.
7 *
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
10 * are met:
11 *
12 * 1. Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer.
14 * 2. Redistributions in binary form must reproduce the above copyright
15 * notice, this list of conditions and the following disclaimer in the
16 * documentation and/or other materials provided with the distribution.
17 *
18 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
19 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
20 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
21 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
22 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
23 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
24 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
25 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
26 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
27 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28 *
29 * $FreeBSD: stable/12/lib/libthr/arch/sparc64/include/pthread_md.h 326219 2017-11-26 02:00:33Z pfg $
30 */
31
32 /*
33 * Machine-dependent thread prototypes/definitions.
34 */
35 #ifndef _PTHREAD_MD_H_
36 #define _PTHREAD_MD_H_
37
38 #include <stddef.h>
39
40 #define CPU_SPINWAIT
41
42 #define DTV_OFFSET offsetof(struct tcb, tcb_dtv)
43
44 /*
45 * Variant II tcb, first two members are required by rtld.
46 * %g7 points to the structure.
47 */
48 struct tcb {
49 struct tcb *tcb_self; /* required by rtld */
50 void *tcb_dtv; /* required by rtld */
51 struct pthread *tcb_thread; /* our hook */
52 void *tcb_spare[1];
53 };
54
55 /* Called from the thread to set its private data. */
56 static __inline void
_tcb_set(struct tcb * tcb)57 _tcb_set(struct tcb *tcb)
58 {
59
60 __asm __volatile("mov %0, %%g7" : : "r" (tcb));
61 }
62
63 static __inline struct tcb *
_tcb_get(void)64 _tcb_get(void)
65 {
66 register struct tcb *tp __asm("%g7");
67
68 return (tp);
69 }
70
71 static __inline struct pthread *
_get_curthread(void)72 _get_curthread(void)
73 {
74
75 return (_tcb_get()->tcb_thread);
76 }
77
78 #define HAS__UMTX_OP_ERR 1
79
80 #endif /* _PTHREAD_MD_H_ */
81