xref: /freebsd/lib/csu/powerpc/crtsavres.S (revision e1c4c8dd8d2d10b6104f06856a77bd5b4813a801)
1/*-
2 * SPDX-License-Identifier: BSD-1-Clause
3 *
4 * Copyright 2019 Justin Hibbits
5 *
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
8 * are met:
9 * 1. Redistributions of source code must retain the above copyright
10 *    notice, this list of conditions and the following disclaimer.
11 *
12 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
13 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
14 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
15 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
16 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
17 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
18 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
19 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
20 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
21 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
22 */
23
24#include <machine/asm.h>
25.text
26
27/*
28 * The PowerPC ABI spec requires the following save/restore functions to be
29 * provided:
30 *
31 * _savefpr_N
32 * _restfpr_N
33 * _restfpr_N_x
34 * _savegpr_N
35 * _restgpr_N
36 * _restgpr_N_x
37 *
38 * With N ranging from 14 to 31, to save the nonvolatile registers.
39 */
40
41#define _CRTENTRY(name) \
42	.text; \
43	.globl	name; \
44	.type	name,@function; \
45	name:
46
47#define SAVEFPR(r)	_CRTENTRY(__CONCAT(_savefpr_,r))	\
48	stfd	r,(-256 + r * 8)(11)
49
50SAVEFPR(14)
51SAVEFPR(15)
52SAVEFPR(16)
53SAVEFPR(17)
54SAVEFPR(18)
55SAVEFPR(19)
56SAVEFPR(20)
57SAVEFPR(21)
58SAVEFPR(22)
59SAVEFPR(23)
60SAVEFPR(24)
61SAVEFPR(25)
62SAVEFPR(26)
63SAVEFPR(27)
64SAVEFPR(28)
65SAVEFPR(29)
66SAVEFPR(30)
67SAVEFPR(31)
68	blr
69
70#define RESTFPR(r)	_CRTENTRY(__CONCAT(_restfpr_,r))	\
71	lfd	r,(-256 + r * 8)(11)
72
73RESTFPR(14)
74RESTFPR(15)
75RESTFPR(16)
76RESTFPR(17)
77RESTFPR(18)
78RESTFPR(19)
79RESTFPR(20)
80RESTFPR(21)
81RESTFPR(22)
82RESTFPR(23)
83RESTFPR(24)
84RESTFPR(25)
85RESTFPR(26)
86RESTFPR(27)
87RESTFPR(28)
88RESTFPR(29)
89RESTFPR(30)
90RESTFPR(31)
91	blr
92
93#define SAVEGPR(r)	_CRTENTRY(__CONCAT(_savegpr_,r))	\
94	stw	r,(-128 + r * 4)(11)
95
96SAVEGPR(14)
97SAVEGPR(15)
98SAVEGPR(16)
99SAVEGPR(17)
100SAVEGPR(18)
101SAVEGPR(19)
102SAVEGPR(20)
103SAVEGPR(21)
104SAVEGPR(22)
105SAVEGPR(23)
106SAVEGPR(24)
107SAVEGPR(25)
108SAVEGPR(26)
109SAVEGPR(27)
110SAVEGPR(28)
111SAVEGPR(29)
112SAVEGPR(30)
113SAVEGPR(31)
114	blr
115
116#define RESTGPR(r)	_CRTENTRY(__CONCAT(_restgpr_,r))	\
117	lwz	r,(-128 + r*4)(11)
118
119RESTGPR(14)
120RESTGPR(15)
121RESTGPR(16)
122RESTGPR(17)
123RESTGPR(18)
124RESTGPR(19)
125RESTGPR(20)
126RESTGPR(21)
127RESTGPR(22)
128RESTGPR(23)
129RESTGPR(24)
130RESTGPR(25)
131RESTGPR(26)
132RESTGPR(27)
133RESTGPR(28)
134RESTGPR(29)
135RESTGPR(30)
136RESTGPR(31)
137	blr
138
139#define RESTFPR_X(r)	_CRTENTRY(__CONCAT(__CONCAT(_restfpr_,r),_x))	\
140	lfd	r,(-256 + r * 8)(11)
141
142RESTFPR_X(14)
143RESTFPR_X(15)
144RESTFPR_X(16)
145RESTFPR_X(17)
146RESTFPR_X(18)
147RESTFPR_X(19)
148RESTFPR_X(20)
149RESTFPR_X(21)
150RESTFPR_X(22)
151RESTFPR_X(23)
152RESTFPR_X(24)
153RESTFPR_X(25)
154RESTFPR_X(26)
155RESTFPR_X(27)
156RESTFPR_X(28)
157RESTFPR_X(29)
158RESTFPR_X(30)
159RESTFPR_X(31)
160	lwz	0,4(11)
161	mtlr	0
162	mr	1,11
163	blr
164
165#define RESTGPR_X(r)	_CRTENTRY(__CONCAT(__CONCAT(_restgpr_,r),_x))	\
166	lwz	r,(-128 + r * 4)(11)
167
168RESTGPR_X(14)
169RESTGPR_X(15)
170RESTGPR_X(16)
171RESTGPR_X(17)
172RESTGPR_X(18)
173RESTGPR_X(19)
174RESTGPR_X(20)
175RESTGPR_X(21)
176RESTGPR_X(22)
177RESTGPR_X(23)
178RESTGPR_X(24)
179RESTGPR_X(25)
180RESTGPR_X(26)
181RESTGPR_X(27)
182RESTGPR_X(28)
183RESTGPR_X(29)
184RESTGPR_X(30)
185RESTGPR_X(31)
186	lwz	0,4(11)
187	mtlr	0
188	mr	1,11
189	blr
190