1 /* $OpenBSD: tcb.h,v 1.4 2016/05/07 19:05:21 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 #define TCB_GET(p) \ 25 ((void *)trapframe(p)->fixreg[2]) 26 #define TCB_SET(p, addr) \ 27 (trapframe(p)->fixreg[2] = (__register_t)(addr)) 28 29 #else /* _KERNEL */ 30 31 /* ELF TLS ABI calls for small TCB, with static TLS data after it */ 32 #define TLS_VARIANT 1 33 34 /* powerpc offsets the TCB pointer 0x7000 bytes after the data */ 35 #define TCB_OFFSET 0x7000 36 37 #if 0 /* XXX perhaps use the gcc global register extension? */ 38 struct thread_control_block; 39 __register__ struct thread_control_block *__tcb __asm__ ("%r2"); 40 #define TCB_GET() (__tcb) 41 #define TCB_GET_MEMBER(member) ((void *)(__tcb->member)) 42 #define TCB_SET(tcb) ((__tcb) = (tcb)) 43 44 #else 45 46 #include <stddef.h> /* for offsetof */ 47 48 /* Get a pointer to the TCB itself */ 49 static inline void * 50 __powerpc_get_tcb(void) 51 { 52 void *val; 53 __asm__ ("mr %0, %%r2" : "=r" (val)); 54 return val; 55 } 56 #define TCB_GET() __powerpc_get_tcb() 57 58 /* Get the value of a specific member in the TCB */ 59 static inline void * 60 __powerpc_read_tcb(int offset) 61 { 62 void *val; 63 __asm__ ("lwzx %0, %%r2, %1" : "=r" (val) : "r" (offset)); 64 return val; 65 } 66 #define TCB_GET_MEMBER(member) \ 67 __powerpc_read_tcb(offsetof(struct thread_control_block, member)) 68 69 #define TCB_SET(tcb) __asm volatile("mr %%r2, %0" : : "r" (tcb)) 70 71 #endif /* 0 */ 72 73 #endif /* _KERNEL */ 74 75 #endif /* _MACHINE_TCB_H_ */ 76