/[gxemul]/trunk/src/cpus/cpu_transputer.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/cpus/cpu_transputer.c

Parent Directory Parent Directory | Revision Log Revision Log


Revision 30 - (hide annotations)
Mon Oct 8 16:20:40 2007 UTC (16 years, 6 months ago) by dpavlin
File MIME type: text/plain
File size: 9576 byte(s)
++ trunk/HISTORY	(local)
$Id: HISTORY,v 1.1325 2006/08/15 15:38:37 debug Exp $
20060723	More Transputer instructions (pfix, nfix, opr, mint, ldl, ldlp,
		eqc, rev, ajw, stl, stlf, sthf, sub, ldnl, ldnlp, ldpi, move,
		wcnt, add, bcnt).
		Adding more SPARC instructions (andcc, addcc, bl, rdpr).
		Progress on the igsfb framebuffer used by NetBSD/netwinder.
		Enabling 8-bit fills in dev_fb.
		NetBSD/netwinder 3.0.1 can now run from a disk image :-)
20060724	Cleanup/performance fix for 64-bit virtual translation table
		updates (by removing the "timestamp" stuff). A full NetBSD/pmax
		3.0.1 install for R4400 has dropped from 667 seconds to 584 :)
		Fixing the igsfb "almost vga" color (it is 24-bit, not 18-bit).
		Adding some MIPS instruction combinations (3*lw, and 3*addu).
		The 8048 keyboard now turns off interrupt enable between the
		KBR_ACK and the KBR_RSTDONE, to work better with Linux 2.6.
		Not causing PPC DEC interrupts if PPC_NO_DEC is set for a
		specific CPU; NetBSD/bebox gets slightly further than before.
		Adding some more SPARC instructions: branches, udiv.
20060725	Refreshing dev_pckbc.c a little.
		Cleanups for the SH emulation mode, and adding the first
		"compact" (16-bit) instructions: various simple movs, nop,
		shll, stc, or, ldc.
20060726	Adding dummy "pcn" (AMD PCnet NIC) PCI glue.
20060727	Various cleanups; removing stuff from cpu.h, such as
		running_translated (not really meaningful anymore), and
		page flags (breaking into the debugger clears all translations
		anyway).
		Minor MIPS instruction combination updates.
20060807	Expanding the 3*sw and 3*lw MIPS instruction combinations to
		work with 2* and 4* too, resulting in a minor performance gain.
		Implementing a usleep hack for the RM52xx/MIPS32/MIPS64 "wait"
		instruction (when emulating 1 cpu).
20060808	Experimenting with some more MIPS instruction combinations.
		Implementing support for showing a (hardcoded 12x22) text
		cursor in igsfb.
20060809	Simplifying the NetBSD/evbmips (Malta) install instructions
		somewhat (by using a NetBSD/pmax ramdisk install kernel).
20060812	Experimenting more with the MIPS 'wait' instruction.
		PCI configuration register writes can now be handled, which
		allow PCI IDE controllers to work with NetBSD/Malta 3.0.1 and
		NetBSD/cobalt 3.0.1. (Previously only NetBSD 2.1 worked.)
20060813	Updating dev_gt.c based on numbers from Alec Voropay, to enable
		Linux 2.6 to use PCI on Malta.
		Continuing on Algor interrupt stuff.
20060814	Adding support for routing ISA interrupts to two different
		interrupts, making it possible to run NetBSD/algor :-)
20060814-15	Testing for the release.

==============  RELEASE 0.4.2  ==============


