6 #include "../../misc.h"
9 * DummyBrain is example how you create you own cpu brain to translate from
10 * cpu to intel assembler, I have not add DummyBrain to the loader it is not
11 * need it in our example. When you write you own brain, it must be setup in
12 * misc.c function LoadPFileImage and PEFileStart, PEFileStart maybe does not
13 * need the brain you have writen so you do not need setup it there then.
16 * cpu_buffer : the memory buffer with loaded program we whant translate
17 * cpu_pos : the positions in the cpu_buffer
18 * cpu_size : the alloced memory size of the cpu_buffer
19 * BaseAddress : the virtual memory address we setup to use.
20 * cpuarch : the sub arch for the brain, example if it exists more one
21 * cpu with same desgin but few other opcode or extend opcode
22 * outfp : the output file pointer
24 * mode : if we should run disambler of this binary or
25 * translate it, Disambler will not calc the
26 * the row name right so we simple give each
27 row a name. In translations mode we run a
28 * analys so we getting better optimzing and
29 * only row name there we need.
30 * value for mode are :
32 * 1 = translate mode intel
42 CPU_INT
PPCBrain( CPU_BYTE
*cpu_buffer
,
45 CPU_UNINT BaseAddress
,
54 /* now we start the process */
55 while (cpu_pos
<cpu_size
)
59 cpuint
= GetData32Le(&cpu_buffer
[cpu_pos
]);
62 if ((cpuint
- (cpuint
& GetMaskByte32(cpuPPCInit_Blr
))) == ConvertBitToByte32(cpuPPCInit_Blr
))
64 retsize
= PPC_Blr( outfp
, cpu_buffer
, cpu_pos
, cpu_size
,
65 BaseAddress
, cpuarch
);
73 if ((cpuint
- (cpuint
& GetMaskByte32(cpuPPCInit_Li
))) == ConvertBitToByte32(cpuPPCInit_Li
))
75 retsize
= PPC_Li( outfp
, cpu_buffer
, cpu_pos
, cpu_size
,
76 BaseAddress
, cpuarch
);
84 if ((cpuint
- (cpuint
& GetMaskByte32(cpuPPCInit_mr
))) == ConvertBitToByte32(cpuPPCInit_mr
))
86 retsize
= PPC_mr( outfp
, cpu_buffer
, cpu_pos
, cpu_size
,
87 BaseAddress
, cpuarch
);
95 if ((cpuint
- (cpuint
& GetMaskByte32(cpuPPCInit_stw
))) == ConvertBitToByte32(cpuPPCInit_stw
))
97 retsize
= PPC_Stw( outfp
, cpu_buffer
, cpu_pos
, cpu_size
,
98 BaseAddress
, cpuarch
);
106 if ((cpuint
- (cpuint
& GetMaskByte32(cpuPPCInit_stwu
))) == ConvertBitToByte32(cpuPPCInit_stwu
))
108 retsize
= PPC_Stwu( outfp
, cpu_buffer
, cpu_pos
, cpu_size
,
109 BaseAddress
, cpuarch
);
116 /* Found all Opcode and breakout and return no error found */
117 if (cpu_pos
>=cpu_size
)
122 /* Check if we have found a cpu opcode */
123 if (cpu_oldpos
== cpu_pos
)
127 /* no unimplement error where found so we return a msg for unknown opcode */
128 printf("Unkonwn Opcode found at 0x%8x opcode 0x%2x\n",cpu_oldpos
+BaseAddress
,(unsigned int)cpu_buffer
[cpu_oldpos
]);
136 /* Erorro Found break and return the error code */
141 return 0; // hack getting dismabler working or converting working