1// Copyright 2020 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_riscv64.S"
6
7/*
8 * void crosscall1(void (*fn)(void), void (*setg_gcc)(void *g), void *g)
9 *
10 * Calling into the gc tool chain, where all registers are caller save.
11 * Called from standard RISCV ELF psABI, where x8-x9, x18-x27, f8-f9 and
12 * f18-f27 are callee-save, so they must be saved explicitly, along with
13 * x1 (LR).
14 */
15.globl crosscall1
16crosscall1:
17	sd	x1, -200(sp)
18	addi	sp, sp, -200
19	sd	x8, 8(sp)
20	sd	x9, 16(sp)
21	sd	x18, 24(sp)
22	sd	x19, 32(sp)
23	sd	x20, 40(sp)
24	sd	x21, 48(sp)
25	sd	x22, 56(sp)
26	sd	x23, 64(sp)
27	sd	x24, 72(sp)
28	sd	x25, 80(sp)
29	sd	x26, 88(sp)
30	sd	x27, 96(sp)
31	fsd	f8, 104(sp)
32	fsd	f9, 112(sp)
33	fsd	f18, 120(sp)
34	fsd	f19, 128(sp)
35	fsd	f20, 136(sp)
36	fsd	f21, 144(sp)
37	fsd	f22, 152(sp)
38	fsd	f23, 160(sp)
39	fsd	f24, 168(sp)
40	fsd	f25, 176(sp)
41	fsd	f26, 184(sp)
42	fsd	f27, 192(sp)
43
44	// a0 = *fn, a1 = *setg_gcc, a2 = *g
45	mv	s1, a0
46	mv	s0, a1
47	mv	a0, a2
48	jalr	ra, s0	// call setg_gcc (clobbers x30 aka g)
49	jalr	ra, s1	// call fn
50
51	ld	x1, 0(sp)
52	ld	x8, 8(sp)
53	ld	x9, 16(sp)
54	ld	x18, 24(sp)
55	ld	x19, 32(sp)
56	ld	x20, 40(sp)
57	ld	x21, 48(sp)
58	ld	x22, 56(sp)
59	ld	x23, 64(sp)
60	ld	x24, 72(sp)
61	ld	x25, 80(sp)
62	ld	x26, 88(sp)
63	ld	x27, 96(sp)
64	fld	f8, 104(sp)
65	fld	f9, 112(sp)
66	fld	f18, 120(sp)
67	fld	f19, 128(sp)
68	fld	f20, 136(sp)
69	fld	f21, 144(sp)
70	fld	f22, 152(sp)
71	fld	f23, 160(sp)
72	fld	f24, 168(sp)
73	fld	f25, 176(sp)
74	fld	f26, 184(sp)
75	fld	f27, 192(sp)
76	addi	sp, sp, 200
77
78	jr	ra
79
80#ifdef __ELF__
81.section .note.GNU-stack,"",%progbits
82#endif
83