xref: /openbsd/sys/arch/alpha/include/tcb.h (revision 09467b48)
1 /*	$OpenBSD: tcb.h,v 1.2 2016/05/15 23:37:42 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 #ifdef _KERNEL
23 
24 void	*tcb_get(struct proc *_p);
25 void	tcb_set(struct proc *_p, void *_newtcb);
26 
27 #define TCB_GET(p)		tcb_get(p)
28 #define TCB_SET(p, addr)	tcb_set(p, addr)
29 
30 #else /* _KERNEL */
31 
32 /* ELF TLS ABI calls for small TCB, with static TLS data after it */
33 #define TLS_VARIANT	1
34 
35 static inline void *
36 __alpha_get_tcb(void)
37 {
38 	register void *__tmp __asm__("$0");
39 
40 	__asm__ ("call_pal %1 # PAL_rdunique"
41 		: "=r" (__tmp)
42 		: "i" (0x009e /* PAL_rdunique */));
43 	return __tmp;
44 }
45 #define TCB_GET()		__alpha_get_tcb()
46 
47 static inline void
48 __alpha_set_tcb(void *__val)
49 {
50 	register void *__tmp __asm__("$16") = __val;
51 
52 	__asm__ volatile ("call_pal %1 # PAL_wrunique"
53 		: "=r" (__tmp)
54 		: "i" (0x009f /* PAL_wrunique */), "0" (__tmp));
55 }
56 #define TCB_SET(addr)		__alpha_set_tcb(addr)
57 
58 #endif /* _KERNEL */
59 
60 #endif /* _MACHINE_TCB_H_ */
61