mirror of
https://github.com/reactos/reactos.git
synced 2025-08-02 06:15:52 +00:00
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 svn path=/trunk/; revision=25527
This commit is contained in:
parent
4f8fd087f7
commit
fa8f26e7c6
10 changed files with 97 additions and 26 deletions
|
@ -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 @@ static void standardreg(CPU_INT *RegTableCount, CPU_UNINT reg, CPU_INT setup_ebp
|
|||
fprintf(outfp,"esi");
|
||||
}
|
||||
/* edi */
|
||||
else if (reg == RegTableCount[10])
|
||||
else if (reg == RegTableCount[11])
|
||||
{
|
||||
fprintf(outfp,"edi");
|
||||
}
|
||||
|
@ -194,7 +194,11 @@ CPU_INT ConvertToIA32Process( FILE *outfp,
|
|||
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);
|
||||
|
|
|
@ -42,13 +42,19 @@ CPU_INT ConvertProcess(FILE *outfp, CPU_INT FromCpuid, CPU_INT ToCpuid)
|
|||
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)
|
||||
{
|
||||
|
|
|
@ -94,8 +94,11 @@ int main(int argc, char * argv[])
|
|||
|
||||
//}
|
||||
|
||||
// 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
|
||||
|
||||
}
|
||||
|
|
|
@ -12,6 +12,7 @@ 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_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
|
||||
|
|
|
@ -80,6 +80,18 @@ CPU_INT PPCBrain( CPU_BYTE *cpu_buffer,
|
|||
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 @@ CPU_INT PPCBrain( CPU_BYTE *cpu_buffer,
|
|||
}
|
||||
}
|
||||
|
||||
// return 0; // hack getting dismabler working or converting working
|
||||
return 0; // hack getting dismabler working or converting working
|
||||
return retcode;
|
||||
}
|
||||
|
|
|
@ -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 */
|
||||
/*
|
||||
|
|
|
@ -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_INT PPC_Li( FILE *out, CPU_BYTE * cpu_buffer, CPU_UNINT cpu_pos,
|
|||
{
|
||||
CPU_UNINT opcode;
|
||||
|
||||
opcode = GetData32Le(cpu_buffer);
|
||||
opcode = GetData32Le(&cpu_buffer[cpu_pos]);
|
||||
|
||||
BaseAddress +=cpu_pos;
|
||||
|
||||
|
@ -87,15 +87,15 @@ CPU_INT PPC_Li( 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 = 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_Stwu( FILE *out, CPU_BYTE * cpu_buffer, CPU_UNINT cpu_pos,
|
||||
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) */
|
||||
|
@ -103,7 +103,46 @@ CPU_INT PPC_Stwu( FILE *out, CPU_BYTE * cpu_buffer, CPU_UNINT cpu_pos,
|
|||
CPU_UNINT opcode;
|
||||
CPU_SHORT tmp = 0;
|
||||
|
||||
opcode = GetData32Le(cpu_buffer);
|
||||
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)
|
||||
{
|
||||
/* r1 store at -0x20(r1) */
|
||||
|
||||
CPU_UNINT opcode;
|
||||
CPU_INT DstReg;
|
||||
CPU_SHORT tmp = 0;
|
||||
|
||||
opcode = GetData32Le(&cpu_buffer[cpu_pos]);
|
||||
|
||||
DstReg = PPC_GetBitArrayBto31xx(opcode);
|
||||
if (DstReg == 0)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
BaseAddress +=cpu_pos;
|
||||
|
||||
|
@ -119,8 +158,8 @@ CPU_INT PPC_Stwu( FILE *out, CPU_BYTE * cpu_buffer, CPU_UNINT cpu_pos,
|
|||
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;
|
||||
|
||||
|
|
|
@ -485,7 +485,8 @@ CPU_INT PEFileStart( CPU_BYTE *memory, CPU_UNINT pos,
|
|||
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:
|
||||
|
|
|
@ -9,11 +9,15 @@ Bit expain
|
|||
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
|
||||
|
||||
|
||||
|
||||
|
|
|
@ -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 ConvertBitToByte(CPU_BYTE *bit)
|
|||
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 GetMaskByte(CPU_BYTE *bit)
|
|||
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 ConvertBitToByte32(CPU_BYTE *bit)
|
|||
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)
|
||||
{
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue