forked from OP-TEE/optee_os
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathstart_rv64.S
61 lines (56 loc) · 1.32 KB
/
start_rv64.S
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
/* SPDX-License-Identifier: BSD-2-Clause */
/*
* Copyright 2022 Beijing ESWIN Computing Technology Co., Ltd.
*/
#include <asm.S>
#include <elf_common.h>
/*
* _ldelf_start() - Entry of ldelf
*
* See include/ldelf.h for details on TEE Core interaction.
*
* void _ldelf_start(struct ldelf_arg *arg);
*/
FUNC _ldelf_start , :
/*
* First ldelf needs to be relocated. The binary is compiled to
* contain only a minimal number of R_RISCV_RELATIVE relocations in
* read/write memory, leaving read-only and executable memory
* untouched.
*/
lla a1, reloc_end_rel
lw a3, 0(a1)
lla a1, reloc_begin_rel
lw a2, 0(a1)
add a2, a2, a1
add a3, a3, a1
beq a2, a3, 2f
lla a1, _ldelf_start /* Get the load offset */
/* Loop over the relocations (Elf64_Rela) and process all entries */
1:
ld t1, 0(a2) /* t1 = r_offset */
ld t2, 8(a2) /* t2 = r_info */
ld t3, 16(a2) /* t3 = r_addend */
addi a2, a2, 24
and t2, t2, 0xff
addi t4, zero, R_RISCV_RELATIVE
bne t2, t4, 3f
/* Update the pointer at r_offset + load offset */
add t1, a1, t1
ld t4, 0(t1)
add t4, t4, t3
add t4, t4, a1
sd t4, 0(t1)
ble a2, a3, 1b
2:
jal ldelf
addi a0, a0, 0
jal _ldelf_return
3:
addi a0, a0, 0
jal _ldelf_panic
reloc_begin_rel:
.word __reloc_begin - reloc_begin_rel
reloc_end_rel:
.word __reloc_end - reloc_end_rel
END_FUNC _ldelf_start