|
From: <sv...@va...> - 2005-12-13 21:30:52
|
Author: cerion
Date: 2005-12-13 21:30:48 +0000 (Tue, 13 Dec 2005)
New Revision: 1490
Log:
Switchbacker updates
- no longer using home-grown linker - simply compiling and linking switc=
hback.c with test_xxx.c
- updated to handle ppc64 (along with it's weirdo function descriptors..=
.)
- have to be careful not to use exported functions from libvex_arch_linu=
x.a, hence vex_printf -> vexxx_printf in test_xxx.c
Modified:
trunk/switchback/Makefile
trunk/switchback/binary_switchback.pl
trunk/switchback/linker.c
trunk/switchback/switchback.c
trunk/switchback/test_bzip2.c
trunk/switchback/test_emfloat.c
Modified: trunk/switchback/Makefile
=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/Makefile 2005-12-13 20:23:36 UTC (rev 1489)
+++ trunk/switchback/Makefile 2005-12-13 21:30:48 UTC (rev 1490)
@@ -1,9 +1,10 @@
=20
all: switchback.c linker.c linker.h
- gcc -Wall -O -g -o switchback switchback.c linker.c ../libvex.a
+ gcc -m64 -Wall -O -g -o switchback switchback.c linker.c ../libvex_ppc6=
4_linux.a
+# gcc -Wall -O -g -o switchback switchback.c linker.c ../libvex.a
=20
test_ppc:
- gcc -Wall -O -c test_ppc_jm1.c -mregnames
+ gcc -Wall -m64 -mregnames -O -c test_ppc_jm1.c
=20
clean:
rm -f switchback switchback.o linker.o
Modified: trunk/switchback/binary_switchback.pl
=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/binary_switchback.pl 2005-12-13 20:23:36 UTC (rev 14=
89)
+++ trunk/switchback/binary_switchback.pl 2005-12-13 21:30:48 UTC (rev 14=
90)
@@ -6,17 +6,20 @@
# Binary search script for switchback
# Finds bad basic block for seg faults and bad output.
#
-# To test output, you need to create $TEST.ref
-# $TEST.ref should hold the correct output for running the program:
+# To test output, you need to create test_ref
+# test_ref should hold the correct output for running the test_xxx progr=
am:
# - Everything between (not including) /^---START---$/ and /^---STOP---=
$/
# - But NOT including output from /^---begin SWITCHBACK/
# to /^--- end SWITCHBACK/ inclusive
#
+# This script can't handle other vex output,
+# so e.g switchback.c::DEBUG_TRACE_FLAGS should be 0
+#
=20
######################################################
# Global consts, vars
use constant DEBUG =3D> 0;
-use constant CONST_N_MAX =3D> 100000000;
+use constant CONST_N_MAX =3D> 10000000000;
use constant CONST_N_MUL =3D> 2;
=20
my $SWITCHBACK =3D "./switchback";
@@ -25,7 +28,7 @@
my $N_LAST_BAD =3D -1;
my $GIVEN_LAST_GOOD =3D -1;
my $GIVEN_LAST_BAD =3D -1;
-my $TEST;
+my $TEST_REF;
=20
=20
=20
@@ -37,9 +40,9 @@
}
=20
sub Usage {
- print "Usage: binary_switchback.pl test_name [last_good [last_bad]]\=
n";
+ print "Usage: binary_switchback.pl test_ref [last_good [last_bad]]\n=
";
print "where:\n";
- print " test_name =3D obj filename - without '.o'\n";
+ print " test_ref =3D reference output from test_xxx\n";
print " last_good =3D last known good bb (search space minimum)\n"=
;
print " last_bad =3D last known bad bb (search space maximum)\n";
print "\n";
@@ -60,12 +63,8 @@
QuitUsage "Error: Bad num args\n";
}
=20
-$TEST =3D $ARGV[0];
+$TEST_REF =3D $ARGV[0];
=20
-if ( ! -e "$TEST.o" ) {
- QuitUsage "File doesn't exist: '$TEST.o'\n";
-}
-
if ( ! -x "$SWITCHBACK" ) {
QuitUsage "File doesn't exist | not executable: '$SWITCHBACK'\n";
}
@@ -146,7 +145,7 @@
=20
print "=3D=3D=3D Calling switchback for bb $n =3D=3D=3D\n";
=20
- system("$SWITCHBACK $TEST.o $n >& $TMPFILE");
+ system("$SWITCHBACK $n >& $TMPFILE");
my $ret =3D $?;
=20
if ($ret =3D=3D 256) {
@@ -217,7 +216,7 @@
sub TestOutput {
my @lines =3D @{$_[0]};
my $n =3D $_[1];
- my $ref_output =3D "$TEST.ref";
+ my $ref_output =3D "$TEST_REF";
=20
# Get the current section we want to compare:
my @newlines;
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-12-13 20:23:36 UTC (rev 1489)
+++ trunk/switchback/linker.c 2005-12-13 21:30:48 UTC (rev 1490)
@@ -1,4 +1,11 @@
+/*
+ 13 Dec '05
+ Linker no longer used - apart from mymalloc().
+ Instead, simply compile and link switchback.c with test_xxx.c, e.g.:
+ ./> (cd .. && make EXTRA_CFLAGS=3D"-m64" libvex_ppc64_linux.a) && gcc =
-m64 -Wall -O -g -o switchback switchback.c linker.c ../libvex_ppc64_linu=
x.a test_bzip2.c
+*/
=20
+
#include <stdlib.h>
#include <stdio.h>
#include <assert.h>
@@ -14,8 +21,10 @@
=20
#include "../pub/libvex_basictypes.h"
=20
+#if 0
#define IF_DEBUG(x,y) /* */
static int debug_linker =3D 0;
+#endif
=20
=20
#if defined(__x86_64__)
@@ -29,6 +38,7 @@
#endif
=20
=20
+#if 0
#define CALLOC_MAX 10000000
static HChar calloc_area[CALLOC_MAX];
static UInt calloc_used =3D 0;
@@ -44,6 +54,7 @@
calloc_used +=3D n*m;
return p;
}
+#endif
=20
#define MYMALLOC_MAX 50*1000*1000
static HChar mymalloc_area[MYMALLOC_MAX];
@@ -51,8 +62,11 @@
void* mymalloc ( Int n )
{
void* p;
- while=20
- ((UInt)(mymalloc_area+mymalloc_used) & 0xFFF)
+#if defined(__powerpc64__)
+ while ((ULong)(mymalloc_area+mymalloc_used) & 0xFFF)
+#else
+ while ((UInt)(mymalloc_area+mymalloc_used) & 0xFFF)
+#endif
mymalloc_used++;
assert(mymalloc_used+n < MYMALLOC_MAX);
p =3D (void*)(&mymalloc_area[mymalloc_used]);
@@ -66,6 +80,12 @@
}
=20
=20
+
+
+
+
+
+#if 0
///////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////
@@ -1460,3 +1480,4 @@
}
=20
=20
+#endif
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-12-13 20:23:36 UTC (rev 1489)
+++ trunk/switchback/switchback.c 2005-12-13 21:30:48 UTC (rev 1490)
@@ -1,10 +1,15 @@
=20
/* HOW TO USE
=20
-Compile test file (eg test_hello.c) to a .o
+13 Dec '05 - Linker no longer used (apart from mymalloc)
+Simply compile and link switchback.c with test_xxx.c,
+e.g. for ppc64:
+$ (cd .. && make EXTRA_CFLAGS=3D"-m64" libvex_ppc64_linux.a)
+$ gcc -m64 -Wall -O -g -o switchback switchback.c linker.c ../libvex_ppc=
64_linux.a test_xxx.c
=20
-It must have an entry point called "entry", which expects to=20
-take a single argument which is a function pointer (to "serviceFn").
+Test file test_xxx.c must have an entry point called "entry",
+which expects to take a single argument which is a function pointer
+(to "serviceFn").
=20
Test file may not reference any other symbols.
=20
@@ -26,6 +31,7 @@
#include "../pub/libvex_guest_x86.h"
#include "../pub/libvex_guest_amd64.h"
#include "../pub/libvex_guest_ppc32.h"
+#include "../pub/libvex_guest_ppc64.h"
#include "../pub/libvex.h"
#include "../pub/libvex_trc_values.h"
#include "linker.h"
@@ -49,13 +55,24 @@
# define GuestPC guest_RIP
# define CacheLineSize 0/*irrelevant*/
#elif defined(__powerpc__)
+
+#if !defined(__powerpc64__) // ppc32
# define VexGuestState VexGuestPPC32State
# define LibVEX_Guest_initialise LibVEX_GuestPPC32_initialise
# define VexArch VexArchPPC32
-# define VexSubArch VexSubArchPPC32_noAV
+# define VexSubArch VexSubArchPPC32_FI
# define GuestPC guest_CIA
# define CacheLineSize 128
#else
+# define VexGuestState VexGuestPPC64State
+# define LibVEX_Guest_initialise LibVEX_GuestPPC64_initialise
+# define VexArch VexArchPPC64
+# define VexSubArch VexSubArchPPC64_FI
+# define GuestPC guest_CIA
+# define CacheLineSize 128
+#endif
+
+#else
# error "Unknown arch"
#endif
=20
@@ -67,8 +84,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)|(0<<0)
-#define DEBUG_TRACE_FLAGS 0 //(1<<7)|(0<<6)|(0<<5)|(0<<4)|(1<<3)|(1<<2)|=
(1<<1)|(0<<0)
+#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)
=20
=20
/* guest state */
@@ -97,6 +114,24 @@
=20
static Bool chase_into_not_ok ( Addr64 dst ) { return False; }
=20
+#if 0
+// local_sys_write_stderr(&c,1);
+static void local_sys_write_stderr ( HChar* buf, Int n )
+{
+ UInt __res;
+ __asm__ volatile (
+ "li %%r0,4\n\t" /* set %r0 =3D __NR_write */
+ "li %%r3,1\n\t" /* set %r3 =3D stdout */
+ "mr %%r4,%1\n\t" /* set %r4 =3D buf */
+ "mr %%r5,%2\n\t" /* set %r5 =3D n */
+ "sc\n\t" /* write(stderr, buf, n) */
+ "mr %0,%%r3\n" /* set __res =3D r3 */
+ : "=3Dmr" (__res)
+ : "g" (buf), "g" (n)
+ : "r0", "r3", "r4", "r5" );
+}
+#endif
+
/* For providing services. */
static HWord serviceFn ( HWord arg1, HWord arg2 )
{
@@ -209,6 +244,7 @@
}
=20
=20
+#if !defined(__powerpc64__) // ppc32
asm(
"switchback_asm:\n"
// gst
@@ -275,6 +311,101 @@
" nop\n"
"nop_end_point:\n"
);
+
+#else // ppc64
+
+asm(
+".text\n"
+" .global switchback_asm\n"
+" .section \".opd\",\"aw\"\n"
+" .align 3\n"
+"switchback_asm:\n"
+" .quad .switchback_asm,.TOC.@tocbase,0\n"
+" .previous\n"
+" .type .switchback_asm,@function\n"
+" .global .switchback_asm\n"
+".switchback_asm:\n"
+"switchback_asm_undotted:\n"
+
+// gst: load word of guest_state_ptr to r31
+" lis %r31,sb_helper1@highest\n"
+" ori %r31,%r31,sb_helper1@higher\n"
+" rldicr %r31,%r31,32,31\n"
+" oris %r31,%r31,sb_helper1@h\n"
+" ori %r31,%r31,sb_helper1@l\n"
+" ld %r31,0(%r31)\n"
+
+
+// LR
+" ld %r3,1032(%r31)\n" // guest_LR
+" mtlr %r3\n" // move to LR
+
+// CR
+" lis %r3,sb_helper2@highest\n"
+" ori %r3,%r3,sb_helper2@higher\n"
+" rldicr %r3,%r3,32,31\n"
+" oris %r3,%r3,sb_helper2@h\n"
+" ori %r3,%r3,sb_helper2@l\n"
+" ld %r3,0(%r3)\n" // load flags word to r3
+" mtcr %r3\n" // move r3 to CR
+
+// CTR
+" ld %r3,1040(%r31)\n" // guest_CTR
+" mtctr %r3\n" // move r3 to CTR
+
+// XER
+" lis %r3,sb_helper3@highest\n"
+" ori %r3,%r3,sb_helper3@higher\n"
+" rldicr %r3,%r3,32,31\n"
+" oris %r3,%r3,sb_helper3@h\n"
+" ori %r3,%r3,sb_helper3@l\n"
+" ld %r3,0(%r3)\n" // load xer word to r3
+" mtxer %r3\n" // move r3 to XER
+
+// GPR's
+" ld %r0, 0(%r31)\n"
+" ld %r1, 8(%r31)\n" // switch stacks (r1 =3D SP)
+" ld %r2, 16(%r31)\n"
+" ld %r3, 24(%r31)\n"
+" ld %r4, 32(%r31)\n"
+" ld %r5, 40(%r31)\n"
+" ld %r6, 48(%r31)\n"
+" ld %r7, 56(%r31)\n"
+" ld %r8, 64(%r31)\n"
+" ld %r9, 72(%r31)\n"
+" ld %r10, 80(%r31)\n"
+" ld %r11, 88(%r31)\n"
+" ld %r12, 96(%r31)\n"
+" ld %r13, 104(%r31)\n"
+" ld %r14, 112(%r31)\n"
+" ld %r15, 120(%r31)\n"
+" ld %r16, 128(%r31)\n"
+" ld %r17, 136(%r31)\n"
+" ld %r18, 144(%r31)\n"
+" ld %r19, 152(%r31)\n"
+" ld %r20, 160(%r31)\n"
+" ld %r21, 168(%r31)\n"
+" ld %r22, 176(%r31)\n"
+" ld %r23, 184(%r31)\n"
+" ld %r24, 192(%r31)\n"
+" ld %r25, 200(%r31)\n"
+" ld %r26, 208(%r31)\n"
+" ld %r27, 216(%r31)\n"
+" ld %r28, 224(%r31)\n"
+" ld %r29, 232(%r31)\n"
+" ld %r30, 240(%r31)\n"
+" ld %r31, 248(%r31)\n"
+"nop_start_point:\n"
+" nop\n"
+" nop\n"
+" nop\n"
+" nop\n"
+" nop\n"
+"nop_end_point:\n"
+);
+#endif
+
+extern void switchback_asm_undotted;
extern void nop_start_point;
extern void nop_end_point;
void switchback ( void )
@@ -284,10 +415,19 @@
memory on which can can set both write and execute permissions,
so we can poke around with it and then run the results. */
=20
+#if defined(__powerpc64__) // ppc32
+ UChar* sa_start =3D (UChar*)&switchback_asm_undotted;
+#else
UChar* sa_start =3D (UChar*)&switchback_asm;
+#endif
UChar* sa_nop_start =3D (UChar*)&nop_start_point;
UChar* sa_end =3D (UChar*)&nop_end_point;
=20
+#if 0
+ printf("sa_start %p\n", sa_start );
+ printf("sa_nop_start %p\n", sa_nop_start);
+ printf("sa_end %p\n", sa_end);
+#endif
Int nbytes =3D sa_end - sa_start;
Int off_nopstart =3D sa_nop_start - sa_start;
if (0)
@@ -301,6 +441,7 @@
=20
UInt* p =3D (UInt*)(©[off_nopstart]);
=20
+#if !defined(__powerpc64__) // ppc32
Addr32 addr_of_nop =3D (Addr32)p;
Addr32 where_to_go =3D gst.guest_CIA;
Int diff =3D ((Int)where_to_go) - ((Int)addr_of_nop);
@@ -311,6 +452,18 @@
printf("diff =3D 0x%x\n", diff);
#endif
=20
+#else // ppc64
+ Addr64 addr_of_nop =3D (Addr64)p;
+ Addr64 where_to_go =3D gst.guest_CIA;
+ Long diff =3D ((Long)where_to_go) - ((Long)addr_of_nop);
+
+#if 0
+ printf("addr of first nop =3D 0x%llx\n", addr_of_nop);
+ printf("where to go =3D 0x%llx\n", where_to_go);
+ printf("diff =3D 0x%llx\n", diff);
+#endif
+#endif
+
if (diff < -0x2000000 || diff >=3D 0x2000000) {
// we're hosed. Give up
printf("hosed -- offset too large\n");
@@ -318,8 +471,13 @@
}
=20
sb_helper1 =3D (HWord)&gst;
+#if !defined(__powerpc64__) // ppc32
sb_helper2 =3D LibVEX_GuestPPC32_get_CR(&gst);
sb_helper3 =3D LibVEX_GuestPPC32_get_XER(&gst);
+#else // ppc64
+ sb_helper2 =3D LibVEX_GuestPPC64_get_CR(&gst);
+ sb_helper3 =3D LibVEX_GuestPPC64_get_XER(&gst);
+#endif
=20
/* stay sane ... */
assert(p[0] =3D=3D 24<<26); /* nop */
@@ -329,7 +487,17 @@
=20
invalidate_icache( copy, nbytes );
=20
+#if defined(__powerpc64__)
+ //printf("jumping to %p\n", copy);
+ { ULong faketoc[3];
+ void* v;
+ faketoc[0] =3D (ULong)copy;
+ v =3D &faketoc[0];
+ ( (void(*)(void)) v )();
+ }
+#else
( (void(*)(void))copy )();
+#endif
}
=20
#else
@@ -397,6 +565,8 @@
);
=20
#elif defined(__powerpc__)
+
+#if !defined(__powerpc64__) // ppc32
asm(
"run_translation_asm:\n"
=20
@@ -483,6 +653,124 @@
" blr"
);
=20
+#else // ppc64
+
+asm(
+".text\n"
+" .global run_translation_asm\n"
+" .section \".opd\",\"aw\"\n"
+" .align 3\n"
+"run_translation_asm:\n"
+" .quad .run_translation_asm,.TOC.@tocbase,0\n"
+" .previous\n"
+" .type .run_translation_asm,@function\n"
+" .global .run_translation_asm\n"
+".run_translation_asm:\n"
+
+// save LR,CTR
+" mflr %r0\n"
+" std %r0,16(%r1)\n"
+" mfctr %r0\n"
+" std %r0,8(%r1)\n"
+
+// create new stack:
+// save old sp at first word & update sp
+" stdu 1,-256(1)\n"
+
+// leave hole @ 4(%r1) for a callee to save it's LR
+// no params
+// no need to save non-volatile CR fields
+
+// store registers to stack: just the callee-saved regs
+" std %r13, 48(%r1)\n"
+" std %r14, 56(%r1)\n"
+" std %r15, 64(%r1)\n"
+" std %r16, 72(%r1)\n"
+" std %r17, 80(%r1)\n"
+" std %r18, 88(%r1)\n"
+" std %r19, 96(%r1)\n"
+" std %r20, 104(%r1)\n"
+" std %r21, 112(%r1)\n"
+" std %r22, 120(%r1)\n"
+" std %r23, 128(%r1)\n"
+" std %r24, 136(%r1)\n"
+" std %r25, 144(%r1)\n"
+" std %r26, 152(%r1)\n"
+" std %r27, 160(%r1)\n"
+" std %r28, 168(%r1)\n"
+" std %r29, 176(%r1)\n"
+" std %r30, 184(%r1)\n"
+" std %r31, 192(%r1)\n"
+
+// r31 (guest state ptr) :=3D global var "gp"
+" lis %r31,gp@highest\n"
+" ori %r31,%r31,gp@higher\n"
+" rldicr %r31,%r31,32,31\n"
+" oris %r31,%r31,gp@h\n"
+" ori %r31,%r31,gp@l\n"
+" ld %r31,0(%r31)\n"
+
+// call translation address in global var "f"
+" lis %r4,f@highest\n"
+" ori %r4,%r4,f@higher\n"
+" rldicr %r4,%r4,32,31\n"
+" oris %r4,%r4,f@h\n"
+" ori %r4,%r4,f@l\n"
+" ld %r4,0(%r4)\n"
+" mtctr %r4\n"
+" bctrl\n"
+
+// save return value (in r3) into global var "res"
+" lis %r5,res@highest\n"
+" ori %r5,%r5,res@higher\n"
+" rldicr %r5,%r5,32,31\n"
+" oris %r5,%r5,res@h\n"
+" ori %r5,%r5,res@l\n"
+" std %r3,0(%r5)\n"
+
+// save possibly modified guest state ptr (r31) in "gp"
+" lis %r5,gp@highest\n"
+" ori %r5,%r5,gp@higher\n"
+" rldicr %r5,%r5,32,31\n"
+" oris %r5,%r5,gp@h\n"
+" ori %r5,%r5,gp@l\n"
+" std %r31,0(%r5)\n"
+
+// reload registers from stack
+" ld %r13, 48(%r1)\n"
+" ld %r14, 56(%r1)\n"
+" ld %r15, 64(%r1)\n"
+" ld %r16, 72(%r1)\n"
+" ld %r17, 80(%r1)\n"
+" ld %r18, 88(%r1)\n"
+" ld %r19, 96(%r1)\n"
+" ld %r20, 104(%r1)\n"
+" ld %r21, 112(%r1)\n"
+" ld %r22, 120(%r1)\n"
+" ld %r23, 128(%r1)\n"
+" ld %r24, 136(%r1)\n"
+" ld %r25, 144(%r1)\n"
+" ld %r26, 152(%r1)\n"
+" ld %r27, 160(%r1)\n"
+" ld %r28, 168(%r1)\n"
+" ld %r29, 176(%r1)\n"
+" ld %r30, 184(%r1)\n"
+" ld %r31, 192(%r1)\n"
+
+// restore previous stack pointer
+" addi %r1,%r1,256\n"
+
+// restore LR,CTR
+" ld %r0,16(%r1)\n"
+" mtlr %r0\n"
+" ld %r0,8(%r1)\n"
+" mtctr %r0\n"
+
+// return
+" blr"
+);
+#endif
+
#else
=20
# error "Unknown arch"
@@ -632,7 +920,7 @@
=20
=20
static ULong stopAfter =3D 0;
-static UChar* entry =3D NULL;
+static UChar* entryP =3D NULL;
=20
=20
__attribute__ ((noreturn))
@@ -665,8 +953,12 @@
=20
if (0)
printf("\nnext_guest: 0x%x\n", (UInt)next_guest);
- =20
+
+#if defined(__powerpc64__)
+ if (next_guest =3D=3D Ptr_to_ULong( (void*)(*(ULong*)(&serviceFn))=
)) {
+#else
if (next_guest =3D=3D Ptr_to_ULong(&serviceFn)) {
+#endif
/* "do" the function call to serviceFn */
# if defined(__i386__)
{
@@ -736,13 +1028,15 @@
=20
static void usage ( void )
{
- printf("usage: switchback file.o #bbs\n");
+ printf("usage: switchback #bbs\n");
printf(" - begins switchback for basic block #bbs\n");
printf(" - use -1 for largest possible run without switchback\n\n")=
;
exit(1);
}
=20
#if defined(__powerpc__)
+
+#if !defined(__powerpc64__) // ppc32
UInt saved_R2;
asm(
"get_R2:\n"
@@ -750,29 +1044,63 @@
" stw %r2,saved_R2@l(%r10)\n"
" blr\n"
);
+#else // ppc64
+ULong saved_R2;
+ULong saved_R13;
+asm(
+".text\n"
+" .global get_R2\n"
+" .section \".opd\",\"aw\"\n"
+" .align 3\n"
+"get_R2:\n"
+" .quad .get_R2,.TOC.@tocbase,0\n"
+" .previous\n"
+" .type .get_R2,@function\n"
+" .global .get_R2\n"
+".get_R2:\n"
+" lis %r10,saved_R2@highest\n"
+" ori %r10,%r10,saved_R2@higher\n"
+" rldicr %r10,%r10,32,31\n"
+" oris %r10,%r10,saved_R2@h\n"
+" ori %r10,%r10,saved_R2@l\n"
+" std %r2,0(%r10)\n"
+" blr\n"
+);
+asm(
+".text\n"
+" .global get_R13\n"
+" .section \".opd\",\"aw\"\n"
+" .align 3\n"
+"get_R13:\n"
+" .quad .get_R13,.TOC.@tocbase,0\n"
+" .previous\n"
+" .type .get_R13,@function\n"
+" .global .get_R13\n"
+".get_R13:\n"
+" lis %r10,saved_R13@highest\n"
+" ori %r10,%r10,saved_R13@higher\n"
+" rldicr %r10,%r10,32,31\n"
+" oris %r10,%r10,saved_R13@h\n"
+" ori %r10,%r10,saved_R13@l\n"
+" std %r13,0(%r10)\n"
+" blr\n"
+);
+#endif
extern void get_R2 ( void );
+extern void get_R13 ( void );
#endif
=20
int main ( Int argc, HChar** argv )
{
- HChar* oname;
-
- struct stat buf;
-
- if (argc !=3D 3)=20
+ if (argc !=3D 2)
usage();
=20
- oname =3D argv[1];
- stopAfter =3D (ULong)atoll(argv[2]);
+ stopAfter =3D (ULong)atoll(argv[1]);
=20
- if (stat(oname, &buf)) {
- printf("switchback: can't stat %s\n", oname);
- return 1;
- }
+ extern void entry ( void*(*service)(int,int) );
+ entryP =3D (UChar*)&entry;
=20
- entry =3D linker_top_level_LINK( 1, &argv[1] );
-
- if (!entry) {
+ if (!entryP) {
printf("switchback: can't find entry point\n");
exit(1);
}
@@ -788,22 +1116,35 @@
/* set up as if a call to the entry point passing serviceFn as=20
the one and only parameter */
# if defined(__i386__)
- gst.guest_EIP =3D (UInt)entry;
+ gst.guest_EIP =3D (UInt)entryP;
gst.guest_ESP =3D (UInt)&gstack[25000];
*(UInt*)(gst.guest_ESP+4) =3D (UInt)serviceFn;
*(UInt*)(gst.guest_ESP+0) =3D 0x12345678;
# elif defined(__x86_64__)
- gst.guest_RIP =3D (ULong)entry;
+ gst.guest_RIP =3D (ULong)entryP;
gst.guest_RSP =3D (ULong)&gstack[25000];
gst.guest_RDI =3D (ULong)serviceFn;
*(ULong*)(gst.guest_RSP+0) =3D 0x12345678AABBCCDDULL;
# elif defined(__powerpc__)
get_R2();
- gst.guest_CIA =3D (UInt)entry;
+
+#if !defined(__powerpc64__) // ppc32
+ gst.guest_CIA =3D (UInt)entryP;
gst.guest_GPR1 =3D (UInt)&gstack[25000]; /* stack pointer */
gst.guest_GPR3 =3D (UInt)serviceFn; /* param to entry */
gst.guest_GPR2 =3D saved_R2;
gst.guest_LR =3D 0x12345678; /* bogus return address */
+#else // ppc64
+ get_R13();
+ gst.guest_CIA =3D * (ULong*)entryP;
+ gst.guest_GPR1 =3D (ULong)&gstack[25000]; /* stack pointer */
+ gst.guest_GPR3 =3D (ULong)serviceFn; /* param to entry */
+ gst.guest_GPR2 =3D saved_R2;
+ gst.guest_GPR13 =3D saved_R13;
+ gst.guest_LR =3D 0x1234567812345678ULL; /* bogus return address */
+// printf("setting CIA to %p\n", (void*)gst.guest_CIA);
+#endif
+
# else
# error "Unknown arch"
# endif
@@ -813,7 +1154,7 @@
#if 1
run_simulator();
#else
- ( (void(*)(HWord(*)(HWord,HWord))) entry ) (serviceFn);
+ ( (void(*)(HWord(*)(HWord,HWord))) entryP ) (serviceFn);
#endif
=20
=20
Modified: trunk/switchback/test_bzip2.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/test_bzip2.c 2005-12-13 20:23:36 UTC (rev 1489)
+++ trunk/switchback/test_bzip2.c 2005-12-13 21:30:48 UTC (rev 1490)
@@ -451,17 +451,17 @@
{ if (!(cond)) bz_internal_error ( errcode ); }
#define AssertD(cond,msg) /* */
#define VPrintf0(zf) \
- vex_printf(zf)
+ vexxx_printf(zf)
#define VPrintf1(zf,za1) \
- vex_printf(zf,za1)
+ vexxx_printf(zf,za1)
#define VPrintf2(zf,za1,za2) \
- vex_printf(zf,za1,za2)
+ vexxx_printf(zf,za1,za2)
#define VPrintf3(zf,za1,za2,za3) \
- vex_printf(zf,za1,za2,za3)
+ vexxx_printf(zf,za1,za2,za3)
#define VPrintf4(zf,za1,za2,za3,za4) \
- vex_printf(zf,za1,za2,za3,za4)
+ vexxx_printf(zf,za1,za2,za3,za4)
#define VPrintf5(zf,za1,za2,za3,za4,za5) \
- vex_printf(zf,za1,za2,za3,za4,za5)
+ vexxx_printf(zf,za1,za2,za3,za4,za5)
#endif
=20
=20
@@ -955,7 +955,7 @@
=20
/////////////////////////////////////////////////////////////////////
=20
-static void vex_log_bytes ( char* p, int n )
+static void vexxx_log_bytes ( char* p, int n )
{
int i;
for (i =3D 0; i < n; i++)
@@ -963,14 +963,14 @@
}
=20
/*---------------------------------------------------------*/
-/*--- vex_printf ---*/
+/*--- vexxx_printf ---*/
/*---------------------------------------------------------*/
=20
/* This should be the only <...> include in the entire VEX library.
- New code for vex_util.c should go above this point. */
+ New code for vexxx_util.c should go above this point. */
#include <stdarg.h>
=20
-static HChar vex_toupper ( HChar c )
+static HChar vexxx_toupper ( HChar c )
{
if (c >=3D 'a' && c <=3D 'z')
return c + ('A' - 'a');
@@ -978,14 +978,14 @@
return c;
}
=20
-static Int vex_strlen ( const HChar* str )
+static Int vexxx_strlen ( const HChar* str )
{
Int i =3D 0;
while (str[i] !=3D 0) i++;
return i;
}
=20
-Bool vex_streq ( const HChar* s1, const HChar* s2 )
+Bool vexxx_streq ( const HChar* s1, const HChar* s2 )
{
while (True) {
if (*s1 =3D=3D 0 && *s2 =3D=3D 0)
@@ -1009,10 +1009,10 @@
myvprintf_str ( void(*send)(HChar), Int flags, Int width, HChar* str,=20
Bool capitalise )
{
-# define MAYBE_TOUPPER(ch) (capitalise ? vex_toupper(ch) : (ch))
+# define MAYBE_TOUPPER(ch) (capitalise ? vexxx_toupper(ch) : (ch))
UInt ret =3D 0;
Int i, extra;
- Int len =3D vex_strlen(str);
+ Int len =3D vexxx_strlen(str);
=20
if (width =3D=3D 0) {
ret +=3D len;
@@ -1257,7 +1257,7 @@
static void add_to_myprintf_buf ( HChar c )
{
if (c =3D=3D '\n' || n_myprintf_buf >=3D 1000-10 /*paranoia*/ ) {
- (*vex_log_bytes)( myprintf_buf, vex_strlen(myprintf_buf) );
+ (*vexxx_log_bytes)( myprintf_buf, vexxx_strlen(myprintf_buf) );
n_myprintf_buf =3D 0;
myprintf_buf[n_myprintf_buf] =3D 0; =20
}
@@ -1265,7 +1265,7 @@
myprintf_buf[n_myprintf_buf] =3D 0;
}
=20
-static UInt vex_printf ( const char *format, ... )
+static UInt vexxx_printf ( const char *format, ... )
{
UInt ret;
va_list vargs;
@@ -1276,7 +1276,7 @@
ret =3D vprintf_wrk ( add_to_myprintf_buf, format, vargs );
=20
if (n_myprintf_buf > 0) {
- (*vex_log_bytes)( myprintf_buf, n_myprintf_buf );
+ (*vexxx_log_bytes)( myprintf_buf, n_myprintf_buf );
}
=20
va_end(vargs);
@@ -1285,7 +1285,7 @@
}
=20
/*---------------------------------------------------------------*/
-/*--- end vex_util.c ---*/
+/*--- end vexxx_util.c ---*/
/*---------------------------------------------------------------*/
=20
=20
@@ -4427,13 +4427,13 @@
/*---------------------------------------------------*/
void BZ2_bz__AssertH__fail ( int errcode )
{
- vex_printf("BZ2_bz__AssertH__fail(%d) called, exiting\n", errcode);
+ vexxx_printf("BZ2_bz__AssertH__fail(%d) called, exiting\n", errcode);
(*serviceFn)(0,0);
}
=20
void bz_internal_error ( int errcode )
{
- vex_printf("bz_internal_error called, exiting\n", errcode);
+ vexxx_printf("bz_internal_error called, exiting\n", errcode);
(*serviceFn)(0,0);
}
=20
@@ -6062,40 +6062,40 @@
serviceFn =3D service;
=20
set_inbuf();
- nIn =3D vex_strlen(inbuf)+1;
- vex_printf( "%d bytes read\n", nIn );
+ nIn =3D vexxx_strlen(inbuf)+1;
+ vexxx_printf( "%d bytes read\n", nIn );
=20
nZ =3D M_BLOCK;
r =3D BZ2_bzBuffToBuffCompress (
zbuf, &nZ, inbuf, nIn, 9, 4/*verb*/, 30 );
=20
if (r !=3D BZ_OK) {
- vex_printf("initial compress failed!\n");
+ vexxx_printf("initial compress failed!\n");
(*serviceFn)(0,0);
}
- vex_printf( "%d after compression\n", nZ );
+ vexxx_printf( "%d after compression\n", nZ );
=20
for (bit =3D 0; bit < nZ*8; bit +=3D (bit < 35 ? 1 : 377)) {
- vex_printf( "bit %d ", bit );
+ vexxx_printf( "bit %d ", bit );
flip_bit ( bit );
nOut =3D M_BLOCK_OUT;
r =3D BZ2_bzBuffToBuffDecompress (
outbuf, &nOut, zbuf, nZ, 1/*small*/, 0 );
- vex_printf( " %d %s ", r, bzerrorstrings[-r] );
+ vexxx_printf( " %d %s ", r, bzerrorstrings[-r] );
=20
if (r !=3D BZ_OK) {
- vex_printf( "\n" );
+ vexxx_printf( "\n" );
} else {
if (nOut !=3D nIn) {
- vex_printf( "nIn/nOut mismatch %d %d\n", nIn, nOut );
+ vexxx_printf( "nIn/nOut mismatch %d %d\n", nIn, nOut );
(*serviceFn)(0,0);
} else {
for (i =3D 0; i < nOut; i++)
if (inbuf[i] !=3D outbuf[i]) {=20
- vex_printf( "mismatch at %d\n", i );=20
+ vexxx_printf( "mismatch at %d\n", i );=20
(*serviceFn)(0,0);=20
}
- if (i =3D=3D nOut) vex_printf( "really ok!\n" );
+ if (i =3D=3D nOut) vexxx_printf( "really ok!\n" );
}
}
=20
@@ -6106,12 +6106,12 @@
assert (nOut =3D=3D nIn);
for (i =3D 0; i < nOut; i++) {
if (inbuf[i] !=3D outbuf[i]) {
- vex_printf( "difference at %d !\n", i );
+ vexxx_printf( "difference at %d !\n", i );
return 1;
}
}
#endif
=20
- vex_printf( "all ok\n" );
+ vexxx_printf( "all ok\n" );
(*serviceFn)(0,0);
}
Modified: trunk/switchback/test_emfloat.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/test_emfloat.c 2005-12-13 20:23:36 UTC (rev 1489)
+++ trunk/switchback/test_emfloat.c 2005-12-13 21:30:48 UTC (rev 1490)
@@ -86,7 +86,7 @@
=20
/////////////////////////////////////////////////////////////////////
=20
-static void vex_log_bytes ( char* p, int n )
+static void vexxx_log_bytes ( char* p, int n )
{
int i;
for (i =3D 0; i < n; i++)
@@ -94,14 +94,14 @@
}
=20
/*---------------------------------------------------------*/
-/*--- vex_printf ---*/
+/*--- vexxx_printf ---*/
/*---------------------------------------------------------*/
=20
-/* This should be the only <...> include in the entire VEX library.
- New code for vex_util.c should go above this point. */
+/* This should be the only <...> include in the entire VEXXX library.
+ New code for vexxx_util.c should go above this point. */
#include <stdarg.h>
=20
-static HChar vex_toupper ( HChar c )
+static HChar vexxx_toupper ( HChar c )
{
if (c >=3D 'a' && c <=3D 'z')
return toHChar(c + ('A' - 'a'));
@@ -109,14 +109,14 @@
return c;
}
=20
-static Int vex_strlen ( const HChar* str )
+static Int vexxx_strlen ( const HChar* str )
{
Int i =3D 0;
while (str[i] !=3D 0) i++;
return i;
}
=20
-Bool vex_streq ( const HChar* s1, const HChar* s2 )
+Bool vexxx_streq ( const HChar* s1, const HChar* s2 )
{
while (True) {
if (*s1 =3D=3D 0 && *s2 =3D=3D 0)
@@ -140,10 +140,10 @@
myvprintf_str ( void(*send)(HChar), Int flags, Int width, HChar* str,=20
Bool capitalise )
{
-# define MAYBE_TOUPPER(ch) toHChar(capitalise ? vex_toupper(ch) : (ch))
+# define MAYBE_TOUPPER(ch) toHChar(capitalise ? vexxx_toupper(ch) : (ch=
))
UInt ret =3D 0;
Int i, extra;
- Int len =3D vex_strlen(str);
+ Int len =3D vexxx_strlen(str);
=20
if (width =3D=3D 0) {
ret +=3D len;
@@ -388,7 +388,7 @@
static void add_to_myprintf_buf ( HChar c )
{
if (c =3D=3D '\n' || n_myprintf_buf >=3D 1000-10 /*paranoia*/ ) {
- (*vex_log_bytes)( myprintf_buf, vex_strlen(myprintf_buf) );
+ (*vexxx_log_bytes)( myprintf_buf, vexxx_strlen(myprintf_buf) );
n_myprintf_buf =3D 0;
myprintf_buf[n_myprintf_buf] =3D 0; =20
}
@@ -396,7 +396,7 @@
myprintf_buf[n_myprintf_buf] =3D 0;
}
=20
-static UInt vex_printf ( const char *format, ... )
+static UInt vexxx_printf ( const char *format, ... )
{
UInt ret;
va_list vargs;
@@ -407,7 +407,7 @@
ret =3D vprintf_wrk ( add_to_myprintf_buf, format, vargs );
=20
if (n_myprintf_buf > 0) {
- (*vex_log_bytes)( myprintf_buf, n_myprintf_buf );
+ (*vexxx_log_bytes)( myprintf_buf, n_myprintf_buf );
}
=20
va_end(vargs);
@@ -416,7 +416,7 @@
}
=20
/*---------------------------------------------------------------*/
-/*--- end vex_util.c ---*/
+/*--- end vexxx_util.c ---*/
/*---------------------------------------------------------------*/
=20
=20
@@ -610,7 +610,7 @@
loops =3D 100;
number_of_loops=3Dloops-1; /* the index of the first loop we run */
=20
-vex_printf(str1, (int)loops);
+vexxx_printf(str1, (int)loops);
=20
/*
** Each pass through the array performs operations in
@@ -662,7 +662,7 @@
for(k=3D0;k<8;k++){
i=3Dj[k];
InternalFPFToString(buffer,abase+i);
- vex_printf("%6d: (%s) ",i,buffer);
+ vexxx_printf("%6d: (%s) ",i,buffer);
switch(jtable[i % 16])
{
case 0: my_strcpy(buffer,"+"); break;
@@ -670,11 +670,11 @@
case 2: my_strcpy(buffer,"*"); break;
case 3: my_strcpy(buffer,"/"); break;
}
- vex_printf("%s ",buffer);
+ vexxx_printf("%s ",buffer);
InternalFPFToString(buffer,bbase+i);
- vex_printf("(%s) =3D ",buffer);
+ vexxx_printf("(%s) =3D ",buffer);
InternalFPFToString(buffer,cbase+i);
- vex_printf("%s\n",buffer);
+ vexxx_printf("%s\n",buffer);
}
return 0;
}
@@ -944,7 +944,7 @@
=20
if (IsMantissaZero(ptr->mantissa))
{
- vex_printf("Error: zero significand in denormalize\n");
+ vexxx_printf("Error: zero significand in denormalize\n");
}
=20
exponent_difference =3D ptr->exp-minimum_exponent;
@@ -1938,7 +1938,7 @@
void entry ( HWord(*f)(HWord,HWord) )
{
serviceFn =3D f;
- vex_printf("starting\n");
+ vexxx_printf("starting\n");
DoEmFloat();
(*serviceFn)(0,0);
}
|