]>
Commit | Line | Data |
---|---|---|
73ffefd0 TT |
1 | /* |
2 | * Copyright 1988, 1989 Hans-J. Boehm, Alan J. Demers | |
3 | * Copyright (c) 1991-1994 by Xerox Corporation. All rights reserved. | |
4 | * | |
5 | * THIS MATERIAL IS PROVIDED AS IS, WITH ABSOLUTELY NO WARRANTY EXPRESSED | |
6 | * OR IMPLIED. ANY USE IS AT YOUR OWN RISK. | |
7 | * | |
8 | * Permission is hereby granted to use or copy this program | |
9 | * for any purpose, provided the above notices are retained on all copies. | |
10 | * Permission to modify the code and to distribute modified code is granted, | |
11 | * provided the above notices are retained, and a notice that the code was | |
12 | * modified is included with the above copyright notice. | |
13 | */ | |
14 | /* Boehm, November 17, 1995 12:13 pm PST */ | |
9110a741 | 15 | # include "private/gc_priv.h" |
73ffefd0 TT |
16 | # include <stdio.h> |
17 | # include <setjmp.h> | |
18 | # if defined(OS2) || defined(CX_UX) | |
19 | # define _setjmp(b) setjmp(b) | |
20 | # define _longjmp(b,v) longjmp(b,v) | |
21 | # endif | |
22 | # ifdef AMIGA | |
20bbd3cd | 23 | # ifndef __GNUC__ |
9110a741 | 24 | # include <dos.h> |
20bbd3cd TT |
25 | # else |
26 | # include <machine/reg.h> | |
27 | # endif | |
73ffefd0 TT |
28 | # endif |
29 | ||
30 | #if defined(__MWERKS__) && !defined(POWERPC) | |
31 | ||
32 | asm static void PushMacRegisters() | |
33 | { | |
34 | sub.w #4,sp // reserve space for one parameter. | |
35 | move.l a2,(sp) | |
36 | jsr GC_push_one | |
37 | move.l a3,(sp) | |
38 | jsr GC_push_one | |
39 | move.l a4,(sp) | |
40 | jsr GC_push_one | |
41 | # if !__option(a6frames) | |
42 | // <pcb> perhaps a6 should be pushed if stack frames are not being used. | |
43 | move.l a6,(sp) | |
44 | jsr GC_push_one | |
45 | # endif | |
46 | // skip a5 (globals), a6 (frame pointer), and a7 (stack pointer) | |
47 | move.l d2,(sp) | |
48 | jsr GC_push_one | |
49 | move.l d3,(sp) | |
50 | jsr GC_push_one | |
51 | move.l d4,(sp) | |
52 | jsr GC_push_one | |
53 | move.l d5,(sp) | |
54 | jsr GC_push_one | |
55 | move.l d6,(sp) | |
56 | jsr GC_push_one | |
57 | move.l d7,(sp) | |
58 | jsr GC_push_one | |
59 | add.w #4,sp // fix stack. | |
60 | rts | |
61 | } | |
62 | ||
63 | #endif /* __MWERKS__ */ | |
64 | ||
20bbd3cd TT |
65 | # if defined(SPARC) || defined(IA64) |
66 | /* Value returned from register flushing routine; either sp (SPARC) */ | |
67 | /* or ar.bsp (IA64) */ | |
68 | word GC_save_regs_ret_val; | |
69 | # endif | |
70 | ||
73ffefd0 TT |
71 | /* Routine to mark from registers that are preserved by the C compiler. */ |
72 | /* This must be ported to every new architecture. There is a generic */ | |
73 | /* version at the end, that is likely, but not guaranteed to work */ | |
74 | /* on your architecture. Run the test_setjmp program to see whether */ | |
75 | /* there is any chance it will work. */ | |
76 | ||
30c3de1f JS |
77 | #if !defined(USE_GENERIC_PUSH_REGS) && !defined(USE_ASM_PUSH_REGS) |
78 | #undef HAVE_PUSH_REGS | |
73ffefd0 TT |
79 | void GC_push_regs() |
80 | { | |
81 | # ifdef RT | |
82 | register long TMP_SP; /* must be bound to r11 */ | |
83 | # endif | |
93002327 | 84 | |
73ffefd0 TT |
85 | # ifdef VAX |
86 | /* VAX - generic code below does not work under 4.2 */ | |
87 | /* r1 through r5 are caller save, and therefore */ | |
88 | /* on the stack or dead. */ | |
89 | asm("pushl r11"); asm("calls $1,_GC_push_one"); | |
90 | asm("pushl r10"); asm("calls $1,_GC_push_one"); | |
91 | asm("pushl r9"); asm("calls $1,_GC_push_one"); | |
92 | asm("pushl r8"); asm("calls $1,_GC_push_one"); | |
93 | asm("pushl r7"); asm("calls $1,_GC_push_one"); | |
94 | asm("pushl r6"); asm("calls $1,_GC_push_one"); | |
30c3de1f | 95 | # define HAVE_PUSH_REGS |
73ffefd0 TT |
96 | # endif |
97 | # if defined(M68K) && (defined(SUNOS4) || defined(NEXT)) | |
98 | /* M68K SUNOS - could be replaced by generic code */ | |
99 | /* a0, a1 and d1 are caller save */ | |
100 | /* and therefore are on stack or dead. */ | |
101 | ||
102 | asm("subqw #0x4,sp"); /* allocate word on top of stack */ | |
103 | ||
104 | asm("movl a2,sp@"); asm("jbsr _GC_push_one"); | |
105 | asm("movl a3,sp@"); asm("jbsr _GC_push_one"); | |
106 | asm("movl a4,sp@"); asm("jbsr _GC_push_one"); | |
107 | asm("movl a5,sp@"); asm("jbsr _GC_push_one"); | |
108 | /* Skip frame pointer and stack pointer */ | |
109 | asm("movl d1,sp@"); asm("jbsr _GC_push_one"); | |
110 | asm("movl d2,sp@"); asm("jbsr _GC_push_one"); | |
111 | asm("movl d3,sp@"); asm("jbsr _GC_push_one"); | |
112 | asm("movl d4,sp@"); asm("jbsr _GC_push_one"); | |
113 | asm("movl d5,sp@"); asm("jbsr _GC_push_one"); | |
114 | asm("movl d6,sp@"); asm("jbsr _GC_push_one"); | |
115 | asm("movl d7,sp@"); asm("jbsr _GC_push_one"); | |
116 | ||
117 | asm("addqw #0x4,sp"); /* put stack back where it was */ | |
30c3de1f | 118 | # define HAVE_PUSH_REGS |
73ffefd0 TT |
119 | # endif |
120 | ||
121 | # if defined(M68K) && defined(HP) | |
122 | /* M68K HP - could be replaced by generic code */ | |
123 | /* a0, a1 and d1 are caller save. */ | |
124 | ||
125 | asm("subq.w &0x4,%sp"); /* allocate word on top of stack */ | |
126 | ||
127 | asm("mov.l %a2,(%sp)"); asm("jsr _GC_push_one"); | |
128 | asm("mov.l %a3,(%sp)"); asm("jsr _GC_push_one"); | |
129 | asm("mov.l %a4,(%sp)"); asm("jsr _GC_push_one"); | |
130 | asm("mov.l %a5,(%sp)"); asm("jsr _GC_push_one"); | |
131 | /* Skip frame pointer and stack pointer */ | |
132 | asm("mov.l %d1,(%sp)"); asm("jsr _GC_push_one"); | |
133 | asm("mov.l %d2,(%sp)"); asm("jsr _GC_push_one"); | |
134 | asm("mov.l %d3,(%sp)"); asm("jsr _GC_push_one"); | |
135 | asm("mov.l %d4,(%sp)"); asm("jsr _GC_push_one"); | |
136 | asm("mov.l %d5,(%sp)"); asm("jsr _GC_push_one"); | |
137 | asm("mov.l %d6,(%sp)"); asm("jsr _GC_push_one"); | |
138 | asm("mov.l %d7,(%sp)"); asm("jsr _GC_push_one"); | |
139 | ||
140 | asm("addq.w &0x4,%sp"); /* put stack back where it was */ | |
30c3de1f | 141 | # define HAVE_PUSH_REGS |
73ffefd0 TT |
142 | # endif /* M68K HP */ |
143 | ||
20bbd3cd TT |
144 | # if defined(M68K) && defined(AMIGA) |
145 | /* AMIGA - could be replaced by generic code */ | |
146 | /* a0, a1, d0 and d1 are caller save */ | |
147 | ||
148 | # ifdef __GNUC__ | |
149 | asm("subq.w &0x4,%sp"); /* allocate word on top of stack */ | |
150 | ||
151 | asm("mov.l %a2,(%sp)"); asm("jsr _GC_push_one"); | |
152 | asm("mov.l %a3,(%sp)"); asm("jsr _GC_push_one"); | |
153 | asm("mov.l %a4,(%sp)"); asm("jsr _GC_push_one"); | |
154 | asm("mov.l %a5,(%sp)"); asm("jsr _GC_push_one"); | |
155 | asm("mov.l %a6,(%sp)"); asm("jsr _GC_push_one"); | |
156 | /* Skip frame pointer and stack pointer */ | |
157 | asm("mov.l %d2,(%sp)"); asm("jsr _GC_push_one"); | |
158 | asm("mov.l %d3,(%sp)"); asm("jsr _GC_push_one"); | |
159 | asm("mov.l %d4,(%sp)"); asm("jsr _GC_push_one"); | |
160 | asm("mov.l %d5,(%sp)"); asm("jsr _GC_push_one"); | |
161 | asm("mov.l %d6,(%sp)"); asm("jsr _GC_push_one"); | |
162 | asm("mov.l %d7,(%sp)"); asm("jsr _GC_push_one"); | |
163 | ||
164 | asm("addq.w &0x4,%sp"); /* put stack back where it was */ | |
30c3de1f | 165 | # define HAVE_PUSH_REGS |
20bbd3cd | 166 | # else /* !__GNUC__ */ |
73ffefd0 TT |
167 | GC_push_one(getreg(REG_A2)); |
168 | GC_push_one(getreg(REG_A3)); | |
9110a741 BM |
169 | # ifndef __SASC |
170 | /* Can probably be changed to #if 0 -Kjetil M. (a4=globals)*/ | |
171 | GC_push_one(getreg(REG_A4)); | |
172 | # endif | |
73ffefd0 TT |
173 | GC_push_one(getreg(REG_A5)); |
174 | GC_push_one(getreg(REG_A6)); | |
175 | /* Skip stack pointer */ | |
176 | GC_push_one(getreg(REG_D2)); | |
177 | GC_push_one(getreg(REG_D3)); | |
178 | GC_push_one(getreg(REG_D4)); | |
179 | GC_push_one(getreg(REG_D5)); | |
180 | GC_push_one(getreg(REG_D6)); | |
181 | GC_push_one(getreg(REG_D7)); | |
30c3de1f | 182 | # define HAVE_PUSH_REGS |
20bbd3cd TT |
183 | # endif /* !__GNUC__ */ |
184 | # endif /* AMIGA */ | |
73ffefd0 TT |
185 | |
186 | # if defined(M68K) && defined(MACOS) | |
187 | # if defined(THINK_C) | |
188 | # define PushMacReg(reg) \ | |
189 | move.l reg,(sp) \ | |
190 | jsr GC_push_one | |
191 | asm { | |
192 | sub.w #4,sp ; reserve space for one parameter. | |
193 | PushMacReg(a2); | |
194 | PushMacReg(a3); | |
195 | PushMacReg(a4); | |
196 | ; skip a5 (globals), a6 (frame pointer), and a7 (stack pointer) | |
197 | PushMacReg(d2); | |
198 | PushMacReg(d3); | |
199 | PushMacReg(d4); | |
200 | PushMacReg(d5); | |
201 | PushMacReg(d6); | |
202 | PushMacReg(d7); | |
203 | add.w #4,sp ; fix stack. | |
204 | } | |
30c3de1f | 205 | # define HAVE_PUSH_REGS |
73ffefd0 TT |
206 | # undef PushMacReg |
207 | # endif /* THINK_C */ | |
208 | # if defined(__MWERKS__) | |
209 | PushMacRegisters(); | |
30c3de1f | 210 | # define HAVE_PUSH_REGS |
73ffefd0 TT |
211 | # endif /* __MWERKS__ */ |
212 | # endif /* MACOS */ | |
213 | ||
93002327 BM |
214 | # if defined(I386) &&!defined(OS2) &&!defined(SVR4) \ |
215 | && (defined(__MINGW32__) || !defined(MSWIN32)) \ | |
20bbd3cd | 216 | && !defined(SCO) && !defined(SCO_ELF) \ |
9110a741 | 217 | && !(defined(LINUX) && defined(__ELF__)) \ |
93002327 | 218 | && !(defined(FREEBSD) && defined(__ELF__)) \ |
9110a741 BM |
219 | && !(defined(NETBSD) && defined(__ELF__)) \ |
220 | && !(defined(OPENBSD) && defined(__ELF__)) \ | |
221 | && !(defined(BEOS) && defined(__ELF__)) \ | |
5a2586cf | 222 | && !defined(DOS4GW) && !defined(HURD) |
73ffefd0 TT |
223 | /* I386 code, generic code does not appear to work */ |
224 | /* It does appear to work under OS2, and asms dont */ | |
225 | /* This is used for some 38g UNIX variants and for CYGWIN32 */ | |
226 | asm("pushl %eax"); asm("call _GC_push_one"); asm("addl $4,%esp"); | |
227 | asm("pushl %ecx"); asm("call _GC_push_one"); asm("addl $4,%esp"); | |
228 | asm("pushl %edx"); asm("call _GC_push_one"); asm("addl $4,%esp"); | |
229 | asm("pushl %ebp"); asm("call _GC_push_one"); asm("addl $4,%esp"); | |
230 | asm("pushl %esi"); asm("call _GC_push_one"); asm("addl $4,%esp"); | |
231 | asm("pushl %edi"); asm("call _GC_push_one"); asm("addl $4,%esp"); | |
232 | asm("pushl %ebx"); asm("call _GC_push_one"); asm("addl $4,%esp"); | |
30c3de1f | 233 | # define HAVE_PUSH_REGS |
73ffefd0 TT |
234 | # endif |
235 | ||
20bbd3cd | 236 | # if ( defined(I386) && defined(LINUX) && defined(__ELF__) ) \ |
9110a741 BM |
237 | || ( defined(I386) && defined(FREEBSD) && defined(__ELF__) ) \ |
238 | || ( defined(I386) && defined(NETBSD) && defined(__ELF__) ) \ | |
5a2586cf | 239 | || ( defined(I386) && defined(OPENBSD) && defined(__ELF__) ) \ |
30c3de1f JS |
240 | || ( defined(I386) && defined(HURD) && defined(__ELF__) ) \ |
241 | || ( defined(I386) && defined(DGUX) ) | |
20bbd3cd TT |
242 | |
243 | /* This is modified for Linux with ELF (Note: _ELF_ only) */ | |
244 | /* This section handles FreeBSD with ELF. */ | |
93002327 BM |
245 | /* Eax is caller-save and dead here. Other caller-save */ |
246 | /* registers could also be skipped. We assume there are no */ | |
247 | /* pointers in MMX registers, etc. */ | |
248 | /* We combine instructions in a single asm to prevent gcc from */ | |
249 | /* inserting code in the middle. */ | |
250 | asm("pushl %ecx; call GC_push_one; addl $4,%esp"); | |
251 | asm("pushl %edx; call GC_push_one; addl $4,%esp"); | |
252 | asm("pushl %ebp; call GC_push_one; addl $4,%esp"); | |
253 | asm("pushl %esi; call GC_push_one; addl $4,%esp"); | |
254 | asm("pushl %edi; call GC_push_one; addl $4,%esp"); | |
255 | asm("pushl %ebx; call GC_push_one; addl $4,%esp"); | |
30c3de1f | 256 | # define HAVE_PUSH_REGS |
73ffefd0 TT |
257 | # endif |
258 | ||
9110a741 BM |
259 | # if ( defined(I386) && defined(BEOS) && defined(__ELF__) ) |
260 | /* As far as I can understand from */ | |
261 | /* http://www.beunited.org/articles/jbq/nasm.shtml, */ | |
262 | /* only ebp, esi, edi and ebx are not scratch. How MMX */ | |
263 | /* etc. registers should be treated, I have no idea. */ | |
264 | asm("pushl %ebp; call GC_push_one; addl $4,%esp"); | |
265 | asm("pushl %esi; call GC_push_one; addl $4,%esp"); | |
266 | asm("pushl %edi; call GC_push_one; addl $4,%esp"); | |
267 | asm("pushl %ebx; call GC_push_one; addl $4,%esp"); | |
30c3de1f | 268 | # define HAVE_PUSH_REGS |
9110a741 BM |
269 | # endif |
270 | ||
93002327 BM |
271 | # if defined(I386) && defined(MSWIN32) && !defined(__MINGW32__) \ |
272 | && !defined(USE_GENERIC) | |
73ffefd0 TT |
273 | /* I386 code, Microsoft variant */ |
274 | __asm push eax | |
275 | __asm call GC_push_one | |
276 | __asm add esp,4 | |
277 | __asm push ebx | |
278 | __asm call GC_push_one | |
279 | __asm add esp,4 | |
280 | __asm push ecx | |
281 | __asm call GC_push_one | |
282 | __asm add esp,4 | |
283 | __asm push edx | |
284 | __asm call GC_push_one | |
285 | __asm add esp,4 | |
286 | __asm push ebp | |
287 | __asm call GC_push_one | |
288 | __asm add esp,4 | |
289 | __asm push esi | |
290 | __asm call GC_push_one | |
291 | __asm add esp,4 | |
292 | __asm push edi | |
293 | __asm call GC_push_one | |
294 | __asm add esp,4 | |
30c3de1f | 295 | # define HAVE_PUSH_REGS |
73ffefd0 TT |
296 | # endif |
297 | ||
298 | # if defined(I386) && (defined(SVR4) || defined(SCO) || defined(SCO_ELF)) | |
299 | /* I386 code, SVR4 variant, generic code does not appear to work */ | |
300 | asm("pushl %eax"); asm("call GC_push_one"); asm("addl $4,%esp"); | |
301 | asm("pushl %ebx"); asm("call GC_push_one"); asm("addl $4,%esp"); | |
302 | asm("pushl %ecx"); asm("call GC_push_one"); asm("addl $4,%esp"); | |
303 | asm("pushl %edx"); asm("call GC_push_one"); asm("addl $4,%esp"); | |
304 | asm("pushl %ebp"); asm("call GC_push_one"); asm("addl $4,%esp"); | |
305 | asm("pushl %esi"); asm("call GC_push_one"); asm("addl $4,%esp"); | |
306 | asm("pushl %edi"); asm("call GC_push_one"); asm("addl $4,%esp"); | |
30c3de1f | 307 | # define HAVE_PUSH_REGS |
73ffefd0 TT |
308 | # endif |
309 | ||
310 | # ifdef NS32K | |
311 | asm ("movd r3, tos"); asm ("bsr ?_GC_push_one"); asm ("adjspb $-4"); | |
312 | asm ("movd r4, tos"); asm ("bsr ?_GC_push_one"); asm ("adjspb $-4"); | |
313 | asm ("movd r5, tos"); asm ("bsr ?_GC_push_one"); asm ("adjspb $-4"); | |
314 | asm ("movd r6, tos"); asm ("bsr ?_GC_push_one"); asm ("adjspb $-4"); | |
315 | asm ("movd r7, tos"); asm ("bsr ?_GC_push_one"); asm ("adjspb $-4"); | |
30c3de1f | 316 | # define HAVE_PUSH_REGS |
73ffefd0 TT |
317 | # endif |
318 | ||
93002327 | 319 | # if defined(SPARC) |
30c3de1f JS |
320 | GC_save_regs_ret_val = GC_save_regs_in_stack(); |
321 | # define HAVE_PUSH_REGS | |
73ffefd0 TT |
322 | # endif |
323 | ||
324 | # ifdef RT | |
325 | GC_push_one(TMP_SP); /* GC_push_one from r11 */ | |
326 | ||
327 | asm("cas r11, r6, r0"); GC_push_one(TMP_SP); /* r6 */ | |
328 | asm("cas r11, r7, r0"); GC_push_one(TMP_SP); /* through */ | |
329 | asm("cas r11, r8, r0"); GC_push_one(TMP_SP); /* r10 */ | |
330 | asm("cas r11, r9, r0"); GC_push_one(TMP_SP); | |
331 | asm("cas r11, r10, r0"); GC_push_one(TMP_SP); | |
332 | ||
333 | asm("cas r11, r12, r0"); GC_push_one(TMP_SP); /* r12 */ | |
334 | asm("cas r11, r13, r0"); GC_push_one(TMP_SP); /* through */ | |
335 | asm("cas r11, r14, r0"); GC_push_one(TMP_SP); /* r15 */ | |
336 | asm("cas r11, r15, r0"); GC_push_one(TMP_SP); | |
30c3de1f | 337 | # define HAVE_PUSH_REGS |
73ffefd0 TT |
338 | # endif |
339 | ||
340 | # if defined(M68K) && defined(SYSV) | |
341 | /* Once again similar to SUN and HP, though setjmp appears to work. | |
342 | --Parag | |
343 | */ | |
344 | # ifdef __GNUC__ | |
345 | asm("subqw #0x4,%sp"); /* allocate word on top of stack */ | |
346 | ||
347 | asm("movl %a2,%sp@"); asm("jbsr GC_push_one"); | |
348 | asm("movl %a3,%sp@"); asm("jbsr GC_push_one"); | |
349 | asm("movl %a4,%sp@"); asm("jbsr GC_push_one"); | |
350 | asm("movl %a5,%sp@"); asm("jbsr GC_push_one"); | |
351 | /* Skip frame pointer and stack pointer */ | |
352 | asm("movl %d1,%sp@"); asm("jbsr GC_push_one"); | |
353 | asm("movl %d2,%sp@"); asm("jbsr GC_push_one"); | |
354 | asm("movl %d3,%sp@"); asm("jbsr GC_push_one"); | |
355 | asm("movl %d4,%sp@"); asm("jbsr GC_push_one"); | |
356 | asm("movl %d5,%sp@"); asm("jbsr GC_push_one"); | |
357 | asm("movl %d6,%sp@"); asm("jbsr GC_push_one"); | |
358 | asm("movl %d7,%sp@"); asm("jbsr GC_push_one"); | |
359 | ||
360 | asm("addqw #0x4,%sp"); /* put stack back where it was */ | |
30c3de1f | 361 | # define HAVE_PUSH_REGS |
73ffefd0 TT |
362 | # else /* !__GNUC__*/ |
363 | asm("subq.w &0x4,%sp"); /* allocate word on top of stack */ | |
364 | ||
365 | asm("mov.l %a2,(%sp)"); asm("jsr GC_push_one"); | |
366 | asm("mov.l %a3,(%sp)"); asm("jsr GC_push_one"); | |
367 | asm("mov.l %a4,(%sp)"); asm("jsr GC_push_one"); | |
368 | asm("mov.l %a5,(%sp)"); asm("jsr GC_push_one"); | |
369 | /* Skip frame pointer and stack pointer */ | |
370 | asm("mov.l %d1,(%sp)"); asm("jsr GC_push_one"); | |
371 | asm("mov.l %d2,(%sp)"); asm("jsr GC_push_one"); | |
372 | asm("mov.l %d3,(%sp)"); asm("jsr GC_push_one"); | |
373 | asm("mov.l %d4,(%sp)"); asm("jsr GC_push_one"); | |
374 | asm("mov.l %d5,(%sp)"); asm("jsr GC_push_one"); | |
375 | asm("mov.l %d6,(%sp)"); asm("jsr GC_push_one"); | |
376 | asm("mov.l %d7,(%sp)"); asm("jsr GC_push_one"); | |
377 | ||
378 | asm("addq.w &0x4,%sp"); /* put stack back where it was */ | |
30c3de1f | 379 | # define HAVE_PUSH_REGS |
73ffefd0 TT |
380 | # endif /* !__GNUC__ */ |
381 | # endif /* M68K/SYSV */ | |
382 | ||
20bbd3cd TT |
383 | # if defined(PJ) |
384 | { | |
385 | register int * sp asm ("optop"); | |
386 | extern int *__libc_stack_end; | |
73ffefd0 | 387 | |
20bbd3cd | 388 | GC_push_all_stack (sp, __libc_stack_end); |
30c3de1f JS |
389 | # define HAVE_PUSH_REGS |
390 | /* Isn't this redundant with the code to push the stack? */ | |
20bbd3cd TT |
391 | } |
392 | # endif | |
393 | ||
394 | /* other machines... */ | |
30c3de1f JS |
395 | # if !defined(HAVE_PUSH_REGS) |
396 | --> We just generated an empty GC_push_regs, which | |
397 | --> is almost certainly broken. Try defining | |
398 | --> USE_GENERIC_PUSH_REGS instead. | |
20bbd3cd TT |
399 | # endif |
400 | } | |
30c3de1f | 401 | #endif /* !USE_GENERIC_PUSH_REGS && !USE_ASM_PUSH_REGS */ |
20bbd3cd TT |
402 | |
403 | #if defined(USE_GENERIC_PUSH_REGS) | |
404 | void GC_generic_push_regs(cold_gc_frame) | |
405 | ptr_t cold_gc_frame; | |
406 | { | |
73ffefd0 | 407 | { |
5a2586cf TT |
408 | # ifdef HAVE_BUILTIN_UNWIND_INIT |
409 | /* This was suggested by Richard Henderson as the way to */ | |
410 | /* force callee-save registers and register windows onto */ | |
411 | /* the stack. */ | |
412 | __builtin_unwind_init(); | |
413 | # else /* !HAVE_BUILTIN_UNWIND_INIT */ | |
414 | /* Generic code */ | |
415 | /* The idea is due to Parag Patel at HP. */ | |
416 | /* We're not sure whether he would like */ | |
417 | /* to be he acknowledged for it or not. */ | |
418 | jmp_buf regs; | |
419 | register word * i = (word *) regs; | |
420 | register ptr_t lim = (ptr_t)(regs) + (sizeof regs); | |
421 | ||
422 | /* Setjmp doesn't always clear all of the buffer. */ | |
423 | /* That tends to preserve garbage. Clear it. */ | |
73ffefd0 TT |
424 | for (; (char *)i < lim; i++) { |
425 | *i = 0; | |
426 | } | |
5a2586cf | 427 | # if defined(POWERPC) || defined(MSWIN32) || defined(MSWINCE) \ |
79f777fd | 428 | || defined(UTS4) || defined(LINUX) || defined(EWS4800) |
5a2586cf TT |
429 | (void) setjmp(regs); |
430 | # else | |
431 | (void) _setjmp(regs); | |
432 | # endif | |
433 | # endif /* !HAVE_BUILTIN_UNWIND_INIT */ | |
434 | # if (defined(SPARC) && !defined(HAVE_BUILTIN_UNWIND_INIT)) \ | |
435 | || defined(IA64) | |
93002327 BM |
436 | /* On a register window machine, we need to save register */ |
437 | /* contents on the stack for this to work. The setjmp */ | |
438 | /* is probably not needed on SPARC, since pointers are */ | |
439 | /* only stored in windowed or scratch registers. It is */ | |
440 | /* needed on IA64, since some non-windowed registers are */ | |
441 | /* preserved. */ | |
442 | { | |
93002327 | 443 | GC_save_regs_ret_val = GC_save_regs_in_stack(); |
5a2586cf TT |
444 | /* On IA64 gcc, could use __builtin_ia64_flushrs() and */ |
445 | /* __builtin_ia64_flushrs(). The latter will be done */ | |
446 | /* implicitly by __builtin_unwind_init() for gcc3.0.1 */ | |
447 | /* and later. */ | |
93002327 BM |
448 | } |
449 | # endif | |
20bbd3cd | 450 | GC_push_current_stack(cold_gc_frame); |
73ffefd0 | 451 | } |
73ffefd0 | 452 | } |
20bbd3cd | 453 | #endif /* USE_GENERIC_PUSH_REGS */ |
73ffefd0 TT |
454 | |
455 | /* On register window machines, we need a way to force registers into */ | |
456 | /* the stack. Return sp. */ | |
457 | # ifdef SPARC | |
458 | asm(" .seg \"text\""); | |
30c3de1f | 459 | # if defined(SVR4) || defined(NETBSD) |
73ffefd0 TT |
460 | asm(" .globl GC_save_regs_in_stack"); |
461 | asm("GC_save_regs_in_stack:"); | |
462 | asm(" .type GC_save_regs_in_stack,#function"); | |
463 | # else | |
464 | asm(" .globl _GC_save_regs_in_stack"); | |
465 | asm("_GC_save_regs_in_stack:"); | |
466 | # endif | |
70635f1e | 467 | # if defined(__arch64__) || defined(__sparcv9) |
9110a741 BM |
468 | asm(" save %sp,-128,%sp"); |
469 | asm(" flushw"); | |
470 | asm(" ret"); | |
471 | asm(" restore %sp,2047+128,%o0"); | |
70635f1e | 472 | # else |
9110a741 BM |
473 | asm(" ta 0x3 ! ST_FLUSH_WINDOWS"); |
474 | asm(" retl"); | |
475 | asm(" mov %sp,%o0"); | |
476 | # endif | |
73ffefd0 TT |
477 | # ifdef SVR4 |
478 | asm(" .GC_save_regs_in_stack_end:"); | |
479 | asm(" .size GC_save_regs_in_stack,.GC_save_regs_in_stack_end-GC_save_regs_in_stack"); | |
480 | # endif | |
481 | # ifdef LINT | |
482 | word GC_save_regs_in_stack() { return(0 /* sp really */);} | |
483 | # endif | |
484 | # endif | |
485 | ||
20bbd3cd TT |
486 | /* On IA64, we also need to flush register windows. But they end */ |
487 | /* up on the other side of the stack segment. */ | |
488 | /* Returns the backing store pointer for the register stack. */ | |
79f777fd BM |
489 | /* We now implement this as a separate assembly file, since inline */ |
490 | /* assembly code here doesn't work with either the Intel or HP */ | |
491 | /* compilers. */ | |
492 | # if 0 | |
4c7726b1 | 493 | # ifdef LINUX |
20bbd3cd TT |
494 | asm(" .text"); |
495 | asm(" .psr abi64"); | |
496 | asm(" .psr lsb"); | |
497 | asm(" .lsb"); | |
498 | asm(""); | |
499 | asm(" .text"); | |
500 | asm(" .align 16"); | |
501 | asm(" .global GC_save_regs_in_stack"); | |
502 | asm(" .proc GC_save_regs_in_stack"); | |
503 | asm("GC_save_regs_in_stack:"); | |
504 | asm(" .body"); | |
505 | asm(" flushrs"); | |
506 | asm(" ;;"); | |
507 | asm(" mov r8=ar.bsp"); | |
508 | asm(" br.ret.sptk.few rp"); | |
509 | asm(" .endp GC_save_regs_in_stack"); | |
4c7726b1 BM |
510 | # endif /* LINUX */ |
511 | # if 0 /* Other alternatives that don't work on HP/UX */ | |
512 | word GC_save_regs_in_stack() { | |
513 | # if USE_BUILTINS | |
514 | __builtin_ia64_flushrs(); | |
515 | return __builtin_ia64_bsp(); | |
516 | # else | |
517 | # ifdef HPUX | |
518 | _asm(" flushrs"); | |
519 | _asm(" ;;"); | |
520 | _asm(" mov r8=ar.bsp"); | |
521 | _asm(" br.ret.sptk.few rp"); | |
522 | # else | |
523 | asm(" flushrs"); | |
524 | asm(" ;;"); | |
525 | asm(" mov r8=ar.bsp"); | |
526 | asm(" br.ret.sptk.few rp"); | |
527 | # endif | |
528 | # endif | |
9110a741 BM |
529 | } |
530 | # endif | |
20bbd3cd | 531 | # endif |
73ffefd0 TT |
532 | |
533 | /* GC_clear_stack_inner(arg, limit) clears stack area up to limit and */ | |
534 | /* returns arg. Stack clearing is crucial on SPARC, so we supply */ | |
535 | /* an assembly version that's more careful. Assumes limit is hotter */ | |
536 | /* than sp, and limit is 8 byte aligned. */ | |
5a2586cf | 537 | #if defined(ASM_CLEAR_CODE) |
73ffefd0 TT |
538 | #ifndef SPARC |
539 | --> fix it | |
540 | #endif | |
541 | # ifdef SUNOS4 | |
542 | asm(".globl _GC_clear_stack_inner"); | |
543 | asm("_GC_clear_stack_inner:"); | |
544 | # else | |
545 | asm(".globl GC_clear_stack_inner"); | |
546 | asm("GC_clear_stack_inner:"); | |
547 | asm(".type GC_save_regs_in_stack,#function"); | |
548 | # endif | |
70635f1e JJ |
549 | #if defined(__arch64__) || defined(__sparcv9) |
550 | asm("mov %sp,%o2"); /* Save sp */ | |
551 | asm("add %sp,2047-8,%o3"); /* p = sp+bias-8 */ | |
552 | asm("add %o1,-2047-192,%sp"); /* Move sp out of the way, */ | |
553 | /* so that traps still work. */ | |
554 | /* Includes some extra words */ | |
555 | /* so we can be sloppy below. */ | |
556 | asm("loop:"); | |
557 | asm("stx %g0,[%o3]"); /* *(long *)p = 0 */ | |
558 | asm("cmp %o3,%o1"); | |
559 | asm("bgu,pt %xcc, loop"); /* if (p > limit) goto loop */ | |
560 | asm("add %o3,-8,%o3"); /* p -= 8 (delay slot) */ | |
561 | asm("retl"); | |
562 | asm("mov %o2,%sp"); /* Restore sp., delay slot */ | |
563 | #else | |
73ffefd0 TT |
564 | asm("mov %sp,%o2"); /* Save sp */ |
565 | asm("add %sp,-8,%o3"); /* p = sp-8 */ | |
566 | asm("clr %g1"); /* [g0,g1] = 0 */ | |
567 | asm("add %o1,-0x60,%sp"); /* Move sp out of the way, */ | |
568 | /* so that traps still work. */ | |
569 | /* Includes some extra words */ | |
570 | /* so we can be sloppy below. */ | |
571 | asm("loop:"); | |
572 | asm("std %g0,[%o3]"); /* *(long long *)p = 0 */ | |
573 | asm("cmp %o3,%o1"); | |
574 | asm("bgu loop "); /* if (p > limit) goto loop */ | |
575 | asm("add %o3,-8,%o3"); /* p -= 8 (delay slot) */ | |
576 | asm("retl"); | |
577 | asm("mov %o2,%sp"); /* Restore sp., delay slot */ | |
9110a741 | 578 | #endif /* old SPARC */ |
73ffefd0 TT |
579 | /* First argument = %o0 = return value */ |
580 | # ifdef SVR4 | |
581 | asm(" .GC_clear_stack_inner_end:"); | |
582 | asm(" .size GC_clear_stack_inner,.GC_clear_stack_inner_end-GC_clear_stack_inner"); | |
583 | # endif | |
584 | ||
585 | # ifdef LINT | |
586 | /*ARGSUSED*/ | |
587 | ptr_t GC_clear_stack_inner(arg, limit) | |
588 | ptr_t arg; word limit; | |
589 | { return(arg); } | |
590 | # endif | |
591 | #endif |