pthread_md.h revision 280862
1240116Smarcel/*-
2240116Smarcel * Copyright (c) 2005 David Xu <davidxu@freebsd.org>.
3240116Smarcel * Copyright (c) 2014 the FreeBSD Foundation
4240116Smarcel * All rights reserved.
5240116Smarcel *
6240116Smarcel * Portions of this software were developed by Andrew Turner
7240116Smarcel * under sponsorship from the FreeBSD Foundation
8240116Smarcel *
9240116Smarcel * Redistribution and use in source and binary forms, with or without
10240116Smarcel * modification, are permitted provided that the following conditions
11240116Smarcel * are met:
12240116Smarcel *
13240116Smarcel * 1. Redistributions of source code must retain the above copyright
14240116Smarcel *    notice, this list of conditions and the following disclaimer.
15240116Smarcel * 2. Redistributions in binary form must reproduce the above copyright
16240116Smarcel *    notice, this list of conditions and the following disclaimer in the
17240116Smarcel *    documentation and/or other materials provided with the distribution.
18240116Smarcel *
19240116Smarcel * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
20240116Smarcel * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
21240116Smarcel * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
22240116Smarcel * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
23240116Smarcel * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
24240116Smarcel * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
25240116Smarcel * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
26240116Smarcel * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27240116Smarcel * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
28240116Smarcel * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29240116Smarcel *
30240116Smarcel * $FreeBSD: head/lib/libthr/arch/aarch64/include/pthread_md.h 280862 2015-03-30 19:10:09Z andrew $
31240116Smarcel */
32240116Smarcel
33260029Sjmmv/*
34260029Sjmmv * Machine-dependent thread prototypes/definitions.
35260029Sjmmv */
36240116Smarcel#ifndef _PTHREAD_MD_H_
37260029Sjmmv#define	_PTHREAD_MD_H_
38260029Sjmmv
39240116Smarcel#include <sys/types.h>
40240116Smarcel#include <machine/sysarch.h>
41240116Smarcel#include <stddef.h>
42260029Sjmmv
43260029Sjmmv#define	CPU_SPINWAIT
44260029Sjmmv#define	DTV_OFFSET		offsetof(struct tcb, tcb_dtv)
45260029Sjmmv
46260029Sjmmv/*
47260029Sjmmv * Variant I tcb. The structure layout is fixed, don't blindly
48260029Sjmmv * change it.
49260029Sjmmv */
50260029Sjmmvstruct tcb {
51260029Sjmmv	void			*tcb_dtv;
52240116Smarcel	struct pthread		*tcb_thread;
53260029Sjmmv};
54260029Sjmmv
55260029Sjmmv/* Called from the thread to set its private data. */
56240116Smarcelstatic __inline void
57260029Sjmmv_tcb_set(struct tcb *tcb)
58260029Sjmmv{
59260029Sjmmv
60260029Sjmmv	__asm __volatile("msr	tpidr_el0, %x0" :: "r" (tcb));
61240116Smarcel}
62260029Sjmmv
63240116Smarcel/*
64240116Smarcel * Get the current tcb.
65240116Smarcel */
66240116Smarcelstatic __inline struct tcb *
67240116Smarcel_tcb_get(void)
68240116Smarcel{
69	struct tcb *tcb;
70
71	__asm __volatile("mrs	%x0, tpidr_el0" : "=r" (tcb));
72	return (tcb);
73}
74
75extern struct pthread *_thr_initial;
76
77static __inline struct pthread *
78_get_curthread(void)
79{
80
81	return (_tcb_get()->tcb_thread);
82}
83
84#endif /* _PTHREAD_MD_H_ */
85