RISC-V: Add RV32E support.
[official-gcc.git] / libgcc / config / riscv / save-restore.S
bloba76c978090227383605878d45927ba154318a051
1 /* Callee-saved register spill and fill routines for RISC-V.
3    Copyright (C) 2016-2018 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 #include "riscv-asm.h"
28   .text
30 #if __riscv_xlen == 64
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
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, -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
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, -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
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, -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
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, -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
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, -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
141 FUNC_END (__riscv_save_12)
142 FUNC_END (__riscv_save_11)
143 FUNC_END (__riscv_save_10)
144 FUNC_END (__riscv_save_9)
145 FUNC_END (__riscv_save_8)
146 FUNC_END (__riscv_save_7)
147 FUNC_END (__riscv_save_6)
148 FUNC_END (__riscv_save_5)
149 FUNC_END (__riscv_save_4)
150 FUNC_END (__riscv_save_3)
151 FUNC_END (__riscv_save_2)
153 FUNC_BEGIN (__riscv_save_1)
154 FUNC_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
166 FUNC_END (__riscv_save_1)
167 FUNC_END (__riscv_save_0)
169 FUNC_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
189 FUNC_BEGIN (__riscv_restore_11)
190 FUNC_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
199 FUNC_BEGIN (__riscv_restore_9)
200 FUNC_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
211 FUNC_BEGIN (__riscv_restore_7)
212 FUNC_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
225 FUNC_BEGIN (__riscv_restore_5)
226 FUNC_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
241 FUNC_BEGIN (__riscv_restore_3)
242 FUNC_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
259 FUNC_BEGIN (__riscv_restore_1)
260 FUNC_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
281 FUNC_END (__riscv_restore_12)
282 FUNC_END (__riscv_restore_11)
283 FUNC_END (__riscv_restore_10)
284 FUNC_END (__riscv_restore_9)
285 FUNC_END (__riscv_restore_8)
286 FUNC_END (__riscv_restore_7)
287 FUNC_END (__riscv_restore_6)
288 FUNC_END (__riscv_restore_5)
289 FUNC_END (__riscv_restore_4)
290 FUNC_END (__riscv_restore_3)
291 FUNC_END (__riscv_restore_2)
292 FUNC_END (__riscv_restore_1)
293 FUNC_END (__riscv_restore_0)
295 #else
297 #ifdef __riscv_32e
298 FUNC_BEGIN(__riscv_save_2)
299 FUNC_BEGIN(__riscv_save_1)
300 FUNC_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
314 FUNC_END(__riscv_save_2)
315 FUNC_END(__riscv_save_1)
316 FUNC_END(__riscv_save_0)
318 FUNC_BEGIN(__riscv_restore_2)
319 FUNC_BEGIN(__riscv_restore_1)
320 FUNC_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
333 FUNC_END(__riscv_restore_2)
334 FUNC_END(__riscv_restore_1)
335 FUNC_END(__riscv_restore_0)
337 #else
339 FUNC_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
350 FUNC_BEGIN (__riscv_save_11)
351 FUNC_BEGIN (__riscv_save_10)
352 FUNC_BEGIN (__riscv_save_9)
353 FUNC_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
369 FUNC_BEGIN (__riscv_save_7)
370 FUNC_BEGIN (__riscv_save_6)
371 FUNC_BEGIN (__riscv_save_5)
372 FUNC_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
403 FUNC_END (__riscv_save_12)
404 FUNC_END (__riscv_save_11)
405 FUNC_END (__riscv_save_10)
406 FUNC_END (__riscv_save_9)
407 FUNC_END (__riscv_save_8)
408 FUNC_END (__riscv_save_7)
409 FUNC_END (__riscv_save_6)
410 FUNC_END (__riscv_save_5)
411 FUNC_END (__riscv_save_4)
413 FUNC_BEGIN (__riscv_save_3)
414 FUNC_BEGIN (__riscv_save_2)
415 FUNC_BEGIN (__riscv_save_1)
416 FUNC_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
431 FUNC_END (__riscv_save_3)
432 FUNC_END (__riscv_save_2)
433 FUNC_END (__riscv_save_1)
434 FUNC_END (__riscv_save_0)
436 FUNC_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
456 FUNC_BEGIN (__riscv_restore_11)
457 FUNC_BEGIN (__riscv_restore_10)
458 FUNC_BEGIN (__riscv_restore_9)
459 FUNC_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
472 FUNC_BEGIN (__riscv_restore_7)
473 FUNC_BEGIN (__riscv_restore_6)
474 FUNC_BEGIN (__riscv_restore_5)
475 FUNC_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
492 FUNC_BEGIN (__riscv_restore_3)
493 FUNC_BEGIN (__riscv_restore_2)
494 FUNC_BEGIN (__riscv_restore_1)
495 FUNC_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
517 FUNC_END (__riscv_restore_12)
518 FUNC_END (__riscv_restore_11)
519 FUNC_END (__riscv_restore_10)
520 FUNC_END (__riscv_restore_9)
521 FUNC_END (__riscv_restore_8)
522 FUNC_END (__riscv_restore_7)
523 FUNC_END (__riscv_restore_6)
524 FUNC_END (__riscv_restore_5)
525 FUNC_END (__riscv_restore_4)
526 FUNC_END (__riscv_restore_3)
527 FUNC_END (__riscv_restore_2)
528 FUNC_END (__riscv_restore_1)
529 FUNC_END (__riscv_restore_0)
531 #endif /* __riscv_32e */
533 #endif /* __riscv_xlen == 64 */