1144518Sdavidxu/*- 2144518Sdavidxu * Copyright (c) 2005 David Xu <davidxu@freebsd.org>. 3144518Sdavidxu * All rights reserved. 4144518Sdavidxu * 5144518Sdavidxu * Redistribution and use in source and binary forms, with or without 6144518Sdavidxu * modification, are permitted provided that the following conditions 7144518Sdavidxu * are met: 8144518Sdavidxu * 9144518Sdavidxu * 1. Redistributions of source code must retain the above copyright 10144518Sdavidxu * notice, this list of conditions and the following disclaimer. 11144518Sdavidxu * 2. Redistributions in binary form must reproduce the above copyright 12144518Sdavidxu * notice, this list of conditions and the following disclaimer in the 13144518Sdavidxu * documentation and/or other materials provided with the distribution. 14144518Sdavidxu * 15144518Sdavidxu * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 16144518Sdavidxu * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 17144518Sdavidxu * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 18144518Sdavidxu * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 19144518Sdavidxu * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 20144518Sdavidxu * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 21144518Sdavidxu * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 22144518Sdavidxu * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 23144518Sdavidxu * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 24144518Sdavidxu * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 25144518Sdavidxu * 26144518Sdavidxu * $FreeBSD$ 27144518Sdavidxu */ 28144518Sdavidxu 29144518Sdavidxu/* 30144518Sdavidxu * Machine-dependent thread prototypes/definitions. 31144518Sdavidxu */ 32144518Sdavidxu#ifndef _PTHREAD_MD_H_ 33144518Sdavidxu#define _PTHREAD_MD_H_ 34144518Sdavidxu 35144518Sdavidxu#include <sys/types.h> 36144518Sdavidxu#include <machine/sysarch.h> 37144518Sdavidxu#include <stddef.h> 38144518Sdavidxu 39165241Sdavidxu#define CPU_SPINWAIT 40144518Sdavidxu#define DTV_OFFSET offsetof(struct tcb, tcb_dtv) 41144518Sdavidxu 42144518Sdavidxu/* 43144518Sdavidxu * Variant II tcb, first two members are required by rtld. 44144518Sdavidxu */ 45144518Sdavidxustruct tcb { 46176225Sobrien void *tcb_dtv; /* required by rtld */ 47176225Sobrien struct pthread *tcb_thread; /* our hook */ 48144518Sdavidxu}; 49144518Sdavidxu 50144518Sdavidxu/* 51144518Sdavidxu * The tcb constructors. 52144518Sdavidxu */ 53144518Sdavidxustruct tcb *_tcb_ctor(struct pthread *, int); 54144518Sdavidxuvoid _tcb_dtor(struct tcb *); 55144518Sdavidxu 56144518Sdavidxu/* Called from the thread to set its private data. */ 57144518Sdavidxustatic __inline void 58144518Sdavidxu_tcb_set(struct tcb *tcb) 59144518Sdavidxu{ 60239270Sgonzo#ifdef ARM_TP_ADDRESS 61239270Sgonzo *((struct tcb **)ARM_TP_ADDRESS) = tcb; /* avoids a system call */ 62239270Sgonzo#else 63239270Sgonzo sysarch(ARM_SET_TP, tcb); 64239270Sgonzo#endif 65144518Sdavidxu} 66144518Sdavidxu 67144518Sdavidxu/* 68144518Sdavidxu * Get the current tcb. 69144518Sdavidxu */ 70144518Sdavidxustatic __inline struct tcb * 71144518Sdavidxu_tcb_get(void) 72144518Sdavidxu{ 73239270Sgonzo#ifdef ARM_TP_ADDRESS 74144518Sdavidxu return (*((struct tcb **)ARM_TP_ADDRESS)); 75239270Sgonzo#else 76239270Sgonzo struct tcb *tcb; 77239270Sgonzo 78239270Sgonzo __asm __volatile("mrc p15, 0, %0, c13, c0, 3" \ 79239270Sgonzo : "=r" (tcb)); 80239270Sgonzo return (tcb); 81239270Sgonzo#endif 82144518Sdavidxu} 83144518Sdavidxu 84144518Sdavidxuextern struct pthread *_thr_initial; 85144518Sdavidxu 86144518Sdavidxustatic __inline struct pthread * 87144518Sdavidxu_get_curthread(void) 88144518Sdavidxu{ 89144518Sdavidxu if (_thr_initial) 90144518Sdavidxu return (_tcb_get()->tcb_thread); 91144518Sdavidxu return (NULL); 92144518Sdavidxu} 93144518Sdavidxu 94144518Sdavidxu#endif /* _PTHREAD_MD_H_ */ 95