| 1 | /*	$OpenBSD: tcb.h,v 1.7 2017/04/20 10:03:40 kettenis 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/reg.h> |
| 25 | |
| 26 | /* |
| 27 | * In userspace, register %g7 contains the address of the thread's TCB |
| 28 | */ |
| 29 | #define TCB_GET(p)		\ |
| 30 | 	((void *)(p)->p_md.md_tf->tf_global[7]) |
| 31 | #define TCB_SET(p, addr)	\ |
| 32 | 	((p)->p_md.md_tf->tf_global[7] = (int64_t)(addr)) |
| 33 | |
| 34 | #else /* _KERNEL */ |
| 35 | |
| 36 | /* ELF TLS ABI calls for big TCB, with static TLS data at negative offsets */ |
| 37 | #define TLS_VARIANT	2 |
| 38 | |
| 39 | register void *__tcb __asm__ ("g7"); |
| 40 | #define TCB_GET()		(__tcb) |
| 41 | #define TCB_SET(tcb)		((__tcb) = (tcb)) |
| 42 | |
| 43 | #endif /* _KERNEL */ |
| 44 | #endif /* _MACHINE_TCB_H_ */ |