/[gxemul]/trunk/src/devices/dev_gt.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

Contents of /trunk/src/devices/dev_gt.c

Parent Directory Parent Directory | Revision Log Revision Log


Revision 10 - (show annotations)
Mon Oct 8 16:18:27 2007 UTC (16 years, 5 months ago) by dpavlin
File MIME type: text/plain
File size: 5727 byte(s)
++ trunk/HISTORY	(local)
$Id: HISTORY,v 1.815 2005/06/27 23:04:35 debug Exp $
20050617	Experimenting some more with netbooting OpenBSD/sgi. Adding
		a hack which allows emulated ethernet networks to be
		distributed across multiple emulator processes.
20050618	Minor updates (documentation, dummy YAMON emulation, etc).
20050620	strcpy/strcat -> strlcpy/strlcat updates.
		Some more progress on evbmips (Malta).
20050621	Adding a section to doc/configfiles.html about ethernet
		emulation across multiple hosts.
		Beginning the work on the ARM translation engine (using the
		dynamic-but-not-binary translation method).
		Fixing a bintrans bug: 0x9fc00000 should always be treated as
		PROM area, just as 0xbfc00000 is.
		Minor progress on Malta emulation (the PCI-ISA bus).
20050622	NetBSD/evbmips can now be installed (using another emulated
		machine) and run (including userland and so on). :-)
		Spliting up the bintrans haddr_entry field into two (one for
		read, one for write). Probably not much of a speed increase,
		though.
		Updating some NetBSD 2.0 -> 2.0.2 in the documentation.
20050623	Minor updates (documentation, the TODO file, etc).
		gzipped kernels are now always automagically gunzipped when
		loaded.
20050624	Adding a dummy Playstation Portable (PSP) mode, just barely
		enough to run Hello World (in weird colors :-).
		Removing the -b command line option; old bintrans is enabled
		by default instead. It makes more sense.
		Trying to finally fix the non-working performance measurement
		thing (instr/second etc).
20050625	Continuing on the essential basics for ARM emulation. Two
		instructions seem to work, a branch and a simple "mov". (The
		mov arguments are not correct yet.) Performance is definitely
		reasonable.
		Various other minor updates.
		Adding the ARM "bl" instruction.
		Adding support for combining multiple ARM instructions into one
		function call. ("mov" + "mov" is the only one implemented so
		far, but it seems to work.)
		Cleaning up some IP32 interrupt things (crime/mace); disabling
		the PS/2 keyboard controller on IP32, so that NetBSD/sgimips
		boots into userland again.
20050626	Finally! NetBSD/sgimips netboots. Adding instructions to
		doc/guestoses.html on how to set up an nfs server etc.
		Various other minor fixes.
		Playstation Portable ".pbp" files can now be used directly.
		(The ELF part of the .pbp is extracted transparently.)
		Converting some sprintf -> snprintf.
		Adding some more instructions to the ARM disassembler.
20050627	More ARM updates. Adding some simple ldr(b), str(b),
		cmps, and conditional branch instructions, enough to run
		a simple Hello World program.
		All ARM instructions are now inlined/generated for all possible
		condition codes.
		Adding add and sub, and more load/store instructions.
		Removing dummy files: cpu_alpha.c, cpu_hppa.c, and cpu_sparc.c.
		Some minor documentation updates; preparing for a 0.3.4
		release. Updating some URLs.

==============  RELEASE 0.3.4  ==============