1 dpavlin 28 /*
2     * Copyright (C) 2006 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 dpavlin 30 * $Id: cpu_transputer.c,v 1.4 2006/07/23 14:37:34 debug Exp $
29 dpavlin 28 *
30     * INMOS transputer CPU emulation.
31     */
32    
33     #include <stdio.h>
34     #include <stdlib.h>
35     #include <string.h>
36     #include <ctype.h>
37    
38     #include "cpu.h"
39     #include "machine.h"
40     #include "memory.h"
41     #include "misc.h"
42     #include "symbol.h"
43    
44     #define DYNTRANS_32
45     #include "tmp_transputer_head.c"
46    
47    
48     static char *opcode_names[16] = TRANSPUTER_INSTRUCTIONS;
49 dpavlin 30 static char *opcode_f_names[N_TRANSPUTER_OPC_F_NAMES] = TRANSPUTER_OPC_F_NAMES;
50 dpavlin 28
51     /*
52     * transputer_cpu_new():
53     *
54     * Create a new TRANSPUTER cpu object.
55     *
56     * Returns 1 on success, 0 if there was no matching TRANSPUTER processor with
57     * this cpu_type_name.
58     */
59     int transputer_cpu_new(struct cpu *cpu, struct memory *mem,
60     struct machine *machine, int cpu_id, char *cpu_type_name)
61     {
62     int i = 0;
63     struct transputer_cpu_type_def cpu_type_defs[] =
64     TRANSPUTER_CPU_TYPE_DEFS;
65    
66     /* Scan the cpu_type_defs list for this cpu type: */
67     while (cpu_type_defs[i].name != NULL) {
68     if (strcasecmp(cpu_type_defs[i].name, cpu_type_name) == 0) {
69     break;
70     }
71     i++;
72     }
73     if (cpu_type_defs[i].name == NULL)
74     return 0;
75    
76     cpu->cd.transputer.cpu_type = cpu_type_defs[i];
77     cpu->name = cpu->cd.transputer.cpu_type.name;
78     cpu->byte_order = EMUL_LITTLE_ENDIAN;
79     cpu->is_32bit = 1;
80    
81     if (cpu->cd.transputer.cpu_type.bits != 32) {
82     fatal("Only 32-bit Transputer processors can be "
83     "emulated. 16-bit mode is not supported. Sorry.\n");
84     exit(1);
85     }
86    
87     cpu->run_instr = transputer_run_instr;
88     cpu->memory_rw = transputer_memory_rw;
89     cpu->update_translation_table = transputer_update_translation_table;
90     cpu->invalidate_translation_caches =
91     transputer_invalidate_translation_caches;
92     cpu->invalidate_code_translation =
93     transputer_invalidate_code_translation;
94    
95     /* Only show name and caches etc for CPU nr 0 (in SMP machines): */
96     if (cpu_id == 0) {
97     debug("%s", cpu->name);
98     }
99    
100 dpavlin 30 cpu->cd.transputer.wptr = machine->physical_ram_in_mb * 1048576 - 2048;
101    
102 dpavlin 28 return 1;
103     }
104    
105    
106     /*
107     * transputer_cpu_list_available_types():
108     *
109     * Print a list of available TRANSPUTER CPU types.
110     */
111     void transputer_cpu_list_available_types(void)
112     {
113     int i = 0, j;
114     struct transputer_cpu_type_def tdefs[] = TRANSPUTER_CPU_TYPE_DEFS;
115    
116     while (tdefs[i].name != NULL) {
117     debug("%s", tdefs[i].name);
118     for (j = 7 - strlen(tdefs[i].name); j > 0; j --)
119     debug(" ");
120     i ++;
121     if ((i % 8) == 0 || tdefs[i].name == NULL)
122     debug("\n");
123     }
124     }
125    
126    
127     /*
128     * transputer_cpu_dumpinfo():
129     */
130     void transputer_cpu_dumpinfo(struct cpu *cpu)
131     {
132     /* TODO */
133     debug("\n");
134     }
135    
136    
137     /*
138     * transputer_cpu_register_dump():
139     *
140     * Dump cpu registers in a relatively readable format.
141     *
142     * gprs: set to non-zero to dump GPRs and some special-purpose registers.
143     * coprocs: set bit 0..3 to dump registers in coproc 0..3.
144     */
145     void transputer_cpu_register_dump(struct cpu *cpu, int gprs, int coprocs)
146     {
147     char *symbol;
148     uint64_t offset;
149     int x = cpu->cpu_id;
150    
151     symbol = get_symbol_name(&cpu->machine->symbol_context,
152     cpu->pc, &offset);
153    
154     debug("cpu%i: wptr = 0x%08"PRIx32" oreg = 0x%08"PRIx32" ip = 0x%08"
155     PRIx32, x, cpu->cd.transputer.wptr, cpu->cd.transputer.oreg,
156     (uint32_t)cpu->pc);
157     debug(" <%s>\n", symbol != NULL? symbol : " no symbol ");
158    
159     debug("cpu%i: a = 0x%08"PRIx32" b = 0x%08"PRIx32" c = 0x%08"
160     PRIx32"\n", x, cpu->cd.transputer.a, cpu->cd.transputer.b,
161     cpu->cd.transputer.c);
162    
163     /* TODO: Error flags, Floating point registers, etc. */
164     }
165    
166    
167     /*
168     * transputer_cpu_register_match():
169     */
170     void transputer_cpu_register_match(struct machine *m, char *name,
171     int writeflag, uint64_t *valuep, int *match_register)
172     {
173     int cpunr = 0;
174    
175     /* CPU number: */
176     /* TODO */
177    
178     /* Register name: */
179     if (strcasecmp(name, "pc") == 0) {
180     if (writeflag) {
181     m->cpus[cpunr]->pc = *valuep;
182     } else
183     *valuep = m->cpus[cpunr]->pc;
184     *match_register = 1;
185     }
186    
187 dpavlin 30 if (strcasecmp(name, "a") == 0) {
188     if (writeflag) {
189     m->cpus[cpunr]->cd.transputer.a = *valuep;
190     } else
191     *valuep = m->cpus[cpunr]->cd.transputer.a;
192     *match_register = 1;
193     }
194    
195     if (strcasecmp(name, "b") == 0) {
196     if (writeflag) {
197     m->cpus[cpunr]->cd.transputer.b = *valuep;
198     } else
199     *valuep = m->cpus[cpunr]->cd.transputer.b;
200     *match_register = 1;
201     }
202    
203     if (strcasecmp(name, "c") == 0) {
204     if (writeflag) {
205     m->cpus[cpunr]->cd.transputer.c = *valuep;
206     } else
207     *valuep = m->cpus[cpunr]->cd.transputer.c;
208     *match_register = 1;
209     }
210    
211     if (strcasecmp(name, "wptr") == 0) {
212     if (writeflag) {
213     m->cpus[cpunr]->cd.transputer.wptr = *valuep;
214     } else
215     *valuep = m->cpus[cpunr]->cd.transputer.wptr;
216     *match_register = 1;
217     }
218    
219     if (strcasecmp(name, "oreg") == 0) {
220     if (writeflag) {
221     m->cpus[cpunr]->cd.transputer.oreg = *valuep;
222     } else
223     *valuep = m->cpus[cpunr]->cd.transputer.oreg;
224     *match_register = 1;
225     }
226    
227     /* TODO: Front and back pointers, etc. */
228 dpavlin 28 }
229    
230    
231     /*
232     * transputer_cpu_tlbdump():
233     *
234     * Called from the debugger to dump the TLB in a readable format.
235     * x is the cpu number to dump, or -1 to dump all CPUs.
236     *
237     * If rawflag is nonzero, then the TLB contents isn't formated nicely,
238     * just dumped.
239     */
240     void transputer_cpu_tlbdump(struct machine *m, int x, int rawflag)
241     {
242     }
243    
244    
245     /*
246     * transputer_cpu_gdb_stub():
247     *
248     * Execute a "remote GDB" command. Returns a newly allocated response string
249     * on success, NULL on failure.
250     */
251     char *transputer_cpu_gdb_stub(struct cpu *cpu, char *cmd)
252     {
253     fatal("transputer_cpu_gdb_stub(): TODO\n");
254     return NULL;
255     }
256    
257    
258     /*
259     * transputer_cpu_interrupt():
260     */
261     int transputer_cpu_interrupt(struct cpu *cpu, uint64_t irq_nr)
262     {
263     fatal("transputer_cpu_interrupt(): TODO\n");
264     return 0;
265     }
266    
267    
268     /*
269     * transputer_cpu_interrupt_ack():
270     */
271     int transputer_cpu_interrupt_ack(struct cpu *cpu, uint64_t irq_nr)
272     {
273     /* fatal("transputer_cpu_interrupt_ack(): TODO\n"); */
274     return 0;
275     }
276    
277    
278     /*
279     * transputer_cpu_disassemble_instr():
280     *
281     * Convert an instruction word into human readable format, for instruction
282     * tracing. On Transputers, an opcode is one byte, optionally followed by
283     * more instruction bytes.
284     *
285     * If running is 1, cpu->pc should be the address of the instruction.
286     *
287     * If running is 0, things that depend on the runtime environment (eg.
288     * register contents) will not be shown, and addr will be used instead of
289     * cpu->pc for relative addresses.
290     */
291     int transputer_cpu_disassemble_instr(struct cpu *cpu, unsigned char *ib,
292     int running, uint64_t dumpaddr)
293     {
294     uint64_t offset;
295     char *symbol;
296     int opcode, operand;
297    
298     if (running)
299     dumpaddr = cpu->pc;
300    
301     symbol = get_symbol_name(&cpu->machine->symbol_context,
302     dumpaddr, &offset);
303     if (symbol != NULL && offset==0)
304     debug("<%s>\n", symbol);
305    
306     if (cpu->machine->ncpus > 1 && running)
307     debug("cpu%i: ", cpu->cpu_id);
308    
309     debug("0x%08x: ", (int)dumpaddr);
310    
311     opcode = ib[0] >> 4;
312     operand = ib[0] & 15;
313 dpavlin 30 debug("%02x %-6s %2i", ib[0], opcode_names[opcode], operand);
314 dpavlin 28
315 dpavlin 30 /*
316     * For opcodes where it is nice to have additional runtime info,
317     * special cases need to be added here. (E.g. an instruction which
318     * updates registers can show the contents of the new registers
319     * after the update.)
320     */
321 dpavlin 28
322 dpavlin 30 switch (opcode) {
323 dpavlin 28
324 dpavlin 30 case T_OPC_PFIX:
325     if (running) {
326     uint32_t oreg = cpu->cd.transputer.oreg | operand;
327     debug("\toreg = 0x%"PRIx32, oreg << 4);
328     }
329     break;
330    
331     case T_OPC_LDC:
332     if (running) {
333     uint32_t new_c = cpu->cd.transputer.b;
334     uint32_t new_b = cpu->cd.transputer.a;
335     uint32_t new_a = cpu->cd.transputer.oreg | operand;
336     debug("\ta=0x%"PRIx32", b=0x%"PRIx32", c=0x%"PRIx32,
337     new_a, new_b, new_c);
338     }
339     break;
340    
341     case T_OPC_STL:
342     if (running) {
343     uint32_t addr = (cpu->cd.transputer.oreg | operand)
344     * sizeof(uint32_t) + cpu->cd.transputer.wptr;
345     debug("\t[0x%"PRIx32"] = 0x%x", addr,
346     cpu->cd.transputer.a);
347     }
348     break;
349    
350     case T_OPC_OPR:
351     if (running) {
352     uint32_t fopcode = cpu->cd.transputer.oreg | operand;
353     debug("\t");
354     if (fopcode < N_TRANSPUTER_OPC_F_NAMES)
355     debug("%s", opcode_f_names[fopcode]);
356     else
357     debug("0x%"PRIx32, fopcode);
358     }
359     break;
360    
361 dpavlin 28 }
362    
363 dpavlin 30 debug("\n");
364    
365 dpavlin 28 return 1;
366     }
367    
368    
369     #include "tmp_transputer_tail.c"
370    

  ViewVC Help
Powered by ViewVC 1.1.26