1 |
2 |
alfik |
/*
|
2 |
|
|
* Copyright (c) 2014, Aleksander Osman
|
3 |
|
|
* All rights reserved.
|
4 |
|
|
*
|
5 |
|
|
* Redistribution and use in source and binary forms, with or without
|
6 |
|
|
* modification, are permitted provided that the following conditions are met:
|
7 |
|
|
*
|
8 |
|
|
* * Redistributions of source code must retain the above copyright notice, this
|
9 |
|
|
* list of conditions and the following disclaimer.
|
10 |
|
|
*
|
11 |
|
|
* * Redistributions in binary form must reproduce the above copyright notice,
|
12 |
|
|
* this list of conditions and the following disclaimer in the documentation
|
13 |
|
|
* and/or other materials provided with the distribution.
|
14 |
|
|
*
|
15 |
|
|
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
16 |
|
|
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
17 |
|
|
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
18 |
|
|
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
|
19 |
|
|
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
20 |
|
|
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
21 |
|
|
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
22 |
|
|
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
|
23 |
|
|
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
24 |
|
|
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
25 |
|
|
*/
|
26 |
|
|
|
27 |
|
|
package ao486.test;
|
28 |
|
|
|
29 |
|
|
import ao486.test.Runner.CMD_start_output;
|
30 |
|
|
import ao486.test.Runner.CMD_start_completed;
|
31 |
|
|
import java.io.File;
|
32 |
|
|
import java.io.InputStream;
|
33 |
|
|
import java.io.InputStreamReader;
|
34 |
|
|
import java.io.LineNumberReader;
|
35 |
|
|
import java.io.OutputStream;
|
36 |
|
|
import java.lang.reflect.Field;
|
37 |
|
|
import java.lang.reflect.Method;
|
38 |
|
|
import java.util.HashMap;
|
39 |
|
|
import java.util.LinkedList;
|
40 |
|
|
import java.util.regex.Matcher;
|
41 |
|
|
import java.util.regex.Pattern;
|
42 |
|
|
|
43 |
|
|
public class Runner {
|
44 |
|
|
|
45 |
|
|
//--------------------------------------------------------------------------
|
46 |
|
|
static class CMD_start_completed {
|
47 |
|
|
long time;
|
48 |
|
|
|
49 |
|
|
long rep;
|
50 |
|
|
long seg;
|
51 |
|
|
long lock;
|
52 |
|
|
long os32;
|
53 |
|
|
long as32;
|
54 |
|
|
long consumed;
|
55 |
|
|
}
|
56 |
|
|
void start_completed(CMD_start_completed params) throws Exception {
|
57 |
|
|
System.out.println("----------------------------------------------------------------[Runner]: start_completed");
|
58 |
|
|
|
59 |
|
|
unit.run_log.add(params);
|
60 |
|
|
}
|
61 |
|
|
|
62 |
|
|
//--------------------------------------------------------------------------
|
63 |
|
|
static class CMD_start_output {
|
64 |
|
|
long time;
|
65 |
|
|
|
66 |
|
|
//only from verilog testbench
|
67 |
|
|
long tb_wr_cmd_last;
|
68 |
|
|
long tb_can_ignore;
|
69 |
|
|
|
70 |
|
|
long eax, ebx, ecx, edx, esi, edi, ebp, esp;
|
71 |
|
|
long eip;
|
72 |
|
|
long cflag, pflag, aflag, zflag, sflag, tflag, iflag, dflag, oflag, iopl, ntflag, rflag, vmflag, acflag, idflag;
|
73 |
|
|
|
74 |
|
|
long cs_cache_valid, cs, cs_rpl, cs_base, cs_limit, cs_g, cs_d_b, cs_avl, cs_p, cs_dpl, cs_s, cs_type;
|
75 |
|
|
long ds_cache_valid, ds, ds_rpl, ds_base, ds_limit, ds_g, ds_d_b, ds_avl, ds_p, ds_dpl, ds_s, ds_type;
|
76 |
|
|
long es_cache_valid, es, es_rpl, es_base, es_limit, es_g, es_d_b, es_avl, es_p, es_dpl, es_s, es_type;
|
77 |
|
|
long fs_cache_valid, fs, fs_rpl, fs_base, fs_limit, fs_g, fs_d_b, fs_avl, fs_p, fs_dpl, fs_s, fs_type;
|
78 |
|
|
long gs_cache_valid, gs, gs_rpl, gs_base, gs_limit, gs_g, gs_d_b, gs_avl, gs_p, gs_dpl, gs_s, gs_type;
|
79 |
|
|
long ss_cache_valid, ss, ss_rpl, ss_base, ss_limit, ss_g, ss_d_b, ss_avl, ss_p, ss_dpl, ss_s, ss_type;
|
80 |
|
|
long ldtr_cache_valid, ldtr, ldtr_rpl, ldtr_base, ldtr_limit, ldtr_g, ldtr_d_b, ldtr_avl, ldtr_p, ldtr_dpl, ldtr_s, ldtr_type;
|
81 |
|
|
long tr_cache_valid, tr, tr_rpl, tr_base, tr_limit, tr_g, tr_d_b, tr_avl, tr_p, tr_dpl, tr_s, tr_type;
|
82 |
|
|
|
83 |
|
|
long gdtr_base, gdtr_limit;
|
84 |
|
|
long idtr_base, idtr_limit;
|
85 |
|
|
|
86 |
|
|
long cr0_pe, cr0_mp, cr0_em, cr0_ts, cr0_ne, cr0_wp, cr0_am, cr0_nw, cr0_cd, cr0_pg;
|
87 |
|
|
|
88 |
|
|
long cr2, cr3;
|
89 |
|
|
|
90 |
|
|
long dr0, dr1, dr2, dr3;
|
91 |
|
|
long dr6, dr7;
|
92 |
|
|
}
|
93 |
|
|
void start_output(CMD_start_output params) throws Exception {
|
94 |
|
|
System.out.println("[Runner]: start_output");
|
95 |
|
|
|
96 |
|
|
unit.run_log.add(params);
|
97 |
|
|
}
|
98 |
|
|
|
99 |
|
|
//--------------------------------------------------------------------------
|
100 |
|
|
static class CMD_start_check_interrupt {
|
101 |
|
|
long time;
|
102 |
|
|
}
|
103 |
|
|
void start_check_interrupt(CMD_start_check_interrupt params) throws Exception {
|
104 |
|
|
System.out.println("[Runner]: start_check_interrupt");
|
105 |
|
|
|
106 |
|
|
long value = unit.check_interrupt(params.time);
|
107 |
|
|
|
108 |
|
|
out.write(String.format("%x\n", value).getBytes());
|
109 |
|
|
out.flush();
|
110 |
|
|
}
|
111 |
|
|
|
112 |
|
|
//--------------------------------------------------------------------------
|
113 |
|
|
static class CMD_start_interrupt {
|
114 |
|
|
long time;
|
115 |
|
|
|
116 |
|
|
long vector;
|
117 |
|
|
}
|
118 |
|
|
void start_interrupt(CMD_start_interrupt params) throws Exception {
|
119 |
|
|
System.out.println("[Runner]: start_interrupt");
|
120 |
|
|
|
121 |
|
|
unit.run_log.add(params);
|
122 |
|
|
}
|
123 |
|
|
|
124 |
|
|
//--------------------------------------------------------------------------
|
125 |
|
|
static class CMD_start_exception {
|
126 |
|
|
long time;
|
127 |
|
|
|
128 |
|
|
long vector;
|
129 |
|
|
long push_error;
|
130 |
|
|
long error_code;
|
131 |
|
|
}
|
132 |
|
|
void start_exception(CMD_start_exception params) throws Exception {
|
133 |
|
|
System.out.println("[Runner]: start_exception");
|
134 |
|
|
|
135 |
|
|
unit.run_log.add(params);
|
136 |
|
|
}
|
137 |
|
|
|
138 |
|
|
//--------------------------------------------------------------------------
|
139 |
|
|
static class CMD_start_read {
|
140 |
|
|
long time;
|
141 |
|
|
|
142 |
|
|
long address;
|
143 |
|
|
long byteena;
|
144 |
|
|
long can_ignore;
|
145 |
|
|
}
|
146 |
|
|
void start_read(CMD_start_read params) throws Exception {
|
147 |
|
|
System.out.printf("[Runner]: start_read, address: %08x, byteena: %x\n", params.address, params.byteena);
|
148 |
|
|
|
149 |
|
|
unit.run_log.add(params);
|
150 |
|
|
|
151 |
|
|
long value = unit.read(params);
|
152 |
|
|
params.byteena |= (value & 0xFFFFFFFFL) << 8;
|
153 |
|
|
|
154 |
|
|
out.write(String.format("%x\n", value).getBytes());
|
155 |
|
|
out.flush();
|
156 |
|
|
|
157 |
|
|
System.out.printf("[Runner]: start_read done: %08x\n", value);
|
158 |
|
|
}
|
159 |
|
|
|
160 |
|
|
//--------------------------------------------------------------------------
|
161 |
|
|
static class CMD_start_read_code {
|
162 |
|
|
long time;
|
163 |
|
|
|
164 |
|
|
long address;
|
165 |
|
|
long byteena;
|
166 |
|
|
}
|
167 |
|
|
void start_read_code(CMD_start_read_code params) throws Exception {
|
168 |
|
|
//System.out.printf("[Runner]: start_read_code: %08x ena %x\n", params.address, params.byteena);
|
169 |
|
|
|
170 |
|
|
long value = unit.read_code(params);
|
171 |
|
|
|
172 |
|
|
//System.out.printf("[Runner]: start_read_code result: %08x\n", value);
|
173 |
|
|
|
174 |
|
|
out.write(String.format("%x\n", value).getBytes());
|
175 |
|
|
out.flush();
|
176 |
|
|
}
|
177 |
|
|
|
178 |
|
|
//--------------------------------------------------------------------------
|
179 |
|
|
static class CMD_start_write {
|
180 |
|
|
long time;
|
181 |
|
|
|
182 |
|
|
long address;
|
183 |
|
|
long data;
|
184 |
|
|
long byteena;
|
185 |
|
|
long can_ignore;
|
186 |
|
|
}
|
187 |
|
|
void start_write(CMD_start_write params) throws Exception {
|
188 |
|
|
System.out.println("[Runner]: start_write");
|
189 |
|
|
|
190 |
|
|
if(((params.byteena >> 0) & 1) == 0) params.data &= 0xFFFFFF00L;
|
191 |
|
|
if(((params.byteena >> 1) & 1) == 0) params.data &= 0xFFFF00FFL;
|
192 |
|
|
if(((params.byteena >> 2) & 1) == 0) params.data &= 0xFF00FFFFL;
|
193 |
|
|
if(((params.byteena >> 3) & 1) == 0) params.data &= 0x00FFFFFFL;
|
194 |
|
|
|
195 |
|
|
unit.run_log.add(params);
|
196 |
|
|
|
197 |
|
|
unit.write(params);
|
198 |
|
|
}
|
199 |
|
|
|
200 |
|
|
//--------------------------------------------------------------------------
|
201 |
|
|
static class CMD_start_io_write {
|
202 |
|
|
long time;
|
203 |
|
|
|
204 |
|
|
long address;
|
205 |
|
|
long data;
|
206 |
|
|
long byteena;
|
207 |
|
|
long can_ignore;
|
208 |
|
|
}
|
209 |
|
|
void start_io_write(CMD_start_io_write params) throws Exception {
|
210 |
|
|
System.out.printf("[Runner]: start_io_write: %04x byteena: %x\n", params.address, params.byteena);
|
211 |
|
|
|
212 |
|
|
if(((params.byteena >> 0) & 1) == 0) params.data &= 0xFFFFFF00L;
|
213 |
|
|
if(((params.byteena >> 1) & 1) == 0) params.data &= 0xFFFF00FFL;
|
214 |
|
|
if(((params.byteena >> 2) & 1) == 0) params.data &= 0xFF00FFFFL;
|
215 |
|
|
if(((params.byteena >> 3) & 1) == 0) params.data &= 0x00FFFFFFL;
|
216 |
|
|
|
217 |
|
|
unit.run_log.add(params);
|
218 |
|
|
|
219 |
|
|
unit.write_io(params);
|
220 |
|
|
}
|
221 |
|
|
|
222 |
|
|
//--------------------------------------------------------------------------
|
223 |
|
|
static class CMD_start_io_read {
|
224 |
|
|
long time;
|
225 |
|
|
|
226 |
|
|
long address;
|
227 |
|
|
long byteena;
|
228 |
|
|
long can_ignore;
|
229 |
|
|
}
|
230 |
|
|
void start_io_read(CMD_start_io_read params) throws Exception {
|
231 |
|
|
System.out.println("[Runner]: start_io_read");
|
232 |
|
|
|
233 |
|
|
unit.run_log.add(params);
|
234 |
|
|
|
235 |
|
|
boolean read_ff =
|
236 |
|
|
(params.address >= 0x0010 && params.address < 0x0020) ||
|
237 |
|
|
(params.address == 0x0020 && (params.byteena & 0x3) == 0) ||
|
238 |
|
|
(params.address >= 0x0024 && params.address < 0x0040) ||
|
239 |
|
|
(params.address >= 0x0044 && params.address < 0x0060) ||
|
240 |
|
|
(params.address >= 0x0068 && params.address < 0x0070) ||
|
241 |
|
|
(params.address == 0x0070 && (params.byteena & 0x3) == 0) ||
|
242 |
|
|
(params.address >= 0x0074 && params.address < 0x0080) ||
|
243 |
|
|
(params.address == 0x00A0 && (params.byteena & 0x3) == 0) ||
|
244 |
|
|
(params.address >= 0x00A4 && params.address < 0x00C0) ||
|
245 |
|
|
(params.address >= 0x00E0 && params.address < 0x01F0) ||
|
246 |
|
|
(params.address >= 0x01F8 && params.address < 0x0220) ||
|
247 |
|
|
(params.address >= 0x0230 && params.address < 0x0388) ||
|
248 |
|
|
(params.address == 0x0388 && (params.byteena & 0x3) == 0) ||
|
249 |
|
|
(params.address >= 0x038C && params.address < 0x03B0) ||
|
250 |
|
|
(params.address >= 0x03E0 && params.address < 0x03F0) ||
|
251 |
|
|
(params.address >= 0x03F8 && params.address < 0x8888) ||
|
252 |
|
|
(params.address >= 0x8890);
|
253 |
|
|
|
254 |
|
|
boolean read_ff_part =
|
255 |
|
|
(params.address == 0x0020) ||
|
256 |
|
|
(params.address == 0x0070) ||
|
257 |
|
|
(params.address == 0x00A0) ||
|
258 |
|
|
(params.address == 0x0388);
|
259 |
|
|
|
260 |
|
|
long value =
|
261 |
|
|
(read_ff)? 0xFFFFFFFFL :
|
262 |
|
|
(read_ff_part)? 0xFFFF0000L | unit.read_io(params) :
|
263 |
|
|
unit.read_io(params);
|
264 |
|
|
|
265 |
|
|
params.byteena |= (value & 0xFFFFFFFFL) << 8;
|
266 |
|
|
|
267 |
|
|
out.write(String.format("%x\n", value).getBytes());
|
268 |
|
|
out.flush();
|
269 |
|
|
}
|
270 |
|
|
|
271 |
|
|
//--------------------------------------------------------------------------
|
272 |
|
|
static class CMD_start_input {
|
273 |
|
|
long time;
|
274 |
|
|
}
|
275 |
|
|
void start_input(CMD_start_input params) throws Exception {
|
276 |
|
|
System.out.println("[Runner]: start_input");
|
277 |
|
|
|
278 |
|
|
for(Field field : CMD_start_output.class.getDeclaredFields()) {
|
279 |
|
|
if(field.getName().equals("time")) continue;
|
280 |
|
|
if(field.getName().equals("tb_wr_cmd_last")) continue;
|
281 |
|
|
if(field.getName().equals("tb_can_ignore")) continue;
|
282 |
|
|
|
283 |
|
|
long value = unit.getInput(field.getName());
|
284 |
|
|
//System.out.println("start_input: " + field.getName() + ", " + value);
|
285 |
|
|
out.write(String.format("%s: %x\n", field.getName(), value).getBytes());
|
286 |
|
|
}
|
287 |
|
|
|
288 |
|
|
out.write(String.format("test_type: %x\n", unit.getTestType()).getBytes());
|
289 |
|
|
|
290 |
|
|
out.write("continue: 0\n".getBytes());
|
291 |
|
|
out.flush();
|
292 |
|
|
}
|
293 |
|
|
|
294 |
|
|
//--------------------------------------------------------------------------
|
295 |
|
|
static class CMD_start_shutdown {
|
296 |
|
|
long time;
|
297 |
|
|
}
|
298 |
|
|
void start_shutdown(CMD_start_shutdown params) throws Exception {
|
299 |
|
|
System.out.println("[Runner]: start_shutdown");
|
300 |
|
|
|
301 |
|
|
unit.run_log.add(params);
|
302 |
|
|
}
|
303 |
|
|
|
304 |
|
|
//--------------------------------------------------------------------------
|
305 |
|
|
//--------------------------------------------------------------------------
|
306 |
|
|
//--------------------------------------------------------------------------
|
307 |
|
|
//--------------------------------------------------------------------------
|
308 |
|
|
|
309 |
|
|
void execute(LinkedList<String> command_line, File directory, TestUnit unit) throws Exception {
|
310 |
|
|
|
311 |
|
|
Process p = null;
|
312 |
|
|
this.unit = unit;
|
313 |
|
|
|
314 |
|
|
try {
|
315 |
|
|
ProcessBuilder pb = new ProcessBuilder(command_line);
|
316 |
|
|
pb.directory(directory);
|
317 |
|
|
pb.redirectErrorStream(true);
|
318 |
|
|
|
319 |
|
|
p = pb.start();
|
320 |
|
|
|
321 |
|
|
InputStream in = p.getInputStream();
|
322 |
|
|
out = p.getOutputStream();
|
323 |
|
|
|
324 |
|
|
boolean started = false;
|
325 |
|
|
LineNumberReader reader = new LineNumberReader(new InputStreamReader(in));
|
326 |
|
|
|
327 |
|
|
HashMap<String, Long> params = new HashMap<>();
|
328 |
|
|
|
329 |
|
|
while(true) {
|
330 |
|
|
String line = reader.readLine();
|
331 |
|
|
if(line == null) {
|
332 |
|
|
in.close();
|
333 |
|
|
out.close();
|
334 |
|
|
|
335 |
|
|
p.waitFor();
|
336 |
|
|
break;
|
337 |
|
|
}
|
338 |
|
|
|
339 |
|
|
line = line.trim();
|
340 |
|
|
|
341 |
|
|
//System.out.println("line: " + line);
|
342 |
|
|
if(line.startsWith("START")) {
|
343 |
|
|
started = true;
|
344 |
|
|
continue;
|
345 |
|
|
}
|
346 |
|
|
|
347 |
|
|
if(started == false) continue;
|
348 |
|
|
|
349 |
|
|
if(line.startsWith("#")) {
|
350 |
|
|
//System.out.println("line: " + line);
|
351 |
|
|
continue;
|
352 |
|
|
}
|
353 |
|
|
|
354 |
|
|
|
355 |
|
|
if(line.equals("")) {
|
356 |
|
|
if(params.isEmpty()) continue;
|
357 |
|
|
|
358 |
|
|
dispatch(params);
|
359 |
|
|
params.clear();
|
360 |
|
|
|
361 |
|
|
continue;
|
362 |
|
|
}
|
363 |
|
|
|
364 |
|
|
//match name: hex_value
|
365 |
|
|
Pattern pat = Pattern.compile("(\\w+?):\\s*([0-9a-fA-F]+)");
|
366 |
|
|
Matcher mat = pat.matcher(line);
|
367 |
|
|
|
368 |
|
|
boolean found = mat.find();
|
369 |
|
|
if(found == false) throw new Exception("Invalid line: " + line);
|
370 |
|
|
|
371 |
|
|
String s1 = mat.group(1).trim();
|
372 |
|
|
String s2 = mat.group(2).trim();
|
373 |
|
|
|
374 |
|
|
params.put(s1, Long.parseLong(s2, 16));
|
375 |
|
|
//System.out.println("PUT: " + s1 + " = " + s2);
|
376 |
|
|
}
|
377 |
|
|
}
|
378 |
|
|
finally {
|
379 |
|
|
if(p != null) p.destroy();
|
380 |
|
|
}
|
381 |
|
|
}
|
382 |
|
|
|
383 |
|
|
private void dispatch(HashMap<String, Long> params) throws Exception {
|
384 |
|
|
|
385 |
|
|
//find name starting with: start_
|
386 |
|
|
String start = null;
|
387 |
|
|
for(String name : params.keySet()) if(name.startsWith("start_")) { start = name; break; }
|
388 |
|
|
|
389 |
|
|
if(start == null) throw new Exception("No start_* in command.");
|
390 |
|
|
|
391 |
|
|
Class this_class = this.getClass();
|
392 |
|
|
|
393 |
|
|
//find class
|
394 |
|
|
Class command_class = null;
|
395 |
|
|
for(Class inner_class : this_class.getDeclaredClasses()) {
|
396 |
|
|
if(inner_class.getSimpleName().equals("CMD_" + start)) {
|
397 |
|
|
command_class = inner_class;
|
398 |
|
|
break;
|
399 |
|
|
}
|
400 |
|
|
}
|
401 |
|
|
if(command_class == null) throw new Exception("No command class found for: " + start);
|
402 |
|
|
|
403 |
|
|
//find method
|
404 |
|
|
Method method = null;
|
405 |
|
|
for(Method m : this_class.getDeclaredMethods()) {
|
406 |
|
|
if(m.getName().equals(start)) {
|
407 |
|
|
method = m;
|
408 |
|
|
break;
|
409 |
|
|
}
|
410 |
|
|
}
|
411 |
|
|
if(method == null) throw new Exception("No method found for: " + start);
|
412 |
|
|
|
413 |
|
|
//command class instance
|
414 |
|
|
Object class_obj = command_class.newInstance();
|
415 |
|
|
|
416 |
|
|
for(Field f : command_class.getDeclaredFields()) {
|
417 |
|
|
String field_name = f.getName();
|
418 |
|
|
|
419 |
|
|
if(field_name.equals("time")) {
|
420 |
|
|
f.set(class_obj, params.get(start));
|
421 |
|
|
}
|
422 |
|
|
else if(params.containsKey(field_name)) {
|
423 |
|
|
f.set(class_obj, params.get(field_name));
|
424 |
|
|
}
|
425 |
|
|
else throw new Exception("Unknown field name: " + field_name + " for class: " + command_class.getSimpleName());
|
426 |
|
|
}
|
427 |
|
|
|
428 |
|
|
//execute method
|
429 |
|
|
method.setAccessible(true);
|
430 |
|
|
method.invoke(this, class_obj);
|
431 |
|
|
}
|
432 |
|
|
|
433 |
|
|
private TestUnit unit;
|
434 |
|
|
private OutputStream out;
|
435 |
|
|
}
|