blob: 3ca3303e499eb54a0719c5d4ac545bd1f53b9f2a [file] [log] [blame]
sewardj6c591e12011-04-11 16:17:51 +00001
2/*--------------------------------------------------------------------*/
3/*--- A minimal setjmp/longjmp implementation. m_libcsetjmp.c ---*/
4/*--------------------------------------------------------------------*/
5
6/*
7 This file is part of Valgrind, a dynamic binary instrumentation
8 framework.
9
10 Copyright (C) 2010-2010 Mozilla Inc
11
12 This program is free software; you can redistribute it and/or
13 modify it under the terms of the GNU General Public License as
14 published by the Free Software Foundation; either version 2 of the
15 License, or (at your option) any later version.
16
17 This program is distributed in the hope that it will be useful, but
18 WITHOUT ANY WARRANTY; without even the implied warranty of
19 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
20 General Public License for more details.
21
22 You should have received a copy of the GNU General Public License
23 along with this program; if not, write to the Free Software
24 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
25 02111-1307, USA.
26
27 The GNU General Public License is contained in the file COPYING.
28*/
29
30/* Contributed by Julian Seward <jseward@acm.org> */
31
32
33#include "pub_core_basics.h"
34#include "pub_core_libcsetjmp.h" /* self */
35
36
37/* See include/pub_tool_libcsetjmp.h for background and rationale. */
38
sewardj97d3ebb2011-04-11 18:36:34 +000039/* The only alternative implementations are for ppc{32,64}-linux. See
40 #259977. */
41
sewardj2a88a012011-04-11 21:26:27 +000042/* ------------ ppc32-linux ------------ */
43
sewardj97d3ebb2011-04-11 18:36:34 +000044#if defined(VGP_ppc32_linux)
45
46__asm__(
47".text" "\n"
sewardj2a88a012011-04-11 21:26:27 +000048"" "\n"
sewardj97d3ebb2011-04-11 18:36:34 +000049".global VG_MINIMAL_SETJMP" "\n" // r3 = jmp_buf
50"VG_MINIMAL_SETJMP:" "\n"
51" stw 0, 0(3)" "\n"
52" stw 1, 4(3)" "\n"
53" stw 2, 8(3)" "\n"
54" stw 3, 12(3)" "\n"
55" stw 4, 16(3)" "\n"
56" stw 5, 20(3)" "\n"
57" stw 6, 24(3)" "\n"
58" stw 7, 28(3)" "\n"
59" stw 8, 32(3)" "\n"
60" stw 9, 36(3)" "\n"
61" stw 10, 40(3)" "\n"
62" stw 11, 44(3)" "\n"
63" stw 12, 48(3)" "\n"
64" stw 13, 52(3)" "\n"
65" stw 14, 56(3)" "\n"
66" stw 15, 60(3)" "\n"
67" stw 16, 64(3)" "\n"
68" stw 17, 68(3)" "\n"
69" stw 18, 72(3)" "\n"
70" stw 19, 76(3)" "\n"
71" stw 20, 80(3)" "\n"
72" stw 21, 84(3)" "\n"
73" stw 22, 88(3)" "\n"
74" stw 23, 92(3)" "\n"
75" stw 24, 96(3)" "\n"
76" stw 25, 100(3)" "\n"
77" stw 26, 104(3)" "\n"
78" stw 27, 108(3)" "\n"
79" stw 28, 112(3)" "\n"
80" stw 29, 116(3)" "\n"
81" stw 30, 120(3)" "\n"
82" stw 31, 124(3)" "\n"
83 // must use a caller-save register here as scratch, hence r4
84" mflr 4" "\n"
85" stw 4, 128(3)" "\n"
86" mfcr 4" "\n"
87" stw 4, 132(3)" "\n"
88" li 3, 0" "\n"
89" blr" "\n"
sewardj2a88a012011-04-11 21:26:27 +000090"" "\n"
sewardj97d3ebb2011-04-11 18:36:34 +000091
92
93".global VG_MINIMAL_LONGJMP" "\n"
94"VG_MINIMAL_LONGJMP:" "\n" // r3 = jmp_buf
95 // do r4 = 1
96 // and park it in the restore slot for r3 (the ret reg)
97" li 4, 1" "\n"
98" stw 4, 12(3)" "\n"
99 // restore everything except r3
100 // then r3 last of all
101 // then blr
102" lwz 0, 128(3)" "\n"
103" mtlr 0" "\n"
104" lwz 0, 132(3)" "\n"
105" mtcr 0" "\n"
106" lwz 0, 0(3)" "\n"
107" lwz 1, 4(3)" "\n"
108" lwz 2, 8(3)" "\n"
109 // r3 is done at the end
110" lwz 4, 16(3)" "\n"
111" lwz 5, 20(3)" "\n"
112" lwz 6, 24(3)" "\n"
113" lwz 7, 28(3)" "\n"
114" lwz 8, 32(3)" "\n"
115" lwz 9, 36(3)" "\n"
116" lwz 10, 40(3)" "\n"
117" lwz 11, 44(3)" "\n"
118" lwz 12, 48(3)" "\n"
119" lwz 13, 52(3)" "\n"
120" lwz 14, 56(3)" "\n"
121" lwz 15, 60(3)" "\n"
122" lwz 16, 64(3)" "\n"
123" lwz 17, 68(3)" "\n"
124" lwz 18, 72(3)" "\n"
125" lwz 19, 76(3)" "\n"
126" lwz 20, 80(3)" "\n"
127" lwz 21, 84(3)" "\n"
128" lwz 22, 88(3)" "\n"
129" lwz 23, 92(3)" "\n"
130" lwz 24, 96(3)" "\n"
131" lwz 25, 100(3)" "\n"
132" lwz 26, 104(3)" "\n"
133" lwz 27, 108(3)" "\n"
134" lwz 28, 112(3)" "\n"
135" lwz 29, 116(3)" "\n"
136" lwz 30, 120(3)" "\n"
137" lwz 31, 124(3)" "\n"
138" lwz 3, 12(3)" "\n"
139" blr" "\n"
sewardj2a88a012011-04-11 21:26:27 +0000140"" "\n"
sewardj97d3ebb2011-04-11 18:36:34 +0000141
142".previous" "\n"
143);
144
145#endif /* VGP_ppc32_linux */
sewardj6c591e12011-04-11 16:17:51 +0000146
147
sewardj2a88a012011-04-11 21:26:27 +0000148/* ------------ ppc64-linux ------------ */
149
150#if defined(VGP_ppc64_linux)
151
152__asm__(
153".section \".toc\",\"aw\"" "\n"
154
155".section \".text\"" "\n"
156".align 2" "\n"
157".p2align 4,,15" "\n"
158".globl VG_MINIMAL_SETJMP" "\n"
159
160".section \".opd\",\"aw\"" "\n"
161".align 3" "\n"
162"VG_MINIMAL_SETJMP:" "\n"
163".quad .L.VG_MINIMAL_SETJMP,.TOC.@tocbase,0" "\n"
164".previous" "\n"
165
166".type VG_MINIMAL_SETJMP, @function" "\n"
167".L.VG_MINIMAL_SETJMP:" "\n"
168" std 0, 0(3)" "\n"
169" std 1, 8(3)" "\n"
170" std 2, 16(3)" "\n"
171" std 3, 24(3)" "\n"
172" std 4, 32(3)" "\n"
173" std 5, 40(3)" "\n"
174" std 6, 48(3)" "\n"
175" std 7, 56(3)" "\n"
176" std 8, 64(3)" "\n"
177" std 9, 72(3)" "\n"
178" std 10, 80(3)" "\n"
179" std 11, 88(3)" "\n"
180" std 12, 96(3)" "\n"
181" std 13, 104(3)" "\n"
182" std 14, 112(3)" "\n"
183" std 15, 120(3)" "\n"
184" std 16, 128(3)" "\n"
185" std 17, 136(3)" "\n"
186" std 18, 144(3)" "\n"
187" std 19, 152(3)" "\n"
188" std 20, 160(3)" "\n"
189" std 21, 168(3)" "\n"
190" std 22, 176(3)" "\n"
191" std 23, 184(3)" "\n"
192" std 24, 192(3)" "\n"
193" std 25, 200(3)" "\n"
194" std 26, 208(3)" "\n"
195" std 27, 216(3)" "\n"
196" std 28, 224(3)" "\n"
197" std 29, 232(3)" "\n"
198" std 30, 240(3)" "\n"
199" std 31, 248(3)" "\n"
200 // must use a caller-save register here as scratch, hence r4
201" mflr 4" "\n"
202" std 4, 256(3)" "\n"
203" mfcr 4" "\n"
204" std 4, 264(3)" "\n"
205" li 3, 0" "\n"
206" blr" "\n"
207"" "\n"
208
209
210".globl VG_MINIMAL_LONGJMP" "\n"
211
212".section \".opd\",\"aw\"" "\n"
213".align 3" "\n"
214"VG_MINIMAL_LONGJMP:" "\n"
215".quad .L.VG_MINIMAL_LONGJMP,.TOC.@tocbase,0" "\n"
216".previous" "\n"
217
218".type VG_MINIMAL_LONGJMP, @function" "\n"
219".L.VG_MINIMAL_LONGJMP:" "\n"
220 // do r4 = 1
221 // and park it in the restore slot for r3 (the ret reg)
222" li 4, 1" "\n"
223" std 4, 24(3)" "\n"
224 // restore everything except r3
225 // then r3 last of all
226 // then blr
227" ld 0, 256(3)" "\n"
228" mtlr 0" "\n"
229" ld 0, 264(3)" "\n"
230" mtcr 0" "\n"
231" ld 0, 0(3)" "\n"
232" ld 1, 8(3)" "\n"
233" ld 2, 16(3)" "\n"
234 // r3 is done at the end
235" ld 4, 32(3)" "\n"
236" ld 5, 40(3)" "\n"
237" ld 6, 48(3)" "\n"
238" ld 7, 56(3)" "\n"
239" ld 8, 64(3)" "\n"
240" ld 9, 72(3)" "\n"
241" ld 10, 80(3)" "\n"
242" ld 11, 88(3)" "\n"
243" ld 12, 96(3)" "\n"
244" ld 13, 104(3)" "\n"
245" ld 14, 112(3)" "\n"
246" ld 15, 120(3)" "\n"
247" ld 16, 128(3)" "\n"
248" ld 17, 136(3)" "\n"
249" ld 18, 144(3)" "\n"
250" ld 19, 152(3)" "\n"
251" ld 20, 160(3)" "\n"
252" ld 21, 168(3)" "\n"
253" ld 22, 176(3)" "\n"
254" ld 23, 184(3)" "\n"
255" ld 24, 192(3)" "\n"
256" ld 25, 200(3)" "\n"
257" ld 26, 208(3)" "\n"
258" ld 27, 216(3)" "\n"
259" ld 28, 224(3)" "\n"
260" ld 29, 232(3)" "\n"
261" ld 30, 240(3)" "\n"
262" ld 31, 248(3)" "\n"
263" ld 3, 24(3)" "\n"
264" blr" "\n"
265"" "\n"
266
267".previous" "\n"
268".previous" "\n"
269);
270
271
272#endif /* VGP_ppc64_linux */
273
sewardj6c591e12011-04-11 16:17:51 +0000274/*--------------------------------------------------------------------*/
275/*--- end ---*/
276/*--------------------------------------------------------------------*/