1 |
/* |
2 |
* Copyright (C) 2005 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: yamon.c,v 1.3 2005/06/21 17:42:08 debug Exp $ |
29 |
* |
30 |
* YAMON emulation. |
31 |
*/ |
32 |
|
33 |
#include <stdio.h> |
34 |
#include <stdlib.h> |
35 |
#include <string.h> |
36 |
#include <sys/types.h> |
37 |
|
38 |
#include "console.h" |
39 |
#include "cpu.h" |
40 |
#include "cpu_mips.h" |
41 |
#include "machine.h" |
42 |
#include "memory.h" |
43 |
#include "misc.h" |
44 |
|
45 |
|
46 |
/* |
47 |
* mem_readchar(): |
48 |
* |
49 |
* Reads a byte from emulated RAM, using a MIPS register as a base address. |
50 |
* (Helper function.) |
51 |
*/ |
52 |
static unsigned char mem_readchar(struct cpu *cpu, int regbase, int offset) |
53 |
{ |
54 |
unsigned char ch; |
55 |
cpu->memory_rw(cpu, cpu->mem, cpu->cd.mips.gpr[regbase] + offset, |
56 |
&ch, sizeof(ch), MEM_READ, CACHE_DATA | NO_EXCEPTIONS); |
57 |
return ch; |
58 |
} |
59 |
|
60 |
|
61 |
/* |
62 |
* yamon_emul(): |
63 |
* |
64 |
* YAMON emulation (for evbmips). |
65 |
*/ |
66 |
int yamon_emul(struct cpu *cpu) |
67 |
{ |
68 |
int ofs = cpu->pc & 0xfff; |
69 |
int n; |
70 |
|
71 |
switch (ofs) { |
72 |
case 0x804: /* "print count": string at a1, count at a2 */ |
73 |
n = 0; |
74 |
while (n < cpu->cd.mips.gpr[MIPS_GPR_A2]) { |
75 |
char ch = mem_readchar(cpu, MIPS_GPR_A1, n); |
76 |
console_putchar(cpu->machine->main_console_handle, |
77 |
ch); |
78 |
n++; |
79 |
} |
80 |
break; |
81 |
case 0x820: /* "exit" */ |
82 |
debug("[ yamon_emul(): exit ]\n"); |
83 |
cpu->running = 0; |
84 |
break; |
85 |
case 0x854: /* "syscon" */ |
86 |
fatal("[ yamon_emul(): syscon: TODO ]\n"); |
87 |
/* TODO. For now, return some kind of "failure": */ |
88 |
cpu->cd.mips.gpr[MIPS_GPR_V0] = 1; |
89 |
break; |
90 |
default:cpu_register_dump(cpu->machine, cpu, 1, 0); |
91 |
printf("\n"); |
92 |
fatal("[ yamon_emul(): unimplemented ofs 0x%x ]\n", ofs); |
93 |
cpu->running = 0; |
94 |
cpu->dead = 1; |
95 |
} |
96 |
|
97 |
return 1; |
98 |
} |
99 |
|