From af42a0cc248604acd14eab8a2086e2c4a1386d37 Mon Sep 17 00:00:00 2001 From: Magnus Olsen Date: Wed, 17 Jan 2007 15:31:47 +0000 Subject: [PATCH] fixing the ppc to ia32 break, use ebx as ebp if we got to many register. svn path=/trunk/; revision=25496 --- .../cputointel/ConvertToIA32Process.c | 32 +++++---- .../devutils/cputointel/ConvertingProcess.c | 71 +++++++++++++++++++ .../devutils/cputointel/From/PPC/PPCBrain.c | 10 --- .../devutils/cputointel/From/PPC/PPCBrain.h | 2 +- .../devutils/cputointel/From/PPC/PPCopcode.c | 15 ---- 5 files changed, 90 insertions(+), 40 deletions(-) create mode 100644 rosapps/devutils/cputointel/ConvertingProcess.c diff --git a/rosapps/devutils/cputointel/ConvertToIA32Process.c b/rosapps/devutils/cputointel/ConvertToIA32Process.c index 470de7ed4da..ccc3fe8d64f 100644 --- a/rosapps/devutils/cputointel/ConvertToIA32Process.c +++ b/rosapps/devutils/cputointel/ConvertToIA32Process.c @@ -22,6 +22,7 @@ CPU_INT ConvertToIntelProcess( FILE *outfp, CPU_INT eax, CPU_INT ebp, if (HowManyRegInUse > 8) { setup_ebp =1; /* we will use ebx as ebp */ + stack = HowManyRegInUse * regbits; } @@ -36,13 +37,17 @@ CPU_INT ConvertToIntelProcess( FILE *outfp, CPU_INT eax, CPU_INT ebp, fprintf(outfp,"_main:\n"); /* setup a frame pointer */ - //fprintf(outfp,"\n; Setup frame pointer \n"); - //fprintf(outfp,"push ebp\n"); - //fprintf(outfp,"mov ebp,esp\n"); - //fprintf(outfp,"sub esp, %d ; Alloc %d bytes for reg\n\n",stack,stack); + + if (setup_ebp == 1) + { + fprintf(outfp,"\n; Setup frame pointer \n"); + fprintf(outfp,"push ebx\n"); + fprintf(outfp,"mov ebx,esp\n"); + fprintf(outfp,"sub esp, %d ; Alloc %d bytes for reg\n\n",stack,stack); + } fprintf(outfp,"; Start the program \n"); - while (pMystart!=pMyend) + while (pMystart!=NULL) { /* fixme the line lookup from anaylysing process */ @@ -60,7 +65,7 @@ CPU_INT ConvertToIntelProcess( FILE *outfp, CPU_INT eax, CPU_INT ebp, { /* source are imm */ - if (pMyBrainAnalys->dst == eax) + if (pMystart->dst == eax) { if (pMystart->src == 0) fprintf(outfp,"xor eax,eax\n"); @@ -90,8 +95,7 @@ CPU_INT ConvertToIntelProcess( FILE *outfp, CPU_INT eax, CPU_INT ebp, } else { - //fprintf(outfp,"mov dword [ebp - %d], %llu\n", tmp, pMystart->src); - printf("not support move from register\n"); + fprintf(outfp,"mov dword [ebx - %d], %llu\n", tmp, pMystart->src); } } } /* end pMyBrainAnalys->type & 8 */ @@ -100,12 +104,12 @@ CPU_INT ConvertToIntelProcess( FILE *outfp, CPU_INT eax, CPU_INT ebp, /* return */ if (pMystart->op == OP_ANY_ret) { - //if (pMyBrainAnalys->ptr_next == NULL) - //{ - // fprintf(outfp,"\n; clean up after the frame \n"); - // fprintf(outfp,"mov esp, ebp\n"); - // fprintf(outfp,"pop ebp\n"); - //} + if (pMyBrainAnalys->ptr_next == NULL) + { + fprintf(outfp,"\n; clean up after the frame \n"); + fprintf(outfp,"mov esp, ebx\n"); + fprintf(outfp,"pop ebx\n"); + } fprintf(outfp,"ret\n"); } pMystart = (PMYBrainAnalys) pMystart->ptr_next; diff --git a/rosapps/devutils/cputointel/ConvertingProcess.c b/rosapps/devutils/cputointel/ConvertingProcess.c new file mode 100644 index 00000000000..9d74cc79b35 --- /dev/null +++ b/rosapps/devutils/cputointel/ConvertingProcess.c @@ -0,0 +1,71 @@ +#include +#include + +#include +#include +#include +#include "misc.h" +#include "any_op.h" + +/* hack should be in misc.h*/ + + +CPU_INT ConvertProcess(FILE *outfp, CPU_INT FromCpuid, CPU_INT ToCpuid) +{ + CPU_INT ret=0; + CPU_INT eax =-1; + CPU_INT ebp =-1; + CPU_INT edx =-1; + CPU_INT esp =-1; + CPU_INT regbits=-1; + CPU_INT HowManyRegInUse = 0; + + PMYBrainAnalys pMystart = pStartMyBrainAnalys; + PMYBrainAnalys pMyend = pMyBrainAnalys; + + if (FromCpuid == IMAGE_FILE_MACHINE_POWERPC) + { + regbits = 32 / 8; + esp = 1; + eax = 3; + edx = 4; + ebp = 31; + } + + + /* FIXME calc where todo first split */ + + /* FIXME calc who many register are in use */ + + //ret = ConvertToIntelProcess(FILE *outfp, + // CPU_INT eax, + // CPU_INT edx, + // CPU_INT edx, + // CPU_INT esp, + // PMYBrainAnalys start, + // PMYBrainAnalys end); + + + + switch (ToCpuid) + { + case IMAGE_FILE_MACHINE_I386: + ret = ConvertToIntelProcess( outfp, eax, ebp, + edx, esp, + pMystart, + pMyend, regbits, + HowManyRegInUse); + if (ret !=0) + { + printf("should not happen contact a devloper, x86 fail\n"); + return -1; + } + break; + + default: + printf("should not happen contact a devloper, unknown fail\n"); + return -1; + } + + return ret; +} diff --git a/rosapps/devutils/cputointel/From/PPC/PPCBrain.c b/rosapps/devutils/cputointel/From/PPC/PPCBrain.c index 1dcb5c38c45..ca932c3a49d 100644 --- a/rosapps/devutils/cputointel/From/PPC/PPCBrain.c +++ b/rosapps/devutils/cputointel/From/PPC/PPCBrain.c @@ -59,16 +59,6 @@ CPU_INT PPCBrain( CPU_BYTE *cpu_buffer, cpuint = GetData32Le(&cpu_buffer[cpu_pos]); - ///* Add */ - //if ((cpuint - (cpuint & GetMaskByte32(cpuPPCInit_Addx))) == ConvertBitToByte32(cpuPPCInit_Addx)) - //{ - // retsize = PPC_Addx( outfp, cpu_buffer, cpu_pos, cpu_size, - // BaseAddress, cpuarch, mode); - // if (retsize<0) - // retcode = 1; - // else - // cpu_pos += retsize; - //} /* 0x38 Ld aslo known as Li */ if ((cpuint - (cpuint & GetMaskByte32(cpuPPCInit_Ld))) == ConvertBitToByte32(cpuPPCInit_Ld)) diff --git a/rosapps/devutils/cputointel/From/PPC/PPCBrain.h b/rosapps/devutils/cputointel/From/PPC/PPCBrain.h index 1cfbdb1ca61..82129e7c3c8 100644 --- a/rosapps/devutils/cputointel/From/PPC/PPCBrain.h +++ b/rosapps/devutils/cputointel/From/PPC/PPCBrain.h @@ -8,7 +8,7 @@ * the opcode. but a opcode have also normal bit that is always been set to * same. thuse bit are always 0 or 1 */ -CPU_BYTE cpuPPCInit_Addx[32] = {2,0,1,0,1,0,0,0,0,1,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,1,1,1,1,1,0}; + CPU_BYTE cpuPPCInit_Blr[32] = {0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,1,0,0,1,1,1,0}; diff --git a/rosapps/devutils/cputointel/From/PPC/PPCopcode.c b/rosapps/devutils/cputointel/From/PPC/PPCopcode.c index 33562764891..44640099f2b 100644 --- a/rosapps/devutils/cputointel/From/PPC/PPCopcode.c +++ b/rosapps/devutils/cputointel/From/PPC/PPCopcode.c @@ -27,22 +27,7 @@ * value +1 and higher : who many byte we should add to cpu_pos */ -CPU_INT PPC_Addx( FILE *out, CPU_BYTE * cpu_buffer, CPU_UNINT cpu_pos, - CPU_UNINT cpu_size, CPU_UNINT BaseAddress, CPU_UNINT cpuarch, - CPU_INT mode) -{ - /* - * ConvertBitToByte() is perfect to use to get the bit being in use from a bit array - * GetMaskByte() is perfect if u whant known which bit have been mask out - * see M68kopcode.c and how it use the ConvertBitToByte() - */ - - fprintf(out,"Line_0x%8x :\n",BaseAddress + cpu_pos); - - printf(";Add unimplement\n"); - return -1; -} CPU_INT PPC_Blr( FILE *out, CPU_BYTE * cpu_buffer, CPU_UNINT cpu_pos, CPU_UNINT cpu_size, CPU_UNINT BaseAddress, CPU_UNINT cpuarch,