yamon.cc Source File

Back to the index.

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

Generated on Tue Mar 24 2020 14:04:48 for GXemul by doxygen 1.8.17