Author: greatlrd
Date: Fri Jan 19 11:20:42 2007
New Revision: 25527
URL:
http://svn.reactos.org/svn/reactos?rev=25527&view=rev
Log:
Fixing the src and dst of register so they are being read right (PPC brain)
Adding stw for dissembler and converting (PPC and IA32)
Fixing a counter bug in ConvertBitToByte, ConvertBitToByte32, GetMaskByte, GetMaskByte32
we did miss one bit calculation when we count the mask the bit 0
Modified:
trunk/rosapps/devutils/cputointel/ConvertToIA32Process.c
trunk/rosapps/devutils/cputointel/ConvertingProcess.c
trunk/rosapps/devutils/cputointel/CpuToIntel.c
trunk/rosapps/devutils/cputointel/From/PPC/PPC.h
trunk/rosapps/devutils/cputointel/From/PPC/PPCBrain.c
trunk/rosapps/devutils/cputointel/From/PPC/PPCBrain.h
trunk/rosapps/devutils/cputointel/From/PPC/PPCopcode.c
trunk/rosapps/devutils/cputointel/ImageLoader.c
trunk/rosapps/devutils/cputointel/OpCodePPC.txt
trunk/rosapps/devutils/cputointel/misc.c
Modified: trunk/rosapps/devutils/cputointel/ConvertToIA32Process.c
URL:
http://svn.reactos.org/svn/reactos/trunk/rosapps/devutils/cputointel/Conver…
==============================================================================
--- trunk/rosapps/devutils/cputointel/ConvertToIA32Process.c (original)
+++ trunk/rosapps/devutils/cputointel/ConvertToIA32Process.c Fri Jan 19 11:20:42 2007
@@ -28,7 +28,7 @@
* mmx/sse/fpu 7 = 28
*/
-static void standardreg(CPU_INT *RegTableCount, CPU_UNINT reg, CPU_INT setup_ebp, FILE
*outfp)
+static void standardreg(CPU_INT *RegTableCount, CPU_INT reg, CPU_INT setup_ebp, FILE
*outfp)
{
/* eax */
if (reg == RegTableCount[3])
@@ -66,7 +66,7 @@
fprintf(outfp,"esi");
}
/* edi */
- else if (reg == RegTableCount[10])
+ else if (reg == RegTableCount[11])
{
fprintf(outfp,"edi");
}
@@ -194,7 +194,11 @@
standardreg( RegTableCount,
pMystart->dst,
setup_ebp, outfp);
- fprintf(outfp," %d], ",pMystart->dst_extra);
+ if (pMystart->dst_extra>=0)
+ fprintf(outfp," +%d], ",pMystart->dst_extra);
+ else
+ fprintf(outfp," %d], ",pMystart->dst_extra);
+
standardreg( RegTableCount,
pMystart->src,
setup_ebp, outfp);
Modified: trunk/rosapps/devutils/cputointel/ConvertingProcess.c
URL:
http://svn.reactos.org/svn/reactos/trunk/rosapps/devutils/cputointel/Conver…
==============================================================================
--- trunk/rosapps/devutils/cputointel/ConvertingProcess.c (original)
+++ trunk/rosapps/devutils/cputointel/ConvertingProcess.c Fri Jan 19 11:20:42 2007
@@ -42,13 +42,19 @@
if ((ptmpMystart->type & 8) == 8)
RegTableCount[ptmpMystart->dst]++;
+ if ((ptmpMystart->type & 32) == 32)
+ RegTableCount[ptmpMystart->src]++;
+
+ if ((ptmpMystart->type & 64) == 64)
+ RegTableCount[ptmpMystart->dst]++;
+
if (ptmpMystart == ptmpMyend)
ptmpMystart=NULL;
else
ptmpMystart = (PMYBrainAnalys) ptmpMystart->ptr_next;
}
- for (t=0;t<31;t++)
+ for (t=0;t<=31;t++)
{
if (RegTableCount[t]!=0)
{
Modified: trunk/rosapps/devutils/cputointel/CpuToIntel.c
URL:
http://svn.reactos.org/svn/reactos/trunk/rosapps/devutils/cputointel/CpuToI…
==============================================================================
--- trunk/rosapps/devutils/cputointel/CpuToIntel.c (original)
+++ trunk/rosapps/devutils/cputointel/CpuToIntel.c Fri Jan 19 11:20:42 2007
@@ -94,8 +94,11 @@
//}
+ // mode 0 disambler
+ // mode 1 convert to intel
+ // mode 2 convert to ppc
//return LoadPFileImage(infile,outfile,BaseAddress,cpuid,type, mode);
- return
LoadPFileImage("e:\\testppc.exe","e:\\cputointel.asm",0,0,0,1); //
disambler
+ return
LoadPFileImage("e:\\testppc.exe","e:\\cputointel.asm",0,0,0,1);
// return
LoadPFileImage("e:\\testms.exe","e:\\cputointel.asm",0,0,0,1); //
convert
}
Modified: trunk/rosapps/devutils/cputointel/From/PPC/PPC.h
URL:
http://svn.reactos.org/svn/reactos/trunk/rosapps/devutils/cputointel/From/P…
==============================================================================
--- trunk/rosapps/devutils/cputointel/From/PPC/PPC.h (original)
+++ trunk/rosapps/devutils/cputointel/From/PPC/PPC.h Fri Jan 19 11:20:42 2007
@@ -12,6 +12,7 @@
/* here we put the prototype for the opcode api that brain need we show a example for it
*/
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_Li( FILE *out, CPU_BYTE * cpu_buffer, CPU_UNINT cpu_pos, CPU_UNINT cpu_size,
CPU_UNINT BaseAddress, CPU_UNINT cpuarch);
+CPU_INT PPC_Stw( FILE *out, CPU_BYTE * cpu_buffer, CPU_UNINT cpu_pos, CPU_UNINT cpu_size,
CPU_UNINT BaseAddress, CPU_UNINT cpuarch);
CPU_INT PPC_Stwu( 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
Modified: trunk/rosapps/devutils/cputointel/From/PPC/PPCBrain.c
URL:
http://svn.reactos.org/svn/reactos/trunk/rosapps/devutils/cputointel/From/P…
==============================================================================
--- trunk/rosapps/devutils/cputointel/From/PPC/PPCBrain.c (original)
+++ trunk/rosapps/devutils/cputointel/From/PPC/PPCBrain.c Fri Jan 19 11:20:42 2007
@@ -80,6 +80,18 @@
cpu_pos += retsize;
}
+ /* stw */
+ if ((cpuint - (cpuint & GetMaskByte32(cpuPPCInit_stw))) ==
ConvertBitToByte32(cpuPPCInit_stw))
+ {
+ retsize = PPC_Stw( outfp, cpu_buffer, cpu_pos, cpu_size,
+ BaseAddress, cpuarch);
+ if (retsize<0)
+ retcode = 1;
+ else
+ cpu_pos += retsize;
+ }
+ retcode = 0;
+
/* stwu */
if ((cpuint - (cpuint & GetMaskByte32(cpuPPCInit_stwu))) ==
ConvertBitToByte32(cpuPPCInit_stwu))
{
@@ -116,6 +128,6 @@
}
}
-// return 0; // hack getting dismabler working or converting working
+ return 0; // hack getting dismabler working or converting working
return retcode;
}
Modified: trunk/rosapps/devutils/cputointel/From/PPC/PPCBrain.h
URL:
http://svn.reactos.org/svn/reactos/trunk/rosapps/devutils/cputointel/From/P…
==============================================================================
--- trunk/rosapps/devutils/cputointel/From/PPC/PPCBrain.h (original)
+++ trunk/rosapps/devutils/cputointel/From/PPC/PPCBrain.h Fri Jan 19 11:20:42 2007
@@ -12,6 +12,7 @@
/* FIXME RA should be 0 in stwu */
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_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};
+CPU_BYTE cpuPPCInit_stw[32] =
{2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,1,0,0,1,0,0,2,2};
CPU_BYTE cpuPPCInit_stwu[32] =
{2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,1,0,0,1,0,1,2,2};
/* mask */
/*
Modified: trunk/rosapps/devutils/cputointel/From/PPC/PPCopcode.c
URL:
http://svn.reactos.org/svn/reactos/trunk/rosapps/devutils/cputointel/From/P…
==============================================================================
--- trunk/rosapps/devutils/cputointel/From/PPC/PPCopcode.c (original)
+++ trunk/rosapps/devutils/cputointel/From/PPC/PPCopcode.c Fri Jan 19 11:20:42 2007
@@ -28,7 +28,7 @@
*/
/* Get Dest register */
-#define PPC_GetBitArrayDstReg(opcode) (((opcode & 0x3) << 3) | ((opcode &
0xE000) >> 13))
+#define PPC_GetBitArraySrcReg(opcode) (((opcode & 0x3) << 3) | ((opcode &
0xE000) >> 13))
/* Get Source register */
CPU_UNINT PPC_GetBitArrayBto31xx(CPU_UNINT opcode)
@@ -75,7 +75,7 @@
{
CPU_UNINT opcode;
- opcode = GetData32Le(cpu_buffer);
+ opcode = GetData32Le(&cpu_buffer[cpu_pos]);
BaseAddress +=cpu_pos;
@@ -87,13 +87,45 @@
pMyBrainAnalys->op = OP_ANY_mov;
pMyBrainAnalys->type= 8 + 16; /* 8 dst reg, 16 imm */
pMyBrainAnalys->src_size = 16;
- pMyBrainAnalys->src = PPC_GetBitArrayBto31(opcode);
- pMyBrainAnalys->dst = PPC_GetBitArrayDstReg(opcode);
+ pMyBrainAnalys->src = PPC_GetBitArraySrcReg(opcode);
+ pMyBrainAnalys->dst = PPC_GetBitArrayBto31(opcode);
pMyBrainAnalys->memAdr=BaseAddress;
return 4;
}
+
+CPU_INT PPC_Stw( FILE *out, CPU_BYTE * cpu_buffer, CPU_UNINT cpu_pos,
+ CPU_UNINT cpu_size, CPU_UNINT BaseAddress, CPU_UNINT cpuarch)
+{
+ /* r1 store at -0x20(r1) */
+
+ CPU_UNINT opcode;
+ CPU_SHORT tmp = 0;
+
+ opcode = GetData32Le(&cpu_buffer[cpu_pos]);
+
+ BaseAddress +=cpu_pos;
+
+ /* own translatons langues */
+ if (AllocAny()!=0) /* alloc memory for pMyBrainAnalys */
+ {
+ return -1;
+ }
+
+ tmp = _byteswap_ushort( ((CPU_SHORT)((opcode >> 16) & 0xffff)));
+
+ pMyBrainAnalys->op = OP_ANY_mov;
+ pMyBrainAnalys->type= 2 + 64;
+ pMyBrainAnalys->src_size = 32;
+ pMyBrainAnalys->dst_size = 32;
+ pMyBrainAnalys->src = PPC_GetBitArraySrcReg(opcode);
+ pMyBrainAnalys->dst = PPC_GetBitArrayBto31xx(opcode);
+ pMyBrainAnalys-> dst_extra = tmp;
+ pMyBrainAnalys->memAdr=BaseAddress;
+
+ return 4;
+}
CPU_INT PPC_Stwu( FILE *out, CPU_BYTE * cpu_buffer, CPU_UNINT cpu_pos,
CPU_UNINT cpu_size, CPU_UNINT BaseAddress, CPU_UNINT cpuarch)
@@ -101,9 +133,16 @@
/* r1 store at -0x20(r1) */
CPU_UNINT opcode;
+ CPU_INT DstReg;
CPU_SHORT tmp = 0;
- opcode = GetData32Le(cpu_buffer);
+ opcode = GetData32Le(&cpu_buffer[cpu_pos]);
+
+ DstReg = PPC_GetBitArrayBto31xx(opcode);
+ if (DstReg == 0)
+ {
+ return 0;
+ }
BaseAddress +=cpu_pos;
@@ -119,8 +158,8 @@
pMyBrainAnalys->type= 2 + 64 + 128;
pMyBrainAnalys->src_size = 32;
pMyBrainAnalys->dst_size = 32;
- pMyBrainAnalys->src = PPC_GetBitArrayBto31xx(opcode);
- pMyBrainAnalys->dst = PPC_GetBitArrayDstReg(opcode);
+ pMyBrainAnalys->src = PPC_GetBitArraySrcReg(opcode);
+ pMyBrainAnalys->dst = DstReg;
pMyBrainAnalys-> dst_extra = tmp;
pMyBrainAnalys->memAdr=BaseAddress;
Modified: trunk/rosapps/devutils/cputointel/ImageLoader.c
URL:
http://svn.reactos.org/svn/reactos/trunk/rosapps/devutils/cputointel/ImageL…
==============================================================================
--- trunk/rosapps/devutils/cputointel/ImageLoader.c (original)
+++ trunk/rosapps/devutils/cputointel/ImageLoader.c Fri Jan 19 11:20:42 2007
@@ -485,7 +485,8 @@
fprintf(outfp,"; CPU found POWERPC\n");
//PPCBrain(memory, pos, cpu_size, base, 0, outfp);
machine_type = IMAGE_FILE_MACHINE_POWERPC;
- return PPCBrain(memory+SectionHeader->PointerToRawData, 0,
SectionHeader->SizeOfRawData, 0, 0, outfp);
+ PPCBrain(memory+SectionHeader->PointerToRawData, 0,
SectionHeader->SizeOfRawData, 0, 0, outfp);
+ break;
case IMAGE_FILE_MACHINE_POWERPCFP:
Modified: trunk/rosapps/devutils/cputointel/OpCodePPC.txt
URL:
http://svn.reactos.org/svn/reactos/trunk/rosapps/devutils/cputointel/OpCode…
==============================================================================
--- trunk/rosapps/devutils/cputointel/OpCodePPC.txt (original)
+++ trunk/rosapps/devutils/cputointel/OpCodePPC.txt Fri Jan 19 11:20:42 2007
@@ -9,11 +9,15 @@
1 = mean bit is set
2 = mean this bit can be 0 or 1
-opcode Name Desciptions
-0010 0000 0000 0000 1000 0000 0100 1110 blr return from a functions
+opcode Name Desciptions
+0010 0000 0000 0000 1000 0000 0100 1110 blr return from a functions
-0222 2222 2222 2222 2222 2222 0011 1000 Li reg,#imm move a value to a register
+0222 2222 2222 2222 2222 2222 0011 1000 Li reg,#imm move a value to a register
+2222 2222 2222 2222 2222 2222 1001 0022 stw reg,mem store a value into memory
+
+2222 2222 2222 2222 2222 2222 1001 0122 stwu reg,mem store contain of reg to memory
and
+ move reg to that memory
position
Modified: trunk/rosapps/devutils/cputointel/misc.c
URL:
http://svn.reactos.org/svn/reactos/trunk/rosapps/devutils/cputointel/misc.c…
==============================================================================
--- trunk/rosapps/devutils/cputointel/misc.c (original)
+++ trunk/rosapps/devutils/cputointel/misc.c Fri Jan 19 11:20:42 2007
@@ -36,10 +36,10 @@
CPU_UNINT ConvertBitToByte(CPU_BYTE *bit)
{
CPU_UNINT Byte = 0;
- CPU_UNINT t;
+ CPU_INT t;
CPU_UNINT size = 15;
- for(t=size;t>0;t--)
+ for(t=size;t>=0;t--)
{
if (bit[size-t] != 2)
Byte = Byte + (bit[size-t]<<t);
@@ -51,10 +51,10 @@
CPU_UNINT GetMaskByte(CPU_BYTE *bit)
{
CPU_UNINT MaskByte = 0;
- CPU_UNINT t;
+ CPU_INT t;
CPU_UNINT size = 15;
- for(t=size;t>0;t--)
+ for(t=size;t>=0;t--)
{
if (bit[size-t] == 2)
{
@@ -68,10 +68,10 @@
CPU_UNINT ConvertBitToByte32(CPU_BYTE *bit)
{
CPU_UNINT Byte = 0;
- CPU_UNINT t;
+ CPU_INT t;
CPU_UNINT size = 31;
- for(t=size;t>0;t--)
+ for(t=size;t>=0;t--)
{
if (bit[size-t] != 2)
Byte = Byte + (bit[size-t]<<t);
@@ -83,10 +83,10 @@
CPU_UNINT GetMaskByte32(CPU_BYTE *bit)
{
CPU_UNINT MaskByte = 0;
- CPU_UNINT t;
+ CPU_INT t;
CPU_UNINT size = 31;
- for(t=size;t>0;t--)
+ for(t=size;t>=0;t--)
{
if (bit[size-t] == 2)
{