xref: /openbsd-src/sys/arch/i386/include/tcb.h (revision 96b8842b622f9505c1b9cc4ddf5b9b4045994781)
1*96b8842bSguenther /*	$OpenBSD: tcb.h,v 1.4 2016/09/04 08:49:35 guenther Exp $	*/
2bcdf0115Sguenther /*
3bcdf0115Sguenther  * Copyright (c) 2011 Philip Guenther <guenther@openbsd.org>
4bcdf0115Sguenther  *
5bcdf0115Sguenther  * Permission to use, copy, modify, and distribute this software for any
6bcdf0115Sguenther  * purpose with or without fee is hereby granted, provided that the above
7bcdf0115Sguenther  * copyright notice and this permission notice appear in all copies.
8bcdf0115Sguenther  *
9bcdf0115Sguenther  * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
10bcdf0115Sguenther  * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
11bcdf0115Sguenther  * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
12bcdf0115Sguenther  * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
13bcdf0115Sguenther  * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
14bcdf0115Sguenther  * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
15bcdf0115Sguenther  * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
16bcdf0115Sguenther  */
17bcdf0115Sguenther 
18bcdf0115Sguenther #ifndef _MACHINE_TCB_H_
19bcdf0115Sguenther #define _MACHINE_TCB_H_
20bcdf0115Sguenther 
21bcdf0115Sguenther #ifdef _KERNEL
22bcdf0115Sguenther 
23bcdf0115Sguenther #include <machine/sysarch.h>
24d19a0e5aSguenther #include <machine/pcb.h>
25bcdf0115Sguenther 
26bcdf0115Sguenther #define TCB_GET(p)		\
27cb9e9379Sguenther 	((void *)i386_get_threadbase(p, TSEG_GS))
28bcdf0115Sguenther #define TCB_SET(p, addr)	\
29bcdf0115Sguenther 	i386_set_threadbase(p, (uint32_t)(addr), TSEG_GS)
30bcdf0115Sguenther 
31bcdf0115Sguenther #else /* _KERNEL */
32bcdf0115Sguenther 
33bcdf0115Sguenther /* ELF TLS ABI calls for big TCB, with static TLS data at negative offsets */
34bcdf0115Sguenther #define TLS_VARIANT	2
35bcdf0115Sguenther 
36bcdf0115Sguenther /* Read a slot from the TCB */
37bcdf0115Sguenther static inline void *
__i386_read_tcb(int offset)38bcdf0115Sguenther __i386_read_tcb(int offset)
39bcdf0115Sguenther {
40bcdf0115Sguenther 	void	*val;
41bcdf0115Sguenther 	__asm__ ("movl %%gs:(%1),%0" : "=r" (val) : "r" (offset));
42bcdf0115Sguenther 	return val;
43bcdf0115Sguenther }
44bcdf0115Sguenther 
45bcdf0115Sguenther /* Get a pointer to the TCB itself */
46bcdf0115Sguenther #define TCB_GET()		__i386_read_tcb(0)
47bcdf0115Sguenther 
48bcdf0115Sguenther /* Setting the TCB pointer can only be done via syscall, so no TCB_SET() */
49bcdf0115Sguenther 
50bcdf0115Sguenther #endif /* _KERNEL */
51bcdf0115Sguenther #endif /* _MACHINE_TCB_H_ */
52