fix include file case
[reactos.git] / rosapps / devutils / cputointel / ConvertToPPCProcess.c
1
2 #include <windows.h>
3 #include <winnt.h>
4
5 #include <stdio.h>
6 #include <stdlib.h>
7 #include <string.h>
8 #include "misc.h"
9 #include "any_op.h"
10
11 static void standardreg(CPU_INT *RegTableCount, CPU_UNINT reg,
12 CPU_INT setup_ebp, FILE *outfp)
13 {
14 CPU_INT t, found = 0;
15 for (t=0;t<31;t++)
16 {
17 if (reg == RegTableCount[t])
18 {
19 fprintf(outfp,"r%d",t);
20 found++;
21 break;
22 }
23 }
24
25 if (found == 0)
26 {
27 fprintf(outfp,"r%d",reg);
28 }
29 }
30
31 CPU_INT ConvertToPPCProcess( FILE *outfp,
32 PMYBrainAnalys pMystart,
33 PMYBrainAnalys pMyend, CPU_INT regbits,
34 CPU_INT HowManyRegInUse,
35 CPU_INT *RegTableCount)
36 {
37
38 CPU_INT stack = 0;
39 //CPU_UNINT tmp;
40 CPU_INT setup_ebp = 0 ; /* 0 = no, 1 = yes */
41 CPU_INT t=0;
42
43 if (HowManyRegInUse > 31)
44 {
45 setup_ebp =1; /* we will use ebx as ebp */
46 stack = HowManyRegInUse * regbits;
47 }
48
49 if (RegTableCount[1]!=0)
50 t++;
51 if (RegTableCount[3]!=0)
52 t++;
53 if (RegTableCount[4]!=0)
54 t++;
55 if (RegTableCount[8]!=0)
56 t++;
57 if (RegTableCount[9]!=0)
58 t++;
59 if (RegTableCount[10]!=0)
60 t++;
61 if (RegTableCount[11]!=0)
62 t++;
63 if (RegTableCount[31]!=0)
64 t++;
65
66 if (HowManyRegInUse != t)
67 {
68 /* fixme optimze the table or active the frame pointer */
69 setup_ebp =1; /* we will use ebx as ebp */
70 stack = HowManyRegInUse * regbits;
71 }
72
73
74 /* fixme gas compatible
75 fprintf(outfp,"BITS 32\n");
76 fprintf(outfp,"GLOBAL _main\n");
77 fprintf(outfp,"SECTION .text\n\n");
78 fprintf(outfp,"; compile with nasm filename.asm -f win32, ld filename.obj -o filename.exe\n\n");
79 fprintf(outfp,"_main:\n");
80 */
81
82 /* setup a frame pointer */
83 if (setup_ebp == 1)
84 {
85 /* fixme ppc frame pointer */
86 // fprintf(outfp,"\n; Setup frame pointer \n");
87 }
88
89 fprintf(outfp,"; Start the program \n");
90 while (pMystart!=NULL)
91 {
92 /* fixme the line lookup from anaylysing process */
93
94 /* mov not full implement */
95 if (pMystart->op == OP_ANY_mov)
96 {
97 printf("waring OP_ANY_mov are not full implement\n");
98
99 if ((pMystart->type & 8)== 8)
100 {
101 /* dst are register */
102 // FIXME frame pointer setup
103 // tmp = stack - (pMystart->dst*regbits);
104
105 if ((pMystart->type & 2)== 2)
106 {
107 fprintf(outfp,"mr ");
108 standardreg( RegTableCount,
109 pMystart->dst,
110 setup_ebp, outfp);
111 fprintf(outfp,",");
112 standardreg( RegTableCount,
113 pMystart->src,
114 setup_ebp, outfp);
115 fprintf(outfp,"\n");
116 }
117
118 if ((pMystart->type & 16)== 16)
119 {
120 /* source are imm */
121 if (setup_ebp == 1)
122 fprintf(outfp,"not supporet\n");
123 else
124 {
125 fprintf(outfp,"li ");
126 standardreg( RegTableCount,
127 pMystart->dst,
128 setup_ebp, outfp);
129 fprintf(outfp," , %llu\n",pMystart->src);
130 }
131 }
132 } /* end pMyBrainAnalys->type & 8 */
133
134 if ((pMystart->type & 64)== 64)
135 {
136 if ((pMystart->type & 2)== 2)
137 {
138 /* dest [eax - 0x20], source reg */
139 if ((pMystart->type & 128)== 128)
140 {
141 fprintf(outfp,"stwu ");
142 }
143 else
144 {
145 fprintf(outfp,"stw ");
146 }
147
148 standardreg( RegTableCount,
149 pMystart->src,
150 setup_ebp, outfp);
151 fprintf(outfp,", %d(",pMystart->dst_extra);
152
153 standardreg( RegTableCount,
154 pMystart->dst,
155 setup_ebp, outfp);
156 fprintf(outfp,")\n");
157 }
158 } /* end pMyBrainAnalys->type & 64 */
159 }
160
161 /* return */
162 if (pMystart->op == OP_ANY_ret)
163 {
164 if (pMyBrainAnalys->ptr_next == NULL)
165 {
166 if (setup_ebp == 1)
167 {
168 // FIXME end our own frame pointer
169 fprintf(outfp,"\n; clean up after the frame \n");
170 }
171 }
172 fprintf(outfp,"blr\n");
173 }
174 if (pMystart == pMyend)
175 pMystart=NULL;
176 else
177 pMystart = (PMYBrainAnalys) pMystart->ptr_next;
178 }
179 return 0;
180 }