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
54 // func exit(code int32)
55 TEXT runtime·exit(SB),NOSPLIT|NOFRAME,$0-4
57 MOV $SYS_exit_group, A7
61 // func exitThread(wait *uint32)
62 TEXT runtime·exitThread(SB),NOSPLIT|NOFRAME,$0-8
64 // We're done using the stack.
68 MOV $0, A0 // exit code
73 // func open(name *byte, mode, perm int32) int32
74 TEXT runtime·open(SB),NOSPLIT|NOFRAME,$0-20
87 // func closefd(fd int32) int32
88 TEXT runtime·closefd(SB),NOSPLIT|NOFRAME,$0-12
98 // func write1(fd uintptr, p unsafe.Pointer, n int32) int32
99 TEXT runtime·write1(SB),NOSPLIT|NOFRAME,$0-28
108 // func read(fd int32, p unsafe.Pointer, n int32) int32
109 TEXT runtime·read(SB),NOSPLIT|NOFRAME,$0-28
118 // func pipe() (r, w int32, errno int32)
119 TEXT runtime·pipe(SB),NOSPLIT|NOFRAME,$0-12
127 // func pipe2(flags int32) (r, w int32, errno int32)
128 TEXT runtime·pipe2(SB),NOSPLIT|NOFRAME,$0-20
133 MOVW A0, errno+16(FP)
136 // func usleep(usec uint32)
137 TEXT runtime·usleep(SB),NOSPLIT,$24-4
148 MOV $SYS_nanosleep, A7
152 // func gettid() uint32
153 TEXT runtime·gettid(SB),NOSPLIT,$0-4
159 // func raise(sig uint32)
160 TEXT runtime·raise(SB),NOSPLIT|NOFRAME,$0
163 // arg 1 tid - already in A0
164 MOVW sig+0(FP), A1 // arg 2
169 // func raiseproc(sig uint32)
170 TEXT runtime·raiseproc(SB),NOSPLIT|NOFRAME,$0
173 // arg 1 pid - already in A0
174 MOVW sig+0(FP), A1 // arg 2
180 TEXT ·getpid(SB),NOSPLIT|NOFRAME,$0-8
186 // func tgkill(tgid, tid, sig int)
187 TEXT ·tgkill(SB),NOSPLIT|NOFRAME,$0-24
195 // func setitimer(mode int32, new, old *itimerval)
196 TEXT runtime·setitimer(SB),NOSPLIT|NOFRAME,$0-24
200 MOV $SYS_setitimer, A7
204 // func mincore(addr unsafe.Pointer, n uintptr, dst *byte) int32
205 TEXT runtime·mincore(SB),NOSPLIT|NOFRAME,$0-28
214 // func walltime() (sec int64, nsec int32)
215 TEXT runtime·walltime(SB),NOSPLIT,$40-12
216 MOV $CLOCK_REALTIME, A0
218 MOV runtime·vdsoClockgettimeSym(SB), A7
220 MOV X2, S2 // S2,S3,S4 is unchanged by C code
221 MOV g_m(g), S3 // S3 = m
223 // Save the old values on stack for reentrant
230 MOV $ret-8(FP), T1 // caller's SP
237 MOV (g_sched+gobuf_sp)(T1), X2
240 ADDI $-24, X2 // Space for result
241 ANDI $~7, X2 // Align for C code
244 // Store g on gsignal's stack, see sys_linux_arm64.s for detail
245 MOVBU runtime·iscgo(SB), S4
247 MOV m_gsignal(S3), S4 // g.m.gsignal
250 MOV (g_stack+stack_lo)(S4), S4 // g.m.gsignal.stack.lo
263 MOV 16(X2), T1 // nsec
265 MOV S2, X2 // restore stack
278 MOV $SYS_clock_gettime, A7
281 MOV 16(X2), T1 // nsec
286 // func nanotime1() int64
287 TEXT runtime·nanotime1(SB),NOSPLIT,$40-8
288 MOV $CLOCK_MONOTONIC, A0
290 MOV runtime·vdsoClockgettimeSym(SB), A7
293 MOV X2, S2 // S2 = RSP, S2 is unchanged by C code
294 MOV g_m(g), S3 // S3 = m
295 // Save the old values on stack for reentrant
302 MOV $ret-8(FP), T0 // caller's SP
309 MOV (g_sched+gobuf_sp)(T1), X2
312 ADDI $-24, X2 // Space for result
313 ANDI $~7, X2 // Align for C code
316 // Store g on gsignal's stack, see sys_linux_arm64.s for detail
317 MOVBU runtime·iscgo(SB), S4
319 MOV m_gsignal(S3), S4 // g.m.gsignal
322 MOV (g_stack+stack_lo)(S4), S4 // g.m.gsignal.stack.lo
335 MOV 16(X2), T1 // nsec
343 // sec is in T0, nsec in T1
353 MOV $SYS_clock_gettime, A7
356 MOV 16(X2), T1 // nsec
363 // func rtsigprocmask(how int32, new, old *sigset, size int32)
364 TEXT runtime·rtsigprocmask(SB),NOSPLIT|NOFRAME,$0-28
369 MOV $SYS_rt_sigprocmask, A7
376 // func rt_sigaction(sig uintptr, new, old *sigactiont, size uintptr) int32
377 TEXT runtime·rt_sigaction(SB),NOSPLIT|NOFRAME,$0-36
382 MOV $SYS_rt_sigaction, A7
387 // func sigfwd(fn uintptr, sig uint32, info *siginfo, ctx unsafe.Pointer)
388 TEXT runtime·sigfwd(SB),NOSPLIT,$0-32
396 // func sigtramp(signo, ureg, ctxt unsafe.Pointer)
397 TEXT runtime·sigtramp(SB),NOSPLIT,$64
402 // this might be called in external code context,
403 // where g is not set.
404 MOVBU runtime·iscgo(SB), A0
406 CALL runtime·load_g(SB)
408 MOV $runtime·sigtrampgo(SB), A0
412 // func cgoSigtramp()
413 TEXT runtime·cgoSigtramp(SB),NOSPLIT,$0
414 MOV $runtime·sigtramp(SB), T1
417 // func mmap(addr unsafe.Pointer, n uintptr, prot, flags, fd int32, off uint32) (p unsafe.Pointer, err int)
418 TEXT runtime·mmap(SB),NOSPLIT|NOFRAME,$0
422 MOVW flags+20(FP), A3
438 // func munmap(addr unsafe.Pointer, n uintptr)
439 TEXT runtime·munmap(SB),NOSPLIT|NOFRAME,$0
449 // func madvise(addr unsafe.Pointer, n uintptr, flags int32)
450 TEXT runtime·madvise(SB),NOSPLIT|NOFRAME,$0
453 MOVW flags+16(FP), A2
459 // func futex(addr unsafe.Pointer, op int32, val uint32, ts, addr2 unsafe.Pointer, val3 uint32) int32
460 TEXT runtime·futex(SB),NOSPLIT|NOFRAME,$0
472 // func clone(flags int32, stk, mp, gp, fn unsafe.Pointer) int32
473 TEXT runtime·clone(SB),NOSPLIT|NOFRAME,$0
477 // Copy mp, gp, fn off parent stack for use by child.
491 // In parent, return.
493 MOVW ZERO, ret+40(FP)
497 // In child, on new stack.
504 // Initialize m->procid to Linux tid
508 MOV -24(X2), T2 // fn
517 // In child, set up new stack
525 // It shouldn't return. If it does, exit this thread.
529 JMP -3(PC) // keep exiting
531 // func sigaltstack(new, old *stackt)
532 TEXT runtime·sigaltstack(SB),NOSPLIT|NOFRAME,$0
535 MOV $SYS_sigaltstack, A7
543 TEXT runtime·osyield(SB),NOSPLIT|NOFRAME,$0
544 MOV $SYS_sched_yield, A7
548 // func sched_getaffinity(pid, len uintptr, buf *uintptr) int32
549 TEXT runtime·sched_getaffinity(SB),NOSPLIT|NOFRAME,$0
553 MOV $SYS_sched_getaffinity, A7
558 // func epollcreate(size int32) int32
559 TEXT runtime·epollcreate(SB),NOSPLIT|NOFRAME,$0
561 MOV $SYS_epoll_create1, A7
566 // func epollcreate1(flags int32) int32
567 TEXT runtime·epollcreate1(SB),NOSPLIT|NOFRAME,$0
569 MOV $SYS_epoll_create1, A7
574 // func epollctl(epfd, op, fd int32, ev *epollevent) int32
575 TEXT runtime·epollctl(SB),NOSPLIT|NOFRAME,$0
580 MOV $SYS_epoll_ctl, A7
585 // func epollwait(epfd int32, ev *epollevent, nev, timeout int32) int32
586 TEXT runtime·epollwait(SB),NOSPLIT|NOFRAME,$0
590 MOVW timeout+20(FP), A3
592 MOV $SYS_epoll_pwait, A7
597 // func closeonexec(int32)
598 TEXT runtime·closeonexec(SB),NOSPLIT|NOFRAME,$0
599 MOVW fd+0(FP), A0 // fd
600 MOV $2, A1 // F_SETFD
601 MOV $1, A2 // FD_CLOEXEC
606 // func runtime·setNonblock(int32 fd)
607 TEXT runtime·setNonblock(SB),NOSPLIT|NOFRAME,$0-4
608 MOVW fd+0(FP), A0 // fd
609 MOV $3, A1 // F_GETFL
613 MOV $0x800, A2 // O_NONBLOCK
615 MOVW fd+0(FP), A0 // fd
616 MOV $4, A1 // F_SETFL
621 // func sbrk0() uintptr
622 TEXT runtime·sbrk0(SB),NOSPLIT,$0-8
623 // Implemented as brk(NULL).