1 /* $OpenBSD: tcb.h,v 1.3 2016/10/02 20:11:32 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 #include <machine/pcb.h>
25
26 static inline void
__arm_set_tcb(void * tcb)27 __arm_set_tcb(void *tcb)
28 {
29 __asm volatile("mcr p15, 0, %0, c13, c0, 3\n" : : "r" (tcb));
30 }
31
32 #define TCB_GET(p) \
33 ((struct pcb *)(p)->p_addr)->pcb_tcb
34
35 #define TCB_SET(p, addr) \
36 do { \
37 ((struct pcb *)(p)->p_addr)->pcb_tcb = (addr); \
38 __arm_set_tcb(addr); \
39 } while (0)
40
41 #else /* _KERNEL */
42
43 /* ELF TLS ABI calls for small TCB, with static TLS data after it */
44 #define TLS_VARIANT 1
45
46 static inline void *
__arm_read_tcb(void)47 __arm_read_tcb(void)
48 {
49 void *tcb;
50 __asm volatile("mrc p15, 0, %0, c13, c0, 3\n" : "=r" (tcb));
51 return tcb;
52 }
53
54 #define TCB_GET() __arm_read_tcb()
55
56 #endif /* _KERNEL */
57
58 #endif /* _MACHINE_TCB_H_ */
59