-/* $OpenBSD: tib.h,v 1.3 2016/05/07 19:05:21 guenther Exp $ */
+/* $OpenBSD: tib.h,v 1.4 2017/04/20 16:07:52 visa Exp $ */
/*
* Copyright (c) 2011,2014 Philip Guenther <guenther@openbsd.org>
*
*/
-/* If <machine/tcb.h> doesn't provide a better way, then use the default */
-#ifdef TCB_GET
+/* All archs but mips64 have fast TCB_GET() and don't need caching */
+#ifndef __mips64__
# define TCB_HAVE_MD_GET 1
-#else
-# define TCB_GET() __get_tcb()
#endif
#ifdef TCB_SET
# define TCB_HAVE_MD_SET 1
-/* $OpenBSD: cancel.h,v 1.2 2016/05/10 05:42:31 guenther Exp $ */
+/* $OpenBSD: cancel.h,v 1.3 2017/04/20 16:07:52 visa Exp $ */
/*
* Copyright (c) 2015 Philip Guenther <guenther@openbsd.org>
*
__dead void _thread_canceled(void);
__END_HIDDEN_DECLS
-#ifdef __LIBC__
+#if defined(__LIBC__) && !defined(TCB_HAVE_MD_SET)
/*
- * Redirect macros that would use the syscall to instead use our callback
+ * Override TIB_GET macro to use the caching callback
*/
-#define __get_tcb() _thread_cb.tc_tcb()
+#undef TIB_GET
+#define TIB_GET() TCB_TO_TIB(_thread_cb.tc_tcb())
#endif
#define PREP_CANCEL_POINT(tib) \
-/* $OpenBSD: tcb.h,v 1.3 2017/04/20 15:42:26 visa Exp $ */
+/* $OpenBSD: tcb.h,v 1.4 2017/04/20 16:07:52 visa Exp $ */
/*
* Copyright (c) 2011 Philip Guenther <guenther@openbsd.org>
/* ELF TLS ABI calls for small TCB, with static TLS data after it */
#define TLS_VARIANT 1
+static inline void *
+__mips64_get_tcb(void)
+{
+ void *tcb;
+
+ /*
+ * This invokes emulation in kernel if the system does not implement
+ * the RDHWR instruction or the UserLocal register.
+ */
+ __asm__ volatile (
+ " .set push\n"
+ " .set mips64r2\n"
+ " rdhwr %0, $29\n"
+ " .set pop\n" : "=r" (tcb));
+ return tcb;
+}
+
+#define TCB_GET() __mips64_get_tcb()
+
#endif /* _KERNEL */
#endif /* _MACHINE_TCB_H_ */