1 // Copyright 2014 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.
5 // System calls and other sys.stuff for AMD64, SunOS
6 // /usr/include/sys/syscall.h for syscall numbers.
13 // This is needed by asm_amd64.s
14 TEXT runtime·settls(SB),NOSPLIT,$8
17 // void libc_miniterrno(void *(*___errno)(void));
19 // Set the TLS errno pointer in M.
21 // Called using runtime·asmcgocall from os_solaris.c:/minit.
22 // NOT USING GO CALLING CONVENTION.
23 TEXT runtime·miniterrno(SB),NOSPLIT,$0
24 // asmcgocall will put first argument into DI.
25 CALL DI // SysV ABI so returns in AX
29 MOVQ AX, (m_mOS+mOS_perrno)(BX)
32 // Call a library function with SysV calling conventions.
33 // The called function can take a maximum of 6 INTEGER class arguments,
35 // Michael Matz, Jan Hubicka, Andreas Jaeger, and Mark Mitchell
36 // System V Application Binary Interface
37 // AMD64 Architecture Processor Supplement
40 // Called by runtime·asmcgocall or runtime·cgocall.
41 // NOT USING GO CALLING CONVENTION.
42 TEXT runtime·asmsysvicall6(SB),NOSPLIT,$0
43 // asmcgocall will put first argument into DI.
44 PUSHQ DI // save for later
45 MOVQ libcall_fn(DI), AX
46 MOVQ libcall_args(DI), R11
47 MOVQ libcall_n(DI), R10
54 MOVQ (m_mOS+mOS_perrno)(BX), DX
62 // Load 6 args into correspondent registers.
76 MOVQ AX, libcall_r1(DI)
77 MOVQ DX, libcall_r2(DI)
84 MOVQ (m_mOS+mOS_perrno)(BX), AX
88 MOVQ AX, libcall_err(DI)
93 // uint32 tstart_sysvicall(M *newm);
94 TEXT runtime·tstart_sysvicall(SB),NOSPLIT,$0
95 // DI contains first arg newm
96 MOVQ m_g0(DI), DX // g
98 // Make TLS entries point at g and m.
103 // Layout new m scheduler stack on os stack.
105 MOVQ AX, (g_stack+stack_hi)(DX)
106 SUBQ $(0x100000), AX // stack size
107 MOVQ AX, (g_stack+stack_lo)(DX)
108 ADDQ $const_stackGuard, AX
109 MOVQ AX, g_stackguard0(DX)
110 MOVQ AX, g_stackguard1(DX)
112 // Someday the convention will be D is always cleared.
115 CALL runtime·stackcheck(SB) // clobbers AX,CX
116 CALL runtime·mstart(SB)
118 XORL AX, AX // return 0 == success
122 // Careful, this is called by __sighndlr, a libc function. We must preserve
123 // registers as per AMD 64 ABI.
124 TEXT runtime·sigtramp(SB),NOSPLIT|TOPFRAME|NOFRAME,$0
125 // Note that we are executing on altsigstack here, so we have
126 // more stack available than NOSPLIT would have us believe.
127 // To defeat the linker, we make our own stack frame with
139 // check that g exists
148 MOVQ $runtime·badsignal(SB), AX
153 // Save m->libcall and m->scratch. We need to do this because we
154 // might get interrupted by a signal in runtime·asmcgocall.
158 LEAQ m_libcall(BP), R11
159 MOVQ libcall_fn(R11), R10
161 MOVQ libcall_args(R11), R10
163 MOVQ libcall_n(R11), R10
165 MOVQ libcall_r1(R11), R10
167 MOVQ libcall_r2(R11), R10
171 LEAQ (m_mOS+mOS_scratch)(BP), R11
185 // save errno, it might be EINTR; stuff we do here might reset it.
186 MOVQ (m_mOS+mOS_perrno)(BP), R10
194 CALL runtime·sigtrampgo(SB)
200 LEAQ m_libcall(BP), R11
202 MOVQ R10, libcall_fn(R11)
204 MOVQ R10, libcall_args(R11)
206 MOVQ R10, libcall_n(R11)
208 MOVQ R10, libcall_r1(R11)
210 MOVQ R10, libcall_r2(R11)
213 LEAQ (m_mOS+mOS_scratch)(BP), R11
228 MOVQ (m_mOS+mOS_perrno)(BP), R11
243 TEXT runtime·sigfwd(SB),NOSPLIT,$0-32
248 MOVQ SP, BX // callee-saved
249 ANDQ $~15, SP // alignment for x86_64 ABI
254 // Called from runtime·usleep (Go). Can be called on Go stack, on OS stack,
255 // can also be called in cgo callback path without a g->m.
256 TEXT runtime·usleep1(SB),NOSPLIT,$0
258 MOVQ $usleep2<>(SB), AX // to hide from 6l
260 // Execute call on m->g0.
271 // TODO(aram): do something about the cpu profiler here.
276 // executing on m->g0 already
281 // Switch to m->g0 stack and back.
282 MOVQ (g_sched+gobuf_sp)(R14), R14
290 // Not a Go-managed thread. Do not switch stack.
294 // Runs on OS stack. duration (in µs units) is in DI.
295 TEXT usleep2<>(SB),NOSPLIT,$0
296 LEAQ libc_usleep(SB), AX
300 // Runs on OS stack, called from runtime·osyield.
301 TEXT runtime·osyield1(SB),NOSPLIT,$0
302 LEAQ libc_sched_yield(SB), AX