From: drahn Date: Tue, 4 May 2021 04:26:00 +0000 (+0000) Subject: Remove cerror dependancy from riscv64 asm syscalls. X-Git-Url: http://artulab.com/gitweb/?a=commitdiff_plain;h=0f2255fcf6ad0f8f9c3d05a414f4bbd17df168d1;p=openbsd Remove cerror dependancy from riscv64 asm syscalls. Directly update cerror as offset of thread pointer, with optimizations on error brnaching ok kettenis@ --- diff --git a/lib/libc/arch/riscv64/Makefile.inc b/lib/libc/arch/riscv64/Makefile.inc index 27b7548345b..1ffa2093188 100644 --- a/lib/libc/arch/riscv64/Makefile.inc +++ b/lib/libc/arch/riscv64/Makefile.inc @@ -1,5 +1,6 @@ -# $OpenBSD: Makefile.inc,v 1.1 2021/04/29 18:33:36 drahn Exp $ +# $OpenBSD: Makefile.inc,v 1.2 2021/05/04 04:26:00 drahn Exp $ .include -CERROR= cerror.S +# Suppress DWARF2 warnings +DEBUG?= -gdwarf-4 diff --git a/lib/libc/arch/riscv64/SYS.h b/lib/libc/arch/riscv64/SYS.h index 21fb4570a29..7c1e59a6593 100644 --- a/lib/libc/arch/riscv64/SYS.h +++ b/lib/libc/arch/riscv64/SYS.h @@ -1,4 +1,4 @@ -/* $OpenBSD: SYS.h,v 1.2 2021/05/02 20:08:49 drahn Exp $ */ +/* $OpenBSD: SYS.h,v 1.3 2021/05/04 04:26:00 drahn Exp $ */ /*- * Copyright (c) 2020 Brian Bamsch * Copyright (c) 1990 The Regents of the University of California. @@ -37,6 +37,12 @@ #include "DEFS.h" #include +/* offsetof(struct tib, tib_errno) - offsetof(struct tib, __tib_tcb) */ +#define TCB_OFFSET_ERRNO (-12) + +/* offset of errno from tp */ +#define TP_OFFSET_ERRNO TCB_OFFSET_ERRNO + #define SYSENTRY(x) \ .weak _C_LABEL(x); \ _C_LABEL(x) = _C_LABEL(_thread_sys_ ## x); \ @@ -54,13 +60,18 @@ li t0, SYS_ ## x; \ ecall -#define CERROR _C_LABEL(__cerror) #define HANDLE_ERROR() \ - beqz t0, 2f; \ -1: auipc t0, %got_pcrel_hi(CERROR); \ - ld t1, %pcrel_lo(1b)(t0); \ - jr t1; \ -2: + beqz t0, 200f; \ + sw a0, TP_OFFSET_ERRNO(tp); \ + li a0, -1; \ +200: + +#define HANDLE_ERROR_TARGET(target) \ + beqz t0, 200f; \ + sw a0, TP_OFFSET_ERRNO(tp); \ + li a0, -1; \ + j target; \ +200: #define _SYSCALL_NOERROR(x,y) \ SYSENTRY(x); \ SYSTRAP(y) @@ -70,10 +81,10 @@ #define _SYSCALL(x, y) \ _SYSCALL_NOERROR(x,y); \ - HANDLE_ERROR + HANDLE_ERROR() \ #define _SYSCALL_HIDDEN(x, y) \ _SYSCALL_HIDDEN_NOERROR(x,y); \ - HANDLE_ERROR + HANDLE_ERROR() \ #define SYSCALL_NOERROR(x) \ _SYSCALL_NOERROR(x,x) @@ -118,5 +129,3 @@ __END(x) #define SYSCALL_END_HIDDEN(x) \ __END_HIDDEN(x) - - .globl CERROR diff --git a/lib/libc/arch/riscv64/sys/cerror.S b/lib/libc/arch/riscv64/sys/cerror.S deleted file mode 100644 index 5f096181fb6..00000000000 --- a/lib/libc/arch/riscv64/sys/cerror.S +++ /dev/null @@ -1,29 +0,0 @@ -/* $OpenBSD: cerror.S,v 1.1 2021/04/29 18:33:36 drahn Exp $ */ -/*- - * Copyright (c) 2020 Mars Li - * - * Permission to use, copy, modify, and distribute this software for any - * purpose with or without fee is hereby granted, provided that the above - * copyright notice and this permission notice appear in all copies. - * - * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES - * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF - * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR - * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES - * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN - * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF - * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. - */ - -#include "SYS.h" - -/* offsetof(struct tib, tib_errno) - offsetof(struct tib, __tib_tcb) */ -#define TCB_OFFSET_ERRNO (-12) - -_ENTRY(CERROR) - RETGUARD_SETUP(CERROR, t6) - sw a0, TCB_OFFSET_ERRNO(tp) - li a0, -1 - RETGUARD_CHECK(CERROR, t6) - ret -END(CERROR) diff --git a/lib/libc/arch/riscv64/sys/sigpending.S b/lib/libc/arch/riscv64/sys/sigpending.S index a36478631b2..91e08867c60 100644 --- a/lib/libc/arch/riscv64/sys/sigpending.S +++ b/lib/libc/arch/riscv64/sys/sigpending.S @@ -1,4 +1,4 @@ -/* $OpenBSD: sigpending.S,v 1.1 2021/04/29 18:33:36 drahn Exp $ */ +/* $OpenBSD: sigpending.S,v 1.2 2021/05/04 04:26:00 drahn Exp $ */ /* * Copyright (c) 2020 Brian Bamsch * All rights reserved. @@ -34,9 +34,10 @@ SYSENTRY(sigpending) RETGUARD_SETUP(sigpending, t6) mv a2, a0 SYSTRAP(sigpending) - HANDLE_ERROR() + HANDLE_ERROR_TARGET(1f) sw a0, 0(a2) /* 4 bytes */ mv a0, x0 +1: RETGUARD_CHECK(sigpending, t6) ret SYSCALL_END(sigpending) diff --git a/lib/libc/arch/riscv64/sys/sigprocmask.S b/lib/libc/arch/riscv64/sys/sigprocmask.S index 8261311fa27..833aadd5dc3 100644 --- a/lib/libc/arch/riscv64/sys/sigprocmask.S +++ b/lib/libc/arch/riscv64/sys/sigprocmask.S @@ -1,4 +1,4 @@ -/* $OpenBSD: sigprocmask.S,v 1.1 2021/04/29 18:33:36 drahn Exp $ */ +/* $OpenBSD: sigprocmask.S,v 1.2 2021/05/04 04:26:00 drahn Exp $ */ /* * Copyright (c) 2020 Brian Bamsch * All rights reserved. @@ -41,11 +41,12 @@ SYSENTRY_HIDDEN(sigprocmask) 2: SYSTRAP(sigprocmask) - HANDLE_ERROR() + HANDLE_ERROR_TARGET(3f) beqz a2, 1f sw a0, (a2) 1: - mv a0, x0 + li a0, 0 +3: RETGUARD_CHECK(sigprocmask, t6) ret SYSCALL_END_HIDDEN(sigprocmask) diff --git a/lib/libc/arch/riscv64/sys/sigsuspend.S b/lib/libc/arch/riscv64/sys/sigsuspend.S index 24bd50b77cc..36072f95da9 100644 --- a/lib/libc/arch/riscv64/sys/sigsuspend.S +++ b/lib/libc/arch/riscv64/sys/sigsuspend.S @@ -1,4 +1,4 @@ -/* $OpenBSD: sigsuspend.S,v 1.1 2021/04/29 18:33:36 drahn Exp $ */ +/* $OpenBSD: sigsuspend.S,v 1.2 2021/05/04 04:26:00 drahn Exp $ */ /* * Copyright (c) 2020 Brian Bamsch * All rights reserved. @@ -34,8 +34,9 @@ SYSENTRY_HIDDEN(sigsuspend) RETGUARD_SETUP(sigsuspend, t6) lw a0, (a0) SYSTRAP(sigsuspend) - HANDLE_ERROR() + HANDLE_ERROR_TARGET(1f) li a0, 0 +1: RETGUARD_CHECK(sigsuspend, t6) ret SYSCALL_END_HIDDEN(sigsuspend) diff --git a/lib/libc/arch/riscv64/sys/tfork_thread.S b/lib/libc/arch/riscv64/sys/tfork_thread.S index 16142761f5a..bbd2d354f75 100644 --- a/lib/libc/arch/riscv64/sys/tfork_thread.S +++ b/lib/libc/arch/riscv64/sys/tfork_thread.S @@ -1,4 +1,4 @@ -/* $OpenBSD: tfork_thread.S,v 1.1 2021/04/29 18:33:36 drahn Exp $ */ +/* $OpenBSD: tfork_thread.S,v 1.2 2021/05/04 04:26:00 drahn Exp $ */ /* * Copyright (c) 2020 Brian Bamsch * All rights reserved. @@ -38,10 +38,11 @@ ENTRY(__tfork_thread) RETGUARD_SETUP(__tfork_thread, t6) SYSTRAP(__tfork) - HANDLE_ERROR() + HANDLE_ERROR_TARGET(2f) beqz a0, 1f /* parent thread */ +2: RETGUARD_CHECK(__tfork_thread, t6) ret