]> git.ipfire.org Git - thirdparty/valgrind.git/commitdiff
Fix up linking/relocation a bit, and track API changes in r1272.
authorJulian Seward <jseward@acm.org>
Mon, 18 Jul 2005 11:39:47 +0000 (11:39 +0000)
committerJulian Seward <jseward@acm.org>
Mon, 18 Jul 2005 11:39:47 +0000 (11:39 +0000)
git-svn-id: svn://svn.valgrind.org/vex/trunk@1274

VEX/switchback/linker.c
VEX/switchback/linker.h
VEX/switchback/switchback.c

index 860ac80e41dae6ae5452eb58fda531709ea6403c..c1fff3dd8cb53ad6f4944c88a033695ea2d9c40c 100644 (file)
@@ -8,7 +8,7 @@
 #include <elf.h>
 #include <fcntl.h>
 #include <string.h>
-#include <malloc.h>
+//#include <malloc.h>
 
 #include "linker.h"
 
@@ -45,6 +45,27 @@ static void* calloc_below2G ( Int n, Int m )
    return p;
 }
 
+#define MYMALLOC_MAX 50*1000*1000
+static HChar mymalloc_area[MYMALLOC_MAX];
+static UInt  mymalloc_used = 0;
+void* mymalloc ( Int n )
+{
+   void* p;
+   while 
+      ((UInt)(mymalloc_area+mymalloc_used) & 0xFFF)
+      mymalloc_used++;
+   assert(mymalloc_used+n < MYMALLOC_MAX);
+   p = (void*)(&mymalloc_area[mymalloc_used]);
+   mymalloc_used += n;
+   //   printf("mymalloc(%d) = %p\n", n, p);
+   return p;
+}
+
+void myfree ( void* p )
+{
+}
+
+
 ///////////////////////////////////////////////////////////////////
 ///////////////////////////////////////////////////////////////////
 ///////////////////////////////////////////////////////////////////
