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
15 #define SYS_clock_gettime 113
18 #define SYS_connect 203
19 #define SYS_epoll_create1 20
20 #define SYS_epoll_ctl 21
21 #define SYS_epoll_pwait 22
23 #define SYS_exit_group 94
24 #define SYS_faccessat 48
27 #define SYS_getpid 172
28 #define SYS_getrlimit 163
29 #define SYS_gettid 178
30 #define SYS_gettimeofday 169
32 #define SYS_madvise 233
33 #define SYS_mincore 232
35 #define SYS_munmap 215
36 #define SYS_nanosleep 101
39 #define SYS_pselect6 72
41 #define SYS_rt_sigaction 134
42 #define SYS_rt_sigprocmask 135
43 #define SYS_rt_sigreturn 139
44 #define SYS_sched_getaffinity 123
45 #define SYS_sched_yield 124
46 #define SYS_setitimer 103
47 #define SYS_sigaltstack 132
48 #define SYS_socket 198
49 #define SYS_tgkill 131
53 #define FENCE WORD $0x0ff0000f
55 // func exit(code int32)
56 TEXT runtime·exit(SB),NOSPLIT|NOFRAME,$0-4
58 MOV $SYS_exit_group, A7
62 // func exitThread(wait *uint32)
63 TEXT runtime·exitThread(SB),NOSPLIT|NOFRAME,$0-8
65 // We're done using the stack.
69 MOV $0, A0 // exit code
74 // func open(name *byte, mode, perm int32) int32
75 TEXT runtime·open(SB),NOSPLIT|NOFRAME,$0-20
88 // func closefd(fd int32) int32
89 TEXT runtime·closefd(SB),NOSPLIT|NOFRAME,$0-12
99 // func write1(fd uintptr, p unsafe.Pointer, n int32) int32
100 TEXT runtime·write1(SB),NOSPLIT|NOFRAME,$0-28
109 // func read(fd int32, p unsafe.Pointer, n int32) int32
110 TEXT runtime·read(SB),NOSPLIT|NOFRAME,$0-28
119 // func pipe() (r, w int32, errno int32)
120 TEXT runtime·pipe(SB),NOSPLIT|NOFRAME,$0-12
128 // func pipe2(flags int32) (r, w int32, errno int32)
129 TEXT runtime·pipe2(SB),NOSPLIT|NOFRAME,$0-20
134 MOVW A0, errno+16(FP)
137 // func getrlimit(kind int32, limit unsafe.Pointer) int32
138 TEXT runtime·getrlimit(SB),NOSPLIT|NOFRAME,$0-20
141 MOV $SYS_getrlimit, A7
146 // func usleep(usec uint32)
147 TEXT runtime·usleep(SB),NOSPLIT,$24-4
158 MOV $SYS_nanosleep, A7
162 // func gettid() uint32
163 TEXT runtime·gettid(SB),NOSPLIT,$0-4
169 // func raise(sig uint32)
170 TEXT runtime·raise(SB),NOSPLIT|NOFRAME,$0
173 // arg 1 tid - already in A0
174 MOVW sig+0(FP), A1 // arg 2
179 // func raiseproc(sig uint32)
180 TEXT runtime·raiseproc(SB),NOSPLIT|NOFRAME,$0
183 // arg 1 pid - already in A0
184 MOVW sig+0(FP), A1 // arg 2
190 TEXT ·getpid(SB),NOSPLIT|NOFRAME,$0-8
196 // func tgkill(tgid, tid, sig int)
197 TEXT ·tgkill(SB),NOSPLIT|NOFRAME,$0-24
205 // func setitimer(mode int32, new, old *itimerval)
206 TEXT runtime·setitimer(SB),NOSPLIT|NOFRAME,$0-24
210 MOV $SYS_setitimer, A7
214 // func mincore(addr unsafe.Pointer, n uintptr, dst *byte) int32
215 TEXT runtime·mincore(SB),NOSPLIT|NOFRAME,$0-28
224 // func walltime1() (sec int64, nsec int32)
225 TEXT runtime·walltime1(SB),NOSPLIT,$24-12
226 MOV $0, A0 // CLOCK_REALTIME
228 MOV $SYS_clock_gettime, A7
231 MOV 16(X2), T1 // nsec
236 // func nanotime1() int64
237 TEXT runtime·nanotime1(SB),NOSPLIT,$24-8
238 MOV $1, A0 // CLOCK_MONOTONIC
240 MOV $SYS_clock_gettime, A7
243 MOV 16(X2), T1 // nsec
244 // sec is in T0, nsec in T1
252 // func rtsigprocmask(how int32, new, old *sigset, size int32)
253 TEXT runtime·rtsigprocmask(SB),NOSPLIT|NOFRAME,$0-28
258 MOV $SYS_rt_sigprocmask, A7
265 // func rt_sigaction(sig uintptr, new, old *sigactiont, size uintptr) int32
266 TEXT runtime·rt_sigaction(SB),NOSPLIT|NOFRAME,$0-36
271 MOV $SYS_rt_sigaction, A7
276 // func sigfwd(fn uintptr, sig uint32, info *siginfo, ctx unsafe.Pointer)
277 TEXT runtime·sigfwd(SB),NOSPLIT,$0-32
285 // func sigtramp(signo, ureg, ctxt unsafe.Pointer)
286 TEXT runtime·sigtramp(SB),NOSPLIT,$64
291 // this might be called in external code context,
292 // where g is not set.
293 MOVBU runtime·iscgo(SB), A0
295 CALL runtime·load_g(SB)
297 MOV $runtime·sigtrampgo(SB), A0
301 // func cgoSigtramp()
302 TEXT runtime·cgoSigtramp(SB),NOSPLIT,$0
303 MOV $runtime·sigtramp(SB), T1
306 // func mmap(addr unsafe.Pointer, n uintptr, prot, flags, fd int32, off uint32) (p unsafe.Pointer, err int)
307 TEXT runtime·mmap(SB),NOSPLIT|NOFRAME,$0
311 MOVW flags+20(FP), A3
327 // func munmap(addr unsafe.Pointer, n uintptr)
328 TEXT runtime·munmap(SB),NOSPLIT|NOFRAME,$0
338 // func madvise(addr unsafe.Pointer, n uintptr, flags int32)
339 TEXT runtime·madvise(SB),NOSPLIT|NOFRAME,$0
342 MOVW flags+16(FP), A2
348 // func futex(addr unsafe.Pointer, op int32, val uint32, ts, addr2 unsafe.Pointer, val3 uint32) int32
349 TEXT runtime·futex(SB),NOSPLIT|NOFRAME,$0
361 // func clone(flags int32, stk, mp, gp, fn unsafe.Pointer) int32
362 TEXT runtime·clone(SB),NOSPLIT|NOFRAME,$0
366 // Copy mp, gp, fn off parent stack for use by child.
380 // In parent, return.
382 MOVW ZERO, ret+40(FP)
386 // In child, on new stack.
393 // Initialize m->procid to Linux tid
397 MOV -24(X2), T2 // fn
406 // In child, set up new stack
414 // It shouldn't return. If it does, exit this thread.
418 JMP -3(PC) // keep exiting
420 // func sigaltstack(new, old *stackt)
421 TEXT runtime·sigaltstack(SB),NOSPLIT|NOFRAME,$0
424 MOV $SYS_sigaltstack, A7
432 TEXT runtime·osyield(SB),NOSPLIT|NOFRAME,$0
433 MOV $SYS_sched_yield, A7
437 // func sched_getaffinity(pid, len uintptr, buf *uintptr) int32
438 TEXT runtime·sched_getaffinity(SB),NOSPLIT|NOFRAME,$0
442 MOV $SYS_sched_getaffinity, A7
447 // func epollcreate(size int32) int32
448 TEXT runtime·epollcreate(SB),NOSPLIT|NOFRAME,$0
450 MOV $SYS_epoll_create1, A7
455 // func epollcreate1(flags int32) int32
456 TEXT runtime·epollcreate1(SB),NOSPLIT|NOFRAME,$0
458 MOV $SYS_epoll_create1, A7
463 // func epollctl(epfd, op, fd int32, ev *epollevent) int32
464 TEXT runtime·epollctl(SB),NOSPLIT|NOFRAME,$0
469 MOV $SYS_epoll_ctl, A7
474 // func epollwait(epfd int32, ev *epollevent, nev, timeout int32) int32
475 TEXT runtime·epollwait(SB),NOSPLIT|NOFRAME,$0
479 MOVW timeout+20(FP), A3
481 MOV $SYS_epoll_pwait, A7
486 // func closeonexec(int32)
487 TEXT runtime·closeonexec(SB),NOSPLIT|NOFRAME,$0
488 MOVW fd+0(FP), A0 // fd
489 MOV $2, A1 // F_SETFD
490 MOV $1, A2 // FD_CLOEXEC
495 // func runtime·setNonblock(int32 fd)
496 TEXT runtime·setNonblock(SB),NOSPLIT|NOFRAME,$0-4
497 MOVW fd+0(FP), A0 // fd
498 MOV $3, A1 // F_GETFL
502 MOV $0x800, A2 // O_NONBLOCK
504 MOVW fd+0(FP), A0 // fd
505 MOV $4, A1 // F_SETFL
510 // func sbrk0() uintptr
511 TEXT runtime·sbrk0(SB),NOSPLIT,$0-8
512 // Implemented as brk(NULL).