From 2eae6e6484e9fc9136bd471126bd4a70da6bcbde Mon Sep 17 00:00:00 2001 From: jhb Date: Thu, 6 Feb 2020 21:46:15 +0000 Subject: [PATCH] Tidy the _set_tp function for RISC-V. - Use a constant for the offset instead of a magic number. - Use an addi instruction that writes to tp directly instead of a mv that writes the result of a compiler-generated addi. Reviewed by: mhorne MFC after: 1 week Sponsored by: DARPA Differential Revision: https://reviews.freebsd.org/D23521 --- lib/libc/riscv/gen/_set_tp.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/lib/libc/riscv/gen/_set_tp.c b/lib/libc/riscv/gen/_set_tp.c index a880465253a4..49295e26857c 100644 --- a/lib/libc/riscv/gen/_set_tp.c +++ b/lib/libc/riscv/gen/_set_tp.c @@ -38,13 +38,14 @@ __FBSDID("$FreeBSD$"); #include #include -#include - #include +/* NB: size of 'struct tcb'. */ +#define TP_OFFSET (sizeof(void *) * 2) + void _set_tp(void *tp) { - __asm __volatile("mv tp, %0" :: "r"((char*)tp + 0x10)); + __asm __volatile("addi tp, %0, %1" :: "r" (tp), "I" (TP_OFFSET)); }