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
22 #define SYS_exit_group 94
23 #define SYS_faccessat 48
25 #define SYS_getpid 172
26 #define SYS_gettid 178
27 #define SYS_gettimeofday 169
29 #define SYS_madvise 233
30 #define SYS_mincore 232
32 #define SYS_munmap 215
33 #define SYS_nanosleep 101
36 #define SYS_pselect6 72
38 #define SYS_rt_sigaction 134
39 #define SYS_rt_sigprocmask 135
40 #define SYS_rt_sigreturn 139
41 #define SYS_sched_getaffinity 123
42 #define SYS_sched_yield 124
43 #define SYS_setitimer 103
44 #define SYS_sigaltstack 132
45 #define SYS_socket 198
46 #define SYS_tgkill 131
47 #define SYS_timer_create 107
48 #define SYS_timer_delete 111
49 #define SYS_timer_settime 110
53 // func exit(code int32)
54 TEXT runtime·exit(SB),NOSPLIT|NOFRAME,$0-4
56 MOV $SYS_exit_group, A7
60 // func exitThread(wait *atomic.Uint32)
61 TEXT runtime·exitThread(SB),NOSPLIT|NOFRAME,$0-8
63 // We're done using the stack.
67 MOV $0, A0 // exit code
72 // func open(name *byte, mode, perm int32) int32
73 TEXT runtime·open(SB),NOSPLIT|NOFRAME,$0-20
86 // func closefd(fd int32) int32
87 TEXT runtime·closefd(SB),NOSPLIT|NOFRAME,$0-12
97 // func write1(fd uintptr, p unsafe.Pointer, n int32) int32
98 TEXT runtime·write1(SB),NOSPLIT|NOFRAME,$0-28
107 // func read(fd int32, p unsafe.Pointer, n int32) int32
108 TEXT runtime·read(SB),NOSPLIT|NOFRAME,$0-28
117 // func pipe2(flags int32) (r, w int32, errno int32)
118 TEXT runtime·pipe2(SB),NOSPLIT|NOFRAME,$0-20
123 MOVW A0, errno+16(FP)
126 // func usleep(usec uint32)
127 TEXT runtime·usleep(SB),NOSPLIT,$24-4
138 MOV $SYS_nanosleep, A7
142 // func gettid() uint32
143 TEXT runtime·gettid(SB),NOSPLIT,$0-4
149 // func raise(sig uint32)
150 TEXT runtime·raise(SB),NOSPLIT|NOFRAME,$0
153 // arg 1 tid - already in A0
154 MOVW sig+0(FP), A1 // arg 2
159 // func raiseproc(sig uint32)
160 TEXT runtime·raiseproc(SB),NOSPLIT|NOFRAME,$0
163 // arg 1 pid - already in A0
164 MOVW sig+0(FP), A1 // arg 2
170 TEXT ·getpid(SB),NOSPLIT|NOFRAME,$0-8
176 // func tgkill(tgid, tid, sig int)
177 TEXT ·tgkill(SB),NOSPLIT|NOFRAME,$0-24
185 // func setitimer(mode int32, new, old *itimerval)
186 TEXT runtime·setitimer(SB),NOSPLIT|NOFRAME,$0-24
190 MOV $SYS_setitimer, A7
194 // func timer_create(clockid int32, sevp *sigevent, timerid *int32) int32
195 TEXT runtime·timer_create(SB),NOSPLIT,$0-28
196 MOVW clockid+0(FP), A0
198 MOV timerid+16(FP), A2
199 MOV $SYS_timer_create, A7
204 // func timer_settime(timerid int32, flags int32, new, old *itimerspec) int32
205 TEXT runtime·timer_settime(SB),NOSPLIT,$0-28
206 MOVW timerid+0(FP), A0
210 MOV $SYS_timer_settime, A7
215 // func timer_delete(timerid int32) int32
216 TEXT runtime·timer_delete(SB),NOSPLIT,$0-12
217 MOVW timerid+0(FP), A0
218 MOV $SYS_timer_delete, A7
223 // func mincore(addr unsafe.Pointer, n uintptr, dst *byte) int32
224 TEXT runtime·mincore(SB),NOSPLIT|NOFRAME,$0-28
233 // func walltime() (sec int64, nsec int32)
234 TEXT runtime·walltime(SB),NOSPLIT,$40-12
235 MOV $CLOCK_REALTIME, A0
237 MOV runtime·vdsoClockgettimeSym(SB), A7
239 MOV X2, S2 // S2,S3,S4 is unchanged by C code
240 MOV g_m(g), S3 // S3 = m
242 // Save the old values on stack for reentrant
249 MOV $ret-8(FP), T1 // caller's SP
256 MOV (g_sched+gobuf_sp)(T1), X2
259 SUB $24, X2 // Space for result
260 ANDI $~7, X2 // Align for C code
263 // Store g on gsignal's stack, see sys_linux_arm64.s for detail
264 MOVBU runtime·iscgo(SB), S4
266 MOV m_gsignal(S3), S4 // g.m.gsignal
269 MOV (g_stack+stack_lo)(S4), S4 // g.m.gsignal.stack.lo
282 MOV 16(X2), T1 // nsec
284 MOV S2, X2 // restore stack
297 MOV $SYS_clock_gettime, A7
300 MOV 16(X2), T1 // nsec
305 // func nanotime1() int64
306 TEXT runtime·nanotime1(SB),NOSPLIT,$40-8
307 MOV $CLOCK_MONOTONIC, A0
309 MOV runtime·vdsoClockgettimeSym(SB), A7
312 MOV X2, S2 // S2 = RSP, S2 is unchanged by C code
313 MOV g_m(g), S3 // S3 = m
314 // Save the old values on stack for reentrant
321 MOV $ret-8(FP), T0 // caller's SP
328 MOV (g_sched+gobuf_sp)(T1), X2
331 SUB $24, X2 // Space for result
332 ANDI $~7, X2 // Align for C code
335 // Store g on gsignal's stack, see sys_linux_arm64.s for detail
336 MOVBU runtime·iscgo(SB), S4
338 MOV m_gsignal(S3), S4 // g.m.gsignal
341 MOV (g_stack+stack_lo)(S4), S4 // g.m.gsignal.stack.lo
354 MOV 16(X2), T1 // nsec
362 // sec is in T0, nsec in T1
372 MOV $SYS_clock_gettime, A7
375 MOV 16(X2), T1 // nsec
382 // func rtsigprocmask(how int32, new, old *sigset, size int32)
383 TEXT runtime·rtsigprocmask(SB),NOSPLIT|NOFRAME,$0-28
388 MOV $SYS_rt_sigprocmask, A7
395 // func rt_sigaction(sig uintptr, new, old *sigactiont, size uintptr) int32
396 TEXT runtime·rt_sigaction(SB),NOSPLIT|NOFRAME,$0-36
401 MOV $SYS_rt_sigaction, A7
406 // func sigfwd(fn uintptr, sig uint32, info *siginfo, ctx unsafe.Pointer)
407 TEXT runtime·sigfwd(SB),NOSPLIT,$0-32
415 // func sigtramp(signo, ureg, ctxt unsafe.Pointer)
416 TEXT runtime·sigtramp(SB),NOSPLIT|TOPFRAME,$64
421 // this might be called in external code context,
422 // where g is not set.
423 MOVBU runtime·iscgo(SB), A0
425 CALL runtime·load_g(SB)
427 MOV $runtime·sigtrampgo(SB), A0
431 // func cgoSigtramp()
432 TEXT runtime·cgoSigtramp(SB),NOSPLIT,$0
433 MOV $runtime·sigtramp(SB), T1
436 // func mmap(addr unsafe.Pointer, n uintptr, prot, flags, fd int32, off uint32) (p unsafe.Pointer, err int)
437 TEXT runtime·mmap(SB),NOSPLIT|NOFRAME,$0
441 MOVW flags+20(FP), A3
457 // func munmap(addr unsafe.Pointer, n uintptr)
458 TEXT runtime·munmap(SB),NOSPLIT|NOFRAME,$0
468 // func madvise(addr unsafe.Pointer, n uintptr, flags int32)
469 TEXT runtime·madvise(SB),NOSPLIT|NOFRAME,$0
472 MOVW flags+16(FP), A2
478 // func futex(addr unsafe.Pointer, op int32, val uint32, ts, addr2 unsafe.Pointer, val3 uint32) int32
479 TEXT runtime·futex(SB),NOSPLIT|NOFRAME,$0
491 // func clone(flags int32, stk, mp, gp, fn unsafe.Pointer) int32
492 TEXT runtime·clone(SB),NOSPLIT|NOFRAME,$0
496 // Copy mp, gp, fn off parent stack for use by child.
510 // In parent, return.
512 MOVW ZERO, ret+40(FP)
516 // In child, on new stack.
523 // Initialize m->procid to Linux tid
527 MOV -24(X2), T2 // fn
536 // In child, set up new stack
544 // It shouldn't return. If it does, exit this thread.
548 JMP -3(PC) // keep exiting
550 // func sigaltstack(new, old *stackt)
551 TEXT runtime·sigaltstack(SB),NOSPLIT|NOFRAME,$0
554 MOV $SYS_sigaltstack, A7
562 TEXT runtime·osyield(SB),NOSPLIT|NOFRAME,$0
563 MOV $SYS_sched_yield, A7
567 // func sched_getaffinity(pid, len uintptr, buf *uintptr) int32
568 TEXT runtime·sched_getaffinity(SB),NOSPLIT|NOFRAME,$0
572 MOV $SYS_sched_getaffinity, A7
577 // func sbrk0() uintptr
578 TEXT runtime·sbrk0(SB),NOSPLIT,$0-8
579 // Implemented as brk(NULL).