* builtins.def (BUILT_IN_SETJMP): Revert latest change.
[official-gcc.git] / libgcc / config / riscv / save-restore.S
blob2073a73089bba3adf7fd9065407c8feb47b263b5
1 /* Callee-saved register spill and fill routines for RISC-V.
3    Copyright (C) 2016-2017 Free Software Foundation, Inc.
5 This file is part of GCC.
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.
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.
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.
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/>.  */
26   .text
28   .globl __riscv_save_12
29   .globl __riscv_save_11
30   .globl __riscv_save_10
31   .globl __riscv_save_9
32   .globl __riscv_save_8
33   .globl __riscv_save_7
34   .globl __riscv_save_6
35   .globl __riscv_save_5
36   .globl __riscv_save_4
37   .globl __riscv_save_3
38   .globl __riscv_save_2
39   .globl __riscv_save_1
40   .globl __riscv_save_0
42   .globl __riscv_restore_12
43   .globl __riscv_restore_11
44   .globl __riscv_restore_10
45   .globl __riscv_restore_9
46   .globl __riscv_restore_8
47   .globl __riscv_restore_7
48   .globl __riscv_restore_6
49   .globl __riscv_restore_5
50   .globl __riscv_restore_4
51   .globl __riscv_restore_3
52   .globl __riscv_restore_2
53   .globl __riscv_restore_1
54   .globl __riscv_restore_0
56 #if __riscv_xlen == 64
58 __riscv_save_12:
59   .cfi_startproc
60   # __riscv_save_* routine use t0/x5 as return address
61   .cfi_return_column 5
62   addi sp, sp, -112
63   .cfi_def_cfa_offset 112
64   li t1, 0
65   sd s11, 8(sp)
66   .cfi_offset 27, -104
67   j .Ls10
69 __riscv_save_11:
70 __riscv_save_10:
71   .cfi_restore 27
72   addi sp, sp, -112
73   .cfi_def_cfa_offset 112
74   li t1, -16
75 .Ls10:
76   sd s10, 16(sp)
77   .cfi_offset 26, -96
78   sd s9, 24(sp)
79   .cfi_offset 25, -88
80   j .Ls8
82 __riscv_save_9:
83 __riscv_save_8:
84   .cfi_restore 25
85   .cfi_restore 26
86   .cfi_restore 27
87   addi sp, sp, -112
88   .cfi_def_cfa_offset 112
89   li t1, -32
90 .Ls8:
91   sd s8, 32(sp)
92   .cfi_offset 24, -80
93   sd s7, 40(sp)
94   .cfi_offset 23, -72
95   j .Ls6
97 __riscv_save_7:
98 __riscv_save_6:
99   .cfi_restore 23
100   .cfi_restore 24
101   .cfi_restore 25
102   .cfi_restore 26
103   .cfi_restore 27
104   addi sp, sp, -112
105   .cfi_def_cfa_offset 112
106   li t1, -48
107 .Ls6:
108   sd s6, 48(sp)
109   .cfi_offset 22, -64
110   sd s5, 56(sp)
111   .cfi_offset 21, -56
112   j .Ls4
114 __riscv_save_5:
115 __riscv_save_4:
116   .cfi_restore 21
117   .cfi_restore 22
118   .cfi_restore 24
119   .cfi_restore 25
120   .cfi_restore 26
121   .cfi_restore 27
122   .cfi_restore 24
123   .cfi_restore 25
124   .cfi_restore 26
125   .cfi_restore 27
126   addi sp, sp, -112
127   .cfi_def_cfa_offset 112
128   li t1, -64
129 .Ls4:
130   sd s4, 64(sp)
131   .cfi_offset 20, -48
132   sd s3, 72(sp)
133   .cfi_offset 19, -40
134   j .Ls2
136 __riscv_save_3:
137 __riscv_save_2:
138   .cfi_restore 19
139   .cfi_restore 20
140   .cfi_restore 21
141   .cfi_restore 22
142   .cfi_restore 24
143   .cfi_restore 25
144   .cfi_restore 26
145   .cfi_restore 27
146   .cfi_restore 24
147   .cfi_restore 25
148   .cfi_restore 26
149   .cfi_restore 27
150   addi sp, sp, -112
151   .cfi_def_cfa_offset 112
152   li t1, -80
153 .Ls2:
154   sd s2, 80(sp)
155   .cfi_offset 18, -32
156   sd s1, 88(sp)
157   .cfi_offset 9, -24
158   sd s0, 96(sp)
159   .cfi_offset 8, -16
160   sd ra, 104(sp)
161   .cfi_offset 1, -8
162   # CFA info is not correct in next 2 instruction since t1's
163   # value is depend on how may register really save.
164   sub sp, sp, t1
165   jr t0
166   .cfi_endproc
168 __riscv_save_1:
169 __riscv_save_0:
170   .cfi_startproc
171   # __riscv_save_* routine use t0/x5 as return address
172   .cfi_return_column 5
173   addi sp, sp, -16
174   .cfi_def_cfa_offset 16
175   sd s0, 0(sp)
176   .cfi_offset 8, -16
177   sd ra, 8(sp)
178   .cfi_offset 1, -8
179   jr t0
180   .cfi_endproc
182 __riscv_restore_12:
183   .cfi_startproc
184   .cfi_def_cfa_offset 112
185   .cfi_offset 27, -104
186   .cfi_offset 26, -96
187   .cfi_offset 25, -88
188   .cfi_offset 24, -80
189   .cfi_offset 23, -72
190   .cfi_offset 22, -64
191   .cfi_offset 21, -56
192   .cfi_offset 20, -48
193   .cfi_offset 19, -40
194   .cfi_offset 18, -32
195   .cfi_offset 9, -24
196   .cfi_offset 8, -16
197   .cfi_offset 1, -8
198   ld s11, 8(sp)
199   .cfi_restore 27
200   addi sp, sp, 16
202 __riscv_restore_11:
203 __riscv_restore_10:
204   .cfi_restore 27
205   .cfi_def_cfa_offset 96
206   ld s10, 0(sp)
207   .cfi_restore 26
208   ld s9, 8(sp)
209   .cfi_restore 25
210   addi sp, sp, 16
212 __riscv_restore_9:
213 __riscv_restore_8:
214   .cfi_restore 25
215   .cfi_restore 26
216   .cfi_restore 27
217   .cfi_def_cfa_offset 80
218   ld s8, 0(sp)
219   .cfi_restore 24
220   ld s7, 8(sp)
221   .cfi_restore 23
222   addi sp, sp, 16
224 __riscv_restore_7:
225 __riscv_restore_6:
226   .cfi_restore 23
227   .cfi_restore 24
228   .cfi_restore 25
229   .cfi_restore 26
230   .cfi_restore 27
231   .cfi_def_cfa_offset 64
232   ld s6, 0(sp)
233   .cfi_restore 22
234   ld s5, 8(sp)
235   .cfi_restore 21
236   addi sp, sp, 16
238 __riscv_restore_5:
239 __riscv_restore_4:
240   .cfi_restore 21
241   .cfi_restore 22
242   .cfi_restore 23
243   .cfi_restore 24
244   .cfi_restore 25
245   .cfi_restore 26
246   .cfi_restore 27
247   .cfi_def_cfa_offset 48
248   ld s4, 0(sp)
249   .cfi_restore 20
250   ld s3, 8(sp)
251   .cfi_restore 19
252   addi sp, sp, 16
254 __riscv_restore_3:
255 __riscv_restore_2:
256   .cfi_restore 19
257   .cfi_restore 20
258   .cfi_restore 21
259   .cfi_restore 22
260   .cfi_restore 23
261   .cfi_restore 24
262   .cfi_restore 25
263   .cfi_restore 26
264   .cfi_restore 27
265   .cfi_def_cfa_offset 32
266   ld s2, 0(sp)
267   .cfi_restore 18
268   ld s1, 8(sp)
269   .cfi_restore 9
270   addi sp, sp, 16
272 __riscv_restore_1:
273 __riscv_restore_0:
274   .cfi_restore 9
275   .cfi_restore 18
276   .cfi_restore 19
277   .cfi_restore 20
278   .cfi_restore 21
279   .cfi_restore 22
280   .cfi_restore 23
281   .cfi_restore 24
282   .cfi_restore 25
283   .cfi_restore 26
284   .cfi_restore 27
285   .cfi_def_cfa_offset 16
286   ld s0, 0(sp)
287   .cfi_restore 8
288   ld ra, 8(sp)
289   .cfi_restore 1
290   addi sp, sp, 16
291   .cfi_def_cfa_offset 0
292   ret
293   .cfi_endproc
295 #else
297 __riscv_save_12:
298   .cfi_startproc
299   # __riscv_save_* routine use t0/x5 as return address
300   .cfi_return_column 5
301   addi sp, sp, -64
302   .cfi_def_cfa_offset 64
303   li t1, 0
304   sw s11, 12(sp)
305   .cfi_offset 27, -52
306   j .Ls10
308 __riscv_save_11:
309 __riscv_save_10:
310 __riscv_save_9:
311 __riscv_save_8:
312   .cfi_restore 27
313   addi sp, sp, -64
314   .cfi_def_cfa_offset 64
315   li t1, -16
316 .Ls10:
317   sw s10, 16(sp)
318   .cfi_offset 26, -48
319   sw s9, 20(sp)
320   .cfi_offset 25, -44
321   sw s8, 24(sp)
322   .cfi_offset 24, -40
323   sw s7, 28(sp)
324   .cfi_offset 23, -36
325   j .Ls6
327 __riscv_save_7:
328 __riscv_save_6:
329 __riscv_save_5:
330 __riscv_save_4:
331   .cfi_restore 23
332   .cfi_restore 24
333   .cfi_restore 25
334   .cfi_restore 26
335   .cfi_restore 27
336   addi sp, sp, -64
337   .cfi_def_cfa_offset 64
338   li t1, -32
339 .Ls6:
340   sw s6, 32(sp)
341   .cfi_offset 22, -32
342   sw s5, 36(sp)
343   .cfi_offset 21, -28
344   sw s4, 40(sp)
345   .cfi_offset 20, -24
346   sw s3, 44(sp)
347   .cfi_offset 19, -20
348   sw s2, 48(sp)
349   .cfi_offset 18, -16
350   sw s1, 52(sp)
351   .cfi_offset 9, -12
352   sw s0, 56(sp)
353   .cfi_offset 8, -8
354   sw ra, 60(sp)
355   .cfi_offset 1, -4
356   # CFA info is not correct in next 2 instruction since t1's
357   # value is depend on how may register really save.
358   sub sp, sp, t1
359   jr t0
360   .cfi_endproc
362 __riscv_save_3:
363 __riscv_save_2:
364 __riscv_save_1:
365 __riscv_save_0:
366   .cfi_startproc
367   # __riscv_save_* routine use t0/x5 as return address
368   .cfi_return_column 5
369   addi sp, sp, -16
370   .cfi_def_cfa_offset 16
371   sw s2, 0(sp)
372   sw s1, 4(sp)
373   .cfi_offset 9, -16
374   sw s0, 8(sp)
375   .cfi_offset 8, -8
376   sw ra, 12(sp)
377   .cfi_offset 1, -4
378   jr t0
379   .cfi_endproc
381 __riscv_restore_12:
382   .cfi_startproc
383   .cfi_def_cfa_offset 64
384   .cfi_offset 27, -52
385   .cfi_offset 26, -48
386   .cfi_offset 25, -44
387   .cfi_offset 24, -40
388   .cfi_offset 23, -36
389   .cfi_offset 22, -32
390   .cfi_offset 21, -28
391   .cfi_offset 20, -24
392   .cfi_offset 19, -20
393   .cfi_offset 18, -16
394   .cfi_offset 9, -12
395   .cfi_offset 8, -8
396   .cfi_offset 1, -4
397   lw s11, 12(sp)
398   .cfi_restore 27
399   addi sp, sp, 16
401 __riscv_restore_11:
402 __riscv_restore_10:
403 __riscv_restore_9:
404 __riscv_restore_8:
405   .cfi_restore 27
406   .cfi_def_cfa_offset 48
407   lw s10, 0(sp)
408   .cfi_restore 26
409   lw s9, 4(sp)
410   .cfi_restore 25
411   lw s8, 8(sp)
412   .cfi_restore 24
413   lw s7, 12(sp)
414   .cfi_restore 23
415   addi sp, sp, 16
417 __riscv_restore_7:
418 __riscv_restore_6:
419 __riscv_restore_5:
420 __riscv_restore_4:
421   .cfi_restore 23
422   .cfi_restore 24
423   .cfi_restore 25
424   .cfi_restore 26
425   .cfi_restore 27
426   .cfi_def_cfa_offset 32
427   lw s6, 0(sp)
428   .cfi_restore 22
429   lw s5, 4(sp)
430   .cfi_restore 21
431   lw s4, 8(sp)
432   .cfi_restore 20
433   lw s3, 12(sp)
434   .cfi_restore 19
435   addi sp, sp, 16
437 __riscv_restore_3:
438 __riscv_restore_2:
439 __riscv_restore_1:
440 __riscv_restore_0:
441   .cfi_restore 19
442   .cfi_restore 20
443   .cfi_restore 21
444   .cfi_restore 22
445   .cfi_restore 24
446   .cfi_restore 25
447   .cfi_restore 26
448   .cfi_restore 27
449   .cfi_def_cfa_offset 16
450   lw s2, 0(sp)
451   .cfi_restore 18
452   lw s1, 4(sp)
453   .cfi_restore 9
454   lw s0, 8(sp)
455   .cfi_restore 8
456   lw ra, 12(sp)
457   .cfi_restore 1
458   addi sp, sp, 16
459   .cfi_def_cfa_offset 0
460   ret
461   .cfi_endproc
463 #endif