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