1 |
156 |
sybreon |
#!/usr/bin/php
|
2 |
|
|
<?php
|
3 |
|
|
|
4 |
|
|
/**
|
5 |
|
|
Prints an error message and quits.
|
6 |
|
|
*/
|
7 |
|
|
function error(string $msg)
|
8 |
|
|
{
|
9 |
|
|
exit($msg);
|
10 |
|
|
}
|
11 |
|
|
|
12 |
|
|
|
13 |
|
|
function parsecsv(array $csv)
|
14 |
|
|
{
|
15 |
|
|
$res = array();
|
16 |
|
|
foreach ($csv as $item)
|
17 |
|
|
{
|
18 |
|
|
$exp = explode("=",$item);
|
19 |
|
|
$res[$exp[0]] = $exp[1];
|
20 |
|
|
}
|
21 |
|
|
|
22 |
|
|
return $res;
|
23 |
|
|
}
|
24 |
|
|
|
25 |
|
|
|
26 |
|
|
function decopc($opword)
|
27 |
|
|
{
|
28 |
|
|
// convert HEX opword
|
29 |
|
|
|
30 |
|
|
$opword = hexdec($opword);
|
31 |
|
|
|
32 |
|
|
// split parts
|
33 |
|
|
$opc = ($opword >> 26) & 63;
|
34 |
|
|
$rd = ($opword >> 21) & 31;
|
35 |
|
|
$ra = ($opword >> 16) & 31;
|
36 |
|
|
$rb = ($opword >> 11) & 31;
|
37 |
|
|
$imm = $opword & 65535;
|
38 |
|
|
|
39 |
|
|
switch ($opc)
|
40 |
|
|
{
|
41 |
|
|
case 000: $str = "ADD\t r" . $rd . ", r" . $ra . ", r" . $rb; break;
|
42 |
|
|
case 001: $str = "RSUB\t r" . $rd . ", r" . $ra . ", r" . $rb; break;
|
43 |
|
|
case 002: $str = "ADDC\t r" . $rd . ", r" . $ra . ", r" . $rb; break;
|
44 |
|
|
case 003: $str = "RSUBC\t r" . $rd . ", r" . $ra . ", r" . $rb; break;
|
45 |
|
|
case 004: $str = "ADDK\t r" . $rd . ", r" . $ra . ", r" . $rb; break;
|
46 |
|
|
|
47 |
|
|
case 005:
|
48 |
|
|
switch ($imm & 3)
|
49 |
|
|
{
|
50 |
|
|
case 0: $str = "RSUBK\t r" . $rd . ", r" . $ra . ", r" . $rb; break;
|
51 |
|
|
case 3: $str = "CMPU\t r" . $rd . ", r" . $ra . ", r" . $rb; break;
|
52 |
|
|
case 1: $str = "CMP\t r" . $rd . ", r" . $ra . ", r" . $rb; break;
|
53 |
|
|
default: $str = "XXX"; break;
|
54 |
|
|
}
|
55 |
|
|
break;
|
56 |
|
|
|
57 |
|
|
case 006: $str = "ADDKC\t r" . $rd . ", r" . $ra . ", r" . $rb; break;
|
58 |
|
|
case 007: $str = "RSUBKC\t r" . $rd . ", r" . $ra . ", r" . $rb; break;
|
59 |
|
|
|
60 |
|
|
case 010: $str = "ADDI\t r" . $rd . ", r" . $ra . ", 0x".dechex($imm); break;
|
61 |
|
|
case 011: $str = "RSUBI\t r" . $rd . ", r" . $ra . ", 0x".dechex($imm); break;
|
62 |
|
|
case 012: $str = "ADDIC\t r" . $rd . ", r" . $ra . ", 0x".dechex($imm); break;
|
63 |
|
|
case 013: $str = "RSUBIC\t r" . $rd . ", r" . $ra . ", 0x".dechex($imm); break;
|
64 |
|
|
case 014: $str = "ADDIK\t r" . $rd . ", r" . $ra . ", 0x".dechex($imm); break;
|
65 |
|
|
case 015: $str = "RSUBIK\t r" . $rd . ", r" . $ra . ", 0x".dechex($imm); break;
|
66 |
|
|
case 016: $str = "ADDIKC\t r" . $rd . ", r" . $ra . ", 0x".dechex($imm); break;
|
67 |
|
|
case 017: $str = "RSUBIKC\t r" . $rd . ", r" . $ra . ", 0x".dechex($imm); break;
|
68 |
|
|
|
69 |
|
|
|
70 |
|
|
case 020: $str = "MUL\t r" . $rd . ", r" . $ra . ", r" . $rb; break;
|
71 |
|
|
case 021:
|
72 |
|
|
switch ( ($imm >> 9) & 3)
|
73 |
|
|
{
|
74 |
|
|
case 0: $str = "BSRL\t r" . $rd . ", r" . $ra . ", r" . $rb; break;
|
75 |
|
|
case 1: $str = "BSRA\t r" . $rd . ", r" . $ra . ", r" . $rb; break;
|
76 |
|
|
case 3: $str = "BSLL\t r" . $rd . ", r" . $ra . ", r" . $rb; break;
|
77 |
|
|
default: $str = "XXX"; break;
|
78 |
|
|
}
|
79 |
|
|
break;
|
80 |
|
|
case 022: $str = "IDIV\t r" . $rd . ", r" . $ra . ", r" . $rb; break;
|
81 |
|
|
|
82 |
|
|
case 030: $str = "MULI\t r" . $rd . ", r" . $ra . ", 0x".dechex($imm); break;
|
83 |
|
|
case 031:
|
84 |
|
|
switch ( ($imm >> 9) & 3)
|
85 |
|
|
{
|
86 |
|
|
case 00: $str = "BSRLI\t r" . $rd . ", r" . $ra . ", 0x".dechex($imm); break;
|
87 |
|
|
case 01: $str = "BSRAI\t r" . $rd . ", r" . $ra . ", 0x".dechex($imm); break;
|
88 |
|
|
case 02: $str = "BSLLI\t r" . $rd . ", r" . $ra . ", 0x".dechex($imm); break;
|
89 |
|
|
default: $str = "XXX"; break;
|
90 |
|
|
}
|
91 |
|
|
break;
|
92 |
|
|
case 033:
|
93 |
|
|
switch ( ($rb >> 2) )
|
94 |
|
|
{
|
95 |
|
|
case 00: $str = "GET\t r" . $rd . ", rfsl0x".dechex($imm); break;
|
96 |
|
|
case 01: $str = "PUT\t rfsl0x".dechex($imm) . ", r" . $ra; break;
|
97 |
|
|
case 02: $str = "NGET\t r" . $rd . ", rfsl0x".dechex($imm); break;
|
98 |
|
|
case 03: $str = "NPUT\t rfsl0x".dechex($imm) . ", r" . $ra; break;
|
99 |
|
|
case 04: $str = "CGET\t r" . $rd . ", rfsl0x".dechex($imm); break;
|
100 |
|
|
case 05: $str = "CPUT\t rfsl0x".dechex($imm) . ", r" . $ra; break;
|
101 |
|
|
case 06: $str = "NCGET\t r" . $rd . ", rfsl0x".dechex($imm); break;
|
102 |
|
|
case 07: $str = "NCPUT\t rfsl0x".dechex($imm) . ", r" . $ra; break;
|
103 |
|
|
}
|
104 |
|
|
break;
|
105 |
|
|
case 040: $str = "OR\t r" . $rd . ", r" . $ra . ", r" . $rb; break;
|
106 |
|
|
case 041: $str = "AND\t r" . $rd . ", r" . $ra . ", r" . $rb; break;
|
107 |
|
|
case 042: $str = "XOR\t r" . $rd . ", r" . $ra . ", r" . $rb; break;
|
108 |
|
|
case 043: $str = "ANDN\t r" . $rd . ", r" . $ra . ", r" . $rb; break;
|
109 |
|
|
|
110 |
|
|
case 044:
|
111 |
|
|
switch ( ($imm >> 5) & 3)
|
112 |
|
|
{
|
113 |
|
|
case 00: $str = "SRA\t r" . $rd . ", r" . $ra; break;
|
114 |
|
|
case 01: $str = "SRC\t r" . $rd . ", r" . $ra; break;
|
115 |
|
|
case 02: $str = "SRL\t r" . $rd . ", r" . $ra; break;
|
116 |
|
|
case 03:
|
117 |
|
|
switch ( $imm & 1 )
|
118 |
|
|
{
|
119 |
|
|
case 00: $str = "SEXT8\t r" . $rd . ", r" . $ra; break;
|
120 |
|
|
case 01: $str = "SEXT16\t r" . $rd . ", r" . $ra; break;
|
121 |
|
|
}
|
122 |
|
|
break;
|
123 |
|
|
}
|
124 |
|
|
break;
|
125 |
|
|
case 045:
|
126 |
|
|
switch ( ($imm >> 14) & 3)
|
127 |
|
|
{
|
128 |
|
|
case 03: $str = "MTS\t rmsr, r" . $ra; break;
|
129 |
|
|
case 02: $str = "MFS\t r" . $rd . ", rmsr"; break;
|
130 |
|
|
case 00:
|
131 |
|
|
switch ( $ra & 1)
|
132 |
|
|
{
|
133 |
|
|
case 1: $str = "MSRCLR\t r" . $rd . ", 0x".dechex($imm); break;
|
134 |
|
|
case 0: $str = "MSRSET\t r" . $rd . ", 0x".dechex($imm); break;
|
135 |
|
|
}
|
136 |
|
|
break;
|
137 |
|
|
default : $str = "XXX"; break;
|
138 |
|
|
}
|
139 |
|
|
break;
|
140 |
|
|
case 046:
|
141 |
|
|
switch ( ($ra >> 2) & 7)
|
142 |
|
|
{
|
143 |
|
|
case 00: $str = "BR\t r".$rb; break;
|
144 |
|
|
case 01: $str = "BRL\t r".$rd.", r".$rb;break;
|
145 |
|
|
case 02: $str = "BRA\t r".$rb;break;
|
146 |
|
|
case 03: $str = "BRAL\t r".$rd.", r".$rb;break;
|
147 |
|
|
case 04: $str = "BRD\t r".$rb; break;
|
148 |
|
|
case 05: $str = "BRLD\t r".$rd.", r".$rb;break;
|
149 |
|
|
case 06: $str = "BRAD\t r".$rb;break;
|
150 |
|
|
case 07: $str = "BRALD\t r".$rd.", r".$rb;break;
|
151 |
|
|
}
|
152 |
|
|
break;
|
153 |
|
|
|
154 |
|
|
case 047:
|
155 |
|
|
switch ( $rd & 31 )
|
156 |
|
|
{
|
157 |
|
|
case 00: $str = "BEQ\t r".$ra.", r".$rb;break;
|
158 |
|
|
case 01: $str = "BNE\t r".$ra.", r".$rb;break;
|
159 |
|
|
case 02: $str = "BLT\t r".$ra.", r".$rb;break;
|
160 |
|
|
case 03: $str = "BLE\t r".$ra.", r".$rb;break;
|
161 |
|
|
case 04: $str = "BGT\t r".$ra.", r".$rb;break;
|
162 |
|
|
case 05: $str = "BGE\t r".$ra.", r".$rb;break;
|
163 |
|
|
case 020: $str = "BEQD\t r".$ra.", r".$rb;break;
|
164 |
|
|
case 021: $str = "BNED\t r".$ra.", r".$rb;break;
|
165 |
|
|
case 022: $str = "BLTD\t r".$ra.", r".$rb;break;
|
166 |
|
|
case 023: $str = "BLED\t r".$ra.", r".$rb;break;
|
167 |
|
|
case 024: $str = "BGTD\t r".$ra.", r".$rb;break;
|
168 |
|
|
case 025: $str = "BGED\t r".$ra.", r".$rb;break;
|
169 |
|
|
default: $str = "XXX"; break;
|
170 |
|
|
}
|
171 |
|
|
break;
|
172 |
|
|
|
173 |
|
|
|
174 |
|
|
case 050: $str = "ORI\t r" . $rd . ", r" . $ra . ", 0x".dechex($imm); break;
|
175 |
|
|
case 051: $str = "ANDI\t r" . $rd . ", r" . $ra . ", 0x".dechex($imm); break;
|
176 |
|
|
case 052: $str = "XORI\t r" . $rd . ", r" . $ra . ", 0x".dechex($imm); break;
|
177 |
|
|
case 053: $str = "ANDNI\t r" . $rd . ", r" . $ra . ", 0x".dechex($imm); break;
|
178 |
|
|
case 054: $str = "IMMI\t 0x".dechex($imm);break;
|
179 |
|
|
|
180 |
|
|
case 055:
|
181 |
|
|
switch ( ($rd & 3))
|
182 |
|
|
{
|
183 |
|
|
case 0: $str = "RTSD\t r". $ra . ", 0x".dechex($imm);break;
|
184 |
|
|
case 1: $str = "RTID\t r". $ra . ", 0x".dechex($imm);break;
|
185 |
|
|
case 2: $str = "RTBD\t r". $ra . ", 0x".dechex($imm);break;
|
186 |
|
|
default: $str = "XXX";break;
|
187 |
|
|
}
|
188 |
|
|
break;
|
189 |
|
|
|
190 |
|
|
case 056:
|
191 |
|
|
switch ( ($ra >> 2) & 7)
|
192 |
|
|
{
|
193 |
|
|
case 00: $str = "BRI\t 0x".dechex($imm); break;
|
194 |
|
|
case 01: $str = "BRLI\t r".$rd.", 0x".dechex($imm);break;
|
195 |
|
|
case 02: $str = "BRAI\t 0x".dechex($imm);break;
|
196 |
|
|
case 03: $str = "BRALI\t r".$rd.", 0x".dechex($imm);break;
|
197 |
|
|
case 04: $str = "BRID\t 0x".dechex($imm); break;
|
198 |
|
|
case 05: $str = "BRLID\t r".$rd.", 0x".dechex($imm);break;
|
199 |
|
|
case 06: $str = "BRAID\t 0x".dechex($imm);break;
|
200 |
|
|
case 07: $str = "BRALID\t r".$rd.", 0x".dechex($imm);break;
|
201 |
|
|
}
|
202 |
|
|
break;
|
203 |
|
|
|
204 |
|
|
case 057:
|
205 |
|
|
switch ( $rd & 31 )
|
206 |
|
|
{
|
207 |
|
|
case 00: $str = "BEQI\t r".$ra.", 0x".dechex($imm);break;
|
208 |
|
|
case 01: $str = "BNEI\t r".$ra.", 0x".dechex($imm);break;
|
209 |
|
|
case 02: $str = "BLTI\t r".$ra.", 0x".dechex($imm);break;
|
210 |
|
|
case 03: $str = "BLEI\t r".$ra.", 0x".dechex($imm);break;
|
211 |
|
|
case 04: $str = "BGTI\t r".$ra.", 0x".dechex($imm);break;
|
212 |
|
|
case 05: $str = "BGEI\t r".$ra.", 0x".dechex($imm);break;
|
213 |
|
|
case 020: $str = "BEQID\t r".$ra.", 0x".dechex($imm);break;
|
214 |
|
|
case 021: $str = "BNEID\t r".$ra.", 0x".dechex($imm);break;
|
215 |
|
|
case 022: $str = "BLTID\t r".$ra.", 0x".dechex($imm);break;
|
216 |
|
|
case 023: $str = "BLEID\t r".$ra.", 0x".dechex($imm);break;
|
217 |
|
|
case 024: $str = "BGTID\t r".$ra.", 0x".dechex($imm);break;
|
218 |
|
|
case 025: $str = "BGEID\t r".$ra.", 0x".dechex($imm);break;
|
219 |
|
|
default: $str = "XXX"; break;
|
220 |
|
|
}
|
221 |
|
|
break;
|
222 |
|
|
|
223 |
|
|
case 060: $str = "LB\t r" . $rd . ", r" . $ra . ", r" . $rb; break;
|
224 |
|
|
case 061: $str = "LH\t r" . $rd . ", r" . $ra . ", r" . $rb; break;
|
225 |
|
|
case 062: $str = "LW\t r" . $rd . ", r" . $ra . ", r" . $rb; break;
|
226 |
|
|
case 064: $str = "SB\t r" . $rd . ", r" . $ra . ", r" . $rb; break;
|
227 |
|
|
case 065: $str = "SH\t r" . $rd . ", r" . $ra . ", r" . $rb; break;
|
228 |
|
|
case 066: $str = "SW\t r" . $rd . ", r" . $ra . ", r" . $rb; break;
|
229 |
|
|
|
230 |
|
|
case 070: $str = "LBI\t r" . $rd . ", r" . $ra . ", 0x".dechex($imm); break;
|
231 |
|
|
case 071: $str = "LHI\t r" . $rd . ", r" . $ra . ", 0x".dechex($imm); break;
|
232 |
|
|
case 072: $str = "LWI\t r" . $rd . ", r" . $ra . ", 0x".dechex($imm); break;
|
233 |
|
|
case 074: $str = "SBI\t r" . $rd . ", r" . $ra . ", 0x".dechex($imm); break;
|
234 |
|
|
case 075: $str = "SHI\t r" . $rd . ", r" . $ra . ", 0x".dechex($imm); break;
|
235 |
|
|
case 076: $str = "SWI\t r" . $rd . ", r" . $ra . ", 0x".dechex($imm); break;
|
236 |
|
|
|
237 |
|
|
default: $str = "XXX " . decoct($opc); break;
|
238 |
|
|
}
|
239 |
|
|
|
240 |
|
|
return $str;
|
241 |
|
|
}
|
242 |
|
|
|
243 |
|
|
function draw(array $sample)
|
244 |
|
|
{
|
245 |
|
|
fputs(STDOUT, "Time\t:" . hexdec($sample["TME"]) . "\t");
|
246 |
|
|
switch ($sample["PHA"])
|
247 |
|
|
{
|
248 |
|
|
case 1: fputs(STDOUT,"".$sample["IWB"]."@".decopc($sample["ASM"])); break;
|
249 |
|
|
case 0: fputs(STDOUT,"\t\t\t\t\t".$sample["IWB"]."@".decopc($sample["ASM"])); break;
|
250 |
|
|
}
|
251 |
|
|
|
252 |
|
|
fputs(STDOUT, "\n");
|
253 |
|
|
//fputs(STDOUT,$sample["PHA"].":".$sample["IWB"]."@".decopc($sample["ASM"]) . "\n");
|
254 |
|
|
}
|
255 |
|
|
|
256 |
|
|
|
257 |
|
|
function main()
|
258 |
|
|
{
|
259 |
|
|
// read simulator output one line at a time
|
260 |
|
|
while ( ($line = fgets(STDIN)) )
|
261 |
|
|
{
|
262 |
|
|
$line = parsecsv(explode(",",$line));
|
263 |
|
|
if (array_key_exists("TME",$line))
|
264 |
|
|
draw($line);
|
265 |
|
|
}
|
266 |
|
|
}
|
267 |
|
|
|
268 |
|
|
|
269 |
|
|
function gui()
|
270 |
|
|
{
|
271 |
|
|
|
272 |
|
|
// we begin by initializing ncurses
|
273 |
|
|
$ncurse = ncurses_init();
|
274 |
|
|
// let ncurses know we wish to use the whole screen
|
275 |
|
|
$fullscreen = ncurses_newwin(0, 0, 0, 0);
|
276 |
|
|
// draw a border around the whole thing.
|
277 |
|
|
ncurses_border(0,0, 0,0, 0,0, 0,0);
|
278 |
|
|
|
279 |
|
|
ncurses_attron(NCURSES_A_REVERSE);
|
280 |
|
|
ncurses_mvaddstr(0,1,"AEMB2 SIMULATOR OUTPUT TRANSLATOR");
|
281 |
|
|
ncurses_attroff(NCURSES_A_REVERSE);
|
282 |
|
|
|
283 |
|
|
// now lets create a small window
|
284 |
|
|
$small = ncurses_newwin(10, 30, 2, 2);
|
285 |
|
|
// border our small window.
|
286 |
|
|
ncurses_wborder($small,0,0, 0,0, 0,0, 0,0);
|
287 |
|
|
ncurses_refresh();// paint both windows
|
288 |
|
|
|
289 |
|
|
// move into the small window and write a string
|
290 |
|
|
ncurses_mvwaddstr($small, 5, 5, " Test String ");
|
291 |
|
|
|
292 |
|
|
// show our handiwork and refresh our small window
|
293 |
|
|
ncurses_wrefresh($small);
|
294 |
|
|
|
295 |
|
|
$pressed = ncurses_getch();// wait for a user keypress
|
296 |
|
|
|
297 |
|
|
ncurses_end();// clean up our screen
|
298 |
|
|
|
299 |
|
|
}
|
300 |
|
|
|
301 |
|
|
main();
|
302 |
|
|
//gui();
|
303 |
|
|
|
304 |
|
|
?>
|