fix include file case
[reactos.git] / rosapps / devutils / cputointel / From / PPC / PPCopcode.c
1
2 #include <stdio.h>
3 #include <stdlib.h>
4 #include "PPC.h"
5 #include "../../misc.h"
6 #include "../../any_op.h"
7
8 /* reg r0-r31
9 r3 = eax
10 */
11
12 /* cpuDummyInit_Add
13 * Input param :
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.
23 *
24 * Return value :
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
28 */
29
30 /* Get Dest register */
31 #define PPC_GetBitArraySrcReg(opcode) (((opcode & 0x3) << 3) | ((opcode & 0xE000) >> 13))
32
33 /* Get Source register */
34 CPU_UNINT PPC_GetBitArrayBto31xx(CPU_UNINT opcode)
35 {
36 CPU_INT x1;
37
38 /* FIXME make it to a macro
39 * not tested to 100% yet */
40 x1 = ((opcode & 0x1F00)>>8);
41 return x1;
42 }
43
44
45 CPU_UNINT PPC_GetBitArrayBto31(CPU_UNINT opcode)
46 {
47 CPU_INT x1;
48 /* FIXME make it to a macro
49 * not tested to 100% yet */
50 x1 = ((opcode & 0xFFFF0000)>>16);
51 return x1;
52 }
53
54
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)
57 {
58
59 BaseAddress +=cpu_pos;
60
61 /* own translatons langues */
62 if (AllocAny()!=0) /* alloc memory for pMyBrainAnalys */
63 {
64 return -1;
65 }
66 pMyBrainAnalys->op = OP_ANY_ret;
67 pMyBrainAnalys->memAdr=BaseAddress;
68
69 return 4;
70 }
71
72
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)
75 {
76 CPU_UNINT opcode;
77
78 opcode = GetData32Le(&cpu_buffer[cpu_pos]);
79
80 BaseAddress +=cpu_pos;
81
82 /* own translatons langues */
83 if (AllocAny()!=0) /* alloc memory for pMyBrainAnalys */
84 {
85 return -1;
86 }
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;
93
94 return 4;
95 }
96
97
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)
100 {
101 CPU_UNINT opcode;
102
103 opcode = GetData32Le(&cpu_buffer[cpu_pos]);
104
105 BaseAddress +=cpu_pos;
106
107 /* own translatons langues */
108 if (AllocAny()!=0) /* alloc memory for pMyBrainAnalys */
109 {
110 return -1;
111 }
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;
118
119 return 4;
120 }
121
122
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)
125 {
126 /* r1 store at -0x20(r1) */
127
128 CPU_UNINT opcode;
129 CPU_SHORT tmp = 0;
130
131 opcode = GetData32Le(&cpu_buffer[cpu_pos]);
132
133 BaseAddress +=cpu_pos;
134
135 /* own translatons langues */
136 if (AllocAny()!=0) /* alloc memory for pMyBrainAnalys */
137 {
138 return -1;
139 }
140
141 tmp = _byteswap_ushort( ((CPU_SHORT)((opcode >> 16) & 0xffff)));
142
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;
151
152 return 4;
153 }
154
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)
157 {
158 /* r1 store at -0x20(r1) */
159
160 CPU_UNINT opcode;
161 CPU_INT DstReg;
162 CPU_SHORT tmp = 0;
163
164 opcode = GetData32Le(&cpu_buffer[cpu_pos]);
165
166 DstReg = PPC_GetBitArrayBto31xx(opcode);
167 if (DstReg == 0)
168 {
169 return 0;
170 }
171
172 BaseAddress +=cpu_pos;
173
174 /* own translatons langues */
175 if (AllocAny()!=0) /* alloc memory for pMyBrainAnalys */
176 {
177 return -1;
178 }
179
180 tmp = _byteswap_ushort( ((CPU_SHORT)((opcode >> 16) & 0xffff)));
181
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;
190
191 return 4;
192 }