Text file
src/runtime/sys_openbsd_mips64.s
1 // Copyright 2020 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 mips64, OpenBSD
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 $3
16
17 // Exit the entire program (like C exit)
18 TEXT runtime·exit(SB),NOSPLIT|NOFRAME,$0
19 MOVW code+0(FP), R4 // arg 1 - status
20 MOVV $1, R2 // sys_exit
21 SYSCALL
22 BEQ R7, 3(PC)
23 MOVV $0, R2 // crash on syscall failure
24 MOVV R2, (R2)
25 RET
26
27 // func exitThread(wait *uint32)
28 TEXT runtime·exitThread(SB),NOSPLIT,$0
29 MOVV wait+0(FP), R4 // arg 1 - notdead
30 MOVV $302, R2 // sys___threxit
31 SYSCALL
32 MOVV $0, R2 // crash on syscall failure
33 MOVV R2, (R2)
34 JMP 0(PC)
35
36 TEXT runtime·open(SB),NOSPLIT|NOFRAME,$0
37 MOVV name+0(FP), R4 // arg 1 - path
38 MOVW mode+8(FP), R5 // arg 2 - mode
39 MOVW perm+12(FP), R6 // arg 3 - perm
40 MOVV $5, R2 // sys_open
41 SYSCALL
42 BEQ R7, 2(PC)
43 MOVW $-1, R2
44 MOVW R2, ret+16(FP)
45 RET
46
47 TEXT runtime·closefd(SB),NOSPLIT|NOFRAME,$0
48 MOVW fd+0(FP), R4 // arg 1 - fd
49 MOVV $6, R2 // sys_close
50 SYSCALL
51 BEQ R7, 2(PC)
52 MOVW $-1, R2
53 MOVW R2, ret+8(FP)
54 RET
55
56 TEXT runtime·read(SB),NOSPLIT|NOFRAME,$0
57 MOVW fd+0(FP), R4 // arg 1 - fd
58 MOVV p+8(FP), R5 // arg 2 - buf
59 MOVW n+16(FP), R6 // arg 3 - nbyte
60 MOVV $3, R2 // sys_read
61 SYSCALL
62 BEQ R7, 2(PC)
63 SUBVU R2, R0, R2 // caller expects negative errno
64 MOVW R2, ret+24(FP)
65 RET
66
67 // func pipe() (r, w int32, errno int32)
68 TEXT runtime·pipe(SB),NOSPLIT|NOFRAME,$0-12
69 MOVV $r+0(FP), R4
70 MOVW $0, R5
71 MOVV $101, R2 // sys_pipe2
72 SYSCALL
73 BEQ R7, 2(PC)
74 SUBVU R2, R0, R2 // caller expects negative errno
75 MOVW R2, errno+8(FP)
76 RET
77
78 // func pipe2(flags int32) (r, w int32, errno int32)
79 TEXT runtime·pipe2(SB),NOSPLIT|NOFRAME,$0-20
80 MOVV $r+8(FP), R4
81 MOVW flags+0(FP), R5
82 MOVV $101, R2 // sys_pipe2
83 SYSCALL
84 BEQ R7, 2(PC)
85 SUBVU R2, R0, R2 // caller expects negative errno
86 MOVW R2, errno+16(FP)
87 RET
88
89 TEXT runtime·write1(SB),NOSPLIT|NOFRAME,$0
90 MOVV fd+0(FP), R4 // arg 1 - fd
91 MOVV p+8(FP), R5 // arg 2 - buf
92 MOVW n+16(FP), R6 // arg 3 - nbyte
93 MOVV $4, R2 // sys_write
94 SYSCALL
95 BEQ R7, 2(PC)
96 SUBVU R2, R0, R2 // caller expects negative errno
97 MOVW R2, ret+24(FP)
98 RET
99
100 TEXT runtime·usleep(SB),NOSPLIT,$24-4
101 MOVWU usec+0(FP), R3
102 MOVV R3, R5
103 MOVW $1000000, R4
104 DIVVU R4, R3
105 MOVV LO, R3
106 MOVV R3, 8(R29) // tv_sec
107 MOVW $1000, R4
108 MULVU R3, R4
109 MOVV LO, R4
110 SUBVU R4, R5
111 MOVV R5, 16(R29) // tv_nsec
112
113 ADDV $8, R29, R4 // arg 1 - rqtp
114 MOVV $0, R5 // arg 2 - rmtp
115 MOVV $91, R2 // sys_nanosleep
116 SYSCALL
117 RET
118
119 TEXT runtime·getthrid(SB),NOSPLIT,$0-4
120 MOVV $299, R2 // sys_getthrid
121 SYSCALL
122 MOVW R2, ret+0(FP)
123 RET
124
125 TEXT runtime·thrkill(SB),NOSPLIT,$0-16
126 MOVW tid+0(FP), R4 // arg 1 - tid
127 MOVV sig+8(FP), R5 // arg 2 - signum
128 MOVW $0, R6 // arg 3 - tcb
129 MOVV $119, R2 // sys_thrkill
130 SYSCALL
131 RET
132
133 TEXT runtime·raiseproc(SB),NOSPLIT,$0
134 MOVV $20, R4 // sys_getpid
135 SYSCALL
136 MOVV R2, R4 // arg 1 - pid
137 MOVW sig+0(FP), R5 // arg 2 - signum
138 MOVV $122, R2 // sys_kill
139 SYSCALL
140 RET
141
142 TEXT runtime·mmap(SB),NOSPLIT,$0
143 MOVV addr+0(FP), R4 // arg 1 - addr
144 MOVV n+8(FP), R5 // arg 2 - len
145 MOVW prot+16(FP), R6 // arg 3 - prot
146 MOVW flags+20(FP), R7 // arg 4 - flags
147 MOVW fd+24(FP), R8 // arg 5 - fd
148 MOVW $0, R9 // arg 6 - pad
149 MOVW off+28(FP), R10 // arg 7 - offset
150 MOVV $197, R2 // sys_mmap
151 SYSCALL
152 MOVV $0, R4
153 BEQ R7, 3(PC)
154 MOVV R2, R4 // if error, move to R4
155 MOVV $0, R2
156 MOVV R2, p+32(FP)
157 MOVV R4, err+40(FP)
158 RET
159
160 TEXT runtime·munmap(SB),NOSPLIT,$0
161 MOVV addr+0(FP), R4 // arg 1 - addr
162 MOVV n+8(FP), R5 // arg 2 - len
163 MOVV $73, R2 // sys_munmap
164 SYSCALL
165 BEQ R7, 3(PC)
166 MOVV $0, R2 // crash on syscall failure
167 MOVV R2, (R2)
168 RET
169
170 TEXT runtime·madvise(SB),NOSPLIT,$0
171 MOVV addr+0(FP), R4 // arg 1 - addr
172 MOVV n+8(FP), R5 // arg 2 - len
173 MOVW flags+16(FP), R6 // arg 2 - flags
174 MOVV $75, R2 // sys_madvise
175 SYSCALL
176 BEQ R7, 2(PC)
177 MOVW $-1, R2
178 MOVW R2, ret+24(FP)
179 RET
180
181 TEXT runtime·setitimer(SB),NOSPLIT,$0
182 MOVW mode+0(FP), R4 // arg 1 - mode
183 MOVV new+8(FP), R5 // arg 2 - new value
184 MOVV old+16(FP), R6 // arg 3 - old value
185 MOVV $69, R2 // sys_setitimer
186 SYSCALL
187 RET
188
189 // func walltime() (sec int64, nsec int32)
190 TEXT runtime·walltime(SB), NOSPLIT, $32
191 MOVW CLOCK_REALTIME, R4 // arg 1 - clock_id
192 MOVV $8(R29), R5 // arg 2 - tp
193 MOVV $87, R2 // sys_clock_gettime
194 SYSCALL
195
196 MOVV 8(R29), R4 // sec
197 MOVV 16(R29), R5 // nsec
198 MOVV R4, sec+0(FP)
199 MOVW R5, nsec+8(FP)
200
201 RET
202
203 // int64 nanotime1(void) so really
204 // void nanotime1(int64 *nsec)
205 TEXT runtime·nanotime1(SB),NOSPLIT,$32
206 MOVW CLOCK_MONOTONIC, R4 // arg 1 - clock_id
207 MOVV $8(R29), R5 // arg 2 - tp
208 MOVV $87, R2 // sys_clock_gettime
209 SYSCALL
210
211 MOVV 8(R29), R3 // sec
212 MOVV 16(R29), R5 // nsec
213
214 MOVV $1000000000, R4
215 MULVU R4, R3
216 MOVV LO, R3
217 ADDVU R5, R3
218 MOVV R3, ret+0(FP)
219 RET
220
221 TEXT runtime·sigaction(SB),NOSPLIT,$0
222 MOVW sig+0(FP), R4 // arg 1 - signum
223 MOVV new+8(FP), R5 // arg 2 - new sigaction
224 MOVV old+16(FP), R6 // arg 3 - old sigaction
225 MOVV $46, R2 // sys_sigaction
226 SYSCALL
227 BEQ R7, 3(PC)
228 MOVV $3, R2 // crash on syscall failure
229 MOVV R2, (R2)
230 RET
231
232 TEXT runtime·obsdsigprocmask(SB),NOSPLIT,$0
233 MOVW how+0(FP), R4 // arg 1 - mode
234 MOVW new+4(FP), R5 // arg 2 - new
235 MOVV $48, R2 // sys_sigprocmask
236 SYSCALL
237 BEQ R7, 3(PC)
238 MOVV $3, R2 // crash on syscall failure
239 MOVV R2, (R2)
240 MOVW R2, ret+8(FP)
241 RET
242
243 TEXT runtime·sigfwd(SB),NOSPLIT,$0-32
244 MOVW sig+8(FP), R4
245 MOVV info+16(FP), R5
246 MOVV ctx+24(FP), R6
247 MOVV fn+0(FP), R25 // Must use R25, needed for PIC code.
248 CALL (R25)
249 RET
250
251 TEXT runtime·sigtramp(SB),NOSPLIT,$192
252 // initialize REGSB = PC&0xffffffff00000000
253 BGEZAL R0, 1(PC)
254 SRLV $32, R31, RSB
255 SLLV $32, RSB
256
257 // this might be called in external code context,
258 // where g is not set.
259 MOVB runtime·iscgo(SB), R1
260 BEQ R1, 2(PC)
261 JAL runtime·load_g(SB)
262
263 MOVW R4, 8(R29)
264 MOVV R5, 16(R29)
265 MOVV R6, 24(R29)
266 MOVV $runtime·sigtrampgo(SB), R1
267 JAL (R1)
268 RET
269
270 // int32 tfork(void *param, uintptr psize, M *mp, G *gp, void (*fn)(void));
271 TEXT runtime·tfork(SB),NOSPLIT,$0
272
273 // Copy mp, gp and fn off parent stack for use by child.
274 MOVV mm+16(FP), R16
275 MOVV gg+24(FP), R17
276 MOVV fn+32(FP), R18
277
278 MOVV param+0(FP), R4 // arg 1 - param
279 MOVV psize+8(FP), R5 // arg 2 - psize
280 MOVV $8, R2 // sys___tfork
281 SYSCALL
282
283 // Return if syscall failed.
284 BEQ R7, 4(PC)
285 SUBVU R2, R0, R2 // caller expects negative errno
286 MOVW R2, ret+40(FP)
287 RET
288
289 // In parent, return.
290 BEQ R2, 3(PC)
291 MOVW R2, ret+40(FP)
292 RET
293
294 // Initialise m, g.
295 MOVV R17, g
296 MOVV R16, g_m(g)
297
298 // Call fn.
299 CALL (R18)
300
301 // fn should never return.
302 MOVV $2, R8 // crash if reached
303 MOVV R8, (R8)
304 RET
305
306 TEXT runtime·sigaltstack(SB),NOSPLIT,$0
307 MOVV new+0(FP), R4 // arg 1 - new sigaltstack
308 MOVV old+8(FP), R5 // arg 2 - old sigaltstack
309 MOVV $288, R2 // sys_sigaltstack
310 SYSCALL
311 BEQ R7, 3(PC)
312 MOVV $0, R8 // crash on syscall failure
313 MOVV R8, (R8)
314 RET
315
316 TEXT runtime·osyield(SB),NOSPLIT,$0
317 MOVV $298, R2 // sys_sched_yield
318 SYSCALL
319 RET
320
321 TEXT runtime·thrsleep(SB),NOSPLIT,$0
322 MOVV ident+0(FP), R4 // arg 1 - ident
323 MOVW clock_id+8(FP), R5 // arg 2 - clock_id
324 MOVV tsp+16(FP), R6 // arg 3 - tsp
325 MOVV lock+24(FP), R7 // arg 4 - lock
326 MOVV abort+32(FP), R8 // arg 5 - abort
327 MOVV $94, R2 // sys___thrsleep
328 SYSCALL
329 MOVW R2, ret+40(FP)
330 RET
331
332 TEXT runtime·thrwakeup(SB),NOSPLIT,$0
333 MOVV ident+0(FP), R4 // arg 1 - ident
334 MOVW n+8(FP), R5 // arg 2 - n
335 MOVV $301, R2 // sys___thrwakeup
336 SYSCALL
337 MOVW R2, ret+16(FP)
338 RET
339
340 TEXT runtime·sysctl(SB),NOSPLIT,$0
341 MOVV mib+0(FP), R4 // arg 1 - mib
342 MOVW miblen+8(FP), R5 // arg 2 - miblen
343 MOVV out+16(FP), R6 // arg 3 - out
344 MOVV size+24(FP), R7 // arg 4 - size
345 MOVV dst+32(FP), R8 // arg 5 - dest
346 MOVV ndst+40(FP), R9 // arg 6 - newlen
347 MOVV $202, R2 // sys___sysctl
348 SYSCALL
349 BEQ R7, 2(PC)
350 SUBVU R2, R0, R2 // caller expects negative errno
351 MOVW R2, ret+48(FP)
352 RET
353
354 // int32 runtime·kqueue(void);
355 TEXT runtime·kqueue(SB),NOSPLIT,$0
356 MOVV $269, R2 // sys_kqueue
357 SYSCALL
358 BEQ R7, 2(PC)
359 SUBVU R2, R0, R2 // caller expects negative errno
360 MOVW R2, ret+0(FP)
361 RET
362
363 // int32 runtime·kevent(int kq, Kevent *changelist, int nchanges, Kevent *eventlist, int nevents, Timespec *timeout);
364 TEXT runtime·kevent(SB),NOSPLIT,$0
365 MOVW kq+0(FP), R4 // arg 1 - kq
366 MOVV ch+8(FP), R5 // arg 2 - changelist
367 MOVW nch+16(FP), R6 // arg 3 - nchanges
368 MOVV ev+24(FP), R7 // arg 4 - eventlist
369 MOVW nev+32(FP), R8 // arg 5 - nevents
370 MOVV ts+40(FP), R9 // arg 6 - timeout
371 MOVV $72, R2 // sys_kevent
372 SYSCALL
373 BEQ R7, 2(PC)
374 SUBVU R2, R0, R2 // caller expects negative errno
375 MOVW R2, ret+48(FP)
376 RET
377
378 // func closeonexec(fd int32)
379 TEXT runtime·closeonexec(SB),NOSPLIT,$0
380 MOVW fd+0(FP), R4 // arg 1 - fd
381 MOVV $2, R5 // arg 2 - cmd (F_SETFD)
382 MOVV $1, R6 // arg 3 - arg (FD_CLOEXEC)
383 MOVV $92, R2 // sys_fcntl
384 SYSCALL
385 RET
386
387 // func runtime·setNonblock(int32 fd)
388 TEXT runtime·setNonblock(SB),NOSPLIT|NOFRAME,$0-4
389 MOVW fd+0(FP), R4 // arg 1 - fd
390 MOVV $3, R5 // arg 2 - cmd (F_GETFL)
391 MOVV $0, R6 // arg 3
392 MOVV $92, R2 // sys_fcntl
393 SYSCALL
394 MOVV $4, R6 // O_NONBLOCK
395 OR R2, R6 // arg 3 - flags
396 MOVW fd+0(FP), R4 // arg 1 - fd
397 MOVV $4, R5 // arg 2 - cmd (F_SETFL)
398 MOVV $92, R2 // sys_fcntl
399 SYSCALL
400 RET
401
View as plain text