Skip to content

Commit

Permalink
unix: add darwin/arm64 support
Browse files Browse the repository at this point in the history
Fixes golang/go#10239.

Change-Id: I3ae657b57ca7bef31207780477c44939c0bdc8b5
Signed-off-by: Shenghou Ma <minux@golang.org>
Reviewed-on: https://go-review.googlesource.com/10185
Reviewed-by: Rob Pike <r@golang.org>
  • Loading branch information
minux committed May 18, 2015
1 parent 785372d commit 58e1096
Show file tree
Hide file tree
Showing 7 changed files with 3,645 additions and 0 deletions.
30 changes: 30 additions & 0 deletions unix/asm_darwin_arm64.s
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
// Copyright 2015 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.

// +build !gccgo
// +build arm64,darwin

#include "textflag.h"

//
// System call support for AMD64, Darwin
//

// Just jump to package syscall's implementation for all these functions.
// The runtime may know about them.

TEXT ·Syscall(SB),NOSPLIT,$0-56
B syscall·Syscall(SB)

TEXT ·Syscall6(SB),NOSPLIT,$0-80
B syscall·Syscall6(SB)

TEXT ·Syscall9(SB),NOSPLIT,$0-104
B syscall·Syscall9(SB)

TEXT ·RawSyscall(SB),NOSPLIT,$0-56
B syscall·RawSyscall(SB)

TEXT ·RawSyscall6(SB),NOSPLIT,$0-80
B syscall·RawSyscall6(SB)
5 changes: 5 additions & 0 deletions unix/mkall.sh
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,11 @@ darwin_arm)
mksysnum="./mksysnum_darwin.pl /usr/include/sys/syscall.h"
mktypes="GOARCH=$GOARCH go tool cgo -godefs"
;;
darwin_arm64)
mkerrors="$mkerrors -m64"
mksysnum="./mksysnum_darwin.pl /usr/include/sys/syscall.h"

This comment has been minimized.

Copy link
@jacobsa

jacobsa Aug 31, 2015

Contributor

@minux (or anybody else who can answer), can you help me with two questions?

  1. Is the path here correct? I assume you're running this on an OS X machine; how is it that the headers for arm64 are in /usr/include?
  2. Which of arm and arm64 correspond to the iPhone OS SDK installed in the latest version of Xcode?

This comment has been minimized.

Copy link
@minux

minux via email Aug 31, 2015

Author Member

This comment has been minimized.

Copy link
@jacobsa

jacobsa Aug 31, 2015

Contributor

Thanks, that all makes sense. But it leaves two questions:

  1. Why does x/sys have iOS support if it shouldn't be used?
  2. Can you confirm that arm64 corresponds to the modern iOS SDK?

This comment has been minimized.

Copy link
@minux

minux via email Aug 31, 2015

Author Member

This comment has been minimized.

Copy link
@jacobsa

jacobsa Aug 31, 2015

Contributor

Thanks for clarifying. I do have syscalls.h for iOS on my machine, so I will check that they correspond.

mktypes="GOARCH=$GOARCH go tool cgo -godefs"
;;
dragonfly_386)
mkerrors="$mkerrors -m32"
mksyscall="./mksyscall.pl -l32 -dragonfly"
Expand Down
75 changes: 75 additions & 0 deletions unix/syscall_darwin_arm64.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
// Copyright 2015 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.

// +build arm64,darwin

package unix

import (
"syscall"
"unsafe"
)

func Getpagesize() int { return 16384 }

func TimespecToNsec(ts Timespec) int64 { return int64(ts.Sec)*1e9 + int64(ts.Nsec) }

func NsecToTimespec(nsec int64) (ts Timespec) {
ts.Sec = nsec / 1e9
ts.Nsec = nsec % 1e9
return
}

func TimevalToNsec(tv Timeval) int64 { return int64(tv.Sec)*1e9 + int64(tv.Usec)*1e3 }

func NsecToTimeval(nsec int64) (tv Timeval) {
nsec += 999 // round up to microsecond
tv.Usec = int32(nsec % 1e9 / 1e3)
tv.Sec = int64(nsec / 1e9)
return
}

//sysnb gettimeofday(tp *Timeval) (sec int64, usec int32, err error)
func Gettimeofday(tv *Timeval) (err error) {
// The tv passed to gettimeofday must be non-nil
// but is otherwise unused. The answers come back
// in the two registers.
sec, usec, err := gettimeofday(tv)
tv.Sec = sec
tv.Usec = usec
return err
}

func SetKevent(k *Kevent_t, fd, mode, flags int) {
k.Ident = uint64(fd)
k.Filter = int16(mode)
k.Flags = uint16(flags)
}

func (iov *Iovec) SetLen(length int) {
iov.Len = uint64(length)
}

func (msghdr *Msghdr) SetControllen(length int) {
msghdr.Controllen = uint32(length)
}

func (cmsg *Cmsghdr) SetLen(length int) {
cmsg.Len = uint32(length)
}

func sendfile(outfd int, infd int, offset *int64, count int) (written int, err error) {
var length = uint64(count)

_, _, e1 := Syscall6(SYS_SENDFILE, uintptr(infd), uintptr(outfd), uintptr(*offset), uintptr(unsafe.Pointer(&length)), 0, 0)

written = int(length)

if e1 != 0 {
err = e1
}
return
}

func Syscall9(num, a1, a2, a3, a4, a5, a6, a7, a8, a9 uintptr) (r1, r2 uintptr, err syscall.Errno) // sic
Loading

0 comments on commit 58e1096

Please sign in to comment.