Delete all Trailing spaces in code.
[reactos.git] / rosapps / devutils / cputointel / From / ARM / ARMBrain.c
1
2 #include <stdio.h>
3 #include <stdlib.h>
4 #include "ARMBrain.h"
5 #include "ARM.h"
6 #include "../../misc.h"
7
8 /*
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.
14 *
15 * input param:
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
23 *
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 :
31 * 0 = disambler mode
32 * 1 = translate mode intel
33 *
34 * return value
35 * 0 : Ok
36 * 1 : unimplemt
37 * 2 : Unkonwn Opcode
38 * 3 : unimplement cpu
39 * 4 : unknown machine
40 */
41
42 CPU_INT ARMBrain( CPU_BYTE *cpu_buffer,
43 CPU_UNINT cpu_pos,
44 CPU_UNINT cpu_size,
45 CPU_UNINT BaseAddress,
46 CPU_UNINT cpuarch,
47 FILE *outfp)
48 {
49 CPU_UNINT cpu_oldpos;
50 CPU_INT cpuint;
51 CPU_INT retcode = 0;
52 CPU_INT retsize;
53
54
55 /* now we start the process */
56 while (cpu_pos<cpu_size)
57 {
58 cpu_oldpos = cpu_pos;
59
60 cpuint = cpu_buffer[cpu_pos];
61
62 /* Add */
63 if ((cpuint - (cpuint & GetMaskByte32(cpuARMInit_))) == ConvertBitToByte32(cpuARMInit_))
64 {
65 retsize = ARM_( outfp, cpu_buffer, cpu_pos, cpu_size,
66 BaseAddress, cpuarch);
67 if (retsize<0)
68 retcode = 1;
69 else
70 cpu_pos += retsize;
71 }
72
73 /* Found all Opcode and breakout and return no error found */
74 if (cpu_pos >=cpu_size)
75 {
76 break;
77 }
78
79 /* Check if we have found a cpu opcode */
80 if (cpu_oldpos == cpu_pos)
81 {
82 if (retcode == 0)
83 {
84 /* no unimplement error where found so we return a msg for unknown opcode */
85 printf("Unkonwn Opcode found at 0x%8x opcode 0x%2x\n",cpu_oldpos+BaseAddress,(unsigned int)cpu_buffer[cpu_oldpos]);
86 retcode = 2;
87 }
88 }
89
90 /* Erorro Found ? */
91 if (retcode!=0)
92 {
93 /* Erorro Found break and return the error code */
94 break;
95 }
96 }
97 return retcode;
98 }