1a091d823SDavid Xu /*- 2a091d823SDavid Xu * Copyright (c) 2005 David Xu <davidxu@freebsd.org>. 3a091d823SDavid Xu * All rights reserved. 4a091d823SDavid Xu * 5a091d823SDavid Xu * Redistribution and use in source and binary forms, with or without 6a091d823SDavid Xu * modification, are permitted provided that the following conditions 7a091d823SDavid Xu * are met: 8a091d823SDavid Xu * 9a091d823SDavid Xu * 1. Redistributions of source code must retain the above copyright 10a091d823SDavid Xu * notice, this list of conditions and the following disclaimer. 11a091d823SDavid Xu * 2. Redistributions in binary form must reproduce the above copyright 12a091d823SDavid Xu * notice, this list of conditions and the following disclaimer in the 13a091d823SDavid Xu * documentation and/or other materials provided with the distribution. 14a091d823SDavid Xu * 15a091d823SDavid Xu * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 16a091d823SDavid Xu * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 17a091d823SDavid Xu * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 18a091d823SDavid Xu * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 19a091d823SDavid Xu * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 20a091d823SDavid Xu * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 21a091d823SDavid Xu * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 22a091d823SDavid Xu * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 23a091d823SDavid Xu * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 24a091d823SDavid Xu * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 25a091d823SDavid Xu * 26a091d823SDavid Xu * $FreeBSD$ 27a091d823SDavid Xu */ 28a091d823SDavid Xu 29a091d823SDavid Xu /* 30a091d823SDavid Xu * Machine-dependent thread prototypes/definitions. 31a091d823SDavid Xu */ 32a091d823SDavid Xu #ifndef _PTHREAD_MD_H_ 33a091d823SDavid Xu #define _PTHREAD_MD_H_ 34a091d823SDavid Xu 35a091d823SDavid Xu #include <sys/types.h> 36a091d823SDavid Xu #include <machine/sysarch.h> 37a091d823SDavid Xu #include <stddef.h> 38a091d823SDavid Xu 39d99f6dacSDavid Xu #define CPU_SPINWAIT 40a091d823SDavid Xu #define DTV_OFFSET offsetof(struct tcb, tcb_dtv) 41a091d823SDavid Xu 42a091d823SDavid Xu /* 43a091d823SDavid Xu * Variant II tcb, first two members are required by rtld. 44a091d823SDavid Xu */ 45a091d823SDavid Xu struct tcb { 46a091d823SDavid Xu struct tcb *tcb_self; /* required by rtld */ 47a091d823SDavid Xu void *tcb_dtv; /* required by rtld */ 48a091d823SDavid Xu struct pthread *tcb_thread; /* our hook */ 49a091d823SDavid Xu void *tcb_spare[1]; 50a091d823SDavid Xu }; 51a091d823SDavid Xu 52a091d823SDavid Xu /* 53a091d823SDavid Xu * The tcb constructors. 54a091d823SDavid Xu */ 55a091d823SDavid Xu struct tcb *_tcb_ctor(struct pthread *, int); 56a091d823SDavid Xu void _tcb_dtor(struct tcb *); 57a091d823SDavid Xu 58a091d823SDavid Xu /* Called from the thread to set its private data. */ 59a091d823SDavid Xu static __inline void 60a091d823SDavid Xu _tcb_set(struct tcb *tcb) 61a091d823SDavid Xu { 62a091d823SDavid Xu *((struct tcb **)ARM_TP_ADDRESS) = tcb; 63a091d823SDavid Xu } 64a091d823SDavid Xu 65a091d823SDavid Xu /* 66a091d823SDavid Xu * Get the current tcb. 67a091d823SDavid Xu */ 68a091d823SDavid Xu static __inline struct tcb * 69a091d823SDavid Xu _tcb_get(void) 70a091d823SDavid Xu { 71a091d823SDavid Xu return (*((struct tcb **)ARM_TP_ADDRESS)); 72a091d823SDavid Xu } 73a091d823SDavid Xu 74a091d823SDavid Xu extern struct pthread *_thr_initial; 75a091d823SDavid Xu 76a091d823SDavid Xu static __inline struct pthread * 77a091d823SDavid Xu _get_curthread(void) 78a091d823SDavid Xu { 79a091d823SDavid Xu if (_thr_initial) 80a091d823SDavid Xu return (_tcb_get()->tcb_thread); 81a091d823SDavid Xu return (NULL); 82a091d823SDavid Xu } 83a091d823SDavid Xu 84a091d823SDavid Xu #endif /* _PTHREAD_MD_H_ */ 85