From: drahn Date: Thu, 29 Apr 2021 18:33:36 +0000 (+0000) Subject: riscv64 libc, more pieces. X-Git-Url: http://artulab.com/gitweb/?a=commitdiff_plain;h=7ecb72fe0d4a784959d47a5dd7c81ac725e35700;p=openbsd riscv64 libc, more pieces. largely derived from aarch64 code. usertc.c taken from hppa with cleanup to Symbols.list and tfork_thread.S Further cleanup and enhancement will be performed in-tree. ok kettenis@ --- diff --git a/lib/libc/arch/riscv64/Makefile.inc b/lib/libc/arch/riscv64/Makefile.inc new file mode 100644 index 00000000000..27b7548345b --- /dev/null +++ b/lib/libc/arch/riscv64/Makefile.inc @@ -0,0 +1,5 @@ +# $OpenBSD: Makefile.inc,v 1.1 2021/04/29 18:33:36 drahn Exp $ +.include + +CERROR= cerror.S + diff --git a/lib/libc/arch/riscv64/SYS.h b/lib/libc/arch/riscv64/SYS.h new file mode 100644 index 00000000000..c3219d51a46 --- /dev/null +++ b/lib/libc/arch/riscv64/SYS.h @@ -0,0 +1,123 @@ +/* $OpenBSD: SYS.h,v 1.1 2021/04/29 18:33:36 drahn Exp $ */ +/*- + * Copyright (c) 2020 Brian Bamsch + * Copyright (c) 1990 The Regents of the University of California. + * All rights reserved. + * + * This code is derived from software contributed to Berkeley by + * William Jolitz. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. Neither the name of the University nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * from: @(#)SYS.h 5.5 (Berkeley) 5/7/91 + */ + +#include "DEFS.h" +#include + +#define SYSENTRY(x) \ + .weak _C_LABEL(x); \ + _C_LABEL(x) = _C_LABEL(_thread_sys_ ## x); \ + ENTRY(_thread_sys_ ## x) +#define SYSENTRY_HIDDEN(x) \ + ENTRY(_thread_sys_ ## x) +#define __END_HIDDEN(x) \ + END(_thread_sys_ ## x); \ + _HIDDEN_FALIAS(x, _thread_sys_ ## x); \ + END(_HIDDEN(x)) +#define __END(x) \ + __END_HIDDEN(x); END(x) + +#define SYSTRAP(x) \ + li t0, SYS_ ## x; \ + ecall + +#define CERROR _C_LABEL(__cerror) +#define HANDLE_ERROR() \ + bnez t0, 1f; \ + ret; \ +1: auipc t0, %got_pcrel_hi(CERROR); \ + ld t1, %pcrel_lo(1b)(t0); \ + jr t1 + +#define _SYSCALL_NOERROR(x,y) \ + SYSENTRY(x); \ + SYSTRAP(y) +#define _SYSCALL_HIDDEN_NOERROR(x,y) \ + SYSENTRY_HIDDEN(x); \ + SYSTRAP(y) + +#define _SYSCALL(x, y) \ + _SYSCALL_NOERROR(x,y); \ + HANDLE_ERROR +#define _SYSCALL_HIDDEN(x, y) \ + _SYSCALL_HIDDEN_NOERROR(x,y); \ + HANDLE_ERROR + +#define SYSCALL_NOERROR(x) \ + _SYSCALL_NOERROR(x,x) + +#define SYSCALL(x) \ + _SYSCALL(x,x) + + +#define PSEUDO_NOERROR(x,y) \ + SYSENTRY(x); \ + RETGUARD_SETUP(x, t6); \ + SYSTRAP(y); \ + RETGUARD_CHECK(x, t6); \ + ret; \ + __END(x) + +#define PSEUDO(x,y) \ + SYSENTRY(x); \ + RETGUARD_SETUP(x, t6); \ + SYSTRAP(y); \ + HANDLE_ERROR(); \ + RETGUARD_CHECK(x, t6); \ + ret; \ + __END(x) +#define PSEUDO_HIDDEN(x,y) \ + SYSENTRY_HIDDEN(x); \ + RETGUARD_SETUP(x, t6); \ + SYSTRAP(y); \ + HANDLE_ERROR(); \ + RETGUARD_CHECK(x, t6); \ + ret; \ + __END_HIDDEN(x) + +#define RSYSCALL_NOERROR(x) \ + PSEUDO_NOERROR(x,x) + +#define RSYSCALL(x) \ + PSEUDO(x,x) +#define RSYSCALL_HIDDEN(x) \ + PSEUDO_HIDDEN(x,x) +#define SYSCALL_END(x) \ + __END(x) +#define SYSCALL_END_HIDDEN(x) \ + __END_HIDDEN(x) + + .globl CERROR diff --git a/lib/libc/arch/riscv64/Symbols.list b/lib/libc/arch/riscv64/Symbols.list new file mode 100644 index 00000000000..fecd8d3daca --- /dev/null +++ b/lib/libc/arch/riscv64/Symbols.list @@ -0,0 +1,5 @@ +__mcount +fabsl +frexpl +ldexpl +modfl diff --git a/lib/libc/arch/riscv64/gen/_atomic_lock.c b/lib/libc/arch/riscv64/gen/_atomic_lock.c new file mode 100644 index 00000000000..779a679955f --- /dev/null +++ b/lib/libc/arch/riscv64/gen/_atomic_lock.c @@ -0,0 +1,43 @@ +/* $OpenBSD: _atomic_lock.c,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. + */ + +/* + * Atomic lock for riscv64 + */ + +#include +#include + +/* + * Spinlock does not have Aquire/Release semantics, so amoswap.w.aq + * should not used here. + */ +int +_atomic_lock(volatile _atomic_lock_t *lock) +{ + _atomic_lock_t old; + + /* + * Use the amoswap instruction to swap the lock value with + * a local variable containing the locked state. + */ + __asm__("amoswap.w %0, %1, (%2)" + : "=r" (old) + : "r" (_ATOMIC_LOCK_LOCKED), "r" (lock) : "memory"); + + return (old != _ATOMIC_LOCK_UNLOCKED); +} diff --git a/lib/libc/arch/riscv64/gen/usertc.c b/lib/libc/arch/riscv64/gen/usertc.c new file mode 100644 index 00000000000..2274976a08f --- /dev/null +++ b/lib/libc/arch/riscv64/gen/usertc.c @@ -0,0 +1,21 @@ +/* $OpenBSD: usertc.c,v 1.1 2021/04/29 18:33:36 drahn Exp $ */ +/* + * Copyright (c) 2020 Paul Irofti + * + * 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 +#include + +int (*const _tc_get_timecount)(struct timekeep *, u_int *) = NULL; diff --git a/lib/libc/arch/riscv64/net/Makefile.inc b/lib/libc/arch/riscv64/net/Makefile.inc new file mode 100644 index 00000000000..1b8cd45dafb --- /dev/null +++ b/lib/libc/arch/riscv64/net/Makefile.inc @@ -0,0 +1 @@ +SRCS += ntohl.c ntohs.c htons.c htonl.c diff --git a/lib/libc/arch/riscv64/sys/Ovfork.S b/lib/libc/arch/riscv64/sys/Ovfork.S new file mode 100644 index 00000000000..c2ba68c9685 --- /dev/null +++ b/lib/libc/arch/riscv64/sys/Ovfork.S @@ -0,0 +1,41 @@ +/* $OpenBSD: Ovfork.S,v 1.1 2021/04/29 18:33:36 drahn Exp $ */ +/* + * Copyright (c) 2020 Brian Bamsch + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. Neither the name of the copyright holder nor the names of contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTOR(S) ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTOR(S) BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + */ + +#include "SYS.h" + +SYSENTRY_HIDDEN(vfork) + RETGUARD_SETUP(vfork, t6) + mv a2, ra + SYSTRAP(vfork) + HANDLE_ERROR() + mv ra, a2 + RETGUARD_CHECK(vfork, t6) + ret +SYSCALL_END_HIDDEN(vfork) diff --git a/lib/libc/arch/riscv64/sys/cerror.S b/lib/libc/arch/riscv64/sys/cerror.S new file mode 100644 index 00000000000..5f096181fb6 --- /dev/null +++ b/lib/libc/arch/riscv64/sys/cerror.S @@ -0,0 +1,29 @@ +/* $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 new file mode 100644 index 00000000000..a36478631b2 --- /dev/null +++ b/lib/libc/arch/riscv64/sys/sigpending.S @@ -0,0 +1,42 @@ +/* $OpenBSD: sigpending.S,v 1.1 2021/04/29 18:33:36 drahn Exp $ */ +/* + * Copyright (c) 2020 Brian Bamsch + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. Neither the name of the copyright holder nor the names of contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTOR(S) ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTOR(S) BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + */ + +#include "SYS.h" + +SYSENTRY(sigpending) + RETGUARD_SETUP(sigpending, t6) + mv a2, a0 + SYSTRAP(sigpending) + HANDLE_ERROR() + sw a0, 0(a2) /* 4 bytes */ + mv a0, x0 + 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 new file mode 100644 index 00000000000..8261311fa27 --- /dev/null +++ b/lib/libc/arch/riscv64/sys/sigprocmask.S @@ -0,0 +1,51 @@ +/* $OpenBSD: sigprocmask.S,v 1.1 2021/04/29 18:33:36 drahn Exp $ */ +/* + * Copyright (c) 2020 Brian Bamsch + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. Neither the name of the copyright holder nor the names of contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTOR(S) ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTOR(S) BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + */ + +#include "SYS.h" + +SYSENTRY_HIDDEN(sigprocmask) + RETGUARD_SETUP(sigprocmask, t6) + beqz a1, 1f + lw a1, (a1) + j 2f +1: + li a0, 1 + li a1, 0 +2: + + SYSTRAP(sigprocmask) + HANDLE_ERROR() + beqz a2, 1f + sw a0, (a2) +1: + mv a0, x0 + 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 new file mode 100644 index 00000000000..24bd50b77cc --- /dev/null +++ b/lib/libc/arch/riscv64/sys/sigsuspend.S @@ -0,0 +1,41 @@ +/* $OpenBSD: sigsuspend.S,v 1.1 2021/04/29 18:33:36 drahn Exp $ */ +/* + * Copyright (c) 2020 Brian Bamsch + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. Neither the name of the copyright holder nor the names of contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTOR(S) ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTOR(S) BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + */ + +#include "SYS.h" + +SYSENTRY_HIDDEN(sigsuspend) + RETGUARD_SETUP(sigsuspend, t6) + lw a0, (a0) + SYSTRAP(sigsuspend) + HANDLE_ERROR() + li a0, 0 + RETGUARD_CHECK(sigsuspend, t6) + ret +SYSCALL_END_HIDDEN(sigsuspend) diff --git a/lib/libc/arch/riscv64/sys/syscall.S b/lib/libc/arch/riscv64/sys/syscall.S new file mode 100644 index 00000000000..b592c3c7e45 --- /dev/null +++ b/lib/libc/arch/riscv64/sys/syscall.S @@ -0,0 +1,35 @@ +/* $OpenBSD: syscall.S,v 1.1 2021/04/29 18:33:36 drahn Exp $ */ +/*- + * Copyright (c) 1990 The Regents of the University of California. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. Neither the name of the University nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * from: @(#)syscall.s 5.1 (Berkeley) 4/23/90 + */ + +#include "SYS.h" + +RSYSCALL(syscall) diff --git a/lib/libc/arch/riscv64/sys/tfork_thread.S b/lib/libc/arch/riscv64/sys/tfork_thread.S new file mode 100644 index 00000000000..16142761f5a --- /dev/null +++ b/lib/libc/arch/riscv64/sys/tfork_thread.S @@ -0,0 +1,52 @@ +/* $OpenBSD: tfork_thread.S,v 1.1 2021/04/29 18:33:36 drahn Exp $ */ +/* + * Copyright (c) 2020 Brian Bamsch + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. Neither the name of the copyright holder nor the names of contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTOR(S) ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTOR(S) BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + */ + +#include "SYS.h" + +/* + * a0 a1 a2 a3 + * __tfork_thread(param, psize, start_fnc, start_arg); + */ + +ENTRY(__tfork_thread) + RETGUARD_SETUP(__tfork_thread, t6) + SYSTRAP(__tfork) + HANDLE_ERROR() + + beqz a0, 1f + /* parent thread */ + RETGUARD_CHECK(__tfork_thread, t6) + ret + +1: /* child thread */ + mv a0, a3 + jalr a2 + SYSTRAP(__threxit) +END(__tfork_thread)