xref: /freebsd/lib/csu/powerpc/crtsavres.S (revision 3c4ba5f55438f7afd4f4b0b56f88f2bb505fd6a6)
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__FBSDID("$FreeBSD$");
26
27.text
28
29/*
30 * The PowerPC ABI spec requires the following save/restore functions to be
31 * provided:
32 *
33 * _savefpr_N
34 * _restfpr_N
35 * _restfpr_N_x
36 * _savegpr_N
37 * _restgpr_N
38 * _restgpr_N_x
39 *
40 * With N ranging from 14 to 31, to save the nonvolatile registers.
41 */
42
43#define _CRTENTRY(name) \
44	.text; \
45	.globl	name; \
46	.type	name,@function; \
47	name:
48
49#define SAVEFPR(r)	_CRTENTRY(__CONCAT(_savefpr_,r))	\
50	stfd	r,(-256 + r * 8)(11)
51
52SAVEFPR(14)
53SAVEFPR(15)
54SAVEFPR(16)
55SAVEFPR(17)
56SAVEFPR(18)
57SAVEFPR(19)
58SAVEFPR(20)
59SAVEFPR(21)
60SAVEFPR(22)
61SAVEFPR(23)
62SAVEFPR(24)
63SAVEFPR(25)
64SAVEFPR(26)
65SAVEFPR(27)
66SAVEFPR(28)
67SAVEFPR(29)
68SAVEFPR(30)
69SAVEFPR(31)
70	blr
71
72#define RESTFPR(r)	_CRTENTRY(__CONCAT(_restfpr_,r))	\
73	lfd	r,(-256 + r * 8)(11)
74
75RESTFPR(14)
76RESTFPR(15)
77RESTFPR(16)
78RESTFPR(17)
79RESTFPR(18)
80RESTFPR(19)
81RESTFPR(20)
82RESTFPR(21)
83RESTFPR(22)
84RESTFPR(23)
85RESTFPR(24)
86RESTFPR(25)
87RESTFPR(26)
88RESTFPR(27)
89RESTFPR(28)
90RESTFPR(29)
91RESTFPR(30)
92RESTFPR(31)
93	blr
94
95#define SAVEGPR(r)	_CRTENTRY(__CONCAT(_savegpr_,r))	\
96	stw	r,(-128 + r * 4)(11)
97
98SAVEGPR(14)
99SAVEGPR(15)
100SAVEGPR(16)
101SAVEGPR(17)
102SAVEGPR(18)
103SAVEGPR(19)
104SAVEGPR(20)
105SAVEGPR(21)
106SAVEGPR(22)
107SAVEGPR(23)
108SAVEGPR(24)
109SAVEGPR(25)
110SAVEGPR(26)
111SAVEGPR(27)
112SAVEGPR(28)
113SAVEGPR(29)
114SAVEGPR(30)
115SAVEGPR(31)
116	blr
117
118#define RESTGPR(r)	_CRTENTRY(__CONCAT(_restgpr_,r))	\
119	lwz	r,(-128 + r*4)(11)
120
121RESTGPR(14)
122RESTGPR(15)
123RESTGPR(16)
124RESTGPR(17)
125RESTGPR(18)
126RESTGPR(19)
127RESTGPR(20)
128RESTGPR(21)
129RESTGPR(22)
130RESTGPR(23)
131RESTGPR(24)
132RESTGPR(25)
133RESTGPR(26)
134RESTGPR(27)
135RESTGPR(28)
136RESTGPR(29)
137RESTGPR(30)
138RESTGPR(31)
139	blr
140
141#define RESTFPR_X(r)	_CRTENTRY(__CONCAT(__CONCAT(_restfpr_,r),_x))	\
142	lfd	r,(-256 + r * 8)(11)
143
144RESTFPR_X(14)
145RESTFPR_X(15)
146RESTFPR_X(16)
147RESTFPR_X(17)
148RESTFPR_X(18)
149RESTFPR_X(19)
150RESTFPR_X(20)
151RESTFPR_X(21)
152RESTFPR_X(22)
153RESTFPR_X(23)
154RESTFPR_X(24)
155RESTFPR_X(25)
156RESTFPR_X(26)
157RESTFPR_X(27)
158RESTFPR_X(28)
159RESTFPR_X(29)
160RESTFPR_X(30)
161RESTFPR_X(31)
162	lwz	0,4(11)
163	mtlr	0
164	mr	1,11
165	blr
166
167#define RESTGPR_X(r)	_CRTENTRY(__CONCAT(__CONCAT(_restgpr_,r),_x))	\
168	lwz	r,(-128 + r * 4)(11)
169
170RESTGPR_X(14)
171RESTGPR_X(15)
172RESTGPR_X(16)
173RESTGPR_X(17)
174RESTGPR_X(18)
175RESTGPR_X(19)
176RESTGPR_X(20)
177RESTGPR_X(21)
178RESTGPR_X(22)
179RESTGPR_X(23)
180RESTGPR_X(24)
181RESTGPR_X(25)
182RESTGPR_X(26)
183RESTGPR_X(27)
184RESTGPR_X(28)
185RESTGPR_X(29)
186RESTGPR_X(30)
187RESTGPR_X(31)
188	lwz	0,4(11)
189	mtlr	0
190	mr	1,11
191	blr
192