|
From: <sv...@va...> - 2005-07-18 11:39:49
|
Author: sewardj
Date: 2005-07-18 12:39:47 +0100 (Mon, 18 Jul 2005)
New Revision: 1274
Log:
Fix up linking/relocation a bit, and track API changes in r1272.
Modified:
trunk/switchback/linker.c
trunk/switchback/linker.h
trunk/switchback/switchback.c
Modified: trunk/switchback/linker.c
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
--- trunk/switchback/linker.c 2005-07-18 11:38:58 UTC (rev 1273)
+++ trunk/switchback/linker.c 2005-07-18 11:39:47 UTC (rev 1274)
@@ -8,7 +8,7 @@
#include <elf.h>
#include <fcntl.h>
#include <string.h>
-#include <malloc.h>
+//#include <malloc.h>
=20
#include "linker.h"
=20
@@ -45,6 +45,27 @@
return p;
}
=20
+#define MYMALLOC_MAX 50*1000*1000
+static HChar mymalloc_area[MYMALLOC_MAX];
+static UInt mymalloc_used =3D 0;
+void* mymalloc ( Int n )
+{
+ void* p;
+ while=20
+ ((UInt)(mymalloc_area+mymalloc_used) & 0xFFF)
+ mymalloc_used++;
+ assert(mymalloc_used+n < MYMALLOC_MAX);
+ p =3D (void*)(&mymalloc_area[mymalloc_used]);
+ mymalloc_used +=3D n;
+ // printf("mymalloc(%d) =3D %p\n", n, p);
+ return p;
+}
+
+void myfree ( void* p )
+{
+}
+
+
///////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////
@@ -190,7 +211,7 @@
static void addProddableBlock ( ObjectCode* oc, void* start, int size )
{
ProddableBlock* pb
- =3D malloc(sizeof(ProddableBlock));
+ =3D mymalloc(sizeof(ProddableBlock));
if (debug_linker)
fprintf(stderr, "aPB oc=3D%p %p %d (%p .. %p)\n", oc, start, siz=
e,
start, ((char*)start)+size-1 );
@@ -241,19 +262,19 @@
=20
static StringMap* new_StringMap ( void )
{
- StringMap* sm =3D malloc(sizeof(StringMap));
+ StringMap* sm =3D mymalloc(sizeof(StringMap));
sm->sm_size =3D 10;
sm->sm_used =3D 0;
- sm->maplets =3D malloc(10 * sizeof(Maplet));
+ sm->maplets =3D mymalloc(10 * sizeof(Maplet));
return sm;
}
=20
static void delete_StringMap ( StringMap* sm )
{
assert(sm->maplets !=3D NULL);
- free(sm->maplets);
+ myfree(sm->maplets);
sm->maplets =3D NULL;
- free(sm);
+ myfree(sm);
}
=20
static void ensure_StringMap ( StringMap* sm )
@@ -264,10 +285,10 @@
if (sm->sm_used < sm->sm_size)
return;
sm->sm_size *=3D 2;
- mp2 =3D malloc(sm->sm_size * sizeof(Maplet));
+ mp2 =3D mymalloc(sm->sm_size * sizeof(Maplet));
for (i =3D 0; i < sm->sm_used; i++)
mp2[i] =3D sm->maplets[i];
- free(sm->maplets);
+ myfree(sm->maplets);
sm->maplets =3D mp2;
}
=20
@@ -1161,7 +1182,7 @@
nent =3D shdr[i].sh_size / sizeof(Elf_Sym);
=20
oc->n_symbols =3D nent;
- oc->symbols =3D malloc(oc->n_symbols * sizeof(char*));
+ oc->symbols =3D mymalloc(oc->n_symbols * sizeof(char*));
=20
for (j =3D 0; j < nent; j++) {
=20
@@ -1180,7 +1201,7 @@
# else
ad =3D calloc(1, stab[j].st_size);
# endif
- assert( Ptr_to_ULong(ad) < 0xF0000000ULL );
+ // assert( Ptr_to_ULong(ad) < 0xF0000000ULL );
=20
if (0)
fprintf(stderr, "COMMON symbol, size %lld name %s allocd %p=
\n",
@@ -1308,7 +1329,7 @@
}
}
=20
- oc =3D malloc(sizeof(ObjectCode));
+ oc =3D mymalloc(sizeof(ObjectCode));
=20
oc->formatName =3D "ELF";
=20
@@ -1316,7 +1337,7 @@
if (r =3D=3D -1) { return 0; }
=20
/* sigh, strdup() isn't a POSIX function, so do it the long way */
- oc->fileName =3D malloc( strlen(path)+1 );
+ oc->fileName =3D mymalloc( strlen(path)+1 );
strcpy(oc->fileName, path);
=20
oc->fileSize =3D st.st_size;
@@ -1343,8 +1364,9 @@
relocations for jump distances > 64M. */
=20
pagesize =3D getpagesize();
- p =3D memalign(pagesize, N_FIXUP_PAGES * pagesize
- + oc->fileSize);
+ // p =3D memalign(pagesize, N_FIXUP_PAGES * pagesize
+ // + oc->fileSize);
+ p =3D mymalloc(N_FIXUP_PAGES * pagesize + oc->fileSize);
if (0) fprintf(stderr,"XXXX p =3D %p\n", p);
if (p =3D=3D NULL) {
fprintf(stderr,"loadObj: failed to allocate space for `%s'\n", pat=
h);
Modified: trunk/switchback/linker.h
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
--- trunk/switchback/linker.h 2005-07-18 11:38:58 UTC (rev 1273)
+++ trunk/switchback/linker.h 2005-07-18 11:39:47 UTC (rev 1274)
@@ -1,3 +1,5 @@
=20
extern
void* linker_top_level_LINK ( int n_object_names, char** object_names );
+
+extern void* mymalloc ( int );
Modified: trunk/switchback/switchback.c
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
--- trunk/switchback/switchback.c 2005-07-18 11:38:58 UTC (rev 1273)
+++ trunk/switchback/switchback.c 2005-07-18 11:39:47 UTC (rev 1274)
@@ -67,8 +67,8 @@
/* 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)
=20
=20
/* guest state */
@@ -79,8 +79,10 @@
/* only used for the switchback transition */
/* i386: helper1 =3D &gst, helper2 =3D %EFLAGS */
/* amd64: helper1 =3D &gst, helper2 =3D %EFLAGS */
+/* ppc32: helper1 =3D &gst, helper2 =3D %CR, helper3 =3D %XER */
HWord sb_helper1 =3D 0;
HWord sb_helper2 =3D 0;
+HWord sb_helper3 =3D 0;
=20
/* translation cache */
#define N_TRANS_CACHE 1000000
@@ -214,24 +216,24 @@
" lwz %r31,sb_helper1@l(%r31)\n" // load word of guest_state_ptr to r=
31
=20
// LR
-" lwz %r3,388(%r31)\n" // guest_LR
+" lwz %r3,900(%r31)\n" // guest_LR
" mtlr %r3\n" // move to LR
=20
// 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
=20
// CTR
-" lwz %r3,392(%r31)\n" // guest_CTR
+" lwz %r3,904(%r31)\n" // guest_CTR
" mtctr %r3\n" // move r3 to CTR
=20
// 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
=20
+
// GPR's
" lwz %r0, 0(%r31)\n"
" lwz %r1, 4(%r31)\n" // switch stacks (r1 =3D SP)
@@ -292,7 +294,7 @@
printf("nbytes =3D %d, nopstart =3D %d\n", nbytes, off_nopstart);
=20
/* copy it into mallocville */
- UChar* copy =3D malloc(nbytes);
+ UChar* copy =3D mymalloc(nbytes);
assert(copy);
for (i =3D 0; i < nbytes; i++)
copy[i] =3D sa_start[i];
@@ -303,6 +305,12 @@
Addr32 where_to_go =3D gst.guest_CIA;
Int diff =3D ((Int)where_to_go) - ((Int)addr_of_nop);
=20
+#if 0
+ printf("addr of first nop =3D 0x%x\n", addr_of_nop);
+ printf("where to go =3D 0x%x\n", where_to_go);
+ printf("diff =3D 0x%x\n", diff);
+#endif
+
if (diff < -0x2000000 || diff >=3D 0x2000000) {
// we're hosed. Give up
printf("hosed -- offset too large\n");
@@ -310,16 +318,12 @@
}
=20
sb_helper1 =3D (HWord)&gst;
- sb_helper2 =3D LibVEX_GuestPPC32_get_cr7(&gst);
+ sb_helper2 =3D LibVEX_GuestPPC32_get_CR(&gst);
+ sb_helper3 =3D LibVEX_GuestPPC32_get_XER(&gst);
=20
/* stay sane ... */
assert(p[0] =3D=3D 24<<26); /* nop */
=20
-#if 0
- printf("addr of first nop =3D 0x%x\n", addr_of_nop);
- printf("where to go =3D 0x%x\n", where_to_go);
- printf("diff =3D %d\n", diff);
-#endif
/* branch to diff */
p[0] =3D ((18<<26) | (((diff >> 2) & 0xFFFFFF) << 2) | (0<<1) | (0<<0=
));
=20
@@ -489,7 +493,7 @@
*/
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 @@
LibVEX_default_VexControl(&vcon);
vcon.guest_max_insns=3D50;
vcon.guest_chase_thresh=3D0;
-// vcon.iropt_level=3D2;
+ vcon.iropt_level=3D2;
=20
LibVEX_Init( failure_exit, log_bytes, 1, False, &vcon );
LibVEX_Guest_initialise(&gst);
|