diff options
| author | Enji Cooper <ngie@FreeBSD.org> | 2026-02-15 01:57:42 +0000 |
|---|---|---|
| committer | Enji Cooper <ngie@FreeBSD.org> | 2026-02-15 02:12:44 +0000 |
| commit | e8dbf2b6df199526a660f81de07d17925cfd8518 (patch) | |
| tree | cd0c09449bea5df56ef67059e797737d70587070 /kernel/arch/aarch64 | |
| parent | 56a7ce8416d181a2060d7a428aed9c3c6a431e6d (diff) | |
Add files missed in 56a7ce8416d181a2060d7a42vendor/NetBSD/tests/2026.02.14_2vendor/NetBSD/tests
Skip usr.bin/diff3 tests as these contain text that gets misinterpreted
as merge conflict markers and blocks push with the relevant pre-receive
hook.
PR: 293186
Diffstat (limited to 'kernel/arch/aarch64')
| -rw-r--r-- | kernel/arch/aarch64/contextspfunc.S | 46 | ||||
| -rw-r--r-- | kernel/arch/aarch64/execregs.c | 226 | ||||
| -rw-r--r-- | kernel/arch/aarch64/execregs.h | 86 | ||||
| -rw-r--r-- | kernel/arch/aarch64/execsp.S | 99 | ||||
| -rw-r--r-- | kernel/arch/aarch64/h_execregs.S | 84 | ||||
| -rw-r--r-- | kernel/arch/aarch64/signalsphandler.S | 46 | ||||
| -rw-r--r-- | kernel/arch/aarch64/stack_pointer.h | 42 | ||||
| -rw-r--r-- | kernel/arch/aarch64/threadspfunc.S | 43 |
8 files changed, 672 insertions, 0 deletions
diff --git a/kernel/arch/aarch64/contextspfunc.S b/kernel/arch/aarch64/contextspfunc.S new file mode 100644 index 000000000000..9a4e3059a8e0 --- /dev/null +++ b/kernel/arch/aarch64/contextspfunc.S @@ -0,0 +1,46 @@ +/* $NetBSD: contextspfunc.S,v 1.2 2025/06/08 18:55:35 christos Exp $ */ + +/*- + * Copyright (c) 2025 The NetBSD Foundation, Inc. + * 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. + * + * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. 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 FOUNDATION 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. + */ + +#define _LOCORE + +#include <machine/asm.h> + +RCSID("$NetBSD: contextspfunc.S,v 1.2 2025/06/08 18:55:35 christos Exp $") + +/* + * contextspfunc() + * + * makecontext(3) function. Store the stack pointer on entry at + * the global variable contextsp and call contextdone. + */ +ENTRY(contextspfunc) + mov x0, sp + adrp x1, _C_LABEL(contextsp) + str x0, [x1, :lo12:_C_LABEL(contextsp)] + b _C_LABEL(contextdone) +END(contextspfunc) diff --git a/kernel/arch/aarch64/execregs.c b/kernel/arch/aarch64/execregs.c new file mode 100644 index 000000000000..4c7697fe98c7 --- /dev/null +++ b/kernel/arch/aarch64/execregs.c @@ -0,0 +1,226 @@ +/* $NetBSD: execregs.c,v 1.1 2025/02/27 00:55:31 riastradh Exp $ */ + +/*- + * Copyright (c) 2025 The NetBSD Foundation, Inc. + * 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. + * + * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. 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 FOUNDATION 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. + */ + +#include <sys/cdefs.h> +__RCSID("$NetBSD: execregs.c,v 1.1 2025/02/27 00:55:31 riastradh Exp $"); + +#include "execregs.h" + +#include <errno.h> +#include <spawn.h> +#include <stddef.h> +#include <unistd.h> + +extern char **environ; + +static unsigned long +nonnull(unsigned long x) +{ + + x |= x << 8; + x |= x << 16; + x |= x << 32; + return x; +} + +int +execregschild(char *path) +{ + /* x0: used to pass exec arg0, nonnull anyway (path) */ + /* x1: used to pass exec arg1, nonnull anyway (argv) */ + /* x2: used to pass exec arg2, nonnull anyway (environ) */ + register long x3 __asm("x3") = nonnull(3); + register long x4 __asm("x4") = nonnull(4); + register long x5 __asm("x5") = nonnull(5); + register long x6 __asm("x6") = nonnull(6); + register long x7 __asm("x7") = nonnull(7); + register long x8 __asm("x8") = nonnull(8); + register long x9 __asm("x9") = nonnull(9); + register long x10 __asm("x10") = nonnull(10); + register long x11 __asm("x11") = nonnull(11); + register long x12 __asm("x12") = nonnull(12); + register long x13 __asm("x13") = nonnull(13); + register long x14 __asm("x14") = nonnull(14); + register long x15 __asm("x15") = nonnull(15); + register long x16 __asm("x16") = nonnull(16); + register long x17 __asm("x17") = nonnull(17); + register long x18 __asm("x18") = nonnull(18); + register long x19 __asm("x19") = nonnull(19); + register long x20 __asm("x20") = nonnull(20); + register long x21 __asm("x21") = nonnull(21); + register long x22 __asm("x22") = nonnull(22); + register long x23 __asm("x23") = nonnull(23); + register long x24 __asm("x24") = nonnull(24); + register long x25 __asm("x25") = nonnull(25); + register long x26 __asm("x26") = nonnull(26); + register long x27 __asm("x27") = nonnull(27); + register long x28 __asm("x28") = nonnull(28); + /* x29: frame pointer, nonnull anyway */ + /* x30: link register, nonnull anyway */ + + char *argv[] = {path, NULL}; + char **envp = environ; + + /* + * Not perfect -- compiler might use some registers for + * stack/argument transfers, but all the arguments are nonnull + * so this is probably a good test anyway. + */ + __asm volatile("" : + "+r"(x3), + "+r"(x4), + "+r"(x5), + "+r"(x6), + "+r"(x7), + "+r"(x8), + "+r"(x9), + "+r"(x10), + "+r"(x11), + "+r"(x12), + "+r"(x13), + "+r"(x14), + "+r"(x15), + "+r"(x16), + "+r"(x17) + :: "memory"); + /* pacify gcc error: more than 30 operands in 'asm' */ + __asm volatile("" : + "+r"(x18), + "+r"(x19), + "+r"(x20), + "+r"(x21), + "+r"(x22), + "+r"(x23), + "+r"(x24), + "+r"(x25), + "+r"(x26), + "+r"(x27), + "+r"(x28) + :: "memory"); + + return execve(path, argv, envp); +} + +pid_t +spawnregschild(char *path, int fd) +{ + /* x0: used to pass posix_spawn arg0, nonnull anyway (&pid) */ + /* x1: used to pass posix_spawn arg1, nonnull anyway (path) */ + /* x2: used to pass posix_spawn arg2, nonnull anyway (&fileacts) */ + /* x3: used to pass posix_spawn arg3, nonnull anyway (&attr) */ + /* x4: used to pass posix_spawn arg3, nonnull anyway (argv) */ + /* x5: used to pass posix_spawn arg3, nonnull anyway (environ) */ + register long x6 __asm("x6") = nonnull(6); + register long x7 __asm("x7") = nonnull(7); + register long x8 __asm("x8") = nonnull(8); + register long x9 __asm("x9") = nonnull(9); + register long x10 __asm("x10") = nonnull(10); + register long x11 __asm("x11") = nonnull(11); + register long x12 __asm("x12") = nonnull(12); + register long x13 __asm("x13") = nonnull(13); + register long x14 __asm("x14") = nonnull(14); + register long x15 __asm("x15") = nonnull(15); + register long x16 __asm("x16") = nonnull(16); + register long x17 __asm("x17") = nonnull(17); + register long x18 __asm("x18") = nonnull(18); + register long x19 __asm("x19") = nonnull(19); + register long x20 __asm("x20") = nonnull(20); + register long x21 __asm("x21") = nonnull(21); + register long x22 __asm("x22") = nonnull(22); + register long x23 __asm("x23") = nonnull(23); + register long x24 __asm("x24") = nonnull(24); + register long x25 __asm("x25") = nonnull(25); + register long x26 __asm("x26") = nonnull(26); + register long x27 __asm("x27") = nonnull(27); + register long x28 __asm("x28") = nonnull(28); + /* x29: frame pointer, nonnull anyway */ + /* x30: link register, nonnull anyway */ + + char *argv[] = {path, NULL}; + char **envp = environ; + posix_spawn_file_actions_t fileacts; + posix_spawnattr_t attr; + pid_t pid; + int error; + + error = posix_spawn_file_actions_init(&fileacts); + if (error) + goto out; + error = posix_spawn_file_actions_adddup2(&fileacts, fd, STDOUT_FILENO); + if (error) + goto out; + error = posix_spawnattr_init(&attr); + if (error) + goto out; + + /* + * Not perfect -- compiler might use some registers for + * stack/argument transfers, but all the arguments are nonnull + * so this is probably a good test anyway. + */ + __asm volatile("" : + "+r"(x6), + "+r"(x7), + "+r"(x8), + "+r"(x9), + "+r"(x10), + "+r"(x11), + "+r"(x12), + "+r"(x13), + "+r"(x14), + "+r"(x15), + "+r"(x16), + "+r"(x17), + "+r"(x18), + "+r"(x19), + "+r"(x20) + :: "memory"); + /* pacify gcc error: more than 30 operands in 'asm' */ + __asm volatile("" : + "+r"(x21), + "+r"(x22), + "+r"(x23), + "+r"(x24), + "+r"(x25), + "+r"(x26), + "+r"(x27), + "+r"(x28) + :: "memory"); + + error = posix_spawn(&pid, path, &fileacts, &attr, argv, envp); + if (error) + goto out; + +out: posix_spawnattr_destroy(&attr); + posix_spawn_file_actions_destroy(&fileacts); + if (error) { + errno = error; + return -1; + } + return 0; +} diff --git a/kernel/arch/aarch64/execregs.h b/kernel/arch/aarch64/execregs.h new file mode 100644 index 000000000000..471a3859c4d1 --- /dev/null +++ b/kernel/arch/aarch64/execregs.h @@ -0,0 +1,86 @@ +/* $NetBSD: execregs.h,v 1.1 2025/02/27 00:55:31 riastradh Exp $ */ + +/*- + * Copyright (c) 2025 The NetBSD Foundation, Inc. + * 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. + * + * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. 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 FOUNDATION 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. + */ + +#ifndef TESTS_KERNEL_ARCH_AARCH64_EXECREGS_H +#define TESTS_KERNEL_ARCH_AARCH64_EXECREGS_H + +#include <sys/cdefs.h> + +#define NEXECREGS 31 + +#ifndef _LOCORE + +#include <unistd.h> + +/* + * Ordered by struct reg in sys/arch/aarch64/include/reg.h for + * convenience of auditing. Must match h_execregs.S. + */ +static const char *const regname[] = { + "x0", + "x1", + /* x2: ps_strings */ + "x3", + "x4", + "x5", + "x6", + "x7", + "x8", + "x9", + "x10", + "x11", + "x12", + "x13", + "x14", + "x15", + "x16", + "x17", + "x18", + "x19", + "x20", + "x21", + "x22", + "x23", + "x24", + "x25", + "x26", + "x27", + "x28", + "x29", + "x30", + "tpidr", +}; + +__CTASSERT(NEXECREGS == __arraycount(regname)); + +int execregschild(char *); +pid_t spawnregschild(char *, int); + +#endif /* _LOCORE */ + +#endif /* TESTS_KERNEL_ARCH_AARCH64_EXECREGS_H */ diff --git a/kernel/arch/aarch64/execsp.S b/kernel/arch/aarch64/execsp.S new file mode 100644 index 000000000000..52c1472afef6 --- /dev/null +++ b/kernel/arch/aarch64/execsp.S @@ -0,0 +1,99 @@ +/* $NetBSD: execsp.S,v 1.3 2025/06/04 19:25:45 christos Exp $ */ + +/*- + * Copyright (c) 2025 The NetBSD Foundation, Inc. + * 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. + * + * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. 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 FOUNDATION 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. + */ + +#define _LOCORE + +#include <machine/asm.h> + +RCSID("$NetBSD: execsp.S,v 1.3 2025/06/04 19:25:45 christos Exp $") + +/* + * void execsp_start(void (*cleanup@x0)(void), void *obj_main@x1, + * struct ps_strings *ps_strings@x2) + * + * ELF entry point. Saves the stack pointer in startsp and defers + * to the usual csu __start routine. + */ +ENTRY(execsp_start) + mov x16, sp + adrp x17, _C_LABEL(startsp) + str x16, [x17, :lo12:_C_LABEL(startsp)] + b _C_LABEL(__start) +END(execsp_start) + +/* + * void execsp_ctor(void) + * + * ELF constructor. Saves the stack pointer in ctorsp and + * returns. + */ +ENTRY(execsp_ctor) + mov x16, sp + adrp x17, _C_LABEL(ctorsp) + str x16, [x17, :lo12:_C_LABEL(ctorsp)] + ret +END(execsp_ctor) + + /* Make execsp_ctor a constructor. */ + .section .init_array,"aw",%init_array + .p2align 3 + .xword _C_LABEL(execsp_ctor) + +/* + * int main(int argc@x0, char **argv@x1, ...) + * + * Main function. Saves the stack pointer in mainsp and returns + * zero. We will call execsp_main in execsp_dtor once dtorsp has + * been initialized. + */ +ENTRY(main) + mov x16, sp + adrp x17, _C_LABEL(mainsp) + str x16, [x17, :lo12:_C_LABEL(mainsp)] + mov x0, #0 + ret +END(main) + +/* + * void execsp_dtor(void) + * + * ELF destructor. Saves the stack pointer in dtorsp and defers + * to the C execsp_main in h_execsp.c to report the stack pointers + * back to the t_signal_and_sp parent. + */ +ENTRY(execsp_dtor) + mov x16, sp + adrp x17, _C_LABEL(dtorsp) + str x16, [x17, :lo12:_C_LABEL(dtorsp)] + b _C_LABEL(execsp_main) +END(execsp_dtor) + + /* Make execsp_ctor a destructor. */ + .section .fini_array,"aw",%fini_array + .p2align 3 + .xword _C_LABEL(execsp_dtor) diff --git a/kernel/arch/aarch64/h_execregs.S b/kernel/arch/aarch64/h_execregs.S new file mode 100644 index 000000000000..f060911067f4 --- /dev/null +++ b/kernel/arch/aarch64/h_execregs.S @@ -0,0 +1,84 @@ +/* $NetBSD: h_execregs.S,v 1.2 2025/04/25 12:58:40 riastradh Exp $ */ + +/*- + * Copyright (c) 2025 The NetBSD Foundation, Inc. + * 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. + * + * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. 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 FOUNDATION 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. + */ + +#define _LOCORE + +#include <sys/syscall.h> + +#include <machine/asm.h> + +#include "execregs.h" + +ENTRY(execregs_start) + /* create a stack frame with NEXECREGS*8 bytes, aligned to 16-byte */ + stp fp, lr, [sp, #-(16 + ((NEXECREGS*8 + 15)/16)*16)]! + + /* store registers to buffer on stack */ + stp x0, x1, [sp, #16] /* order matches execregs.h */ + /* x2: ps_strings */ + stp x3, x4, [sp, #(16 + 1*2*8)] + stp x5, x6, [sp, #(16 + 2*2*8)] + stp x7, x8, [sp, #(16 + 3*2*8)] + stp x9, x10, [sp, #(16 + 4*2*8)] + stp x11, x12, [sp, #(16 + 5*2*8)] + stp x13, x14, [sp, #(16 + 6*2*8)] + stp x15, x16, [sp, #(16 + 7*2*8)] + stp x17, x18, [sp, #(16 + 8*2*8)] + stp x19, x20, [sp, #(16 + 9*2*8)] + stp x21, x22, [sp, #(16 + 10*2*8)] + stp x23, x24, [sp, #(16 + 11*2*8)] + stp x25, x26, [sp, #(16 + 12*2*8)] + stp x27, x28, [sp, #(16 + 13*2*8)] + stp x29, x30, [sp, #(16 + 14*2*8)] + mrs x0, tpidr_el0 + str x0, [sp, #(16 + 15*2*8)] + + /* call write(STDOUT_FILENO, regs, sizeof(regs)) */ + mov x0, #1 /* arg0 := STDOUT_FILENO */ + add x1, sp, #16 /* arg1 := regs */ + mov x2, #(NEXECREGS*8) /* arg2 := sizeof(regs) */ + svc #SYS_write + + b.cs 2f /* bail if write failed */ + cmp x0, #(NEXECREGS*8) /* bail if wrote wrong # of bytes */ + b.ne 2f + + /* call exit(0) */ + mov x0, #0 /* arg0 := 0 */ +1: svc #SYS_exit + brk #0xffff /* paranoia */ + +2: /* call exit(127) */ + mov x0, #127 /* arg0 := 127 */ + b 1b +END(execregs_start) + +/* main stub to simplify linking */ +ENTRY(main) + brk #0xffff +END(main) diff --git a/kernel/arch/aarch64/signalsphandler.S b/kernel/arch/aarch64/signalsphandler.S new file mode 100644 index 000000000000..246ed383273d --- /dev/null +++ b/kernel/arch/aarch64/signalsphandler.S @@ -0,0 +1,46 @@ +/* $NetBSD: signalsphandler.S,v 1.2 2025/06/08 18:55:35 christos Exp $ */ + +/*- + * Copyright (c) 2025 The NetBSD Foundation, Inc. + * 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. + * + * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. 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 FOUNDATION 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. + */ + +#define _LOCORE + +#include <machine/asm.h> + +RCSID("$NetBSD: signalsphandler.S,v 1.2 2025/06/08 18:55:35 christos Exp $") + +/* + * signalsphandler(signo@x0) + * + * Signal handler. Store the stack pointer on entry at the global + * variable signalsp and return. + */ +ENTRY(signalsphandler) + mov x0, sp + adrp x1, _C_LABEL(signalsp) + str x0, [x1, :lo12:_C_LABEL(signalsp)] + ret +END(signalsphandler) diff --git a/kernel/arch/aarch64/stack_pointer.h b/kernel/arch/aarch64/stack_pointer.h new file mode 100644 index 000000000000..3bd7e6f65335 --- /dev/null +++ b/kernel/arch/aarch64/stack_pointer.h @@ -0,0 +1,42 @@ +/* $NetBSD: stack_pointer.h,v 1.2 2025/04/20 22:31:00 riastradh Exp $ */ + +/* + * Copyright (c) 2024 The NetBSD Foundation, Inc. + * 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. + * + * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. 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 FOUNDATION 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. + */ + +#ifndef TESTS_KERNEL_ARCH_AARCH64_STACK_POINTER_H +#define TESTS_KERNEL_ARCH_AARCH64_STACK_POINTER_H + +#define MISALIGN_SP \ + __asm__ volatile ( \ + "sub sp, sp, #8" \ + ) + +#define FIX_SP \ + __asm__ volatile ( \ + "add sp, sp, #8" \ + ) + +#endif /* TESTS_KERNEL_ARCH_AARCH64_STACK_POINTER_H */ diff --git a/kernel/arch/aarch64/threadspfunc.S b/kernel/arch/aarch64/threadspfunc.S new file mode 100644 index 000000000000..90f779d5e961 --- /dev/null +++ b/kernel/arch/aarch64/threadspfunc.S @@ -0,0 +1,43 @@ +/* $NetBSD: threadspfunc.S,v 1.1 2025/04/21 02:33:44 riastradh Exp $ */ + +/*- + * Copyright (c) 2025 The NetBSD Foundation, Inc. + * 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. + * + * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. 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 FOUNDATION 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. + */ + +#define _LOCORE + +#include <machine/asm.h> + +RCSID("$NetBSD: threadspfunc.S,v 1.1 2025/04/21 02:33:44 riastradh Exp $") + +/* + * void *threadspfunc(void *cookie@x0) + * + * pthread_create(3) function. Return the stack pointer on entry. + */ +ENTRY(threadspfunc) + mov x0, sp + ret +END(threadspfunc) |
