1// SPDX-License-Identifier: GPL-2.0-only
2// Copyright (C) 2021 ARM Limited.
3//
4// Assembly portion of the syscall ABI test
5
6//
7// Load values from memory into registers, invoke a syscall and save the
8// register values back to memory for later checking.  The syscall to be
9// invoked is configured in x8 of the input GPR data.
10//
11// x0:	SVE VL, 0 for FP only
12//
13//	GPRs:	gpr_in, gpr_out
14//	FPRs:	fpr_in, fpr_out
15//	Zn:	z_in, z_out
16//	Pn:	p_in, p_out
17//	FFR:	ffr_in, ffr_out
18
19.arch_extension sve
20
21.globl do_syscall
22do_syscall:
23	// Store callee saved registers x19-x29 (80 bytes) plus x0 and x1
24	stp	x29, x30, [sp, #-112]!
25	mov	x29, sp
26	stp	x0, x1, [sp, #16]
27	stp	x19, x20, [sp, #32]
28	stp	x21, x22, [sp, #48]
29	stp	x23, x24, [sp, #64]
30	stp	x25, x26, [sp, #80]
31	stp	x27, x28, [sp, #96]
32
33	// Load GPRs x8-x28, and save our SP/FP for later comparison
34	ldr	x2, =gpr_in
35	add	x2, x2, #64
36	ldp	x8, x9, [x2], #16
37	ldp	x10, x11, [x2], #16
38	ldp	x12, x13, [x2], #16
39	ldp	x14, x15, [x2], #16
40	ldp	x16, x17, [x2], #16
41	ldp	x18, x19, [x2], #16
42	ldp	x20, x21, [x2], #16
43	ldp	x22, x23, [x2], #16
44	ldp	x24, x25, [x2], #16
45	ldp	x26, x27, [x2], #16
46	ldr	x28, [x2], #8
47	str	x29, [x2], #8		// FP
48	str	x30, [x2], #8		// LR
49
50	// Load FPRs if we're not doing SVE
51	cbnz	x0, 1f
52	ldr	x2, =fpr_in
53	ldp	q0, q1, [x2]
54	ldp	q2, q3, [x2, #16 * 2]
55	ldp	q4, q5, [x2, #16 * 4]
56	ldp	q6, q7, [x2, #16 * 6]
57	ldp	q8, q9, [x2, #16 * 8]
58	ldp	q10, q11, [x2, #16 * 10]
59	ldp	q12, q13, [x2, #16 * 12]
60	ldp	q14, q15, [x2, #16 * 14]
61	ldp	q16, q17, [x2, #16 * 16]
62	ldp	q18, q19, [x2, #16 * 18]
63	ldp	q20, q21, [x2, #16 * 20]
64	ldp	q22, q23, [x2, #16 * 22]
65	ldp	q24, q25, [x2, #16 * 24]
66	ldp	q26, q27, [x2, #16 * 26]
67	ldp	q28, q29, [x2, #16 * 28]
68	ldp	q30, q31, [x2, #16 * 30]
691:
70
71	// Load the SVE registers if we're doing SVE
72	cbz	x0, 1f
73
74	ldr	x2, =z_in
75	ldr	z0, [x2, #0, MUL VL]
76	ldr	z1, [x2, #1, MUL VL]
77	ldr	z2, [x2, #2, MUL VL]
78	ldr	z3, [x2, #3, MUL VL]
79	ldr	z4, [x2, #4, MUL VL]
80	ldr	z5, [x2, #5, MUL VL]
81	ldr	z6, [x2, #6, MUL VL]
82	ldr	z7, [x2, #7, MUL VL]
83	ldr	z8, [x2, #8, MUL VL]
84	ldr	z9, [x2, #9, MUL VL]
85	ldr	z10, [x2, #10, MUL VL]
86	ldr	z11, [x2, #11, MUL VL]
87	ldr	z12, [x2, #12, MUL VL]
88	ldr	z13, [x2, #13, MUL VL]
89	ldr	z14, [x2, #14, MUL VL]
90	ldr	z15, [x2, #15, MUL VL]
91	ldr	z16, [x2, #16, MUL VL]
92	ldr	z17, [x2, #17, MUL VL]
93	ldr	z18, [x2, #18, MUL VL]
94	ldr	z19, [x2, #19, MUL VL]
95	ldr	z20, [x2, #20, MUL VL]
96	ldr	z21, [x2, #21, MUL VL]
97	ldr	z22, [x2, #22, MUL VL]
98	ldr	z23, [x2, #23, MUL VL]
99	ldr	z24, [x2, #24, MUL VL]
100	ldr	z25, [x2, #25, MUL VL]
101	ldr	z26, [x2, #26, MUL VL]
102	ldr	z27, [x2, #27, MUL VL]
103	ldr	z28, [x2, #28, MUL VL]
104	ldr	z29, [x2, #29, MUL VL]
105	ldr	z30, [x2, #30, MUL VL]
106	ldr	z31, [x2, #31, MUL VL]
107
108	ldr	x2, =ffr_in
109	ldr	p0, [x2, #0]
110	wrffr	p0.b
111
112	ldr	x2, =p_in
113	ldr	p0, [x2, #0, MUL VL]
114	ldr	p1, [x2, #1, MUL VL]
115	ldr	p2, [x2, #2, MUL VL]
116	ldr	p3, [x2, #3, MUL VL]
117	ldr	p4, [x2, #4, MUL VL]
118	ldr	p5, [x2, #5, MUL VL]
119	ldr	p6, [x2, #6, MUL VL]
120	ldr	p7, [x2, #7, MUL VL]
121	ldr	p8, [x2, #8, MUL VL]
122	ldr	p9, [x2, #9, MUL VL]
123	ldr	p10, [x2, #10, MUL VL]
124	ldr	p11, [x2, #11, MUL VL]
125	ldr	p12, [x2, #12, MUL VL]
126	ldr	p13, [x2, #13, MUL VL]
127	ldr	p14, [x2, #14, MUL VL]
128	ldr	p15, [x2, #15, MUL VL]
1291:
130
131	// Do the syscall
132	svc	#0
133
134	// Save GPRs x8-x30
135	ldr	x2, =gpr_out
136	add	x2, x2, #64
137	stp	x8, x9, [x2], #16
138	stp	x10, x11, [x2], #16
139	stp	x12, x13, [x2], #16
140	stp	x14, x15, [x2], #16
141	stp	x16, x17, [x2], #16
142	stp	x18, x19, [x2], #16
143	stp	x20, x21, [x2], #16
144	stp	x22, x23, [x2], #16
145	stp	x24, x25, [x2], #16
146	stp	x26, x27, [x2], #16
147	stp	x28, x29, [x2], #16
148	str	x30, [x2]
149
150	// Restore x0 and x1 for feature checks
151	ldp	x0, x1, [sp, #16]
152
153	// Save FPSIMD state
154	ldr	x2, =fpr_out
155	stp	q0, q1, [x2]
156	stp	q2, q3, [x2, #16 * 2]
157	stp	q4, q5, [x2, #16 * 4]
158	stp	q6, q7, [x2, #16 * 6]
159	stp	q8, q9, [x2, #16 * 8]
160	stp	q10, q11, [x2, #16 * 10]
161	stp	q12, q13, [x2, #16 * 12]
162	stp	q14, q15, [x2, #16 * 14]
163	stp	q16, q17, [x2, #16 * 16]
164	stp	q18, q19, [x2, #16 * 18]
165	stp	q20, q21, [x2, #16 * 20]
166	stp	q22, q23, [x2, #16 * 22]
167	stp	q24, q25, [x2, #16 * 24]
168	stp	q26, q27, [x2, #16 * 26]
169	stp	q28, q29, [x2, #16 * 28]
170	stp	q30, q31, [x2, #16 * 30]
171
172	// Save the SVE state if we have some
173	cbz	x0, 1f
174
175	ldr	x2, =z_out
176	str	z0, [x2, #0, MUL VL]
177	str	z1, [x2, #1, MUL VL]
178	str	z2, [x2, #2, MUL VL]
179	str	z3, [x2, #3, MUL VL]
180	str	z4, [x2, #4, MUL VL]
181	str	z5, [x2, #5, MUL VL]
182	str	z6, [x2, #6, MUL VL]
183	str	z7, [x2, #7, MUL VL]
184	str	z8, [x2, #8, MUL VL]
185	str	z9, [x2, #9, MUL VL]
186	str	z10, [x2, #10, MUL VL]
187	str	z11, [x2, #11, MUL VL]
188	str	z12, [x2, #12, MUL VL]
189	str	z13, [x2, #13, MUL VL]
190	str	z14, [x2, #14, MUL VL]
191	str	z15, [x2, #15, MUL VL]
192	str	z16, [x2, #16, MUL VL]
193	str	z17, [x2, #17, MUL VL]
194	str	z18, [x2, #18, MUL VL]
195	str	z19, [x2, #19, MUL VL]
196	str	z20, [x2, #20, MUL VL]
197	str	z21, [x2, #21, MUL VL]
198	str	z22, [x2, #22, MUL VL]
199	str	z23, [x2, #23, MUL VL]
200	str	z24, [x2, #24, MUL VL]
201	str	z25, [x2, #25, MUL VL]
202	str	z26, [x2, #26, MUL VL]
203	str	z27, [x2, #27, MUL VL]
204	str	z28, [x2, #28, MUL VL]
205	str	z29, [x2, #29, MUL VL]
206	str	z30, [x2, #30, MUL VL]
207	str	z31, [x2, #31, MUL VL]
208
209	ldr	x2, =p_out
210	str	p0, [x2, #0, MUL VL]
211	str	p1, [x2, #1, MUL VL]
212	str	p2, [x2, #2, MUL VL]
213	str	p3, [x2, #3, MUL VL]
214	str	p4, [x2, #4, MUL VL]
215	str	p5, [x2, #5, MUL VL]
216	str	p6, [x2, #6, MUL VL]
217	str	p7, [x2, #7, MUL VL]
218	str	p8, [x2, #8, MUL VL]
219	str	p9, [x2, #9, MUL VL]
220	str	p10, [x2, #10, MUL VL]
221	str	p11, [x2, #11, MUL VL]
222	str	p12, [x2, #12, MUL VL]
223	str	p13, [x2, #13, MUL VL]
224	str	p14, [x2, #14, MUL VL]
225	str	p15, [x2, #15, MUL VL]
226
227	ldr	x2, =ffr_out
228	rdffr	p0.b
229	str	p0, [x2, #0]
2301:
231
232	// Restore callee saved registers x19-x30
233	ldp	x19, x20, [sp, #32]
234	ldp	x21, x22, [sp, #48]
235	ldp	x23, x24, [sp, #64]
236	ldp	x25, x26, [sp, #80]
237	ldp	x27, x28, [sp, #96]
238	ldp	x29, x30, [sp], #112
239
240	ret
241