aboutsummaryrefslogtreecommitdiff
path: root/lib/csu/powerpc
diff options
context:
space:
mode:
Diffstat (limited to 'lib/csu/powerpc')
-rw-r--r--lib/csu/powerpc/Makefile5
-rw-r--r--lib/csu/powerpc/Makefile.depend11
-rw-r--r--lib/csu/powerpc/crt.h31
-rw-r--r--lib/csu/powerpc/crt1_c.c89
-rw-r--r--lib/csu/powerpc/crti.S49
-rw-r--r--lib/csu/powerpc/crtn.S44
-rw-r--r--lib/csu/powerpc/crtsavres.S189
7 files changed, 418 insertions, 0 deletions
diff --git a/lib/csu/powerpc/Makefile b/lib/csu/powerpc/Makefile
new file mode 100644
index 000000000000..b6928446d005
--- /dev/null
+++ b/lib/csu/powerpc/Makefile
@@ -0,0 +1,5 @@
+.PATH: ${.CURDIR:H}/common
+
+OBJS+= crtsavres.o
+
+.include <bsd.lib.mk>
diff --git a/lib/csu/powerpc/Makefile.depend b/lib/csu/powerpc/Makefile.depend
new file mode 100644
index 000000000000..993ab0638f4a
--- /dev/null
+++ b/lib/csu/powerpc/Makefile.depend
@@ -0,0 +1,11 @@
+# Autogenerated - do NOT edit!
+
+DIRDEPS = \
+ include \
+
+
+.include <dirdeps.mk>
+
+.if ${DEP_RELDIR} == ${_DEP_RELDIR}
+# local dependencies - needed for -jN in clean tree
+.endif
diff --git a/lib/csu/powerpc/crt.h b/lib/csu/powerpc/crt.h
new file mode 100644
index 000000000000..fd589b9adf37
--- /dev/null
+++ b/lib/csu/powerpc/crt.h
@@ -0,0 +1,31 @@
+/*-
+ * SPDX-License-Identifier: BSD-1-Clause
+ *
+ * Copyright 2018 Andrew Turner
+ *
+ * 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.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``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 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 _CRT_H_
+#define _CRT_H_
+
+#define HAVE_CTORS
+#define CTORS_CONSTRUCTORS
+#define INIT_CALL_SEQ(func) "bl " __STRING(func) "; nop"
+
+#endif
diff --git a/lib/csu/powerpc/crt1_c.c b/lib/csu/powerpc/crt1_c.c
new file mode 100644
index 000000000000..656ca9cde9ea
--- /dev/null
+++ b/lib/csu/powerpc/crt1_c.c
@@ -0,0 +1,89 @@
+/* LINTLIBRARY */
+/*-
+ * SPDX-License-Identifier: BSD-4-Clause
+ *
+ * Copyright 2001 David E. O'Brien.
+ * All rights reserved.
+ * Copyright 1996-1998 John D. Polstra.
+ * All rights reserved.
+ * Copyright (c) 1997 Jason R. Thorpe.
+ * Copyright (c) 1995 Christopher G. Demetriou
+ * 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. All advertising materials mentioning features or use of this software
+ * must display the following acknowledgement:
+ * This product includes software developed for the
+ * FreeBSD Project. See https://www.freebsd.org/ for
+ * information about FreeBSD.
+ * This product includes software developed for the
+ * NetBSD Project. See http://www.netbsd.org/ for
+ * information about NetBSD.
+ * 4. The name of the author may not be used to endorse or promote products
+ * derived from this software without specific prior written permission
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``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 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>
+#include <stdlib.h>
+
+#include "libc_private.h"
+#include "csu_common.h"
+
+struct Struct_Obj_Entry;
+struct ps_strings;
+
+struct ps_strings *__ps_strings;
+
+void _start(int, char **, char **, const struct Struct_Obj_Entry *,
+ void (*)(void), struct ps_strings *) __dead2;
+
+/* The entry function. */
+/*
+ * First 5 arguments are specified by the PowerPC SVR4 ABI.
+ * The last argument, ps_strings, is a BSD extension.
+ */
+/* ARGSUSED */
+void
+_start(int argc, char **argv, char **env,
+ const struct Struct_Obj_Entry *obj __unused, void (*cleanup)(void),
+ struct ps_strings *ps_strings)
+{
+ if (ps_strings != (struct ps_strings *)0)
+ __ps_strings = ps_strings;
+
+#ifdef GCRT
+ __libc_start1_gcrt(argc, argv, env, cleanup, main, &eprol, &etext);
+#else
+ __libc_start1(argc, argv, env, cleanup, main);
+#endif
+}
+
+#ifdef GCRT
+__asm__(".text");
+__asm__("eprol:");
+__asm__(".previous");
+#endif
+
+#ifndef PIC
+__asm__(".text\n"
+ "\t.global _GLOBAL_OFFSET_TABLE_\n"
+ "\t.reloc 0, R_PPC_NONE, _GLOBAL_OFFSET_TABLE_");
+#endif
diff --git a/lib/csu/powerpc/crti.S b/lib/csu/powerpc/crti.S
new file mode 100644
index 000000000000..25d0df585bb9
--- /dev/null
+++ b/lib/csu/powerpc/crti.S
@@ -0,0 +1,49 @@
+/*-
+ * Copyright 2001 David E. O'Brien
+ * 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 AUTHOR ``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 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 <machine/asm.h>
+ .section .init,"ax",@progbits
+ .align 2
+ .globl _init
+ .type _init,@function
+_init:
+ stwu 1,-16(1)
+ mflr 0
+ stw 31,12(1)
+ stw 0,20(1)
+ mr 31,1
+
+
+ .section .fini,"ax",@progbits
+ .align 2
+ .globl _fini
+_fini:
+ stwu 1,-16(1)
+ mflr 0
+ stw 31,12(1)
+ stw 0,20(1)
+ mr 31,1
+
+ .section .note.GNU-stack,"",%progbits
diff --git a/lib/csu/powerpc/crtn.S b/lib/csu/powerpc/crtn.S
new file mode 100644
index 000000000000..026cf4fe3e55
--- /dev/null
+++ b/lib/csu/powerpc/crtn.S
@@ -0,0 +1,44 @@
+/*-
+ * Copyright 2001 David E. O'Brien
+ * 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 AUTHOR ``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 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 <machine/asm.h>
+ .section .init,"ax",@progbits
+ lwz 11,0(1)
+ lwz 0,4(11)
+ mtlr 0
+ lwz 31,-4(11)
+ mr 1,11
+ blr
+
+
+ .section .fini,"ax",@progbits
+ lwz 11,0(1)
+ lwz 0,4(11)
+ mtlr 0
+ lwz 31,-4(11)
+ mr 1,11
+ blr
+
+ .section .note.GNU-stack,"",%progbits
diff --git a/lib/csu/powerpc/crtsavres.S b/lib/csu/powerpc/crtsavres.S
new file mode 100644
index 000000000000..95ac7171213f
--- /dev/null
+++ b/lib/csu/powerpc/crtsavres.S
@@ -0,0 +1,189 @@
+/*-
+ * SPDX-License-Identifier: BSD-1-Clause
+ *
+ * Copyright 2019 Justin Hibbits
+ *
+ * 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.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``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 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 <machine/asm.h>
+.text
+
+/*
+ * The PowerPC ABI spec requires the following save/restore functions to be
+ * provided:
+ *
+ * _savefpr_N
+ * _restfpr_N
+ * _restfpr_N_x
+ * _savegpr_N
+ * _restgpr_N
+ * _restgpr_N_x
+ *
+ * With N ranging from 14 to 31, to save the nonvolatile registers.
+ */
+
+#define _CRTENTRY(name) \
+ .text; \
+ .globl name; \
+ .type name,@function; \
+ name:
+
+#define SAVEFPR(r) _CRTENTRY(__CONCAT(_savefpr_,r)) \
+ stfd r,(-256 + r * 8)(11)
+
+SAVEFPR(14)
+SAVEFPR(15)
+SAVEFPR(16)
+SAVEFPR(17)
+SAVEFPR(18)
+SAVEFPR(19)
+SAVEFPR(20)
+SAVEFPR(21)
+SAVEFPR(22)
+SAVEFPR(23)
+SAVEFPR(24)
+SAVEFPR(25)
+SAVEFPR(26)
+SAVEFPR(27)
+SAVEFPR(28)
+SAVEFPR(29)
+SAVEFPR(30)
+SAVEFPR(31)
+ blr
+
+#define RESTFPR(r) _CRTENTRY(__CONCAT(_restfpr_,r)) \
+ lfd r,(-256 + r * 8)(11)
+
+RESTFPR(14)
+RESTFPR(15)
+RESTFPR(16)
+RESTFPR(17)
+RESTFPR(18)
+RESTFPR(19)
+RESTFPR(20)
+RESTFPR(21)
+RESTFPR(22)
+RESTFPR(23)
+RESTFPR(24)
+RESTFPR(25)
+RESTFPR(26)
+RESTFPR(27)
+RESTFPR(28)
+RESTFPR(29)
+RESTFPR(30)
+RESTFPR(31)
+ blr
+
+#define SAVEGPR(r) _CRTENTRY(__CONCAT(_savegpr_,r)) \
+ stw r,(-128 + r * 4)(11)
+
+SAVEGPR(14)
+SAVEGPR(15)
+SAVEGPR(16)
+SAVEGPR(17)
+SAVEGPR(18)
+SAVEGPR(19)
+SAVEGPR(20)
+SAVEGPR(21)
+SAVEGPR(22)
+SAVEGPR(23)
+SAVEGPR(24)
+SAVEGPR(25)
+SAVEGPR(26)
+SAVEGPR(27)
+SAVEGPR(28)
+SAVEGPR(29)
+SAVEGPR(30)
+SAVEGPR(31)
+ blr
+
+#define RESTGPR(r) _CRTENTRY(__CONCAT(_restgpr_,r)) \
+ lwz r,(-128 + r*4)(11)
+
+RESTGPR(14)
+RESTGPR(15)
+RESTGPR(16)
+RESTGPR(17)
+RESTGPR(18)
+RESTGPR(19)
+RESTGPR(20)
+RESTGPR(21)
+RESTGPR(22)
+RESTGPR(23)
+RESTGPR(24)
+RESTGPR(25)
+RESTGPR(26)
+RESTGPR(27)
+RESTGPR(28)
+RESTGPR(29)
+RESTGPR(30)
+RESTGPR(31)
+ blr
+
+#define RESTFPR_X(r) _CRTENTRY(__CONCAT(__CONCAT(_restfpr_,r),_x)) \
+ lfd r,(-256 + r * 8)(11)
+
+RESTFPR_X(14)
+RESTFPR_X(15)
+RESTFPR_X(16)
+RESTFPR_X(17)
+RESTFPR_X(18)
+RESTFPR_X(19)
+RESTFPR_X(20)
+RESTFPR_X(21)
+RESTFPR_X(22)
+RESTFPR_X(23)
+RESTFPR_X(24)
+RESTFPR_X(25)
+RESTFPR_X(26)
+RESTFPR_X(27)
+RESTFPR_X(28)
+RESTFPR_X(29)
+RESTFPR_X(30)
+RESTFPR_X(31)
+ lwz 0,4(11)
+ mtlr 0
+ mr 1,11
+ blr
+
+#define RESTGPR_X(r) _CRTENTRY(__CONCAT(__CONCAT(_restgpr_,r),_x)) \
+ lwz r,(-128 + r * 4)(11)
+
+RESTGPR_X(14)
+RESTGPR_X(15)
+RESTGPR_X(16)
+RESTGPR_X(17)
+RESTGPR_X(18)
+RESTGPR_X(19)
+RESTGPR_X(20)
+RESTGPR_X(21)
+RESTGPR_X(22)
+RESTGPR_X(23)
+RESTGPR_X(24)
+RESTGPR_X(25)
+RESTGPR_X(26)
+RESTGPR_X(27)
+RESTGPR_X(28)
+RESTGPR_X(29)
+RESTGPR_X(30)
+RESTGPR_X(31)
+ lwz 0,4(11)
+ mtlr 0
+ mr 1,11
+ blr