1 /*
2 * Copyright (C) 2003-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: dev_gt.c,v 1.22 2005/06/20 08:19:58 debug Exp $
29 *
30 * Galileo Technology GT-64xxx PCI controller.
31 *
32 * GT-64011 Used in Cobalt machines.
33 * GT-64120 Used in evbmips machines (Malta).
34 *
35 * TODO: This more or less just a dummy device, so far.
36 */
37
38 #include <stdio.h>
39 #include <stdlib.h>
40 #include <string.h>
41
42 #include "bus_pci.h"
43 #include "cpu.h"
44 #include "devices.h"
45 #include "machine.h"
46 #include "memory.h"
47 #include "misc.h"
48
49
50 #define TICK_STEPS_SHIFT 16
51
52 #define PCI_VENDOR_GALILEO 0x11ab /* Galileo Technology */
53 #define PCI_PRODUCT_GALILEO_GT64011 0x4146 /* GT-64011 System Controller */
54 #define PCI_PRODUCT_GALILEO_GT64120 0x4620 /* GT-64120 */
55
56 struct gt_data {
57 int reg[8];
58 int irqnr;
59 int pciirq;
60 int type;
61
62 struct pci_data *pci_data;
63 };
64
65
66 /*
67 * dev_gt_tick():
68 */
69 void dev_gt_tick(struct cpu *cpu, void *extra)
70 {
71 struct gt_data *gt_data = extra;
72
73 cpu_interrupt(cpu, gt_data->irqnr);
74 }
75
76
77 /*
78 * dev_gt_access():
79 */
80 int dev_gt_access(struct cpu *cpu, struct memory *mem, uint64_t relative_addr,
81 unsigned char *data, size_t len, int writeflag, void *extra)
82 {
83 uint64_t idata = 0, odata = 0;
84 int i;
85 struct gt_data *d = extra;
86
87 idata = memory_readmax64(cpu, data, len);
88
89 switch (relative_addr) {
90 case 0xc18:
91 if (writeflag == MEM_WRITE) {
92 debug("[ gt write to 0xc18: data = 0x%08lx ]\n",
93 (long)idata);
94 return 1;
95 } else {
96 odata = 0xffffffffULL;
97 /* ??? interrupt something... */
98
99 odata = 0x00000100; /* netbsd/cobalt cobalt/machdep.c:cpu_intr() */
100
101 cpu_interrupt_ack(cpu, d->irqnr);
102
103 debug("[ gt read from 0xc18 (data = 0x%08lx) ]\n",
104 (long)odata);
105 }
106 break;
107 case 0xcf8: /* PCI ADDR */
108 case 0xcfc: /* PCI DATA */
109 if (writeflag == MEM_WRITE) {
110 bus_pci_access(cpu, mem, relative_addr, &idata,
111 writeflag, d->pci_data);
112 } else {
113 bus_pci_access(cpu, mem, relative_addr, &odata,
114 writeflag, d->pci_data);
115 }
116 break;
117 default:
118 if (writeflag==MEM_READ) {
119 debug("[ gt read from addr 0x%x ]\n",
120 (int)relative_addr);
121 odata = d->reg[relative_addr];
122 } else {
123 debug("[ gt write to addr 0x%x:", (int)relative_addr);
124 for (i=0; i<len; i++)
125 debug(" %02x", data[i]);
126 debug(" ]\n");
127 d->reg[relative_addr] = idata;
128 }
129 }
130
131 if (writeflag == MEM_READ)
132 memory_writemax64(cpu, data, len, odata);
133
134 return 1;
135 }
136
137
138 /*
139 * pci_gt_rr_011():
140 */
141 static uint32_t pci_gt_rr_011(int reg)
142 {
143 switch (reg) {
144 case 0x00:
145 return PCI_VENDOR_GALILEO + (PCI_PRODUCT_GALILEO_GT64011 << 16);
146 case 0x08:
147 return 0x06000001; /* Revision 1 */
148 default:
149 return 0;
150 }
151 }
152
153
154 /*
155 * pci_gt_rr_120():
156 */
157 static uint32_t pci_gt_rr_120(int reg)
158 {
159 switch (reg) {
160 case 0x00:
161 return PCI_VENDOR_GALILEO + (PCI_PRODUCT_GALILEO_GT64120 << 16);
162 case 0x08:
163 return 0x06000002; /* Revision 2? */
164 default:
165 return 0;
166 }
167 }
168
169
170 /*
171 * pci_gt_init():
172 */
173 void pci_gt_init(struct machine *machine, struct memory *mem)
174 {
175 }
176
177
178 /*
179 * dev_gt_init():
180 *
181 * Initialize a GT device. Return a pointer to the pci_data used, so that
182 * the caller may add PCI devices. First, however, we add the GT device
183 * itself.
184 */
185 struct pci_data *dev_gt_init(struct machine *machine, struct memory *mem,
186 uint64_t baseaddr, int irq_nr, int pciirq, int type)
187 {
188 struct gt_data *d;
189
190 d = malloc(sizeof(struct gt_data));
191 if (d == NULL) {
192 fprintf(stderr, "out of memory\n");
193 exit(1);
194 }
195 memset(d, 0, sizeof(struct gt_data));
196 d->irqnr = irq_nr;
197 d->pciirq = pciirq;
198 d->pci_data = bus_pci_init(pciirq);
199
200 switch (type) {
201 case 11:
202 d->type = PCI_PRODUCT_GALILEO_GT64011;
203 break;
204 case 120:
205 d->type = PCI_PRODUCT_GALILEO_GT64120;
206 break;
207 default:fatal("dev_gt_init(): type must be 11 or 120.\n");
208 exit(1);
209 }
210
211 /*
212 * According to NetBSD/cobalt:
213 * pchb0 at pci0 dev 0 function 0: Galileo GT-64011
214 * System Controller, rev 1
215 */
216 bus_pci_add(machine, d->pci_data, mem, 0, 0, 0, pci_gt_init,
217 d->type == PCI_PRODUCT_GALILEO_GT64011?
218 pci_gt_rr_011 : pci_gt_rr_120);
219
220 memory_device_register(mem, "gt", baseaddr, DEV_GT_LENGTH,
221 dev_gt_access, d, MEM_DEFAULT, NULL);
222 machine_add_tickfunction(machine, dev_gt_tick, d, TICK_STEPS_SHIFT);
223
224 return d->pci_data;
225 }
226

  ViewVC Help
Powered by ViewVC 1.1.26