Merged revisions 8245-8298 via svnmerge from
[cacao.git] / src / vm / jit / m68k / md.c
index 4214fad1b1668b5f78a1350a0ad268ec49c6dab0..2d28f43d656c74698f310f7073442bb8904b600d 100644 (file)
  */
 void md_init(void) 
 {
-       assert(sizeof(vm_arg) == sizevmarg);
-       assert(OFFSET(java_objectheader, vftbl) == offobjvftbl);
        assert(OFFSET(vftbl_t, baseval) == offbaseval);
        assert(OFFSET(vftbl_t, diffval) == offdiffval);
-       assert(OFFSET(vm_arg, type) == offvmargtype);
-       assert(OFFSET(vm_arg, data) == offvmargdata);
        assert(OFFSET(castinfo, super_baseval) == offcast_super_baseval);
        assert(OFFSET(castinfo, super_diffval) == offcast_super_diffval);
        assert(OFFSET(castinfo, sub_baseval) == offcast_sub_baseval);
 
+#if 0
 #if defined(ENABLE_REPLACEMENT)
        assert(sizeof(executionstate_t) = sizeexecutionstate);
        assert(OFFSET(executionstate_t, pc) == offes_pc);
@@ -70,6 +67,7 @@ void md_init(void)
        assert(OFFSET(executionstate_t, intregs) == offes_intregs);
        assert(OFFSET(executionstate_t, fltregs) == offes_fltregs);
 #endif
+#endif
 
 #ifdef __LINUX__
        md_init_linux();
@@ -119,20 +117,28 @@ u1* md_get_method_patch_address(u1 *ra, stackframeinfo *sfi, u1 *mptr)
        s2   offset;
 
        if (*((u2*)(ra - 2)) == 0x4e94) {               /* jsr %a4@ */
-               /* we had a moveal XXX, %a3 which is a 3 word opcode */
-               /* 2679 0000 0000 */
-               assert(*(u2*)(ra - 8) == 0x2879);               /* moveal */
-               pa = *((u4*)(ra - 6));                          /* another indirection ! */
-       } else if (*((u2*)(ra - 2)) == 0x4e92)  {               /* jsr %a2@ */
-               if (*(u2*)(ra - 8) == 0x247c)   {
-                       /* found a invokestatic/invokespecial */
-                       pa = ((u4*)(ra - 6));                   /* no indirection ! */
-               } else if (*((u2*)(ra - 6)) == 0x246b)  {
+               if (*((u2*)(ra - 6)) == 0x286b) {
                        /* found an invokevirtual */
                        /* get offset of load instruction 246b XXXX */
                        offset = *((s2*)(ra - 4));
+
+                       /* return NULL if no mptr was specified (used for replacement) */
+
+                       if (mptr == NULL)
+                               return NULL;
+
                        pa = mptr + offset;                     /* mptr contains the magic we want */
                } else  {
+                       /* we had a moveal XXX, %a3 which is a 3 word opcode */
+                       /* 2679 0000 0000 */
+                       assert(*(u2*)(ra - 8) == 0x2879);               /* moveal */
+                       pa = *((u4*)(ra - 6));                          /* another indirection ! */
+               }
+       } else if (*((u2*)(ra - 2)) == 0x4e92)  {               /* jsr %a2@ */
+               if (*(u2*)(ra - 8) == 0x247c)   {
+                       /* found a invokestatic/invokespecial */
+                       pa = ((u4*)(ra - 6));                   /* no indirection ! */
+               } else {
                        assert(0);
                }
        } else {
@@ -211,8 +217,39 @@ u1* md_stacktrace_get_returnaddress(u1* sp, u4 framesize)
 { 
        /* return address is above stackpointer */
        u1 *ra = *((u1**)(sp + framesize));
+       
+       /* XXX: This helps for now, but it's a ugly hack
+        * the problem _may_ be: the link instruction is used
+        * by some gcc generated code, and we get an additional word
+        * on the stack, the old framepointer. Its address is somewhere
+        * near sp, but that all depends the code generated by the compiler.
+        * I'm unsure about a clean solution.
+        */
+       #if 0
+       if (!(ra > 0x40000000 && ra < 0x80000000))      {
+               ra = *((u1**)(sp + framesize + 4));
+       }
+       #endif
+       /* assert(ra > 0x40000000 && ra < 0x80000000);
+       printf("XXXXXX=%x\n", ra);
+        */
        return ra;
 }
 
 
 void md_codegen_patch_branch(void) { assert(0); }
+
+
+/*
+ * These are local overrides for various environment variables in Emacs.
+ * Please do not remove this and leave it at the end of the file, where
+ * Emacs will automagically detect them.
+ * ---------------------------------------------------------------------
+ * Local variables:
+ * mode: c
+ * indent-tabs-mode: t
+ * c-basic-offset: 4
+ * tab-width: 4
+ * End:
+ * vim:noexpandtab:sw=4:ts=4:
+ */