xref: /openbsd/sys/arch/m88k/include/tcb.h (revision d74b3acf)
1 /*	$OpenBSD: tcb.h,v 1.6 2019/12/11 07:21:40 guenther Exp $	*/
2 
3 /*
4  * Copyright (c) 2011 Philip Guenther <guenther@openbsd.org>
5  *
6  * Permission to use, copy, modify, and distribute this software for any
7  * purpose with or without fee is hereby granted, provided that the above
8  * copyright notice and this permission notice appear in all copies.
9  *
10  * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
11  * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
12  * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
13  * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
14  * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
15  * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
16  * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
17  */
18 
19 #ifndef _MACHINE_TCB_H_
20 #define _MACHINE_TCB_H_
21 
22 /*
23  * In userspace, register %r27 contains the address of the thread's TCB.
24  * It is the responsibility of the kernel to set %r27 to the proper value
25  * when creating the thread.
26  */
27 
28 #ifdef _KERNEL
29 
30 #include <machine/reg.h>
31 
32 #define TCB_GET(p)		\
33 	((void *)(p)->p_md.md_tf->tf_r[27])
34 #define TCB_SET(p, addr)	\
35 	((p)->p_md.md_tf->tf_r[27] = (register_t)(addr))
36 
37 #else /* _KERNEL */
38 
39 /*
40  * It is unknown whether the m88k ELF ABI mentions TLS. On m88k, since only
41  * unsigned offsets in (register + immediate offset) addressing is supported
42  * on all processors, it makes sense to use a small TCB, with static TLS data
43  * after it.
44  */
45 #define TLS_VARIANT	1
46 
47 #if defined(__GNUC__) && __GNUC__ >= 4
48 
49 register void *__tcb __asm__ ("%r27");
50 #define	TCB_GET()	(__tcb)
51 #define	TCB_SET(tcb)	((__tcb) = (tcb))
52 
53 #else /* __GNUC__ >= 4 */
54 
55 /* Get a pointer to the TCB itself */
56 static inline void *
__m88k_get_tcb(void)57 __m88k_get_tcb(void)
58 {
59 	void *val;
60 	__asm__ ("or %0,%%r27,%%r0" : "=r" (val));
61 	return val;
62 }
63 
64 #define TCB_GET()	__m88k_get_tcb()
65 #define TCB_SET(tcb)	__asm volatile("or %%r27,%0,%r0" : : "r" (tcb))
66 
67 #endif /* __GNUC__ >= 4 */
68 
69 #endif /* _KERNEL */
70 #endif /* _MACHINE_TCB_H_ */
71