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>
37 #include "remote-sim.h"
38 #include "../../newlib/libc/sys/w65/sys/syscall.h"
42 saved_state_type saved_state
;
47 return time ((long *) 0);
50 control_c (sig
, code
, scp
, addr
)
56 saved_state
.exception
= SIGINT
;
61 saved_state
.exception
= SIGTRAP
;
72 /* The x points to where the registers live, acc has code */
74 #define R(arg) (x + arg * 2)
81 unsigned char *memory
= saved_state
.memory
;
82 int a1
= fetch16 (R (4));
87 int file
= fetch16 (R5
);
88 unsigned char *buf
= fetch24 (R6
) + memory
;
89 int len
= fetch16 (R8
);
90 int res
= write (file
, buf
, len
);
99 saved_state
.exception
= SIGTRAP
;
102 saved_state
.exception
= SIGILL
;
109 sim_resume (step
, insignal
)
114 register unsigned char *memory
;
117 saved_state
.exception
= SIGTRAP
;
121 saved_state
.exception
= 0;
125 prev
= signal (SIGINT
, control_c
);
128 int x
= (saved_state
.p
>> 4) & 1;
129 int m
= (saved_state
.p
>> 5) & 1;
130 if (x
== 0 && m
== 0)
134 else if (x
== 0 && m
== 1)
138 else if (x
== 1 && m
== 0)
142 else if (x
== 1 && m
== 1)
147 while (saved_state
.exception
== 0);
149 signal (SIGINT
, prev
);
157 if (!saved_state
.memory
)
159 saved_state
.memory
= calloc (64 * 1024, NUMSEGS
);
164 sim_write (addr
, buffer
, size
)
166 unsigned char *buffer
;
172 for (i
= 0; i
< size
; i
++)
174 saved_state
.memory
[(addr
+ i
) & MMASK
] = buffer
[i
];
180 sim_read (addr
, buffer
, size
)
182 unsigned char *buffer
;
189 for (i
= 0; i
< size
; i
++)
191 buffer
[i
] = saved_state
.memory
[(addr
+ i
) & MMASK
];
206 &saved_state
.r
[0], 2,
207 &saved_state
.r
[1], 2,
208 &saved_state
.r
[2], 2,
209 &saved_state
.r
[3], 2,
210 &saved_state
.r
[4], 2,
211 &saved_state
.r
[5], 2,
212 &saved_state
.r
[6], 2,
213 &saved_state
.r
[7], 2,
214 &saved_state
.r
[8], 2,
215 &saved_state
.r
[9], 2,
216 &saved_state
.r
[10], 2,
217 &saved_state
.r
[11], 2,
218 &saved_state
.r
[12], 2,
219 &saved_state
.r
[13], 2,
220 &saved_state
.r
[14], 2,
221 &saved_state
.r
[15], 4,
230 &saved_state
.ticks
, 4,
231 &saved_state
.cycles
, 4,
232 &saved_state
.insts
, 4,
237 sim_store_register (rn
, value
)
239 unsigned char *value
;
244 for (i
= 0; i
< rinfo
[rn
].size
; i
++)
246 val
|= (*value
++) << (i
* 8);
249 *(rinfo
[rn
].ptr
) = val
;
253 sim_fetch_register (rn
, buf
)
257 unsigned int val
= *(rinfo
[rn
].ptr
);
260 for (i
= 0; i
< rinfo
[rn
].size
; i
++)
270 return rinfo
[n
].size
;
279 sim_stop_reason (reason
, sigrc
)
280 enum sim_stop
*reason
;
283 *reason
= sim_stopped
;
284 *sigrc
= saved_state
.exception
;
300 double timetaken
= (double) saved_state
.ticks
;
301 double virttime
= saved_state
.cycles
/ 2.0e6
;
303 printf ("\n\n# instructions executed %10d\n", saved_state
.insts
);
304 printf ("# cycles %10d\n", saved_state
.cycles
);
305 printf ("# real time taken %10.4f\n", timetaken
);
306 printf ("# virtual time taken %10.4f\n", virttime
);
310 printf ("# cycles/second %10d\n", (int) (saved_state
.cycles
/ timetaken
));
311 printf ("# simulation ratio %10.4f\n", virttime
/ timetaken
);
319 sim_open (kind
, cb
, abfd
, argv
)
334 saved_state
.exception
= SIGBUS
;
337 return saved_state
.memory
[x
];
342 return fetch8func(x
);
353 sim_load (prog
, from_tty
)
357 /* Return nonzero so gdb will handle it. */
363 sim_create_inferior (abfd
, argv
, env
)
368 SIM_ADDR start_address
;
371 start_address
= bfd_get_start_address (abfd
);
373 start_address
= 0; /*??*/
374 /* ??? We assume this is a 4 byte quantity. */
376 sim_store_register (16, (unsigned char *) &pc
);
380 sim_set_callbacks (ptr
)
381 struct host_callback_struct
*ptr
;