1 /* Simulator for the WDC 65816 architecture.
3 Written by Steve Chamberlain of Cygnus Support.
6 This file is part of W65 sim
9 THIS SOFTWARE IS NOT COPYRIGHTED
11 Cygnus offers the following for use in the public domain. Cygnus
12 makes no warranty with regard to the software or it's performance
13 and the user accepts the software "AS IS" with all faults.
15 CYGNUS DISCLAIMS ANY WARRANTIES, EXPRESS OR IMPLIED, WITH REGARD TO
16 THIS SOFTWARE INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
17 MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
23 #include <sys/times.h>
24 #include <sys/param.h>
26 #include "remote-sim.h"
27 #include "../../newlib/libc/sys/w65/sys/syscall.h"
31 saved_state_type saved_state;
36 return time ((long *) 0);
39 control_c (sig, code, scp, addr)
45 saved_state.exception = SIGINT;
50 saved_state.exception = SIGTRAP;
61 /* The x points to where the registers live, acc has code */
63 #define R(arg) (x + arg * 2)
70 unsigned char *memory = saved_state.memory;
71 int a1 = fetch16 (R (4));
76 int file = fetch16 (R5);
77 unsigned char *buf = fetch24 (R6) + memory;
78 int len = fetch16 (R8);
79 int res = write (file, buf, len);
88 saved_state.exception = SIGTRAP;
91 saved_state.exception = SIGILL;
98 sim_resume (step, insignal)
103 register unsigned char *memory;
106 saved_state.exception = SIGTRAP;
110 saved_state.exception = 0;
114 prev = signal (SIGINT, control_c);
117 int x = (saved_state.p >> 4) & 1;
118 int m = (saved_state.p >> 5) & 1;
119 if (x == 0 && m == 0)
123 else if (x == 0 && m == 1)
127 else if (x == 1 && m == 0)
131 else if (x == 1 && m == 1)
136 while (saved_state.exception == 0);
138 signal (SIGINT, prev);
146 if (!saved_state.memory)
148 saved_state.memory = calloc (64 * 1024, NUMSEGS);
153 sim_write (addr, buffer, size)
155 unsigned char *buffer;
161 for (i = 0; i < size; i++)
163 saved_state.memory[(addr + i) & MMASK] = buffer[i];
169 sim_read (addr, buffer, size)
171 unsigned char *buffer;
178 for (i = 0; i < size; i++)
180 buffer[i] = saved_state.memory[(addr + i) & MMASK];
195 &saved_state.r[0], 2,
196 &saved_state.r[1], 2,
197 &saved_state.r[2], 2,
198 &saved_state.r[3], 2,
199 &saved_state.r[4], 2,
200 &saved_state.r[5], 2,
201 &saved_state.r[6], 2,
202 &saved_state.r[7], 2,
203 &saved_state.r[8], 2,
204 &saved_state.r[9], 2,
205 &saved_state.r[10], 2,
206 &saved_state.r[11], 2,
207 &saved_state.r[12], 2,
208 &saved_state.r[13], 2,
209 &saved_state.r[14], 2,
210 &saved_state.r[15], 4,
219 &saved_state.ticks, 4,
220 &saved_state.cycles, 4,
221 &saved_state.insts, 4,
226 sim_store_register (rn, value)
228 unsigned char *value;
233 for (i = 0; i < rinfo[rn].size; i++)
235 val |= (*value++) << (i * 8);
238 *(rinfo[rn].ptr) = val;
242 sim_fetch_register (rn, buf)
246 unsigned int val = *(rinfo[rn].ptr);
249 for (i = 0; i < rinfo[rn].size; i++)
259 return rinfo[n].size;
268 sim_stop_reason (reason, sigrc)
269 enum sim_stop *reason;
272 *reason = sim_stopped;
273 *sigrc = saved_state.exception;
289 double timetaken = (double) saved_state.ticks;
290 double virttime = saved_state.cycles / 2.0e6;
292 printf ("\n\n# instructions executed %10d\n", saved_state.insts);
293 printf ("# cycles %10d\n", saved_state.cycles);
294 printf ("# real time taken %10.4f\n", timetaken);
295 printf ("# virtual time taken %10.4f\n", virttime);
299 printf ("# cycles/second %10d\n", (int) (saved_state.cycles / timetaken));
300 printf ("# simulation ratio %10.4f\n", virttime / timetaken);
326 saved_state.exception = SIGBUS;
329 return saved_state.memory[x];
334 return fetch8func(x);
345 sim_load (prog, from_tty)
349 /* Return nonzero so gdb will handle it. */
355 sim_create_inferior (start_address, argv, env)
356 SIM_ADDR start_address;
360 /* ??? We assume this is a 4 byte quantity. */
364 sim_store_register (16, (unsigned char *) &pc);