2 * Copyright (c) 2015-2018 Ruslan Bukin <br@bsdpad.com>
5 * This software was developed by SRI International and the University of
6 * Cambridge Computer Laboratory under DARPA/AFRL contract FA8750-10-C-0237
7 * ("CTSRD"), as part of the DARPA CRASH research programme.
9 * This software was developed by the University of Cambridge Computer
10 * Laboratory as part of the CTSRD Project, with support from the UK Higher
11 * Education Innovation Fund (HEIF).
13 * Redistribution and use in source and binary forms, with or without
14 * modification, are permitted provided that the following conditions
16 * 1. Redistributions of source code must retain the above copyright
17 * notice, this list of conditions and the following disclaimer.
18 * 2. Redistributions in binary form must reproduce the above copyright
19 * notice, this list of conditions and the following disclaimer in the
20 * documentation and/or other materials provided with the distribution.
22 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
23 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
24 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
25 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
26 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
27 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
28 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
29 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
30 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
31 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
35 #include <machine/asm.h>
36 __FBSDID("$FreeBSD$");
40 * _rtld(Elf_Addr *sp, func_ptr_type *exit_proc, Obj_Entry **objp)
44 mv s0, a0 /* Put ps_strings in a callee-saved register */
45 mv s1, sp /* And the stack pointer */
47 addi sp, sp, -16 /* Make room for obj_main & exit proc */
49 mv a1, sp /* exit_proc */
50 addi a2, a1, 8 /* obj_main */
51 jal _rtld /* Call the loader */
52 mv t0, a0 /* Backup the entry point */
54 ld a2, 0(sp) /* Load cleanup */
55 ld a1, 8(sp) /* Load obj_main */
56 mv a0, s0 /* Restore ps_strings */
57 mv sp, s1 /* Restore the stack pointer */
58 jr t0 /* Jump to the entry point */
65 ENTRY(_rtld_bind_start)
66 /* Save the arguments and ra */
67 /* We require 17 dwords, but the stack must be aligned to 16-bytes */
68 addi sp, sp, -(8 * 18)
79 #ifdef __riscv_float_abi_double
80 /* Save any floating-point arguments */
91 /* Reloc offset is 3x of the .got.plt offset */
92 slli a1, t1, 1 /* Mult items by 2 */
93 add a1, a1, t1 /* Plus item */
101 /* Backup the address to branch to */
104 /* Restore the arguments and ra */
115 #ifdef __riscv_float_abi_double
116 /* Restore floating-point arguments */
118 fld fa1, (8 * 10)(sp)
119 fld fa2, (8 * 11)(sp)
120 fld fa3, (8 * 12)(sp)
121 fld fa4, (8 * 13)(sp)
122 fld fa5, (8 * 14)(sp)
123 fld fa6, (8 * 15)(sp)
124 fld fa7, (8 * 16)(sp)
126 addi sp, sp, (8 * 18)
128 /* Call into the correct function */
130 END(_rtld_bind_start)