Text file
src/runtime/sys_freebsd_arm64.s
1 // Copyright 2019 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 //
6 // System calls and other sys.stuff for arm64, FreeBSD
7 // /usr/src/sys/kern/syscalls.master for syscall numbers.
8 //
9
10 #include "go_asm.h"
11 #include "go_tls.h"
12 #include "textflag.h"
13
14 #define CLOCK_REALTIME 0
15 #define CLOCK_MONOTONIC 4
16 #define FD_CLOEXEC 1
17 #define F_SETFD 2
18 #define F_GETFL 3
19 #define F_SETFL 4
20 #define O_NONBLOCK 4
21
22 #define SYS_exit 1
23 #define SYS_read 3
24 #define SYS_write 4
25 #define SYS_open 5
26 #define SYS_close 6
27 #define SYS_getpid 20
28 #define SYS_kill 37
29 #define SYS_sigaltstack 53
30 #define SYS_munmap 73
31 #define SYS_madvise 75
32 #define SYS_setitimer 83
33 #define SYS_fcntl 92
34 #define SYS___sysctl 202
35 #define SYS_nanosleep 240
36 #define SYS_clock_gettime 232
37 #define SYS_sched_yield 331
38 #define SYS_sigprocmask 340
39 #define SYS_kqueue 362
40 #define SYS_kevent 363
41 #define SYS_sigaction 416
42 #define SYS_thr_exit 431
43 #define SYS_thr_self 432
44 #define SYS_thr_kill 433
45 #define SYS__umtx_op 454
46 #define SYS_thr_new 455
47 #define SYS_mmap 477
48 #define SYS_cpuset_getaffinity 487
49 #define SYS_pipe2 542
50
51 TEXT emptyfunc<>(SB),0,$0-0
52 RET
53
54 // func sys_umtx_op(addr *uint32, mode int32, val uint32, uaddr1 uintptr, ut *umtx_time) int32
55 TEXT runtime·sys_umtx_op(SB),NOSPLIT,$0
56 MOVD addr+0(FP), R0
57 MOVW mode+8(FP), R1
58 MOVW val+12(FP), R2
59 MOVD uaddr1+16(FP), R3
60 MOVD ut+24(FP), R4
61 MOVD $SYS__umtx_op, R8
62 SVC
63 BCC ok
64 NEG R0, R0
65 ok:
66 MOVW R0, ret+32(FP)
67 RET
68
69 // func thr_new(param *thrparam, size int32) int32
70 TEXT runtime·thr_new(SB),NOSPLIT,$0
71 MOVD param+0(FP), R0
72 MOVW size+8(FP), R1
73 MOVD $SYS_thr_new, R8
74 SVC
75 BCC ok
76 NEG R0, R0
77 ok:
78 MOVW R0, ret+16(FP)
79 RET
80
81 // func thr_start()
82 TEXT runtime·thr_start(SB),NOSPLIT,$0
83 // set up g
84 MOVD m_g0(R0), g
85 MOVD R0, g_m(g)
86 BL emptyfunc<>(SB) // fault if stack check is wrong
87 BL runtime·mstart(SB)
88
89 MOVD $2, R8 // crash (not reached)
90 MOVD R8, (R8)
91 RET
92
93 // func exit(code int32)
94 TEXT runtime·exit(SB),NOSPLIT|NOFRAME,$0-4
95 MOVW code+0(FP), R0
96 MOVD $SYS_exit, R8
97 SVC
98 MOVD $0, R0
99 MOVD R0, (R0)
100
101 // func exitThread(wait *uint32)
102 TEXT runtime·exitThread(SB),NOSPLIT|NOFRAME,$0-8
103 MOVD wait+0(FP), R0
104 // We're done using the stack.
105 MOVW $0, R1
106 STLRW R1, (R0)
107 MOVW $0, R0
108 MOVD $SYS_thr_exit, R8
109 SVC
110 JMP 0(PC)
111
112 // func open(name *byte, mode, perm int32) int32
113 TEXT runtime·open(SB),NOSPLIT|NOFRAME,$0-20
114 MOVD name+0(FP), R0
115 MOVW mode+8(FP), R1
116 MOVW perm+12(FP), R2
117 MOVD $SYS_open, R8
118 SVC
119 BCC ok
120 MOVW $-1, R0
121 ok:
122 MOVW R0, ret+16(FP)
123 RET
124
125 // func closefd(fd int32) int32
126 TEXT runtime·closefd(SB),NOSPLIT|NOFRAME,$0-12
127 MOVW fd+0(FP), R0
128 MOVD $SYS_close, R8
129 SVC
130 BCC ok
131 MOVW $-1, R0
132 ok:
133 MOVW R0, ret+8(FP)
134 RET
135
136 // func pipe() (r, w int32, errno int32)
137 TEXT runtime·pipe(SB),NOSPLIT|NOFRAME,$0-12
138 MOVD $r+0(FP), R0
139 MOVW $0, R1
140 MOVD $SYS_pipe2, R8
141 SVC
142 BCC ok
143 NEG R0, R0
144 ok:
145 MOVW R0, errno+8(FP)
146 RET
147
148 // func pipe2(flags int32) (r, w int32, errno int32)
149 TEXT runtime·pipe2(SB),NOSPLIT|NOFRAME,$0-20
150 MOVD $r+8(FP), R0
151 MOVW flags+0(FP), R1
152 MOVD $SYS_pipe2, R8
153 SVC
154 BCC ok
155 NEG R0, R0
156 ok:
157 MOVW R0, errno+16(FP)
158 RET
159
160 // func write1(fd uintptr, p unsafe.Pointer, n int32) int32
161 TEXT runtime·write1(SB),NOSPLIT|NOFRAME,$0-28
162 MOVD fd+0(FP), R0
163 MOVD p+8(FP), R1
164 MOVW n+16(FP), R2
165 MOVD $SYS_write, R8
166 SVC
167 BCC ok
168 NEG R0, R0 // caller expects negative errno
169 ok:
170 MOVW R0, ret+24(FP)
171 RET
172
173 // func read(fd int32, p unsafe.Pointer, n int32) int32
174 TEXT runtime·read(SB),NOSPLIT|NOFRAME,$0-28
175 MOVW fd+0(FP), R0
176 MOVD p+8(FP), R1
177 MOVW n+16(FP), R2
178 MOVD $SYS_read, R8
179 SVC
180 BCC ok
181 NEG R0, R0 // caller expects negative errno
182 ok:
183 MOVW R0, ret+24(FP)
184 RET
185
186 // func usleep(usec uint32)
187 TEXT runtime·usleep(SB),NOSPLIT,$24-4
188 MOVWU usec+0(FP), R3
189 MOVD R3, R5
190 MOVW $1000000, R4
191 UDIV R4, R3
192 MOVD R3, 8(RSP)
193 MUL R3, R4
194 SUB R4, R5
195 MOVW $1000, R4
196 MUL R4, R5
197 MOVD R5, 16(RSP)
198
199 // nanosleep(&ts, 0)
200 ADD $8, RSP, R0
201 MOVD $0, R1
202 MOVD $SYS_nanosleep, R8
203 SVC
204 RET
205
206 // func thr_self() thread
207 TEXT runtime·thr_self(SB),NOSPLIT,$8-8
208 MOVD $ptr-8(SP), R0 // arg 1 &8(SP)
209 MOVD $SYS_thr_self, R8
210 SVC
211 MOVD ptr-8(SP), R0
212 MOVD R0, ret+0(FP)
213 RET
214
215 // func thr_kill(t thread, sig int)
216 TEXT runtime·thr_kill(SB),NOSPLIT,$0-16
217 MOVD tid+0(FP), R0 // arg 1 pid
218 MOVD sig+8(FP), R1 // arg 2 sig
219 MOVD $SYS_thr_kill, R8
220 SVC
221 RET
222
223 // func raiseproc(sig uint32)
224 TEXT runtime·raiseproc(SB),NOSPLIT|NOFRAME,$0
225 MOVD $SYS_getpid, R8
226 SVC
227 MOVW sig+0(FP), R1
228 MOVD $SYS_kill, R8
229 SVC
230 RET
231
232 // func setitimer(mode int32, new, old *itimerval)
233 TEXT runtime·setitimer(SB),NOSPLIT|NOFRAME,$0-24
234 MOVW mode+0(FP), R0
235 MOVD new+8(FP), R1
236 MOVD old+16(FP), R2
237 MOVD $SYS_setitimer, R8
238 SVC
239 RET
240
241 // func fallback_walltime() (sec int64, nsec int32)
242 TEXT runtime·fallback_walltime(SB),NOSPLIT,$24-12
243 MOVW $CLOCK_REALTIME, R0
244 MOVD $8(RSP), R1
245 MOVD $SYS_clock_gettime, R8
246 SVC
247 MOVD 8(RSP), R0 // sec
248 MOVW 16(RSP), R1 // nsec
249 MOVD R0, sec+0(FP)
250 MOVW R1, nsec+8(FP)
251 RET
252
253 // func fallback_nanotime() int64
254 TEXT runtime·fallback_nanotime(SB),NOSPLIT,$24-8
255 MOVD $CLOCK_MONOTONIC, R0
256 MOVD $8(RSP), R1
257 MOVD $SYS_clock_gettime, R8
258 SVC
259 MOVD 8(RSP), R0 // sec
260 MOVW 16(RSP), R2 // nsec
261
262 // sec is in R0, nsec in R2
263 // return nsec in R2
264 MOVD $1000000000, R3
265 MUL R3, R0
266 ADD R2, R0
267
268 MOVD R0, ret+0(FP)
269 RET
270
271 // func asmSigaction(sig uintptr, new, old *sigactiont) int32
272 TEXT runtime·asmSigaction(SB),NOSPLIT|NOFRAME,$0
273 MOVD sig+0(FP), R0 // arg 1 sig
274 MOVD new+8(FP), R1 // arg 2 act
275 MOVD old+16(FP), R2 // arg 3 oact
276 MOVD $SYS_sigaction, R8
277 SVC
278 BCC ok
279 MOVW $-1, R0
280 ok:
281 MOVW R0, ret+24(FP)
282 RET
283
284 // func sigfwd(fn uintptr, sig uint32, info *siginfo, ctx unsafe.Pointer)
285 TEXT runtime·sigfwd(SB),NOSPLIT,$0-32
286 MOVW sig+8(FP), R0
287 MOVD info+16(FP), R1
288 MOVD ctx+24(FP), R2
289 MOVD fn+0(FP), R11
290 BL (R11)
291 RET
292
293 // func sigtramp()
294 TEXT runtime·sigtramp(SB),NOSPLIT,$192
295 // Save callee-save registers in the case of signal forwarding.
296 // Please refer to https://golang.org/issue/31827 .
297 MOVD R19, 8*4(RSP)
298 MOVD R20, 8*5(RSP)
299 MOVD R21, 8*6(RSP)
300 MOVD R22, 8*7(RSP)
301 MOVD R23, 8*8(RSP)
302 MOVD R24, 8*9(RSP)
303 MOVD R25, 8*10(RSP)
304 MOVD R26, 8*11(RSP)
305 MOVD R27, 8*12(RSP)
306 MOVD g, 8*13(RSP)
307 MOVD R29, 8*14(RSP)
308 FMOVD F8, 8*15(RSP)
309 FMOVD F9, 8*16(RSP)
310 FMOVD F10, 8*17(RSP)
311 FMOVD F11, 8*18(RSP)
312 FMOVD F12, 8*19(RSP)
313 FMOVD F13, 8*20(RSP)
314 FMOVD F14, 8*21(RSP)
315 FMOVD F15, 8*22(RSP)
316
317 // this might be called in external code context,
318 // where g is not set.
319 // first save R0, because runtime·load_g will clobber it
320 MOVW R0, 8(RSP)
321 MOVBU runtime·iscgo(SB), R0
322 CMP $0, R0
323 BEQ 2(PC)
324 BL runtime·load_g(SB)
325
326 MOVD R1, 16(RSP)
327 MOVD R2, 24(RSP)
328 MOVD $runtime·sigtrampgo(SB), R0
329 BL (R0)
330
331 // Restore callee-save registers.
332 MOVD 8*4(RSP), R19
333 MOVD 8*5(RSP), R20
334 MOVD 8*6(RSP), R21
335 MOVD 8*7(RSP), R22
336 MOVD 8*8(RSP), R23
337 MOVD 8*9(RSP), R24
338 MOVD 8*10(RSP), R25
339 MOVD 8*11(RSP), R26
340 MOVD 8*12(RSP), R27
341 MOVD 8*13(RSP), g
342 MOVD 8*14(RSP), R29
343 FMOVD 8*15(RSP), F8
344 FMOVD 8*16(RSP), F9
345 FMOVD 8*17(RSP), F10
346 FMOVD 8*18(RSP), F11
347 FMOVD 8*19(RSP), F12
348 FMOVD 8*20(RSP), F13
349 FMOVD 8*21(RSP), F14
350 FMOVD 8*22(RSP), F15
351
352 RET
353
354 // func mmap(addr uintptr, n uintptr, prot int, flags int, fd int, off int64) (ret uintptr, err error)
355 TEXT runtime·mmap(SB),NOSPLIT|NOFRAME,$0
356 MOVD addr+0(FP), R0
357 MOVD n+8(FP), R1
358 MOVW prot+16(FP), R2
359 MOVW flags+20(FP), R3
360 MOVW fd+24(FP), R4
361 MOVW off+28(FP), R5
362 MOVD $SYS_mmap, R8
363 SVC
364 BCS fail
365 MOVD R0, p+32(FP)
366 MOVD $0, err+40(FP)
367 RET
368 fail:
369 MOVD $0, p+32(FP)
370 MOVD R0, err+40(FP)
371 RET
372
373 // func munmap(addr uintptr, n uintptr) (err error)
374 TEXT runtime·munmap(SB),NOSPLIT|NOFRAME,$0
375 MOVD addr+0(FP), R0
376 MOVD n+8(FP), R1
377 MOVD $SYS_munmap, R8
378 SVC
379 BCS fail
380 RET
381 fail:
382 MOVD $0, R0
383 MOVD R0, (R0) // crash
384
385 // func madvise(addr unsafe.Pointer, n uintptr, flags int32) int32
386 TEXT runtime·madvise(SB),NOSPLIT|NOFRAME,$0
387 MOVD addr+0(FP), R0
388 MOVD n+8(FP), R1
389 MOVW flags+16(FP), R2
390 MOVD $SYS_madvise, R8
391 SVC
392 BCC ok
393 MOVW $-1, R0
394 ok:
395 MOVW R0, ret+24(FP)
396 RET
397
398 // func sysctl(mib *uint32, miblen uint32, out *byte, size *uintptr, dst *byte, ndst uintptr) int32
399 TEXT runtime·sysctl(SB),NOSPLIT,$0
400 MOVD mib+0(FP), R0
401 MOVD miblen+8(FP), R1
402 MOVD out+16(FP), R2
403 MOVD size+24(FP), R3
404 MOVD dst+32(FP), R4
405 MOVD ndst+40(FP), R5
406 MOVD $SYS___sysctl, R8
407 SVC
408 BCC ok
409 NEG R0, R0
410 ok:
411 MOVW R0, ret+48(FP)
412 RET
413
414 // func sigaltstack(new, old *stackt)
415 TEXT runtime·sigaltstack(SB),NOSPLIT|NOFRAME,$0
416 MOVD new+0(FP), R0
417 MOVD old+8(FP), R1
418 MOVD $SYS_sigaltstack, R8
419 SVC
420 BCS fail
421 RET
422 fail:
423 MOVD $0, R0
424 MOVD R0, (R0) // crash
425
426 // func osyield()
427 TEXT runtime·osyield(SB),NOSPLIT|NOFRAME,$0
428 MOVD $SYS_sched_yield, R8
429 SVC
430 RET
431
432 // func sigprocmask(how int32, new, old *sigset)
433 TEXT runtime·sigprocmask(SB),NOSPLIT|NOFRAME,$0-24
434 MOVW how+0(FP), R0
435 MOVD new+8(FP), R1
436 MOVD old+16(FP), R2
437 MOVD $SYS_sigprocmask, R8
438 SVC
439 BCS fail
440 RET
441 fail:
442 MOVD $0, R0
443 MOVD R0, (R0) // crash
444
445 // func cpuset_getaffinity(level int, which int, id int64, size int, mask *byte) int32
446 TEXT runtime·cpuset_getaffinity(SB),NOSPLIT|NOFRAME,$0-44
447 MOVD level+0(FP), R0
448 MOVD which+8(FP), R1
449 MOVD id+16(FP), R2
450 MOVD size+24(FP), R3
451 MOVD mask+32(FP), R4
452 MOVD $SYS_cpuset_getaffinity, R8
453 SVC
454 BCC ok
455 MOVW $-1, R0
456 ok:
457 MOVW R0, ret+40(FP)
458 RET
459
460 // func kqueue() int32
461 TEXT runtime·kqueue(SB),NOSPLIT|NOFRAME,$0
462 MOVD $SYS_kqueue, R8
463 SVC
464 BCC ok
465 MOVW $-1, R0
466 ok:
467 MOVW R0, ret+0(FP)
468 RET
469
470 // func kevent(kq int, ch unsafe.Pointer, nch int, ev unsafe.Pointer, nev int, ts *Timespec) (n int, err error)
471 TEXT runtime·kevent(SB),NOSPLIT,$0
472 MOVW kq+0(FP), R0
473 MOVD ch+8(FP), R1
474 MOVW nch+16(FP), R2
475 MOVD ev+24(FP), R3
476 MOVW nev+32(FP), R4
477 MOVD ts+40(FP), R5
478 MOVD $SYS_kevent, R8
479 SVC
480 BCC ok
481 NEG R0, R0
482 ok:
483 MOVW R0, ret+48(FP)
484 RET
485
486 // func closeonexec(fd int32)
487 TEXT runtime·closeonexec(SB),NOSPLIT|NOFRAME,$0
488 MOVW fd+0(FP), R0
489 MOVD $F_SETFD, R1
490 MOVD $FD_CLOEXEC, R2
491 MOVD $SYS_fcntl, R8
492 SVC
493 RET
494
495 // func runtime·setNonblock(fd int32)
496 TEXT runtime·setNonblock(SB),NOSPLIT,$0-4
497 MOVW fd+0(FP), R0
498 MOVD $F_GETFL, R1
499 MOVD $0, R2
500 MOVD $SYS_fcntl, R8
501 SVC
502 ORR $O_NONBLOCK, R0, R2
503 MOVW fd+0(FP), R0
504 MOVW $F_SETFL, R1
505 MOVW $SYS_fcntl, R7
506 SVC
507 RET
508
509 // func getCntxct(physical bool) uint32
510 TEXT runtime·getCntxct(SB),NOSPLIT,$0
511 MOVB physical+0(FP), R0
512 CMP $0, R0
513 BEQ 3(PC)
514
515 // get CNTPCT (Physical Count Register) into R0
516 MRS CNTPCT_EL0, R0 // SIGILL
517 B 2(PC)
518
519 // get CNTVCT (Virtual Count Register) into R0
520 MRS CNTVCT_EL0, R0
521
522 MOVW R0, ret+8(FP)
523 RET
524
View as plain text