aboutsummaryrefslogtreecommitdiff
path: root/src/runtime/sys_openbsd_arm64.s
diff options
context:
space:
mode:
Diffstat (limited to 'src/runtime/sys_openbsd_arm64.s')
-rw-r--r--src/runtime/sys_openbsd_arm64.s920
1 files changed, 586 insertions, 334 deletions
diff --git a/src/runtime/sys_openbsd_arm64.s b/src/runtime/sys_openbsd_arm64.s
index 621b1b1a42..9b4acc90a5 100644
--- a/src/runtime/sys_openbsd_arm64.s
+++ b/src/runtime/sys_openbsd_arm64.s
@@ -3,7 +3,9 @@
// license that can be found in the LICENSE file.
//
// System calls and other sys.stuff for arm64, OpenBSD
-// /usr/src/sys/kern/syscalls.master for syscall numbers.
+// System calls are implemented in libc/libpthread, this file
+// contains trampolines that convert from Go to C calling convention.
+// Some direct system call implementations currently remain.
//
#include "go_asm.h"
@@ -13,239 +15,65 @@
#define CLOCK_REALTIME $0
#define CLOCK_MONOTONIC $3
-// With OpenBSD 6.7 onwards, an arm64 syscall returns two instructions
-// after the SVC instruction, to allow for a speculative execution
-// barrier to be placed after the SVC without impacting performance.
-// For now use hardware no-ops as this works with both older and newer
-// kernels. After OpenBSD 6.8 is released this should be changed to
-// speculation barriers.
-#define INVOKE_SYSCALL \
- SVC; \
- NOOP; \
- NOOP
+// mstart_stub is the first function executed on a new thread started by pthread_create.
+// It just does some low-level setup and then calls mstart.
+// Note: called with the C calling convention.
+TEXT runtime·mstart_stub(SB),NOSPLIT,$160
+ // R0 points to the m.
+ // We are already on m's g0 stack.
-// Exit the entire program (like C exit)
-TEXT runtime·exit(SB),NOSPLIT|NOFRAME,$0
- MOVW code+0(FP), R0 // arg 1 - status
- MOVD $1, R8 // sys_exit
- INVOKE_SYSCALL
- BCC 3(PC)
- MOVD $0, R0 // crash on syscall failure
- MOVD R0, (R0)
- RET
-
-// func exitThread(wait *uint32)
-TEXT runtime·exitThread(SB),NOSPLIT,$0
- MOVD wait+0(FP), R0 // arg 1 - notdead
- MOVD $302, R8 // sys___threxit
- INVOKE_SYSCALL
- MOVD $0, R0 // crash on syscall failure
- MOVD R0, (R0)
- JMP 0(PC)
-
-TEXT runtime·open(SB),NOSPLIT|NOFRAME,$0
- MOVD name+0(FP), R0 // arg 1 - path
- MOVW mode+8(FP), R1 // arg 2 - mode
- MOVW perm+12(FP), R2 // arg 3 - perm
- MOVD $5, R8 // sys_open
- INVOKE_SYSCALL
- BCC 2(PC)
- MOVW $-1, R0
- MOVW R0, ret+16(FP)
- RET
-
-TEXT runtime·closefd(SB),NOSPLIT|NOFRAME,$0
- MOVW fd+0(FP), R0 // arg 1 - fd
- MOVD $6, R8 // sys_close
- INVOKE_SYSCALL
- BCC 2(PC)
- MOVW $-1, R0
- MOVW R0, ret+8(FP)
- RET
-
-TEXT runtime·read(SB),NOSPLIT|NOFRAME,$0
- MOVW fd+0(FP), R0 // arg 1 - fd
- MOVD p+8(FP), R1 // arg 2 - buf
- MOVW n+16(FP), R2 // arg 3 - nbyte
- MOVD $3, R8 // sys_read
- INVOKE_SYSCALL
- BCC 2(PC)
- NEG R0, R0
- MOVW R0, ret+24(FP)
- RET
-
-// func pipe() (r, w int32, errno int32)
-TEXT runtime·pipe(SB),NOSPLIT|NOFRAME,$0-12
- MOVD $r+0(FP), R0
- MOVW $0, R1
- MOVD $101, R8 // sys_pipe2
- INVOKE_SYSCALL
- BCC 2(PC)
- NEG R0, R0
- MOVW R0, errno+8(FP)
- RET
-
-// func pipe2(flags int32) (r, w int32, errno int32)
-TEXT runtime·pipe2(SB),NOSPLIT|NOFRAME,$0-20
- MOVD $r+8(FP), R0
- MOVW flags+0(FP), R1
- MOVD $101, R8 // sys_pipe2
- INVOKE_SYSCALL
- BCC 2(PC)
- NEG R0, R0
- MOVW R0, errno+16(FP)
- RET
-
-TEXT runtime·write1(SB),NOSPLIT|NOFRAME,$0
- MOVD fd+0(FP), R0 // arg 1 - fd
- MOVD p+8(FP), R1 // arg 2 - buf
- MOVW n+16(FP), R2 // arg 3 - nbyte
- MOVD $4, R8 // sys_write
- INVOKE_SYSCALL
- BCC 2(PC)
- NEG R0, R0
- MOVW R0, ret+24(FP)
- RET
+ // Save callee-save registers.
+ MOVD R19, 8(RSP)
+ MOVD R20, 16(RSP)
+ MOVD R21, 24(RSP)
+ MOVD R22, 32(RSP)
+ MOVD R23, 40(RSP)
+ MOVD R24, 48(RSP)
+ MOVD R25, 56(RSP)
+ MOVD R26, 64(RSP)
+ MOVD R27, 72(RSP)
+ MOVD g, 80(RSP)
+ MOVD R29, 88(RSP)
+ FMOVD F8, 96(RSP)
+ FMOVD F9, 104(RSP)
+ FMOVD F10, 112(RSP)
+ FMOVD F11, 120(RSP)
+ FMOVD F12, 128(RSP)
+ FMOVD F13, 136(RSP)
+ FMOVD F14, 144(RSP)
+ FMOVD F15, 152(RSP)
-TEXT runtime·usleep(SB),NOSPLIT,$24-4
- MOVWU usec+0(FP), R3
- MOVD R3, R5
- MOVW $1000000, R4
- UDIV R4, R3
- MOVD R3, 8(RSP) // tv_sec
- MUL R3, R4
- SUB R4, R5
- MOVW $1000, R4
- MUL R4, R5
- MOVD R5, 16(RSP) // tv_nsec
+ MOVD m_g0(R0), g
+ BL runtime·save_g(SB)
- ADD $8, RSP, R0 // arg 1 - rqtp
- MOVD $0, R1 // arg 2 - rmtp
- MOVD $91, R8 // sys_nanosleep
- INVOKE_SYSCALL
- RET
-
-TEXT runtime·getthrid(SB),NOSPLIT,$0-4
- MOVD $299, R8 // sys_getthrid
- INVOKE_SYSCALL
- MOVW R0, ret+0(FP)
- RET
-
-TEXT runtime·thrkill(SB),NOSPLIT,$0-16
- MOVW tid+0(FP), R0 // arg 1 - tid
- MOVD sig+8(FP), R1 // arg 2 - signum
- MOVW $0, R2 // arg 3 - tcb
- MOVD $119, R8 // sys_thrkill
- INVOKE_SYSCALL
- RET
+ BL runtime·mstart(SB)
-TEXT runtime·raiseproc(SB),NOSPLIT,$0
- MOVD $20, R8 // sys_getpid
- INVOKE_SYSCALL
- // arg 1 - pid, already in R0
- MOVW sig+0(FP), R1 // arg 2 - signum
- MOVD $122, R8 // sys_kill
- INVOKE_SYSCALL
- RET
+ // Restore callee-save registers.
+ MOVD 8(RSP), R19
+ MOVD 16(RSP), R20
+ MOVD 24(RSP), R21
+ MOVD 32(RSP), R22
+ MOVD 40(RSP), R23
+ MOVD 48(RSP), R24
+ MOVD 56(RSP), R25
+ MOVD 64(RSP), R26
+ MOVD 72(RSP), R27
+ MOVD 80(RSP), g
+ MOVD 88(RSP), R29
+ FMOVD 96(RSP), F8
+ FMOVD 104(RSP), F9
+ FMOVD 112(RSP), F10
+ FMOVD 120(RSP), F11
+ FMOVD 128(RSP), F12
+ FMOVD 136(RSP), F13
+ FMOVD 144(RSP), F14
+ FMOVD 152(RSP), F15
-TEXT runtime·mmap(SB),NOSPLIT,$0
- MOVD addr+0(FP), R0 // arg 1 - addr
- MOVD n+8(FP), R1 // arg 2 - len
- MOVW prot+16(FP), R2 // arg 3 - prot
- MOVW flags+20(FP), R3 // arg 4 - flags
- MOVW fd+24(FP), R4 // arg 5 - fd
- MOVW $0, R5 // arg 6 - pad
- MOVW off+28(FP), R6 // arg 7 - offset
- MOVD $197, R8 // sys_mmap
- INVOKE_SYSCALL
- MOVD $0, R1
- BCC 3(PC)
- MOVD R0, R1 // if error, move to R1
+ // Go is all done with this OS thread.
+ // Tell pthread everything is ok (we never join with this thread, so
+ // the value here doesn't really matter).
MOVD $0, R0
- MOVD R0, p+32(FP)
- MOVD R1, err+40(FP)
- RET
-TEXT runtime·munmap(SB),NOSPLIT,$0
- MOVD addr+0(FP), R0 // arg 1 - addr
- MOVD n+8(FP), R1 // arg 2 - len
- MOVD $73, R8 // sys_munmap
- INVOKE_SYSCALL
- BCC 3(PC)
- MOVD $0, R0 // crash on syscall failure
- MOVD R0, (R0)
- RET
-
-TEXT runtime·madvise(SB),NOSPLIT,$0
- MOVD addr+0(FP), R0 // arg 1 - addr
- MOVD n+8(FP), R1 // arg 2 - len
- MOVW flags+16(FP), R2 // arg 2 - flags
- MOVD $75, R8 // sys_madvise
- INVOKE_SYSCALL
- BCC 2(PC)
- MOVW $-1, R0
- MOVW R0, ret+24(FP)
- RET
-
-TEXT runtime·setitimer(SB),NOSPLIT,$0
- MOVW mode+0(FP), R0 // arg 1 - mode
- MOVD new+8(FP), R1 // arg 2 - new value
- MOVD old+16(FP), R2 // arg 3 - old value
- MOVD $69, R8 // sys_setitimer
- INVOKE_SYSCALL
- RET
-
-// func walltime1() (sec int64, nsec int32)
-TEXT runtime·walltime1(SB), NOSPLIT, $32
- MOVW CLOCK_REALTIME, R0 // arg 1 - clock_id
- MOVD $8(RSP), R1 // arg 2 - tp
- MOVD $87, R8 // sys_clock_gettime
- INVOKE_SYSCALL
-
- MOVD 8(RSP), R0 // sec
- MOVD 16(RSP), R1 // nsec
- MOVD R0, sec+0(FP)
- MOVW R1, nsec+8(FP)
-
- RET
-
-// int64 nanotime1(void) so really
-// void nanotime1(int64 *nsec)
-TEXT runtime·nanotime1(SB),NOSPLIT,$32
- MOVW CLOCK_MONOTONIC, R0 // arg 1 - clock_id
- MOVD $8(RSP), R1 // arg 2 - tp
- MOVD $87, R8 // sys_clock_gettime
- INVOKE_SYSCALL
-
- MOVW 8(RSP), R3 // sec
- MOVW 16(RSP), R5 // nsec
-
- MOVD $1000000000, R4
- MUL R4, R3
- ADD R5, R3
- MOVD R3, ret+0(FP)
- RET
-
-TEXT runtime·sigaction(SB),NOSPLIT,$0
- MOVW sig+0(FP), R0 // arg 1 - signum
- MOVD new+8(FP), R1 // arg 2 - new sigaction
- MOVD old+16(FP), R2 // arg 3 - old sigaction
- MOVD $46, R8 // sys_sigaction
- INVOKE_SYSCALL
- BCC 3(PC)
- MOVD $3, R0 // crash on syscall failure
- MOVD R0, (R0)
- RET
-
-TEXT runtime·obsdsigprocmask(SB),NOSPLIT,$0
- MOVW how+0(FP), R0 // arg 1 - mode
- MOVW new+4(FP), R1 // arg 2 - new
- MOVD $48, R8 // sys_sigprocmask
- INVOKE_SYSCALL
- BCC 3(PC)
- MOVD $3, R8 // crash on syscall failure
- MOVD R8, (R8)
- MOVW R0, ret+8(FP)
RET
TEXT runtime·sigfwd(SB),NOSPLIT,$0-32
@@ -282,9 +110,6 @@ TEXT runtime·sigtramp(SB),NOSPLIT,$192
// If called from an external code context, g will not be set.
// Save R0, since runtime·load_g will clobber it.
MOVW R0, 8(RSP) // signum
- MOVB runtime·iscgo(SB), R0
- CMP $0, R0
- BEQ 2(PC)
BL runtime·load_g(SB)
MOVD R1, 16(RSP)
@@ -314,135 +139,562 @@ TEXT runtime·sigtramp(SB),NOSPLIT,$192
RET
-// int32 tfork(void *param, uintptr psize, M *mp, G *gp, void (*fn)(void));
-TEXT runtime·tfork(SB),NOSPLIT,$0
+//
+// These trampolines help convert from Go calling convention to C calling convention.
+// They should be called with asmcgocall.
+// A pointer to the arguments is passed in R0.
+// A single int32 result is returned in R0.
+// (For more results, make an args/results structure.)
+TEXT runtime·pthread_attr_init_trampoline(SB),NOSPLIT,$0
+ MOVD 0(R0), R0 // arg 1 - attr
+ CALL libc_pthread_attr_init(SB)
+ RET
+
+TEXT runtime·pthread_attr_destroy_trampoline(SB),NOSPLIT,$0
+ MOVD 0(R0), R0 // arg 1 - attr
+ CALL libc_pthread_attr_destroy(SB)
+ RET
+
+TEXT runtime·pthread_attr_getstacksize_trampoline(SB),NOSPLIT,$0
+ MOVD 8(R0), R1 // arg 2 - size
+ MOVD 0(R0), R0 // arg 1 - attr
+ CALL libc_pthread_attr_getstacksize(SB)
+ RET
+
+TEXT runtime·pthread_attr_setdetachstate_trampoline(SB),NOSPLIT,$0
+ MOVD 8(R0), R1 // arg 2 - state
+ MOVD 0(R0), R0 // arg 1 - attr
+ CALL libc_pthread_attr_setdetachstate(SB)
+ RET
+
+TEXT runtime·pthread_create_trampoline(SB),NOSPLIT,$0
+ MOVD 0(R0), R1 // arg 2 - attr
+ MOVD 8(R0), R2 // arg 3 - start
+ MOVD 16(R0), R3 // arg 4 - arg
+ SUB $16, RSP
+ MOVD RSP, R0 // arg 1 - &threadid (discard)
+ CALL libc_pthread_create(SB)
+ ADD $16, RSP
+ RET
+
+TEXT runtime·thrkill_trampoline(SB),NOSPLIT,$0
+ MOVW 8(R0), R1 // arg 2 - signal
+ MOVD $0, R2 // arg 3 - tcb
+ MOVW 0(R0), R0 // arg 1 - tid
+ CALL libc_thrkill(SB)
+ RET
+
+TEXT runtime·thrsleep_trampoline(SB),NOSPLIT,$0
+ MOVW 8(R0), R1 // arg 2 - clock_id
+ MOVD 16(R0), R2 // arg 3 - abstime
+ MOVD 24(R0), R3 // arg 4 - lock
+ MOVD 32(R0), R4 // arg 5 - abort
+ MOVD 0(R0), R0 // arg 1 - id
+ CALL libc_thrsleep(SB)
+ RET
+
+TEXT runtime·thrwakeup_trampoline(SB),NOSPLIT,$0
+ MOVW 8(R0), R1 // arg 2 - count
+ MOVD 0(R0), R0 // arg 1 - id
+ CALL libc_thrwakeup(SB)
+ RET
+
+TEXT runtime·exit_trampoline(SB),NOSPLIT,$0
+ MOVW 0(R0), R0 // arg 1 - status
+ CALL libc_exit(SB)
+ MOVD $0, R0 // crash on failure
+ MOVD R0, (R0)
+ RET
+
+TEXT runtime·getthrid_trampoline(SB),NOSPLIT,$0
+ MOVD R0, R19 // pointer to args
+ CALL libc_getthrid(SB)
+ MOVW R0, 0(R19) // return value
+ RET
+
+TEXT runtime·raiseproc_trampoline(SB),NOSPLIT,$0
+ MOVD R0, R19 // pointer to args
+ CALL libc_getpid(SB) // arg 1 - pid
+ MOVW 0(R19), R1 // arg 2 - signal
+ CALL libc_kill(SB)
+ RET
+
+TEXT runtime·sched_yield_trampoline(SB),NOSPLIT,$0
+ CALL libc_sched_yield(SB)
+ RET
+
+TEXT runtime·mmap_trampoline(SB),NOSPLIT,$0
+ MOVD R0, R19 // pointer to args
+ MOVD 0(R19), R0 // arg 1 - addr
+ MOVD 8(R19), R1 // arg 2 - len
+ MOVW 16(R19), R2 // arg 3 - prot
+ MOVW 20(R19), R3 // arg 4 - flags
+ MOVW 24(R19), R4 // arg 5 - fid
+ MOVW 28(R19), R5 // arg 6 - offset
+ CALL libc_mmap(SB)
+ MOVD $0, R1
+ CMP $-1, R0
+ BNE noerr
+ CALL libc_errno(SB)
+ MOVW (R0), R1 // errno
+ MOVD $0, R0
+noerr:
+ MOVD R0, 32(R19)
+ MOVD R1, 40(R19)
+ RET
+
+TEXT runtime·munmap_trampoline(SB),NOSPLIT,$0
+ MOVD 8(R0), R1 // arg 2 - len
+ MOVD 0(R0), R0 // arg 1 - addr
+ CALL libc_munmap(SB)
+ CMP $-1, R0
+ BNE 3(PC)
+ MOVD $0, R0 // crash on failure
+ MOVD R0, (R0)
+ RET
+
+TEXT runtime·madvise_trampoline(SB), NOSPLIT, $0
+ MOVD 8(R0), R1 // arg 2 - len
+ MOVW 16(R0), R2 // arg 3 - advice
+ MOVD 0(R0), R0 // arg 1 - addr
+ CALL libc_madvise(SB)
+ // ignore failure - maybe pages are locked
+ RET
+
+TEXT runtime·open_trampoline(SB),NOSPLIT,$0
+ MOVW 8(R0), R1 // arg 2 - flags
+ MOVW 12(R0), R2 // arg 3 - mode
+ MOVD 0(R0), R0 // arg 1 - path
+ MOVD $0, R3 // varargs
+ CALL libc_open(SB)
+ RET
- // Copy mp, gp and fn off parent stack for use by child.
- MOVD mm+16(FP), R4
- MOVD gg+24(FP), R5
- MOVD fn+32(FP), R6
+TEXT runtime·close_trampoline(SB),NOSPLIT,$0
+ MOVD 0(R0), R0 // arg 1 - fd
+ CALL libc_close(SB)
+ RET
- MOVD param+0(FP), R0 // arg 1 - param
- MOVD psize+8(FP), R1 // arg 2 - psize
- MOVD $8, R8 // sys___tfork
- INVOKE_SYSCALL
+TEXT runtime·read_trampoline(SB),NOSPLIT,$0
+ MOVD 8(R0), R1 // arg 2 - buf
+ MOVW 16(R0), R2 // arg 3 - count
+ MOVW 0(R0), R0 // arg 1 - fd
+ CALL libc_read(SB)
+ CMP $-1, R0
+ BNE noerr
+ CALL libc_errno(SB)
+ MOVW (R0), R0 // errno
+ NEG R0, R0 // caller expects negative errno value
+noerr:
+ RET
- // Return if syscall failed.
- BCC 4(PC)
- NEG R0, R0
- MOVW R0, ret+40(FP)
+TEXT runtime·write_trampoline(SB),NOSPLIT,$0
+ MOVD 8(R0), R1 // arg 2 - buf
+ MOVW 16(R0), R2 // arg 3 - count
+ MOVW 0(R0), R0 // arg 1 - fd
+ CALL libc_write(SB)
+ CMP $-1, R0
+ BNE noerr
+ CALL libc_errno(SB)
+ MOVW (R0), R0 // errno
+ NEG R0, R0 // caller expects negative errno value
+noerr:
RET
- // In parent, return.
- CMP $0, R0
- BEQ 3(PC)
- MOVW R0, ret+40(FP)
+TEXT runtime·pipe2_trampoline(SB),NOSPLIT,$0
+ MOVW 8(R0), R1 // arg 2 - flags
+ MOVD 0(R0), R0 // arg 1 - filedes
+ CALL libc_pipe2(SB)
+ CMP $-1, R0
+ BNE noerr
+ CALL libc_errno(SB)
+ MOVW (R0), R0 // errno
+ NEG R0, R0 // caller expects negative errno value
+noerr:
RET
- // Initialise m, g.
- MOVD R5, g
- MOVD R4, g_m(g)
+TEXT runtime·setitimer_trampoline(SB),NOSPLIT,$0
+ MOVD 8(R0), R1 // arg 2 - new
+ MOVD 16(R0), R2 // arg 3 - old
+ MOVW 0(R0), R0 // arg 1 - which
+ CALL libc_setitimer(SB)
+ RET
- // Call fn.
- BL (R6)
+TEXT runtime·usleep_trampoline(SB),NOSPLIT,$0
+ MOVD 0(R0), R0 // arg 1 - usec
+ CALL libc_usleep(SB)
+ RET
- // fn should never return.
- MOVD $2, R8 // crash if reached
- MOVD R8, (R8)
+TEXT runtime·sysctl_trampoline(SB),NOSPLIT,$0
+ MOVW 8(R0), R1 // arg 2 - miblen
+ MOVD 16(R0), R2 // arg 3 - out
+ MOVD 24(R0), R3 // arg 4 - size
+ MOVD 32(R0), R4 // arg 5 - dst
+ MOVD 40(R0), R5 // arg 6 - ndst
+ MOVD 0(R0), R0 // arg 1 - mib
+ CALL libc_sysctl(SB)
RET
-TEXT runtime·sigaltstack(SB),NOSPLIT,$0
- MOVD new+0(FP), R0 // arg 1 - new sigaltstack
- MOVD old+8(FP), R1 // arg 2 - old sigaltstack
- MOVD $288, R8 // sys_sigaltstack
- INVOKE_SYSCALL
- BCC 3(PC)
- MOVD $0, R8 // crash on syscall failure
- MOVD R8, (R8)
+TEXT runtime·kqueue_trampoline(SB),NOSPLIT,$0
+ CALL libc_kqueue(SB)
RET
-TEXT runtime·osyield(SB),NOSPLIT,$0
- MOVD $298, R8 // sys_sched_yield
- INVOKE_SYSCALL
+TEXT runtime·kevent_trampoline(SB),NOSPLIT,$0
+ MOVD 8(R0), R1 // arg 2 - keventt
+ MOVW 16(R0), R2 // arg 3 - nch
+ MOVD 24(R0), R3 // arg 4 - ev
+ MOVW 32(R0), R4 // arg 5 - nev
+ MOVD 40(R0), R5 // arg 6 - ts
+ MOVW 0(R0), R0 // arg 1 - kq
+ CALL libc_kevent(SB)
+ CMP $-1, R0
+ BNE noerr
+ CALL libc_errno(SB)
+ MOVW (R0), R0 // errno
+ NEG R0, R0 // caller expects negative errno value
+noerr:
RET
-TEXT runtime·thrsleep(SB),NOSPLIT,$0
- MOVD ident+0(FP), R0 // arg 1 - ident
- MOVW clock_id+8(FP), R1 // arg 2 - clock_id
- MOVD tsp+16(FP), R2 // arg 3 - tsp
- MOVD lock+24(FP), R3 // arg 4 - lock
- MOVD abort+32(FP), R4 // arg 5 - abort
- MOVD $94, R8 // sys___thrsleep
- INVOKE_SYSCALL
- MOVW R0, ret+40(FP)
+TEXT runtime·clock_gettime_trampoline(SB),NOSPLIT,$0
+ MOVD 8(R0), R1 // arg 2 - tp
+ MOVD 0(R0), R0 // arg 1 - clock_id
+ CALL libc_clock_gettime(SB)
+ CMP $-1, R0
+ BNE 3(PC)
+ MOVD $0, R0 // crash on failure
+ MOVD R0, (R0)
RET
-TEXT runtime·thrwakeup(SB),NOSPLIT,$0
- MOVD ident+0(FP), R0 // arg 1 - ident
- MOVW n+8(FP), R1 // arg 2 - n
- MOVD $301, R8 // sys___thrwakeup
- INVOKE_SYSCALL
- MOVW R0, ret+16(FP)
+TEXT runtime·fcntl_trampoline(SB),NOSPLIT,$0
+ MOVW 4(R0), R1 // arg 2 - cmd
+ MOVW 8(R0), R2 // arg 3 - arg
+ MOVW 0(R0), R0 // arg 1 - fd
+ MOVD $0, R3 // vararg
+ CALL libc_fcntl(SB)
RET
-TEXT runtime·sysctl(SB),NOSPLIT,$0
- MOVD mib+0(FP), R0 // arg 1 - mib
- MOVW miblen+8(FP), R1 // arg 2 - miblen
- MOVD out+16(FP), R2 // arg 3 - out
- MOVD size+24(FP), R3 // arg 4 - size
- MOVD dst+32(FP), R4 // arg 5 - dest
- MOVD ndst+40(FP), R5 // arg 6 - newlen
- MOVD $202, R8 // sys___sysctl
- INVOKE_SYSCALL
- BCC 2(PC)
- NEG R0, R0
- MOVW R0, ret+48(FP)
+TEXT runtime·sigaction_trampoline(SB),NOSPLIT,$0
+ MOVD 8(R0), R1 // arg 2 - new
+ MOVD 16(R0), R2 // arg 3 - old
+ MOVW 0(R0), R0 // arg 1 - sig
+ CALL libc_sigaction(SB)
+ CMP $-1, R0
+ BNE 3(PC)
+ MOVD $0, R0 // crash on syscall failure
+ MOVD R0, (R0)
RET
-// int32 runtime·kqueue(void);
-TEXT runtime·kqueue(SB),NOSPLIT,$0
- MOVD $269, R8 // sys_kqueue
- INVOKE_SYSCALL
- BCC 2(PC)
- NEG R0, R0
- MOVW R0, ret+0(FP)
+TEXT runtime·sigprocmask_trampoline(SB),NOSPLIT,$0
+ MOVD 8(R0), R1 // arg 2 - new
+ MOVD 16(R0), R2 // arg 3 - old
+ MOVW 0(R0), R0 // arg 1 - how
+ CALL libc_pthread_sigmask(SB)
+ CMP $-1, R0
+ BNE 3(PC)
+ MOVD $0, R0 // crash on syscall failure
+ MOVD R0, (R0)
RET
-// int32 runtime·kevent(int kq, Kevent *changelist, int nchanges, Kevent *eventlist, int nevents, Timespec *timeout);
-TEXT runtime·kevent(SB),NOSPLIT,$0
- MOVW kq+0(FP), R0 // arg 1 - kq
- MOVD ch+8(FP), R1 // arg 2 - changelist
- MOVW nch+16(FP), R2 // arg 3 - nchanges
- MOVD ev+24(FP), R3 // arg 4 - eventlist
- MOVW nev+32(FP), R4 // arg 5 - nevents
- MOVD ts+40(FP), R5 // arg 6 - timeout
- MOVD $72, R8 // sys_kevent
- INVOKE_SYSCALL
- BCC 2(PC)
- NEG R0, R0
- MOVW R0, ret+48(FP)
+TEXT runtime·sigaltstack_trampoline(SB),NOSPLIT,$0
+ MOVD 8(R0), R1 // arg 2 - old
+ MOVD 0(R0), R0 // arg 1 - new
+ CALL libc_sigaltstack(SB)
+ CMP $-1, R0
+ BNE 3(PC)
+ MOVD $0, R0 // crash on syscall failure
+ MOVD R0, (R0)
RET
-// func closeonexec(fd int32)
-TEXT runtime·closeonexec(SB),NOSPLIT,$0
- MOVW fd+0(FP), R0 // arg 1 - fd
- MOVD $2, R1 // arg 2 - cmd (F_SETFD)
- MOVD $1, R2 // arg 3 - arg (FD_CLOEXEC)
- MOVD $92, R8 // sys_fcntl
- INVOKE_SYSCALL
+// syscall calls a function in libc on behalf of the syscall package.
+// syscall takes a pointer to a struct like:
+// struct {
+// fn uintptr
+// a1 uintptr
+// a2 uintptr
+// a3 uintptr
+// r1 uintptr
+// r2 uintptr
+// err uintptr
+// }
+// syscall must be called on the g0 stack with the
+// C calling convention (use libcCall).
+//
+// syscall expects a 32-bit result and tests for 32-bit -1
+// to decide there was an error.
+TEXT runtime·syscall(SB),NOSPLIT,$0
+ MOVD R0, R19 // pointer to args
+
+ MOVD (0*8)(R19), R11 // fn
+ MOVD (1*8)(R19), R0 // a1
+ MOVD (2*8)(R19), R1 // a2
+ MOVD (3*8)(R19), R2 // a3
+ MOVD $0, R3 // vararg
+
+ CALL R11
+
+ MOVD R0, (4*8)(R19) // r1
+ MOVD R1, (5*8)(R19) // r2
+
+ // Standard libc functions return -1 on error
+ // and set errno.
+ CMPW $-1, R0
+ BNE ok
+
+ // Get error code from libc.
+ CALL libc_errno(SB)
+ MOVW (R0), R0
+ MOVD R0, (6*8)(R19) // err
+
+ok:
RET
-// func runtime·setNonblock(int32 fd)
-TEXT runtime·setNonblock(SB),NOSPLIT|NOFRAME,$0-4
- MOVW fd+0(FP), R0 // arg 1 - fd
- MOVD $3, R1 // arg 2 - cmd (F_GETFL)
- MOVD $0, R2 // arg 3
- MOVD $92, R8 // sys_fcntl
- INVOKE_SYSCALL
- MOVD $4, R2 // O_NONBLOCK
- ORR R0, R2 // arg 3 - flags
- MOVW fd+0(FP), R0 // arg 1 - fd
- MOVD $4, R1 // arg 2 - cmd (F_SETFL)
- MOVD $92, R8 // sys_fcntl
- INVOKE_SYSCALL
+// syscallX calls a function in libc on behalf of the syscall package.
+// syscallX takes a pointer to a struct like:
+// struct {
+// fn uintptr
+// a1 uintptr
+// a2 uintptr
+// a3 uintptr
+// r1 uintptr
+// r2 uintptr
+// err uintptr
+// }
+// syscallX must be called on the g0 stack with the
+// C calling convention (use libcCall).
+//
+// syscallX is like syscall but expects a 64-bit result
+// and tests for 64-bit -1 to decide there was an error.
+TEXT runtime·syscallX(SB),NOSPLIT,$0
+ MOVD R0, R19 // pointer to args
+
+ MOVD (0*8)(R19), R11 // fn
+ MOVD (1*8)(R19), R0 // a1
+ MOVD (2*8)(R19), R1 // a2
+ MOVD (3*8)(R19), R2 // a3
+ MOVD $0, R3 // vararg
+
+ CALL R11
+
+ MOVD R0, (4*8)(R19) // r1
+ MOVD R1, (5*8)(R19) // r2
+
+ // Standard libc functions return -1 on error
+ // and set errno.
+ CMP $-1, R0
+ BNE ok
+
+ // Get error code from libc.
+ CALL libc_errno(SB)
+ MOVW (R0), R0
+ MOVD R0, (6*8)(R19) // err
+
+ok:
+ RET
+
+// syscall6 calls a function in libc on behalf of the syscall package.
+// syscall6 takes a pointer to a struct like:
+// struct {
+// fn uintptr
+// a1 uintptr
+// a2 uintptr
+// a3 uintptr
+// a4 uintptr
+// a5 uintptr
+// a6 uintptr
+// r1 uintptr
+// r2 uintptr
+// err uintptr
+// }
+// syscall6 must be called on the g0 stack with the
+// C calling convention (use libcCall).
+//
+// syscall6 expects a 32-bit result and tests for 32-bit -1
+// to decide there was an error.
+TEXT runtime·syscall6(SB),NOSPLIT,$0
+ MOVD R0, R19 // pointer to args
+
+ MOVD (0*8)(R19), R11 // fn
+ MOVD (1*8)(R19), R0 // a1
+ MOVD (2*8)(R19), R1 // a2
+ MOVD (3*8)(R19), R2 // a3
+ MOVD (4*8)(R19), R3 // a4
+ MOVD (5*8)(R19), R4 // a5
+ MOVD (6*8)(R19), R5 // a6
+ MOVD $0, R6 // vararg
+
+ CALL R11
+
+ MOVD R0, (7*8)(R19) // r1
+ MOVD R1, (8*8)(R19) // r2
+
+ // Standard libc functions return -1 on error
+ // and set errno.
+ CMPW $-1, R0
+ BNE ok
+
+ // Get error code from libc.
+ CALL libc_errno(SB)
+ MOVW (R0), R0
+ MOVD R0, (9*8)(R19) // err
+
+ok:
+ RET
+
+// syscall6X calls a function in libc on behalf of the syscall package.
+// syscall6X takes a pointer to a struct like:
+// struct {
+// fn uintptr
+// a1 uintptr
+// a2 uintptr
+// a3 uintptr
+// a4 uintptr
+// a5 uintptr
+// a6 uintptr
+// r1 uintptr
+// r2 uintptr
+// err uintptr
+// }
+// syscall6X must be called on the g0 stack with the
+// C calling convention (use libcCall).
+//
+// syscall6X is like syscall6 but expects a 64-bit result
+// and tests for 64-bit -1 to decide there was an error.
+TEXT runtime·syscall6X(SB),NOSPLIT,$0
+ MOVD R0, R19 // pointer to args
+
+ MOVD (0*8)(R19), R11 // fn
+ MOVD (1*8)(R19), R0 // a1
+ MOVD (2*8)(R19), R1 // a2
+ MOVD (3*8)(R19), R2 // a3
+ MOVD (4*8)(R19), R3 // a4
+ MOVD (5*8)(R19), R4 // a5
+ MOVD (6*8)(R19), R5 // a6
+ MOVD $0, R6 // vararg
+
+ CALL R11
+
+ MOVD R0, (7*8)(R19) // r1
+ MOVD R1, (8*8)(R19) // r2
+
+ // Standard libc functions return -1 on error
+ // and set errno.
+ CMP $-1, R0
+ BNE ok
+
+ // Get error code from libc.
+ CALL libc_errno(SB)
+ MOVW (R0), R0
+ MOVD R0, (9*8)(R19) // err
+
+ok:
+ RET
+
+// syscall10 calls a function in libc on behalf of the syscall package.
+// syscall10 takes a pointer to a struct like:
+// struct {
+// fn uintptr
+// a1 uintptr
+// a2 uintptr
+// a3 uintptr
+// a4 uintptr
+// a5 uintptr
+// a6 uintptr
+// a7 uintptr
+// a8 uintptr
+// a9 uintptr
+// a10 uintptr
+// r1 uintptr
+// r2 uintptr
+// err uintptr
+// }
+// syscall10 must be called on the g0 stack with the
+// C calling convention (use libcCall).
+TEXT runtime·syscall10(SB),NOSPLIT,$0
+ MOVD R0, R19 // pointer to args
+
+ MOVD (0*8)(R19), R11 // fn
+ MOVD (1*8)(R19), R0 // a1
+ MOVD (2*8)(R19), R1 // a2
+ MOVD (3*8)(R19), R2 // a3
+ MOVD (4*8)(R19), R3 // a4
+ MOVD (5*8)(R19), R4 // a5
+ MOVD (6*8)(R19), R5 // a6
+ MOVD (7*8)(R19), R6 // a7
+ MOVD (8*8)(R19), R7 // a8
+ MOVD (9*8)(R19), R8 // a9
+ MOVD (10*8)(R19), R9 // a10
+ MOVD $0, R10 // vararg
+
+ CALL R11
+
+ MOVD R0, (11*8)(R19) // r1
+ MOVD R1, (12*8)(R19) // r2
+
+ // Standard libc functions return -1 on error
+ // and set errno.
+ CMPW $-1, R0
+ BNE ok
+
+ // Get error code from libc.
+ CALL libc_errno(SB)
+ MOVW (R0), R0
+ MOVD R0, (13*8)(R19) // err
+
+ok:
+ RET
+
+// syscall10X calls a function in libc on behalf of the syscall package.
+// syscall10X takes a pointer to a struct like:
+// struct {
+// fn uintptr
+// a1 uintptr
+// a2 uintptr
+// a3 uintptr
+// a4 uintptr
+// a5 uintptr
+// a6 uintptr
+// a7 uintptr
+// a8 uintptr
+// a9 uintptr
+// a10 uintptr
+// r1 uintptr
+// r2 uintptr
+// err uintptr
+// }
+// syscall10X must be called on the g0 stack with the
+// C calling convention (use libcCall).
+//
+// syscall10X is like syscall10 but expects a 64-bit result
+// and tests for 64-bit -1 to decide there was an error.
+TEXT runtime·syscall10X(SB),NOSPLIT,$0
+ MOVD R0, R19 // pointer to args
+
+ MOVD (0*8)(R19), R11 // fn
+ MOVD (1*8)(R19), R0 // a1
+ MOVD (2*8)(R19), R1 // a2
+ MOVD (3*8)(R19), R2 // a3
+ MOVD (4*8)(R19), R3 // a4
+ MOVD (5*8)(R19), R4 // a5
+ MOVD (6*8)(R19), R5 // a6
+ MOVD (7*8)(R19), R6 // a7
+ MOVD (8*8)(R19), R7 // a8
+ MOVD (9*8)(R19), R8 // a9
+ MOVD (10*8)(R19), R9 // a10
+ MOVD $0, R10 // vararg
+
+ CALL R11
+
+ MOVD R0, (11*8)(R19) // r1
+ MOVD R1, (12*8)(R19) // r2
+
+ // Standard libc functions return -1 on error
+ // and set errno.
+ CMP $-1, R0
+ BNE ok
+
+ // Get error code from libc.
+ CALL libc_errno(SB)
+ MOVW (R0), R0
+ MOVD R0, (13*8)(R19) // err
+
+ok:
RET