Remove cerror dependancy from riscv64 asm syscalls.
authordrahn <drahn@openbsd.org>
Tue, 4 May 2021 04:26:00 +0000 (04:26 +0000)
committerdrahn <drahn@openbsd.org>
Tue, 4 May 2021 04:26:00 +0000 (04:26 +0000)
Directly update cerror as  offset of thread pointer, with
optimizations on error brnaching
ok kettenis@

lib/libc/arch/riscv64/Makefile.inc
lib/libc/arch/riscv64/SYS.h
lib/libc/arch/riscv64/sys/cerror.S [deleted file]
lib/libc/arch/riscv64/sys/sigpending.S
lib/libc/arch/riscv64/sys/sigprocmask.S
lib/libc/arch/riscv64/sys/sigsuspend.S
lib/libc/arch/riscv64/sys/tfork_thread.S

index 27b7548..1ffa209 100644 (file)
@@ -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 <bsd.own.mk>
 
-CERROR=        cerror.S
+# Suppress DWARF2 warnings
+DEBUG?= -gdwarf-4
 
index 21fb457..7c1e59a 100644 (file)
@@ -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 <bbamsch@google.com>
  * Copyright (c) 1990 The Regents of the University of California.
 #include "DEFS.h"
 #include <sys/syscall.h>
 
+/* 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);      \
        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)
 
 #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)
        __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 (file)
index 5f09618..0000000
+++ /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 <mengshi.li.mars@gmail.com>
- *
- * 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)
index a364786..91e0886 100644 (file)
@@ -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 <bbamsch@google.com>
  * 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)
index 8261311..833aadd 100644 (file)
@@ -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 <bbamsch@google.com>
  * 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)
index 24bd50b..36072f9 100644 (file)
@@ -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 <bbamsch@google.com>
  * 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)
index 1614276..bbd2d35 100644 (file)
@@ -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 <bbamsch@google.com>
  * All rights reserved.
 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