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(MSWIN32) && !defined(USE_GENERIC)
228 /* I386 code, Microsoft variant */
230 __asm call GC_push_one
233 __asm call GC_push_one
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
252 # if defined(I386) && (defined(SVR4) || defined(SCO) || defined(SCO_ELF))
253 /* I386 code, SVR4 variant, generic code does not appear to work */
254 asm("pushl %eax"); asm("call GC_push_one"); asm("addl $4,%esp");
255 asm("pushl %ebx"); asm("call GC_push_one"); asm("addl $4,%esp");
256 asm("pushl %ecx"); asm("call GC_push_one"); asm("addl $4,%esp");
257 asm("pushl %edx"); asm("call GC_push_one"); asm("addl $4,%esp");
258 asm("pushl %ebp"); asm("call GC_push_one"); asm("addl $4,%esp");
259 asm("pushl %esi"); asm("call GC_push_one"); asm("addl $4,%esp");
260 asm("pushl %edi"); asm("call GC_push_one"); asm("addl $4,%esp");
264 asm ("movd r3, tos"); asm ("bsr ?_GC_push_one"); asm ("adjspb $-4");
265 asm ("movd r4, tos"); asm ("bsr ?_GC_push_one"); asm ("adjspb $-4");
266 asm ("movd r5, tos"); asm ("bsr ?_GC_push_one"); asm ("adjspb $-4");
267 asm ("movd r6, tos"); asm ("bsr ?_GC_push_one"); asm ("adjspb $-4");
268 asm ("movd r7, tos"); asm ("bsr ?_GC_push_one"); asm ("adjspb $-4");
273 word GC_save_regs_in_stack();
275 /* generic code will not work */
276 (void)GC_save_regs_in_stack();
281 GC_push_one(TMP_SP); /* GC_push_one from r11 */
283 asm("cas r11, r6, r0"); GC_push_one(TMP_SP); /* r6 */
284 asm("cas r11, r7, r0"); GC_push_one(TMP_SP); /* through */
285 asm("cas r11, r8, r0"); GC_push_one(TMP_SP); /* r10 */
286 asm("cas r11, r9, r0"); GC_push_one(TMP_SP);
287 asm("cas r11, r10, r0"); GC_push_one(TMP_SP);
289 asm("cas r11, r12, r0"); GC_push_one(TMP_SP); /* r12 */
290 asm("cas r11, r13, r0"); GC_push_one(TMP_SP); /* through */
291 asm("cas r11, r14, r0"); GC_push_one(TMP_SP); /* r15 */
292 asm("cas r11, r15, r0"); GC_push_one(TMP_SP);
295 # if defined(M68K) && defined(SYSV)
296 /* Once again similar to SUN and HP, though setjmp appears to work.
300 asm("subqw #0x4,%sp"); /* allocate word on top of stack */
302 asm("movl %a2,%sp@"); asm("jbsr GC_push_one");
303 asm("movl %a3,%sp@"); asm("jbsr GC_push_one");
304 asm("movl %a4,%sp@"); asm("jbsr GC_push_one");
305 asm("movl %a5,%sp@"); asm("jbsr GC_push_one");
306 /* Skip frame pointer and stack pointer */
307 asm("movl %d1,%sp@"); asm("jbsr GC_push_one");
308 asm("movl %d2,%sp@"); asm("jbsr GC_push_one");
309 asm("movl %d3,%sp@"); asm("jbsr GC_push_one");
310 asm("movl %d4,%sp@"); asm("jbsr GC_push_one");
311 asm("movl %d5,%sp@"); asm("jbsr GC_push_one");
312 asm("movl %d6,%sp@"); asm("jbsr GC_push_one");
313 asm("movl %d7,%sp@"); asm("jbsr GC_push_one");
315 asm("addqw #0x4,%sp"); /* put stack back where it was */
316 # else /* !__GNUC__*/
317 asm("subq.w &0x4,%sp"); /* allocate word on top of stack */
319 asm("mov.l %a2,(%sp)"); asm("jsr GC_push_one");
320 asm("mov.l %a3,(%sp)"); asm("jsr GC_push_one");
321 asm("mov.l %a4,(%sp)"); asm("jsr GC_push_one");
322 asm("mov.l %a5,(%sp)"); asm("jsr GC_push_one");
323 /* Skip frame pointer and stack pointer */
324 asm("mov.l %d1,(%sp)"); asm("jsr GC_push_one");
325 asm("mov.l %d2,(%sp)"); asm("jsr GC_push_one");
326 asm("mov.l %d3,(%sp)"); asm("jsr GC_push_one");
327 asm("mov.l %d4,(%sp)"); asm("jsr GC_push_one");
328 asm("mov.l %d5,(%sp)"); asm("jsr GC_push_one");
329 asm("mov.l %d6,(%sp)"); asm("jsr GC_push_one");
330 asm("mov.l %d7,(%sp)"); asm("jsr GC_push_one");
332 asm("addq.w &0x4,%sp"); /* put stack back where it was */
333 # endif /* !__GNUC__ */
334 # endif /* M68K/SYSV */
337 /* other machines... */
338 # if !(defined M68K) && !(defined VAX) && !(defined RT)
339 # if !(defined SPARC) && !(defined I386) && !(defined NS32K)
340 # if !defined(POWERPC) && !defined(UTS4)
346 #endif /* !USE_GENERIC_PUSH_REGS */
348 #if defined(USE_GENERIC_PUSH_REGS)
349 void GC_generic_push_regs(cold_gc_frame)
353 /* The idea is due to Parag Patel at HP. */
354 /* We're not sure whether he would like */
355 /* to be he acknowledged for it or not. */
358 register word * i = (word *) regs;
359 register ptr_t lim = (ptr_t)(regs) + (sizeof regs);
361 /* Setjmp on Sun 3s doesn't clear all of the buffer. */
362 /* That tends to preserve garbage. Clear it. */
363 for (; (char *)i < lim; i++) {
366 # if defined(POWERPC) || defined(MSWIN32) || defined(UTS4)
369 (void) _setjmp(regs);
371 GC_push_current_stack(cold_gc_frame);
374 #endif /* USE_GENERIC_PUSH_REGS */
376 /* On register window machines, we need a way to force registers into */
377 /* the stack. Return sp. */
379 asm(" .seg \"text\"");
381 asm(" .globl GC_save_regs_in_stack");
382 asm("GC_save_regs_in_stack:");
383 asm(" .type GC_save_regs_in_stack,#function");
385 asm(" .globl _GC_save_regs_in_stack");
386 asm("_GC_save_regs_in_stack:");
388 asm(" ta 0x3 ! ST_FLUSH_WINDOWS");
393 asm(" .GC_save_regs_in_stack_end:");
394 asm(" .size GC_save_regs_in_stack,.GC_save_regs_in_stack_end-GC_save_regs_in_stack");
397 word GC_save_regs_in_stack() { return(0 /* sp really */);}
402 /* GC_clear_stack_inner(arg, limit) clears stack area up to limit and */
403 /* returns arg. Stack clearing is crucial on SPARC, so we supply */
404 /* an assembly version that's more careful. Assumes limit is hotter */
405 /* than sp, and limit is 8 byte aligned. */
406 #if defined(ASM_CLEAR_CODE) && !defined(THREADS)
411 asm(".globl _GC_clear_stack_inner");
412 asm("_GC_clear_stack_inner:");
414 asm(".globl GC_clear_stack_inner");
415 asm("GC_clear_stack_inner:");
416 asm(".type GC_save_regs_in_stack,#function");
418 asm("mov %sp,%o2"); /* Save sp */
419 asm("add %sp,-8,%o3"); /* p = sp-8 */
420 asm("clr %g1"); /* [g0,g1] = 0 */
421 asm("add %o1,-0x60,%sp"); /* Move sp out of the way, */
422 /* so that traps still work. */
423 /* Includes some extra words */
424 /* so we can be sloppy below. */
426 asm("std %g0,[%o3]"); /* *(long long *)p = 0 */
428 asm("bgu loop "); /* if (p > limit) goto loop */
429 asm("add %o3,-8,%o3"); /* p -= 8 (delay slot) */
431 asm("mov %o2,%sp"); /* Restore sp., delay slot */
432 /* First argument = %o0 = return value */
434 asm(" .GC_clear_stack_inner_end:");
435 asm(" .size GC_clear_stack_inner,.GC_clear_stack_inner_end-GC_clear_stack_inner");
440 ptr_t GC_clear_stack_inner(arg, limit)
441 ptr_t arg; word limit;