From e6cfb666caa06e2e2dc0c0cfcaaad308830201b6 Mon Sep 17 00:00:00 2001 From: Magnus Olsen Date: Thu, 18 Jan 2007 15:40:37 +0000 Subject: [PATCH] Fixing some ppc disambler bugs. Li are not 100% test it can contain some fault. Fixing Li bug the register for dest was wrong calctions see file OpCodePPC.txt. fixing some meaing in ReadMe.txt svn path=/trunk/; revision=25511 --- rosapps/devutils/cputointel/From/PPC/PPC.h | 7 ++-- .../devutils/cputointel/From/PPC/PPCBrain.c | 6 ++-- .../devutils/cputointel/From/PPC/PPCBrain.h | 13 +++++--- .../devutils/cputointel/From/PPC/PPCopcode.c | 33 ++++++++++--------- rosapps/devutils/cputointel/OpCodePPC.txt | 12 +++---- rosapps/devutils/cputointel/ReadMe.txt | 23 +++++++------ 6 files changed, 50 insertions(+), 44 deletions(-) diff --git a/rosapps/devutils/cputointel/From/PPC/PPC.h b/rosapps/devutils/cputointel/From/PPC/PPC.h index ff29428a251..169c53ae6b8 100644 --- a/rosapps/devutils/cputointel/From/PPC/PPC.h +++ b/rosapps/devutils/cputointel/From/PPC/PPC.h @@ -10,14 +10,11 @@ CPU_INT PPCBrain( CPU_BYTE *cpu_buffer, /* here we put the prototype for the opcode api that brain need we show a example for it */ -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 PPC_Blr( FILE *out, CPU_BYTE * cpu_buffer, CPU_UNINT cpu_pos, CPU_UNINT cpu_size, CPU_UNINT BaseAddress, CPU_UNINT cpuarch); -CPU_INT PPC_Ld( FILE *out, CPU_BYTE * cpu_buffer, CPU_UNINT cpu_pos, CPU_UNINT cpu_size, CPU_UNINT BaseAddress, CPU_UNINT cpuarch); +CPU_INT PPC_Li( FILE *out, CPU_BYTE * cpu_buffer, CPU_UNINT cpu_pos, CPU_UNINT cpu_size, CPU_UNINT BaseAddress, CPU_UNINT cpuarch); /* Export comment thing see m68k for example * in dummy we do not show it, for it is diffent for each cpu */ -extern CPU_BYTE PPC_D[32]; -extern CPU_BYTE PPC_A[32]; -extern CPU_BYTE PPC_ds[32]; + diff --git a/rosapps/devutils/cputointel/From/PPC/PPCBrain.c b/rosapps/devutils/cputointel/From/PPC/PPCBrain.c index 2f8a8ec72fe..0c95fc09b94 100644 --- a/rosapps/devutils/cputointel/From/PPC/PPCBrain.c +++ b/rosapps/devutils/cputointel/From/PPC/PPCBrain.c @@ -59,10 +59,10 @@ CPU_INT PPCBrain( CPU_BYTE *cpu_buffer, cpuint = GetData32Le(&cpu_buffer[cpu_pos]); - /* 0x38 Ld aslo known as Li */ - if ((cpuint - (cpuint & GetMaskByte32(cpuPPCInit_Ld))) == ConvertBitToByte32(cpuPPCInit_Ld)) + /* 0xE = Li*/ + if ((cpuint - (cpuint & GetMaskByte32(cpuPPCInit_Li))) == ConvertBitToByte32(cpuPPCInit_Li)) { - retsize = PPC_Ld( outfp, cpu_buffer, cpu_pos, cpu_size, + retsize = PPC_Li( outfp, cpu_buffer, cpu_pos, cpu_size, BaseAddress, cpuarch); if (retsize<0) retcode = 1; diff --git a/rosapps/devutils/cputointel/From/PPC/PPCBrain.h b/rosapps/devutils/cputointel/From/PPC/PPCBrain.h index 82129e7c3c8..4232c36b8d4 100644 --- a/rosapps/devutils/cputointel/From/PPC/PPCBrain.h +++ b/rosapps/devutils/cputointel/From/PPC/PPCBrain.h @@ -12,14 +12,17 @@ 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}; -CPU_BYTE cpuPPCInit_Ld[32] = {0,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,0,0,1,1,1,0,0,0}; -CPU_BYTE cpuPPCInit_Ldu[32] = {1,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,0,0,1,1,1,0,0,0}; +/* xxxx xxxx xxxx xxxx DDD0 0000 xxxx xxDD + * 2222 2222 2222 2222 2222 2222 0011 1022 Li + */ +CPU_BYTE cpuPPCInit_Li[32] = {2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,0,0,0,0,0,0,0,1,1, 1,0,2,2}; + /* mask */ -CPU_BYTE PPC_D[32] = {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1,1,1,1,0,0,0,0,0,0}; -CPU_BYTE PPC_A[32] = {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1,1,1,1,0,0,0,0,0,0,0,0,0,0,0}; -CPU_BYTE PPC_ds[32] = {0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}; +/* + * no mask we implement function getting the reg right + */ /* bit index 3 3 2 2 2 2 2 2 2 2 2 2 1 1 1 1 1 1 1 1 1 1 0 0 0 0 0 0 0 0 0 0 diff --git a/rosapps/devutils/cputointel/From/PPC/PPCopcode.c b/rosapps/devutils/cputointel/From/PPC/PPCopcode.c index bc011187d0e..2eae149614d 100644 --- a/rosapps/devutils/cputointel/From/PPC/PPCopcode.c +++ b/rosapps/devutils/cputointel/From/PPC/PPCopcode.c @@ -26,7 +26,21 @@ * value 0 : wrong opcode or not vaild opcode * value +1 and higher : who many byte we should add to cpu_pos */ - + +/* only for ppc */ +#define PPC_GetBitArray6toA(opcode) (((opcode & 0x3) << 3) | ((opcode & 0xE000) >> 13)) + + + + +CPU_UNINT PPC_GetBitArrayBto31(CPU_UNINT opcode) +{ + CPU_INT x1; + /* FIXME make it to a macro + * not tested to 100% yet */ + x1 = ((opcode & 0xFFFF0000)>>16); + return x1; +} CPU_INT PPC_Blr( FILE *out, CPU_BYTE * cpu_buffer, CPU_UNINT cpu_pos, @@ -47,23 +61,12 @@ CPU_INT PPC_Blr( FILE *out, CPU_BYTE * cpu_buffer, CPU_UNINT cpu_pos, } -CPU_INT PPC_Ld( FILE *out, CPU_BYTE * cpu_buffer, CPU_UNINT cpu_pos, +CPU_INT PPC_Li( FILE *out, CPU_BYTE * cpu_buffer, CPU_UNINT cpu_pos, CPU_UNINT cpu_size, CPU_UNINT BaseAddress, CPU_UNINT cpuarch) { - CPU_UNINT formA; - CPU_UNINT formD; - CPU_UNINT formDS; CPU_UNINT opcode; opcode = GetData32Le(cpu_buffer); - formD = (opcode & ConvertBitToByte32(PPC_D)) >> 6; - formA = (opcode & ConvertBitToByte32(PPC_A)) >> 13; - formDS = (opcode & ConvertBitToByte32(PPC_ds)) >> 15; - - if (formD != 0) - { - return 0; - } BaseAddress +=cpu_pos; @@ -75,8 +78,8 @@ CPU_INT PPC_Ld( FILE *out, CPU_BYTE * cpu_buffer, CPU_UNINT cpu_pos, pMyBrainAnalys->op = OP_ANY_mov; pMyBrainAnalys->type= 8 + 16; /* 8 dst reg, 16 imm */ pMyBrainAnalys->src_size = 16; - pMyBrainAnalys->src = formDS; - pMyBrainAnalys->dst = formA; + pMyBrainAnalys->src = PPC_GetBitArrayBto31(opcode); + pMyBrainAnalys->dst = PPC_GetBitArray6toA(opcode); pMyBrainAnalys->memAdr=BaseAddress; return 4; diff --git a/rosapps/devutils/cputointel/OpCodePPC.txt b/rosapps/devutils/cputointel/OpCodePPC.txt index 8fdb14ffc0d..2b201a671c7 100644 --- a/rosapps/devutils/cputointel/OpCodePPC.txt +++ b/rosapps/devutils/cputointel/OpCodePPC.txt @@ -20,14 +20,15 @@ opcode Name Desciptions Here how the primary opcode work xxxx xxxx xxxx xxxx DDDS SSSS 3333 33DD + 3 = it is the primary opcode D = Destions register S = Source reigters - opcode - ------------------------ - |bit order: 0123 45 67| - ------- ------- ----------- ---- + opcode + ------------------------ + |bit order: 0123 45 67| + ------- ------- ----------- ---- 34: | 0c 00 | | e1 93 | stw r31,12(r1) 0000 1100 0000 0000 1110 0001 | 1001 00 | 00 38: | 14 00 | | 01 90 | stw r0,20(r1) 0001 0100 0000 0000 0000 0001 | 1001 00 | 11 ------- ------- --------- @@ -41,8 +42,7 @@ S = Source reigters \ / The address offset 12 or 20 - - + --------------------------------------------------------- |bit order: pos 1111 1111 1111 1111 0000 0000 0000 0000 | | 89AB CDEF 0123 4567 89AB CDEF 0123 4567 | diff --git a/rosapps/devutils/cputointel/ReadMe.txt b/rosapps/devutils/cputointel/ReadMe.txt index 6fbd1668603..50ff74b71a5 100644 --- a/rosapps/devutils/cputointel/ReadMe.txt +++ b/rosapps/devutils/cputointel/ReadMe.txt @@ -2,22 +2,25 @@ CpuToIntel is a experment tools and is strict under havy devloping The Idea -The idea is to convert a binary file or win pe file +The idea is to converting binary files or win pe files from one cpu to another cpu, But it does not exists plan to port over diffent hardware architect like how diffent hw comucate, example x86 DMA controller -to PPC like. It is only to convert the the binary or -pe file to another cpu. it mean a user mode apps -will always be ported, but if it self modify code -it will not work. But it exists a idea to deal with -self modify code. +to PPC like that stuff. It is only to convert the +binary or pe files to another cpu. it mean a user +mode apps will always be ported, but if it self +modify code it will not work. But it exists idea how +to deal with self modify code. The idea to handling self modify code -The idea is to add a small emulator that -runing the apps or adding a anylasuing process -to dectect self modify code and extract it -this is hard thing todo. almost imposible +The idea is to add a small emulator or adding +anaylysing process to dectect self modify code +and extract it. This is very hard part todo, some say +imposible, some other say almost imposble. and I say +it is posible todo but extream hard todo. for it is +very diffcul to dectect self modify code with a +analysing process. Why the name are CpuToIntel