* src/vm/jit/arm/codegen.c (codegen_emit): Allow larger displacements for
authorMichael Starzinger <michi@complang.tuwien.ac.at>
Thu, 13 Nov 2008 09:37:44 +0000 (10:37 +0100)
committerMichael Starzinger <michi@complang.tuwien.ac.at>
Thu, 13 Nov 2008 09:37:44 +0000 (10:37 +0100)
resolved case of ICMD_INVOKEINTERFACE.
* src/vm/jit/arm/codegen.h (M_MEM_GET_Rd, M_MEM_GET_Rbase): Added newmacros.
* src/vm/jit/arm/md.c (md_jit_method_patch_address): Adapted to above changes.

src/vm/jit/arm/codegen.c
src/vm/jit/arm/codegen.h
src/vm/jit/arm/md.c

index bc8c777a37e01748f1d75f37b0e6cde234a72717..b78fdd2cfbb7048d5a861de167a38bc834a47c19 100644 (file)
@@ -2352,8 +2352,7 @@ bool codegen_emit(jitdata *jd)
                                        // The following instruction MUST NOT change a0 because of the implicit NPE check.
                                        M_LDR_INTERN(REG_METHODPTR, REG_A0, OFFSET(java_object_t, vftbl));
                                        M_LDR(REG_METHODPTR, REG_METHODPTR, s1);
-                                       // XXX The offset s2 will exceed the boundry soon. Fix me!
-                                       M_LDR_INTERN(REG_PV, REG_METHODPTR, s2);
+                                       M_LDR(REG_PV, REG_METHODPTR, s2);
                                }
 
                                // Generate the actual call.
index fafeb6c038e4f6b517beb0ee7650e71e872073aa..1a45898e86cec5442e37000df0f533bf6e920113 100644 (file)
@@ -186,6 +186,9 @@ void asm_debug_intern(int a1, int a2, int a3, int a4);
         cd->mcodeptr += 4; \
     } while (0)
 
+#define M_MEM_GET_Rd(mcode)    (((mcode) >> 12) & 0x0f)
+#define M_MEM_GET_Rbase(mcode) (((mcode) >> 16) & 0x0f)
+
 
 /* load and store instruction: M_MEM2
    cond ... conditional execution
index b150f1a14831499f59267ff14222b67708e1627d..30df98d484ba893b04a6925ec15d4c3b7ff2de6b 100644 (file)
@@ -28,6 +28,7 @@
 #include <assert.h>
 #include <stdint.h>
 
+#include "vm/jit/arm/codegen.h"
 #include "vm/jit/arm/md.h"
 #include "vm/jit/arm/md-abi.h"
 
@@ -59,10 +60,18 @@ void md_init(void)
    or
 
    e590b000    ldr   fp, [r0]
-   e59bc000    ldr   ip, [fp]
+   e59bc004    ldr   ip, [fp, #4]
    e1a0e00f    mov   lr, pc
    e1a0f00c    mov   pc, ip
 
+   or
+
+   e590b000    ldr     fp, [r0]
+   e28bca01    add     ip, fp, #4096   ; 0x1000
+   e59cc004    ldr     ip, [ip, #4]
+   e1a0e00f    mov     lr, pc
+   e1a0f00c    mov     pc, ip
+
    How we find out the patching address to store new method pointer:
     - loaded IP with LDR IP,[METHODPTR]?
         yes=INVOKEVIRTUAL or INVOKEINTERFACE (things are easy!)
@@ -76,7 +85,7 @@ void *md_jit_method_patch_address(void *pv, void *ra, void *mptr)
 {
        uint32_t *pc;
        uint32_t  mcode;
-       int32_t   offset;
+       int32_t   disp;
        void     *pa;                       /* patch address                      */
 
        /* Go back to the actual load instruction. */
@@ -87,22 +96,39 @@ void *md_jit_method_patch_address(void *pv, void *ra, void *mptr)
 
        mcode = pc[0];
 
-       /* sanity check: are we inside jit code? */
+       /* Sanity check: Are we inside jit code? */
 
        assert(pc[1] == 0xe1a0e00f /*MOV LR,PC*/);
        assert(pc[2] == 0xe1a0f00c /*MOV PC,IP*/);
 
-       /* get the load instruction and offset */
-
-       offset = (int32_t) (mcode & 0x0fff);
+       /* Sanity check: We unconditionally loaded a word into REG_PV? */
 
        assert ((mcode & 0xff70f000) == 0xe510c000);
 
-       if ((mcode & 0x000f0000) == 0x000b0000) {
-               /* sanity check: offset was positive */
+       /* Get load displacement. */
+
+       disp = (int32_t) (mcode & 0x0fff);
+
+       /* Case: We loaded from base REG_PV with negative displacement. */
+
+       if (M_MEM_GET_Rbase(mcode) == REG_PV && (mcode & 0x00800000) == 0) {
+               /* We loaded from data segment, displacement can be larger. */
+
+               mcode = pc[-1];
+
+               /* check for "SUB IP, IP, #??, ROTL 12" */
+
+               if ((mcode & 0xffffff00) == 0xe24cca00)
+                       disp += (int32_t) ((mcode & 0x00ff) << 12);
+
+               /* and get the final data segment address */
+
+               pa = ((uint8_t *) pv) - disp;
+       }
 
-               assert((mcode & 0x00800000) == 0x00800000);
+       /* Case: We loaded from base REG_METHODPTR with positive displacement. */
 
+       else if (M_MEM_GET_Rbase(mcode) == REG_METHODPTR && (mcode & 0x00800000) == 0x00800000) {
                /* return NULL if no mptr was specified (used for replacement) */
 
                if (mptr == NULL)
@@ -110,26 +136,36 @@ void *md_jit_method_patch_address(void *pv, void *ra, void *mptr)
 
                /* we loaded from REG_METHODPTR */
 
-               pa = ((uint8_t *) mptr) + offset;
+               pa = ((uint8_t *) mptr) + disp;
        }
-       else {
-               /* sanity check: we loaded from REG_IP; offset was negative or zero */
 
-               assert((mcode & 0x008f0000) == 0x000c0000 ||
-                      (mcode & 0x008f0fff) == 0x008c0000);
+       /* Case: We loaded from base REG_PV with positive offset. */
 
-               /* we loaded from data segment; offset can be larger */
+       else if (M_MEM_GET_Rbase(mcode) == REG_PV && (mcode & 0x00800000) == 0x00800000) {
+               /* We loaded from REG_METHODPTR with a larger displacement */
 
                mcode = pc[-1];
 
-               /* check for "SUB IP, IP, #??, ROTL 12" */
+               /* check for "ADD IP, FP, #??, ROTL 12" */
 
-               if ((mcode & 0xffffff00) == 0xe24cca00)
-                       offset += (int32_t) ((mcode & 0x00ff) << 12);
+               if ((mcode & 0xffffff00) == 0xe28bca00)
+                       disp += (int32_t) ((mcode & 0x00ff) << 12);
+               else
+                       vm_abort_disassemble(pc - 1, 4, "md_jit_method_patch_address: unknown instruction %x", mcode);
 
-               /* and get the final data segment address */
+               /* we loaded from REG_METHODPTR */
+
+               pa = ((uint8_t *) mptr) + disp;
+       }
+
+       /* Case is not covered, something is severely wrong. */
+
+       else {
+               vm_abort_disassemble(pc, 3, "md_jit_method_patch_address: unknown instruction %x", mcode);
+
+               /* Keep compiler happy. */
 
-               pa = ((uint8_t *) pv) - offset;        
+               pa = NULL;
        }
 
        return pa;