@@ -190,7 +211,7 @@ typedef struct _ObjectCode {
 static void addProddableBlock ( ObjectCode* oc, void* start, int size )
 {
    ProddableBlock* pb
-      = malloc(sizeof(ProddableBlock));
+      = mymalloc(sizeof(ProddableBlock));
    if (debug_linker)
       fprintf(stderr, "aPB oc=%p %p %d   (%p .. %p)\n", oc, start, size,
              start, ((char*)start)+size-1 );
@@ -241,19 +262,19 @@ typedef
 
 static StringMap* new_StringMap ( void )
 {
-   StringMap* sm = malloc(sizeof(StringMap));
+   StringMap* sm = mymalloc(sizeof(StringMap));
    sm->sm_size = 10;
    sm->sm_used = 0;
-   sm->maplets = malloc(10 * sizeof(Maplet));
+   sm->maplets = mymalloc(10 * sizeof(Maplet));
    return sm;
 }
 
 static void delete_StringMap ( StringMap* sm )
 {
    assert(sm->maplets != NULL);
-   free(sm->maplets);
+   myfree(sm->maplets);
    sm->maplets = NULL;
-   free(sm);
+   myfree(sm);
 }
 
 static void ensure_StringMap ( StringMap* sm )
@@ -264,10 +285,10 @@ static void ensure_StringMap ( StringMap* sm )
    if (sm->sm_used < sm->sm_size)
      return;
    sm->sm_size *= 2;
-   mp2 = malloc(sm->sm_size * sizeof(Maplet));
+   mp2 = mymalloc(sm->sm_size * sizeof(Maplet));
    for (i = 0; i < sm->sm_used; i++)
       mp2[i] = sm->maplets[i];
-   free(sm->maplets);
+   myfree(sm->maplets);
    sm->maplets = mp2;
 }
 
@@ -1161,7 +1182,7 @@ ocGetNames_ELF ( ObjectCode* oc )
       nent = shdr[i].sh_size / sizeof(Elf_Sym);
 
       oc->n_symbols = nent;
-      oc->symbols = malloc(oc->n_symbols * sizeof(char*));
+      oc->symbols = mymalloc(oc->n_symbols * sizeof(char*));
 
       for (j = 0; j < nent; j++) {
 
@@ -1180,7 +1201,7 @@ ocGetNames_ELF ( ObjectCode* oc )
 #           else
             ad = calloc(1, stab[j].st_size);
 #           endif
-           assert( Ptr_to_ULong(ad) < 0xF0000000ULL );
+    //     assert( Ptr_to_ULong(ad) < 0xF0000000ULL );
 
            if (0)
             fprintf(stderr, "COMMON symbol, size %lld name %s  allocd %p\n",
@@ -1308,7 +1329,7 @@ int loadObj( char *path )
        }
    }
 
-   oc = malloc(sizeof(ObjectCode));
+   oc = mymalloc(sizeof(ObjectCode));
 
    oc->formatName = "ELF";
 
@@ -1316,7 +1337,7 @@ int loadObj( char *path )
    if (r == -1) { return 0; }
 
    /* sigh, strdup() isn't a POSIX function, so do it the long way */
-   oc->fileName = malloc( strlen(path)+1 );
+   oc->fileName = mymalloc( strlen(path)+1 );
    strcpy(oc->fileName, path);
 
    oc->fileSize          = st.st_size;
@@ -1343,8 +1364,9 @@ int loadObj( char *path )
       relocations for jump distances > 64M. */
 
    pagesize = getpagesize();
-   p = memalign(pagesize, N_FIXUP_PAGES * pagesize
-                          + oc->fileSize);
+   //   p = memalign(pagesize, N_FIXUP_PAGES * pagesize
+   //                          + oc->fileSize);
+   p = mymalloc(N_FIXUP_PAGES * pagesize + oc->fileSize);
    if (0) fprintf(stderr,"XXXX p = %p\n", p);
    if (p == NULL) {
       fprintf(stderr,"loadObj: failed to allocate space for `%s'\n", path);
index 6b6c54b22b2b4d11122075c20a90beedf77e6dca..e8b683ea4246d974151ffd2be7385346260b56dd 100644 (file)
@@ -1,3 +1,5 @@
 
 extern
 void* linker_top_level_LINK ( int n_object_names, char** object_names );
+
+extern void* mymalloc ( int );
index d8ee78e096c43dbe825576b1edf93ca0bc85619e..fad90dccf431f1ca8e951d402fd62c2585f256c0 100644 (file)
@@ -67,8 +67,8 @@ static Int   n_translations_made = 0;
 /* 2: show selected insns */
 /* 1: show after reg-alloc */
 /* 0: show final assembly */
-#define TEST_FLAGS (1<<7)|(1<<3)|(1<<2)|(1<<1) //|(1<<0)
-#define DEBUG_TRACE_FLAGS 0//(1<<7)|(0<<6)|(0<<5)|(0<<4)|(1<<3)|(1<<2)|(1<<1)|(1<<0)
+#define TEST_FLAGS (1<<7)|(1<<3)|(1<<2)|(1<<1)|(0<<0)
+#define DEBUG_TRACE_FLAGS 0 //(1<<7)|(0<<6)|(0<<5)|(0<<4)|(1<<3)|(1<<2)|(1<<1)|(0<<0)
 
 
 /* guest state */
@@ -79,8 +79,10 @@ VexControl vcon;
 /* only used for the switchback transition */
 /* i386:  helper1 = &gst, helper2 = %EFLAGS */
 /* amd64: helper1 = &gst, helper2 = %EFLAGS */
+/* ppc32: helper1 = &gst, helper2 = %CR, helper3 = %XER */
 HWord sb_helper1 = 0;
 HWord sb_helper2 = 0;
+HWord sb_helper3 = 0;
 
 /* translation cache */
 #define N_TRANS_CACHE 1000000
@@ -214,23 +216,23 @@ asm(
 "   lwz  %r31,sb_helper1@l(%r31)\n" // load word of guest_state_ptr to r31
 
 // LR
-"   lwz  %r3,388(%r31)\n"           // guest_LR
+"   lwz  %r3,900(%r31)\n"           // guest_LR
 "   mtlr %r3\n"                     // move to LR
 
 // CR
 "   lis  %r3,sb_helper2@ha\n"       // get hi-wd of flags addr
 "   lwz  %r3,sb_helper2@l(%r3)\n"   // load flags word to r3
 "   mtcr %r3\n"                     // move r3 to CR
-"   lwz  %r3,408(%r31)\n"           // guest_CR0to6
-"   mtcrf 0x3F,%r3\n"               // set remaining fields of CR
 
 // CTR
-"   lwz %r3,392(%r31)\n"       // guest_CTR
+"   lwz %r3,904(%r31)\n"       // guest_CTR
 "   mtctr %r3\n"               // move r3 to CTR
 
 // XER
-"   lwz %r3,416(%r31)\n"       // guest_XER
-"   mtxer %r3\n"               // move r3 to XER
+"   lis  %r3,sb_helper3@ha\n"       // get hi-wd of xer addr
+"   lwz  %r3,sb_helper3@l(%r3)\n"   // load xer word to r3
+"   mtxer %r3\n"                     // move r3 to XER
+
 
 // GPR's
 "   lwz %r0,    0(%r31)\n"
@@ -292,7 +294,7 @@ void switchback ( void )
       printf("nbytes = %d, nopstart = %d\n", nbytes, off_nopstart);
 
    /* copy it into mallocville */
-   UChar* copy = malloc(nbytes);
+   UChar* copy = mymalloc(nbytes);
    assert(copy);
    for (i = 0; i < nbytes; i++)
       copy[i] = sa_start[i];
@@ -303,6 +305,12 @@ void switchback ( void )
    Addr32 where_to_go = gst.guest_CIA;
    Int    diff = ((Int)where_to_go) - ((Int)addr_of_nop);
 
+#if 0
+   printf("addr of first nop = 0x%x\n", addr_of_nop);
+   printf("where to go       = 0x%x\n", where_to_go);
+   printf("diff = 0x%x\n", diff);
+#endif
+
    if (diff < -0x2000000 || diff >= 0x2000000) {
      // we're hosed.  Give up
      printf("hosed -- offset too large\n");
@@ -310,16 +318,12 @@ void switchback ( void )
    }
 
    sb_helper1 = (HWord)&gst;
-   sb_helper2 = LibVEX_GuestPPC32_get_cr7(&gst);
+   sb_helper2 = LibVEX_GuestPPC32_get_CR(&gst);
+   sb_helper3 = LibVEX_GuestPPC32_get_XER(&gst);
 
    /* stay sane ... */
    assert(p[0] == 24<<26); /* nop */
 
-#if 0
-   printf("addr of first nop = 0x%x\n", addr_of_nop);
-   printf("where to go       = 0x%x\n", where_to_go);
-   printf("diff = %d\n", diff);
-#endif
    /* branch to diff */
    p[0] = ((18<<26) | (((diff >> 2) & 0xFFFFFF) << 2) | (0<<1) | (0<<0));
 
@@ -489,7 +493,7 @@ asm(
 */
 Bool run_translation ( HWord translation )
 {
-   if (DEBUG_TRACE_FLAGS) {
+   if (0 && DEBUG_TRACE_FLAGS) {
       printf(" run translation %p\n", (void*)translation );
       printf(" simulated bb: %llu\n", n_bbs_done);
    }
@@ -776,7 +780,7 @@ int main ( Int argc, HChar** argv )
    LibVEX_default_VexControl(&vcon);
    vcon.guest_max_insns=50;
    vcon.guest_chase_thresh=0;
-//   vcon.iropt_level=2;
+   vcon.iropt_level=2;
 
    LibVEX_Init( failure_exit, log_bytes, 1, False, &vcon );
    LibVEX_Guest_initialise(&gst);