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