5 #include "../../misc.h"
6 #include "../../any_op.h"
14 * out : The file pointer that we write to (the output file to intel asm)
15 * cpu_buffer : The memory buffer we have our binary code that we whant convert
16 * cpu_pos : Current positions in the cpu_buffer
17 * cpu_size : The memory size of the cpu_buffer
18 * BaseAddress : The base address you whant the binay file should run from
19 * cpuarch : if it exists diffent cpu from a manufactor like pentium,
20 * pentinum-mmx so on, use this flag to specify which type
21 * of cpu you whant or do not use it if it does not exists
22 * other or any sub model.
25 * value -1 : unimplement
26 * value 0 : wrong opcode or not vaild opcode
27 * value +1 and higher : who many byte we should add to cpu_pos
30 /* Get Dest register */
31 #define PPC_GetBitArraySrcReg(opcode) (((opcode & 0x3) << 3) | ((opcode & 0xE000) >> 13))
33 /* Get Source register */
34 CPU_UNINT
PPC_GetBitArrayBto31xx(CPU_UNINT opcode
)
38 /* FIXME make it to a macro
39 * not tested to 100% yet */
40 x1
= ((opcode
& 0x1F00)>>8);
45 CPU_UNINT
PPC_GetBitArrayBto31(CPU_UNINT opcode
)
48 /* FIXME make it to a macro
49 * not tested to 100% yet */
50 x1
= ((opcode
& 0xFFFF0000)>>16);
55 CPU_INT
PPC_Blr( FILE *out
, CPU_BYTE
* cpu_buffer
, CPU_UNINT cpu_pos
,
56 CPU_UNINT cpu_size
, CPU_UNINT BaseAddress
, CPU_UNINT cpuarch
)
59 BaseAddress
+=cpu_pos
;
61 /* own translatons langues */
62 if (AllocAny()!=0) /* alloc memory for pMyBrainAnalys */
66 pMyBrainAnalys
->op
= OP_ANY_ret
;
67 pMyBrainAnalys
->memAdr
=BaseAddress
;
73 CPU_INT
PPC_Li( FILE *out
, CPU_BYTE
* cpu_buffer
, CPU_UNINT cpu_pos
,
74 CPU_UNINT cpu_size
, CPU_UNINT BaseAddress
, CPU_UNINT cpuarch
)
78 opcode
= GetData32Le(&cpu_buffer
[cpu_pos
]);
80 BaseAddress
+=cpu_pos
;
82 /* own translatons langues */
83 if (AllocAny()!=0) /* alloc memory for pMyBrainAnalys */
87 pMyBrainAnalys
->op
= OP_ANY_mov
;
88 pMyBrainAnalys
->type
= 8 + 16; /* 8 dst reg, 16 imm */
89 pMyBrainAnalys
->src_size
= 16;
90 pMyBrainAnalys
->src
= PPC_GetBitArraySrcReg(opcode
);
91 pMyBrainAnalys
->dst
= PPC_GetBitArrayBto31(opcode
);
92 pMyBrainAnalys
->memAdr
=BaseAddress
;
98 CPU_INT
PPC_mr( FILE *out
, CPU_BYTE
* cpu_buffer
, CPU_UNINT cpu_pos
,
99 CPU_UNINT cpu_size
, CPU_UNINT BaseAddress
, CPU_UNINT cpuarch
)
103 opcode
= GetData32Le(&cpu_buffer
[cpu_pos
]);
105 BaseAddress
+=cpu_pos
;
107 /* own translatons langues */
108 if (AllocAny()!=0) /* alloc memory for pMyBrainAnalys */
112 pMyBrainAnalys
->op
= OP_ANY_mov
;
113 pMyBrainAnalys
->type
= 2 + 8; /* 8 dst reg, 2 src reg */
114 pMyBrainAnalys
->src_size
= 32;
115 pMyBrainAnalys
->src
= PPC_GetBitArraySrcReg(opcode
);
116 pMyBrainAnalys
->dst
= PPC_GetBitArrayBto31xx(opcode
);
117 pMyBrainAnalys
->memAdr
=BaseAddress
;
123 CPU_INT
PPC_Stw( FILE *out
, CPU_BYTE
* cpu_buffer
, CPU_UNINT cpu_pos
,
124 CPU_UNINT cpu_size
, CPU_UNINT BaseAddress
, CPU_UNINT cpuarch
)
126 /* r1 store at -0x20(r1) */
131 opcode
= GetData32Le(&cpu_buffer
[cpu_pos
]);
133 BaseAddress
+=cpu_pos
;
135 /* own translatons langues */
136 if (AllocAny()!=0) /* alloc memory for pMyBrainAnalys */
141 tmp
= _byteswap_ushort( ((CPU_SHORT
)((opcode
>> 16) & 0xffff)));
143 pMyBrainAnalys
->op
= OP_ANY_mov
;
144 pMyBrainAnalys
->type
= 2 + 64;
145 pMyBrainAnalys
->src_size
= 32;
146 pMyBrainAnalys
->dst_size
= 32;
147 pMyBrainAnalys
->src
= PPC_GetBitArraySrcReg(opcode
);
148 pMyBrainAnalys
->dst
= PPC_GetBitArrayBto31xx(opcode
);
149 pMyBrainAnalys
-> dst_extra
= tmp
;
150 pMyBrainAnalys
->memAdr
=BaseAddress
;
155 CPU_INT
PPC_Stwu( FILE *out
, CPU_BYTE
* cpu_buffer
, CPU_UNINT cpu_pos
,
156 CPU_UNINT cpu_size
, CPU_UNINT BaseAddress
, CPU_UNINT cpuarch
)
158 /* r1 store at -0x20(r1) */
164 opcode
= GetData32Le(&cpu_buffer
[cpu_pos
]);
166 DstReg
= PPC_GetBitArrayBto31xx(opcode
);
172 BaseAddress
+=cpu_pos
;
174 /* own translatons langues */
175 if (AllocAny()!=0) /* alloc memory for pMyBrainAnalys */
180 tmp
= _byteswap_ushort( ((CPU_SHORT
)((opcode
>> 16) & 0xffff)));
182 pMyBrainAnalys
->op
= OP_ANY_mov
;
183 pMyBrainAnalys
->type
= 2 + 64 + 128;
184 pMyBrainAnalys
->src_size
= 32;
185 pMyBrainAnalys
->dst_size
= 32;
186 pMyBrainAnalys
->src
= PPC_GetBitArraySrcReg(opcode
);
187 pMyBrainAnalys
->dst
= DstReg
;
188 pMyBrainAnalys
-> dst_extra
= tmp
;
189 pMyBrainAnalys
->memAdr
=BaseAddress
;