blob: ae0b620393760b30e672b800e4d128261d9f5d2c [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
42#if defined(VGP_ppc32_linux)
43
44__asm__(
45".text" "\n"
46"" "\n"
47".global VG_MINIMAL_SETJMP" "\n" // r3 = jmp_buf
48"VG_MINIMAL_SETJMP:" "\n"
49" stw 0, 0(3)" "\n"
50" stw 1, 4(3)" "\n"
51" stw 2, 8(3)" "\n"
52" stw 3, 12(3)" "\n"
53" stw 4, 16(3)" "\n"
54" stw 5, 20(3)" "\n"
55" stw 6, 24(3)" "\n"
56" stw 7, 28(3)" "\n"
57" stw 8, 32(3)" "\n"
58" stw 9, 36(3)" "\n"
59" stw 10, 40(3)" "\n"
60" stw 11, 44(3)" "\n"
61" stw 12, 48(3)" "\n"
62" stw 13, 52(3)" "\n"
63" stw 14, 56(3)" "\n"
64" stw 15, 60(3)" "\n"
65" stw 16, 64(3)" "\n"
66" stw 17, 68(3)" "\n"
67" stw 18, 72(3)" "\n"
68" stw 19, 76(3)" "\n"
69" stw 20, 80(3)" "\n"
70" stw 21, 84(3)" "\n"
71" stw 22, 88(3)" "\n"
72" stw 23, 92(3)" "\n"
73" stw 24, 96(3)" "\n"
74" stw 25, 100(3)" "\n"
75" stw 26, 104(3)" "\n"
76" stw 27, 108(3)" "\n"
77" stw 28, 112(3)" "\n"
78" stw 29, 116(3)" "\n"
79" stw 30, 120(3)" "\n"
80" stw 31, 124(3)" "\n"
81 // must use a caller-save register here as scratch, hence r4
82" mflr 4" "\n"
83" stw 4, 128(3)" "\n"
84" mfcr 4" "\n"
85" stw 4, 132(3)" "\n"
86" li 3, 0" "\n"
87" blr" "\n"
88"" "\n"
89
90
91".global VG_MINIMAL_LONGJMP" "\n"
92"VG_MINIMAL_LONGJMP:" "\n" // r3 = jmp_buf
93 // do r4 = 1
94 // and park it in the restore slot for r3 (the ret reg)
95" li 4, 1" "\n"
96" stw 4, 12(3)" "\n"
97 // restore everything except r3
98 // then r3 last of all
99 // then blr
100" lwz 0, 128(3)" "\n"
101" mtlr 0" "\n"
102" lwz 0, 132(3)" "\n"
103" mtcr 0" "\n"
104" lwz 0, 0(3)" "\n"
105" lwz 1, 4(3)" "\n"
106" lwz 2, 8(3)" "\n"
107 // r3 is done at the end
108" lwz 4, 16(3)" "\n"
109" lwz 5, 20(3)" "\n"
110" lwz 6, 24(3)" "\n"
111" lwz 7, 28(3)" "\n"
112" lwz 8, 32(3)" "\n"
113" lwz 9, 36(3)" "\n"
114" lwz 10, 40(3)" "\n"
115" lwz 11, 44(3)" "\n"
116" lwz 12, 48(3)" "\n"
117" lwz 13, 52(3)" "\n"
118" lwz 14, 56(3)" "\n"
119" lwz 15, 60(3)" "\n"
120" lwz 16, 64(3)" "\n"
121" lwz 17, 68(3)" "\n"
122" lwz 18, 72(3)" "\n"
123" lwz 19, 76(3)" "\n"
124" lwz 20, 80(3)" "\n"
125" lwz 21, 84(3)" "\n"
126" lwz 22, 88(3)" "\n"
127" lwz 23, 92(3)" "\n"
128" lwz 24, 96(3)" "\n"
129" lwz 25, 100(3)" "\n"
130" lwz 26, 104(3)" "\n"
131" lwz 27, 108(3)" "\n"
132" lwz 28, 112(3)" "\n"
133" lwz 29, 116(3)" "\n"
134" lwz 30, 120(3)" "\n"
135" lwz 31, 124(3)" "\n"
136" lwz 3, 12(3)" "\n"
137" blr" "\n"
138"" "\n"
139
140
141".previous" "\n"
142);
143
144#endif /* VGP_ppc32_linux */
sewardj6c591e12011-04-11 16:17:51 +0000145
146
147/*--------------------------------------------------------------------*/
148/*--- end ---*/
149/*--------------------------------------------------------------------*/