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