Skip to content

Instantly share code, notes, and snippets.

@davecheney
Created August 8, 2014 12:16
Show Gist options
  • Save davecheney/cce4d956f793b5f46abe to your computer and use it in GitHub Desktop.
Save davecheney/cce4d956f793b5f46abe to your computer and use it in GitHub Desktop.
odessa(~/src/github.com/pkg/mach) % cat sys_darwin_amd64.s
// Copyright 2009 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.
//
// System calls and other sys.stuff for AMD64, Darwin
// See http://fxr.watson.org/fxr/source/bsd/kern/syscalls.c?v=xnu-1228
// or /usr/include/sys/syscall.h (on a Mac) for system call numbers.
//
// The low 24 bits are the system call number.
// The high 8 bits specify the kind of system call: 1=Mach, 2=BSD, 3=Machine-Dependent.
//
// adapted from $GOROOT/src/pkg/runtime/sys_darwin_amd64.s
#include "textflag.h"
// Mach system calls use 0x1000000 instead of the BSD's 0x2000000.
// uint32 mach_msg_trap(void*, uint32, uint32, uint32, uint32, uint32, uint32)
TEXT ·mach_msg_trap(SB),NOSPLIT,$8
MOVQ 8(SP), DI
MOVL 16(SP), SI
MOVL 20(SP), DX
MOVL 24(SP), R10
MOVL 28(SP), R8
MOVL 32(SP), R9
MOVL 36(SP), R11
PUSHQ R11 // seventh arg, on stack
MOVL $(0x1000000+31), AX // mach_msg_trap
SYSCALL
POPQ R11
MOVL AX, result+0(FP)
RET
TEXT ·mach_host_self(SB),NOSPLIT,$8
MOVL $(0x1000000+29), AX // host_self_trap
SYSCALL
MOVL AX, self+0(FP)
RET
TEXT ·mach_task_self(SB),NOSPLIT,$8
MOVL $(0x1000000+28), AX // task_self_trap
SYSCALL
MOVL AX, self+0(FP)
RET
TEXT ·mach_thread_self(SB),NOSPLIT,$8
MOVL $(0x1000000+27), AX // task_thread_self
SYSCALL
MOVL AX, self+0(FP)
RET
TEXT ·mach_reply_port(SB),NOSPLIT,$8
MOVL $(0x1000000+26), AX // mach_reply_port
SYSCALL
MOVL AX, port+0(FP)
RET
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment