/[gxemul]/trunk/src/promemul/yamon.c
This is repository of my old source code which isn't updated any more. Go to git.rot13.org for current projects!
ViewVC logotype

Annotation of /trunk/src/promemul/yamon.c

Parent Directory Parent Directory | Revision Log Revision Log


Revision 44 - (hide annotations)
Mon Oct 8 16:22:56 2007 UTC (16 years, 7 months ago) by dpavlin
File MIME type: text/plain
File size: 6679 byte(s)
++ trunk/HISTORY	(local)
$Id: HISTORY,v 1.1632 2007/09/11 21:46:35 debug Exp $
20070616	Implementing the MIPS32/64 revision 2 "ror" instruction.
20070617	Adding a struct for each physpage which keeps track of which
		ranges within that page (base offset, length) that are
		continuously translatable. When running with native code
		generation enabled (-b), a range is added after each read-
		ahead loop.
		Experimenting with using the physical program counter sample
		data (implemented 20070608) together with the "translatable
		range" information, to figure out which physical address ranges
		would be worth translating to native code (if the number of
		samples falling within a range is above a certain threshold).
20070618	Adding automagic building of .index comment files for
		src/file/, src/promemul/, src src/useremul/ as well.
		Adding a "has been translated" bit to the ranges, so that only
		not-yet-translated ranges will be sampled.
20070619	Moving src/cpu.c and src/memory_rw.c into src/cpus/,
		src/device.c into src/devices/, and src/machine.c into
		src/machines/.
		Creating a skeleton cc/ld native backend module; beginning on
		the function which will detect cc command line, etc.
20070620	Continuing on the native code generation infrastructure.
20070621	Moving src/x11.c and src/console.c into a new src/console/
		subdir (for everything that is console or framebuffer related).
		Moving src/symbol*.c into a new src/symbol/, which should
		contain anything that is symbol handling related.
20070624	Making the program counter sampling threshold a "settings
		variable" (sampling_threshold), i.e. it can now be changed
		during runtime.
		Switching the RELEASE notes format from plain text to HTML.
		If the TMPDIR environment variable is set, it is used instead
		of "/tmp" for temporary files.
		Continuing on the cc/ld backend: simple .c code is generated,
		the compiler and linker are called, etc.
		Adding detection of host architecture to the configure script
		(again), and adding icache invalidation support (only
		implemented for Alpha hosts so far).
20070625	Simplifying the program counter sampling mechanism.
20070626	Removing the cc/ld native code generation stuff, program
		counter sampling, etc; it would not have worked well in the
		general case.
20070627	Removing everything related to native code generation.
20070629	Removing the (practically unusable) support for multiple
		emulations. (The single emulation allowed now still supports
		multiple simultaneous machines, as before.)
		Beginning on PCCTWO and M88K interrupts.
20070723	Adding a dummy skeleton for emulation of M32R processors.
20070901	Fixing a warning found by "gcc version 4.3.0 20070817
		(experimental)" on amd64.
20070905	Removing some more traces of the old "multiple emulations"
		code.
		Also looking in /usr/local/include and /usr/local/lib for
		X11 libs, when running configure.
20070909	Minor updates to the guest OS install instructions, in
		preparation for the NetBSD 4.0 release.
20070918	More testing of NetBSD 4.0 RC1.

1 dpavlin 14 /*
2 dpavlin 34 * Copyright (C) 2005-2007 Anders Gavare. All rights reserved.
3 dpavlin 14 *
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 dpavlin 44 * $Id: yamon.c,v 1.14 2007/06/17 23:32:21 debug Exp $
29 dpavlin 14 *
30 dpavlin 44 * COMMENT: YAMON emulation
31     *
32     * (Very basic, only what is needed to get NetBSD booting.)
33 dpavlin 14 */
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 dpavlin 32 #include "net.h"
47 dpavlin 14
48 dpavlin 28 #include "yamon.h"
49 dpavlin 14
50    
51     /*
52 dpavlin 32 * 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 dpavlin 14 * yamon_emul():
138     *
139     * YAMON emulation (for evbmips).
140     */
141     int yamon_emul(struct cpu *cpu)
142     {
143 dpavlin 28 uint32_t ofs = (cpu->pc & 0xff) + YAMON_FUNCTION_BASE;
144     uint8_t ch;
145 dpavlin 14 int n;
146 dpavlin 42 uint32_t oid;
147     uint64_t paddr, psize;
148 dpavlin 14
149     switch (ofs) {
150 dpavlin 28
151     case YAMON_PRINT_COUNT_OFS:
152     /*
153     * print count:
154     * a1 = string
155     * a2 = count
156     */
157 dpavlin 14 n = 0;
158 dpavlin 28 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 dpavlin 14 n++;
164     }
165     break;
166 dpavlin 28
167     case YAMON_EXIT_OFS:
168     /*
169     * exit
170     */
171     debug("[ yamon_emul(): exit ]\n");
172 dpavlin 14 cpu->running = 0;
173     break;
174 dpavlin 28
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 dpavlin 42 * syscon_read(oid [a0], addr [a1], size [a2])
196 dpavlin 28 */
197    
198 dpavlin 42 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 dpavlin 14 break;
232 dpavlin 28
233 dpavlin 42 default:
234     cpu_register_dump(cpu->machine, cpu, 1, 0);
235 dpavlin 14 printf("\n");
236 dpavlin 28 fatal("[ yamon_emul(): unimplemented yamon function 0x%"
237     PRIx32" ]\n", ofs);
238 dpavlin 14 cpu->running = 0;
239     }
240    
241     return 1;
242     }
243    

  ViewVC Help
Powered by ViewVC 1.1.26