C:/Users/Dennis/src/lang/russell.orig/src/gc/mach_dep.c

Go to the documentation of this file.
00001 # include "gc_private.h"
00002 # include <stdio.h>
00003 # include <setjmp.h>
00004 # ifdef OS2
00005 #   define _setjmp(b) setjmp(b)
00006 #   define _longjmp(b,v) longjmp(b,v)
00007 # endif
00008 
00009 /* Routine to mark from registers that are preserved by the C compiler. */
00010 /* This must be ported to every new architecture.  There is a generic   */
00011 /* version at the end, that is likely, but not guaranteed to work       */
00012 /* on your architecture.  Run the test_setjmp program to see whether    */
00013 /* there is any chance it will work.                                    */
00014 GC_mark_regs()
00015 {
00016 #       ifdef RT
00017           register long TMP_SP; /* must be bound to r11 */
00018 #       endif
00019 #       ifdef VAX
00020         /* VAX - generic code below does not work under 4.2 */
00021           /* r1 through r5 are caller save, and therefore     */
00022           /* on the stack or dead.                            */
00023           asm("pushl r11");     asm("calls $1,_GC_tl_mark");
00024           asm("pushl r10");     asm("calls $1,_GC_tl_mark");
00025           asm("pushl r9");      asm("calls $1,_GC_tl_mark");
00026           asm("pushl r8");      asm("calls $1,_GC_tl_mark");
00027           asm("pushl r7");      asm("calls $1,_GC_tl_mark");
00028           asm("pushl r6");      asm("calls $1,_GC_tl_mark");
00029 #       endif
00030 #       if defined(M68K) && defined(SUNOS)
00031         /*  M68K SUNOS - could be replaced by generic code */
00032           /* a0, a1 and d1 are caller save          */
00033           /*  and therefore are on stack or dead.   */
00034         
00035           asm("subqw #0x4,sp");         /* allocate word on top of stack */
00036 
00037           asm("movl a2,sp@");   asm("jbsr _GC_tl_mark");
00038           asm("movl a3,sp@");   asm("jbsr _GC_tl_mark");
00039           asm("movl a4,sp@");   asm("jbsr _GC_tl_mark");
00040           asm("movl a5,sp@");   asm("jbsr _GC_tl_mark");
00041           /* Skip frame pointer and stack pointer */
00042           asm("movl d1,sp@");   asm("jbsr _GC_tl_mark");
00043           asm("movl d2,sp@");   asm("jbsr _GC_tl_mark");
00044           asm("movl d3,sp@");   asm("jbsr _GC_tl_mark");
00045           asm("movl d4,sp@");   asm("jbsr _GC_tl_mark");
00046           asm("movl d5,sp@");   asm("jbsr _GC_tl_mark");
00047           asm("movl d6,sp@");   asm("jbsr _GC_tl_mark");
00048           asm("movl d7,sp@");   asm("jbsr _GC_tl_mark");
00049 
00050           asm("addqw #0x4,sp");         /* put stack back where it was  */
00051 #       endif
00052 
00053 #       if defined(M68K) && defined(HP)
00054         /*  M68K HP - could be replaced by generic code */
00055           /* a0, a1 and d1 are caller save.  */
00056         
00057           asm("subq.w &0x4,%sp");       /* allocate word on top of stack */
00058 
00059           asm("mov.l %a2,(%sp)"); asm("jsr _GC_tl_mark");
00060           asm("mov.l %a3,(%sp)"); asm("jsr _GC_tl_mark");
00061           asm("mov.l %a4,(%sp)"); asm("jsr _GC_tl_mark");
00062           asm("mov.l %a5,(%sp)"); asm("jsr _GC_tl_mark");
00063           /* Skip frame pointer and stack pointer */
00064           asm("mov.l %d1,(%sp)"); asm("jsr _GC_tl_mark");
00065           asm("mov.l %d2,(%sp)"); asm("jsr _GC_tl_mark");
00066           asm("mov.l %d3,(%sp)"); asm("jsr _GC_tl_mark");
00067           asm("mov.l %d4,(%sp)"); asm("jsr _GC_tl_mark");
00068           asm("mov.l %d5,(%sp)"); asm("jsr _GC_tl_mark");
00069           asm("mov.l %d6,(%sp)"); asm("jsr _GC_tl_mark");
00070           asm("mov.l %d7,(%sp)"); asm("jsr _GC_tl_mark");
00071 
00072           asm("addq.w &0x4,%sp");       /* put stack back where it was  */
00073 #       endif /* M68K HP */
00074 
00075 #       if defined(I386) && !defined(OS2) && !defined(SUNOS5)
00076         /* I386 code, generic code does not appear to work */
00077         /* It does appear to work under OS2, and asms dont */
00078           asm("pushl %eax");  asm("call _GC_tl_mark"); asm("addl $4,%esp");
00079           asm("pushl %ecx");  asm("call _GC_tl_mark"); asm("addl $4,%esp");
00080           asm("pushl %edx");  asm("call _GC_tl_mark"); asm("addl $4,%esp");
00081           asm("pushl %esi");  asm("call _GC_tl_mark"); asm("addl $4,%esp");
00082           asm("pushl %edi");  asm("call _GC_tl_mark"); asm("addl $4,%esp");
00083           asm("pushl %ebx");  asm("call _GC_tl_mark"); asm("addl $4,%esp");
00084 #       endif
00085 
00086 #       if defined(I386) && defined(SUNOS5)
00087         /* I386 code, generic code does not appear to work */
00088         /* It does appear to work under OS2, and asms dont */
00089           asm("pushl %eax");  asm("call GC_tl_mark"); asm("addl $4,%esp");
00090           asm("pushl %ecx");  asm("call GC_tl_mark"); asm("addl $4,%esp");
00091           asm("pushl %edx");  asm("call GC_tl_mark"); asm("addl $4,%esp");
00092           asm("pushl %esi");  asm("call GC_tl_mark"); asm("addl $4,%esp");
00093           asm("pushl %edi");  asm("call GC_tl_mark"); asm("addl $4,%esp");
00094           asm("pushl %ebx");  asm("call GC_tl_mark"); asm("addl $4,%esp");
00095 #       endif
00096 
00097 #       ifdef NS32K
00098           asm ("movd r3, tos"); asm ("bsr ?_GC_tl_mark"); asm ("adjspb $-4");
00099           asm ("movd r4, tos"); asm ("bsr ?_GC_tl_mark"); asm ("adjspb $-4");
00100           asm ("movd r5, tos"); asm ("bsr ?_GC_tl_mark"); asm ("adjspb $-4");
00101           asm ("movd r6, tos"); asm ("bsr ?_GC_tl_mark"); asm ("adjspb $-4");
00102           asm ("movd r7, tos"); asm ("bsr ?_GC_tl_mark"); asm ("adjspb $-4");
00103 #       endif
00104 
00105 #       ifdef SPARC
00106           /* generic code will not work */
00107           GC_save_regs_in_stack();
00108 #       endif
00109 
00110 #       ifdef RT
00111             GC_tl_mark(TMP_SP);    /* GC_tl_mark from r11 */
00112 
00113             asm("cas r11, r6, r0"); GC_tl_mark(TMP_SP); /* r6 */
00114             asm("cas r11, r7, r0"); GC_tl_mark(TMP_SP); /* through */
00115             asm("cas r11, r8, r0"); GC_tl_mark(TMP_SP); /* r10 */
00116             asm("cas r11, r9, r0"); GC_tl_mark(TMP_SP);
00117             asm("cas r11, r10, r0"); GC_tl_mark(TMP_SP);
00118 
00119             asm("cas r11, r12, r0"); GC_tl_mark(TMP_SP); /* r12 */
00120             asm("cas r11, r13, r0"); GC_tl_mark(TMP_SP); /* through */
00121             asm("cas r11, r14, r0"); GC_tl_mark(TMP_SP); /* r15 */
00122             asm("cas r11, r15, r0"); GC_tl_mark(TMP_SP);
00123 #       endif
00124 
00125 #       if defined(M68K) && defined(SYSV)
00126         /*  Once again similar to SUN and HP, though setjmp appears to work.
00127                 --Parag
00128          */
00129 #        ifdef __GNUC__
00130           asm("subqw #0x4,%sp");        /* allocate word on top of stack */
00131   
00132           asm("movl %a2,%sp@"); asm("jbsr GC_tl_mark");
00133           asm("movl %a3,%sp@"); asm("jbsr GC_tl_mark");
00134           asm("movl %a4,%sp@"); asm("jbsr GC_tl_mark");
00135           asm("movl %a5,%sp@"); asm("jbsr GC_tl_mark");
00136           /* Skip frame pointer and stack pointer */
00137           asm("movl %d1,%sp@"); asm("jbsr GC_tl_mark");
00138           asm("movl %d2,%sp@"); asm("jbsr GC_tl_mark");
00139           asm("movl %d3,%sp@"); asm("jbsr GC_tl_mark");
00140           asm("movl %d4,%sp@"); asm("jbsr GC_tl_mark");
00141           asm("movl %d5,%sp@"); asm("jbsr GC_tl_mark");
00142           asm("movl %d6,%sp@"); asm("jbsr GC_tl_mark");
00143           asm("movl %d7,%sp@"); asm("jbsr GC_tl_mark");
00144   
00145           asm("addqw #0x4,%sp");        /* put stack back where it was  */
00146 #        else /* !__GNUC__*/
00147           asm("subq.w &0x4,%sp");       /* allocate word on top of stack */
00148   
00149           asm("mov.l %a2,(%sp)"); asm("jsr GC_tl_mark");
00150           asm("mov.l %a3,(%sp)"); asm("jsr GC_tl_mark");
00151           asm("mov.l %a4,(%sp)"); asm("jsr GC_tl_mark");
00152           asm("mov.l %a5,(%sp)"); asm("jsr GC_tl_mark");
00153           /* Skip frame pointer and stack pointer */
00154           asm("mov.l %d1,(%sp)"); asm("jsr GC_tl_mark");
00155           asm("mov.l %d2,(%sp)"); asm("jsr GC_tl_mark");
00156           asm("mov.l %d3,(%sp)"); asm("jsr GC_tl_mark");
00157           asm("mov.l %d4,(%sp)"); asm("jsr GC_tl_mark");
00158           asm("mov.l %d5,(%sp)"); asm("jsr GC_tl_mark");
00159           asm("mov.l %d6,(%sp)"); asm("jsr GC_tl_mark");
00160           asm("mov.l %d7,(%sp)"); asm("jsr GC_tl_mark");
00161   
00162           asm("addq.w &0x4,%sp");       /* put stack back where it was  */
00163 #        endif /* !__GNUC__ */
00164 #       endif /* M68K/SYSV */
00165 
00166 
00167 #     if defined(HP_PA) || (defined(I386) && defined(OS2))
00168         /* Generic code                          */
00169         /* The idea is due to Parag Patel at HP. */
00170         /* We're not sure whether he would like  */
00171         /* to be he acknowledged for it or not.  */
00172         {
00173             jmp_buf regs;
00174             register word * i = (word *) regs;
00175             register ptr_t lim = (ptr_t)(regs) + (sizeof regs);
00176 
00177             /* Setjmp on Sun 3s doesn't clear all of the buffer.  */
00178             /* That tends to preserve garbage.  Clear it.         */
00179                 for (; (char *)i < lim; i++) {
00180                     *i = 0;
00181                 }
00182             (void) _setjmp(regs);
00183             GC_mark_all_stack((ptr_t)regs, lim);
00184         }
00185 #     endif
00186 
00187       /* other machines... */
00188 #       if !(defined M68K) && !(defined VAX) && !(defined RT) 
00189 #       if !(defined SPARC) && !(defined I386) &&!(defined NS32K)
00190 #       if !defined(HP_PA)
00191             --> bad news <--
00192 #       endif
00193 #       endif
00194 #       endif
00195 }
00196 
00197 /* On register window machines, we need a way to force registers into   */
00198 /* the stack.                                                           */
00199 # ifdef SPARC
00200 #   ifdef SUNOS5
00201       asm("     .globl  GC_save_regs_in_stack");
00202       asm("GC_save_regs_in_stack:");
00203 #   else
00204       asm("     .globl  _GC_save_regs_in_stack");
00205       asm("_GC_save_regs_in_stack:");
00206 #   endif
00207     asm("       ta      0x3   ! ST_FLUSH_WINDOWS");
00208     asm("       mov     %sp,%o0");
00209     asm("       retl");
00210     asm("       nop");
00211 # endif
00212 

Generated on Fri Jan 25 10:39:45 2008 for russell by  doxygen 1.5.4