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: yamon.c,v 1.14 2007/06/17 23:32:21 debug Exp $ |
29 |
* |
30 |
* COMMENT: YAMON emulation |
31 |
* |
32 |
* (Very basic, only what is needed to get NetBSD booting.) |
33 |
*/ |
34 |
|
35 |
#include <stdio.h> |
36 |
#include <stdlib.h> |
37 |
#include <string.h> |
38 |
#include <sys/types.h> |
39 |
|
40 |
#include "console.h" |
41 |
#include "cpu.h" |
42 |
#include "cpu_mips.h" |
43 |
#include "machine.h" |
44 |
#include "memory.h" |
45 |
#include "misc.h" |
46 |
#include "net.h" |
47 |
|
48 |
#include "yamon.h" |
49 |
|
50 |
|
51 |
/* |
52 |
* yamon_machine_setup(): |
53 |
*/ |
54 |
void yamon_machine_setup(struct machine *machine, uint64_t env) |
55 |
{ |
56 |
char tmps[200]; |
57 |
char macaddr[6]; |
58 |
uint64_t tmpptr = env + 0x400; |
59 |
struct cpu *cpu = machine->cpus[0]; |
60 |
|
61 |
/* |
62 |
* Standard YAMON environment variables: |
63 |
* |
64 |
* baseboardserial |
65 |
* bootfile TODO |
66 |
* bootprot TODO: Non-tftp boot |
67 |
* bootserport |
68 |
* bootserver |
69 |
* cpuconfig TODO |
70 |
* ethaddr |
71 |
* fpu TODO |
72 |
* gateway |
73 |
* ipaddr TODO: Don't hardcode! |
74 |
* memsize |
75 |
* modetty0 |
76 |
* modetty1 |
77 |
* prompt |
78 |
* start TODO |
79 |
* startdelay TODO |
80 |
* subnetmask TODO: Real subnet mask |
81 |
* yamonrev |
82 |
*/ |
83 |
|
84 |
add_environment_string_dual(cpu, &env, &tmpptr, |
85 |
"baseboardserial", "0000000000"); |
86 |
|
87 |
/* TODO: Disk boot! */ |
88 |
add_environment_string_dual(cpu, &env, &tmpptr, "bootprot", "tftp"); |
89 |
|
90 |
add_environment_string_dual(cpu, &env, &tmpptr, "bootserport", "tty0"); |
91 |
|
92 |
add_environment_string_dual(cpu, &env, &tmpptr, |
93 |
"bootserver", "10.0.0.254"); |
94 |
|
95 |
net_generate_unique_mac(machine, (unsigned char *) macaddr); |
96 |
snprintf(tmps, sizeof(tmps), "%02x.%02x.%02x.%02x.%02x.%02x", |
97 |
macaddr[0], macaddr[1], macaddr[2], |
98 |
macaddr[3], macaddr[4], macaddr[5]); |
99 |
add_environment_string_dual(cpu, &env, &tmpptr, "ethaddr", tmps); |
100 |
|
101 |
add_environment_string_dual(cpu, &env, &tmpptr, |
102 |
"gateway", "10.0.0.254"); |
103 |
|
104 |
/* TODO: Don't hardcode! */ |
105 |
add_environment_string_dual(cpu, &env, &tmpptr, |
106 |
"ipaddr", "10.0.0.1"); |
107 |
|
108 |
snprintf(tmps, sizeof(tmps), "0x%08x", machine->physical_ram_in_mb<<20); |
109 |
add_environment_string_dual(cpu, &env, &tmpptr, "memsize", tmps); |
110 |
|
111 |
add_environment_string_dual(cpu, &env, &tmpptr, |
112 |
"modetty0", "38400,n,8,1,none"); |
113 |
|
114 |
add_environment_string_dual(cpu, &env, &tmpptr, |
115 |
"modetty1", "38400,n,8,1,none"); |
116 |
|
117 |
add_environment_string_dual(cpu, &env, &tmpptr, "prompt", "YAMON"); |
118 |
|
119 |
add_environment_string_dual(cpu, &env, &tmpptr, "yamonrev", "02.06"); |
120 |
|
121 |
/* TODO: Real subnet mask: */ |
122 |
add_environment_string_dual(cpu, &env, &tmpptr, |
123 |
"subnetmask", "255.0.0.0"); |
124 |
|
125 |
|
126 |
/* FreeBSD development specific: */ |
127 |
snprintf(tmps, sizeof(tmps), "%i", machine->emulated_hz / 1000); |
128 |
add_environment_string_dual(cpu, &env, &tmpptr, "khz", tmps); |
129 |
|
130 |
/* NULL terminate: */ |
131 |
tmpptr = 0; |
132 |
add_environment_string_dual(cpu, &env, &tmpptr, NULL, NULL); |
133 |
} |
134 |
|
135 |
|
136 |
/* |
137 |
* yamon_emul(): |
138 |
* |
139 |
* YAMON emulation (for evbmips). |
140 |
*/ |
141 |
int yamon_emul(struct cpu *cpu) |
142 |
{ |
143 |
uint32_t ofs = (cpu->pc & 0xff) + YAMON_FUNCTION_BASE; |
144 |
uint8_t ch; |
145 |
int n; |
146 |
uint32_t oid; |
147 |
uint64_t paddr, psize; |
148 |
|
149 |
switch (ofs) { |
150 |
|
151 |
case YAMON_PRINT_COUNT_OFS: |
152 |
/* |
153 |
* print count: |
154 |
* a1 = string |
155 |
* a2 = count |
156 |
*/ |
157 |
n = 0; |
158 |
while (n < (int32_t)cpu->cd.mips.gpr[MIPS_GPR_A2]) { |
159 |
cpu->memory_rw(cpu, cpu->mem, (int32_t)cpu->cd.mips.gpr |
160 |
[MIPS_GPR_A1] + n, &ch, sizeof(ch), MEM_READ, |
161 |
CACHE_DATA | NO_EXCEPTIONS); |
162 |
console_putchar(cpu->machine->main_console_handle, ch); |
163 |
n++; |
164 |
} |
165 |
break; |
166 |
|
167 |
case YAMON_EXIT_OFS: |
168 |
/* |
169 |
* exit |
170 |
*/ |
171 |
debug("[ yamon_emul(): exit ]\n"); |
172 |
cpu->running = 0; |
173 |
break; |
174 |
|
175 |
/* YAMON_FLUSH_CACHE_OFS: TODO */ |
176 |
/* YAMON_PRINT_OFS: TODO */ |
177 |
/* YAMON_REG_CPU_ISR_OFS: TODO */ |
178 |
/* YAMON_DEREG_CPU_ISR_OFS: TODO */ |
179 |
/* YAMON_REG_IC_ISR_OFS: TODO */ |
180 |
/* YAMON_DEREG_IC_ISR_OFS: TODO */ |
181 |
/* YAMON_REG_ESR_OFS: TODO */ |
182 |
/* YAMON_DEREG_ESR_OFS: TODO */ |
183 |
|
184 |
case YAMON_GETCHAR_OFS: |
185 |
n = console_readchar(cpu->machine->main_console_handle); |
186 |
/* Note: -1 (if no char was available) becomes 0xff: */ |
187 |
ch = n; |
188 |
cpu->memory_rw(cpu, cpu->mem, (int32_t)cpu->cd.mips.gpr[ |
189 |
MIPS_GPR_A1], &ch, sizeof(ch), MEM_WRITE, |
190 |
CACHE_DATA | NO_EXCEPTIONS); |
191 |
break; |
192 |
|
193 |
case YAMON_SYSCON_READ_OFS: |
194 |
/* |
195 |
* syscon_read(oid [a0], addr [a1], size [a2]) |
196 |
*/ |
197 |
|
198 |
oid = cpu->cd.mips.gpr[MIPS_GPR_A0]; |
199 |
paddr = cpu->cd.mips.gpr[MIPS_GPR_A1]; |
200 |
psize = cpu->cd.mips.gpr[MIPS_GPR_A2]; |
201 |
|
202 |
switch (oid) { |
203 |
case SYSCON_BOARD_CPU_CLOCK_FREQ_ID: |
204 |
if (psize == sizeof(uint32_t)) { |
205 |
uint32_t freq = cpu->machine->emulated_hz; |
206 |
|
207 |
debug("[ yamon_emul(): reporting CPU " |
208 |
"frequency of %u ]\n", (unsigned int) |
209 |
freq); |
210 |
|
211 |
if (cpu->byte_order == EMUL_LITTLE_ENDIAN) |
212 |
freq = LE32_TO_HOST(freq); |
213 |
else |
214 |
freq = BE32_TO_HOST(freq); |
215 |
|
216 |
cpu->memory_rw(cpu, cpu->mem, (int32_t)paddr, |
217 |
(void *) &freq, sizeof(freq), MEM_WRITE, |
218 |
CACHE_DATA | NO_EXCEPTIONS); |
219 |
|
220 |
cpu->cd.mips.gpr[MIPS_GPR_V0] = 0; |
221 |
} else { |
222 |
cpu->cd.mips.gpr[MIPS_GPR_V0] = 1; |
223 |
} |
224 |
break; |
225 |
|
226 |
default: |
227 |
fatal("[ yamon_emul(): unimplemented object id 0x%" |
228 |
PRIx32" ]\n", oid); |
229 |
cpu->cd.mips.gpr[MIPS_GPR_V0] = 1; |
230 |
} |
231 |
break; |
232 |
|
233 |
default: |
234 |
cpu_register_dump(cpu->machine, cpu, 1, 0); |
235 |
printf("\n"); |
236 |
fatal("[ yamon_emul(): unimplemented yamon function 0x%" |
237 |
PRIx32" ]\n", ofs); |
238 |
cpu->running = 0; |
239 |
} |
240 |
|
241 |
return 1; |
242 |
} |
243 |
|