- Rearrange reactos.dff according to rosapps rearrange.
[reactos.git] / rosapps / devutils / cputointel / From / dummycpu / DummyBrain.c
1
2 #include <stdio.h>
3 #include <stdlib.h>
4 #include "DummyBrain.h"
5 #include "Dummy.h"
6 #include "../../misc.h"
7
8
9
10 /*
11 * DummyBrain is example how you create you own cpu brain to translate from
12 * cpu to intel assembler, I have not add DummyBrain to the loader it is not
13 * need it in our example. When you write you own brain, it must be setup in
14 * misc.c function LoadPFileImage and PEFileStart, PEFileStart maybe does not
15 * need the brain you have writen so you do not need setup it there then.
16 *
17 * input param:
18 * cpu_buffer : the memory buffer with loaded program we whant translate
19 * cpu_pos : the positions in the cpu_buffer
20 * cpu_size : the alloced memory size of the cpu_buffer
21 * BaseAddress : the virtual memory address we setup to use.
22 * cpuarch : the sub arch for the brain, example if it exists more one
23 * cpu with same desgin but few other opcode or extend opcode
24 * outfp : the output file pointer
25 *
26 * return value
27 * 0 : Ok
28 * 1 : unimplemt
29 * 2 : Unkonwn Opcode
30 * 3 : unimplement cpu
31 * 4 : unknown machine
32 */
33
34 CPU_INT DummyBrain( CPU_BYTE *cpu_buffer,
35 CPU_UNINT cpu_pos,
36 CPU_UNINT cpu_size,
37 CPU_UNINT BaseAddress,
38 CPU_UNINT cpuarch,
39 FILE *outfp)
40 {
41 CPU_UNINT cpu_oldpos;
42 CPU_INT cpuint;
43 CPU_INT retcode = 0;
44 CPU_INT retsize;
45
46 /* now we start the process */
47 while (cpu_pos<cpu_size)
48 {
49 cpu_oldpos = cpu_pos;
50
51 /* use the GetData32Be or GetData32Le
52 to read from the memory the
53 Le is for small endian and the
54 Be is for big endian
55 the 32 is how many bits we should read
56 */
57 cpuint = GetData32Be(&cpu_buffer[cpu_pos]);
58
59 /* Add */
60 if ((cpuint - (cpuint & GetMaskByte(cpuDummyInit_Add))) == ConvertBitToByte(cpuDummyInit_Add))
61 {
62 retsize = DUMMY_Add( outfp, cpu_buffer, cpu_pos, cpu_size,
63 BaseAddress, cpuarch);
64 if (retsize<0)
65 retcode = 1;
66 else
67 cpu_pos += retsize;
68 }
69
70 /* Found all Opcode and breakout and return no error found */
71 if (cpu_pos >=cpu_size)
72 {
73 break;
74 }
75
76 /* Check if we have found a cpu opcode */
77 if (cpu_oldpos == cpu_pos)
78 {
79 if (retcode == 0)
80 {
81 /* no unimplement error where found so we return a msg for unknown opcode */
82 printf("Unkonwn Opcode found at 0x%8x opcode 0x%2x\n",cpu_oldpos+BaseAddress,(unsigned int)cpu_buffer[cpu_oldpos]);
83 retcode = 2;
84 }
85 }
86
87 /* Erorro Found ? */
88 if (retcode!=0)
89 {
90 /* Erorro Found break and return the error code */
91 break;
92 }
93 }
94 return retcode;
95 }