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
32 CPU_INT
M68KBrain( CPU_BYTE
*cpu_buffer
,
35 CPU_UNINT BaseAddress
,
44 /* now we start the process */
45 while (cpu_pos
<cpu_size
)
49 cpuint
= cpu_buffer
[cpu_pos
];
52 if ((cpuint
- (cpuint
& GetMaskByte(cpuM68kInit_Abcd
))) == ConvertBitToByte(cpuM68kInit_Abcd
))
54 retsize
= M68k_Abcd( outfp
, cpu_buffer
, cpu_pos
, cpu_size
,
55 BaseAddress
, cpuarch
);
62 if ((cpuint
- (cpuint
& GetMaskByte(cpuM68kInit_Add
))) == ConvertBitToByte(cpuM68kInit_Add
))
64 retsize
= M68k_Add( outfp
, cpu_buffer
, cpu_pos
, cpu_size
,
65 BaseAddress
, cpuarch
);
72 if ((cpuint
- (cpuint
& GetMaskByte(cpuM68kInit_Addi
))) == ConvertBitToByte(cpuM68kInit_Addi
))
74 retsize
= M68k_Addi( outfp
, cpu_buffer
, cpu_pos
, cpu_size
,
75 BaseAddress
, cpuarch
);
82 if ((cpuint
- (cpuint
& GetMaskByte(cpuM68kInit_Addq
))) == ConvertBitToByte(cpuM68kInit_Addq
))
84 retsize
= M68k_Addq( outfp
, cpu_buffer
, cpu_pos
, cpu_size
,
85 BaseAddress
, cpuarch
);
92 if ((cpuint
- (cpuint
& GetMaskByte(cpuM68kInit_Addx
))) == ConvertBitToByte(cpuM68kInit_Addx
))
94 retsize
= M68k_Addx( outfp
, cpu_buffer
, cpu_pos
, cpu_size
,
95 BaseAddress
, cpuarch
);
102 if ((cpuint
- (cpuint
& GetMaskByte(cpuM68kInit_And
))) == ConvertBitToByte(cpuM68kInit_And
))
104 retsize
= M68k_Add( outfp
, cpu_buffer
, cpu_pos
, cpu_size
,
105 BaseAddress
, cpuarch
);
112 if ((cpuint
- (cpuint
& GetMaskByte(cpuM68kInit_Andi
))) == ConvertBitToByte(cpuM68kInit_Andi
))
114 retsize
= M68k_Andi( outfp
, cpu_buffer
, cpu_pos
, cpu_size
,
115 BaseAddress
, cpuarch
);
122 if ((cpuint
- (cpuint
& GetMaskByte(cpuM68kInit_AndToCCRF
))) == ConvertBitToByte(cpuM68kInit_AndToCCRF
))
124 cpuint
= cpu_buffer
[cpu_pos
+1];
125 if ((cpuint
- (cpuint
& GetMaskByte(cpuM68kInit_AndToCCRS
))) == ConvertBitToByte(cpuM68kInit_AndToCCRS
))
128 retsize
= M68k_AndToCCR( outfp
, cpu_buffer
, cpu_pos
, cpu_size
,
129 BaseAddress
, cpuarch
);
137 cpuint
= cpu_buffer
[cpu_pos
];
142 if ((cpuint
- (cpuint
& GetMaskByte(cpuM68kInit_Bhi
))) == ConvertBitToByte(cpuM68kInit_Bhi
))
144 retsize
= M68k_Bhi( outfp
, cpu_buffer
, cpu_pos
, cpu_size
,
145 BaseAddress
, cpuarch
);
153 if ((cpuint
- (cpuint
& GetMaskByte(cpuM68kInit_Bls
))) == ConvertBitToByte(cpuM68kInit_Bls
))
155 retsize
= M68k_Bls( outfp
, cpu_buffer
, cpu_pos
, cpu_size
,
156 BaseAddress
, cpuarch
);
164 if ((cpuint
- (cpuint
& GetMaskByte(cpuM68kInit_Bcc
))) == ConvertBitToByte(cpuM68kInit_Bcc
))
166 retsize
= M68k_Bcc( outfp
, cpu_buffer
, cpu_pos
, cpu_size
,
167 BaseAddress
, cpuarch
);
175 if ((cpuint
- (cpuint
& GetMaskByte(cpuM68kInit_Bcs
))) == ConvertBitToByte(cpuM68kInit_Bcs
))
177 retsize
= M68k_Bcs( outfp
, cpu_buffer
, cpu_pos
, cpu_size
,
178 BaseAddress
, cpuarch
);
186 if ((cpuint
- (cpuint
& GetMaskByte(cpuM68kInit_Bne
))) == ConvertBitToByte(cpuM68kInit_Bne
))
188 retsize
= M68k_Bne( outfp
, cpu_buffer
, cpu_pos
, cpu_size
,
189 BaseAddress
, cpuarch
);
197 if ((cpuint
- (cpuint
& GetMaskByte(cpuM68kInit_Beq
))) == ConvertBitToByte(cpuM68kInit_Beq
))
199 retsize
= M68k_Beq( outfp
, cpu_buffer
, cpu_pos
, cpu_size
,
200 BaseAddress
, cpuarch
);
208 if ((cpuint
- (cpuint
& GetMaskByte(cpuM68kInit_Bvc
))) == ConvertBitToByte(cpuM68kInit_Bvc
))
210 retsize
= M68k_Bvc( outfp
, cpu_buffer
, cpu_pos
, cpu_size
,
211 BaseAddress
, cpuarch
);
219 if ((cpuint
- (cpuint
& GetMaskByte(cpuM68kInit_Bvs
))) == ConvertBitToByte(cpuM68kInit_Bvs
))
221 retsize
= M68k_Bvs( outfp
, cpu_buffer
, cpu_pos
, cpu_size
,
222 BaseAddress
, cpuarch
);
230 if ((cpuint
- (cpuint
& GetMaskByte(cpuM68kInit_Bpl
))) == ConvertBitToByte(cpuM68kInit_Bpl
))
232 retsize
= M68k_Bpl( outfp
, cpu_buffer
, cpu_pos
, cpu_size
,
233 BaseAddress
, cpuarch
);
241 if ((cpuint
- (cpuint
& GetMaskByte(cpuM68kInit_Bmi
))) == ConvertBitToByte(cpuM68kInit_Bmi
))
243 retsize
= M68k_Bmi( outfp
, cpu_buffer
, cpu_pos
, cpu_size
,
244 BaseAddress
, cpuarch
);
252 if ((cpuint
- (cpuint
& GetMaskByte(cpuM68kInit_Bge
))) == ConvertBitToByte(cpuM68kInit_Bge
))
254 retsize
= M68k_Bge( outfp
, cpu_buffer
, cpu_pos
, cpu_size
,
255 BaseAddress
, cpuarch
);
263 if ((cpuint
- (cpuint
& GetMaskByte(cpuM68kInit_Blt
))) == ConvertBitToByte(cpuM68kInit_Blt
))
265 retsize
= M68k_Blt( outfp
, cpu_buffer
, cpu_pos
, cpu_size
,
266 BaseAddress
, cpuarch
);
274 if ((cpuint
- (cpuint
& GetMaskByte(cpuM68kInit_Bgt
))) == ConvertBitToByte(cpuM68kInit_Bgt
))
276 retsize
= M68k_Bgt( outfp
, cpu_buffer
, cpu_pos
, cpu_size
,
277 BaseAddress
, cpuarch
);
285 if ((cpuint
- (cpuint
& GetMaskByte(cpuM68kInit_Ble
))) == ConvertBitToByte(cpuM68kInit_Ble
))
287 retsize
= M68k_Ble( outfp
, cpu_buffer
, cpu_pos
, cpu_size
,
288 BaseAddress
, cpuarch
);
295 /* Found all Opcode and breakout and return no error found */
296 if (cpu_pos
>=cpu_size
)
301 /* Check if we have found a cpu opcode */
302 if (cpu_oldpos
== cpu_pos
)
306 /* no unimplement error where found so we return a msg for unknown opcode */
307 printf("Unkonwn Opcode found at 0x%8x opcode 0x%2x\n",cpu_oldpos
+BaseAddress
,(unsigned int)cpu_buffer
[cpu_oldpos
]);
315 /* Erorro Found break and return the error code */