Skip to content

Commit e2cb9be

Browse files
minuxcrawshaw
authored andcommitted
syscall: darwin/arm64 support
Change-Id: I3b3f80791a1db4c2b7318f81a115972cd2237f04 Signed-off-by: Shenghou Ma <minux@golang.org> Reviewed-on: https://go-review.googlesource.com/8783 Reviewed-by: David Crawshaw <crawshaw@golang.org>
1 parent e6d5233 commit e2cb9be

File tree

7 files changed

+3867
-0
lines changed

7 files changed

+3867
-0
lines changed

src/syscall/asm_darwin_arm64.s

Lines changed: 127 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,127 @@
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.
4+
5+
#include "textflag.h"
6+
7+
//
8+
// System call support for ARM64, Darwin
9+
//
10+
11+
// func Syscall(syscall uintptr, a1, a2, a3 uintptr) (r1, r2, err uintptr)
12+
TEXT ·Syscall(SB),NOSPLIT,$0-56
13+
BL runtime·entersyscall(SB)
14+
MOVD syscall+0(FP), R16
15+
MOVD a1+8(FP), R0
16+
MOVD a2+16(FP), R1
17+
MOVD a3+24(FP), R2
18+
SVC $0x80
19+
BCC ok
20+
MOVD $-1, R1
21+
MOVD R1, r1+32(FP) // r1
22+
MOVD ZR, r2+40(FP) // r2
23+
MOVD R0, errno+48(FP) // errno
24+
BL runtime·exitsyscall(SB)
25+
RET
26+
ok:
27+
MOVD R0, r1+32(FP) // r1
28+
MOVD R1, r2+40(FP) // r2
29+
MOVD ZR, errno+48(FP) // errno
30+
BL runtime·exitsyscall(SB)
31+
RET
32+
33+
// func RawSyscall(trap uintptr, a1, a2, a3 uintptr) (r1, r2, err uintptr)
34+
TEXT ·RawSyscall(SB),NOSPLIT,$0-56
35+
MOVD syscall+0(FP), R16 // syscall entry
36+
MOVD a1+8(FP), R0
37+
MOVD a2+16(FP), R1
38+
MOVD a3+24(FP), R2
39+
SVC $0x80
40+
BCC ok
41+
MOVD $-1, R1
42+
MOVD R1, r1+32(FP) // r1
43+
MOVD ZR, r2+40(FP) // r2
44+
MOVD R0, errno+48(FP) // errno
45+
RET
46+
ok:
47+
MOVD R0, r1+32(FP) // r1
48+
MOVD R1, r2+40(FP) // r2
49+
MOVD ZR, errno+48(FP) // errno
50+
RET
51+
52+
// func Syscall6(trap uintptr, a1, a2, a3, a4, a5, a6 uintptr) (r1, r2, err uintptr)
53+
TEXT ·Syscall6(SB),NOSPLIT,$0-80
54+
BL runtime·entersyscall(SB)
55+
MOVD syscall+0(FP), R16 // syscall entry
56+
MOVD a1+8(FP), R0
57+
MOVD a2+16(FP), R1
58+
MOVD a3+24(FP), R2
59+
MOVD a4+32(FP), R3
60+
MOVD a5+40(FP), R4
61+
MOVD a6+48(FP), R5
62+
SVC $0x80
63+
BCC ok
64+
MOVD $-1, R1
65+
MOVD R1, r1+56(FP) // r1
66+
MOVD ZR, r2+64(FP) // r2
67+
MOVD R0, errno+72(FP) // errno
68+
BL runtime·exitsyscall(SB)
69+
RET
70+
ok:
71+
MOVD R0, r1+56(FP) // r1
72+
MOVD R1, r2+64(FP) // r2
73+
MOVD ZR, errno+72(FP) // errno
74+
BL runtime·exitsyscall(SB)
75+
RET
76+
77+
// func RawSyscall6(trap uintptr, a1, a2, a3, a4, a5, a6 uintptr) (r1, r2, err uintptr)
78+
TEXT ·RawSyscall6(SB),NOSPLIT,$0-80
79+
MOVD trap+0(FP), R16 // syscall entry
80+
MOVD a1+8(FP), R0
81+
MOVD a2+16(FP), R1
82+
MOVD a3+24(FP), R2
83+
MOVD a4+32(FP), R3
84+
MOVD a5+40(FP), R4
85+
MOVD a6+48(FP), R5
86+
SVC $0x80
87+
BCC ok
88+
MOVD $-1, R1
89+
MOVD R1, r1+56(FP) // r1
90+
MOVD ZR, r2+64(FP) // r2
91+
MOVD R0, errno+72(FP) // errno
92+
RET
93+
ok:
94+
MOVD R0, r1+56(FP) // r1
95+
MOVD R1, r2+64(FP) // r2
96+
MOVD ZR, R0
97+
MOVD R0, errno+72(FP) // errno
98+
RET
99+
100+
// Actually Syscall7
101+
TEXT ·Syscall9(SB),NOSPLIT,$0-104
102+
BL runtime·entersyscall(SB)
103+
MOVD syscall+0(FP), R16 // syscall entry
104+
MOVD a1+8(FP), R0
105+
MOVD a2+16(FP), R1
106+
MOVD a3+24(FP), R2
107+
MOVD a4+32(FP), R3
108+
MOVD a5+40(FP), R4
109+
MOVD a6+48(FP), R5
110+
MOVD a7+56(FP), R6
111+
//MOVD a8+64(FP), R7
112+
//MOVD a9+72(FP), R8
113+
SVC $0x80
114+
BCC ok
115+
MOVD $-1, R1
116+
MOVD R1, r1+80(FP) // r1
117+
MOVD ZR, r2+88(FP) // r2
118+
MOVD R0, errno+96(FP) // errno
119+
BL runtime·exitsyscall(SB)
120+
RET
121+
ok:
122+
MOVD R0, r1+80(FP) // r1
123+
MOVD R1, r2+88(FP) // r2
124+
MOVD ZR, errno+96(FP) // errno
125+
BL runtime·exitsyscall(SB)
126+
RET
127+

