aboutsummaryrefslogtreecommitdiff
path: root/lib/csu/amd64
diff options
context:
space:
mode:
Diffstat (limited to 'lib/csu/amd64')
-rw-r--r--lib/csu/amd64/Makefile9
-rw-r--r--lib/csu/amd64/Makefile.depend11
-rw-r--r--lib/csu/amd64/crt.h30
-rw-r--r--lib/csu/amd64/crt1_c.c30
-rw-r--r--lib/csu/amd64/crt1_s.S86
-rw-r--r--lib/csu/amd64/crti.S43
-rw-r--r--lib/csu/amd64/crtn.S35
7 files changed, 244 insertions, 0 deletions
diff --git a/lib/csu/amd64/Makefile b/lib/csu/amd64/Makefile
new file mode 100644
index 000000000000..80ae5484d662
--- /dev/null
+++ b/lib/csu/amd64/Makefile
@@ -0,0 +1,9 @@
+.PATH: ${.CURDIR:H}/common
+
+CFLAGS+= -I${.CURDIR}
+CFLAGS+= -fno-omit-frame-pointer
+
+CRT1SRC= crt1_s.S
+CRT1OBJ= crt1_c.o
+
+.include <bsd.lib.mk>
diff --git a/lib/csu/amd64/Makefile.depend b/lib/csu/amd64/Makefile.depend
new file mode 100644
index 000000000000..993ab0638f4a
--- /dev/null
+++ b/lib/csu/amd64/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/amd64/crt.h b/lib/csu/amd64/crt.h
new file mode 100644
index 000000000000..7ce1eb826905
--- /dev/null
+++ b/lib/csu/amd64/crt.h
@@ -0,0 +1,30 @@
+/*-
+ * 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 INIT_CALL_SEQ(func) "call " __STRING(func)
+
+#endif
diff --git a/lib/csu/amd64/crt1_c.c b/lib/csu/amd64/crt1_c.c
new file mode 100644
index 000000000000..85fe0309600c
--- /dev/null
+++ b/lib/csu/amd64/crt1_c.c
@@ -0,0 +1,30 @@
+/* LINTLIBRARY */
+/*-
+ * SPDX-License-Identifier: BSD-2-Clause
+ *
+ * Copyright 1996-1998 John D. Polstra.
+ * 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 <sys/cdefs.h>
+#include "csu_common.h"
diff --git a/lib/csu/amd64/crt1_s.S b/lib/csu/amd64/crt1_s.S
new file mode 100644
index 000000000000..3ceea9289330
--- /dev/null
+++ b/lib/csu/amd64/crt1_s.S
@@ -0,0 +1,86 @@
+/*-
+ * SPDX-License-Identifier: BSD-2-Clause
+ *
+ * Copyright (C) 2023 Dmitry Chagin <dchagin@FreeBSD.org>
+ *
+ * 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 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 AUTHOR 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 <machine/asm.h>
+
+
+ .text
+ .align 8
+
+ /*
+ * The program entry point
+ * %rdi %rsi
+ * void _start(char **ap, void (*cleanup)(void)) __dead2
+ */
+ .globl _start
+ .type _start, @function
+_start:
+ .cfi_startproc
+ .cfi_undefined %rip /* Terminate call chain. */
+ pushq %rbp /* Align stack, terminate call chain. */
+ .cfi_def_cfa_offset 8
+ movq %rsp, %rbp
+ .cfi_offset %rbp, -16
+ .cfi_def_cfa_register %rbp
+#ifdef GCRT
+ subq $16, %rsp
+#endif
+ movq %rsi, %rcx /* cleanup */
+ movslq (%rdi), %rax /* long *ap; tmpargc = *ap */
+ leaq 0x8(%rdi), %rsi /* argv = ap + 1 */
+ leaq 0x10(%rdi, %rax, 8), %rdx /* env = ap + 2 + tmpargc */
+ movl %eax, %edi /* argc = tmpargc */
+
+#ifdef PIC
+ /*
+ * XXX. %rip relative addressing is not intended for use in the
+ * large memory model due to the offset from %rip being limited
+ * to 32 bits.
+ */
+ leaq main@plt(%rip), %r8
+#else
+ movabsq $main, %r8
+#endif
+#ifdef GCRT
+ movabsq $eprol, %r9
+ movabsq $etext, %rax
+ movq %rax, (%rsp)
+ /*
+ * %edi %rsi %rdx %rcx %r8 %r9 (%rsp)
+ * __libc_start1_gcrt(argc, argv, env, cleanup, main, &eprol, &etext)
+ */
+ callq __libc_start1_gcrt
+eprol:
+#else
+ /* __libc_start1(argc, argv, env, cleanup, main) */
+ callq __libc_start1
+#endif
+ int3
+ .cfi_endproc
+ .size _start, . - _start
+
+ .section .note.GNU-stack,"",%progbits
diff --git a/lib/csu/amd64/crti.S b/lib/csu/amd64/crti.S
new file mode 100644
index 000000000000..9fc507e5fff5
--- /dev/null
+++ b/lib/csu/amd64/crti.S
@@ -0,0 +1,43 @@
+/*-
+ * Copyright 1996, 1997, 1998, 2000 John D. Polstra.
+ * 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 4
+ .globl _init
+ .type _init,@function
+_init:
+ pushq %rbp
+ movq %rsp,%rbp
+
+ .section .fini,"ax",@progbits
+ .align 4
+ .globl _fini
+ .type _fini,@function
+_fini:
+ pushq %rbp
+ movq %rsp,%rbp
+
+ .section .note.GNU-stack,"",%progbits
diff --git a/lib/csu/amd64/crtn.S b/lib/csu/amd64/crtn.S
new file mode 100644
index 000000000000..d6336688d4ce
--- /dev/null
+++ b/lib/csu/amd64/crtn.S
@@ -0,0 +1,35 @@
+/*-
+ * Copyright 1996, 1997, 1998, 2000 John D. Polstra.
+ * 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
+ popq %rbp
+ ret
+
+ .section .fini,"ax",@progbits
+ popq %rbp
+ ret
+
+ .section .note.GNU-stack,"",%progbits