1 |
/* |
2 |
* Copyright (C) 2004-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_sgi_ip19.c,v 1.14 2005/10/26 14:37:04 debug Exp $ |
29 |
* |
30 |
* SGI IP19 (and IP25) stuff. The stuff in here is mostly guesswork. |
31 |
*/ |
32 |
|
33 |
#include <stdio.h> |
34 |
#include <stdlib.h> |
35 |
#include <string.h> |
36 |
|
37 |
#include "cpu.h" |
38 |
#include "device.h" |
39 |
#include "machine.h" |
40 |
#include "memory.h" |
41 |
#include "misc.h" |
42 |
|
43 |
|
44 |
#define DEV_SGI_IP19_LENGTH 0x100000 |
45 |
|
46 |
struct sgi_ip19_data { |
47 |
uint64_t cycle_counter; |
48 |
}; |
49 |
|
50 |
|
51 |
/* |
52 |
* dev_sgi_ip19_access(): |
53 |
*/ |
54 |
int dev_sgi_ip19_access(struct cpu *cpu, struct memory *mem, |
55 |
uint64_t relative_addr, unsigned char *data, size_t len, |
56 |
int writeflag, void *extra) |
57 |
{ |
58 |
struct sgi_ip19_data *d = (struct sgi_ip19_data *) extra; |
59 |
uint64_t idata = 0, odata = 0; |
60 |
int regnr; |
61 |
|
62 |
if (writeflag == MEM_WRITE) |
63 |
idata = memory_readmax64(cpu, data, len); |
64 |
|
65 |
regnr = relative_addr / sizeof(uint32_t); |
66 |
|
67 |
switch (relative_addr) { |
68 |
case 0x08: /* cpu id */ |
69 |
if (writeflag == MEM_WRITE) { |
70 |
debug("[ sgi_ip19: unimplemented write to address " |
71 |
"0x%x (cpu id), data=0x%08x ]\n", (int) |
72 |
relative_addr, (int)idata); |
73 |
} else { |
74 |
odata = cpu->cpu_id; /* ? TODO */ |
75 |
} |
76 |
break; |
77 |
case 0x200: /* cpu available mask? */ |
78 |
if (writeflag == MEM_WRITE) { |
79 |
debug("[ sgi_ip19: unimplemented write to address " |
80 |
"0x%x (cpu available mask), data=0x%08x ]\n", |
81 |
(int)relative_addr, (int)idata); |
82 |
} else { |
83 |
/* Max 16 cpus? */ |
84 |
odata = ((1 << cpu->machine->ncpus) - 1) << 16; |
85 |
} |
86 |
break; |
87 |
case 0x20000: /* cycle counter or clock */ |
88 |
if (writeflag == MEM_WRITE) { |
89 |
debug("[ sgi_ip19: unimplemented write to address " |
90 |
"0x%x (cycle counter), data=0x%08x ]\n", |
91 |
(int)relative_addr, (int)idata); |
92 |
} else { |
93 |
d->cycle_counter += 100; |
94 |
odata = d->cycle_counter; |
95 |
} |
96 |
|
97 |
break; |
98 |
default: |
99 |
if (writeflag == MEM_WRITE) { |
100 |
debug("[ sgi_ip19: unimplemented write to address " |
101 |
"0x%x, data=0x%08x ]\n", (int)relative_addr, |
102 |
(int)idata); |
103 |
} else { |
104 |
debug("[ sgi_ip19: unimplemented read from address " |
105 |
"0x%x: 0x%08x ]\n", (int)relative_addr, (int)odata); |
106 |
} |
107 |
} |
108 |
|
109 |
if (writeflag == MEM_READ) |
110 |
memory_writemax64(cpu, data, len, odata); |
111 |
|
112 |
return 1; |
113 |
} |
114 |
|
115 |
|
116 |
/* |
117 |
* devinit__sgi_ip19(): |
118 |
*/ |
119 |
int devinit_sgi_ip19(struct devinit *devinit) |
120 |
{ |
121 |
struct sgi_ip19_data *d = malloc(sizeof(struct sgi_ip19_data)); |
122 |
if (d == NULL) { |
123 |
fprintf(stderr, "out of memory\n"); |
124 |
exit(1); |
125 |
} |
126 |
memset(d, 0, sizeof(struct sgi_ip19_data)); |
127 |
|
128 |
memory_device_register(devinit->machine->memory, devinit->name, |
129 |
devinit->addr, DEV_SGI_IP19_LENGTH, |
130 |
dev_sgi_ip19_access, (void *)d, MEM_DEFAULT, NULL); |
131 |
|
132 |
return 1; |
133 |
} |
134 |
|