1 /* $OpenBSD: tcb.h,v 1.2 2011/11/09 15:35:01 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 #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 #if 0 /* XXX perhaps use the gcc global register extension? */ 35 struct thread_control_block; 36 __register__ struct thread_control_block *__tcb __asm__ ("%r2"); 37 #define TCB_GET() (__tcb) 38 #define TCB_GET_MEMBER(member) ((void *)(__tcb->member)) 39 #define TCB_SET(tcb) ((__tcb) = (tcb)) 40 41 #else 42 43 #include <stddef.h> /* for offsetof */ 44 45 /* Get a pointer to the TCB itself */ 46 static inline void * 47 __powerpc_get_tcb(void) 48 { 49 void *val; 50 __asm__ ("mr %0, %%r2" : "=r" (val)); 51 return val; 52 } 53 #define TCB_GET() __powerpc_get_tcb() 54 55 /* Get the value of a specific member in the TCB */ 56 static inline void * 57 __powerpc_read_tcb(int offset) 58 { 59 void *val; 60 __asm__ ("lwzx %0, %%r2, %1" : "=r" (val) : "r" (offset)); 61 return val; 62 } 63 #define TCB_GET_MEMBER(member) \ 64 __powerpc_read_tcb(offsetof(struct thread_control_block, member)) 65 66 #define TCB_SET(tcb) __asm __volatile("mr %%r2, %0" : : "r" (tcb)) 67 68 #endif /* 0 */ 69 70 #endif /* _KERNEL */ 71 72 #endif /* _MACHINE_TCB_H_ */ 73