1// Copyright 2009 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.
4
5.file "gcc_amd64.S"
6
7/*
8 * Apple still insists on underscore prefixes for C function names.
9 */
10#if defined(__APPLE__)
11#define EXT(s) _##s
12#else
13#define EXT(s) s
14#endif
15
16/*
17 * void crosscall1(void (*fn)(void), void (*setg_gcc)(void*), void *g)
18 *
19 * Calling into the gc tool chain, where all registers are caller save.
20 * Called from standard x86-64 ABI, where %rbx, %rbp, %r12-%r15
21 * are callee-save so they must be saved explicitly.
22 * The standard x86-64 ABI passes the three arguments m, g, fn
23 * in %rdi, %rsi, %rdx.
24 */
25.globl EXT(crosscall1)
26EXT(crosscall1):
27	pushq %rbx
28	pushq %rbp
29	pushq %r12
30	pushq %r13
31	pushq %r14
32	pushq %r15
33
34#if defined(_WIN64)
35	movq %r8, %rdi	/* arg of setg_gcc */
36	call *%rdx	/* setg_gcc */
37	call *%rcx	/* fn */
38#else
39	movq %rdi, %rbx
40	movq %rdx, %rdi	/* arg of setg_gcc */
41	call *%rsi	/* setg_gcc */
42	call *%rbx	/* fn */
43#endif
44
45	popq %r15
46	popq %r14
47	popq %r13
48	popq %r12
49	popq %rbp
50	popq %rbx
51	ret
52
53#ifdef __ELF__
54.section .note.GNU-stack,"",@progbits
55#endif
56