~ubuntu-branches/ubuntu/utopic/golang/utopic

« back to all changes in this revision

Viewing changes to src/pkg/runtime/sys_darwin_amd64.s

  • Committer: Package Import Robot
  • Author(s): James Page
  • Date: 2013-08-20 14:06:23 UTC
  • mfrom: (14.1.23 saucy-proposed)
  • Revision ID: package-import@ubuntu.com-20130820140623-b414jfxi3m0qkmrq
Tags: 2:1.1.2-2ubuntu1
* Merge from Debian unstable (LP: #1211749, #1202027). Remaining changes:
  - 016-armhf-elf-header.patch: Use correct ELF header for armhf binaries.
  - d/control,control.cross: Update Breaks/Replaces for Ubuntu
    versions to ensure smooth upgrades, regenerate control file.

Show diffs side-by-side

added added

removed removed

Lines of Context:
30
30
        MOVL    $0xf1, 0xf1  // crash
31
31
        RET
32
32
 
 
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
 
38
        SYSCALL
 
39
        RET
 
40
 
 
41
TEXT runtime·close(SB),7,$0
 
42
        MOVL    8(SP), DI               // arg 1 fd
 
43
        MOVL    $(0x2000000+6), AX      // syscall entry
 
44
        SYSCALL
 
45
        RET
 
46
 
 
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
 
52
        SYSCALL
 
53
        RET
 
54
 
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
38
60
        SYSCALL
39
61
        RET
40
62
 
41
 
TEXT runtime·raisesigpipe(SB),7,$24
42
 
        get_tls(CX)
43
 
        MOVQ    m(CX), DX
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
 
65
        SYSCALL
 
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
47
70
        SYSCALL
48
71
        RET
49
72
 
61
84
        MOVL    24(SP), DX              // arg 3 advice
62
85
        MOVL    $(0x2000000+75), AX     // syscall entry madvise
63
86
        SYSCALL
64
 
        JCC     2(PC)
65
 
        MOVL    $0xf1, 0xf1  // crash
66
 
        RET
67
 
 
68
 
// func now() (sec int64, nsec int32)
69
 
TEXT time·now(SB), 7, $32
70
 
        MOVQ    SP, DI  // must be non-nil, unused
71
 
        MOVQ    $0, SI
72
 
        MOVL    $(0x2000000+116), AX
73
 
        SYSCALL
74
 
 
75
 
        // sec is in AX, usec in DX
76
 
        MOVQ    AX, sec+0(FP)
77
 
        IMULQ   $1000, DX
78
 
        MOVL    DX, nsec+8(FP)
79
 
        RET
 
87
        // ignore failure - maybe pages are locked
 
88
        RET
 
89
 
 
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
 
93
#define nt_scale        0x58
 
94
#define nt_shift        0x5c
 
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
80
100
 
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.
 
106
timeloop:
 
107
        MOVL    gtod_generation(BP), R8
 
108
        TESTL   R8, R8
 
109
        JZ      systime
 
110
        MOVL    nt_generation(BP), R9
 
111
        TESTL   R9, R9
 
112
        JZ      timeloop
 
113
        RDTSC
 
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
 
118
        JNE     timeloop
 
119
        MOVQ    gtod_ns_base(BP), R13
 
120
        MOVQ    gtod_sec_base(BP), R14
 
121
        CMPL    gtod_generation(BP), R8
 
122
        JNE     timeloop
 
123
 
 
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.
 
127
        SHLQ    $32, DX
 
128
        ADDQ    DX, AX
 
129
        SUBQ    R10, AX
 
130
        MULQ    R11
 
131
        SHRQ    $32, AX:DX
 
132
        ADDQ    R12, AX
 
133
        SUBQ    R13, AX
 
134
        IMULQ   $1000000000, R14
 
135
        ADDQ    R14, AX
 
136
        RET
 
137
 
 
138
systime:
 
139
        // Fall back to system call (usually first call in this thread).
83
140
        MOVQ    SP, DI  // must be non-nil, unused
84
141
        MOVQ    $0, SI
85
142
        MOVL    $(0x2000000+116), AX
86
143
        SYSCALL
87
 
 
88
144
        // sec is in AX, usec in DX
89
145
        // return nsec in AX
90
146
        IMULQ   $1000000000, AX
92
148
        ADDQ    DX, AX
93
149
        RET
94
150
 
 
151
// func now() (sec int64, nsec int32)
 
152
TEXT time·now(SB),7,$0
 
153
        CALL    runtime·nanotime(SB)
 
154
 
 
155
        // generated code for
 
156
        //      func f(x uint64) (uint64, uint64) { return x/1000000000, x%100000000 }
 
157
        // adapted to reduce duplication
 
158
        MOVQ    AX, CX
 
159
        MOVQ    $1360296554856532783, AX
 
160
        MULQ    CX
 
161
        ADDQ    CX, DX
 
162
        RCRQ    $1, DX
 
163
        SHRQ    $29, DX
 
164
        MOVQ    DX, sec+0(FP)
 
165
        IMULQ   $1000000000, DX
 
166
        SUBQ    DX, CX
 
167
        MOVL    CX, nsec+8(FP)
 
168
        RET
 
169
 
95
170
TEXT runtime·sigprocmask(SB),7,$0
96
171
        MOVL    8(SP), DI
97
172
        MOVQ    16(SP), SI
120
195
        // check that m exists
121
196
        MOVQ    m(BX), BP
122
197
        CMPQ    BP, $0
123
 
        JNE     2(PC)
 
198
        JNE     4(PC)
 
199
        MOVL    DX, 0(SP)
124
200
        CALL    runtime·badsignal(SB)
 
201
        RET
125
202
 
126
203
        // save g
127
204
        MOVQ    g(BX), R10
199
276
        SYSCALL
200
277
        RET
201
278
 
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
213
290
        MOVQ    $(0x2000000+360), AX    // bsdthread_create
214
291
        SYSCALL
215
292
        JCC 3(PC)
216
 
        NEGL    AX
 
293
        NEGQ    AX
217
294
        RET
218
295
        MOVL    $0, AX
219
296
        RET
265
342
        MOVQ    $0, R9  // dispatchqueue_offset
266
343
        MOVQ    $(0x2000000+366), AX    // bsdthread_register
267
344
        SYSCALL
268
 
        JCC 2(PC)
269
 
        MOVL    $0xf1, 0xf1  // crash
 
345
        JCC 3(PC)
 
346
        NEGQ    AX
 
347
        RET
 
348
        MOVL    $0, AX
270
349
        RET
271
350
 
272
351
// Mach system calls use 0x1000000 instead of the BSD's 0x2000000.
357
436
        MOVL    $(0x2000000+202), AX    // syscall entry
358
437
        SYSCALL
359
438
        JCC 3(PC)
360
 
        NEGL    AX
 
439
        NEGQ    AX
361
440
        RET
362
441
        MOVL    $0, AX
363
442
        RET
 
443
 
 
444
// int32 runtime·kqueue(void);
 
445
TEXT runtime·kqueue(SB),7,$0
 
446
        MOVQ    $0, DI
 
447
        MOVQ    $0, SI
 
448
        MOVQ    $0, DX
 
449
        MOVL    $(0x2000000+362), AX
 
450
        SYSCALL
 
451
        JCC     2(PC)
 
452
        NEGQ    AX
 
453
        RET
 
454
 
 
455
// int32 runtime·kevent(int kq, Kevent *changelist, int nchanges, Kevent *eventlist, int nevents, Timespec *timeout);
 
456
TEXT runtime·kevent(SB),7,$0
 
457
        MOVL    8(SP), DI
 
458
        MOVQ    16(SP), SI
 
459
        MOVL    24(SP), DX
 
460
        MOVQ    32(SP), R10
 
461
        MOVL    40(SP), R8
 
462
        MOVQ    48(SP), R9
 
463
        MOVL    $(0x2000000+363), AX
 
464
        SYSCALL
 
465
        JCC     2(PC)
 
466
        NEGQ    AX
 
467
        RET
 
468
 
 
469
// void runtime·closeonexec(int32 fd);
 
470
TEXT runtime·closeonexec(SB),7,$0
 
471
        MOVL    8(SP), DI  // fd
 
472
        MOVQ    $2, SI  // F_SETFD
 
473
        MOVQ    $1, DX  // FD_CLOEXEC
 
474
        MOVL    $(0x2000000+92), AX  // fcntl
 
475
        SYSCALL
 
476
        RET