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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
|
/* $OpenBSD: md_init.h,v 1.4 2023/11/18 16:26:16 deraadt 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.
*/
#define MD_SECT_CALL_FUNC(section, func) \
__asm (".section "#section", \"ax\" \n" \
"call " # func "@plt \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" \
" 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" \
"/* 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");
#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" \
"_csu_abort: \n" \
" unimp \n" \
".previous");
|