Debian Codegraph @

libgcc/config/riscv/save-restore.S

raw
1 /* Callee-saved register spill and fill routines for RISC-V.
2
3 Copyright (C) 2016-2025 Free Software Foundation, Inc.
4
5 This file is part of GCC.
6
7 GCC is free software; you can redistribute it and/or modify it under
8 the terms of the GNU General Public License as published by the Free
9 Software Foundation; either version 3, or (at your option) any later
10 version.
11
12 GCC is distributed in the hope that it will be useful, but WITHOUT ANY
13 WARRANTY; without even the implied warranty of MERCHANTABILITY or
14 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
15 for more details.
16
17 Under Section 7 of GPL version 3, you are granted additional
18 permissions described in the GCC Runtime Library Exception, version
19 3.1, as published by the Free Software Foundation.
20
21 You should have received a copy of the GNU General Public License and
22 a copy of the GCC Runtime Library Exception along with this program;
23 see the files COPYING3 and COPYING.RUNTIME respectively. If not, see
24 <http://www.gnu.org/licenses/>. */
25
26 #include "riscv-asm.h"
27
28 .text
29
30 #if __riscv_xlen == 64
31
32 FUNC_BEGIN (__riscv_save_12)
33 .cfi_startproc
34 # __riscv_save_* routine use t0/x5 as return address
35 .cfi_return_column 5
36 addi sp, sp, -112
37 .cfi_def_cfa_offset 112
38 li t1, 0
39 sd s11, 8(sp)
40 .cfi_offset 27, -104
41 j .Ls10
42
43 FUNC_BEGIN (__riscv_save_11)
44 FUNC_BEGIN (__riscv_save_10)
45 .cfi_restore 27
46 addi sp, sp, -112
47 .cfi_def_cfa_offset 112
48 li t1, 1
49 .Ls10:
50 sd s10, 16(sp)
51 .cfi_offset 26, -96
52 sd s9, 24(sp)
53 .cfi_offset 25, -88
54 j .Ls8
55
56 FUNC_BEGIN (__riscv_save_9)
57 FUNC_BEGIN (__riscv_save_8)
58 .cfi_restore 25
59 .cfi_restore 26
60 .cfi_restore 27
61 addi sp, sp, -112
62 .cfi_def_cfa_offset 112
63 li t1, 2
64 .Ls8:
65 sd s8, 32(sp)
66 .cfi_offset 24, -80
67 sd s7, 40(sp)
68 .cfi_offset 23, -72
69 j .Ls6
70
71 FUNC_BEGIN (__riscv_save_7)
72 FUNC_BEGIN (__riscv_save_6)
73 .cfi_restore 23
74 .cfi_restore 24
75 .cfi_restore 25
76 .cfi_restore 26
77 .cfi_restore 27
78 addi sp, sp, -112
79 .cfi_def_cfa_offset 112
80 li t1, 3
81 .Ls6:
82 sd s6, 48(sp)
83 .cfi_offset 22, -64
84 sd s5, 56(sp)
85 .cfi_offset 21, -56
86 j .Ls4
87
88 FUNC_BEGIN (__riscv_save_5)
89 FUNC_BEGIN (__riscv_save_4)
90 .cfi_restore 21
91 .cfi_restore 22
92 .cfi_restore 24
93 .cfi_restore 25
94 .cfi_restore 26
95 .cfi_restore 27
96 .cfi_restore 24
97 .cfi_restore 25
98 .cfi_restore 26
99 .cfi_restore 27
100 addi sp, sp, -112
101 .cfi_def_cfa_offset 112
102 li t1, 4
103 .Ls4:
104 sd s4, 64(sp)
105 .cfi_offset 20, -48
106 sd s3, 72(sp)
107 .cfi_offset 19, -40
108 j .Ls2
109
110 FUNC_BEGIN (__riscv_save_3)
111 FUNC_BEGIN (__riscv_save_2)
112 .cfi_restore 19
113 .cfi_restore 20
114 .cfi_restore 21
115 .cfi_restore 22
116 .cfi_restore 24
117 .cfi_restore 25
118 .cfi_restore 26
119 .cfi_restore 27
120 .cfi_restore 24
121 .cfi_restore 25
122 .cfi_restore 26
123 .cfi_restore 27
124 addi sp, sp, -112
125 .cfi_def_cfa_offset 112
126 li t1, 5
127 .Ls2:
128 sd s2, 80(sp)
129 .cfi_offset 18, -32
130 sd s1, 88(sp)
131 .cfi_offset 9, -24
132 sd s0, 96(sp)
133 .cfi_offset 8, -16
134 sd ra, 104(sp)
135 .cfi_offset 1, -8
136 slli t1, t1, 4
137 # CFA info is not correct in next 2 instruction since t1's
138 # value is depend on how may register really save.
139 add sp, sp, t1
140 SET_LPAD
141 jr t0
142 .cfi_endproc
143 FUNC_END (__riscv_save_12)
144 FUNC_END (__riscv_save_11)
145 FUNC_END (__riscv_save_10)
146 FUNC_END (__riscv_save_9)
147 FUNC_END (__riscv_save_8)
148 FUNC_END (__riscv_save_7)
149 FUNC_END (__riscv_save_6)
150 FUNC_END (__riscv_save_5)
151 FUNC_END (__riscv_save_4)
152 FUNC_END (__riscv_save_3)
153 FUNC_END (__riscv_save_2)
154
155 FUNC_BEGIN (__riscv_save_1)
156 FUNC_BEGIN (__riscv_save_0)
157 .cfi_startproc
158 # __riscv_save_* routine use t0/x5 as return address
159 .cfi_return_column 5
160 addi sp, sp, -16
161 .cfi_def_cfa_offset 16
162 sd s0, 0(sp)
163 .cfi_offset 8, -16
164 sd ra, 8(sp)
165 .cfi_offset 1, -8
166 SET_LPAD
167 jr t0
168 .cfi_endproc
169 FUNC_END (__riscv_save_1)
170 FUNC_END (__riscv_save_0)
171
172 FUNC_BEGIN (__riscv_restore_12)
173 .cfi_startproc
174 .cfi_def_cfa_offset 112
175 .cfi_offset 27, -104
176 .cfi_offset 26, -96
177 .cfi_offset 25, -88
178 .cfi_offset 24, -80
179 .cfi_offset 23, -72
180 .cfi_offset 22, -64
181 .cfi_offset 21, -56
182 .cfi_offset 20, -48
183 .cfi_offset 19, -40
184 .cfi_offset 18, -32
185 .cfi_offset 9, -24
186 .cfi_offset 8, -16
187 .cfi_offset 1, -8
188 ld s11, 8(sp)
189 .cfi_restore 27
190 addi sp, sp, 16
191
192 FUNC_BEGIN (__riscv_restore_11)
193 FUNC_BEGIN (__riscv_restore_10)
194 .cfi_restore 27
195 .cfi_def_cfa_offset 96
196 ld s10, 0(sp)
197 .cfi_restore 26
198 ld s9, 8(sp)
199 .cfi_restore 25
200 addi sp, sp, 16
201
202 FUNC_BEGIN (__riscv_restore_9)
203 FUNC_BEGIN (__riscv_restore_8)
204 .cfi_restore 25
205 .cfi_restore 26
206 .cfi_restore 27
207 .cfi_def_cfa_offset 80
208 ld s8, 0(sp)
209 .cfi_restore 24
210 ld s7, 8(sp)
211 .cfi_restore 23
212 addi sp, sp, 16
213
214 FUNC_BEGIN (__riscv_restore_7)
215 FUNC_BEGIN (__riscv_restore_6)
216 .cfi_restore 23
217 .cfi_restore 24
218 .cfi_restore 25
219 .cfi_restore 26
220 .cfi_restore 27
221 .cfi_def_cfa_offset 64
222 ld s6, 0(sp)
223 .cfi_restore 22
224 ld s5, 8(sp)
225 .cfi_restore 21
226 addi sp, sp, 16
227
228 FUNC_BEGIN (__riscv_restore_5)
229 FUNC_BEGIN (__riscv_restore_4)
230 .cfi_restore 21
231 .cfi_restore 22
232 .cfi_restore 23
233 .cfi_restore 24
234 .cfi_restore 25
235 .cfi_restore 26
236 .cfi_restore 27
237 .cfi_def_cfa_offset 48
238 ld s4, 0(sp)
239 .cfi_restore 20
240 ld s3, 8(sp)
241 .cfi_restore 19
242 addi sp, sp, 16
243
244 FUNC_BEGIN (__riscv_restore_3)
245 FUNC_BEGIN (__riscv_restore_2)
246 .cfi_restore 19
247 .cfi_restore 20
248 .cfi_restore 21
249 .cfi_restore 22
250 .cfi_restore 23
251 .cfi_restore 24
252 .cfi_restore 25
253 .cfi_restore 26
254 .cfi_restore 27
255 .cfi_def_cfa_offset 32
256 ld s2, 0(sp)
257 .cfi_restore 18
258 ld s1, 8(sp)
259 .cfi_restore 9
260 addi sp, sp, 16
261
262 FUNC_BEGIN (__riscv_restore_1)
263 FUNC_BEGIN (__riscv_restore_0)
264 .cfi_restore 9
265 .cfi_restore 18
266 .cfi_restore 19
267 .cfi_restore 20
268 .cfi_restore 21
269 .cfi_restore 22
270 .cfi_restore 23
271 .cfi_restore 24
272 .cfi_restore 25
273 .cfi_restore 26
274 .cfi_restore 27
275 .cfi_def_cfa_offset 16
276 ld s0, 0(sp)
277 .cfi_restore 8
278 ld ra, 8(sp)
279 .cfi_restore 1
280 addi sp, sp, 16
281 .cfi_def_cfa_offset 0
282 ret
283 .cfi_endproc
284 FUNC_END (__riscv_restore_12)
285 FUNC_END (__riscv_restore_11)
286 FUNC_END (__riscv_restore_10)
287 FUNC_END (__riscv_restore_9)
288 FUNC_END (__riscv_restore_8)
289 FUNC_END (__riscv_restore_7)
290 FUNC_END (__riscv_restore_6)
291 FUNC_END (__riscv_restore_5)
292 FUNC_END (__riscv_restore_4)
293 FUNC_END (__riscv_restore_3)
294 FUNC_END (__riscv_restore_2)
295 FUNC_END (__riscv_restore_1)
296 FUNC_END (__riscv_restore_0)
297
298 #else
299
300 #ifdef __riscv_abi_rve
301 FUNC_BEGIN(__riscv_save_2)
302 FUNC_BEGIN(__riscv_save_1)
303 FUNC_BEGIN(__riscv_save_0)
304 .cfi_startproc
305 # __riscv_save_* routine use t0/x5 as return address
306 .cfi_return_column 5
307 addi sp, sp, -12
308 .cfi_def_cfa_offset 12
309 sw s1, 0(sp)
310 .cfi_offset 9, -12
311 sw s0, 4(sp)
312 .cfi_offset 8, -8
313 sw ra, 8(sp)
314 .cfi_offset 1, -4
315 SET_LPAD
316 jr t0
317 .cfi_endproc
318 FUNC_END(__riscv_save_2)
319 FUNC_END(__riscv_save_1)
320 FUNC_END(__riscv_save_0)
321
322 FUNC_BEGIN(__riscv_restore_2)
323 FUNC_BEGIN(__riscv_restore_1)
324 FUNC_BEGIN(__riscv_restore_0)
325 .cfi_startproc
326 .cfi_def_cfa_offset 14
327 lw s1, 0(sp)
328 .cfi_restore 9
329 lw s0, 4(sp)
330 .cfi_restore 8
331 lw ra, 8(sp)
332 .cfi_restore 1
333 addi sp, sp, 12
334 .cfi_def_cfa_offset 0
335 ret
336 .cfi_endproc
337 FUNC_END(__riscv_restore_2)
338 FUNC_END(__riscv_restore_1)
339 FUNC_END(__riscv_restore_0)
340
341 #else
342
343 FUNC_BEGIN (__riscv_save_12)
344 .cfi_startproc
345 # __riscv_save_* routine use t0/x5 as return address
346 .cfi_return_column 5
347 addi sp, sp, -64
348 .cfi_def_cfa_offset 64
349 li t1, 0
350 sw s11, 12(sp)
351 .cfi_offset 27, -52
352 j .Ls10
353
354 FUNC_BEGIN (__riscv_save_11)
355 FUNC_BEGIN (__riscv_save_10)
356 FUNC_BEGIN (__riscv_save_9)
357 FUNC_BEGIN (__riscv_save_8)
358 .cfi_restore 27
359 addi sp, sp, -64
360 .cfi_def_cfa_offset 64
361 li t1, -16
362 .Ls10:
363 sw s10, 16(sp)
364 .cfi_offset 26, -48
365 sw s9, 20(sp)
366 .cfi_offset 25, -44
367 sw s8, 24(sp)
368 .cfi_offset 24, -40
369 sw s7, 28(sp)
370 .cfi_offset 23, -36
371 j .Ls6
372
373 FUNC_BEGIN (__riscv_save_7)
374 FUNC_BEGIN (__riscv_save_6)
375 FUNC_BEGIN (__riscv_save_5)
376 FUNC_BEGIN (__riscv_save_4)
377 .cfi_restore 23
378 .cfi_restore 24
379 .cfi_restore 25
380 .cfi_restore 26
381 .cfi_restore 27
382 addi sp, sp, -64
383 .cfi_def_cfa_offset 64
384 li t1, -32
385 .Ls6:
386 sw s6, 32(sp)
387 .cfi_offset 22, -32
388 sw s5, 36(sp)
389 .cfi_offset 21, -28
390 sw s4, 40(sp)
391 .cfi_offset 20, -24
392 sw s3, 44(sp)
393 .cfi_offset 19, -20
394 sw s2, 48(sp)
395 .cfi_offset 18, -16
396 sw s1, 52(sp)
397 .cfi_offset 9, -12
398 sw s0, 56(sp)
399 .cfi_offset 8, -8
400 sw ra, 60(sp)
401 .cfi_offset 1, -4
402 # CFA info is not correct in next 2 instruction since t1's
403 # value is depend on how may register really save.
404 sub sp, sp, t1
405 SET_LPAD
406 jr t0
407 .cfi_endproc
408 FUNC_END (__riscv_save_12)
409 FUNC_END (__riscv_save_11)
410 FUNC_END (__riscv_save_10)
411 FUNC_END (__riscv_save_9)
412 FUNC_END (__riscv_save_8)
413 FUNC_END (__riscv_save_7)
414 FUNC_END (__riscv_save_6)
415 FUNC_END (__riscv_save_5)
416 FUNC_END (__riscv_save_4)
417
418 FUNC_BEGIN (__riscv_save_3)
419 FUNC_BEGIN (__riscv_save_2)
420 FUNC_BEGIN (__riscv_save_1)
421 FUNC_BEGIN (__riscv_save_0)
422 .cfi_startproc
423 # __riscv_save_* routine use t0/x5 as return address
424 .cfi_return_column 5
425 addi sp, sp, -16
426 .cfi_def_cfa_offset 16
427 sw s2, 0(sp)
428 .cfi_offset 18, -16
429 sw s1, 4(sp)
430 .cfi_offset 9, -12
431 sw s0, 8(sp)
432 .cfi_offset 8, -8
433 sw ra, 12(sp)
434 .cfi_offset 1, -4
435 SET_LPAD
436 jr t0
437 .cfi_endproc
438 FUNC_END (__riscv_save_3)
439 FUNC_END (__riscv_save_2)
440 FUNC_END (__riscv_save_1)
441 FUNC_END (__riscv_save_0)
442
443 FUNC_BEGIN (__riscv_restore_12)
444 .cfi_startproc
445 .cfi_def_cfa_offset 64
446 .cfi_offset 27, -52
447 .cfi_offset 26, -48
448 .cfi_offset 25, -44
449 .cfi_offset 24, -40
450 .cfi_offset 23, -36
451 .cfi_offset 22, -32
452 .cfi_offset 21, -28
453 .cfi_offset 20, -24
454 .cfi_offset 19, -20
455 .cfi_offset 18, -16
456 .cfi_offset 9, -12
457 .cfi_offset 8, -8
458 .cfi_offset 1, -4
459 lw s11, 12(sp)
460 .cfi_restore 27
461 addi sp, sp, 16
462
463 FUNC_BEGIN (__riscv_restore_11)
464 FUNC_BEGIN (__riscv_restore_10)
465 FUNC_BEGIN (__riscv_restore_9)
466 FUNC_BEGIN (__riscv_restore_8)
467 .cfi_restore 27
468 .cfi_def_cfa_offset 48
469 lw s10, 0(sp)
470 .cfi_restore 26
471 lw s9, 4(sp)
472 .cfi_restore 25
473 lw s8, 8(sp)
474 .cfi_restore 24
475 lw s7, 12(sp)
476 .cfi_restore 23
477 addi sp, sp, 16
478
479 FUNC_BEGIN (__riscv_restore_7)
480 FUNC_BEGIN (__riscv_restore_6)
481 FUNC_BEGIN (__riscv_restore_5)
482 FUNC_BEGIN (__riscv_restore_4)
483 .cfi_restore 23
484 .cfi_restore 24
485 .cfi_restore 25
486 .cfi_restore 26
487 .cfi_restore 27
488 .cfi_def_cfa_offset 32
489 lw s6, 0(sp)
490 .cfi_restore 22
491 lw s5, 4(sp)
492 .cfi_restore 21
493 lw s4, 8(sp)
494 .cfi_restore 20
495 lw s3, 12(sp)
496 .cfi_restore 19
497 addi sp, sp, 16
498
499 FUNC_BEGIN (__riscv_restore_3)
500 FUNC_BEGIN (__riscv_restore_2)
501 FUNC_BEGIN (__riscv_restore_1)
502 FUNC_BEGIN (__riscv_restore_0)
503 .cfi_restore 19
504 .cfi_restore 20
505 .cfi_restore 21
506 .cfi_restore 22
507 .cfi_restore 24
508 .cfi_restore 25
509 .cfi_restore 26
510 .cfi_restore 27
511 .cfi_def_cfa_offset 16
512 lw s2, 0(sp)
513 .cfi_restore 18
514 lw s1, 4(sp)
515 .cfi_restore 9
516 lw s0, 8(sp)
517 .cfi_restore 8
518 lw ra, 12(sp)
519 .cfi_restore 1
520 addi sp, sp, 16
521 .cfi_def_cfa_offset 0
522 ret
523 .cfi_endproc
524 FUNC_END (__riscv_restore_12)
525 FUNC_END (__riscv_restore_11)
526 FUNC_END (__riscv_restore_10)
527 FUNC_END (__riscv_restore_9)
528 FUNC_END (__riscv_restore_8)
529 FUNC_END (__riscv_restore_7)
530 FUNC_END (__riscv_restore_6)
531 FUNC_END (__riscv_restore_5)
532 FUNC_END (__riscv_restore_4)
533 FUNC_END (__riscv_restore_3)
534 FUNC_END (__riscv_restore_2)
535 FUNC_END (__riscv_restore_1)
536 FUNC_END (__riscv_restore_0)
537
538 #endif /* __riscv_abi_rve */
539
540 #endif /* __riscv_xlen == 64 */