1280862Sandrew/*- 2280862Sandrew * Copyright (c) 2005 David Xu <davidxu@freebsd.org>. 3280862Sandrew * Copyright (c) 2014 the FreeBSD Foundation 4280862Sandrew * All rights reserved. 5280862Sandrew * 6280862Sandrew * Portions of this software were developed by Andrew Turner 7280862Sandrew * under sponsorship from the FreeBSD Foundation 8280862Sandrew * 9280862Sandrew * Redistribution and use in source and binary forms, with or without 10280862Sandrew * modification, are permitted provided that the following conditions 11280862Sandrew * are met: 12280862Sandrew * 13280862Sandrew * 1. Redistributions of source code must retain the above copyright 14280862Sandrew * notice, this list of conditions and the following disclaimer. 15280862Sandrew * 2. Redistributions in binary form must reproduce the above copyright 16280862Sandrew * notice, this list of conditions and the following disclaimer in the 17280862Sandrew * documentation and/or other materials provided with the distribution. 18280862Sandrew * 19280862Sandrew * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 20280862Sandrew * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 21280862Sandrew * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 22280862Sandrew * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 23280862Sandrew * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 24280862Sandrew * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 25280862Sandrew * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 26280862Sandrew * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 27280862Sandrew * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 28280862Sandrew * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 29280862Sandrew * 30280862Sandrew * $FreeBSD: stable/11/lib/libthr/arch/aarch64/include/pthread_md.h 319430 2017-06-01 14:49:53Z vangyzen $ 31280862Sandrew */ 32280862Sandrew 33280862Sandrew/* 34280862Sandrew * Machine-dependent thread prototypes/definitions. 35280862Sandrew */ 36280862Sandrew#ifndef _PTHREAD_MD_H_ 37280862Sandrew#define _PTHREAD_MD_H_ 38280862Sandrew 39280862Sandrew#include <sys/types.h> 40280862Sandrew#include <machine/sysarch.h> 41280862Sandrew#include <stddef.h> 42280862Sandrew 43280862Sandrew#define CPU_SPINWAIT 44280862Sandrew#define DTV_OFFSET offsetof(struct tcb, tcb_dtv) 45280862Sandrew 46280862Sandrew/* 47280862Sandrew * Variant I tcb. The structure layout is fixed, don't blindly 48280862Sandrew * change it. 49280862Sandrew */ 50280862Sandrewstruct tcb { 51280862Sandrew void *tcb_dtv; 52280862Sandrew struct pthread *tcb_thread; 53280862Sandrew}; 54280862Sandrew 55280862Sandrew/* Called from the thread to set its private data. */ 56280862Sandrewstatic __inline void 57280862Sandrew_tcb_set(struct tcb *tcb) 58280862Sandrew{ 59280862Sandrew 60280862Sandrew __asm __volatile("msr tpidr_el0, %x0" :: "r" (tcb)); 61280862Sandrew} 62280862Sandrew 63280862Sandrew/* 64280862Sandrew * Get the current tcb. 65280862Sandrew */ 66280862Sandrewstatic __inline struct tcb * 67280862Sandrew_tcb_get(void) 68280862Sandrew{ 69280862Sandrew struct tcb *tcb; 70280862Sandrew 71280862Sandrew __asm __volatile("mrs %x0, tpidr_el0" : "=r" (tcb)); 72280862Sandrew return (tcb); 73280862Sandrew} 74280862Sandrew 75280862Sandrewstatic __inline struct pthread * 76280862Sandrew_get_curthread(void) 77280862Sandrew{ 78280862Sandrew 79280862Sandrew return (_tcb_get()->tcb_thread); 80280862Sandrew} 81280862Sandrew 82280862Sandrew#endif /* _PTHREAD_MD_H_ */ 83