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.
34 #include <sys/param.h>
36 #include "remote-sim.h"
37 #include "../../newlib/libc/sys/w65/sys/syscall.h"
41 saved_state_type saved_state;
46 return time ((long *) 0);
49 control_c (sig, code, scp, addr)
55 saved_state.exception = SIGINT;
60 saved_state.exception = SIGTRAP;
71 /* The x points to where the registers live, acc has code */
73 #define R(arg) (x + arg * 2)
80 unsigned char *memory = saved_state.memory;
81 int a1 = fetch16 (R (4));
86 int file = fetch16 (R5);
87 unsigned char *buf = fetch24 (R6) + memory;
88 int len = fetch16 (R8);
89 int res = write (file, buf, len);
98 saved_state.exception = SIGTRAP;
101 saved_state.exception = SIGILL;
108 sim_resume (step, insignal)
113 register unsigned char *memory;
116 saved_state.exception = SIGTRAP;
120 saved_state.exception = 0;
124 prev = signal (SIGINT, control_c);
127 int x = (saved_state.p >> 4) & 1;
128 int m = (saved_state.p >> 5) & 1;
129 if (x == 0 && m == 0)
133 else if (x == 0 && m == 1)
137 else if (x == 1 && m == 0)
141 else if (x == 1 && m == 1)
146 while (saved_state.exception == 0);
148 signal (SIGINT, prev);
156 if (!saved_state.memory)
158 saved_state.memory = calloc (64 * 1024, NUMSEGS);
163 sim_write (addr, buffer, size)
165 unsigned char *buffer;
171 for (i = 0; i < size; i++)
173 saved_state.memory[(addr + i) & MMASK] = buffer[i];
179 sim_read (addr, buffer, size)
181 unsigned char *buffer;
188 for (i = 0; i < size; i++)
190 buffer[i] = saved_state.memory[(addr + i) & MMASK];
205 &saved_state.r[0], 2,
206 &saved_state.r[1], 2,
207 &saved_state.r[2], 2,
208 &saved_state.r[3], 2,
209 &saved_state.r[4], 2,
210 &saved_state.r[5], 2,
211 &saved_state.r[6], 2,
212 &saved_state.r[7], 2,
213 &saved_state.r[8], 2,
214 &saved_state.r[9], 2,
215 &saved_state.r[10], 2,
216 &saved_state.r[11], 2,
217 &saved_state.r[12], 2,
218 &saved_state.r[13], 2,
219 &saved_state.r[14], 2,
220 &saved_state.r[15], 4,
229 &saved_state.ticks, 4,
230 &saved_state.cycles, 4,
231 &saved_state.insts, 4,
236 sim_store_register (rn, value)
238 unsigned char *value;
243 for (i = 0; i < rinfo[rn].size; i++)
245 val |= (*value++) << (i * 8);
248 *(rinfo[rn].ptr) = val;
252 sim_fetch_register (rn, buf)
256 unsigned int val = *(rinfo[rn].ptr);
259 for (i = 0; i < rinfo[rn].size; i++)
269 return rinfo[n].size;
278 sim_stop_reason (reason, sigrc)
279 enum sim_stop *reason;
282 *reason = sim_stopped;
283 *sigrc = saved_state.exception;
299 double timetaken = (double) saved_state.ticks;
300 double virttime = saved_state.cycles / 2.0e6;
302 printf ("\n\n# instructions executed %10d\n", saved_state.insts);
303 printf ("# cycles %10d\n", saved_state.cycles);
304 printf ("# real time taken %10.4f\n", timetaken);
305 printf ("# virtual time taken %10.4f\n", virttime);
309 printf ("# cycles/second %10d\n", (int) (saved_state.cycles / timetaken));
310 printf ("# simulation ratio %10.4f\n", virttime / timetaken);
336 saved_state.exception = SIGBUS;
339 return saved_state.memory[x];
344 return fetch8func(x);
355 sim_load (prog, from_tty)
359 /* Return nonzero so gdb will handle it. */
365 sim_create_inferior (start_address, argv, env)
366 SIM_ADDR start_address;
370 /* ??? We assume this is a 4 byte quantity. */
374 sim_store_register (16, (unsigned char *) &pc);