summaryrefslogtreecommitdiff
path: root/lib/csu
diff options
context:
space:
mode:
authorDale Rahn <drahn@cvs.openbsd.org>2004-01-08 14:59:16 +0000
committerDale Rahn <drahn@cvs.openbsd.org>2004-01-08 14:59:16 +0000
commit58b037aa2a117fe4c474549ee14e4c6bfbba585d (patch)
treef5d8f4fd6ca0aa5131b9bc178009e1cae0a1bae3 /lib/csu
parent6e07118b4073b7f92810dfdf7b6a0ea317d3ae5f (diff)
__init/__fini handling on ELF has not been correct. It is supposed to
be a section which code stubs (branches) can be added to initialize/destructor This adds MD stubs to allow this to operate as expected. should fix wine and behave according to ELF specs. ok miod@
Diffstat (limited to 'lib/csu')
-rw-r--r--lib/csu/alpha/Makefile4
-rw-r--r--lib/csu/alpha/md_init.h63
-rw-r--r--lib/csu/common_elf/crtbegin.c37
-rw-r--r--lib/csu/common_elf/crtbeginS.c18
-rw-r--r--lib/csu/common_elf/crtend.c8
-rw-r--r--lib/csu/common_elf/crtendS.c6
-rw-r--r--lib/csu/hppa/Makefile6
-rw-r--r--lib/csu/hppa/md_init.h70
-rw-r--r--lib/csu/i386/Makefile4
-rw-r--r--lib/csu/i386/md_init.h61
-rw-r--r--lib/csu/powerpc/Makefile2
-rw-r--r--lib/csu/powerpc/md_init.h62
-rw-r--r--lib/csu/sparc/Makefile4
-rw-r--r--lib/csu/sparc/md_init.h59
-rw-r--r--lib/csu/sparc64/Makefile4
-rw-r--r--lib/csu/sparc64/md_init.h59
16 files changed, 434 insertions, 33 deletions
diff --git a/lib/csu/alpha/Makefile b/lib/csu/alpha/Makefile
index 687ac1892da..f1aebe8ee1a 100644
--- a/lib/csu/alpha/Makefile
+++ b/lib/csu/alpha/Makefile
@@ -1,4 +1,4 @@
-# $OpenBSD: Makefile,v 1.13 2003/05/30 19:03:24 drahn Exp $
+# $OpenBSD: Makefile,v 1.14 2004/01/08 14:59:15 drahn Exp $
# $NetBSD: Makefile,v 1.6 1996/10/18 05:27:38 thorpej Exp $
CFLAGS+= -DLIBC_SCCS -DELFSIZE=64
@@ -7,7 +7,7 @@ SRCS= crt0.c crtbegin.c crtbeginS.c crtend.c crtendS.c
ELFDIR= ${.CURDIR}/../common_elf
.PATH: ${ELFDIR}
-CFLAGS+= -I${ELFDIR}
+CFLAGS+= -I${ELFDIR} -I${.CURDIR}
PICFLAG?=-fpic
diff --git a/lib/csu/alpha/md_init.h b/lib/csu/alpha/md_init.h
new file mode 100644
index 00000000000..020b05c3bff
--- /dev/null
+++ b/lib/csu/alpha/md_init.h
@@ -0,0 +1,63 @@
+/* $OpenBSD: md_init.h,v 1.1 2004/01/08 14:59:15 drahn Exp $ */
+/*-
+ * Copyright (c) 2001 Ross Harvey
+ * 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 by the NetBSD
+ * Foundation, Inc. and its contributors.
+ * 4. Neither the name of The NetBSD Foundation 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 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 MD_SECT_CALL_FUNC(section, func) \
+ __asm (".section "#section", \"ax\"\n" \
+ " jsr $26," #func " \n" \
+ " ldgp $29,0($26) \n" \
+ " .previous")
+
+#define MD_SECTION_PROLOGUE(sect, entry_pt) \
+ __asm ( \
+ ".section "#sect",\"ax\",@progbits \n" \
+ " .globl " #entry_pt " \n" \
+ " .type " #entry_pt ",@function \n" \
+ #entry_pt": \n" \
+ " ldgp $29, 0($27) \n" \
+ " lda $30, -16($30) \n" \
+ " stq $26, 0($30) \n" \
+ " stq $15, 8($30) \n" \
+ " .align 5 \n" \
+ " /* fall thru */ \n" \
+ " .previous")
+
+
+#define MD_SECTION_EPILOGUE(sect) \
+ __asm ( \
+ ".section "#sect",\"ax\",@progbits \n" \
+ " ldq $15, 8($30) \n" \
+ " ldq $26, 0($30) \n" \
+ " lda $30, 16($30) \n" \
+ " ret \n" \
+ " .previous")
diff --git a/lib/csu/common_elf/crtbegin.c b/lib/csu/common_elf/crtbegin.c
index cb7da3b2a14..6399d6c8075 100644
--- a/lib/csu/common_elf/crtbegin.c
+++ b/lib/csu/common_elf/crtbegin.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: crtbegin.c,v 1.6 2002/02/16 21:27:20 millert Exp $ */
+/* $OpenBSD: crtbegin.c,v 1.7 2004/01/08 14:59:15 drahn Exp $ */
/* $NetBSD: crtbegin.c,v 1.1 1996/09/12 16:59:03 cgd Exp $ */
/*
@@ -41,11 +41,12 @@
*/
#include <stdlib.h>
+#include "md_init.h"
#include "os-note-elf.h"
-static void (*__CTOR_LIST__[1])(void)
+static const void (*__CTOR_LIST__[1])(void)
__attribute__((section(".ctors"))) = { (void *)-1 }; /* XXX */
-static void (*__DTOR_LIST__[1])(void)
+static const void (*__DTOR_LIST__[1])(void)
__attribute__((section(".dtors"))) = { (void *)-1 }; /* XXX */
static void __dtors(void);
@@ -55,7 +56,7 @@ static void
__dtors()
{
unsigned long i = (unsigned long) __DTOR_LIST__[0];
- void (**p)(void);
+ void const (**p)(void);
if (i == -1) {
for (i = 1; __DTOR_LIST__[i] != NULL; i++)
@@ -70,17 +71,27 @@ __dtors()
static void
__ctors()
{
- void (**p)(void) = __CTOR_LIST__ + 1;
+ void const (**p)(void) = __CTOR_LIST__ + 1;
while (*p)
(**p++)();
}
-void __init(void) __attribute__((section(".init")));
-void __fini(void) __attribute__((section(".fini")));
+void __init(void);
+void __fini(void);
+static void __do_init(void);
+static void __do_fini(void);
+
+MD_SECTION_PROLOGUE(".init", __init);
+
+MD_SECTION_PROLOGUE(".fini", __fini);
+
+MD_SECT_CALL_FUNC(".init", __do_init);
+MD_SECT_CALL_FUNC(".fini", __do_fini);
+
void
-__init()
+__do_init()
{
static int initialized = 0;
@@ -90,18 +101,18 @@ __init()
*/
if (!initialized) {
initialized = 1;
- __ctors();
- }
+ (__ctors)();
- atexit(__fini);
+ atexit(__fini);
+ }
}
void
-__fini()
+__do_fini()
{
/*
* Call global destructors.
*/
- __dtors();
+ (__dtors)();
}
diff --git a/lib/csu/common_elf/crtbeginS.c b/lib/csu/common_elf/crtbeginS.c
index da66081dae3..08ec27bb21c 100644
--- a/lib/csu/common_elf/crtbeginS.c
+++ b/lib/csu/common_elf/crtbeginS.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: crtbeginS.c,v 1.4 2003/12/28 04:11:52 drahn Exp $ */
+/* $OpenBSD: crtbeginS.c,v 1.5 2004/01/08 14:59:15 drahn Exp $ */
/* $NetBSD: crtbegin.c,v 1.1 1996/09/12 16:59:03 cgd Exp $ */
/*
@@ -41,6 +41,7 @@
*/
#include <stdlib.h>
+#include "md_init.h"
static void (*__CTOR_LIST__[1])(void)
__attribute__((section(".ctors"))) = { (void *)-1 }; /* XXX */
@@ -76,9 +77,20 @@ __ctors(void)
(**p++)();
}
}
+void _init(void);
+void _fini(void);
+static void _do_init(void);
+static void _do_fini(void);
+
+MD_SECTION_PROLOGUE(".init", _init);
+
+MD_SECTION_PROLOGUE(".fini", _fini);
+
+MD_SECT_CALL_FUNC(".init", _do_init);
+MD_SECT_CALL_FUNC(".fini", _do_fini);
void
-_init(void)
+_do_init(void)
{
static int initialized = 0;
@@ -93,7 +105,7 @@ _init(void)
}
void
-_fini(void)
+_do_fini(void)
{
/*
* since the _init() function sets up the destructors to be called
diff --git a/lib/csu/common_elf/crtend.c b/lib/csu/common_elf/crtend.c
index e81d17481f2..484ca3cc5d3 100644
--- a/lib/csu/common_elf/crtend.c
+++ b/lib/csu/common_elf/crtend.c
@@ -1,13 +1,13 @@
-/* $OpenBSD: crtend.c,v 1.2 2002/02/16 21:27:20 millert Exp $ */
+/* $OpenBSD: crtend.c,v 1.3 2004/01/08 14:59:15 drahn Exp $ */
/* $NetBSD: crtend.c,v 1.1 1996/09/12 16:59:04 cgd Exp $ */
-#ifndef ECOFF_COMPAT
-
#include <sys/cdefs.h>
+#include "md_init.h"
static void (*__CTOR_LIST__[1])(void)
__attribute__((section(".ctors"))) = { (void *)0 }; /* XXX */
static void (*__DTOR_LIST__[1])(void)
__attribute__((section(".dtors"))) = { (void *)0 }; /* XXX */
-#endif /* !ECOFF_COMPAT */
+MD_SECTION_EPILOGUE(".init");
+MD_SECTION_EPILOGUE(".fini");
diff --git a/lib/csu/common_elf/crtendS.c b/lib/csu/common_elf/crtendS.c
index 264189126e8..dd957d071fc 100644
--- a/lib/csu/common_elf/crtendS.c
+++ b/lib/csu/common_elf/crtendS.c
@@ -1,9 +1,13 @@
-/* $OpenBSD: crtendS.c,v 1.2 2002/02/16 21:27:20 millert Exp $ */
+/* $OpenBSD: crtendS.c,v 1.3 2004/01/08 14:59:15 drahn Exp $ */
/* $NetBSD: crtend.c,v 1.1 1997/04/16 19:38:24 thorpej Exp $ */
#include <sys/cdefs.h>
+#include "md_init.h"
static void (*__CTOR_LIST__[1])(void)
__attribute__((section(".ctors"))) = { (void *)0 }; /* XXX */
static void (*__DTOR_LIST__[1])(void)
__attribute__((section(".dtors"))) = { (void *)0 }; /* XXX */
+
+MD_SECTION_EPILOGUE(".init");
+MD_SECTION_EPILOGUE(".fini");
diff --git a/lib/csu/hppa/Makefile b/lib/csu/hppa/Makefile
index 052e293925c..10626bf1de7 100644
--- a/lib/csu/hppa/Makefile
+++ b/lib/csu/hppa/Makefile
@@ -1,4 +1,4 @@
-# $OpenBSD: Makefile,v 1.3 2003/05/30 19:03:24 drahn Exp $
+# $OpenBSD: Makefile,v 1.4 2004/01/08 14:59:15 drahn Exp $
# from: @(#)Makefile 5.5 (Berkeley) 5/21/91
CFLAGS+= -DLIBC_SCCS
@@ -7,9 +7,9 @@ SRCS= crt0.c crtbegin.c crtbeginS.c crtend.c crtendS.c
ELFDIR= ${.CURDIR}/../common_elf
.PATH: ${ELFDIR}
-CFLAGS+= -I${ELFDIR}
+CFLAGS+= -I${ELFDIR} -I${.CURDIR}
-#PICFLAG?=-fPIC
+PICFLAG?=-fPIC -DPIC
all: ${OBJS}
diff --git a/lib/csu/hppa/md_init.h b/lib/csu/hppa/md_init.h
new file mode 100644
index 00000000000..6b405c59301
--- /dev/null
+++ b/lib/csu/hppa/md_init.h
@@ -0,0 +1,70 @@
+/* $OpenBSD: md_init.h,v 1.1 2004/01/08 14:59:15 drahn Exp $ */
+
+/*
+ * Copyright (c) 2003 Dale Rahn. 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.
+ */
+
+
+#ifdef PIC
+#define MD_SECT_CALL_FUNC(section, func) \
+ __asm (".section "#section",\"ax\",@progbits \n" \
+ " stw %r19,-32(%r30) \n" \
+ " stw %r4,-64(%r30) \n" \
+ " bl " #func ",%r2 \n" \
+ " copy %r19,%r4 \n" \
+ " copy %r4,%r19 \n" \
+ " .previous")
+#else
+#define MD_SECT_CALL_FUNC(section, func) \
+ __asm (".section .rodata \n" \
+ " .align 4 \n" \
+ "L$" #func " \n" \
+ " .word "#func " \n" \
+ " .previous \n" \
+ " .section "#section",\"ax\",@progbits \n" \
+ " ldil LR'L$" #func ",%r1 \n" \
+ " ldw RR'L$" #func "(%r1), %r31 \n" \
+ " ble 0(%sr4,%r31) \n" \
+ " copy %r31,%r2 \n" \
+ " .previous")
+#endif
+
+#define MD_SECTION_PROLOGUE(sect, entry_pt) \
+ __asm ( \
+ " .section "#sect",\"ax\",@progbits \n" \
+ " .EXPORT "#entry_pt",ENTRY,PRIV_LEV=3,ARGW0=NO,ARGW1=NO,ARGW2=NO,ARGW3=NO,RTNVAL=NO \n" \
+ " .align 4 \n" \
+ #entry_pt" \n" \
+ " stw %r2, -20(%r30) \n" \
+ " ldo 64(%r30),%r30 \n" \
+ " /* fall thru */ \n" \
+ " .previous")
+
+
+#define MD_SECTION_EPILOGUE(sect) \
+ __asm ( \
+ " .section "#sect",\"ax\",@progbits \n" \
+ " ldw -84(%r30),%r2 \n" \
+ " bv %r0(%r2) \n" \
+ " ldo -64(%r30),%r30 \n" \
+ " .previous")
diff --git a/lib/csu/i386/Makefile b/lib/csu/i386/Makefile
index 234e9f70a87..0155a11ac85 100644
--- a/lib/csu/i386/Makefile
+++ b/lib/csu/i386/Makefile
@@ -1,4 +1,4 @@
-# $OpenBSD: Makefile,v 1.8 2003/05/30 19:03:24 drahn Exp $
+# $OpenBSD: Makefile,v 1.9 2004/01/08 14:59:15 drahn Exp $
# from: @(#)Makefile 5.5 (Berkeley) 5/21/91
CFLAGS+= -DLIBC_SCCS -fno-omit-frame-pointer
@@ -7,7 +7,7 @@ SRCS= crt0.c crtbegin.c crtbeginS.c crtend.c crtendS.c
ELFDIR= ${.CURDIR}/../common_elf
.PATH: ${ELFDIR}
-CFLAGS+= -I${ELFDIR}
+CFLAGS+= -I${ELFDIR} -I${.CURDIR}
PICFLAG?=-fpic
diff --git a/lib/csu/i386/md_init.h b/lib/csu/i386/md_init.h
new file mode 100644
index 00000000000..852d46cd407
--- /dev/null
+++ b/lib/csu/i386/md_init.h
@@ -0,0 +1,61 @@
+/* $OpenBSD: md_init.h,v 1.1 2004/01/08 14:59:15 drahn Exp $ */
+
+/*-
+ * Copyright (c) 2001 Ross Harvey
+ * 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 by the NetBSD
+ * Foundation, Inc. and its contributors.
+ * 4. Neither the name of The NetBSD Foundation 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 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 MD_SECT_CALL_FUNC(section, func) \
+ __asm (".section "#section", \"ax\"\n" \
+ " call " #func "\n" \
+ " .previous")
+
+/*
+ * Align is after because we want the function to start at the first
+ * address of the section, but overall we want the section to be
+ * aligned by the align amount.
+ */
+#define MD_SECTION_PROLOGUE(sect, entry_pt) \
+ __asm ( \
+ ".section "#sect",\"ax\",@progbits \n" \
+ " .globl " #entry_pt " \n" \
+ " .type " #entry_pt ",@function \n" \
+ #entry_pt": \n" \
+ " .align 16 \n" \
+ " /* fall thru */ \n" \
+ " .previous")
+
+
+#define MD_SECTION_EPILOGUE(sect) \
+ __asm ( \
+ ".section "#sect",\"ax\",@progbits \n" \
+ " ret \n" \
+ " .previous")
diff --git a/lib/csu/powerpc/Makefile b/lib/csu/powerpc/Makefile
index 3d5a9b89d1a..47adc13a1d1 100644
--- a/lib/csu/powerpc/Makefile
+++ b/lib/csu/powerpc/Makefile
@@ -7,7 +7,7 @@ SRCS= crt0.c crtbegin.c crtbeginS.c crtend.c crtendS.c
ELFDIR= ${.CURDIR}/../common_elf
.PATH: ${ELFDIR}
-CFLAGS+= -I${ELFDIR}
+CFLAGS+= -I${ELFDIR} -I${.CURDIR}
PICFLAG?=-fpic
diff --git a/lib/csu/powerpc/md_init.h b/lib/csu/powerpc/md_init.h
new file mode 100644
index 00000000000..c7953143668
--- /dev/null
+++ b/lib/csu/powerpc/md_init.h
@@ -0,0 +1,62 @@
+/* $OpenBSD: md_init.h,v 1.1 2004/01/08 14:59:15 drahn Exp $ */
+
+/*-
+ * Copyright (c) 2001 Ross Harvey
+ * 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 by the NetBSD
+ * Foundation, Inc. and its contributors.
+ * 4. Neither the name of The NetBSD Foundation 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 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 MD_SECT_CALL_FUNC(section, func) \
+ __asm (".section "#section", \"ax\"\n" \
+ " bl " #func "\n" \
+ " .previous")
+
+#define MD_SECTION_PROLOGUE(sect, entry_pt) \
+ __asm ( \
+ ".section "#sect",\"ax\",@progbits \n" \
+ " .globl " #entry_pt " \n" \
+ " .type " #entry_pt ",@function \n" \
+ " .align 4 \n" \
+ #entry_pt": \n" \
+ " stwu %r1,-16(%r1) \n" \
+ " mflr %r0 \n" \
+ " stw %r0,12(%r1) \n" \
+ " /* fall thru */ \n" \
+ " .previous")
+
+
+#define MD_SECTION_EPILOGUE(sect) \
+ __asm ( \
+ ".section "#sect",\"ax\",@progbits \n" \
+ " lwz %r0,12(%r1) \n" \
+ " mtlr %r0 \n" \
+ " addi %r1,%r1,16 \n" \
+ " blr \n" \
+ " .previous")
diff --git a/lib/csu/sparc/Makefile b/lib/csu/sparc/Makefile
index 4da9d6b939d..541b3114020 100644
--- a/lib/csu/sparc/Makefile
+++ b/lib/csu/sparc/Makefile
@@ -1,4 +1,4 @@
-# $OpenBSD: Makefile,v 1.7 2003/05/30 19:03:24 drahn Exp $
+# $OpenBSD: Makefile,v 1.8 2004/01/08 14:59:15 drahn Exp $
# from: @(#)Makefile 5.5 (Berkeley) 5/21/91
CFLAGS+= -DLIBC_SCCS
@@ -7,7 +7,7 @@ SRCS= crt0.c crtbegin.c crtbeginS.c crtend.c crtendS.c
ELFDIR= ${.CURDIR}/../common_elf
.PATH: ${ELFDIR}
-CFLAGS+= -I${ELFDIR}
+CFLAGS+= -I${ELFDIR} -I${.CURDIR}
PICFLAG?=-fPIC
diff --git a/lib/csu/sparc/md_init.h b/lib/csu/sparc/md_init.h
new file mode 100644
index 00000000000..30c0116ede0
--- /dev/null
+++ b/lib/csu/sparc/md_init.h
@@ -0,0 +1,59 @@
+/* $OpenBSD: md_init.h,v 1.1 2004/01/08 14:59:15 drahn Exp $ */
+
+/*-
+ * Copyright (c) 2001 Ross Harvey
+ * 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 by the NetBSD
+ * Foundation, Inc. and its contributors.
+ * 4. Neither the name of The NetBSD Foundation 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 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 MD_SECT_CALL_FUNC(section, func) \
+ __asm (".section "#section", \"ax\" \n" \
+ " call " #func ", 0 \n" \
+ " nop \n" \
+ " .previous")
+
+#define MD_SECTION_PROLOGUE(sect, entry_pt) \
+ __asm ( \
+ ".section "#sect",\"ax\",@progbits \n" \
+ " .globl " #entry_pt " \n" \
+ " .type " #entry_pt ",@function \n" \
+ #entry_pt": \n" \
+ " save %sp, -96, %sp \n" \
+ " .align 4 \n" \
+ " /* fall thru */ \n" \
+ " .previous")
+
+
+#define MD_SECTION_EPILOGUE(sect) \
+ __asm ( \
+ ".section "#sect",\"ax\",@progbits \n" \
+ " ret \n" \
+ " restore \n" \
+ " .previous")
diff --git a/lib/csu/sparc64/Makefile b/lib/csu/sparc64/Makefile
index 27b8c5d3076..e63640416b8 100644
--- a/lib/csu/sparc64/Makefile
+++ b/lib/csu/sparc64/Makefile
@@ -1,4 +1,4 @@
-# $OpenBSD: Makefile,v 1.2 2003/05/30 19:03:24 drahn Exp $
+# $OpenBSD: Makefile,v 1.3 2004/01/08 14:59:15 drahn Exp $
# $NetBSD: Makefile,v 1.6 1996/10/18 05:27:38 thorpej Exp $
CFLAGS+= -DLIBC_SCCS -DELFSIZE=64
@@ -7,7 +7,7 @@ SRCS= crt0.c crtbegin.c crtbeginS.c crtend.c crtendS.c
ELFDIR= ${.CURDIR}/../common_elf
.PATH: ${ELFDIR}
-CFLAGS+= -I${ELFDIR}
+CFLAGS+= -I${ELFDIR} -I${.CURDIR}
PICFLAG?=-fpic
diff --git a/lib/csu/sparc64/md_init.h b/lib/csu/sparc64/md_init.h
new file mode 100644
index 00000000000..045199de0b9
--- /dev/null
+++ b/lib/csu/sparc64/md_init.h
@@ -0,0 +1,59 @@
+/* $OpenBSD: md_init.h,v 1.1 2004/01/08 14:59:15 drahn Exp $ */
+
+/*-
+ * Copyright (c) 2001 Ross Harvey
+ * 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 by the NetBSD
+ * Foundation, Inc. and its contributors.
+ * 4. Neither the name of The NetBSD Foundation 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 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 MD_SECT_CALL_FUNC(section, func) \
+ __asm (".section "#section", \"ax\" \n" \
+ " call " #func ", 0 \n" \
+ " nop \n" \
+ " .previous")
+
+#define MD_SECTION_PROLOGUE(sect, entry_pt) \
+ __asm ( \
+ ".section "#sect",\"ax\",@progbits \n" \
+ " .globl " #entry_pt " \n" \
+ " .type " #entry_pt ",@function \n" \
+ #entry_pt": \n" \
+ " save %sp, -192, %sp \n" \
+ " .align 4 \n" \
+ " /* fall thru */ \n" \
+ " .previous")
+
+
+#define MD_SECTION_EPILOGUE(sect) \
+ __asm ( \
+ ".section "#sect",\"ax\",@progbits \n" \
+ " ret \n" \
+ " restore \n" \
+ " .previous")