2 /*--------------------------------------------------------------------*/
3 /*--- A minimal setjmp/longjmp implementation. m_libcsetjmp.c ---*/
4 /*--------------------------------------------------------------------*/
7 This file is part of Valgrind, a dynamic binary instrumentation
10 Copyright (C) 2010-2010 Mozilla Inc
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.
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.
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
27 The GNU General Public License is contained in the file COPYING.
30 /* Contributed by Julian Seward <jseward@acm.org> */
33 #include "pub_core_basics.h"
34 #include "pub_core_libcsetjmp.h" /* self */
37 /* See include/pub_tool_libcsetjmp.h for background and rationale. */
39 /* The only alternative implementations are for ppc{32,64}-linux. See
42 /* ------------ ppc32-linux ------------ */
44 #if defined(VGP_ppc32_linux)
49 ".global VG_MINIMAL_SETJMP" "\n" // r3 = jmp_buf
50 "VG_MINIMAL_SETJMP:" "\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
93 ".global VG_MINIMAL_LONGJMP" "\n"
94 "VG_MINIMAL_LONGJMP:" "\n" // r3 = jmp_buf
96 // and park it in the restore slot for r3 (the ret reg)
99 // restore everything except r3
100 // then r3 last of all
102 " lwz 0, 128(3)" "\n"
104 " lwz 0, 132(3)" "\n"
109 // r3 is done at the end
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"
145 #endif /* VGP_ppc32_linux */
148 /* ------------ ppc64-linux ------------ */
150 #if defined(VGP_ppc64_linux)
153 ".section \".toc\",\"aw\"" "\n"
155 ".section \".text\"" "\n"
157 ".p2align 4,,15" "\n"
158 ".globl VG_MINIMAL_SETJMP" "\n"
160 ".section \".opd\",\"aw\"" "\n"
162 "VG_MINIMAL_SETJMP:" "\n"
163 ".quad .L.VG_MINIMAL_SETJMP,.TOC.@tocbase,0" "\n"
166 ".type VG_MINIMAL_SETJMP, @function" "\n"
167 ".L.VG_MINIMAL_SETJMP:" "\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
202 " std 4, 256(3)" "\n"
204 " std 4, 264(3)" "\n"
210 ".globl VG_MINIMAL_LONGJMP" "\n"
212 ".section \".opd\",\"aw\"" "\n"
214 "VG_MINIMAL_LONGJMP:" "\n"
215 ".quad .L.VG_MINIMAL_LONGJMP,.TOC.@tocbase,0" "\n"
218 ".type VG_MINIMAL_LONGJMP, @function" "\n"
219 ".L.VG_MINIMAL_LONGJMP:" "\n"
221 // and park it in the restore slot for r3 (the ret reg)
224 // restore everything except r3
225 // then r3 last of all
234 // r3 is done at the end
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"
272 #endif /* VGP_ppc64_linux */
274 /*--------------------------------------------------------------------*/
276 /*--------------------------------------------------------------------*/