1 // Copyright 2015 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.
6 // System calls and other sys.stuff for riscv64, Linux
13 #define CLOCK_REALTIME 0
14 #define CLOCK_MONOTONIC 1
17 #define SYS_clock_gettime 113
20 #define SYS_connect 203
21 #define SYS_epoll_create1 20
22 #define SYS_epoll_ctl 21
23 #define SYS_epoll_pwait 22
25 #define SYS_exit_group 94
26 #define SYS_faccessat 48
29 #define SYS_getpid 172
30 #define SYS_gettid 178
31 #define SYS_gettimeofday 169
33 #define SYS_madvise 233
34 #define SYS_mincore 232
36 #define SYS_munmap 215
37 #define SYS_nanosleep 101
40 #define SYS_pselect6 72
42 #define SYS_rt_sigaction 134
43 #define SYS_rt_sigprocmask 135
44 #define SYS_rt_sigreturn 139
45 #define SYS_sched_getaffinity 123
46 #define SYS_sched_yield 124
47 #define SYS_setitimer 103
48 #define SYS_sigaltstack 132
49 #define SYS_socket 198
50 #define SYS_tgkill 131
51 #define SYS_timer_create 107
52 #define SYS_timer_delete 111
53 #define SYS_timer_settime 110
57 // func exit(code int32)
58 TEXT runtime·exit(SB),NOSPLIT|NOFRAME,$0-4
60 MOV $SYS_exit_group, A7
64 // func exitThread(wait *uint32)
65 TEXT runtime·exitThread(SB),NOSPLIT|NOFRAME,$0-8
67 // We're done using the stack.
71 MOV $0, A0 // exit code
76 // func open(name *byte, mode, perm int32) int32
77 TEXT runtime·open(SB),NOSPLIT|NOFRAME,$0-20
90 // func closefd(fd int32) int32
91 TEXT runtime·closefd(SB),NOSPLIT|NOFRAME,$0-12
101 // func write1(fd uintptr, p unsafe.Pointer, n int32) int32
102 TEXT runtime·write1(SB),NOSPLIT|NOFRAME,$0-28
111 // func read(fd int32, p unsafe.Pointer, n int32) int32
112 TEXT runtime·read(SB),NOSPLIT|NOFRAME,$0-28
121 // func pipe2(flags int32) (r, w int32, errno int32)
122 TEXT runtime·pipe2(SB),NOSPLIT|NOFRAME,$0-20
127 MOVW A0, errno+16(FP)
130 // func usleep(usec uint32)
131 TEXT runtime·usleep(SB),NOSPLIT,$24-4
142 MOV $SYS_nanosleep, A7
146 // func gettid() uint32
147 TEXT runtime·gettid(SB),NOSPLIT,$0-4
153 // func raise(sig uint32)
154 TEXT runtime·raise(SB),NOSPLIT|NOFRAME,$0
157 // arg 1 tid - already in A0
158 MOVW sig+0(FP), A1 // arg 2
163 // func raiseproc(sig uint32)
164 TEXT runtime·raiseproc(SB),NOSPLIT|NOFRAME,$0
167 // arg 1 pid - already in A0
168 MOVW sig+0(FP), A1 // arg 2
174 TEXT ·getpid(SB),NOSPLIT|NOFRAME,$0-8
180 // func tgkill(tgid, tid, sig int)
181 TEXT ·tgkill(SB),NOSPLIT|NOFRAME,$0-24
189 // func setitimer(mode int32, new, old *itimerval)
190 TEXT runtime·setitimer(SB),NOSPLIT|NOFRAME,$0-24
194 MOV $SYS_setitimer, A7
198 // func timer_create(clockid int32, sevp *sigevent, timerid *int32) int32
199 TEXT runtime·timer_create(SB),NOSPLIT,$0-28
200 MOVW clockid+0(FP), A0
202 MOV timerid+16(FP), A2
203 MOV $SYS_timer_create, A7
208 // func timer_settime(timerid int32, flags int32, new, old *itimerspec) int32
209 TEXT runtime·timer_settime(SB),NOSPLIT,$0-28
210 MOVW timerid+0(FP), A0
214 MOV $SYS_timer_settime, A7
219 // func timer_delete(timerid int32) int32
220 TEXT runtime·timer_delete(SB),NOSPLIT,$0-12
221 MOVW timerid+0(FP), A0
222 MOV $SYS_timer_delete, A7
227 // func mincore(addr unsafe.Pointer, n uintptr, dst *byte) int32
228 TEXT runtime·mincore(SB),NOSPLIT|NOFRAME,$0-28
237 // func walltime() (sec int64, nsec int32)
238 TEXT runtime·walltime(SB),NOSPLIT,$40-12
239 MOV $CLOCK_REALTIME, A0
241 MOV runtime·vdsoClockgettimeSym(SB), A7
243 MOV X2, S2 // S2,S3,S4 is unchanged by C code
244 MOV g_m(g), S3 // S3 = m
246 // Save the old values on stack for reentrant
253 MOV $ret-8(FP), T1 // caller's SP
260 MOV (g_sched+gobuf_sp)(T1), X2
263 ADDI $-24, X2 // Space for result
264 ANDI $~7, X2 // Align for C code
267 // Store g on gsignal's stack, see sys_linux_arm64.s for detail
268 MOVBU runtime·iscgo(SB), S4
270 MOV m_gsignal(S3), S4 // g.m.gsignal
273 MOV (g_stack+stack_lo)(S4), S4 // g.m.gsignal.stack.lo
286 MOV 16(X2), T1 // nsec
288 MOV S2, X2 // restore stack
301 MOV $SYS_clock_gettime, A7
304 MOV 16(X2), T1 // nsec
309 // func nanotime1() int64
310 TEXT runtime·nanotime1(SB),NOSPLIT,$40-8
311 MOV $CLOCK_MONOTONIC, A0
313 MOV runtime·vdsoClockgettimeSym(SB), A7
316 MOV X2, S2 // S2 = RSP, S2 is unchanged by C code
317 MOV g_m(g), S3 // S3 = m
318 // Save the old values on stack for reentrant
325 MOV $ret-8(FP), T0 // caller's SP
332 MOV (g_sched+gobuf_sp)(T1), X2
335 ADDI $-24, X2 // Space for result
336 ANDI $~7, X2 // Align for C code
339 // Store g on gsignal's stack, see sys_linux_arm64.s for detail
340 MOVBU runtime·iscgo(SB), S4
342 MOV m_gsignal(S3), S4 // g.m.gsignal
345 MOV (g_stack+stack_lo)(S4), S4 // g.m.gsignal.stack.lo
358 MOV 16(X2), T1 // nsec
366 // sec is in T0, nsec in T1
376 MOV $SYS_clock_gettime, A7
379 MOV 16(X2), T1 // nsec
386 // func rtsigprocmask(how int32, new, old *sigset, size int32)
387 TEXT runtime·rtsigprocmask(SB),NOSPLIT|NOFRAME,$0-28
392 MOV $SYS_rt_sigprocmask, A7
399 // func rt_sigaction(sig uintptr, new, old *sigactiont, size uintptr) int32
400 TEXT runtime·rt_sigaction(SB),NOSPLIT|NOFRAME,$0-36
405 MOV $SYS_rt_sigaction, A7
410 // func sigfwd(fn uintptr, sig uint32, info *siginfo, ctx unsafe.Pointer)
411 TEXT runtime·sigfwd(SB),NOSPLIT,$0-32
419 // func sigtramp(signo, ureg, ctxt unsafe.Pointer)
420 TEXT runtime·sigtramp(SB),NOSPLIT,$64
425 // this might be called in external code context,
426 // where g is not set.
427 MOVBU runtime·iscgo(SB), A0
429 CALL runtime·load_g(SB)
431 MOV $runtime·sigtrampgo(SB), A0
435 // func cgoSigtramp()
436 TEXT runtime·cgoSigtramp(SB),NOSPLIT,$0
437 MOV $runtime·sigtramp(SB), T1
440 // func mmap(addr unsafe.Pointer, n uintptr, prot, flags, fd int32, off uint32) (p unsafe.Pointer, err int)
441 TEXT runtime·mmap(SB),NOSPLIT|NOFRAME,$0
445 MOVW flags+20(FP), A3
461 // func munmap(addr unsafe.Pointer, n uintptr)
462 TEXT runtime·munmap(SB),NOSPLIT|NOFRAME,$0
472 // func madvise(addr unsafe.Pointer, n uintptr, flags int32)
473 TEXT runtime·madvise(SB),NOSPLIT|NOFRAME,$0
476 MOVW flags+16(FP), A2
482 // func futex(addr unsafe.Pointer, op int32, val uint32, ts, addr2 unsafe.Pointer, val3 uint32) int32
483 TEXT runtime·futex(SB),NOSPLIT|NOFRAME,$0
495 // func clone(flags int32, stk, mp, gp, fn unsafe.Pointer) int32
496 TEXT runtime·clone(SB),NOSPLIT|NOFRAME,$0
500 // Copy mp, gp, fn off parent stack for use by child.
514 // In parent, return.
516 MOVW ZERO, ret+40(FP)
520 // In child, on new stack.
527 // Initialize m->procid to Linux tid
531 MOV -24(X2), T2 // fn
540 // In child, set up new stack
548 // It shouldn't return. If it does, exit this thread.
552 JMP -3(PC) // keep exiting
554 // func sigaltstack(new, old *stackt)
555 TEXT runtime·sigaltstack(SB),NOSPLIT|NOFRAME,$0
558 MOV $SYS_sigaltstack, A7
566 TEXT runtime·osyield(SB),NOSPLIT|NOFRAME,$0
567 MOV $SYS_sched_yield, A7
571 // func sched_getaffinity(pid, len uintptr, buf *uintptr) int32
572 TEXT runtime·sched_getaffinity(SB),NOSPLIT|NOFRAME,$0
576 MOV $SYS_sched_getaffinity, A7
581 // func epollcreate(size int32) int32
582 TEXT runtime·epollcreate(SB),NOSPLIT|NOFRAME,$0
584 MOV $SYS_epoll_create1, A7
589 // func epollcreate1(flags int32) int32
590 TEXT runtime·epollcreate1(SB),NOSPLIT|NOFRAME,$0
592 MOV $SYS_epoll_create1, A7
597 // func epollctl(epfd, op, fd int32, ev *epollevent) int32
598 TEXT runtime·epollctl(SB),NOSPLIT|NOFRAME,$0
603 MOV $SYS_epoll_ctl, A7
608 // func epollwait(epfd int32, ev *epollevent, nev, timeout int32) int32
609 TEXT runtime·epollwait(SB),NOSPLIT|NOFRAME,$0
613 MOVW timeout+20(FP), A3
615 MOV $SYS_epoll_pwait, A7
620 // func closeonexec(int32)
621 TEXT runtime·closeonexec(SB),NOSPLIT|NOFRAME,$0
622 MOVW fd+0(FP), A0 // fd
623 MOV $2, A1 // F_SETFD
624 MOV $1, A2 // FD_CLOEXEC
629 // func sbrk0() uintptr
630 TEXT runtime·sbrk0(SB),NOSPLIT,$0-8
631 // Implemented as brk(NULL).