30
30
MOVL $0xf1, 0xf1 // crash
33
TEXT runtime·open(SB),7,$0
34
MOVQ 8(SP), DI // arg 1 pathname
35
MOVL 16(SP), SI // arg 2 flags
36
MOVL 20(SP), DX // arg 3 mode
37
MOVL $(0x2000000+5), AX // syscall entry
41
TEXT runtime·close(SB),7,$0
42
MOVL 8(SP), DI // arg 1 fd
43
MOVL $(0x2000000+6), AX // syscall entry
47
TEXT runtime·read(SB),7,$0
48
MOVL 8(SP), DI // arg 1 fd
49
MOVQ 16(SP), SI // arg 2 buf
50
MOVL 24(SP), DX // arg 3 count
51
MOVL $(0x2000000+3), AX // syscall entry
33
55
TEXT runtime·write(SB),7,$0
34
56
MOVL 8(SP), DI // arg 1 fd
35
57
MOVQ 16(SP), SI // arg 2 buf
41
TEXT runtime·raisesigpipe(SB),7,$24
44
MOVL $13, DI // arg 1 SIGPIPE
45
MOVQ m_procid(DX), SI // arg 2 thread_port
46
MOVL $(0x2000000+328), AX // syscall entry __pthread_kill
63
TEXT runtime·raise(SB),7,$24
64
MOVL $(0x2000000+20), AX // getpid
66
MOVQ AX, DI // arg 1 - pid
67
MOVL sig+0(FP), SI // arg 2 - signal
68
MOVL $1, DX // arg 3 - posix
69
MOVL $(0x2000000+37), AX // kill
61
84
MOVL 24(SP), DX // arg 3 advice
62
85
MOVL $(0x2000000+75), AX // syscall entry madvise
65
MOVL $0xf1, 0xf1 // crash
68
// func now() (sec int64, nsec int32)
69
TEXT time·now(SB), 7, $32
70
MOVQ SP, DI // must be non-nil, unused
72
MOVL $(0x2000000+116), AX
75
// sec is in AX, usec in DX
87
// ignore failure - maybe pages are locked
90
// OS X comm page time offsets
91
// http://www.opensource.apple.com/source/xnu/xnu-1699.26.8/osfmk/i386/cpu_capabilities.h
92
#define nt_tsc_base 0x50
95
#define nt_ns_base 0x60
96
#define nt_generation 0x68
97
#define gtod_generation 0x6c
98
#define gtod_ns_base 0x70
99
#define gtod_sec_base 0x78
81
101
// int64 nanotime(void)
82
102
TEXT runtime·nanotime(SB), 7, $32
103
MOVQ $0x7fffffe00000, BP /* comm page base */
104
// Loop trying to take a consistent snapshot
105
// of the time parameters.
107
MOVL gtod_generation(BP), R8
110
MOVL nt_generation(BP), R9
114
MOVQ nt_tsc_base(BP), R10
115
MOVL nt_scale(BP), R11
116
MOVQ nt_ns_base(BP), R12
117
CMPL nt_generation(BP), R9
119
MOVQ gtod_ns_base(BP), R13
120
MOVQ gtod_sec_base(BP), R14
121
CMPL gtod_generation(BP), R8
124
// Gathered all the data we need. Compute time.
125
// ((tsc - nt_tsc_base) * nt_scale) >> 32 + nt_ns_base - gtod_ns_base + gtod_sec_base*1e9
126
// The multiply and shift extracts the top 64 bits of the 96-bit product.
134
IMULQ $1000000000, R14
139
// Fall back to system call (usually first call in this thread).
83
140
MOVQ SP, DI // must be non-nil, unused
85
142
MOVL $(0x2000000+116), AX
88
144
// sec is in AX, usec in DX
89
145
// return nsec in AX
90
146
IMULQ $1000000000, AX
151
// func now() (sec int64, nsec int32)
152
TEXT time·now(SB),7,$0
153
CALL runtime·nanotime(SB)
155
// generated code for
156
// func f(x uint64) (uint64, uint64) { return x/1000000000, x%100000000 }
157
// adapted to reduce duplication
159
MOVQ $1360296554856532783, AX
165
IMULQ $1000000000, DX
95
170
TEXT runtime·sigprocmask(SB),7,$0
202
// void bsdthread_create(void *stk, M *m, G *g, void (*fn)(void))
279
// void bsdthread_create(void *stk, M *mp, G *gp, void (*fn)(void))
203
280
TEXT runtime·bsdthread_create(SB),7,$0
204
281
// Set up arguments to bsdthread_create system call.
205
282
// The ones in quotes pass through to the thread callback
265
342
MOVQ $0, R9 // dispatchqueue_offset
266
343
MOVQ $(0x2000000+366), AX // bsdthread_register
269
MOVL $0xf1, 0xf1 // crash
272
351
// Mach system calls use 0x1000000 instead of the BSD's 0x2000000.
357
436
MOVL $(0x2000000+202), AX // syscall entry
444
// int32 runtime·kqueue(void);
445
TEXT runtime·kqueue(SB),7,$0
449
MOVL $(0x2000000+362), AX
455
// int32 runtime·kevent(int kq, Kevent *changelist, int nchanges, Kevent *eventlist, int nevents, Timespec *timeout);
456
TEXT runtime·kevent(SB),7,$0
463
MOVL $(0x2000000+363), AX
469
// void runtime·closeonexec(int32 fd);
470
TEXT runtime·closeonexec(SB),7,$0
472
MOVQ $2, SI // F_SETFD
473
MOVQ $1, DX // FD_CLOEXEC
474
MOVL $(0x2000000+92), AX // fcntl