Commit | Line | Data |
---|---|---|
aea481da DE |
1 | /* Copyright (C) 1998, Cygnus Solutions |
2 | ||
3 | */ | |
4 | ||
5 | #include "sim-main.h" | |
486c714a | 6 | #include "sim-endian.h" |
aea481da | 7 | |
803f52b9 DE |
8 | #include "sky-device.h" |
9 | #include "sky-vu1.h" | |
10 | #include "sky-libvpe.h" | |
11 | #include "sky-vu.h" | |
9c577d9a IC |
12 | #include "sky-bits.h" |
13 | ||
14 | #include <assert.h> | |
aea481da DE |
15 | |
16 | VectorUnitState vu1_state; | |
17 | ||
04a7f72a IC |
18 | #define sim_warning printf |
19 | ||
121d6745 | 20 | /* these are aligned versions of zalloc() pointers - do not zfree()! */ |
f0bb94cd FCE |
21 | static char* vu1_umem_buffer = 0; |
22 | static char* vu1_mem_buffer = 0; | |
aea481da | 23 | |
52793fab | 24 | void init_vu1(void); |
121d6745 FCE |
25 | void init_vu(VectorUnitState *state, |
26 | char* umem_buffer, unsigned umem_dw_size, | |
27 | char* mem_buffer, unsigned mem_qw_size); | |
aea481da | 28 | |
9614fb3c | 29 | #if 0 |
733cfc78 IC |
30 | static void dump_mem() { |
31 | int i; | |
32 | typedef int T[2048][4]; | |
33 | T *mem = (T*)&vu1_mem_buffer; | |
34 | ||
35 | for (i = 0; i < 200; i++) { | |
36 | printf("%d: %x %x %x %x\n", i, (*mem)[i][0], (*mem)[i][1], (*mem)[i][2], (*mem)[i][3]); | |
37 | } | |
38 | } | |
9614fb3c | 39 | #endif |
733cfc78 | 40 | |
aea481da | 41 | void |
52793fab | 42 | vu1_issue(void) |
aea481da DE |
43 | { |
44 | if (vu1_state.runState == VU_RUN) | |
45 | vpecallms_cycle(&vu1_state); | |
46 | } | |
47 | ||
52793fab | 48 | static int |
aea481da | 49 | vu1_io_read_register_window(device *me, |
d44859a2 RU |
50 | void *dest, |
51 | int space, | |
52 | address_word addr, | |
53 | unsigned nr_bytes, | |
54 | sim_cpu *processor, | |
55 | sim_cia cia) | |
aea481da | 56 | { |
d44859a2 RU |
57 | if (addr < VU1_REGISTER_WINDOW_START) |
58 | return 0; | |
04a7f72a | 59 | |
d44859a2 | 60 | addr -= VU1_REGISTER_WINDOW_START; |
aea481da | 61 | |
d44859a2 RU |
62 | /* Adjust nr_bytes if too big */ |
63 | if ((addr + nr_bytes) > VU_REG_END) | |
64 | nr_bytes -= addr + nr_bytes - VU_REG_END; | |
aea481da | 65 | |
d44859a2 | 66 | return read_vu_registers (&vu1_state, addr, nr_bytes, dest); |
aea481da DE |
67 | } |
68 | ||
52793fab | 69 | static int |
aea481da | 70 | vu1_io_write_register_window(device *me, |
d44859a2 RU |
71 | const void *source, |
72 | int space, | |
73 | address_word addr, | |
74 | unsigned nr_bytes, | |
75 | sim_cpu *processor, | |
76 | sim_cia cia) | |
aea481da | 77 | { |
d44859a2 RU |
78 | if (addr < VU1_REGISTER_WINDOW_START) |
79 | return 0; | |
80 | ||
81 | addr -= VU1_REGISTER_WINDOW_START; | |
82 | ||
83 | /* Adjust nr_bytes if too big */ | |
84 | if ((addr + nr_bytes) > VU_REG_END) | |
85 | nr_bytes -= addr + nr_bytes - VU_REG_END; | |
86 | ||
87 | return write_vu_registers (&vu1_state, addr, nr_bytes, source); | |
aea481da DE |
88 | } |
89 | ||
90 | device vu1_device = | |
91 | { | |
92 | "vu1", | |
93 | &vu1_io_read_register_window, | |
94 | &vu1_io_write_register_window | |
95 | }; | |
96 | ||
97 | void | |
98 | vu1_init(SIM_DESC sd) | |
99 | { | |
100 | ||
101 | sim_core_attach (sd, | |
102 | NULL, | |
103 | 0 /*level*/, | |
104 | access_read_write, | |
105 | 0 /*space ???*/, | |
106 | VU1_REGISTER_WINDOW_START, | |
d44859a2 | 107 | VU_REG_END /*nr_bytes*/, |
aea481da DE |
108 | 0 /*modulo*/, |
109 | &vu1_device, | |
110 | NULL /*buffer*/); | |
111 | ||
f0bb94cd | 112 | vu1_umem_buffer = zalloc(VU1_MEM0_SIZE); |
121d6745 | 113 | vu1_umem_buffer = (void*) ALIGN_16((unsigned)vu1_umem_buffer); |
aea481da DE |
114 | sim_core_attach (sd, |
115 | NULL, | |
116 | 0 /*level*/, | |
117 | access_read_write, | |
118 | 0 /*space ???*/, | |
119 | VU1_MEM0_WINDOW_START, | |
120 | VU1_MEM0_SIZE /*nr_bytes*/, | |
121 | 0 /*modulo*/, | |
122 | 0 /*device*/, | |
f0bb94cd | 123 | vu1_umem_buffer /*buffer*/); |
aea481da | 124 | |
121d6745 FCE |
125 | vu1_mem_buffer = zalloc(VU1_MEM1_SIZE + 2*sizeof(unsigned_16)); |
126 | vu1_mem_buffer = (void*) ALIGN_16((unsigned)vu1_mem_buffer); | |
aea481da DE |
127 | sim_core_attach (sd, |
128 | NULL, | |
129 | 0 /*level*/, | |
130 | access_read_write, | |
131 | 0 /*space ???*/, | |
132 | VU1_MEM1_WINDOW_START, | |
133 | VU1_MEM1_SIZE /*nr_bytes*/, | |
134 | 0 /*modulo*/, | |
135 | 0 /*device*/, | |
f0bb94cd | 136 | vu1_mem_buffer /*buffer*/); |
aea481da DE |
137 | |
138 | init_vu1(); | |
139 | /*initvpe();*/ | |
140 | vpecallms_init(&vu1_state); | |
141 | } | |
142 | ||
143 | /****************************************************************************/ | |
144 | /* */ | |
145 | /* Sony Computer Entertainment CONFIDENTIAL */ | |
146 | /* (C) 1997 Sony Computer Entertainment Inc. All Rights Reserved */ | |
147 | /* */ | |
148 | /* VPE1 simulator */ | |
149 | /* */ | |
150 | /****************************************************************************/ | |
151 | ||
152 | #include <stdio.h> | |
153 | #include <sys/types.h> | |
154 | #include <strings.h> | |
72db5610 | 155 | #include "sky-libvpe.h" |
aea481da DE |
156 | |
157 | char ifilename[64] = "vu.bin"; | |
158 | char ofilename[64] = ""; | |
159 | char pfilename[64] = ""; | |
160 | ||
52793fab | 161 | static void abend2(char *fmt, char* p) { |
aea481da DE |
162 | fprintf(stderr, fmt, p); |
163 | exit(1); | |
164 | } | |
165 | ||
486c714a | 166 | void getoption(VectorUnitState* state); |
aea481da | 167 | |
52793fab | 168 | void init_vu1(void) { |
121d6745 FCE |
169 | init_vu(&vu1_state, |
170 | &vu1_umem_buffer[0], VU1_MEM0_SIZE/8, | |
171 | &vu1_mem_buffer[0], VU1_MEM1_SIZE/16); | |
aea481da DE |
172 | } |
173 | ||
121d6745 FCE |
174 | void init_vu(VectorUnitState *state, |
175 | char* umem_buffer, unsigned umem_dw_size, | |
176 | char* mem_buffer, unsigned mem_qw_size) | |
aea481da DE |
177 | { |
178 | FILE *fp; | |
179 | int i, j; | |
180 | u_long data[4]; | |
181 | ||
182 | /* set up memory buffers */ | |
121d6745 FCE |
183 | state->uMEM_buffer = (uMEM_Entry_Type *) umem_buffer; |
184 | state->uMEM_size = umem_dw_size; | |
185 | state->MEM_buffer = (MEM_Entry_Type*) mem_buffer; | |
186 | state->MEM_size = mem_qw_size; | |
187 | ||
aea481da DE |
188 | /* set up run state */ |
189 | state->runState = VU_READY; | |
190 | ||
191 | /* read option */ | |
486c714a | 192 | getoption(state); |
aea481da DE |
193 | |
194 | /* read instruction file (mandatory) */ | |
195 | if (*ifilename) { | |
dde66fa7 IC |
196 | if((fp = fopen(ifilename, "r")) != NULL) { |
197 | for (i = 0; fread(&data[0], 4, 1, fp) != 0; i++) { | |
198 | fread(&data[1], 4, 1, fp); | |
199 | LoadMMem(state, i, data, 1); | |
200 | } | |
201 | fclose(fp); | |
aea481da | 202 | } |
aea481da DE |
203 | } |
204 | ||
205 | /* PKE dirven simvpe */ | |
206 | if (*pfilename) { | |
207 | /* initpke(pfilename); */ | |
208 | initvpe(&vu1_state); | |
209 | /* while (simpke() != -1) | |
210 | simvpe(); */ | |
211 | } | |
212 | ||
213 | /* conventional simvpe */ | |
214 | else { | |
215 | initvpe(&vu1_state); | |
216 | /*simvpe();*/ | |
217 | } | |
218 | ||
219 | /* write result memory image (optional) */ | |
220 | if (*ofilename) { | |
221 | if((fp = fopen(ofilename, "w")) == NULL) | |
222 | abend2("%s: can not open\n", ofilename); | |
223 | ||
224 | for(i = 0; i < 2048; i++){ | |
52793fab | 225 | StoreVUMem(state, i, data, 1); |
aea481da DE |
226 | for(j = 0; j < 4; j++) |
227 | fwrite(&data[j], 4, 1, fp); | |
228 | } | |
229 | fclose(fp); | |
230 | } | |
231 | } | |
232 | ||
52793fab | 233 | #if 0 |
aea481da DE |
234 | static void Usage(void) |
235 | { | |
236 | fprintf(stderr, "Usage: simvpe [options]\n"); | |
237 | fprintf(stderr, "\t\t-i instruction-file\n"); | |
238 | fprintf(stderr, "\t\t-o output-memory-file\n"); | |
239 | fprintf(stderr, "\t\t-t PKE-file (text type)\n"); | |
240 | fprintf(stderr, "\t\t-s start-address [default = 0]\n"); | |
241 | fprintf(stderr, "\t\t-d [interactive mode enable: default desable]\n"); | |
242 | fprintf(stderr, "\t\t-v [statistics mode enable: default desable]\n"); | |
243 | fprintf(stderr, "\t\t-p [debug print mode enable: default desable]\n"); | |
244 | } | |
52793fab | 245 | #endif |
aea481da | 246 | |
486c714a | 247 | void getoption(VectorUnitState* state) |
aea481da | 248 | { |
52793fab | 249 | #if 0 |
aea481da DE |
250 | int startline = 0; |
251 | int count = 1; | |
52793fab | 252 | #endif |
aea481da | 253 | |
486c714a IC |
254 | state->junk._is_dbg = 1; |
255 | state->junk._vpepc = 0; | |
256 | state->junk._is_verb = 0; | |
257 | state->junk._is_dump = 0; | |
374ed20d | 258 | state->junk._pgpuif = 4; /* MEMGPUIF */ |
486c714a IC |
259 | state->junk._ITOP = 20; |
260 | state->junk._TOP = 10; | |
aea481da DE |
261 | |
262 | #if 0 | |
263 | while(argc - count){ | |
264 | if(argv[count][0] == '-'){ | |
265 | switch(argv[count][1]){ | |
266 | case 'i': | |
267 | strcpy(ifilename, argv[count+1]); | |
268 | count += 2; | |
269 | break; | |
270 | case 'o': | |
271 | strcpy(ofilename, argv[count+1]); | |
272 | count += 2; | |
273 | break; | |
274 | case 't': | |
275 | strcpy(pfilename, argv[count+1]); | |
276 | count += 2; | |
277 | break; | |
278 | case 's': | |
279 | sscanf(argv[count+1], "%d", &startline); | |
486c714a | 280 | state->junk._vpepc = startline; |
aea481da DE |
281 | count += 2; |
282 | break; | |
283 | case 'd': | |
486c714a | 284 | state->junk._is_dbg = 1; |
aea481da DE |
285 | count += 1; |
286 | break; | |
287 | case 'v': | |
486c714a | 288 | state->junk._is_verb = 1; |
aea481da DE |
289 | count += 1; |
290 | break; | |
291 | case 'p': | |
486c714a | 292 | state->junk._is_dump = 1; |
aea481da DE |
293 | count += 1; |
294 | break; | |
295 | case 'h': | |
296 | case '?': | |
297 | Usage(); | |
298 | exit(1); | |
299 | break; | |
300 | default: | |
301 | Usage(); | |
302 | exit(1); | |
303 | } | |
304 | }else{ | |
305 | Usage(); | |
306 | exit(1); | |
307 | } | |
308 | } | |
309 | #endif | |
310 | } |