Text file
src/runtime/sys_freebsd_riscv64.s
Documentation: runtime
1// Copyright 2022 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 riscv64, 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
17#define SYS_exit 1
18#define SYS_read 3
19#define SYS_write 4
20#define SYS_open 5
21#define SYS_close 6
22#define SYS_getpid 20
23#define SYS_kill 37
24#define SYS_sigaltstack 53
25#define SYS_munmap 73
26#define SYS_madvise 75
27#define SYS_setitimer 83
28#define SYS_fcntl 92
29#define SYS___sysctl 202
30#define SYS_nanosleep 240
31#define SYS_issetugid 253
32#define SYS_clock_gettime 232
33#define SYS_sched_yield 331
34#define SYS_sigprocmask 340
35#define SYS_kqueue 362
36#define SYS_sigaction 416
37#define SYS_thr_exit 431
38#define SYS_thr_self 432
39#define SYS_thr_kill 433
40#define SYS__umtx_op 454
41#define SYS_thr_new 455
42#define SYS_mmap 477
43#define SYS_cpuset_getaffinity 487
44#define SYS_pipe2 542
45#define SYS_kevent 560
46
47TEXT emptyfunc<>(SB),0,$0-0
48 RET
49
50// func sys_umtx_op(addr *uint32, mode int32, val uint32, uaddr1 uintptr, ut *umtx_time) int32
51TEXT runtime·sys_umtx_op(SB),NOSPLIT,$0
52 MOV addr+0(FP), A0
53 MOVW mode+8(FP), A1
54 MOVW val+12(FP), A2
55 MOV uaddr1+16(FP), A3
56 MOV ut+24(FP), A4
57 MOV $SYS__umtx_op, T0
58 ECALL
59 BEQ T0, ZERO, ok
60 NEG A0, A0
61ok:
62 MOVW A0, ret+32(FP)
63 RET
64
65// func thr_new(param *thrparam, size int32) int32
66TEXT runtime·thr_new(SB),NOSPLIT,$0
67 MOV param+0(FP), A0
68 MOVW size+8(FP), A1
69 MOV $SYS_thr_new, T0
70 ECALL
71 BEQ T0, ZERO, ok
72 NEG A0, A0
73ok:
74 MOVW A0, ret+16(FP)
75 RET
76
77// func thr_start()
78TEXT runtime·thr_start(SB),NOSPLIT,$0
79 // set up g
80 MOV m_g0(A0), g
81 MOV A0, g_m(g)
82 CALL emptyfunc<>(SB) // fault if stack check is wrong
83 CALL runtime·mstart(SB)
84
85 WORD $0 // crash
86 RET
87
88// func exit(code int32)
89TEXT runtime·exit(SB),NOSPLIT|NOFRAME,$0-4
90 MOVW code+0(FP), A0
91 MOV $SYS_exit, T0
92 ECALL
93 WORD $0 // crash
94
95// func exitThread(wait *atomic.Uint32)
96TEXT runtime·exitThread(SB),NOSPLIT|NOFRAME,$0-8
97 MOV wait+0(FP), A0
98 // We're done using the stack.
99 FENCE
100 MOVW ZERO, (A0)
101 FENCE
102 MOV $0, A0 // exit code
103 MOV $SYS_thr_exit, T0
104 ECALL
105 JMP 0(PC)
106
107// func open(name *byte, mode, perm int32) int32
108TEXT runtime·open(SB),NOSPLIT|NOFRAME,$0-20
109 MOV name+0(FP), A0
110 MOVW mode+8(FP), A1
111 MOVW perm+12(FP), A2
112 MOV $SYS_open, T0
113 ECALL
114 BEQ T0, ZERO, ok
115 MOV $-1, A0
116ok:
117 MOVW A0, ret+16(FP)
118 RET
119
120// func closefd(fd int32) int32
121TEXT runtime·closefd(SB),NOSPLIT|NOFRAME,$0-12
122 MOVW fd+0(FP), A0
123 MOV $SYS_close, T0
124 ECALL
125 BEQ T0, ZERO, ok
126 MOV $-1, A0
127ok:
128 MOVW A0, ret+8(FP)
129 RET
130
131// func pipe2(flags int32) (r, w int32, errno int32)
132TEXT runtime·pipe2(SB),NOSPLIT|NOFRAME,$0-20
133 MOV $r+8(FP), A0
134 MOVW flags+0(FP), A1
135 MOV $SYS_pipe2, T0
136 ECALL
137 BEQ T0, ZERO, ok
138 NEG A0, A0
139ok:
140 MOVW A0, errno+16(FP)
141 RET
142
143// func write1(fd uintptr, p unsafe.Pointer, n int32) int32
144TEXT runtime·write1(SB),NOSPLIT|NOFRAME,$0-28
145 MOV fd+0(FP), A0
146 MOV p+8(FP), A1
147 MOVW n+16(FP), A2
148 MOV $SYS_write, T0
149 ECALL
150 BEQ T0, ZERO, ok
151 NEG A0, A0
152ok:
153 MOVW A0, ret+24(FP)
154 RET
155
156// func read(fd int32, p unsafe.Pointer, n int32) int32
157TEXT runtime·read(SB),NOSPLIT|NOFRAME,$0-28
158 MOVW fd+0(FP), A0
159 MOV p+8(FP), A1
160 MOVW n+16(FP), A2
161 MOV $SYS_read, T0
162 ECALL
163 BEQ T0, ZERO, ok
164 NEG A0, A0
165ok:
166 MOVW A0, ret+24(FP)
167 RET
168
169// func usleep(usec uint32)
170TEXT runtime·usleep(SB),NOSPLIT,$24-4
171 MOVWU usec+0(FP), A0
172 MOV $1000, A1
173 MUL A1, A0, A0
174 MOV $1000000000, A1
175 DIV A1, A0, A2
176 MOV A2, 8(X2)
177 REM A1, A0, A3
178 MOV A3, 16(X2)
179 ADD $8, X2, A0
180 MOV ZERO, A1
181 MOV $SYS_nanosleep, T0
182 ECALL
183 RET
184
185// func thr_self() thread
186TEXT runtime·thr_self(SB),NOSPLIT,$8-8
187 MOV $ptr-8(SP), A0 // arg 1 &8(SP)
188 MOV $SYS_thr_self, T0
189 ECALL
190 MOV ptr-8(SP), A0
191 MOV A0, ret+0(FP)
192 RET
193
194// func thr_kill(t thread, sig int)
195TEXT runtime·thr_kill(SB),NOSPLIT,$0-16
196 MOV tid+0(FP), A0 // arg 1 pid
197 MOV sig+8(FP), A1 // arg 2 sig
198 MOV $SYS_thr_kill, T0
199 ECALL
200 RET
201
202// func raiseproc(sig uint32)
203TEXT runtime·raiseproc(SB),NOSPLIT|NOFRAME,$0
204 MOV $SYS_getpid, T0
205 ECALL
206 // arg 1 pid - already in A0
207 MOVW sig+0(FP), A1 // arg 2
208 MOV $SYS_kill, T0
209 ECALL
210 RET
211
212// func setitimer(mode int32, new, old *itimerval)
213TEXT runtime·setitimer(SB),NOSPLIT|NOFRAME,$0-24
214 MOVW mode+0(FP), A0
215 MOV new+8(FP), A1
216 MOV old+16(FP), A2
217 MOV $SYS_setitimer, T0
218 ECALL
219 RET
220
221// func fallback_walltime() (sec int64, nsec int32)
222TEXT runtime·fallback_walltime(SB),NOSPLIT,$24-12
223 MOV $CLOCK_REALTIME, A0
224 MOV $8(X2), A1
225 MOV $SYS_clock_gettime, T0
226 ECALL
227 MOV 8(X2), T0 // sec
228 MOVW 16(X2), T1 // nsec
229 MOV T0, sec+0(FP)
230 MOVW T1, nsec+8(FP)
231 RET
232
233// func fallback_nanotime() int64
234TEXT runtime·fallback_nanotime(SB),NOSPLIT,$24-8
235 MOV $CLOCK_MONOTONIC, A0
236 MOV $8(X2), A1
237 MOV $SYS_clock_gettime, T0
238 ECALL
239 MOV 8(X2), T0 // sec
240 MOV 16(X2), T1 // nsec
241
242 // sec is in T0, nsec in T1
243 // return nsec in T0
244 MOV $1000000000, T2
245 MUL T2, T0
246 ADD T1, T0
247
248 MOV T0, ret+0(FP)
249 RET
250
251// func asmSigaction(sig uintptr, new, old *sigactiont) int32
252TEXT runtime·asmSigaction(SB),NOSPLIT|NOFRAME,$0
253 MOV sig+0(FP), A0 // arg 1 sig
254 MOV new+8(FP), A1 // arg 2 act
255 MOV old+16(FP), A2 // arg 3 oact
256 MOV $SYS_sigaction, T0
257 ECALL
258 BEQ T0, ZERO, ok
259 MOV $-1, A0
260ok:
261 MOVW A0, ret+24(FP)
262 RET
263
264// func sigfwd(fn uintptr, sig uint32, info *siginfo, ctx unsafe.Pointer)
265TEXT runtime·sigfwd(SB),NOSPLIT,$0-32
266 MOVW sig+8(FP), A0
267 MOV info+16(FP), A1
268 MOV ctx+24(FP), A2
269 MOV fn+0(FP), T1
270 JALR RA, T1
271 RET
272
273// func sigtramp(signo, ureg, ctxt unsafe.Pointer)
274TEXT runtime·sigtramp(SB),NOSPLIT,$64
275 MOVW A0, 8(X2)
276 MOV A1, 16(X2)
277 MOV A2, 24(X2)
278
279 // this might be called in external code context,
280 // where g is not set.
281 MOVBU runtime·iscgo(SB), A0
282 BEQ A0, ZERO, ok
283 CALL runtime·load_g(SB)
284ok:
285 MOV $runtime·sigtrampgo(SB), A0
286 JALR RA, A0
287 RET
288
289// func mmap(addr uintptr, n uintptr, prot int, flags int, fd int, off int64) (ret uintptr, err error)
290TEXT runtime·mmap(SB),NOSPLIT|NOFRAME,$0
291 MOV addr+0(FP), A0
292 MOV n+8(FP), A1
293 MOVW prot+16(FP), A2
294 MOVW flags+20(FP), A3
295 MOVW fd+24(FP), A4
296 MOVW off+28(FP), A5
297 MOV $SYS_mmap, T0
298 ECALL
299 BNE T0, ZERO, fail
300 MOV A0, p+32(FP)
301 MOV ZERO, err+40(FP)
302 RET
303fail:
304 MOV ZERO, p+32(FP)
305 MOV A0, err+40(FP)
306 RET
307
308// func munmap(addr uintptr, n uintptr) (err error)
309TEXT runtime·munmap(SB),NOSPLIT|NOFRAME,$0
310 MOV addr+0(FP), A0
311 MOV n+8(FP), A1
312 MOV $SYS_munmap, T0
313 ECALL
314 BNE T0, ZERO, fail
315 RET
316fail:
317 WORD $0 // crash
318
319// func madvise(addr unsafe.Pointer, n uintptr, flags int32) int32
320TEXT runtime·madvise(SB),NOSPLIT|NOFRAME,$0
321 MOV addr+0(FP), A0
322 MOV n+8(FP), A1
323 MOVW flags+16(FP), A2
324 MOV $SYS_madvise, T0
325 ECALL
326 BEQ T0, ZERO, ok
327 MOV $-1, A0
328ok:
329 MOVW A0, ret+24(FP)
330 RET
331
332// func sysctl(mib *uint32, miblen uint32, out *byte, size *uintptr, dst *byte, ndst uintptr) int32
333TEXT runtime·sysctl(SB),NOSPLIT,$0
334 MOV mib+0(FP), A0
335 MOV miblen+8(FP), A1
336 MOV out+16(FP), A2
337 MOV size+24(FP), A3
338 MOV dst+32(FP), A4
339 MOV ndst+40(FP), A5
340 MOV $SYS___sysctl, T0
341 ECALL
342 BEQ T0, ZERO, ok
343 NEG A0, A0
344ok:
345 MOVW A0, ret+48(FP)
346 RET
347
348// func sigaltstack(new, old *stackt)
349TEXT runtime·sigaltstack(SB),NOSPLIT|NOFRAME,$0
350 MOV new+0(FP), A0
351 MOV old+8(FP), A1
352 MOV $SYS_sigaltstack, T0
353 ECALL
354 BNE T0, ZERO, fail
355 RET
356fail:
357 WORD $0 // crash
358
359// func osyield()
360TEXT runtime·osyield(SB),NOSPLIT|NOFRAME,$0
361 MOV $SYS_sched_yield, T0
362 ECALL
363 RET
364
365// func sigprocmask(how int32, new, old *sigset)
366TEXT runtime·sigprocmask(SB),NOSPLIT|NOFRAME,$0-24
367 MOVW how+0(FP), A0
368 MOV new+8(FP), A1
369 MOV old+16(FP), A2
370 MOV $SYS_sigprocmask, T0
371 ECALL
372 BNE T0, ZERO, fail
373 RET
374fail:
375 WORD $0 // crash
376
377
378// func cpuset_getaffinity(level int, which int, id int64, size int, mask *byte) int32
379TEXT runtime·cpuset_getaffinity(SB),NOSPLIT|NOFRAME,$0-44
380 MOV level+0(FP), A0
381 MOV which+8(FP), A1
382 MOV id+16(FP), A2
383 MOV size+24(FP), A3
384 MOV mask+32(FP), A4
385 MOV $SYS_cpuset_getaffinity, T0
386 ECALL
387 BEQ T0, ZERO, ok
388 MOV $-1, A0
389ok:
390 MOVW A0, ret+40(FP)
391 RET
392
393// func kqueue() int32
394TEXT runtime·kqueue(SB),NOSPLIT|NOFRAME,$0
395 MOV $SYS_kqueue, T0
396 ECALL
397 BEQ T0, ZERO, ok
398 MOV $-1, A0
399ok:
400 MOVW A0, ret+0(FP)
401 RET
402
403// func kevent(kq int, ch unsafe.Pointer, nch int, ev unsafe.Pointer, nev int, ts *Timespec) (n int, err error)
404TEXT runtime·kevent(SB),NOSPLIT,$0
405 MOVW kq+0(FP), A0
406 MOV ch+8(FP), A1
407 MOVW nch+16(FP), A2
408 MOV ev+24(FP), A3
409 MOVW nev+32(FP), A4
410 MOV ts+40(FP), A5
411 MOV $SYS_kevent, T0
412 ECALL
413 BEQ T0, ZERO, ok
414 NEG A0, A0
415ok:
416 MOVW A0, ret+48(FP)
417 RET
418
419// func fcntl(fd, cmd, arg int32) (int32, int32)
420TEXT runtime·fcntl(SB),NOSPLIT,$0
421 MOVW fd+0(FP), A0
422 MOVW cmd+4(FP), A1
423 MOVW arg+8(FP), A2
424 MOV $SYS_fcntl, T0
425 ECALL
426 BEQ T0, ZERO, noerr
427 MOV $-1, A1
428 MOVW A1, ret+16(FP)
429 MOVW A0, errno+20(FP)
430 RET
431noerr:
432 MOVW A0, ret+16(FP)
433 MOVW ZERO, errno+20(FP)
434 RET
435
436// func getCntxct() uint32
437TEXT runtime·getCntxct(SB),NOSPLIT|NOFRAME,$0
438 RDTIME A0
439 MOVW A0, ret+0(FP)
440 RET
441
442// func issetugid() int32
443TEXT runtime·issetugid(SB),NOSPLIT|NOFRAME,$0
444 MOV $SYS_issetugid, T0
445 ECALL
446 MOVW A0, ret+0(FP)
447 RET
448
View as plain text