1 |
/* |
2 |
* Copyright (C) 2005-2007 Anders Gavare. All rights reserved. |
3 |
* |
4 |
* Redistribution and use in source and binary forms, with or without |
5 |
* modification, are permitted provided that the following conditions are met: |
6 |
* |
7 |
* 1. Redistributions of source code must retain the above copyright |
8 |
* notice, this list of conditions and the following disclaimer. |
9 |
* 2. Redistributions in binary form must reproduce the above copyright |
10 |
* notice, this list of conditions and the following disclaimer in the |
11 |
* documentation and/or other materials provided with the distribution. |
12 |
* 3. The name of the author may not be used to endorse or promote products |
13 |
* derived from this software without specific prior written permission. |
14 |
* |
15 |
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND |
16 |
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
17 |
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
18 |
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR 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 |
21 |
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) |
22 |
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT |
23 |
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY |
24 |
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF |
25 |
* SUCH DAMAGE. |
26 |
* |
27 |
* |
28 |
* $Id: machine_test.c,v 1.40 2007/08/29 20:36:49 debug Exp $ |
29 |
* |
30 |
* COMMENT: Various test machines |
31 |
* |
32 |
* Generally, the machines are as follows: |
33 |
* |
34 |
* bareXYZ: A bare machine using an XYZ processor. |
35 |
* |
36 |
* testXYZ: A machine with an XYZ processor, and some experimental |
37 |
* devices connected to it. |
38 |
* |
39 |
* The experimental devices in the test machines are: |
40 |
* |
41 |
* cons A serial I/O console device. |
42 |
* disk A device for reading/writing (emulated) disk sectors. |
43 |
* ether An ethernet device, for sending/receiving ethernet |
44 |
* frames on an emulated network. |
45 |
* fb Framebuffer (24-bit RGB per pixel). |
46 |
* irqc A generic interrupt controller. |
47 |
* mp A multiprocessor controller. |
48 |
* rtc A real-time clock device. |
49 |
*/ |
50 |
|
51 |
#include <stdio.h> |
52 |
#include <string.h> |
53 |
|
54 |
#include "cpu.h" |
55 |
#include "device.h" |
56 |
#include "machine.h" |
57 |
#include "memory.h" |
58 |
#include "misc.h" |
59 |
|
60 |
#include "sh4_exception.h" |
61 |
|
62 |
#include "testmachine/dev_cons.h" |
63 |
#include "testmachine/dev_disk.h" |
64 |
#include "testmachine/dev_ether.h" |
65 |
#include "testmachine/dev_fb.h" |
66 |
#include "testmachine/dev_irqc.h" |
67 |
#include "testmachine/dev_mp.h" |
68 |
#include "testmachine/dev_rtc.h" |
69 |
|
70 |
|
71 |
/* |
72 |
* default_test(): |
73 |
* |
74 |
* Initializes devices for most test machines. (Note: MIPS is different, |
75 |
* because of legacy reasons.) |
76 |
*/ |
77 |
static void default_test(struct machine *machine, struct cpu *cpu) |
78 |
{ |
79 |
char tmpstr[1000]; |
80 |
char base_irq[1000]; |
81 |
char end_of_base_irq[50]; |
82 |
|
83 |
/* |
84 |
* First add the interrupt controller. Most processor architectures |
85 |
* in GXemul have only 1 interrupt pin on the CPU, and it is simply |
86 |
* called "machine[y].cpu[z]". |
87 |
* |
88 |
* MIPS is an exception, dealt with in a separate setup function. |
89 |
* ARM and SH are dealt with here. |
90 |
*/ |
91 |
|
92 |
switch (machine->arch) { |
93 |
|
94 |
case ARCH_ARM: |
95 |
snprintf(end_of_base_irq, sizeof(end_of_base_irq), ".irq"); |
96 |
break; |
97 |
|
98 |
case ARCH_SH: |
99 |
snprintf(end_of_base_irq, sizeof(end_of_base_irq), |
100 |
".irq[0x%x]", SH4_INTEVT_IRQ15); |
101 |
break; |
102 |
|
103 |
default: |
104 |
end_of_base_irq[0] = '\0'; |
105 |
} |
106 |
|
107 |
snprintf(base_irq, sizeof(base_irq), "%s.cpu[%i]%s", |
108 |
machine->path, machine->bootstrap_cpu, end_of_base_irq); |
109 |
|
110 |
snprintf(tmpstr, sizeof(tmpstr), "irqc addr=0x%"PRIx64" irq=%s", |
111 |
(uint64_t) DEV_IRQC_ADDRESS, base_irq); |
112 |
device_add(machine, tmpstr); |
113 |
|
114 |
|
115 |
/* Now, add the other devices: */ |
116 |
|
117 |
snprintf(tmpstr, sizeof(tmpstr), "cons addr=0x%"PRIx64 |
118 |
" irq=%s.irqc.2 in_use=%i", |
119 |
(uint64_t) DEV_CONS_ADDRESS, base_irq, machine->arch != ARCH_SH); |
120 |
machine->main_console_handle = (size_t)device_add(machine, tmpstr); |
121 |
|
122 |
snprintf(tmpstr, sizeof(tmpstr), "mp addr=0x%"PRIx64" irq=%s%sirqc.6", |
123 |
(uint64_t) DEV_MP_ADDRESS, |
124 |
end_of_base_irq[0]? end_of_base_irq + 1 : "", |
125 |
end_of_base_irq[0]? "." : ""); |
126 |
device_add(machine, tmpstr); |
127 |
|
128 |
snprintf(tmpstr, sizeof(tmpstr), "fbctrl addr=0x%"PRIx64, |
129 |
(uint64_t) DEV_FBCTRL_ADDRESS); |
130 |
device_add(machine, tmpstr); |
131 |
|
132 |
snprintf(tmpstr, sizeof(tmpstr), "disk addr=0x%"PRIx64, |
133 |
(uint64_t) DEV_DISK_ADDRESS); |
134 |
device_add(machine, tmpstr); |
135 |
|
136 |
snprintf(tmpstr, sizeof(tmpstr), "ether addr=0x%"PRIx64" irq=%s.irqc.3", |
137 |
(uint64_t) DEV_ETHER_ADDRESS, base_irq); |
138 |
device_add(machine, tmpstr); |
139 |
|
140 |
snprintf(tmpstr, sizeof(tmpstr), "rtc addr=0x%"PRIx64" irq=%s.irqc.4", |
141 |
(uint64_t) DEV_RTC_ADDRESS, base_irq); |
142 |
device_add(machine, tmpstr); |
143 |
} |
144 |
|
145 |
|
146 |
MACHINE_SETUP(barealpha) |
147 |
{ |
148 |
machine->machine_name = "Generic \"bare\" Alpha machine"; |
149 |
} |
150 |
|
151 |
|
152 |
MACHINE_SETUP(testalpha) |
153 |
{ |
154 |
machine->machine_name = "Alpha test machine"; |
155 |
|
156 |
default_test(machine, cpu); |
157 |
} |
158 |
|
159 |
|
160 |
MACHINE_DEFAULT_CPU(barealpha) |
161 |
{ |
162 |
machine->cpu_name = strdup("21264"); |
163 |
} |
164 |
|
165 |
|
166 |
MACHINE_DEFAULT_CPU(testalpha) |
167 |
{ |
168 |
machine->cpu_name = strdup("21264"); |
169 |
} |
170 |
|
171 |
|
172 |
MACHINE_REGISTER(barealpha) |
173 |
{ |
174 |
MR_DEFAULT(barealpha, "Generic \"bare\" Alpha machine", |
175 |
ARCH_ALPHA, MACHINE_BAREALPHA); |
176 |
|
177 |
machine_entry_add_alias(me, "barealpha"); |
178 |
} |
179 |
|
180 |
|
181 |
MACHINE_REGISTER(testalpha) |
182 |
{ |
183 |
MR_DEFAULT(testalpha, "Test-machine for Alpha", |
184 |
ARCH_ALPHA, MACHINE_TESTALPHA); |
185 |
|
186 |
machine_entry_add_alias(me, "testalpha"); |
187 |
} |
188 |
|
189 |
|
190 |
MACHINE_SETUP(barearm) |
191 |
{ |
192 |
machine->machine_name = "Generic \"bare\" ARM machine"; |
193 |
} |
194 |
|
195 |
|
196 |
MACHINE_SETUP(testarm) |
197 |
{ |
198 |
machine->machine_name = "ARM test machine"; |
199 |
|
200 |
default_test(machine, cpu); |
201 |
|
202 |
/* |
203 |
* Place a tiny stub at end of memory, and set the link register to |
204 |
* point to it. This stub halts the machine (making it easy to try |
205 |
* out simple stand-alone C functions). |
206 |
*/ |
207 |
cpu->cd.arm.r[ARM_SP] = machine->physical_ram_in_mb * 1048576 - 4096; |
208 |
cpu->cd.arm.r[ARM_LR] = cpu->cd.arm.r[ARM_SP] + 32; |
209 |
store_32bit_word(cpu, cpu->cd.arm.r[ARM_LR] + 0, 0xe3a00201); |
210 |
store_32bit_word(cpu, cpu->cd.arm.r[ARM_LR] + 4, 0xe5c00010); |
211 |
store_32bit_word(cpu, cpu->cd.arm.r[ARM_LR] + 8, 0xeafffffe); |
212 |
} |
213 |
|
214 |
|
215 |
MACHINE_DEFAULT_CPU(barearm) |
216 |
{ |
217 |
machine->cpu_name = strdup("SA1110"); |
218 |
} |
219 |
|
220 |
|
221 |
MACHINE_DEFAULT_CPU(testarm) |
222 |
{ |
223 |
machine->cpu_name = strdup("SA1110"); |
224 |
} |
225 |
|
226 |
|
227 |
MACHINE_REGISTER(barearm) |
228 |
{ |
229 |
MR_DEFAULT(barearm, "Generic \"bare\" ARM machine", |
230 |
ARCH_ARM, MACHINE_BAREARM); |
231 |
|
232 |
machine_entry_add_alias(me, "barearm"); |
233 |
} |
234 |
|
235 |
|
236 |
MACHINE_REGISTER(testarm) |
237 |
{ |
238 |
MR_DEFAULT(testarm, "Test-machine for ARM", ARCH_ARM, MACHINE_TESTARM); |
239 |
|
240 |
machine_entry_add_alias(me, "testarm"); |
241 |
} |
242 |
|
243 |
|
244 |
|
245 |
MACHINE_SETUP(barem32r) |
246 |
{ |
247 |
machine->machine_name = "Generic \"bare\" M32R machine"; |
248 |
} |
249 |
|
250 |
|
251 |
MACHINE_SETUP(testm32r) |
252 |
{ |
253 |
machine->machine_name = "M32R test machine"; |
254 |
|
255 |
default_test(machine, cpu); |
256 |
} |
257 |
|
258 |
|
259 |
MACHINE_DEFAULT_CPU(barem32r) |
260 |
{ |
261 |
machine->cpu_name = strdup("M32R"); |
262 |
} |
263 |
|
264 |
|
265 |
MACHINE_DEFAULT_CPU(testm32r) |
266 |
{ |
267 |
machine->cpu_name = strdup("M32R"); |
268 |
} |
269 |
|
270 |
|
271 |
MACHINE_REGISTER(barem32r) |
272 |
{ |
273 |
MR_DEFAULT(barem32r, "Generic \"bare\" M32R machine", |
274 |
ARCH_M32R, MACHINE_BAREM32R); |
275 |
|
276 |
machine_entry_add_alias(me, "barem32r"); |
277 |
} |
278 |
|
279 |
|
280 |
MACHINE_REGISTER(testm32r) |
281 |
{ |
282 |
MR_DEFAULT(testm32r, "Test-machine for M32R", |
283 |
ARCH_M32R, MACHINE_TESTM32R); |
284 |
|
285 |
machine_entry_add_alias(me, "testm32r"); |
286 |
} |
287 |
|
288 |
|
289 |
MACHINE_SETUP(barem88k) |
290 |
{ |
291 |
machine->machine_name = "Generic \"bare\" M88K machine"; |
292 |
} |
293 |
|
294 |
|
295 |
MACHINE_SETUP(testm88k) |
296 |
{ |
297 |
machine->machine_name = "M88K test machine"; |
298 |
|
299 |
default_test(machine, cpu); |
300 |
} |
301 |
|
302 |
|
303 |
MACHINE_DEFAULT_CPU(barem88k) |
304 |
{ |
305 |
machine->cpu_name = strdup("88110"); |
306 |
} |
307 |
|
308 |
|
309 |
MACHINE_DEFAULT_CPU(testm88k) |
310 |
{ |
311 |
machine->cpu_name = strdup("88110"); |
312 |
} |
313 |
|
314 |
|
315 |
MACHINE_REGISTER(barem88k) |
316 |
{ |
317 |
MR_DEFAULT(barem88k, "Generic \"bare\" M88K machine", |
318 |
ARCH_M88K, MACHINE_BAREM88K); |
319 |
|
320 |
machine_entry_add_alias(me, "barem88k"); |
321 |
} |
322 |
|
323 |
|
324 |
MACHINE_REGISTER(testm88k) |
325 |
{ |
326 |
MR_DEFAULT(testm88k, "Test-machine for M88K", |
327 |
ARCH_M88K, MACHINE_TESTM88K); |
328 |
|
329 |
machine_entry_add_alias(me, "testm88k"); |
330 |
} |
331 |
|
332 |
|
333 |
MACHINE_SETUP(baremips) |
334 |
{ |
335 |
machine->machine_name = "Generic \"bare\" MIPS machine"; |
336 |
cpu->byte_order = EMUL_BIG_ENDIAN; |
337 |
} |
338 |
|
339 |
|
340 |
MACHINE_SETUP(testmips) |
341 |
{ |
342 |
/* |
343 |
* A MIPS test machine. Originally, this was created as a way for |
344 |
* me to test my master's thesis code; since then it has both |
345 |
* evolved to support new things, and suffered bit rot so that it |
346 |
* no longer can run my thesis code. Well, well... |
347 |
* |
348 |
* IRQ map: |
349 |
* 7 CPU counter |
350 |
* 6 SMP IPIs |
351 |
* 5 not used yet |
352 |
* 4 rtc |
353 |
* 3 ethernet |
354 |
* 2 serial console |
355 |
*/ |
356 |
|
357 |
char tmpstr[300]; |
358 |
|
359 |
machine->machine_name = "MIPS test machine"; |
360 |
cpu->byte_order = EMUL_BIG_ENDIAN; |
361 |
|
362 |
snprintf(tmpstr, sizeof(tmpstr), "cons addr=0x%"PRIx64" irq=%s." |
363 |
"cpu[%i].2", (uint64_t) DEV_CONS_ADDRESS, machine->path, |
364 |
machine->bootstrap_cpu); |
365 |
machine->main_console_handle = (size_t)device_add(machine, tmpstr); |
366 |
|
367 |
snprintf(tmpstr, sizeof(tmpstr), "mp addr=0x%"PRIx64" irq=6", |
368 |
(uint64_t) DEV_MP_ADDRESS); |
369 |
device_add(machine, tmpstr); |
370 |
|
371 |
snprintf(tmpstr, sizeof(tmpstr), "fbctrl addr=0x%"PRIx64, |
372 |
(uint64_t) DEV_FBCTRL_ADDRESS); |
373 |
device_add(machine, tmpstr); |
374 |
|
375 |
snprintf(tmpstr, sizeof(tmpstr), "disk addr=0x%"PRIx64, |
376 |
(uint64_t) DEV_DISK_ADDRESS); |
377 |
device_add(machine, tmpstr); |
378 |
|
379 |
snprintf(tmpstr, sizeof(tmpstr), "ether addr=0x%"PRIx64" irq=%s." |
380 |
"cpu[%i].3", (uint64_t) DEV_ETHER_ADDRESS, machine->path, |
381 |
machine->bootstrap_cpu); |
382 |
device_add(machine, tmpstr); |
383 |
|
384 |
snprintf(tmpstr, sizeof(tmpstr), "rtc addr=0x%"PRIx64" irq=%s." |
385 |
"cpu[%i].4", (uint64_t) DEV_RTC_ADDRESS, machine->path, |
386 |
machine->bootstrap_cpu); |
387 |
device_add(machine, tmpstr); |
388 |
} |
389 |
|
390 |
|
391 |
MACHINE_DEFAULT_CPU(baremips) |
392 |
{ |
393 |
machine->cpu_name = strdup("5KE"); |
394 |
} |
395 |
|
396 |
|
397 |
MACHINE_DEFAULT_CPU(testmips) |
398 |
{ |
399 |
machine->cpu_name = strdup("5KE"); |
400 |
} |
401 |
|
402 |
|
403 |
MACHINE_REGISTER(baremips) |
404 |
{ |
405 |
MR_DEFAULT(baremips, "Generic \"bare\" MIPS machine", |
406 |
ARCH_MIPS, MACHINE_BAREMIPS); |
407 |
|
408 |
machine_entry_add_alias(me, "baremips"); |
409 |
} |
410 |
|
411 |
|
412 |
MACHINE_REGISTER(testmips) |
413 |
{ |
414 |
MR_DEFAULT(testmips, "Test-machine for MIPS", |
415 |
ARCH_MIPS, MACHINE_TESTMIPS); |
416 |
|
417 |
machine_entry_add_alias(me, "testmips"); |
418 |
} |
419 |
|
420 |
|
421 |
MACHINE_SETUP(bareppc) |
422 |
{ |
423 |
machine->machine_name = "Generic \"bare\" PPC machine"; |
424 |
} |
425 |
|
426 |
|
427 |
MACHINE_SETUP(testppc) |
428 |
{ |
429 |
machine->machine_name = "PPC test machine"; |
430 |
|
431 |
default_test(machine, cpu); |
432 |
} |
433 |
|
434 |
|
435 |
MACHINE_DEFAULT_CPU(bareppc) |
436 |
{ |
437 |
machine->cpu_name = strdup("PPC970"); |
438 |
} |
439 |
|
440 |
|
441 |
MACHINE_DEFAULT_CPU(testppc) |
442 |
{ |
443 |
machine->cpu_name = strdup("PPC970"); |
444 |
} |
445 |
|
446 |
|
447 |
MACHINE_REGISTER(bareppc) |
448 |
{ |
449 |
MR_DEFAULT(bareppc, "Generic \"bare\" PPC machine", |
450 |
ARCH_PPC, MACHINE_BAREPPC); |
451 |
|
452 |
machine_entry_add_alias(me, "bareppc"); |
453 |
} |
454 |
|
455 |
|
456 |
MACHINE_REGISTER(testppc) |
457 |
{ |
458 |
MR_DEFAULT(testppc, "Test-machine for PPC", ARCH_PPC, MACHINE_TESTPPC); |
459 |
|
460 |
machine_entry_add_alias(me, "testppc"); |
461 |
} |
462 |
|
463 |
|
464 |
MACHINE_SETUP(baresh) |
465 |
{ |
466 |
machine->machine_name = "Generic \"bare\" SH machine"; |
467 |
} |
468 |
|
469 |
|
470 |
MACHINE_SETUP(testsh) |
471 |
{ |
472 |
machine->machine_name = "SH test machine"; |
473 |
|
474 |
default_test(machine, cpu); |
475 |
} |
476 |
|
477 |
|
478 |
MACHINE_DEFAULT_CPU(baresh) |
479 |
{ |
480 |
machine->cpu_name = strdup("SH7750"); |
481 |
} |
482 |
|
483 |
|
484 |
MACHINE_DEFAULT_CPU(testsh) |
485 |
{ |
486 |
machine->cpu_name = strdup("SH7750"); |
487 |
} |
488 |
|
489 |
|
490 |
MACHINE_REGISTER(baresh) |
491 |
{ |
492 |
MR_DEFAULT(baresh, "Generic \"bare\" SH machine", |
493 |
ARCH_SH, MACHINE_BARESH); |
494 |
|
495 |
machine_entry_add_alias(me, "baresh"); |
496 |
} |
497 |
|
498 |
|
499 |
MACHINE_REGISTER(testsh) |
500 |
{ |
501 |
MR_DEFAULT(testsh, "Test-machine for SH", ARCH_SH, MACHINE_TESTSH); |
502 |
|
503 |
machine_entry_add_alias(me, "testsh"); |
504 |
} |
505 |
|
506 |
|
507 |
MACHINE_SETUP(baresparc) |
508 |
{ |
509 |
machine->machine_name = "Generic \"bare\" SPARC machine"; |
510 |
} |
511 |
|
512 |
|
513 |
MACHINE_SETUP(testsparc) |
514 |
{ |
515 |
machine->machine_name = "SPARC test machine"; |
516 |
|
517 |
default_test(machine, cpu); |
518 |
} |
519 |
|
520 |
|
521 |
MACHINE_DEFAULT_CPU(baresparc) |
522 |
{ |
523 |
machine->cpu_name = strdup("UltraSPARC"); |
524 |
} |
525 |
|
526 |
|
527 |
MACHINE_DEFAULT_CPU(testsparc) |
528 |
{ |
529 |
machine->cpu_name = strdup("UltraSPARC"); |
530 |
} |
531 |
|
532 |
|
533 |
MACHINE_REGISTER(baresparc) |
534 |
{ |
535 |
MR_DEFAULT(baresparc, "Generic \"bare\" SPARC machine", |
536 |
ARCH_SPARC, MACHINE_BARESPARC); |
537 |
|
538 |
machine_entry_add_alias(me, "baresparc"); |
539 |
} |
540 |
|
541 |
|
542 |
MACHINE_REGISTER(testsparc) |
543 |
{ |
544 |
MR_DEFAULT(testsparc, "Test-machine for SPARC", |
545 |
ARCH_SPARC, MACHINE_TESTSPARC); |
546 |
|
547 |
machine_entry_add_alias(me, "testsparc"); |
548 |
} |
549 |
|
550 |
|