aboutsummaryrefslogtreecommitdiff
path: root/kernel/arch/sparc
diff options
context:
space:
mode:
authorEnji Cooper <ngie@FreeBSD.org>2026-02-15 01:57:42 +0000
committerEnji Cooper <ngie@FreeBSD.org>2026-02-15 02:12:44 +0000
commite8dbf2b6df199526a660f81de07d17925cfd8518 (patch)
treecd0c09449bea5df56ef67059e797737d70587070 /kernel/arch/sparc
parent56a7ce8416d181a2060d7a428aed9c3c6a431e6d (diff)
Diffstat (limited to 'kernel/arch/sparc')
-rw-r--r--kernel/arch/sparc/contextspfunc.S64
-rw-r--r--kernel/arch/sparc/execsp.S123
-rw-r--r--kernel/arch/sparc/signalsphandler.S62
-rw-r--r--kernel/arch/sparc/stack_pointer.h35
-rw-r--r--kernel/arch/sparc/threadspfunc.S45
5 files changed, 329 insertions, 0 deletions
diff --git a/kernel/arch/sparc/contextspfunc.S b/kernel/arch/sparc/contextspfunc.S
new file mode 100644
index 000000000000..a24185cabd73
--- /dev/null
+++ b/kernel/arch/sparc/contextspfunc.S
@@ -0,0 +1,64 @@
+/* $NetBSD: contextspfunc.S,v 1.1 2025/04/21 02:33:45 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: contextspfunc.S,v 1.1 2025/04/21 02:33:45 riastradh Exp $")
+
+#ifdef __PIC__
+#define SETHI(label, got, reg) \
+ set label, reg; /* reg := &label - &GOT */ \
+ ld [got + reg], reg /* reg := &label */
+#define LO(label, reg) \
+ reg
+#else
+#define SETHI(label, got, reg) \
+ sethi %hi(label), reg /* reg := &label - %lo(label) */
+#define LO(label, reg) \
+ reg + %lo(label)
+#endif
+
+ .text
+
+/*
+ * contextspfunc()
+ *
+ * makecontext(3) function. Store the stack pointer on entry at
+ * the global variable contextsp and call contextdone.
+ */
+ENTRY(contextspfunc)
+ /* Reminder: o6 is frame pointer, o7 + 8 is return address. */
+ PIC_PROLOGUE(%g1, %o5) /* g1 := &GOT, clobber o5 */
+ SETHI(_C_LABEL(contextsp), %g1, %o5) /* o5 := &contextsp */
+ call _C_LABEL(contextdone) /* jump to contextdone */
+ st %sp, [LO(_C_LABEL(contextsp), %o5)] /* contextsp := sp */
+ /* don't care what happens here, caller must never return */
+ ta 1 /* Tcc, trap always */
+END(contextspfunc)
diff --git a/kernel/arch/sparc/execsp.S b/kernel/arch/sparc/execsp.S
new file mode 100644
index 000000000000..4b225dd6d550
--- /dev/null
+++ b/kernel/arch/sparc/execsp.S
@@ -0,0 +1,123 @@
+/* $NetBSD: execsp.S,v 1.1 2025/04/20 22:33:41 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: execsp.S,v 1.1 2025/04/20 22:33:41 riastradh Exp $")
+
+#ifdef __PIC__
+#define SETHI(label, got, reg) \
+ set label, reg; /* reg := &label - &GOT */ \
+ ld [got + reg], reg /* reg := &label */
+#define LO(label, reg) \
+ reg
+#else
+#define SETHI(label, got, reg) \
+ sethi %hi(label), reg /* reg := &label - %lo(label) */
+#define LO(label, reg) \
+ reg + %lo(label)
+#endif
+
+ .text
+
+/*
+ * void execsp_start(struct ps_strings *ps_strings@g1,
+ * void *obj_main@g2, void (*cleanup@g3)(void))
+ *
+ * ELF entry point. Saves the stack pointer in startsp and defers
+ * to the usual csu __start routine.
+ */
+ENTRY(execsp_start)
+ PIC_PROLOGUE(%o1, %o2) /* o1 := GOT, clobber o2 */
+ SETHI(_C_LABEL(startsp), %o1, %o2) /* o2 := &startup */
+ call _C_LABEL(__start) /* jump to start via PLT */
+ st %sp, [LO(_C_LABEL(startsp), %o2)] /* startsp := sp */
+ /* don't care what happens here, caller must never return */
+ ta 1 /* Tcc, trap always */
+END(execsp_start)
+
+/*
+ * void execsp_ctor(void)
+ *
+ * ELF constructor. Saves the stack pointer in ctorsp and
+ * returns.
+ */
+ENTRY(execsp_ctor)
+ /* Reminder: o6 is frame pointer, o7 + 8 is return address. */
+ PIC_PROLOGUE(%g1, %o5) /* g1 := &GOT, clobber o5 */
+ SETHI(_C_LABEL(ctorsp), %g1, %o5) /* o5 := &ctorsp */
+ retl /* return to caller */
+ st %sp, [LO(_C_LABEL(ctorsp), %o5)] /* ctorsp := sp */
+END(execsp_ctor)
+
+ /* Make execsp_ctor a constructor. */
+ .pushsection .ctors,"aw",@progbits
+ .p2align 2
+ .long _C_LABEL(execsp_ctor)
+ .popsection
+
+/*
+ * int main(int argc@a0, char **argv@a1, ...)
+ *
+ * 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)
+ /* Reminder: o6 is frame pointer, o7 + 8 is return address. */
+ PIC_PROLOGUE(%g1, %o5) /* g1 := &GOT, clobber o5 */
+ SETHI(_C_LABEL(mainsp), %g1, %o5) /* o5 := &mainsp */
+ st %sp, [LO(_C_LABEL(mainsp), %o5)] /* mainsp := sp */
+ retl /* return to caller */
+ mov 0, %o0 /* return 0 */
+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)
+ /* Reminder: o6 is frame pointer, o7 + 8 is return address. */
+ PIC_PROLOGUE(%g1, %o5) /* g1 := &GOT, clobber o5 */
+ SETHI(_C_LABEL(dtorsp), %g1, %o5) /* o5 := &dtorsp - &GOT */
+ st %sp, [LO(_C_LABEL(dtorsp), %o5)] /* dtorsp := sp */
+ mov %o7, %o5 /* save return address */
+ call _C_LABEL(execsp_main) /* tail call to execsp_main */
+ mov %o5, %o7 /* restore return address */
+END(execsp_dtor)
+
+ /* Make execsp_ctor a destructor. */
+ .pushsection .dtors,"aw",@progbits
+ .p2align 2
+ .long _C_LABEL(execsp_dtor)
+ .popsection
diff --git a/kernel/arch/sparc/signalsphandler.S b/kernel/arch/sparc/signalsphandler.S
new file mode 100644
index 000000000000..187091d23c01
--- /dev/null
+++ b/kernel/arch/sparc/signalsphandler.S
@@ -0,0 +1,62 @@
+/* $NetBSD: signalsphandler.S,v 1.1 2025/04/20 22:33:41 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: signalsphandler.S,v 1.1 2025/04/20 22:33:41 riastradh Exp $")
+
+#ifdef __PIC__
+#define SETHI(label, got, reg) \
+ set label, reg; /* reg := &label - &GOT */ \
+ ld [got + reg], reg /* reg := &label */
+#define LO(label, reg) \
+ reg
+#else
+#define SETHI(label, got, reg) \
+ sethi %hi(label), reg /* reg := &label - %lo(label) */
+#define LO(label, reg) \
+ reg + %lo(label)
+#endif
+
+ .text
+
+/*
+ * signalsphandler(signo@o0)
+ *
+ * Signal handler. Store the stack pointer on entry at the global
+ * variable signalsp and return.
+ */
+ENTRY(signalsphandler)
+ /* Reminder: o6 is frame pointer, o7 + 8 is return address. */
+ PIC_PROLOGUE(%g1, %o5) /* g1 := &GOT, clobber o5 */
+ SETHI(_C_LABEL(signalsp), %g1, %o5) /* o5 := &signalsp */
+ retl /* return to caller */
+ st %sp, [LO(_C_LABEL(signalsp), %o5)] /* signalsp := sp */
+END(signalsphandler)
diff --git a/kernel/arch/sparc/stack_pointer.h b/kernel/arch/sparc/stack_pointer.h
new file mode 100644
index 000000000000..20c06bec77cd
--- /dev/null
+++ b/kernel/arch/sparc/stack_pointer.h
@@ -0,0 +1,35 @@
+/* $NetBSD: stack_pointer.h,v 1.1 2025/04/20 22:33:41 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_SPARC_STACK_POINTER_H
+#define TESTS_KERNEL_ARCH_SPARC_STACK_POINTER_H
+
+#define MISALIGN_SP __asm __volatile("dec %%sp" ::: "memory")
+#define FIX_SP __asm __volatile("inc %%sp" ::: "memory")
+
+#endif /* TESTS_KERNEL_ARCH_SPARC_STACK_POINTER_H */
diff --git a/kernel/arch/sparc/threadspfunc.S b/kernel/arch/sparc/threadspfunc.S
new file mode 100644
index 000000000000..794804d85741
--- /dev/null
+++ b/kernel/arch/sparc/threadspfunc.S
@@ -0,0 +1,45 @@
+/* $NetBSD: threadspfunc.S,v 1.1 2025/04/21 02:33:45 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:45 riastradh Exp $")
+
+ .text
+
+/*
+ * void *threadspfunc(void *cookie@o0)
+ *
+ * pthread_create(3) function. Return the stack pointer on entry.
+ */
+ENTRY(threadspfunc)
+ retl /* return to caller */
+ mov %sp, %o0 /* return sp */
+END(threadspfunc)