summaryrefslogtreecommitdiff
path: root/lib/csu
diff options
context:
space:
mode:
authorDale Rahn <drahn@cvs.openbsd.org>2021-04-28 00:11:12 +0000
committerDale Rahn <drahn@cvs.openbsd.org>2021-04-28 00:11:12 +0000
commit67e981fcbce4c309fae5649efc4fb2144bf347ad (patch)
tree775ed3a5e002ec431974b6a4bff8263b725ee54c /lib/csu
parent8cc6543bade0617ef6dc028341657ad55cfd731e (diff)
Riscv64 csu support
Includes fixes pointed out by kettenis, jsg, naddy
Diffstat (limited to 'lib/csu')
-rw-r--r--lib/csu/riscv64/md_init.h156
1 files changed, 156 insertions, 0 deletions
diff --git a/lib/csu/riscv64/md_init.h b/lib/csu/riscv64/md_init.h
new file mode 100644
index 00000000000..83d3b4502c3
--- /dev/null
+++ b/lib/csu/riscv64/md_init.h
@@ -0,0 +1,156 @@
+/* $OpenBSD: md_init.h,v 1.1 2021/04/28 00:11:11 drahn Exp $ */
+/*
+ * Copyright (c) 2020 Dale Rahn <drahn@openbsd.org>
+ *
+ * Permission to use, copy, modify, and distribute this software for any
+ * purpose with or without fee is hereby granted, provided that the above
+ * copyright notice and this permission notice appear in all copies.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
+ * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
+ * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
+ * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
+ * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
+ * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
+ * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+ */
+
+#ifdef __PIC__
+#define MD_SECT_CALL_FUNC(section, func) \
+ __asm (".section "#section", \"ax\" \n" \
+ "call " # func "@plt \n" \
+" .previous")
+#else
+#define MD_SECT_CALL_FUNC(section, func) \
+ __asm (".section "#section", \"ax\" \n" \
+ "call " # func " \n" \
+" .previous")
+#endif
+
+#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" \
+ " addi sp, sp, -16 \n" \
+ " sd ra,8(sp) \n" \
+ " sd s0,0(sp) \n" \
+ " addi s0, sp, 16 \n" \
+ " /* fall thru */ \n" \
+ " .previous")
+
+
+#define MD_SECTION_EPILOGUE(sect) \
+ __asm ( \
+ ".section "#sect",\"ax\",%progbits \n" \
+ " ld ra, 8(sp) \n" \
+ " ld s0, 0(sp) \n" \
+ " addi sp, sp, 16 \n" \
+ " jr ra \n" \
+ " .previous")
+
+
+#define MD_CRT0_START \
+ __asm( \
+ ".text \n" \
+ " .align 0 \n" \
+ " .globl _start \n" \
+ " .globl __start \n" \
+ " .type _start, @function \n" \
+ " .type __start, @function \n" \
+ "_start: \n" \
+ "__start: \n" \
+ " mv a3, a2 # cleanup \n" \
+ "/* Get argc/argv/envp from stack */ \n" \
+ " ld a0, (sp) \n" \
+ " addi a1, sp, 0x8 \n" \
+ " slli t0, a0, 0x3 \n" \
+ " add a2, a1, t0 \n" \
+ " addi a2, a2, 0x8 \n" \
+ " \n" \
+ " addi sp, sp, -16 \n" \
+ " li t0, 0 \n" \
+ " sd t0,(sp) \n" \
+ " \n" \
+ " j ___start \n" \
+ " .size _start, .-_start \n" \
+ " .size __start, .-__start \n" \
+ ".previous");
+
+#ifdef __PIC__
+#define MD_RCRT0_START \
+ char **environ, *__progname; \
+ __asm( \
+ ".text \n" \
+ " .align 0 \n" \
+ " .globl _start \n" \
+ " .globl __start \n" \
+ " .type _start, @function \n" \
+ " .type __start, @function \n" \
+ "_start: \n" \
+ "__start: \n" \
+ " mv a0, sp \n" \
+ " mv fp, sp \n" \
+ " \n" \
+ " addi sp, sp, -(8+8+(16*8)) \n" \
+ " addi a1, sp, 4 \n" \
+ " \n" \
+ "1: auipc a2, %pcrel_hi(_DYNAMIC) \n" \
+ " addi a2, a2, %pcrel_lo(1b) \n" \
+ " \n" \
+ " call _dl_boot_bind \n" \
+ " \n" \
+ " mv sp, fp \n" \
+ " li fp, 0x0 \n" \
+ " \n" \
+ " li a3, 0x0 /* cleanup */ \n" \
+ "/* Get argc/argv/envp from stack */ \n" \
+ " ld a0, (sp) \n" \
+ " addi a1, sp, 0x0008 \n" \
+ " slli a2, a0, 0x3 \n" \
+ " add a2, a1, a2 \n" \
+ " addi a2, a2, 0x0008 \n" \
+ " \n" \
+ " j ___start \n" \
+ " .size _start, .-_start \n" \
+ " .size __start, .-__start \n" \
+ "_dl_exit: \n" \
+ " li t0, " STR(SYS_exit) " \n" \
+ " ecall \n" \
+ " unimp \n" \
+ ".previous");
+#else /* non-pic/pie */
+#define MD_RCRT0_START \
+ char **environ, *__progname; \
+ __asm( \
+ ".text \n" \
+ " .align 0 \n" \
+ " .globl _start \n" \
+ " .globl __start \n" \
+ " .type _start, @function \n" \
+ " .type __start, @function \n" \
+ "_start: \n" \
+ "__start: \n" \
+ " mv a0, sp \n" \
+ " li fp, 0x0 \n" \
+ " \n" \
+ " li a3, 0x0 /* cleanup */ \n" \
+ "/* Get argc/argv/envp from stack */ \n" \
+ " ld a0, (sp) \n" \
+ " addi a1, sp, 0x0008 \n" \
+ " slli a2, a0, 0x3 \n" \
+ " add a2, a1, a2 \n" \
+ " addi a2, a2, 0x0008 \n" \
+ " \n" \
+ " j ___start \n" \
+ " .size _start, .-_start \n" \
+ " .size __start, .-__start \n" \
+ "_dl_exit: \n" \
+ " li t0, " STR(SYS_exit) " \n" \
+ " ecall \n" \
+ " unimp \n" \
+
+ ".previous");
+#endif