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 #if defined(__MWERKS__) && !defined(POWERPC)
28 asm static void PushMacRegisters()
30 sub
.w
#4,sp // reserve space for one parameter.
37 # if !__option(a6frames)
38 // <pcb> perhaps a6 should be pushed if stack frames are not being used.
42 // skip a5 (globals), a6 (frame pointer), and a7 (stack pointer)
55 add
.w
#4,sp // fix stack.
59 #endif /* __MWERKS__ */
61 /* Routine to mark from registers that are preserved by the C compiler. */
62 /* This must be ported to every new architecture. There is a generic */
63 /* version at the end, that is likely, but not guaranteed to work */
64 /* on your architecture. Run the test_setjmp program to see whether */
65 /* there is any chance it will work. */
70 register long TMP_SP
; /* must be bound to r11 */
73 /* VAX - generic code below does not work under 4.2 */
74 /* r1 through r5 are caller save, and therefore */
75 /* on the stack or dead. */
76 asm("pushl r11"); asm("calls $1,_GC_push_one");
77 asm("pushl r10"); asm("calls $1,_GC_push_one");
78 asm("pushl r9"); asm("calls $1,_GC_push_one");
79 asm("pushl r8"); asm("calls $1,_GC_push_one");
80 asm("pushl r7"); asm("calls $1,_GC_push_one");
81 asm("pushl r6"); asm("calls $1,_GC_push_one");
83 # if defined(M68K) && (defined(SUNOS4) || defined(NEXT))
84 /* M68K SUNOS - could be replaced by generic code */
85 /* a0, a1 and d1 are caller save */
86 /* and therefore are on stack or dead. */
88 asm("subqw #0x4,sp"); /* allocate word on top of stack */
90 asm("movl a2,sp@"); asm("jbsr _GC_push_one");
91 asm("movl a3,sp@"); asm("jbsr _GC_push_one");
92 asm("movl a4,sp@"); asm("jbsr _GC_push_one");
93 asm("movl a5,sp@"); asm("jbsr _GC_push_one");
94 /* Skip frame pointer and stack pointer */
95 asm("movl d1,sp@"); asm("jbsr _GC_push_one");
96 asm("movl d2,sp@"); asm("jbsr _GC_push_one");
97 asm("movl d3,sp@"); asm("jbsr _GC_push_one");
98 asm("movl d4,sp@"); asm("jbsr _GC_push_one");
99 asm("movl d5,sp@"); asm("jbsr _GC_push_one");
100 asm("movl d6,sp@"); asm("jbsr _GC_push_one");
101 asm("movl d7,sp@"); asm("jbsr _GC_push_one");
103 asm("addqw #0x4,sp"); /* put stack back where it was */
106 # if defined(M68K) && defined(HP)
107 /* M68K HP - could be replaced by generic code */
108 /* a0, a1 and d1 are caller save. */
110 asm("subq.w &0x4,%sp"); /* allocate word on top of stack */
112 asm("mov.l %a2,(%sp)"); asm("jsr _GC_push_one");
113 asm("mov.l %a3,(%sp)"); asm("jsr _GC_push_one");
114 asm("mov.l %a4,(%sp)"); asm("jsr _GC_push_one");
115 asm("mov.l %a5,(%sp)"); asm("jsr _GC_push_one");
116 /* Skip frame pointer and stack pointer */
117 asm("mov.l %d1,(%sp)"); asm("jsr _GC_push_one");
118 asm("mov.l %d2,(%sp)"); asm("jsr _GC_push_one");
119 asm("mov.l %d3,(%sp)"); asm("jsr _GC_push_one");
120 asm("mov.l %d4,(%sp)"); asm("jsr _GC_push_one");
121 asm("mov.l %d5,(%sp)"); asm("jsr _GC_push_one");
122 asm("mov.l %d6,(%sp)"); asm("jsr _GC_push_one");
123 asm("mov.l %d7,(%sp)"); asm("jsr _GC_push_one");
125 asm("addq.w &0x4,%sp"); /* put stack back where it was */
126 # endif /* M68K HP */
129 /* AMIGA - could be replaced by generic code */
130 /* a0, a1, d0 and d1 are caller save */
131 GC_push_one(getreg(REG_A2
));
132 GC_push_one(getreg(REG_A3
));
133 GC_push_one(getreg(REG_A4
));
134 GC_push_one(getreg(REG_A5
));
135 GC_push_one(getreg(REG_A6
));
136 /* Skip stack pointer */
137 GC_push_one(getreg(REG_D2
));
138 GC_push_one(getreg(REG_D3
));
139 GC_push_one(getreg(REG_D4
));
140 GC_push_one(getreg(REG_D5
));
141 GC_push_one(getreg(REG_D6
));
142 GC_push_one(getreg(REG_D7
));
145 # if defined(M68K) && defined(MACOS)
146 # if defined(THINK_C)
147 # define PushMacReg(reg) \
151 sub
.w
#4,sp ; reserve space for one parameter.
155 ; skip
a5 (globals
), a6 (frame pointer
), and a7 (stack pointer
)
162 add
.w
#4,sp ; fix stack.
165 # endif /* THINK_C */
166 # if defined(__MWERKS__)
168 # endif /* __MWERKS__ */
171 # if defined(I386) &&!defined(OS2) &&!defined(SVR4) &&!defined(MSWIN32) \
172 && !defined(SCO) && !defined(SCO_ELF) && !(defined(LINUX) \
173 && defined(__ELF__)) && !defined(DOS4GW)
174 /* I386 code, generic code does not appear to work */
175 /* It does appear to work under OS2, and asms dont */
176 /* This is used for some 38g UNIX variants and for CYGWIN32 */
177 asm("pushl %eax"); asm("call _GC_push_one"); asm("addl $4,%esp");
178 asm("pushl %ecx"); asm("call _GC_push_one"); asm("addl $4,%esp");
179 asm("pushl %edx"); asm("call _GC_push_one"); asm("addl $4,%esp");
180 asm("pushl %ebp"); asm("call _GC_push_one"); asm("addl $4,%esp");
181 asm("pushl %esi"); asm("call _GC_push_one"); asm("addl $4,%esp");
182 asm("pushl %edi"); asm("call _GC_push_one"); asm("addl $4,%esp");
183 asm("pushl %ebx"); asm("call _GC_push_one"); asm("addl $4,%esp");
186 # if defined(I386) && defined(LINUX) && defined(__ELF__)
187 /* This is modified for Linux with ELF (Note: _ELF_ only) */
188 asm("pushl %eax"); asm("call GC_push_one"); asm("addl $4,%esp");
189 asm("pushl %ecx"); asm("call GC_push_one"); asm("addl $4,%esp");
190 asm("pushl %edx"); asm("call GC_push_one"); asm("addl $4,%esp");
191 asm("pushl %ebp"); asm("call GC_push_one"); asm("addl $4,%esp");
192 asm("pushl %esi"); asm("call GC_push_one"); asm("addl $4,%esp");
193 asm("pushl %edi"); asm("call GC_push_one"); asm("addl $4,%esp");
194 asm("pushl %ebx"); asm("call GC_push_one"); asm("addl $4,%esp");
197 # if defined(I386) && defined(MSWIN32) && !defined(USE_GENERIC)
198 /* I386 code, Microsoft variant */
200 __asm call GC_push_one
203 __asm call GC_push_one
206 __asm call GC_push_one
209 __asm call GC_push_one
212 __asm call GC_push_one
215 __asm call GC_push_one
218 __asm call GC_push_one
222 # if defined(I386) && (defined(SVR4) || defined(SCO) || defined(SCO_ELF))
223 /* I386 code, SVR4 variant, generic code does not appear to work */
224 asm("pushl %eax"); asm("call GC_push_one"); asm("addl $4,%esp");
225 asm("pushl %ebx"); asm("call GC_push_one"); asm("addl $4,%esp");
226 asm("pushl %ecx"); asm("call GC_push_one"); asm("addl $4,%esp");
227 asm("pushl %edx"); asm("call GC_push_one"); asm("addl $4,%esp");
228 asm("pushl %ebp"); asm("call GC_push_one"); asm("addl $4,%esp");
229 asm("pushl %esi"); asm("call GC_push_one"); asm("addl $4,%esp");
230 asm("pushl %edi"); asm("call GC_push_one"); asm("addl $4,%esp");
234 asm ("movd r3, tos"); asm ("bsr ?_GC_push_one"); asm ("adjspb $-4");
235 asm ("movd r4, tos"); asm ("bsr ?_GC_push_one"); asm ("adjspb $-4");
236 asm ("movd r5, tos"); asm ("bsr ?_GC_push_one"); asm ("adjspb $-4");
237 asm ("movd r6, tos"); asm ("bsr ?_GC_push_one"); asm ("adjspb $-4");
238 asm ("movd r7, tos"); asm ("bsr ?_GC_push_one"); asm ("adjspb $-4");
243 word
GC_save_regs_in_stack();
245 /* generic code will not work */
246 (void)GC_save_regs_in_stack();
251 GC_push_one(TMP_SP
); /* GC_push_one from r11 */
253 asm("cas r11, r6, r0"); GC_push_one(TMP_SP
); /* r6 */
254 asm("cas r11, r7, r0"); GC_push_one(TMP_SP
); /* through */
255 asm("cas r11, r8, r0"); GC_push_one(TMP_SP
); /* r10 */
256 asm("cas r11, r9, r0"); GC_push_one(TMP_SP
);
257 asm("cas r11, r10, r0"); GC_push_one(TMP_SP
);
259 asm("cas r11, r12, r0"); GC_push_one(TMP_SP
); /* r12 */
260 asm("cas r11, r13, r0"); GC_push_one(TMP_SP
); /* through */
261 asm("cas r11, r14, r0"); GC_push_one(TMP_SP
); /* r15 */
262 asm("cas r11, r15, r0"); GC_push_one(TMP_SP
);
265 # if defined(M68K) && defined(SYSV)
266 /* Once again similar to SUN and HP, though setjmp appears to work.
270 asm("subqw #0x4,%sp"); /* allocate word on top of stack */
272 asm("movl %a2,%sp@"); asm("jbsr GC_push_one");
273 asm("movl %a3,%sp@"); asm("jbsr GC_push_one");
274 asm("movl %a4,%sp@"); asm("jbsr GC_push_one");
275 asm("movl %a5,%sp@"); asm("jbsr GC_push_one");
276 /* Skip frame pointer and stack pointer */
277 asm("movl %d1,%sp@"); asm("jbsr GC_push_one");
278 asm("movl %d2,%sp@"); asm("jbsr GC_push_one");
279 asm("movl %d3,%sp@"); asm("jbsr GC_push_one");
280 asm("movl %d4,%sp@"); asm("jbsr GC_push_one");
281 asm("movl %d5,%sp@"); asm("jbsr GC_push_one");
282 asm("movl %d6,%sp@"); asm("jbsr GC_push_one");
283 asm("movl %d7,%sp@"); asm("jbsr GC_push_one");
285 asm("addqw #0x4,%sp"); /* put stack back where it was */
286 # else /* !__GNUC__*/
287 asm("subq.w &0x4,%sp"); /* allocate word on top of stack */
289 asm("mov.l %a2,(%sp)"); asm("jsr GC_push_one");
290 asm("mov.l %a3,(%sp)"); asm("jsr GC_push_one");
291 asm("mov.l %a4,(%sp)"); asm("jsr GC_push_one");
292 asm("mov.l %a5,(%sp)"); asm("jsr GC_push_one");
293 /* Skip frame pointer and stack pointer */
294 asm("mov.l %d1,(%sp)"); asm("jsr GC_push_one");
295 asm("mov.l %d2,(%sp)"); asm("jsr GC_push_one");
296 asm("mov.l %d3,(%sp)"); asm("jsr GC_push_one");
297 asm("mov.l %d4,(%sp)"); asm("jsr GC_push_one");
298 asm("mov.l %d5,(%sp)"); asm("jsr GC_push_one");
299 asm("mov.l %d6,(%sp)"); asm("jsr GC_push_one");
300 asm("mov.l %d7,(%sp)"); asm("jsr GC_push_one");
302 asm("addq.w &0x4,%sp"); /* put stack back where it was */
303 # endif /* !__GNUC__ */
304 # endif /* M68K/SYSV */
307 # if defined(HP_PA) || defined(M88K) || defined(POWERPC) || (defined(I386) && (defined(OS2) || defined(USE_GENERIC))) || defined(UTS4)
309 /* The idea is due to Parag Patel at HP. */
310 /* We're not sure whether he would like */
311 /* to be he acknowledged for it or not. */
314 register word
* i
= (word
*) regs
;
315 register ptr_t lim
= (ptr_t
)(regs
) + (sizeof regs
);
317 /* Setjmp on Sun 3s doesn't clear all of the buffer. */
318 /* That tends to preserve garbage. Clear it. */
319 for (; (char *)i
< lim
; i
++) {
322 # if defined(POWERPC) || defined(MSWIN32) || defined(UTS4)
325 (void) _setjmp(regs
);
327 GC_push_all_stack((ptr_t
)regs
, lim
);
331 /* other machines... */
332 # if !(defined M68K) && !(defined VAX) && !(defined RT)
333 # if !(defined SPARC) && !(defined I386) && !(defined NS32K)
334 # if !defined(HP_PA) && !defined(M88K) && !defined(POWERPC)
343 /* On register window machines, we need a way to force registers into */
344 /* the stack. Return sp. */
346 asm(" .seg \"text\"");
348 asm(" .globl GC_save_regs_in_stack");
349 asm("GC_save_regs_in_stack:");
350 asm(" .type GC_save_regs_in_stack,#function");
352 asm(" .globl _GC_save_regs_in_stack");
353 asm("_GC_save_regs_in_stack:");
355 asm(" ta 0x3 ! ST_FLUSH_WINDOWS");
360 asm(" .GC_save_regs_in_stack_end:");
361 asm(" .size GC_save_regs_in_stack,.GC_save_regs_in_stack_end-GC_save_regs_in_stack");
364 word
GC_save_regs_in_stack() { return(0 /* sp really */);}
369 /* GC_clear_stack_inner(arg, limit) clears stack area up to limit and */
370 /* returns arg. Stack clearing is crucial on SPARC, so we supply */
371 /* an assembly version that's more careful. Assumes limit is hotter */
372 /* than sp, and limit is 8 byte aligned. */
373 #if defined(ASM_CLEAR_CODE) && !defined(THREADS)
378 asm(".globl _GC_clear_stack_inner");
379 asm("_GC_clear_stack_inner:");
381 asm(".globl GC_clear_stack_inner");
382 asm("GC_clear_stack_inner:");
383 asm(".type GC_save_regs_in_stack,#function");
385 asm("mov %sp,%o2"); /* Save sp */
386 asm("add %sp,-8,%o3"); /* p = sp-8 */
387 asm("clr %g1"); /* [g0,g1] = 0 */
388 asm("add %o1,-0x60,%sp"); /* Move sp out of the way, */
389 /* so that traps still work. */
390 /* Includes some extra words */
391 /* so we can be sloppy below. */
393 asm("std %g0,[%o3]"); /* *(long long *)p = 0 */
395 asm("bgu loop "); /* if (p > limit) goto loop */
396 asm("add %o3,-8,%o3"); /* p -= 8 (delay slot) */
398 asm("mov %o2,%sp"); /* Restore sp., delay slot */
399 /* First argument = %o0 = return value */
401 asm(" .GC_clear_stack_inner_end:");
402 asm(" .size GC_clear_stack_inner,.GC_clear_stack_inner_end-GC_clear_stack_inner");
407 ptr_t
GC_clear_stack_inner(arg
, limit
)
408 ptr_t arg
; word limit
;