1 // Copyright 2009 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.
5 // System calls and other sys.stuff for 386, NetBSD
6 // /usr/src/sys/kern/syscalls.master for syscall numbers.
13 #define CLOCK_REALTIME 0
14 #define CLOCK_MONOTONIC 3
24 #define SYS_madvise 75
27 #define SYS___sysctl 202
28 #define SYS___sigaltstack14 281
29 #define SYS___sigprocmask14 293
30 #define SYS_issetugid 305
31 #define SYS_getcontext 307
32 #define SYS_setcontext 308
33 #define SYS__lwp_create 309
34 #define SYS__lwp_exit 310
35 #define SYS__lwp_self 311
36 #define SYS__lwp_setprivate 317
37 #define SYS__lwp_kill 318
38 #define SYS__lwp_unpark 321
39 #define SYS___sigaction_sigtramp 340
40 #define SYS_kqueue 344
41 #define SYS_sched_yield 350
42 #define SYS___setitimer50 425
43 #define SYS___clock_gettime50 427
44 #define SYS___nanosleep50 430
45 #define SYS___kevent50 435
46 #define SYS____lwp_park60 478
48 // Exit the entire program (like C exit)
49 TEXT runtime·exit(SB),NOSPLIT,$-4
52 MOVL $0xf1, 0xf1 // crash
55 // func exitThread(wait *atomic.Uint32)
56 TEXT runtime·exitThread(SB),NOSPLIT,$0-4
58 // We're done using the stack.
60 MOVL $SYS__lwp_exit, AX
62 MOVL $0xf1, 0xf1 // crash
65 TEXT runtime·open(SB),NOSPLIT,$-4
73 TEXT runtime·closefd(SB),NOSPLIT,$-4
81 TEXT runtime·read(SB),NOSPLIT,$-4
85 NEGL AX // caller expects negative errno
89 // func pipe2(flags int32) (r, w int32, errno int32)
90 TEXT runtime·pipe2(SB),NOSPLIT,$12-16
100 TEXT runtime·write1(SB),NOSPLIT,$-4
104 NEGL AX // caller expects negative errno
108 TEXT runtime·usleep(SB),NOSPLIT,$24
113 MOVL AX, 12(SP) // tv_sec - l32
114 MOVL $0, 16(SP) // tv_sec - h32
117 MOVL AX, 20(SP) // tv_nsec
121 MOVL AX, 4(SP) // arg 1 - rqtp
122 MOVL $0, 8(SP) // arg 2 - rmtp
123 MOVL $SYS___nanosleep50, AX
127 TEXT runtime·lwp_kill(SB),NOSPLIT,$12-8
130 MOVL AX, 4(SP) // arg 1 - target
132 MOVL AX, 8(SP) // arg 2 - signo
133 MOVL $SYS__lwp_kill, AX
137 TEXT runtime·raiseproc(SB),NOSPLIT,$12
141 MOVL AX, 4(SP) // arg 1 - pid
143 MOVL AX, 8(SP) // arg 2 - signo
148 TEXT runtime·mmap(SB),NOSPLIT,$36
152 MOVSL // arg 1 - addr
154 MOVSL // arg 3 - prot
155 MOVSL // arg 4 - flags
159 MOVSL // arg 7 - offset
160 MOVL $0, AX // top 32 bits of file offset
173 TEXT runtime·munmap(SB),NOSPLIT,$-4
177 MOVL $0xf1, 0xf1 // crash
180 TEXT runtime·madvise(SB),NOSPLIT,$-4
181 MOVL $SYS_madvise, AX
188 TEXT runtime·setitimer(SB),NOSPLIT,$-4
189 MOVL $SYS___setitimer50, AX
193 // func walltime() (sec int64, nsec int32)
194 TEXT runtime·walltime(SB), NOSPLIT, $32
196 MOVL $CLOCK_REALTIME, 4(SP) // arg 1 - clock_id
197 MOVL BX, 8(SP) // arg 2 - tp
198 MOVL $SYS___clock_gettime50, AX
201 MOVL 12(SP), AX // sec - l32
202 MOVL AX, sec_lo+0(FP)
203 MOVL 16(SP), AX // sec - h32
204 MOVL AX, sec_hi+4(FP)
206 MOVL 20(SP), BX // nsec
210 // int64 nanotime1(void) so really
211 // void nanotime1(int64 *nsec)
212 TEXT runtime·nanotime1(SB),NOSPLIT,$32
214 MOVL $CLOCK_MONOTONIC, 4(SP) // arg 1 - clock_id
215 MOVL BX, 8(SP) // arg 2 - tp
216 MOVL $SYS___clock_gettime50, AX
219 MOVL 16(SP), CX // sec - h32
220 IMULL $1000000000, CX
222 MOVL 12(SP), AX // sec - l32
224 MULL BX // result in dx:ax
226 MOVL 20(SP), BX // nsec
228 ADCL CX, DX // add high bits with carry
230 MOVL AX, ret_lo+0(FP)
231 MOVL DX, ret_hi+4(FP)
234 TEXT runtime·getcontext(SB),NOSPLIT,$-4
235 MOVL $SYS_getcontext, AX
238 MOVL $0xf1, 0xf1 // crash
241 TEXT runtime·sigprocmask(SB),NOSPLIT,$-4
242 MOVL $SYS___sigprocmask14, AX
245 MOVL $0xf1, 0xf1 // crash
248 TEXT sigreturn_tramp<>(SB),NOSPLIT,$0
249 LEAL 140(SP), AX // Load address of ucontext
251 MOVL $SYS_setcontext, AX
253 MOVL $-1, 4(SP) // Something failed...
257 TEXT runtime·sigaction(SB),NOSPLIT,$24
263 MOVSL // arg 3 - oact
264 LEAL sigreturn_tramp<>(SB), AX
265 STOSL // arg 4 - tramp
267 STOSL // arg 5 - vers
268 MOVL $SYS___sigaction_sigtramp, AX
271 MOVL $0xf1, 0xf1 // crash
274 TEXT runtime·sigfwd(SB),NOSPLIT,$12-16
281 ANDL $-15, SP // align stack: handler might be a C function
285 MOVL SI, 12(SP) // save SI: handler might be a Go function
291 // Called by OS using C ABI.
292 TEXT runtime·sigtramp(SB),NOSPLIT|TOPFRAME,$28
293 NOP SP // tell vet SP changed - stop checking offsets
294 // Save callee-saved C registers, since the caller may be a C signal handler.
299 // We don't save mxcsr or the x87 control word because sigtrampgo doesn't
302 MOVL 32(SP), BX // signo
304 MOVL 36(SP), BX // info
306 MOVL 40(SP), BX // context
308 CALL runtime·sigtrampgo(SB)
316 // int32 lwp_create(void *context, uintptr flags, void *lwpid);
317 TEXT runtime·lwp_create(SB),NOSPLIT,$16
320 MOVL AX, 4(SP) // arg 1 - context
322 MOVL AX, 8(SP) // arg 2 - flags
324 MOVL AX, 12(SP) // arg 3 - lwpid
325 MOVL $SYS__lwp_create, AX
332 TEXT runtime·lwp_tramp(SB),NOSPLIT,$0
334 // Set FS to point at m->tls
336 PUSHAL // save registers
338 CALL lwp_setprivate<>(SB)
342 // Now segment is established. Initialize m, g.
347 CALL runtime·stackcheck(SB) // smashes AX, CX
348 MOVL 0(DX), DX // paranoia; check they are not nil
351 // more paranoia; check that stack splitting code works
353 CALL runtime·emptyfunc(SB)
359 // fn should never return
363 TEXT ·netbsdMstart(SB),NOSPLIT|TOPFRAME,$0
364 CALL ·netbsdMstart0(SB)
367 TEXT runtime·sigaltstack(SB),NOSPLIT,$-8
368 MOVL $SYS___sigaltstack14, AX
377 TEXT runtime·setldt(SB),NOSPLIT,$8
378 // Under NetBSD we set the GS base instead of messing with the LDT.
381 CALL lwp_setprivate<>(SB)
384 TEXT lwp_setprivate<>(SB),NOSPLIT,$16
385 // adjust for ELF: wants to use -4(GS) for g
388 MOVL $0, 0(SP) // syscall gap
389 MOVL CX, 4(SP) // arg 1 - ptr
390 MOVL $SYS__lwp_setprivate, AX
393 MOVL $0xf1, 0xf1 // crash
396 TEXT runtime·osyield(SB),NOSPLIT,$-4
397 MOVL $SYS_sched_yield, AX
401 TEXT runtime·lwp_park(SB),NOSPLIT,$-4
402 MOVL $SYS____lwp_park60, AX
407 TEXT runtime·lwp_unpark(SB),NOSPLIT,$-4
408 MOVL $SYS__lwp_unpark, AX
413 TEXT runtime·lwp_self(SB),NOSPLIT,$-4
414 MOVL $SYS__lwp_self, AX
419 TEXT runtime·sysctl(SB),NOSPLIT,$28
423 MOVSL // arg 1 - name
424 MOVSL // arg 2 - namelen
425 MOVSL // arg 3 - oldp
426 MOVSL // arg 4 - oldlenp
427 MOVSL // arg 5 - newp
428 MOVSL // arg 6 - newlen
429 MOVL $SYS___sysctl, AX
439 GLOBL runtime·tlsoffset(SB),NOPTR,$4
441 // int32 runtime·kqueue(void)
442 TEXT runtime·kqueue(SB),NOSPLIT,$0
450 // int32 runtime·kevent(int kq, Kevent *changelist, int nchanges, Kevent *eventlist, int nevents, Timespec *timeout)
451 TEXT runtime·kevent(SB),NOSPLIT,$0
452 MOVL $SYS___kevent50, AX
459 // func fcntl(fd, cmd, arg int32) (int32, int32)
460 TEXT runtime·fcntl(SB),NOSPLIT,$-4
465 MOVL AX, errno+16(FP)
469 MOVL $0, errno+16(FP)
472 // func issetugid() int32
473 TEXT runtime·issetugid(SB),NOSPLIT,$0
474 MOVL $SYS_issetugid, AX