src/syscall/mkall.sh

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,11 @@ darwin_amd64)
124124
mksysnum="./mksysnum_darwin.pl /usr/include/sys/syscall.h"
125125
mktypes="GOARCH=$GOARCH go tool cgo -godefs"
126126
;;
127+
darwin_arm64)
128+
mkerrors="$mkerrors -m64"
129+
mksysnum="./mksysnum_darwin.pl /usr/include/sys/syscall.h"
130+
mktypes="GOARCH=$GOARCH go tool cgo -godefs"
131+
;;
127132
dragonfly_386)
128133
mkerrors="$mkerrors -m32"
129134
mksyscall="./mksyscall.pl -l32 -dragonfly"
Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
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.
4+
5+
package syscall
6+
7+
import "unsafe"
8+
9+
func Getpagesize() int { return 16384 }
10+
11+
func TimespecToNsec(ts Timespec) int64 { return int64(ts.Sec)*1e9 + int64(ts.Nsec) }
12+
13+
func NsecToTimespec(nsec int64) (ts Timespec) {
14+
ts.Sec = nsec / 1e9
15+
ts.Nsec = nsec % 1e9
16+
return
17+
}
18+
19+
func TimevalToNsec(tv Timeval) int64 { return int64(tv.Sec)*1e9 + int64(tv.Usec)*1e3 }
20+
21+
func NsecToTimeval(nsec int64) (tv Timeval) {
22+
nsec += 999 // round up to microsecond
23+
tv.Usec = int32(nsec % 1e9 / 1e3)
24+
tv.Sec = int64(nsec / 1e9)
25+
return
26+
}
27+
28+
//sysnb gettimeofday(tp *Timeval) (sec int64, usec int32, err error)
29+
func Gettimeofday(tv *Timeval) (err error) {
30+
// The tv passed to gettimeofday must be non-nil
31+
// but is otherwise unused. The answers come back
32+
// in the two registers.
33+
sec, usec, err := gettimeofday(tv)
34+
tv.Sec = sec
35+
tv.Usec = usec
36+
return err
37+
}
38+
39+
func SetKevent(k *Kevent_t, fd, mode, flags int) {
40+
k.Ident = uint64(fd)
41+
k.Filter = int16(mode)
42+
k.Flags = uint16(flags)
43+
}
44+
45+
func (iov *Iovec) SetLen(length int) {
46+
iov.Len = uint64(length)
47+
}
48+
49+
func (msghdr *Msghdr) SetControllen(length int) {
50+
msghdr.Controllen = uint32(length)
51+
}
52+
53+
func (cmsg *Cmsghdr) SetLen(length int) {
54+
cmsg.Len = uint32(length)
55+
}
56+
57+
func sendfile(outfd int, infd int, offset *int64, count int) (written int, err error) {
58+
var length = uint64(count)
59+
60+
_, _, e1 := Syscall6(SYS_SENDFILE, uintptr(infd), uintptr(outfd), uintptr(*offset), uintptr(unsafe.Pointer(&length)), 0, 0)
61+
62+
written = int(length)
63+
64+
if e1 != 0 {
65+
err = e1
66+
}
67+
return
68+
}
69+
70+
func Syscall9(num, a1, a2, a3, a4, a5, a6, a7, a8, a9 uintptr) (r1, r2 uintptr, err Errno) // sic

0 commit comments

Comments
 (0)