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 /* Routine to mark from registers that are preserved by the C compiler. */
66 /* This must be ported to every new architecture. There is a generic */
67 /* version at the end, that is likely, but not guaranteed to work */
68 /* on your architecture. Run the test_setjmp program to see whether */
69 /* there is any chance it will work. */
71 #ifndef USE_GENERIC_PUSH_REGS
75 register long TMP_SP; /* must be bound to r11 */
78 /* VAX - generic code below does not work under 4.2 */
79 /* r1 through r5 are caller save, and therefore */
80 /* on the stack or dead. */
81 asm("pushl r11"); asm("calls $1,_GC_push_one");
82 asm("pushl r10"); asm("calls $1,_GC_push_one");
83 asm("pushl r9"); asm("calls $1,_GC_push_one");
84 asm("pushl r8"); asm("calls $1,_GC_push_one");
85 asm("pushl r7"); asm("calls $1,_GC_push_one");
86 asm("pushl r6"); asm("calls $1,_GC_push_one");
88 # if defined(M68K) && (defined(SUNOS4) || defined(NEXT))
89 /* M68K SUNOS - could be replaced by generic code */
90 /* a0, a1 and d1 are caller save */
91 /* and therefore are on stack or dead. */
93 asm("subqw #0x4,sp"); /* allocate word on top of stack */
95 asm("movl a2,sp@"); asm("jbsr _GC_push_one");
96 asm("movl a3,sp@"); asm("jbsr _GC_push_one");
97 asm("movl a4,sp@"); asm("jbsr _GC_push_one");
98 asm("movl a5,sp@"); asm("jbsr _GC_push_one");
99 /* Skip frame pointer and stack pointer */
100 asm("movl d1,sp@"); asm("jbsr _GC_push_one");
101 asm("movl d2,sp@"); asm("jbsr _GC_push_one");
102 asm("movl d3,sp@"); asm("jbsr _GC_push_one");
103 asm("movl d4,sp@"); asm("jbsr _GC_push_one");
104 asm("movl d5,sp@"); asm("jbsr _GC_push_one");
105 asm("movl d6,sp@"); asm("jbsr _GC_push_one");
106 asm("movl d7,sp@"); asm("jbsr _GC_push_one");
108 asm("addqw #0x4,sp"); /* put stack back where it was */
111 # if defined(M68K) && defined(HP)
112 /* M68K HP - could be replaced by generic code */
113 /* a0, a1 and d1 are caller save. */
115 asm("subq.w &0x4,%sp"); /* allocate word on top of stack */
117 asm("mov.l %a2,(%sp)"); asm("jsr _GC_push_one");
118 asm("mov.l %a3,(%sp)"); asm("jsr _GC_push_one");
119 asm("mov.l %a4,(%sp)"); asm("jsr _GC_push_one");
120 asm("mov.l %a5,(%sp)"); asm("jsr _GC_push_one");
121 /* Skip frame pointer and stack pointer */
122 asm("mov.l %d1,(%sp)"); asm("jsr _GC_push_one");
123 asm("mov.l %d2,(%sp)"); asm("jsr _GC_push_one");
124 asm("mov.l %d3,(%sp)"); asm("jsr _GC_push_one");
125 asm("mov.l %d4,(%sp)"); asm("jsr _GC_push_one");
126 asm("mov.l %d5,(%sp)"); asm("jsr _GC_push_one");
127 asm("mov.l %d6,(%sp)"); asm("jsr _GC_push_one");
128 asm("mov.l %d7,(%sp)"); asm("jsr _GC_push_one");
130 asm("addq.w &0x4,%sp"); /* put stack back where it was */
131 # endif /* M68K HP */
133 # if defined(M68K) && defined(AMIGA)
134 /* AMIGA - could be replaced by generic code */
135 /* a0, a1, d0 and d1 are caller save */
138 asm("subq.w &0x4,%sp"); /* allocate word on top of stack */
140 asm("mov.l %a2,(%sp)"); asm("jsr _GC_push_one");
141 asm("mov.l %a3,(%sp)"); asm("jsr _GC_push_one");
142 asm("mov.l %a4,(%sp)"); asm("jsr _GC_push_one");
143 asm("mov.l %a5,(%sp)"); asm("jsr _GC_push_one");
144 asm("mov.l %a6,(%sp)"); asm("jsr _GC_push_one");
145 /* Skip frame pointer and stack pointer */
146 asm("mov.l %d2,(%sp)"); asm("jsr _GC_push_one");
147 asm("mov.l %d3,(%sp)"); asm("jsr _GC_push_one");
148 asm("mov.l %d4,(%sp)"); asm("jsr _GC_push_one");
149 asm("mov.l %d5,(%sp)"); asm("jsr _GC_push_one");
150 asm("mov.l %d6,(%sp)"); asm("jsr _GC_push_one");
151 asm("mov.l %d7,(%sp)"); asm("jsr _GC_push_one");
153 asm("addq.w &0x4,%sp"); /* put stack back where it was */
154 # else /* !__GNUC__ */
155 GC_push_one(getreg(REG_A2));
156 GC_push_one(getreg(REG_A3));
157 GC_push_one(getreg(REG_A4));
158 GC_push_one(getreg(REG_A5));
159 GC_push_one(getreg(REG_A6));
160 /* Skip stack pointer */
161 GC_push_one(getreg(REG_D2));
162 GC_push_one(getreg(REG_D3));
163 GC_push_one(getreg(REG_D4));
164 GC_push_one(getreg(REG_D5));
165 GC_push_one(getreg(REG_D6));
166 GC_push_one(getreg(REG_D7));
167 # endif /* !__GNUC__ */
170 # if defined(M68K) && defined(MACOS)
171 # if defined(THINK_C)
172 # define PushMacReg(reg) \
176 sub.w #4,sp ; reserve space for one parameter.
180 ; skip a5 (globals), a6 (frame pointer), and a7 (stack pointer)
187 add.w #4,sp ; fix stack.
190 # endif /* THINK_C */
191 # if defined(__MWERKS__)
193 # endif /* __MWERKS__ */
196 # if defined(I386) &&!defined(OS2) &&!defined(SVR4) &&!defined(MSWIN32) \
197 && !defined(SCO) && !defined(SCO_ELF) \
198 && !(defined(LINUX) && defined(__ELF__)) \
199 && !(defined(__FreeBSD__) && defined(__ELF__)) \
201 /* I386 code, generic code does not appear to work */
202 /* It does appear to work under OS2, and asms dont */
203 /* This is used for some 38g UNIX variants and for CYGWIN32 */
204 asm("pushl %eax"); asm("call _GC_push_one"); asm("addl $4,%esp");
205 asm("pushl %ecx"); asm("call _GC_push_one"); asm("addl $4,%esp");
206 asm("pushl %edx"); asm("call _GC_push_one"); asm("addl $4,%esp");
207 asm("pushl %ebp"); asm("call _GC_push_one"); asm("addl $4,%esp");
208 asm("pushl %esi"); asm("call _GC_push_one"); asm("addl $4,%esp");
209 asm("pushl %edi"); asm("call _GC_push_one"); asm("addl $4,%esp");
210 asm("pushl %ebx"); asm("call _GC_push_one"); asm("addl $4,%esp");
213 # if ( defined(I386) && defined(LINUX) && defined(__ELF__) ) \
214 || ( defined(I386) && defined(__FreeBSD__) && defined(__ELF__) )
216 /* This is modified for Linux with ELF (Note: _ELF_ only) */
217 /* This section handles FreeBSD with ELF. */
218 asm("pushl %eax"); asm("call GC_push_one"); asm("addl $4,%esp");
219 asm("pushl %ecx"); asm("call GC_push_one"); asm("addl $4,%esp");
220 asm("pushl %edx"); asm("call GC_push_one"); asm("addl $4,%esp");
221 asm("pushl %ebp"); asm("call GC_push_one"); asm("addl $4,%esp");
222 asm("pushl %esi"); asm("call GC_push_one"); asm("addl $4,%esp");
223 asm("pushl %edi"); asm("call GC_push_one"); asm("addl $4,%esp");
224 asm("pushl %ebx"); asm("call GC_push_one"); asm("addl $4,%esp");
227 # if defined(I386) && defined(__MINGW32__)
228 /* I386 code, generic code does not appear to work */
229 /* It does appear to work under OS2, and asms dont */
230 /* This is used for some 38g UNIX variants and for CYGWIN32 */
231 asm("pushl %eax"); asm("call _GC_push_one"); asm("addl $4,%esp");
232 asm("pushl %ecx"); asm("call _GC_push_one"); asm("addl $4,%esp");
233 asm("pushl %edx"); asm("call _GC_push_one"); asm("addl $4,%esp");
234 asm("pushl %ebp"); asm("call _GC_push_one"); asm("addl $4,%esp");
235 asm("pushl %esi"); asm("call _GC_push_one"); asm("addl $4,%esp");
236 asm("pushl %edi"); asm("call _GC_push_one"); asm("addl $4,%esp");
237 asm("pushl %ebx"); asm("call _GC_push_one"); asm("addl $4,%esp");
240 # if defined(I386) && defined(MSWIN32) && !defined(USE_GENERIC) && !defined(__MINGW32__)
241 /* I386 code, Microsoft variant */
243 __asm call GC_push_one
246 __asm call GC_push_one
249 __asm call GC_push_one
252 __asm call GC_push_one
255 __asm call GC_push_one
258 __asm call GC_push_one
261 __asm call GC_push_one
265 # if defined(I386) && (defined(SVR4) || defined(SCO) || defined(SCO_ELF))
266 /* I386 code, SVR4 variant, generic code does not appear to work */
267 asm("pushl %eax"); asm("call GC_push_one"); asm("addl $4,%esp");
268 asm("pushl %ebx"); asm("call GC_push_one"); asm("addl $4,%esp");
269 asm("pushl %ecx"); asm("call GC_push_one"); asm("addl $4,%esp");
270 asm("pushl %edx"); asm("call GC_push_one"); asm("addl $4,%esp");
271 asm("pushl %ebp"); asm("call GC_push_one"); asm("addl $4,%esp");
272 asm("pushl %esi"); asm("call GC_push_one"); asm("addl $4,%esp");
273 asm("pushl %edi"); asm("call GC_push_one"); asm("addl $4,%esp");
277 asm ("movd r3, tos"); asm ("bsr ?_GC_push_one"); asm ("adjspb $-4");
278 asm ("movd r4, tos"); asm ("bsr ?_GC_push_one"); asm ("adjspb $-4");
279 asm ("movd r5, tos"); asm ("bsr ?_GC_push_one"); asm ("adjspb $-4");
280 asm ("movd r6, tos"); asm ("bsr ?_GC_push_one"); asm ("adjspb $-4");
281 asm ("movd r7, tos"); asm ("bsr ?_GC_push_one"); asm ("adjspb $-4");
286 word GC_save_regs_in_stack();
288 /* generic code will not work */
289 (void)GC_save_regs_in_stack();
294 GC_push_one(TMP_SP); /* GC_push_one from r11 */
296 asm("cas r11, r6, r0"); GC_push_one(TMP_SP); /* r6 */
297 asm("cas r11, r7, r0"); GC_push_one(TMP_SP); /* through */
298 asm("cas r11, r8, r0"); GC_push_one(TMP_SP); /* r10 */
299 asm("cas r11, r9, r0"); GC_push_one(TMP_SP);
300 asm("cas r11, r10, r0"); GC_push_one(TMP_SP);
302 asm("cas r11, r12, r0"); GC_push_one(TMP_SP); /* r12 */
303 asm("cas r11, r13, r0"); GC_push_one(TMP_SP); /* through */
304 asm("cas r11, r14, r0"); GC_push_one(TMP_SP); /* r15 */
305 asm("cas r11, r15, r0"); GC_push_one(TMP_SP);
308 # if defined(M68K) && defined(SYSV)
309 /* Once again similar to SUN and HP, though setjmp appears to work.
313 asm("subqw #0x4,%sp"); /* allocate word on top of stack */
315 asm("movl %a2,%sp@"); asm("jbsr GC_push_one");
316 asm("movl %a3,%sp@"); asm("jbsr GC_push_one");
317 asm("movl %a4,%sp@"); asm("jbsr GC_push_one");
318 asm("movl %a5,%sp@"); asm("jbsr GC_push_one");
319 /* Skip frame pointer and stack pointer */
320 asm("movl %d1,%sp@"); asm("jbsr GC_push_one");
321 asm("movl %d2,%sp@"); asm("jbsr GC_push_one");
322 asm("movl %d3,%sp@"); asm("jbsr GC_push_one");
323 asm("movl %d4,%sp@"); asm("jbsr GC_push_one");
324 asm("movl %d5,%sp@"); asm("jbsr GC_push_one");
325 asm("movl %d6,%sp@"); asm("jbsr GC_push_one");
326 asm("movl %d7,%sp@"); asm("jbsr GC_push_one");
328 asm("addqw #0x4,%sp"); /* put stack back where it was */
329 # else /* !__GNUC__*/
330 asm("subq.w &0x4,%sp"); /* allocate word on top of stack */
332 asm("mov.l %a2,(%sp)"); asm("jsr GC_push_one");
333 asm("mov.l %a3,(%sp)"); asm("jsr GC_push_one");
334 asm("mov.l %a4,(%sp)"); asm("jsr GC_push_one");
335 asm("mov.l %a5,(%sp)"); asm("jsr GC_push_one");
336 /* Skip frame pointer and stack pointer */
337 asm("mov.l %d1,(%sp)"); asm("jsr GC_push_one");
338 asm("mov.l %d2,(%sp)"); asm("jsr GC_push_one");
339 asm("mov.l %d3,(%sp)"); asm("jsr GC_push_one");
340 asm("mov.l %d4,(%sp)"); asm("jsr GC_push_one");
341 asm("mov.l %d5,(%sp)"); asm("jsr GC_push_one");
342 asm("mov.l %d6,(%sp)"); asm("jsr GC_push_one");
343 asm("mov.l %d7,(%sp)"); asm("jsr GC_push_one");
345 asm("addq.w &0x4,%sp"); /* put stack back where it was */
346 # endif /* !__GNUC__ */
347 # endif /* M68K/SYSV */
350 /* other machines... */
351 # if !(defined M68K) && !(defined VAX) && !(defined RT)
352 # if !(defined SPARC) && !(defined I386) && !(defined NS32K)
353 # if !defined(POWERPC) && !defined(UTS4)
359 #endif /* !USE_GENERIC_PUSH_REGS */
361 #if defined(USE_GENERIC_PUSH_REGS)
362 void GC_generic_push_regs(cold_gc_frame)
366 /* The idea is due to Parag Patel at HP. */
367 /* We're not sure whether he would like */
368 /* to be he acknowledged for it or not. */
371 register word * i = (word *) regs;
372 register ptr_t lim = (ptr_t)(regs) + (sizeof regs);
374 /* Setjmp on Sun 3s doesn't clear all of the buffer. */
375 /* That tends to preserve garbage. Clear it. */
376 for (; (char *)i < lim; i++) {
379 # if defined(POWERPC) || defined(MSWIN32) || defined(UTS4)
382 (void) _setjmp(regs);
384 GC_push_current_stack(cold_gc_frame);
387 #endif /* USE_GENERIC_PUSH_REGS */
389 /* On register window machines, we need a way to force registers into */
390 /* the stack. Return sp. */
392 asm(" .seg \"text\"");
394 asm(" .globl GC_save_regs_in_stack");
395 asm("GC_save_regs_in_stack:");
396 asm(" .type GC_save_regs_in_stack,#function");
398 asm(" .globl _GC_save_regs_in_stack");
399 asm("_GC_save_regs_in_stack:");
401 asm(" ta 0x3 ! ST_FLUSH_WINDOWS");
406 asm(" .GC_save_regs_in_stack_end:");
407 asm(" .size GC_save_regs_in_stack,.GC_save_regs_in_stack_end-GC_save_regs_in_stack");
410 word GC_save_regs_in_stack() { return(0 /* sp really */);}
415 /* GC_clear_stack_inner(arg, limit) clears stack area up to limit and */
416 /* returns arg. Stack clearing is crucial on SPARC, so we supply */
417 /* an assembly version that's more careful. Assumes limit is hotter */
418 /* than sp, and limit is 8 byte aligned. */
419 #if defined(ASM_CLEAR_CODE) && !defined(THREADS)
424 asm(".globl _GC_clear_stack_inner");
425 asm("_GC_clear_stack_inner:");
427 asm(".globl GC_clear_stack_inner");
428 asm("GC_clear_stack_inner:");
429 asm(".type GC_save_regs_in_stack,#function");
431 asm("mov %sp,%o2"); /* Save sp */
432 asm("add %sp,-8,%o3"); /* p = sp-8 */
433 asm("clr %g1"); /* [g0,g1] = 0 */
434 asm("add %o1,-0x60,%sp"); /* Move sp out of the way, */
435 /* so that traps still work. */
436 /* Includes some extra words */
437 /* so we can be sloppy below. */
439 asm("std %g0,[%o3]"); /* *(long long *)p = 0 */
441 asm("bgu loop "); /* if (p > limit) goto loop */
442 asm("add %o3,-8,%o3"); /* p -= 8 (delay slot) */
444 asm("mov %o2,%sp"); /* Restore sp., delay slot */
445 /* First argument = %o0 = return value */
447 asm(" .GC_clear_stack_inner_end:");
448 asm(" .size GC_clear_stack_inner,.GC_clear_stack_inner_end-GC_clear_stack_inner");
453 ptr_t GC_clear_stack_inner(arg, limit)
454 ptr_t arg; word limit;