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
, length
)
239 unsigned char *value
;
245 for (i
= 0; i
< rinfo
[rn
].size
; i
++)
247 val
|= (*value
++) << (i
* 8);
250 *(rinfo
[rn
].ptr
) = val
;
255 sim_fetch_register (rn
, buf
, length
)
260 unsigned int val
= *(rinfo
[rn
].ptr
);
263 for (i
= 0; i
< rinfo
[rn
].size
; i
++)
274 return rinfo
[n
].size
;
283 sim_stop_reason (reason
, sigrc
)
284 enum sim_stop
*reason
;
287 *reason
= sim_stopped
;
288 *sigrc
= saved_state
.exception
;
304 double timetaken
= (double) saved_state
.ticks
;
305 double virttime
= saved_state
.cycles
/ 2.0e6
;
307 printf ("\n\n# instructions executed %10d\n", saved_state
.insts
);
308 printf ("# cycles %10d\n", saved_state
.cycles
);
309 printf ("# real time taken %10.4f\n", timetaken
);
310 printf ("# virtual time taken %10.4f\n", virttime
);
314 printf ("# cycles/second %10d\n", (int) (saved_state
.cycles
/ timetaken
));
315 printf ("# simulation ratio %10.4f\n", virttime
/ timetaken
);
323 sim_open (kind
, cb
, abfd
, argv
)
338 saved_state
.exception
= SIGBUS
;
341 return saved_state
.memory
[x
];
346 return fetch8func(x
);
357 sim_load (prog
, from_tty
)
361 /* Return nonzero so gdb will handle it. */
367 sim_create_inferior (abfd
, argv
, env
)
372 SIM_ADDR start_address
;
375 start_address
= bfd_get_start_address (abfd
);
377 start_address
= 0; /*??*/
378 /* ??? We assume this is a 4 byte quantity. */
380 sim_store_register (16, (unsigned char *) &pc
);
384 sim_set_callbacks (ptr
)
385 struct host_callback_struct
*ptr
;