-
Notifications
You must be signed in to change notification settings - Fork 0
/
crt.S
302 lines (293 loc) · 4.77 KB
/
crt.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
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
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
.global errno
.global _exit
.global _start
.global write
.bss
errno:
#if __SUNPRO_C
.size errno, 4
#else
.word
#endif
.text
_exit:
#if __aarch64__ && (__FreeBSD__ || __OpenBSD__)
mov w8, 1
svc 0
#elif __aarch64__ && __linux__
mov w8, 93
svc 0
#elif __aarch64__ && __NetBSD__
mov w17, 1
svc 0
#elif __amd64__ && (__FreeBSD__ || __NetBSD__ || __OpenBSD__ || __sun__)
mov $1, %eax
syscall
#elif __amd64__ && __linux__
mov $60, %eax
syscall
#elif __arm__ && (__FreeBSD__ || __linux__)
mov r7, #1
swi #0
#elif __arm__ && __NetBSD__
svc #0xa00001
#elif __i386__ && __linux__
mov 4(%esp), %ebx
mov $1, %eax
int $128
#elif __i386__ && __sun__
mov $1, %eax
int $145
#elif __powerpc64__ && __linux__
li %r0, 1
sc
#elif __riscv && __linux__
li a7, 93
scall
#elif __s390x__ && __linux__
lghi %r1, 1
svc 0
#endif
_start:
#if __aarch64__ && __FreeBSD__
add x1, x0, 8
ldr w0, [x0]
bl main
b _exit
#elif __aarch64__ && (__linux__ || __NetBSD__ || __OpenBSD__)
ldr w0, [sp]
add x1, sp, 8
bl main
b _exit
#elif __amd64__ && __FreeBSD__
lea 8(%rdi), %rsi
mov (%rdi), %edi
call main
mov %eax, %edi
call _exit
#elif __amd64__ && (__linux__ || __OpenBSD__ || __sun__)
mov (%rsp), %edi
lea 8(%rsp), %rsi
call main
mov %eax, %edi
call _exit
#elif __amd64__ && __NetBSD__
mov (%rbx), %rsi
mov -8(%rsi), %edi
call main
mov %eax, %edi
call _exit
#elif __arm__ && __FreeBSD__
ldr r0, [sp]
add r1, sp, #4
bl main
b _exit
#elif __arm__ && __linux__
pop {r0}
mov r1, sp
bl main
b _exit
#elif __arm__ && __NetBSD__
ldr r1, [r0]
ldr r0, [r0, #4]
bl main
b _exit
#elif __i386__ && (__linux__ || __sun__)
pop %eax
push %esp
push %eax
call main
push %eax
call _exit
#elif __powerpc64__ && __linux__
addis %r2, %r12, .TOC.-_start@ha
addi %r2, %r2, .TOC.-_start@l
lwz %r3, 0(%r1)
addi %r4, %r1, 8
stdu %r1, -128(%r1)
bl main
b _exit
#elif __riscv && __riscv_xlen == 64 && __linux__
.option push
.option norelax
la gp, __global_pointer$
.option pop
ld a0, 0(sp)
addi a1, sp, 8
call main
tail _exit
#elif __s390x__ && __linux__
lg %r2, 0(%r15)
la %r3, 8(%r15)
aghi %r15, -176
brasl %r14, main
j _exit
#else
#error target not supported
#endif
write:
#if __aarch64__ && __FreeBSD__
mov w8, 4
svc 0
bcs .Lerr
ret
#elif __aarch64__ && __linux__
mov w8, 64
svc 0
tbnz w0, 31, .Lerr
ret
#elif __aarch64__ && __NetBSD__
mov w17, 4
svc 0
bcs .Lerr
ret
#elif __aarch64__ && __OpenBSD__
mov w8, 4
svc 0
dsb nsh
isb
bcs .Lerr
ret
#elif __amd64__ && (__FreeBSD__ || __NetBSD__ || __OpenBSD__ || __sun__)
mov $4, %eax
syscall
jc .Lerr
ret
#elif __amd64__ && __linux__
mov $1, %eax
syscall
test %eax, %eax
js .Lerr
ret
#elif __arm__ && __FreeBSD__
mov ip, r7
mov r7, #4
swi #0
mov r7, ip
bxcc lr
#elif __arm__ && __linux__
push {r7}
mov r7, #4
swi #0
pop {r7}
cmp r0, #0
bxcc lr
#elif __arm__ && __NetBSD__
svc #0xa00004
bxcc lr
#elif __i386__ && __linux__
push %ebx
push %ecx
push %edx
mov 16(%esp), %ebx
mov 20(%esp), %ecx
mov 24(%esp), %edx
mov $4, %eax
int $128
pop %edx
pop %ecx
pop %ebx
test %eax, %eax
js .Lerr
ret
#elif __i386__ && __sun__
mov $4, %eax
int $145
jc .Lerr
ret
#elif __powerpc64__ && __linux__
li %r0, 4
sc
bso- .Lerr
blr
#elif __riscv && __linux__
li a7, 64
scall
bltz a0, .Lerr
ret
#elif __s390x__ && __linux__
lghi %r1, 4
svc 0
cgijl %r2, 0, .Lerr
br %r14
#endif
.Lerr:
#if __aarch64__ && (__FreeBSD__ || __NetBSD__ || __OpenBSD__)
adrp x1, errno
str w0, [x1, :lo12:errno]
mov w0, -1
ret
#elif __aarch64__ && __linux__
neg w0, w0
adrp x1, errno
str w0, [x1, :lo12:errno]
mov w0, -1
ret
#elif __amd64__ && (__FreeBSD__ || __NetBSD__ || __OpenBSD__ || __sun__)
mov %eax, errno
mov $-1, %eax
ret
#elif __amd64__ && __linux__
neg %eax
mov %eax, errno
mov $-1, %eax
ret
#elif __arm__ && (__FreeBSD__ || __linux__ || __NetBSD__)
movw r1, #:lower16:errno
movt r1, #:upper16:errno
str r0, [r1]
mov r0, #-1
bx lr
#elif __i386__ && __linux__
neg %eax
mov %eax, errno
mov $-1, %eax
ret
#elif __i386__ && __sun__
mov %eax, errno
mov $-1, %eax
ret
#elif __powerpc64__ && __linux__
lis %r4, errno@ha
addi %r4, %r4, errno@l
stw %r3, 0(%r4)
li %r3, -1
blr
#elif __riscv && __linux__
neg a0, a0
sw a0, errno, t1
li a0, -1
ret
#elif __s390x__ && __linux__
lcr %r2, %r2
strl %r2, errno
lhi %r2, -1
br %r14
#endif
#if __arm__
#include "div.asm"
#endif
#if __FreeBSD__
.section .note.ABI-tag, "a"
.long 8, 4, 1
.string "FreeBSD"
.long 0
#elif __NetBSD__
.section .note.netbsd.ident, "a"
.long 7, 4, 1
.string "NetBSD\0"
.long 0
#elif __OpenBSD__
.section .note.openbsd.ident, "a"
.long 8, 4, 1
.string "OpenBSD"
.long 0
#endif
#if __arm__ && __linux__
.type _exit, #function
.type write, #function
.type __aeabi_idiv, #function
.type __aeabi_idivmod, #function
.type __aeabi_uidiv, #function
.type __aeabi_uidivmod, #function
#endif