2 * Copyright 1988, 1989 Hans-J. Boehm, Alan J. Demers
3 * Copyright (c) 1991-1994 by Xerox Corporation. All rights reserved.
5 * THIS MATERIAL IS PROVIDED AS IS, WITH ABSOLUTELY NO WARRANTY EXPRESSED
6 * OR IMPLIED. ANY USE IS AT YOUR OWN RISK.
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.
14 /* Boehm, November 17, 1995 12:13 pm PST */
18 # if defined(OS2) || defined(CX_UX)
19 # define _setjmp(b) setjmp(b)
20 # define _longjmp(b,v) longjmp(b,v)
26 # include <machine/reg.h>
30 #if defined(__MWERKS__) && !defined(POWERPC)
32 asm static void PushMacRegisters()
34 sub
.w
#4,sp // reserve space for one parameter.
41 # if !__option(a6frames)
42 // <pcb> perhaps a6 should be pushed if stack frames are not being used.
46 // skip a5 (globals), a6 (frame pointer), and a7 (stack pointer)
59 add
.w
#4,sp // fix stack.
63 #endif /* __MWERKS__ */
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
;
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. */
77 #ifndef USE_GENERIC_PUSH_REGS
81 register long TMP_SP
; /* must be bound to r11 */
84 /* VAX - generic code below does not work under 4.2 */
85 /* r1 through r5 are caller save, and therefore */
86 /* on the stack or dead. */
87 asm("pushl r11"); asm("calls $1,_GC_push_one");
88 asm("pushl r10"); asm("calls $1,_GC_push_one");
89 asm("pushl r9"); asm("calls $1,_GC_push_one");
90 asm("pushl r8"); asm("calls $1,_GC_push_one");
91 asm("pushl r7"); asm("calls $1,_GC_push_one");
92 asm("pushl r6"); asm("calls $1,_GC_push_one");
94 # if defined(M68K) && (defined(SUNOS4) || defined(NEXT))
95 /* M68K SUNOS - could be replaced by generic code */
96 /* a0, a1 and d1 are caller save */
97 /* and therefore are on stack or dead. */
99 asm("subqw #0x4,sp"); /* allocate word on top of stack */
101 asm("movl a2,sp@"); asm("jbsr _GC_push_one");
102 asm("movl a3,sp@"); asm("jbsr _GC_push_one");
103 asm("movl a4,sp@"); asm("jbsr _GC_push_one");
104 asm("movl a5,sp@"); asm("jbsr _GC_push_one");
105 /* Skip frame pointer and stack pointer */
106 asm("movl d1,sp@"); asm("jbsr _GC_push_one");
107 asm("movl d2,sp@"); asm("jbsr _GC_push_one");
108 asm("movl d3,sp@"); asm("jbsr _GC_push_one");
109 asm("movl d4,sp@"); asm("jbsr _GC_push_one");
110 asm("movl d5,sp@"); asm("jbsr _GC_push_one");
111 asm("movl d6,sp@"); asm("jbsr _GC_push_one");
112 asm("movl d7,sp@"); asm("jbsr _GC_push_one");
114 asm("addqw #0x4,sp"); /* put stack back where it was */
117 # if defined(M68K) && defined(HP)
118 /* M68K HP - could be replaced by generic code */
119 /* a0, a1 and d1 are caller save. */
121 asm("subq.w &0x4,%sp"); /* allocate word on top of stack */
123 asm("mov.l %a2,(%sp)"); asm("jsr _GC_push_one");
124 asm("mov.l %a3,(%sp)"); asm("jsr _GC_push_one");
125 asm("mov.l %a4,(%sp)"); asm("jsr _GC_push_one");
126 asm("mov.l %a5,(%sp)"); asm("jsr _GC_push_one");
127 /* Skip frame pointer and stack pointer */
128 asm("mov.l %d1,(%sp)"); asm("jsr _GC_push_one");
129 asm("mov.l %d2,(%sp)"); asm("jsr _GC_push_one");
130 asm("mov.l %d3,(%sp)"); asm("jsr _GC_push_one");
131 asm("mov.l %d4,(%sp)"); asm("jsr _GC_push_one");
132 asm("mov.l %d5,(%sp)"); asm("jsr _GC_push_one");
133 asm("mov.l %d6,(%sp)"); asm("jsr _GC_push_one");
134 asm("mov.l %d7,(%sp)"); asm("jsr _GC_push_one");
136 asm("addq.w &0x4,%sp"); /* put stack back where it was */
137 # endif /* M68K HP */
139 # if defined(M68K) && defined(AMIGA)
140 /* AMIGA - could be replaced by generic code */
141 /* a0, a1, d0 and d1 are caller save */
144 asm("subq.w &0x4,%sp"); /* allocate word on top of stack */
146 asm("mov.l %a2,(%sp)"); asm("jsr _GC_push_one");
147 asm("mov.l %a3,(%sp)"); asm("jsr _GC_push_one");
148 asm("mov.l %a4,(%sp)"); asm("jsr _GC_push_one");
149 asm("mov.l %a5,(%sp)"); asm("jsr _GC_push_one");
150 asm("mov.l %a6,(%sp)"); asm("jsr _GC_push_one");
151 /* Skip frame pointer and stack pointer */
152 asm("mov.l %d2,(%sp)"); asm("jsr _GC_push_one");
153 asm("mov.l %d3,(%sp)"); asm("jsr _GC_push_one");
154 asm("mov.l %d4,(%sp)"); asm("jsr _GC_push_one");
155 asm("mov.l %d5,(%sp)"); asm("jsr _GC_push_one");
156 asm("mov.l %d6,(%sp)"); asm("jsr _GC_push_one");
157 asm("mov.l %d7,(%sp)"); asm("jsr _GC_push_one");
159 asm("addq.w &0x4,%sp"); /* put stack back where it was */
160 # else /* !__GNUC__ */
161 GC_push_one(getreg(REG_A2
));
162 GC_push_one(getreg(REG_A3
));
163 GC_push_one(getreg(REG_A4
));
164 GC_push_one(getreg(REG_A5
));
165 GC_push_one(getreg(REG_A6
));
166 /* Skip stack pointer */
167 GC_push_one(getreg(REG_D2
));
168 GC_push_one(getreg(REG_D3
));
169 GC_push_one(getreg(REG_D4
));
170 GC_push_one(getreg(REG_D5
));
171 GC_push_one(getreg(REG_D6
));
172 GC_push_one(getreg(REG_D7
));
173 # endif /* !__GNUC__ */
176 # if defined(M68K) && defined(MACOS)
177 # if defined(THINK_C)
178 # define PushMacReg(reg) \
182 sub
.w
#4,sp ; reserve space for one parameter.
186 ; skip
a5 (globals
), a6 (frame pointer
), and a7 (stack pointer
)
193 add
.w
#4,sp ; fix stack.
196 # endif /* THINK_C */
197 # if defined(__MWERKS__)
199 # endif /* __MWERKS__ */
202 # if defined(I386) &&!defined(OS2) &&!defined(SVR4) &&!defined(MSWIN32) \
203 && !defined(SCO) && !defined(SCO_ELF) \
204 && !(defined(LINUX) && defined(__ELF__)) \
205 && !(defined(__FreeBSD__) && defined(__ELF__)) \
207 /* I386 code, generic code does not appear to work */
208 /* It does appear to work under OS2, and asms dont */
209 /* This is used for some 38g UNIX variants and for CYGWIN32 */
210 asm("pushl %eax"); asm("call _GC_push_one"); asm("addl $4,%esp");
211 asm("pushl %ecx"); asm("call _GC_push_one"); asm("addl $4,%esp");
212 asm("pushl %edx"); asm("call _GC_push_one"); asm("addl $4,%esp");
213 asm("pushl %ebp"); asm("call _GC_push_one"); asm("addl $4,%esp");
214 asm("pushl %esi"); asm("call _GC_push_one"); asm("addl $4,%esp");
215 asm("pushl %edi"); asm("call _GC_push_one"); asm("addl $4,%esp");
216 asm("pushl %ebx"); asm("call _GC_push_one"); asm("addl $4,%esp");
219 # if ( defined(I386) && defined(LINUX) && defined(__ELF__) ) \
220 || ( defined(I386) && defined(__FreeBSD__) && defined(__ELF__) )
222 /* This is modified for Linux with ELF (Note: _ELF_ only) */
223 /* This section handles FreeBSD with ELF. */
224 asm("pushl %eax"); asm("call GC_push_one"); asm("addl $4,%esp");
225 asm("pushl %ecx"); asm("call GC_push_one"); asm("addl $4,%esp");
226 asm("pushl %edx"); asm("call GC_push_one"); asm("addl $4,%esp");
227 asm("pushl %ebp"); asm("call GC_push_one"); asm("addl $4,%esp");
228 asm("pushl %esi"); asm("call GC_push_one"); asm("addl $4,%esp");
229 asm("pushl %edi"); asm("call GC_push_one"); asm("addl $4,%esp");
230 asm("pushl %ebx"); asm("call GC_push_one"); asm("addl $4,%esp");
233 # if defined(I386) && defined(MSWIN32) && !defined(USE_GENERIC)
234 /* I386 code, Microsoft variant */
236 __asm call GC_push_one
239 __asm call GC_push_one
242 __asm call GC_push_one
245 __asm call GC_push_one
248 __asm call GC_push_one
251 __asm call GC_push_one
254 __asm call GC_push_one
258 # if defined(I386) && (defined(SVR4) || defined(SCO) || defined(SCO_ELF))
259 /* I386 code, SVR4 variant, generic code does not appear to work */
260 asm("pushl %eax"); asm("call GC_push_one"); asm("addl $4,%esp");
261 asm("pushl %ebx"); asm("call GC_push_one"); asm("addl $4,%esp");
262 asm("pushl %ecx"); asm("call GC_push_one"); asm("addl $4,%esp");
263 asm("pushl %edx"); asm("call GC_push_one"); asm("addl $4,%esp");
264 asm("pushl %ebp"); asm("call GC_push_one"); asm("addl $4,%esp");
265 asm("pushl %esi"); asm("call GC_push_one"); asm("addl $4,%esp");
266 asm("pushl %edi"); asm("call GC_push_one"); asm("addl $4,%esp");
270 asm ("movd r3, tos"); asm ("bsr ?_GC_push_one"); asm ("adjspb $-4");
271 asm ("movd r4, tos"); asm ("bsr ?_GC_push_one"); asm ("adjspb $-4");
272 asm ("movd r5, tos"); asm ("bsr ?_GC_push_one"); asm ("adjspb $-4");
273 asm ("movd r6, tos"); asm ("bsr ?_GC_push_one"); asm ("adjspb $-4");
274 asm ("movd r7, tos"); asm ("bsr ?_GC_push_one"); asm ("adjspb $-4");
277 # if defined(SPARC) || defined(IA64)
279 word
GC_save_regs_in_stack();
281 /* generic code will not work */
282 GC_save_regs_ret_val
= GC_save_regs_in_stack();
287 GC_push_one(TMP_SP
); /* GC_push_one from r11 */
289 asm("cas r11, r6, r0"); GC_push_one(TMP_SP
); /* r6 */
290 asm("cas r11, r7, r0"); GC_push_one(TMP_SP
); /* through */
291 asm("cas r11, r8, r0"); GC_push_one(TMP_SP
); /* r10 */
292 asm("cas r11, r9, r0"); GC_push_one(TMP_SP
);
293 asm("cas r11, r10, r0"); GC_push_one(TMP_SP
);
295 asm("cas r11, r12, r0"); GC_push_one(TMP_SP
); /* r12 */
296 asm("cas r11, r13, r0"); GC_push_one(TMP_SP
); /* through */
297 asm("cas r11, r14, r0"); GC_push_one(TMP_SP
); /* r15 */
298 asm("cas r11, r15, r0"); GC_push_one(TMP_SP
);
301 # if defined(M68K) && defined(SYSV)
302 /* Once again similar to SUN and HP, though setjmp appears to work.
306 asm("subqw #0x4,%sp"); /* allocate word on top of stack */
308 asm("movl %a2,%sp@"); asm("jbsr GC_push_one");
309 asm("movl %a3,%sp@"); asm("jbsr GC_push_one");
310 asm("movl %a4,%sp@"); asm("jbsr GC_push_one");
311 asm("movl %a5,%sp@"); asm("jbsr GC_push_one");
312 /* Skip frame pointer and stack pointer */
313 asm("movl %d1,%sp@"); asm("jbsr GC_push_one");
314 asm("movl %d2,%sp@"); asm("jbsr GC_push_one");
315 asm("movl %d3,%sp@"); asm("jbsr GC_push_one");
316 asm("movl %d4,%sp@"); asm("jbsr GC_push_one");
317 asm("movl %d5,%sp@"); asm("jbsr GC_push_one");
318 asm("movl %d6,%sp@"); asm("jbsr GC_push_one");
319 asm("movl %d7,%sp@"); asm("jbsr GC_push_one");
321 asm("addqw #0x4,%sp"); /* put stack back where it was */
322 # else /* !__GNUC__*/
323 asm("subq.w &0x4,%sp"); /* allocate word on top of stack */
325 asm("mov.l %a2,(%sp)"); asm("jsr GC_push_one");
326 asm("mov.l %a3,(%sp)"); asm("jsr GC_push_one");
327 asm("mov.l %a4,(%sp)"); asm("jsr GC_push_one");
328 asm("mov.l %a5,(%sp)"); asm("jsr GC_push_one");
329 /* Skip frame pointer and stack pointer */
330 asm("mov.l %d1,(%sp)"); asm("jsr GC_push_one");
331 asm("mov.l %d2,(%sp)"); asm("jsr GC_push_one");
332 asm("mov.l %d3,(%sp)"); asm("jsr GC_push_one");
333 asm("mov.l %d4,(%sp)"); asm("jsr GC_push_one");
334 asm("mov.l %d5,(%sp)"); asm("jsr GC_push_one");
335 asm("mov.l %d6,(%sp)"); asm("jsr GC_push_one");
336 asm("mov.l %d7,(%sp)"); asm("jsr GC_push_one");
338 asm("addq.w &0x4,%sp"); /* put stack back where it was */
339 # endif /* !__GNUC__ */
340 # endif /* M68K/SYSV */
344 register int * sp
asm ("optop");
345 extern int *__libc_stack_end
;
347 GC_push_all_stack (sp
, __libc_stack_end
);
351 /* other machines... */
352 # if !(defined M68K) && !(defined VAX) && !(defined RT)
353 # if !(defined SPARC) && !(defined I386) && !(defined NS32K)
354 # if !defined(POWERPC) && !defined(UTS4) && !defined(IA64)
362 #endif /* !USE_GENERIC_PUSH_REGS */
364 #if defined(USE_GENERIC_PUSH_REGS)
365 void GC_generic_push_regs(cold_gc_frame
)
369 /* The idea is due to Parag Patel at HP. */
370 /* We're not sure whether he would like */
371 /* to be he acknowledged for it or not. */
374 register word
* i
= (word
*) regs
;
375 register ptr_t lim
= (ptr_t
)(regs
) + (sizeof regs
);
377 /* Setjmp on Sun 3s doesn't clear all of the buffer. */
378 /* That tends to preserve garbage. Clear it. */
379 for (; (char *)i
< lim
; i
++) {
382 # if defined(POWERPC) || defined(MSWIN32) || defined(UTS4)
385 (void) _setjmp(regs
);
387 GC_push_current_stack(cold_gc_frame
);
390 #endif /* USE_GENERIC_PUSH_REGS */
392 /* On register window machines, we need a way to force registers into */
393 /* the stack. Return sp. */
395 asm(" .seg \"text\"");
397 asm(" .globl GC_save_regs_in_stack");
398 asm("GC_save_regs_in_stack:");
399 asm(" .type GC_save_regs_in_stack,#function");
401 asm(" .globl _GC_save_regs_in_stack");
402 asm("_GC_save_regs_in_stack:");
404 asm(" ta 0x3 ! ST_FLUSH_WINDOWS");
409 asm(" .GC_save_regs_in_stack_end:");
410 asm(" .size GC_save_regs_in_stack,.GC_save_regs_in_stack_end-GC_save_regs_in_stack");
413 word
GC_save_regs_in_stack() { return(0 /* sp really */);}
417 /* On IA64, we also need to flush register windows. But they end */
418 /* up on the other side of the stack segment. */
419 /* Returns the backing store pointer for the register stack. */
428 asm(" .global GC_save_regs_in_stack");
429 asm(" .proc GC_save_regs_in_stack");
430 asm("GC_save_regs_in_stack:");
434 asm(" mov r8=ar.bsp");
435 asm(" br.ret.sptk.few rp");
436 asm(" .endp GC_save_regs_in_stack");
439 /* GC_clear_stack_inner(arg, limit) clears stack area up to limit and */
440 /* returns arg. Stack clearing is crucial on SPARC, so we supply */
441 /* an assembly version that's more careful. Assumes limit is hotter */
442 /* than sp, and limit is 8 byte aligned. */
443 #if defined(ASM_CLEAR_CODE) && !defined(THREADS)
448 asm(".globl _GC_clear_stack_inner");
449 asm("_GC_clear_stack_inner:");
451 asm(".globl GC_clear_stack_inner");
452 asm("GC_clear_stack_inner:");
453 asm(".type GC_save_regs_in_stack,#function");
455 asm("mov %sp,%o2"); /* Save sp */
456 asm("add %sp,-8,%o3"); /* p = sp-8 */
457 asm("clr %g1"); /* [g0,g1] = 0 */
458 asm("add %o1,-0x60,%sp"); /* Move sp out of the way, */
459 /* so that traps still work. */
460 /* Includes some extra words */
461 /* so we can be sloppy below. */
463 asm("std %g0,[%o3]"); /* *(long long *)p = 0 */
465 asm("bgu loop "); /* if (p > limit) goto loop */
466 asm("add %o3,-8,%o3"); /* p -= 8 (delay slot) */
468 asm("mov %o2,%sp"); /* Restore sp., delay slot */
469 /* First argument = %o0 = return value */
471 asm(" .GC_clear_stack_inner_end:");
472 asm(" .size GC_clear_stack_inner,.GC_clear_stack_inner_end-GC_clear_stack_inner");
477 ptr_t
GC_clear_stack_inner(arg
, limit
)
478 ptr_t arg
; word limit
;