Text file
src/runtime/sys_netbsd_arm.s
1 // Copyright 2013 The Go Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style
3 // license that can be found in the LICENSE file.
4 //
5 // System calls and other sys.stuff for ARM, NetBSD
6 // /usr/src/sys/kern/syscalls.master for syscall numbers.
7 //
8
9 #include "go_asm.h"
10 #include "go_tls.h"
11 #include "textflag.h"
12
13 #define CLOCK_REALTIME 0
14 #define CLOCK_MONOTONIC 3
15 #define FD_CLOEXEC 1
16 #define F_SETFD 2
17
18 #define SWI_OS_NETBSD 0xa00000
19 #define SYS_exit SWI_OS_NETBSD | 1
20 #define SYS_read SWI_OS_NETBSD | 3
21 #define SYS_write SWI_OS_NETBSD | 4
22 #define SYS_open SWI_OS_NETBSD | 5
23 #define SYS_close SWI_OS_NETBSD | 6
24 #define SYS_getpid SWI_OS_NETBSD | 20
25 #define SYS_kill SWI_OS_NETBSD | 37
26 #define SYS_munmap SWI_OS_NETBSD | 73
27 #define SYS_madvise SWI_OS_NETBSD | 75
28 #define SYS_fcntl SWI_OS_NETBSD | 92
29 #define SYS_mmap SWI_OS_NETBSD | 197
30 #define SYS___sysctl SWI_OS_NETBSD | 202
31 #define SYS___sigaltstack14 SWI_OS_NETBSD | 281
32 #define SYS___sigprocmask14 SWI_OS_NETBSD | 293
33 #define SYS_getcontext SWI_OS_NETBSD | 307
34 #define SYS_setcontext SWI_OS_NETBSD | 308
35 #define SYS__lwp_create SWI_OS_NETBSD | 309
36 #define SYS__lwp_exit SWI_OS_NETBSD | 310
37 #define SYS__lwp_self SWI_OS_NETBSD | 311
38 #define SYS__lwp_getprivate SWI_OS_NETBSD | 316
39 #define SYS__lwp_setprivate SWI_OS_NETBSD | 317
40 #define SYS__lwp_kill SWI_OS_NETBSD | 318
41 #define SYS__lwp_unpark SWI_OS_NETBSD | 321
42 #define SYS___sigaction_sigtramp SWI_OS_NETBSD | 340
43 #define SYS_kqueue SWI_OS_NETBSD | 344
44 #define SYS_sched_yield SWI_OS_NETBSD | 350
45 #define SYS___setitimer50 SWI_OS_NETBSD | 425
46 #define SYS___clock_gettime50 SWI_OS_NETBSD | 427
47 #define SYS___nanosleep50 SWI_OS_NETBSD | 430
48 #define SYS___kevent50 SWI_OS_NETBSD | 435
49 #define SYS____lwp_park60 SWI_OS_NETBSD | 478
50
51 // Exit the entire program (like C exit)
52 TEXT runtime·exit(SB),NOSPLIT|NOFRAME,$0
53 MOVW code+0(FP), R0 // arg 1 exit status
54 SWI $SYS_exit
55 MOVW.CS $0, R8 // crash on syscall failure
56 MOVW.CS R8, (R8)
57 RET
58
59 // func exitThread(wait *uint32)
60 TEXT runtime·exitThread(SB),NOSPLIT,$0-4
61 MOVW wait+0(FP), R0
62 // We're done using the stack.
63 MOVW $0, R2
64 storeloop:
65 LDREX (R0), R4 // loads R4
66 STREX R2, (R0), R1 // stores R2
67 CMP $0, R1
68 BNE storeloop
69 SWI $SYS__lwp_exit
70 MOVW $1, R8 // crash
71 MOVW R8, (R8)
72 JMP 0(PC)
73
74 TEXT runtime·open(SB),NOSPLIT|NOFRAME,$0
75 MOVW name+0(FP), R0
76 MOVW mode+4(FP), R1
77 MOVW perm+8(FP), R2
78 SWI $SYS_open
79 MOVW.CS $-1, R0
80 MOVW R0, ret+12(FP)
81 RET
82
83 TEXT runtime·closefd(SB),NOSPLIT|NOFRAME,$0
84 MOVW fd+0(FP), R0
85 SWI $SYS_close
86 MOVW.CS $-1, R0
87 MOVW R0, ret+4(FP)
88 RET
89
90 TEXT runtime·read(SB),NOSPLIT|NOFRAME,$0
91 MOVW fd+0(FP), R0
92 MOVW p+4(FP), R1
93 MOVW n+8(FP), R2
94 SWI $SYS_read
95 RSB.CS $0, R0 // caller expects negative errno
96 MOVW R0, ret+12(FP)
97 RET
98
99 // func pipe() (r, w int32, errno int32)
100 TEXT runtime·pipe(SB),NOSPLIT,$0-12
101 SWI $0xa0002a
102 BCC pipeok
103 MOVW $-1,R2
104 MOVW R2, r+0(FP)
105 MOVW R2, w+4(FP)
106 MOVW R0, errno+8(FP)
107 RET
108 pipeok:
109 MOVW $0, R2
110 MOVW R0, r+0(FP)
111 MOVW R1, w+4(FP)
112 MOVW R2, errno+8(FP)
113 RET
114
115 // func pipe2(flags int32) (r, w int32, errno int32)
116 TEXT runtime·pipe2(SB),NOSPLIT,$0-16
117 MOVW $r+4(FP), R0
118 MOVW flags+0(FP), R1
119 SWI $0xa001c5
120 MOVW R0, errno+12(FP)
121 RET
122
123 TEXT runtime·write1(SB),NOSPLIT|NOFRAME,$0
124 MOVW fd+0(FP), R0 // arg 1 - fd
125 MOVW p+4(FP), R1 // arg 2 - buf
126 MOVW n+8(FP), R2 // arg 3 - nbyte
127 SWI $SYS_write
128 RSB.CS $0, R0 // caller expects negative errno
129 MOVW R0, ret+12(FP)
130 RET
131
132 // int32 lwp_create(void *context, uintptr flags, void *lwpid)
133 TEXT runtime·lwp_create(SB),NOSPLIT,$0
134 MOVW ctxt+0(FP), R0
135 MOVW flags+4(FP), R1
136 MOVW lwpid+8(FP), R2
137 SWI $SYS__lwp_create
138 MOVW R0, ret+12(FP)
139 RET
140
141 TEXT runtime·osyield(SB),NOSPLIT,$0
142 SWI $SYS_sched_yield
143 RET
144
145 TEXT runtime·lwp_park(SB),NOSPLIT,$8
146 MOVW clockid+0(FP), R0 // arg 1 - clock_id
147 MOVW flags+4(FP), R1 // arg 2 - flags
148 MOVW ts+8(FP), R2 // arg 3 - ts
149 MOVW unpark+12(FP), R3 // arg 4 - unpark
150 MOVW hint+16(FP), R4 // arg 5 - hint
151 MOVW R4, 4(R13)
152 MOVW unparkhint+20(FP), R5 // arg 6 - unparkhint
153 MOVW R5, 8(R13)
154 SWI $SYS____lwp_park60
155 MOVW R0, ret+24(FP)
156 RET
157
158 TEXT runtime·lwp_unpark(SB),NOSPLIT,$0
159 MOVW lwp+0(FP), R0 // arg 1 - lwp
160 MOVW hint+4(FP), R1 // arg 2 - hint
161 SWI $SYS__lwp_unpark
162 MOVW R0, ret+8(FP)
163 RET
164
165 TEXT runtime·lwp_self(SB),NOSPLIT,$0
166 SWI $SYS__lwp_self
167 MOVW R0, ret+0(FP)
168 RET
169
170 TEXT runtime·lwp_tramp(SB),NOSPLIT,$0
171 MOVW R0, g_m(R1)
172 MOVW R1, g
173
174 BL runtime·emptyfunc(SB) // fault if stack check is wrong
175 BL (R2)
176 MOVW $2, R8 // crash (not reached)
177 MOVW R8, (R8)
178 RET
179
180 TEXT ·netbsdMstart(SB),NOSPLIT|TOPFRAME,$0
181 BL ·netbsdMstart0(SB)
182 RET // not reached
183
184 TEXT runtime·usleep(SB),NOSPLIT,$16
185 MOVW usec+0(FP), R0
186 CALL runtime·usplitR0(SB)
187 // 0(R13) is the saved LR, don't use it
188 MOVW R0, 4(R13) // tv_sec.low
189 MOVW $0, R0
190 MOVW R0, 8(R13) // tv_sec.high
191 MOVW $1000, R2
192 MUL R1, R2
193 MOVW R2, 12(R13) // tv_nsec
194
195 MOVW $4(R13), R0 // arg 1 - rqtp
196 MOVW $0, R1 // arg 2 - rmtp
197 SWI $SYS___nanosleep50
198 RET
199
200 TEXT runtime·lwp_kill(SB),NOSPLIT,$0-8
201 MOVW tid+0(FP), R0 // arg 1 - tid
202 MOVW sig+4(FP), R1 // arg 2 - signal
203 SWI $SYS__lwp_kill
204 RET
205
206 TEXT runtime·raiseproc(SB),NOSPLIT,$16
207 SWI $SYS_getpid // the returned R0 is arg 1
208 MOVW sig+0(FP), R1 // arg 2 - signal
209 SWI $SYS_kill
210 RET
211
212 TEXT runtime·setitimer(SB),NOSPLIT|NOFRAME,$0
213 MOVW mode+0(FP), R0 // arg 1 - which
214 MOVW new+4(FP), R1 // arg 2 - itv
215 MOVW old+8(FP), R2 // arg 3 - oitv
216 SWI $SYS___setitimer50
217 RET
218
219 // func walltime() (sec int64, nsec int32)
220 TEXT runtime·walltime(SB), NOSPLIT, $32
221 MOVW $0, R0 // CLOCK_REALTIME
222 MOVW $8(R13), R1
223 SWI $SYS___clock_gettime50
224
225 MOVW 8(R13), R0 // sec.low
226 MOVW 12(R13), R1 // sec.high
227 MOVW 16(R13), R2 // nsec
228
229 MOVW R0, sec_lo+0(FP)
230 MOVW R1, sec_hi+4(FP)
231 MOVW R2, nsec+8(FP)
232 RET
233
234 // int64 nanotime1(void) so really
235 // void nanotime1(int64 *nsec)
236 TEXT runtime·nanotime1(SB), NOSPLIT, $32
237 MOVW $3, R0 // CLOCK_MONOTONIC
238 MOVW $8(R13), R1
239 SWI $SYS___clock_gettime50
240
241 MOVW 8(R13), R0 // sec.low
242 MOVW 12(R13), R4 // sec.high
243 MOVW 16(R13), R2 // nsec
244
245 MOVW $1000000000, R3
246 MULLU R0, R3, (R1, R0)
247 MUL R3, R4
248 ADD.S R2, R0
249 ADC R4, R1
250
251 MOVW R0, ret_lo+0(FP)
252 MOVW R1, ret_hi+4(FP)
253 RET
254
255 TEXT runtime·getcontext(SB),NOSPLIT|NOFRAME,$0
256 MOVW ctxt+0(FP), R0 // arg 1 - context
257 SWI $SYS_getcontext
258 MOVW.CS $0, R8 // crash on syscall failure
259 MOVW.CS R8, (R8)
260 RET
261
262 TEXT runtime·sigprocmask(SB),NOSPLIT,$0
263 MOVW how+0(FP), R0 // arg 1 - how
264 MOVW new+4(FP), R1 // arg 2 - set
265 MOVW old+8(FP), R2 // arg 3 - oset
266 SWI $SYS___sigprocmask14
267 MOVW.CS $0, R8 // crash on syscall failure
268 MOVW.CS R8, (R8)
269 RET
270
271 TEXT sigreturn_tramp<>(SB),NOSPLIT|NOFRAME,$0
272 // on entry, SP points to siginfo, we add sizeof(ucontext)
273 // to SP to get a pointer to ucontext.
274 ADD $0x80, R13, R0 // 0x80 == sizeof(UcontextT)
275 SWI $SYS_setcontext
276 // something failed, we have to exit
277 MOVW $0x4242, R0 // magic return number
278 SWI $SYS_exit
279 B -2(PC) // continue exit
280
281 TEXT runtime·sigaction(SB),NOSPLIT,$4
282 MOVW sig+0(FP), R0 // arg 1 - signum
283 MOVW new+4(FP), R1 // arg 2 - nsa
284 MOVW old+8(FP), R2 // arg 3 - osa
285 MOVW $sigreturn_tramp<>(SB), R3 // arg 4 - tramp
286 MOVW $2, R4 // arg 5 - vers
287 MOVW R4, 4(R13)
288 ADD $4, R13 // pass arg 5 on stack
289 SWI $SYS___sigaction_sigtramp
290 SUB $4, R13
291 MOVW.CS $3, R8 // crash on syscall failure
292 MOVW.CS R8, (R8)
293 RET
294
295 TEXT runtime·sigfwd(SB),NOSPLIT,$0-16
296 MOVW sig+4(FP), R0
297 MOVW info+8(FP), R1
298 MOVW ctx+12(FP), R2
299 MOVW fn+0(FP), R11
300 MOVW R13, R4
301 SUB $24, R13
302 BIC $0x7, R13 // alignment for ELF ABI
303 BL (R11)
304 MOVW R4, R13
305 RET
306
307 TEXT runtime·sigtramp(SB),NOSPLIT,$0
308 // Reserve space for callee-save registers and arguments.
309 MOVM.DB.W [R4-R11], (R13)
310 SUB $16, R13
311
312 // this might be called in external code context,
313 // where g is not set.
314 // first save R0, because runtime·load_g will clobber it
315 MOVW R0, 4(R13) // signum
316 MOVB runtime·iscgo(SB), R0
317 CMP $0, R0
318 BL.NE runtime·load_g(SB)
319
320 MOVW R1, 8(R13)
321 MOVW R2, 12(R13)
322 BL runtime·sigtrampgo(SB)
323
324 // Restore callee-save registers.
325 ADD $16, R13
326 MOVM.IA.W (R13), [R4-R11]
327
328 RET
329
330 TEXT runtime·mmap(SB),NOSPLIT,$12
331 MOVW addr+0(FP), R0 // arg 1 - addr
332 MOVW n+4(FP), R1 // arg 2 - len
333 MOVW prot+8(FP), R2 // arg 3 - prot
334 MOVW flags+12(FP), R3 // arg 4 - flags
335 // arg 5 (fid) and arg6 (offset_lo, offset_hi) are passed on stack
336 // note the C runtime only passes the 32-bit offset_lo to us
337 MOVW fd+16(FP), R4 // arg 5
338 MOVW R4, 4(R13)
339 MOVW off+20(FP), R5 // arg 6 lower 32-bit
340 MOVW R5, 8(R13)
341 MOVW $0, R6 // higher 32-bit for arg 6
342 MOVW R6, 12(R13)
343 ADD $4, R13 // pass arg 5 and arg 6 on stack
344 SWI $SYS_mmap
345 SUB $4, R13
346 MOVW $0, R1
347 MOVW.CS R0, R1 // if error, move to R1
348 MOVW.CS $0, R0
349 MOVW R0, p+24(FP)
350 MOVW R1, err+28(FP)
351 RET
352
353 TEXT runtime·munmap(SB),NOSPLIT,$0
354 MOVW addr+0(FP), R0 // arg 1 - addr
355 MOVW n+4(FP), R1 // arg 2 - len
356 SWI $SYS_munmap
357 MOVW.CS $0, R8 // crash on syscall failure
358 MOVW.CS R8, (R8)
359 RET
360
361 TEXT runtime·madvise(SB),NOSPLIT,$0
362 MOVW addr+0(FP), R0 // arg 1 - addr
363 MOVW n+4(FP), R1 // arg 2 - len
364 MOVW flags+8(FP), R2 // arg 3 - behav
365 SWI $SYS_madvise
366 MOVW.CS $-1, R0
367 MOVW R0, ret+12(FP)
368 RET
369
370 TEXT runtime·sigaltstack(SB),NOSPLIT|NOFRAME,$0
371 MOVW new+0(FP), R0 // arg 1 - nss
372 MOVW old+4(FP), R1 // arg 2 - oss
373 SWI $SYS___sigaltstack14
374 MOVW.CS $0, R8 // crash on syscall failure
375 MOVW.CS R8, (R8)
376 RET
377
378 TEXT runtime·sysctl(SB),NOSPLIT,$8
379 MOVW mib+0(FP), R0 // arg 1 - name
380 MOVW miblen+4(FP), R1 // arg 2 - namelen
381 MOVW out+8(FP), R2 // arg 3 - oldp
382 MOVW size+12(FP), R3 // arg 4 - oldlenp
383 MOVW dst+16(FP), R4 // arg 5 - newp
384 MOVW R4, 4(R13)
385 MOVW ndst+20(FP), R4 // arg 6 - newlen
386 MOVW R4, 8(R13)
387 ADD $4, R13 // pass arg 5 and 6 on stack
388 SWI $SYS___sysctl
389 SUB $4, R13
390 MOVW R0, ret+24(FP)
391 RET
392
393 // int32 runtime·kqueue(void)
394 TEXT runtime·kqueue(SB),NOSPLIT,$0
395 SWI $SYS_kqueue
396 RSB.CS $0, R0
397 MOVW R0, ret+0(FP)
398 RET
399
400 // int32 runtime·kevent(int kq, Kevent *changelist, int nchanges, Kevent *eventlist, int nevents, Timespec *timeout)
401 TEXT runtime·kevent(SB),NOSPLIT,$8
402 MOVW kq+0(FP), R0 // kq
403 MOVW ch+4(FP), R1 // changelist
404 MOVW nch+8(FP), R2 // nchanges
405 MOVW ev+12(FP), R3 // eventlist
406 MOVW nev+16(FP), R4 // nevents
407 MOVW R4, 4(R13)
408 MOVW ts+20(FP), R4 // timeout
409 MOVW R4, 8(R13)
410 ADD $4, R13 // pass arg 5 and 6 on stack
411 SWI $SYS___kevent50
412 RSB.CS $0, R0
413 SUB $4, R13
414 MOVW R0, ret+24(FP)
415 RET
416
417 // void runtime·closeonexec(int32 fd)
418 TEXT runtime·closeonexec(SB),NOSPLIT,$0
419 MOVW fd+0(FP), R0 // fd
420 MOVW $F_SETFD, R1 // F_SETFD
421 MOVW $FD_CLOEXEC, R2 // FD_CLOEXEC
422 SWI $SYS_fcntl
423 RET
424
425 // func runtime·setNonblock(fd int32)
426 TEXT runtime·setNonblock(SB),NOSPLIT,$0-4
427 MOVW fd+0(FP), R0 // fd
428 MOVW $3, R1 // F_GETFL
429 MOVW $0, R2
430 SWI $0xa0005c // sys_fcntl
431 ORR $0x4, R0, R2 // O_NONBLOCK
432 MOVW fd+0(FP), R0 // fd
433 MOVW $4, R1 // F_SETFL
434 SWI $0xa0005c // sys_fcntl
435 RET
436
437 // TODO: this is only valid for ARMv7+
438 TEXT ·publicationBarrier(SB),NOSPLIT|NOFRAME,$0-0
439 B runtime·armPublicationBarrier(SB)
440
441 TEXT runtime·read_tls_fallback(SB),NOSPLIT|NOFRAME,$0
442 MOVM.WP [R1, R2, R3, R12], (R13)
443 SWI $SYS__lwp_getprivate
444 MOVM.IAW (R13), [R1, R2, R3, R12]
445 RET
446
View as plain text