1 /* Simulator for the Hitachi SH architecture.
3 Written by Steve Chamberlain of Cygnus Support.
6 This file is part of SH 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.
30 #include "gdb/callback.h"
31 #include "gdb/remote-sim.h"
32 #include "gdb/sim-sh.h"
34 /* This file is local - if newlib changes, then so should this. */
40 #include <float.h> /* Needed for _isnan() */
45 #define SIGBUS SIGSEGV
49 #define SIGQUIT SIGTERM
56 extern unsigned char sh_jump_table
[], sh_dsp_table
[0x1000], ppi_table
[];
58 int sim_write (SIM_DESC sd
, SIM_ADDR addr
, unsigned char *buffer
, int size
);
60 #define O_RECOMPILE 85
62 #define DISASSEMBLER_TABLE
64 /* Define the rate at which the simulator should poll the host
66 #define POLL_QUIT_INTERVAL 0x60000
76 /* System registers. For sh-dsp this also includes A0 / X0 / X1 / Y0 / Y1
77 which are located in fregs, i.e. strictly speaking, these are
78 out-of-bounds accesses of sregs.i . This wart of the code could be
79 fixed by making fregs part of sregs, and including pc too - to avoid
80 alignment repercussions - but this would cause very onerous union /
81 structure nesting, which would only be managable with anonymous
82 unions and structs. */
91 int fpul
; /* A1 for sh-dsp - but only for movs etc. */
92 int fpscr
; /* dsr for sh-dsp */
106 /* Control registers; on the SH4, ldc / stc is privileged, except when
127 unsigned char *insn_end
;
139 int end_of_registers
;
142 #define PROFILE_FREQ 1
143 #define PROFILE_SHIFT 2
145 unsigned short *profile_hist
;
146 unsigned char *memory
;
147 int xyram_select
, xram_start
, yram_start
;
150 unsigned char *xmem_offset
;
151 unsigned char *ymem_offset
;
157 saved_state_type saved_state
;
159 struct loop_bounds
{ unsigned char *start
, *end
; };
161 /* These variables are at file scope so that functions other than
162 sim_resume can use the fetch/store macros */
164 static int target_little_endian
;
165 static int global_endianw
, endianb
;
166 static int target_dsp
;
167 static int host_little_endian
;
168 static char **prog_argv
;
171 static int maskw
= 0;
174 static SIM_OPEN_KIND sim_kind
;
178 /* Short hand definitions of the registers */
180 #define SBIT(x) ((x)&sbit)
181 #define R0 saved_state.asregs.regs[0]
182 #define Rn saved_state.asregs.regs[n]
183 #define Rm saved_state.asregs.regs[m]
184 #define UR0 (unsigned int)(saved_state.asregs.regs[0])
185 #define UR (unsigned int)R
186 #define UR (unsigned int)R
187 #define SR0 saved_state.asregs.regs[0]
188 #define CREG(n) (saved_state.asregs.cregs.i[(n)])
189 #define GBR saved_state.asregs.cregs.named.gbr
190 #define VBR saved_state.asregs.cregs.named.vbr
191 #define SSR saved_state.asregs.cregs.named.ssr
192 #define SPC saved_state.asregs.cregs.named.spc
193 #define SREG(n) (saved_state.asregs.sregs.i[(n)])
194 #define MACH saved_state.asregs.sregs.named.mach
195 #define MACL saved_state.asregs.sregs.named.macl
196 #define PR saved_state.asregs.sregs.named.pr
197 #define FPUL saved_state.asregs.sregs.named.fpul
203 /* Alternate bank of registers r0-r7 */
205 /* Note: code controling SR handles flips between BANK0 and BANK1 */
206 #define Rn_BANK(n) (saved_state.asregs.cregs.named.bank[(n)])
207 #define SET_Rn_BANK(n, EXP) do { saved_state.asregs.cregs.named.bank[(n)] = (EXP); } while (0)
212 #define SR_MASK_DMY (1 << 11)
213 #define SR_MASK_DMX (1 << 10)
214 #define SR_MASK_M (1 << 9)
215 #define SR_MASK_Q (1 << 8)
216 #define SR_MASK_I (0xf << 4)
217 #define SR_MASK_S (1 << 1)
218 #define SR_MASK_T (1 << 0)
220 #define SR_MASK_BL (1 << 28)
221 #define SR_MASK_RB (1 << 29)
222 #define SR_MASK_MD (1 << 30)
223 #define SR_MASK_RC 0x0fff0000
224 #define SR_RC_INCREMENT -0x00010000
226 #define M ((saved_state.asregs.cregs.named.sr & SR_MASK_M) != 0)
227 #define Q ((saved_state.asregs.cregs.named.sr & SR_MASK_Q) != 0)
228 #define S ((saved_state.asregs.cregs.named.sr & SR_MASK_S) != 0)
229 #define T ((saved_state.asregs.cregs.named.sr & SR_MASK_T) != 0)
231 #define SR_BL ((saved_state.asregs.cregs.named.sr & SR_MASK_BL) != 0)
232 #define SR_RB ((saved_state.asregs.cregs.named.sr & SR_MASK_RB) != 0)
233 #define SR_MD ((saved_state.asregs.cregs.named.sr & SR_MASK_MD) != 0)
234 #define SR_DMY ((saved_state.asregs.cregs.named.sr & SR_MASK_DMY) != 0)
235 #define SR_DMX ((saved_state.asregs.cregs.named.sr & SR_MASK_DMX) != 0)
236 #define SR_RC ((saved_state.asregs.cregs.named.sr & SR_MASK_RC))
238 /* Note: don't use this for privileged bits */
239 #define SET_SR_BIT(EXP, BIT) \
242 saved_state.asregs.cregs.named.sr |= (BIT); \
244 saved_state.asregs.cregs.named.sr &= ~(BIT); \
247 #define SET_SR_M(EXP) SET_SR_BIT ((EXP), SR_MASK_M)
248 #define SET_SR_Q(EXP) SET_SR_BIT ((EXP), SR_MASK_Q)
249 #define SET_SR_S(EXP) SET_SR_BIT ((EXP), SR_MASK_S)
250 #define SET_SR_T(EXP) SET_SR_BIT ((EXP), SR_MASK_T)
252 /* stc currently relies on being able to read SR without modifications. */
253 #define GET_SR() (saved_state.asregs.cregs.named.sr - 0)
255 #define SET_SR(x) set_sr (x)
258 (saved_state.asregs.cregs.named.sr \
259 = saved_state.asregs.cregs.named.sr & 0xf000ffff | ((x) & 0xfff) << 16)
261 /* Manipulate FPSCR */
263 #define FPSCR_MASK_FR (1 << 21)
264 #define FPSCR_MASK_SZ (1 << 20)
265 #define FPSCR_MASK_PR (1 << 19)
267 #define FPSCR_FR ((GET_FPSCR() & FPSCR_MASK_FR) != 0)
268 #define FPSCR_SZ ((GET_FPSCR() & FPSCR_MASK_SZ) != 0)
269 #define FPSCR_PR ((GET_FPSCR() & FPSCR_MASK_PR) != 0)
271 /* Count the number of arguments in an argv. */
273 count_argc (char **argv
)
280 for (i
= 0; argv
[i
] != NULL
; ++i
)
289 int old
= saved_state
.asregs
.sregs
.named
.fpscr
;
290 saved_state
.asregs
.sregs
.named
.fpscr
= (x
);
291 /* swap the floating point register banks */
292 if ((saved_state
.asregs
.sregs
.named
.fpscr
^ old
) & FPSCR_MASK_FR
293 /* Ignore bit change if simulating sh-dsp. */
296 union fregs_u tmpf
= saved_state
.asregs
.fregs
[0];
297 saved_state
.asregs
.fregs
[0] = saved_state
.asregs
.fregs
[1];
298 saved_state
.asregs
.fregs
[1] = tmpf
;
302 /* sts relies on being able to read fpscr directly. */
303 #define GET_FPSCR() (saved_state.asregs.sregs.named.fpscr)
304 #define SET_FPSCR(x) \
309 #define DSR (saved_state.asregs.sregs.named.fpscr)
317 #define RAISE_EXCEPTION(x) \
318 (saved_state.asregs.exception = x, saved_state.asregs.insn_end = 0)
320 /* This function exists mainly for the purpose of setting a breakpoint to
321 catch simulated bus errors when running the simulator under GDB. */
333 raise_exception (SIGBUS
);
336 #define PROCESS_SPECIAL_ADDRESS(addr, endian, ptr, bits_written, \
337 forbidden_addr_bits, data, retval) \
339 if (addr & forbidden_addr_bits) \
344 else if ((addr & saved_state.asregs.xyram_select) \
345 == saved_state.asregs.xram_start) \
346 ptr = (void *) &saved_state.asregs.xmem_offset[addr ^ endian]; \
347 else if ((addr & saved_state.asregs.xyram_select) \
348 == saved_state.asregs.yram_start) \
349 ptr = (void *) &saved_state.asregs.ymem_offset[addr ^ endian]; \
350 else if ((unsigned) addr >> 24 == 0xf0 \
351 && bits_written == 32 && (data & 1) == 0) \
352 /* This invalidates (if not associative) or might invalidate \
353 (if associative) an instruction cache line. This is used for \
354 trampolines. Since we don't simulate the cache, this is a no-op \
355 as far as the simulator is concerned. */ \
359 if (bits_written == 8 && addr > 0x5000000) \
360 IOMEM (addr, 1, data); \
361 /* We can't do anything useful with the other stuff, so fail. */ \
367 /* FIXME: sim_resume should be renamed to sim_engine_run. sim_resume
368 being implemented by ../common/sim_resume.c and the below should
369 make a call to sim_engine_halt */
371 #define BUSERROR(addr, mask) ((addr) & (mask))
373 #define WRITE_BUSERROR(addr, mask, data, addr_func) \
378 addr_func (addr, data); \
384 #define READ_BUSERROR(addr, mask, addr_func) \
388 return addr_func (addr); \
392 /* Define this to enable register lifetime checking.
393 The compiler generates "add #0,rn" insns to mark registers as invalid,
394 the simulator uses this info to call fail if it finds a ref to an invalid
395 register before a def
402 #define CREF(x) if(!valid[x]) fail();
403 #define CDEF(x) valid[x] = 1;
404 #define UNDEF(x) valid[x] = 0;
411 static void parse_and_set_memory_size
PARAMS ((char *str
));
412 static int IOMEM
PARAMS ((int addr
, int write
, int value
));
413 static struct loop_bounds get_loop_bounds
PARAMS((int, int, unsigned char *,
414 unsigned char *, int, int));
415 static void process_wlat_addr
PARAMS((int, int));
416 static void process_wwat_addr
PARAMS((int, int));
417 static void process_wbat_addr
PARAMS((int, int));
418 static int process_rlat_addr
PARAMS((int));
419 static int process_rwat_addr
PARAMS((int));
420 static int process_rbat_addr
PARAMS((int));
421 static void INLINE wlat_fast
PARAMS ((unsigned char *, int, int, int));
422 static void INLINE wwat_fast
PARAMS ((unsigned char *, int, int, int, int));
423 static void INLINE wbat_fast
PARAMS ((unsigned char *, int, int, int));
424 static int INLINE rlat_fast
PARAMS ((unsigned char *, int, int));
425 static int INLINE rwat_fast
PARAMS ((unsigned char *, int, int, int));
426 static int INLINE rbat_fast
PARAMS ((unsigned char *, int, int));
428 static host_callback
*callback
;
432 /* Floating point registers */
434 #define DR(n) (get_dr (n))
440 if (host_little_endian
)
447 dr
.i
[1] = saved_state
.asregs
.fregs
[0].i
[n
+ 0];
448 dr
.i
[0] = saved_state
.asregs
.fregs
[0].i
[n
+ 1];
452 return (saved_state
.asregs
.fregs
[0].d
[n
>> 1]);
455 #define SET_DR(n, EXP) set_dr ((n), (EXP))
462 if (host_little_endian
)
470 saved_state
.asregs
.fregs
[0].i
[n
+ 0] = dr
.i
[1];
471 saved_state
.asregs
.fregs
[0].i
[n
+ 1] = dr
.i
[0];
474 saved_state
.asregs
.fregs
[0].d
[n
>> 1] = exp
;
477 #define SET_FI(n,EXP) (saved_state.asregs.fregs[0].i[(n)] = (EXP))
478 #define FI(n) (saved_state.asregs.fregs[0].i[(n)])
480 #define FR(n) (saved_state.asregs.fregs[0].f[(n)])
481 #define SET_FR(n,EXP) (saved_state.asregs.fregs[0].f[(n)] = (EXP))
483 #define XD_TO_XF(n) ((((n) & 1) << 5) | ((n) & 0x1e))
484 #define XF(n) (saved_state.asregs.fregs[(n) >> 5].i[(n) & 0x1f])
485 #define SET_XF(n,EXP) (saved_state.asregs.fregs[(n) >> 5].i[(n) & 0x1f] = (EXP))
487 #define RS saved_state.asregs.cregs.named.rs
488 #define RE saved_state.asregs.cregs.named.re
489 #define MOD (saved_state.asregs.cregs.named.mod)
492 MOD_ME = (unsigned) MOD >> 16 | (SR_DMY ? ~0xffff : (SR_DMX ? 0 : 0x10000)), \
493 MOD_DELTA = (MOD & 0xffff) - ((unsigned) MOD >> 16))
495 #define DSP_R(n) saved_state.asregs.sregs.i[(n)]
496 #define DSP_GRD(n) DSP_R ((n) + 8)
497 #define GET_DSP_GRD(n) ((n | 2) == 7 ? SEXT (DSP_GRD (n)) : SIGN32 (DSP_R (n)))
502 #define Y0 DSP_R (10)
503 #define Y1 DSP_R (11)
504 #define M0 DSP_R (12)
505 #define A1G DSP_R (13)
506 #define M1 DSP_R (14)
507 #define A0G DSP_R (15)
508 /* DSP_R (16) / DSP_GRD (16) are used as a fake destination for pcmp. */
509 #define MOD_ME DSP_GRD (17)
510 #define MOD_DELTA DSP_GRD (18)
512 #define FP_OP(n, OP, m) \
516 if (((n) & 1) || ((m) & 1)) \
517 RAISE_EXCEPTION (SIGILL); \
519 SET_DR(n, (DR(n) OP DR(m))); \
522 SET_FR(n, (FR(n) OP FR(m))); \
525 #define FP_UNARY(n, OP) \
530 RAISE_EXCEPTION (SIGILL); \
532 SET_DR(n, (OP (DR(n)))); \
535 SET_FR(n, (OP (FR(n)))); \
538 #define FP_CMP(n, OP, m) \
542 if (((n) & 1) || ((m) & 1)) \
543 RAISE_EXCEPTION (SIGILL); \
545 SET_SR_T (DR(n) OP DR(m)); \
548 SET_SR_T (FR(n) OP FR(m)); \
555 /* do we need to swap banks */
556 int old_gpr
= SR_MD
&& SR_RB
;
557 int new_gpr
= (new_sr
& SR_MASK_MD
) && (new_sr
& SR_MASK_RB
);
558 if (old_gpr
!= new_gpr
)
561 for (i
= 0; i
< 8; i
++)
563 tmp
= saved_state
.asregs
.cregs
.named
.bank
[i
];
564 saved_state
.asregs
.cregs
.named
.bank
[i
] = saved_state
.asregs
.regs
[i
];
565 saved_state
.asregs
.regs
[i
] = tmp
;
568 saved_state
.asregs
.cregs
.named
.sr
= new_sr
;
573 wlat_fast (memory
, x
, value
, maskl
)
574 unsigned char *memory
;
577 unsigned int *p
= (unsigned int *)(memory
+ x
);
578 WRITE_BUSERROR (x
, maskl
, v
, process_wlat_addr
);
583 wwat_fast (memory
, x
, value
, maskw
, endianw
)
584 unsigned char *memory
;
587 unsigned short *p
= (unsigned short *)(memory
+ (x
^ endianw
));
588 WRITE_BUSERROR (x
, maskw
, v
, process_wwat_addr
);
593 wbat_fast (memory
, x
, value
, maskb
)
594 unsigned char *memory
;
596 unsigned char *p
= memory
+ (x
^ endianb
);
597 WRITE_BUSERROR (x
, maskb
, value
, process_wbat_addr
);
605 rlat_fast (memory
, x
, maskl
)
606 unsigned char *memory
;
608 unsigned int *p
= (unsigned int *)(memory
+ x
);
609 READ_BUSERROR (x
, maskl
, process_rlat_addr
);
615 rwat_fast (memory
, x
, maskw
, endianw
)
616 unsigned char *memory
;
617 int x
, maskw
, endianw
;
619 unsigned short *p
= (unsigned short *)(memory
+ (x
^ endianw
));
620 READ_BUSERROR (x
, maskw
, process_rwat_addr
);
626 riat_fast (insn_ptr
, endianw
)
627 unsigned char *insn_ptr
;
629 unsigned short *p
= (unsigned short *)((size_t) insn_ptr
^ endianw
);
635 rbat_fast (memory
, x
, maskb
)
636 unsigned char *memory
;
638 unsigned char *p
= memory
+ (x
^ endianb
);
639 READ_BUSERROR (x
, maskb
, process_rbat_addr
);
644 #define RWAT(x) (rwat_fast (memory, x, maskw, endianw))
645 #define RLAT(x) (rlat_fast (memory, x, maskl))
646 #define RBAT(x) (rbat_fast (memory, x, maskb))
647 #define RIAT(p) (riat_fast ((p), endianw))
648 #define WWAT(x,v) (wwat_fast (memory, x, v, maskw, endianw))
649 #define WLAT(x,v) (wlat_fast (memory, x, v, maskl))
650 #define WBAT(x,v) (wbat_fast (memory, x, v, maskb))
652 #define RUWAT(x) (RWAT(x) & 0xffff)
653 #define RSWAT(x) ((short)(RWAT(x)))
654 #define RSBAT(x) (SEXT(RBAT(x)))
656 #define RDAT(x, n) (do_rdat (memory, (x), (n), (maskl)))
658 do_rdat (memory
, x
, n
, maskl
)
668 f0
= rlat_fast (memory
, x
+ 0, maskl
);
669 f1
= rlat_fast (memory
, x
+ 4, maskl
);
670 saved_state
.asregs
.fregs
[i
].i
[(j
+ 0)] = f0
;
671 saved_state
.asregs
.fregs
[i
].i
[(j
+ 1)] = f1
;
675 #define WDAT(x, n) (do_wdat (memory, (x), (n), (maskl)))
677 do_wdat (memory
, x
, n
, maskl
)
687 f0
= saved_state
.asregs
.fregs
[i
].i
[(j
+ 0)];
688 f1
= saved_state
.asregs
.fregs
[i
].i
[(j
+ 1)];
689 wlat_fast (memory
, (x
+ 0), f0
, maskl
);
690 wlat_fast (memory
, (x
+ 4), f1
, maskl
);
695 process_wlat_addr (addr
, value
)
701 PROCESS_SPECIAL_ADDRESS (addr
, endianb
, ptr
, 32, 3, value
, );
706 process_wwat_addr (addr
, value
)
712 PROCESS_SPECIAL_ADDRESS (addr
, endianb
, ptr
, 16, 1, value
, );
717 process_wbat_addr (addr
, value
)
723 PROCESS_SPECIAL_ADDRESS (addr
, endianb
, ptr
, 8, 0, value
, );
728 process_rlat_addr (addr
)
733 PROCESS_SPECIAL_ADDRESS (addr
, endianb
, ptr
, -32, 3, -1, 0);
738 process_rwat_addr (addr
)
743 PROCESS_SPECIAL_ADDRESS (addr
, endianb
, ptr
, -16, 1, -1, 0);
748 process_rbat_addr (addr
)
753 PROCESS_SPECIAL_ADDRESS (addr
, endianb
, ptr
, -8, 0, -1, 0);
757 #define SEXT(x) (((x & 0xff) ^ (~0x7f))+0x80)
758 #define SEXT12(x) (((x & 0xfff) ^ 0x800) - 0x800)
759 #define SEXTW(y) ((int)((short)y))
761 #define SEXT32(x) ((int)((x & 0xffffffff) ^ 0x80000000U) - 0x7fffffff - 1)
763 #define SEXT32(x) ((int)(x))
765 #define SIGN32(x) (SEXT32 (x) >> 31)
767 /* convert pointer from target to host value. */
768 #define PT2H(x) ((x) + memory)
769 /* convert pointer from host to target value. */
770 #define PH2T(x) ((x) - memory)
772 #define SKIP_INSN(p) ((p) += ((RIAT (p) & 0xfc00) == 0xf800 ? 4 : 2))
774 #define SET_NIP(x) nip = (x); CHECK_INSN_PTR (nip);
776 #define Delay_Slot(TEMPPC) iword = RIAT (TEMPPC); goto top;
778 #define CHECK_INSN_PTR(p) \
780 if (saved_state.asregs.exception || PH2T (p) & maskw) \
781 saved_state.asregs.insn_end = 0; \
782 else if (p < loop.end) \
783 saved_state.asregs.insn_end = loop.end; \
785 saved_state.asregs.insn_end = mem_end; \
798 do { memstalls += ((((int) PC & 3) != 0) ? (n) : ((n) - 1)); } while (0)
800 #define L(x) thislock = x;
801 #define TL(x) if ((x) == prevlock) stalls++;
802 #define TB(x,y) if ((x) == prevlock || (y)==prevlock) stalls++;
806 #if defined(__GO32__) || defined(_WIN32)
807 int sim_memory_size
= 19;
809 int sim_memory_size
= 24;
812 static int sim_profile_size
= 17;
818 #define SMR1 (0x05FFFEC8) /* Channel 1 serial mode register */
819 #define BRR1 (0x05FFFEC9) /* Channel 1 bit rate register */
820 #define SCR1 (0x05FFFECA) /* Channel 1 serial control register */
821 #define TDR1 (0x05FFFECB) /* Channel 1 transmit data register */
822 #define SSR1 (0x05FFFECC) /* Channel 1 serial status register */
823 #define RDR1 (0x05FFFECD) /* Channel 1 receive data register */
825 #define SCI_RDRF 0x40 /* Recieve data register full */
826 #define SCI_TDRE 0x80 /* Transmit data register empty */
829 IOMEM (addr
, write
, value
)
861 return time ((long *) 0);
870 static FILE *profile_file
;
872 static unsigned INLINE
877 n
= (n
<< 24 | (n
& 0xff00) << 8
878 | (n
& 0xff0000) >> 8 | (n
& 0xff000000) >> 24);
882 static unsigned short INLINE
887 n
= n
<< 8 | (n
& 0xff00) >> 8;
897 union { char b
[4]; int n
; } u
;
899 fwrite (u
.b
, 4, 1, profile_file
);
907 union { char b
[4]; int n
; } u
;
909 fwrite (u
.b
, 2, 1, profile_file
);
912 /* Turn a pointer in a register into a pointer into real memory. */
918 return (char *) (x
+ saved_state
.asregs
.memory
);
925 unsigned char *memory
= saved_state
.asregs
.memory
;
927 int endian
= endianb
;
932 for (end
= str
; memory
[end
^ endian
]; end
++) ;
943 if (! endianb
|| ! len
)
945 start
= (int *) ptr (str
& ~3);
946 end
= (int *) ptr (str
+ len
);
950 *start
= (old
<< 24 | (old
& 0xff00) << 8
951 | (old
& 0xff0000) >> 8 | (old
& 0xff000000) >> 24);
957 /* Simulate a monitor trap, put the result into r0 and errno into r1
958 return offset by which to adjust pc. */
961 trap (i
, regs
, insn_ptr
, memory
, maskl
, maskw
, endianw
)
964 unsigned char *insn_ptr
;
965 unsigned char *memory
;
970 printf ("%c", regs
[0]);
973 raise_exception (SIGQUIT
);
975 case 3: /* FIXME: for backwards compat, should be removed */
978 unsigned int countp
= * (unsigned int *) (insn_ptr
+ 4);
980 WLAT (countp
, RLAT (countp
) + 1);
992 #if !defined(__GO32__) && !defined(_WIN32)
996 /* This would work only if endianness matched between host and target.
997 Besides, it's quite dangerous. */
1000 regs
[0] = execve (ptr (regs
[5]), (char **)ptr (regs
[6]), (char **)ptr (regs
[7]));
1003 regs
[0] = execve (ptr (regs
[5]),(char **) ptr (regs
[6]), 0);
1008 regs
[0] = (BUSERROR (regs
[5], maskl
)
1010 : pipe ((int *) ptr (regs
[5])));
1015 regs
[0] = wait (ptr (regs
[5]));
1017 #endif /* !defined(__GO32__) && !defined(_WIN32) */
1020 strnswap (regs
[6], regs
[7]);
1022 = callback
->read (callback
, regs
[5], ptr (regs
[6]), regs
[7]);
1023 strnswap (regs
[6], regs
[7]);
1026 strnswap (regs
[6], regs
[7]);
1028 regs
[0] = (int)callback
->write_stdout (callback
, ptr(regs
[6]), regs
[7]);
1030 regs
[0] = (int)callback
->write (callback
, regs
[5], ptr (regs
[6]), regs
[7]);
1031 strnswap (regs
[6], regs
[7]);
1034 regs
[0] = callback
->lseek (callback
,regs
[5], regs
[6], regs
[7]);
1037 regs
[0] = callback
->close (callback
,regs
[5]);
1041 int len
= strswaplen (regs
[5]);
1042 strnswap (regs
[5], len
);
1043 regs
[0] = callback
->open (callback
,ptr (regs
[5]), regs
[6]);
1044 strnswap (regs
[5], len
);
1048 /* EXIT - caller can look in r5 to work out the reason */
1049 raise_exception (SIGQUIT
);
1053 case SYS_stat
: /* added at hmsi */
1054 /* stat system call */
1056 struct stat host_stat
;
1058 int len
= strswaplen (regs
[5]);
1060 strnswap (regs
[5], len
);
1061 regs
[0] = stat (ptr (regs
[5]), &host_stat
);
1062 strnswap (regs
[5], len
);
1066 WWAT (buf
, host_stat
.st_dev
);
1068 WWAT (buf
, host_stat
.st_ino
);
1070 WLAT (buf
, host_stat
.st_mode
);
1072 WWAT (buf
, host_stat
.st_nlink
);
1074 WWAT (buf
, host_stat
.st_uid
);
1076 WWAT (buf
, host_stat
.st_gid
);
1078 WWAT (buf
, host_stat
.st_rdev
);
1080 WLAT (buf
, host_stat
.st_size
);
1082 WLAT (buf
, host_stat
.st_atime
);
1086 WLAT (buf
, host_stat
.st_mtime
);
1090 WLAT (buf
, host_stat
.st_ctime
);
1104 int len
= strswaplen (regs
[5]);
1106 strnswap (regs
[5], len
);
1107 regs
[0] = chown (ptr (regs
[5]), regs
[6], regs
[7]);
1108 strnswap (regs
[5], len
);
1114 int len
= strswaplen (regs
[5]);
1116 strnswap (regs
[5], len
);
1117 regs
[0] = chmod (ptr (regs
[5]), regs
[6]);
1118 strnswap (regs
[5], len
);
1123 /* Cast the second argument to void *, to avoid type mismatch
1124 if a prototype is present. */
1125 int len
= strswaplen (regs
[5]);
1127 strnswap (regs
[5], len
);
1128 regs
[0] = utime (ptr (regs
[5]), (void *) ptr (regs
[6]));
1129 strnswap (regs
[5], len
);
1133 regs
[0] = count_argc (prog_argv
);
1136 if (regs
[5] < count_argc (prog_argv
))
1137 regs
[0] = strlen (prog_argv
[regs
[5]]);
1142 if (regs
[5] < count_argc (prog_argv
))
1144 /* Include the termination byte. */
1145 int i
= strlen (prog_argv
[regs
[5]]) + 1;
1146 regs
[0] = sim_write (0, regs
[6], prog_argv
[regs
[5]], i
);
1152 regs
[0] = get_now ();
1158 regs
[1] = callback
->get_errno (callback
);
1165 raise_exception (SIGTRAP
);
1174 control_c (sig
, code
, scp
, addr
)
1180 raise_exception (SIGINT
);
1184 div1 (R
, iRn2
, iRn1
/*, T*/)
1191 unsigned char old_q
, tmp1
;
1194 SET_SR_Q ((unsigned char) ((0x80000000 & R
[iRn1
]) != 0));
1196 R
[iRn1
] |= (unsigned long) T
;
1206 tmp1
= (R
[iRn1
] > tmp0
);
1213 SET_SR_Q ((unsigned char) (tmp1
== 0));
1220 tmp1
= (R
[iRn1
] < tmp0
);
1224 SET_SR_Q ((unsigned char) (tmp1
== 0));
1239 tmp1
= (R
[iRn1
] < tmp0
);
1246 SET_SR_Q ((unsigned char) (tmp1
== 0));
1253 tmp1
= (R
[iRn1
] > tmp0
);
1257 SET_SR_Q ((unsigned char) (tmp1
== 0));
1278 unsigned long RnL
, RnH
;
1279 unsigned long RmL
, RmH
;
1280 unsigned long temp0
, temp1
, temp2
, temp3
;
1281 unsigned long Res2
, Res1
, Res0
;
1284 RnH
= (rn
>> 16) & 0xffff;
1286 RmH
= (rm
>> 16) & 0xffff;
1292 Res1
= temp1
+ temp2
;
1295 temp1
= (Res1
<< 16) & 0xffff0000;
1296 Res0
= temp0
+ temp1
;
1299 Res2
+= ((Res1
>> 16) & 0xffff) + temp3
;
1303 if (rn
& 0x80000000)
1305 if (rm
& 0x80000000)
1314 macw (regs
, memory
, n
, m
, endianw
)
1316 unsigned char *memory
;
1321 long prod
, macl
, sum
;
1323 tempm
=RSWAT(regs
[m
]); regs
[m
]+=2;
1324 tempn
=RSWAT(regs
[n
]); regs
[n
]+=2;
1327 prod
= (long)(short) tempm
* (long)(short) tempn
;
1331 if ((~(prod
^ macl
) & (sum
^ prod
)) < 0)
1333 /* MACH's lsb is a sticky overflow bit. */
1335 /* Store the smallest negative number in MACL if prod is
1336 negative, and the largest positive number otherwise. */
1337 sum
= 0x7fffffff + (prod
< 0);
1343 /* Add to MACH the sign extended product, and carry from low sum. */
1344 mach
= MACH
+ (-(prod
< 0)) + ((unsigned long) sum
< prod
);
1345 /* Sign extend at 10:th bit in MACH. */
1346 MACH
= (mach
& 0x1ff) | -(mach
& 0x200);
1351 static struct loop_bounds
1352 get_loop_bounds (rs
, re
, memory
, mem_end
, maskw
, endianw
)
1354 unsigned char *memory
, *mem_end
;
1357 struct loop_bounds loop
;
1363 loop
.start
= PT2H (RE
- 4);
1364 SKIP_INSN (loop
.start
);
1365 loop
.end
= loop
.start
;
1367 SKIP_INSN (loop
.end
);
1369 SKIP_INSN (loop
.end
);
1370 SKIP_INSN (loop
.end
);
1374 loop
.start
= PT2H (RS
);
1375 loop
.end
= PT2H (RE
- 4);
1376 SKIP_INSN (loop
.end
);
1377 SKIP_INSN (loop
.end
);
1378 SKIP_INSN (loop
.end
);
1379 SKIP_INSN (loop
.end
);
1381 if (loop
.end
>= mem_end
)
1382 loop
.end
= PT2H (0);
1385 loop
.end
= PT2H (0);
1395 /* Set the memory size to the power of two provided. */
1402 saved_state
.asregs
.msize
= 1 << power
;
1404 sim_memory_size
= power
;
1406 if (saved_state
.asregs
.memory
)
1408 free (saved_state
.asregs
.memory
);
1411 saved_state
.asregs
.memory
=
1412 (unsigned char *) calloc (64, saved_state
.asregs
.msize
/ 64);
1414 if (!saved_state
.asregs
.memory
)
1417 "Not enough VM for simulation of %d bytes of RAM\n",
1418 saved_state
.asregs
.msize
);
1420 saved_state
.asregs
.msize
= 1;
1421 saved_state
.asregs
.memory
= (unsigned char *) calloc (1, 1);
1429 int was_dsp
= target_dsp
;
1430 unsigned long mach
= bfd_get_mach (abfd
);
1432 if (mach
== bfd_mach_sh_dsp
|| mach
== bfd_mach_sh3_dsp
)
1434 int ram_area_size
, xram_start
, yram_start
;
1438 if (mach
== bfd_mach_sh_dsp
)
1440 /* SH7410 (orig. sh-sdp):
1441 4KB each for X & Y memory;
1442 On-chip X RAM 0x0800f000-0x0800ffff
1443 On-chip Y RAM 0x0801f000-0x0801ffff */
1444 xram_start
= 0x0800f000;
1445 ram_area_size
= 0x1000;
1447 if (mach
== bfd_mach_sh3_dsp
)
1450 8KB each for X & Y memory;
1451 On-chip X RAM 0x1000e000-0x1000ffff
1452 On-chip Y RAM 0x1001e000-0x1001ffff */
1453 xram_start
= 0x1000e000;
1454 ram_area_size
= 0x2000;
1456 yram_start
= xram_start
+ 0x10000;
1457 new_select
= ~(ram_area_size
- 1);
1458 if (saved_state
.asregs
.xyram_select
!= new_select
)
1460 saved_state
.asregs
.xyram_select
= new_select
;
1461 free (saved_state
.asregs
.xmem
);
1462 free (saved_state
.asregs
.ymem
);
1463 saved_state
.asregs
.xmem
= (unsigned char *) calloc (1, ram_area_size
);
1464 saved_state
.asregs
.ymem
= (unsigned char *) calloc (1, ram_area_size
);
1466 /* Disable use of X / Y mmeory if not allocated. */
1467 if (! saved_state
.asregs
.xmem
|| ! saved_state
.asregs
.ymem
)
1469 saved_state
.asregs
.xyram_select
= 0;
1470 if (saved_state
.asregs
.xmem
)
1471 free (saved_state
.asregs
.xmem
);
1472 if (saved_state
.asregs
.ymem
)
1473 free (saved_state
.asregs
.ymem
);
1476 saved_state
.asregs
.xram_start
= xram_start
;
1477 saved_state
.asregs
.yram_start
= yram_start
;
1478 saved_state
.asregs
.xmem_offset
= saved_state
.asregs
.xmem
- xram_start
;
1479 saved_state
.asregs
.ymem_offset
= saved_state
.asregs
.ymem
- yram_start
;
1484 if (saved_state
.asregs
.xyram_select
)
1486 saved_state
.asregs
.xyram_select
= 0;
1487 free (saved_state
.asregs
.xmem
);
1488 free (saved_state
.asregs
.ymem
);
1492 if (! saved_state
.asregs
.xyram_select
)
1494 saved_state
.asregs
.xram_start
= 1;
1495 saved_state
.asregs
.yram_start
= 1;
1498 if (target_dsp
!= was_dsp
)
1502 for (i
= sizeof sh_dsp_table
- 1; i
>= 0; i
--)
1504 tmp
= sh_jump_table
[0xf000 + i
];
1505 sh_jump_table
[0xf000 + i
] = sh_dsp_table
[i
];
1506 sh_dsp_table
[i
] = tmp
;
1514 host_little_endian
= 0;
1515 *(char*)&host_little_endian
= 1;
1516 host_little_endian
&= 1;
1518 if (saved_state
.asregs
.msize
!= 1 << sim_memory_size
)
1520 sim_size (sim_memory_size
);
1523 if (saved_state
.asregs
.profile
&& !profile_file
)
1525 profile_file
= fopen ("gmon.out", "wb");
1526 /* Seek to where to put the call arc data */
1527 nsamples
= (1 << sim_profile_size
);
1529 fseek (profile_file
, nsamples
* 2 + 12, 0);
1533 fprintf (stderr
, "Can't open gmon.out\n");
1537 saved_state
.asregs
.profile_hist
=
1538 (unsigned short *) calloc (64, (nsamples
* sizeof (short) / 64));
1551 p
= saved_state
.asregs
.profile_hist
;
1553 maxpc
= (1 << sim_profile_size
);
1555 fseek (profile_file
, 0L, 0);
1556 swapout (minpc
<< PROFILE_SHIFT
);
1557 swapout (maxpc
<< PROFILE_SHIFT
);
1558 swapout (nsamples
* 2 + 12);
1559 for (i
= 0; i
< nsamples
; i
++)
1560 swapout16 (saved_state
.asregs
.profile_hist
[i
]);
1574 #define MMASKB ((saved_state.asregs.msize -1) & ~0)
1580 raise_exception (SIGINT
);
1585 sim_resume (sd
, step
, siggnal
)
1589 register unsigned char *insn_ptr
;
1590 unsigned char *mem_end
;
1591 struct loop_bounds loop
;
1592 register int cycles
= 0;
1593 register int stalls
= 0;
1594 register int memstalls
= 0;
1595 register int insts
= 0;
1596 register int prevlock
;
1597 register int thislock
;
1598 register unsigned int doprofile
;
1599 register int pollcount
= 0;
1600 /* endianw is used for every insn fetch, hence it makes sense to cache it.
1601 endianb is used less often. */
1602 register int endianw
= global_endianw
;
1604 int tick_start
= get_now ();
1606 void (*prev_fpe
) ();
1608 register unsigned char *jump_table
= sh_jump_table
;
1610 register int *R
= &(saved_state
.asregs
.regs
[0]);
1616 register int maskb
= ~((saved_state
.asregs
.msize
- 1) & ~0);
1617 register int maskw
= ~((saved_state
.asregs
.msize
- 1) & ~1);
1618 register int maskl
= ~((saved_state
.asregs
.msize
- 1) & ~3);
1619 register unsigned char *memory
;
1620 register unsigned int sbit
= ((unsigned int) 1 << 31);
1622 prev
= signal (SIGINT
, control_c
);
1623 prev_fpe
= signal (SIGFPE
, SIG_IGN
);
1626 saved_state
.asregs
.exception
= 0;
1628 memory
= saved_state
.asregs
.memory
;
1629 mem_end
= memory
+ saved_state
.asregs
.msize
;
1631 loop
= get_loop_bounds (RS
, RE
, memory
, mem_end
, maskw
, endianw
);
1632 insn_ptr
= PT2H (saved_state
.asregs
.pc
);
1633 CHECK_INSN_PTR (insn_ptr
);
1636 PR
= saved_state
.asregs
.sregs
.named
.pr
;
1638 /*T = GET_SR () & SR_MASK_T;*/
1639 prevlock
= saved_state
.asregs
.prevlock
;
1640 thislock
= saved_state
.asregs
.thislock
;
1641 doprofile
= saved_state
.asregs
.profile
;
1643 /* If profiling not enabled, disable it by asking for
1644 profiles infrequently. */
1649 if (step
&& insn_ptr
< saved_state
.asregs
.insn_end
)
1651 if (saved_state
.asregs
.exception
)
1652 /* This can happen if we've already been single-stepping and
1653 encountered a loop end. */
1654 saved_state
.asregs
.insn_end
= insn_ptr
;
1657 saved_state
.asregs
.exception
= SIGTRAP
;
1658 saved_state
.asregs
.insn_end
= insn_ptr
+ 2;
1662 while (insn_ptr
< saved_state
.asregs
.insn_end
)
1664 register unsigned int iword
= RIAT (insn_ptr
);
1665 register unsigned int ult
;
1666 register unsigned char *nip
= insn_ptr
+ 2;
1678 if (--pollcount
< 0)
1680 pollcount
= POLL_QUIT_INTERVAL
;
1681 if ((*callback
->poll_quit
) != NULL
1682 && (*callback
->poll_quit
) (callback
))
1689 prevlock
= thislock
;
1693 if (cycles
>= doprofile
)
1696 saved_state
.asregs
.cycles
+= doprofile
;
1697 cycles
-= doprofile
;
1698 if (saved_state
.asregs
.profile_hist
)
1700 int n
= PH2T (insn_ptr
) >> PROFILE_SHIFT
;
1703 int i
= saved_state
.asregs
.profile_hist
[n
];
1705 saved_state
.asregs
.profile_hist
[n
] = i
+ 1;
1712 if (saved_state
.asregs
.insn_end
== loop
.end
)
1714 saved_state
.asregs
.cregs
.named
.sr
+= SR_RC_INCREMENT
;
1716 insn_ptr
= loop
.start
;
1719 saved_state
.asregs
.insn_end
= mem_end
;
1720 loop
.end
= PT2H (0);
1725 if (saved_state
.asregs
.exception
== SIGILL
1726 || saved_state
.asregs
.exception
== SIGBUS
)
1730 /* Check for SIGBUS due to insn fetch. */
1731 else if (! saved_state
.asregs
.exception
)
1732 saved_state
.asregs
.exception
= SIGBUS
;
1734 saved_state
.asregs
.ticks
+= get_now () - tick_start
;
1735 saved_state
.asregs
.cycles
+= cycles
;
1736 saved_state
.asregs
.stalls
+= stalls
;
1737 saved_state
.asregs
.memstalls
+= memstalls
;
1738 saved_state
.asregs
.insts
+= insts
;
1739 saved_state
.asregs
.pc
= PH2T (insn_ptr
);
1741 saved_state
.asregs
.sregs
.named
.pr
= PR
;
1744 saved_state
.asregs
.prevlock
= prevlock
;
1745 saved_state
.asregs
.thislock
= thislock
;
1752 signal (SIGFPE
, prev_fpe
);
1753 signal (SIGINT
, prev
);
1757 sim_write (sd
, addr
, buffer
, size
)
1760 unsigned char *buffer
;
1767 for (i
= 0; i
< size
; i
++)
1769 saved_state
.asregs
.memory
[(MMASKB
& (addr
+ i
)) ^ endianb
] = buffer
[i
];
1775 sim_read (sd
, addr
, buffer
, size
)
1778 unsigned char *buffer
;
1785 for (i
= 0; i
< size
; i
++)
1787 buffer
[i
] = saved_state
.asregs
.memory
[(MMASKB
& (addr
+ i
)) ^ endianb
];
1793 sim_store_register (sd
, rn
, memory
, length
)
1796 unsigned char *memory
;
1802 val
= swap (* (int *)memory
);
1805 case SIM_SH_R0_REGNUM
: case SIM_SH_R1_REGNUM
: case SIM_SH_R2_REGNUM
:
1806 case SIM_SH_R3_REGNUM
: case SIM_SH_R4_REGNUM
: case SIM_SH_R5_REGNUM
:
1807 case SIM_SH_R6_REGNUM
: case SIM_SH_R7_REGNUM
: case SIM_SH_R8_REGNUM
:
1808 case SIM_SH_R9_REGNUM
: case SIM_SH_R10_REGNUM
: case SIM_SH_R11_REGNUM
:
1809 case SIM_SH_R12_REGNUM
: case SIM_SH_R13_REGNUM
: case SIM_SH_R14_REGNUM
:
1810 case SIM_SH_R15_REGNUM
:
1811 saved_state
.asregs
.regs
[rn
] = val
;
1813 case SIM_SH_PC_REGNUM
:
1814 saved_state
.asregs
.pc
= val
;
1816 case SIM_SH_PR_REGNUM
:
1819 case SIM_SH_GBR_REGNUM
:
1822 case SIM_SH_VBR_REGNUM
:
1825 case SIM_SH_MACH_REGNUM
:
1828 case SIM_SH_MACL_REGNUM
:
1831 case SIM_SH_SR_REGNUM
:
1834 case SIM_SH_FPUL_REGNUM
:
1837 case SIM_SH_FPSCR_REGNUM
:
1840 case SIM_SH_FR0_REGNUM
: case SIM_SH_FR1_REGNUM
: case SIM_SH_FR2_REGNUM
:
1841 case SIM_SH_FR3_REGNUM
: case SIM_SH_FR4_REGNUM
: case SIM_SH_FR5_REGNUM
:
1842 case SIM_SH_FR6_REGNUM
: case SIM_SH_FR7_REGNUM
: case SIM_SH_FR8_REGNUM
:
1843 case SIM_SH_FR9_REGNUM
: case SIM_SH_FR10_REGNUM
: case SIM_SH_FR11_REGNUM
:
1844 case SIM_SH_FR12_REGNUM
: case SIM_SH_FR13_REGNUM
: case SIM_SH_FR14_REGNUM
:
1845 case SIM_SH_FR15_REGNUM
:
1846 SET_FI (rn
- SIM_SH_FR0_REGNUM
, val
);
1848 case SIM_SH_DSR_REGNUM
:
1851 case SIM_SH_A0G_REGNUM
:
1854 case SIM_SH_A0_REGNUM
:
1857 case SIM_SH_A1G_REGNUM
:
1860 case SIM_SH_A1_REGNUM
:
1863 case SIM_SH_M0_REGNUM
:
1866 case SIM_SH_M1_REGNUM
:
1869 case SIM_SH_X0_REGNUM
:
1872 case SIM_SH_X1_REGNUM
:
1875 case SIM_SH_Y0_REGNUM
:
1878 case SIM_SH_Y1_REGNUM
:
1881 case SIM_SH_MOD_REGNUM
:
1884 case SIM_SH_RS_REGNUM
:
1887 case SIM_SH_RE_REGNUM
:
1890 case SIM_SH_SSR_REGNUM
:
1893 case SIM_SH_SPC_REGNUM
:
1896 /* The rn_bank idiosyncracies are not due to hardware differences, but to
1897 a weird aliasing naming scheme for sh3 / sh3e / sh4. */
1898 case SIM_SH_R0_BANK0_REGNUM
: case SIM_SH_R1_BANK0_REGNUM
:
1899 case SIM_SH_R2_BANK0_REGNUM
: case SIM_SH_R3_BANK0_REGNUM
:
1900 case SIM_SH_R4_BANK0_REGNUM
: case SIM_SH_R5_BANK0_REGNUM
:
1901 case SIM_SH_R6_BANK0_REGNUM
: case SIM_SH_R7_BANK0_REGNUM
:
1903 Rn_BANK (rn
- SIM_SH_R0_BANK0_REGNUM
) = val
;
1905 saved_state
.asregs
.regs
[rn
- SIM_SH_R0_BANK0_REGNUM
] = val
;
1907 case SIM_SH_R0_BANK1_REGNUM
: case SIM_SH_R1_BANK1_REGNUM
:
1908 case SIM_SH_R2_BANK1_REGNUM
: case SIM_SH_R3_BANK1_REGNUM
:
1909 case SIM_SH_R4_BANK1_REGNUM
: case SIM_SH_R5_BANK1_REGNUM
:
1910 case SIM_SH_R6_BANK1_REGNUM
: case SIM_SH_R7_BANK1_REGNUM
:
1912 saved_state
.asregs
.regs
[rn
- SIM_SH_R0_BANK1_REGNUM
] = val
;
1914 Rn_BANK (rn
- SIM_SH_R0_BANK1_REGNUM
) = val
;
1916 case SIM_SH_R0_BANK_REGNUM
: case SIM_SH_R1_BANK_REGNUM
:
1917 case SIM_SH_R2_BANK_REGNUM
: case SIM_SH_R3_BANK_REGNUM
:
1918 case SIM_SH_R4_BANK_REGNUM
: case SIM_SH_R5_BANK_REGNUM
:
1919 case SIM_SH_R6_BANK_REGNUM
: case SIM_SH_R7_BANK_REGNUM
:
1920 SET_Rn_BANK (rn
- SIM_SH_R0_BANK_REGNUM
, val
);
1929 sim_fetch_register (sd
, rn
, memory
, length
)
1932 unsigned char *memory
;
1940 case SIM_SH_R0_REGNUM
: case SIM_SH_R1_REGNUM
: case SIM_SH_R2_REGNUM
:
1941 case SIM_SH_R3_REGNUM
: case SIM_SH_R4_REGNUM
: case SIM_SH_R5_REGNUM
:
1942 case SIM_SH_R6_REGNUM
: case SIM_SH_R7_REGNUM
: case SIM_SH_R8_REGNUM
:
1943 case SIM_SH_R9_REGNUM
: case SIM_SH_R10_REGNUM
: case SIM_SH_R11_REGNUM
:
1944 case SIM_SH_R12_REGNUM
: case SIM_SH_R13_REGNUM
: case SIM_SH_R14_REGNUM
:
1945 case SIM_SH_R15_REGNUM
:
1946 val
= saved_state
.asregs
.regs
[rn
];
1948 case SIM_SH_PC_REGNUM
:
1949 val
= saved_state
.asregs
.pc
;
1951 case SIM_SH_PR_REGNUM
:
1954 case SIM_SH_GBR_REGNUM
:
1957 case SIM_SH_VBR_REGNUM
:
1960 case SIM_SH_MACH_REGNUM
:
1963 case SIM_SH_MACL_REGNUM
:
1966 case SIM_SH_SR_REGNUM
:
1969 case SIM_SH_FPUL_REGNUM
:
1972 case SIM_SH_FPSCR_REGNUM
:
1975 case SIM_SH_FR0_REGNUM
: case SIM_SH_FR1_REGNUM
: case SIM_SH_FR2_REGNUM
:
1976 case SIM_SH_FR3_REGNUM
: case SIM_SH_FR4_REGNUM
: case SIM_SH_FR5_REGNUM
:
1977 case SIM_SH_FR6_REGNUM
: case SIM_SH_FR7_REGNUM
: case SIM_SH_FR8_REGNUM
:
1978 case SIM_SH_FR9_REGNUM
: case SIM_SH_FR10_REGNUM
: case SIM_SH_FR11_REGNUM
:
1979 case SIM_SH_FR12_REGNUM
: case SIM_SH_FR13_REGNUM
: case SIM_SH_FR14_REGNUM
:
1980 case SIM_SH_FR15_REGNUM
:
1981 val
= FI (rn
- SIM_SH_FR0_REGNUM
);
1983 case SIM_SH_DSR_REGNUM
:
1986 case SIM_SH_A0G_REGNUM
:
1989 case SIM_SH_A0_REGNUM
:
1992 case SIM_SH_A1G_REGNUM
:
1995 case SIM_SH_A1_REGNUM
:
1998 case SIM_SH_M0_REGNUM
:
2001 case SIM_SH_M1_REGNUM
:
2004 case SIM_SH_X0_REGNUM
:
2007 case SIM_SH_X1_REGNUM
:
2010 case SIM_SH_Y0_REGNUM
:
2013 case SIM_SH_Y1_REGNUM
:
2016 case SIM_SH_MOD_REGNUM
:
2019 case SIM_SH_RS_REGNUM
:
2022 case SIM_SH_RE_REGNUM
:
2025 case SIM_SH_SSR_REGNUM
:
2028 case SIM_SH_SPC_REGNUM
:
2031 /* The rn_bank idiosyncracies are not due to hardware differences, but to
2032 a weird aliasing naming scheme for sh3 / sh3e / sh4. */
2033 case SIM_SH_R0_BANK0_REGNUM
: case SIM_SH_R1_BANK0_REGNUM
:
2034 case SIM_SH_R2_BANK0_REGNUM
: case SIM_SH_R3_BANK0_REGNUM
:
2035 case SIM_SH_R4_BANK0_REGNUM
: case SIM_SH_R5_BANK0_REGNUM
:
2036 case SIM_SH_R6_BANK0_REGNUM
: case SIM_SH_R7_BANK0_REGNUM
:
2037 val
= (SR_MD
&& SR_RB
2038 ? Rn_BANK (rn
- SIM_SH_R0_BANK0_REGNUM
)
2039 : saved_state
.asregs
.regs
[rn
- SIM_SH_R0_BANK0_REGNUM
]);
2041 case SIM_SH_R0_BANK1_REGNUM
: case SIM_SH_R1_BANK1_REGNUM
:
2042 case SIM_SH_R2_BANK1_REGNUM
: case SIM_SH_R3_BANK1_REGNUM
:
2043 case SIM_SH_R4_BANK1_REGNUM
: case SIM_SH_R5_BANK1_REGNUM
:
2044 case SIM_SH_R6_BANK1_REGNUM
: case SIM_SH_R7_BANK1_REGNUM
:
2045 val
= (! SR_MD
|| ! SR_RB
2046 ? Rn_BANK (rn
- SIM_SH_R0_BANK1_REGNUM
)
2047 : saved_state
.asregs
.regs
[rn
- SIM_SH_R0_BANK1_REGNUM
]);
2049 case SIM_SH_R0_BANK_REGNUM
: case SIM_SH_R1_BANK_REGNUM
:
2050 case SIM_SH_R2_BANK_REGNUM
: case SIM_SH_R3_BANK_REGNUM
:
2051 case SIM_SH_R4_BANK_REGNUM
: case SIM_SH_R5_BANK_REGNUM
:
2052 case SIM_SH_R6_BANK_REGNUM
: case SIM_SH_R7_BANK_REGNUM
:
2053 val
= Rn_BANK (rn
- SIM_SH_R0_BANK_REGNUM
);
2058 * (int *) memory
= swap (val
);
2070 sim_stop_reason (sd
, reason
, sigrc
)
2072 enum sim_stop
*reason
;
2075 /* The SH simulator uses SIGQUIT to indicate that the program has
2076 exited, so we must check for it here and translate it to exit. */
2077 if (saved_state
.asregs
.exception
== SIGQUIT
)
2079 *reason
= sim_exited
;
2080 *sigrc
= saved_state
.asregs
.regs
[5];
2084 *reason
= sim_stopped
;
2085 *sigrc
= saved_state
.asregs
.exception
;
2090 sim_info (sd
, verbose
)
2094 double timetaken
= (double) saved_state
.asregs
.ticks
/ (double) now_persec ();
2095 double virttime
= saved_state
.asregs
.cycles
/ 36.0e6
;
2097 callback
->printf_filtered (callback
, "\n\n# instructions executed %10d\n",
2098 saved_state
.asregs
.insts
);
2099 callback
->printf_filtered (callback
, "# cycles %10d\n",
2100 saved_state
.asregs
.cycles
);
2101 callback
->printf_filtered (callback
, "# pipeline stalls %10d\n",
2102 saved_state
.asregs
.stalls
);
2103 callback
->printf_filtered (callback
, "# misaligned load/store %10d\n",
2104 saved_state
.asregs
.memstalls
);
2105 callback
->printf_filtered (callback
, "# real time taken %10.4f\n",
2107 callback
->printf_filtered (callback
, "# virtual time taken %10.4f\n",
2109 callback
->printf_filtered (callback
, "# profiling size %10d\n",
2111 callback
->printf_filtered (callback
, "# profiling frequency %10d\n",
2112 saved_state
.asregs
.profile
);
2113 callback
->printf_filtered (callback
, "# profile maxpc %10x\n",
2114 (1 << sim_profile_size
) << PROFILE_SHIFT
);
2118 callback
->printf_filtered (callback
, "# cycles/second %10d\n",
2119 (int) (saved_state
.asregs
.cycles
/ timetaken
));
2120 callback
->printf_filtered (callback
, "# simulation ratio %10.4f\n",
2121 virttime
/ timetaken
);
2129 saved_state
.asregs
.profile
= n
;
2133 sim_set_profile_size (n
)
2136 sim_profile_size
= n
;
2140 sim_open (kind
, cb
, abfd
, argv
)
2161 for (p
= argv
+ 1; *p
!= NULL
; ++p
)
2163 if (strcmp (*p
, "-E") == 0)
2168 /* FIXME: This doesn't use stderr, but then the rest of the
2169 file doesn't either. */
2170 callback
->printf_filtered (callback
, "Missing argument to `-E'.\n");
2173 target_little_endian
= strcmp (*p
, "big") != 0;
2176 else if (isdigit (**p
))
2177 parse_and_set_memory_size (*p
);
2180 if (abfd
!= NULL
&& ! endian_set
)
2181 target_little_endian
= ! bfd_big_endian (abfd
);
2186 for (i
= 4; (i
-= 2) >= 0; )
2187 mem_word
.s
[i
>> 1] = i
;
2188 global_endianw
= mem_word
.i
>> (target_little_endian
? 0 : 16) & 0xffff;
2190 for (i
= 4; --i
>= 0; )
2192 endianb
= mem_word
.i
>> (target_little_endian
? 0 : 24) & 0xff;
2194 /* fudge our descriptor for now */
2195 return (SIM_DESC
) 1;
2199 parse_and_set_memory_size (str
)
2204 n
= strtol (str
, NULL
, 10);
2205 if (n
> 0 && n
<= 24)
2206 sim_memory_size
= n
;
2208 callback
->printf_filtered (callback
, "Bad memory size %d; must be 1 to 24, inclusive\n", n
);
2212 sim_close (sd
, quitting
)
2220 sim_load (sd
, prog
, abfd
, from_tty
)
2226 extern bfd
*sim_load_file (); /* ??? Don't know where this should live. */
2229 prog_bfd
= sim_load_file (sd
, myname
, callback
, prog
, abfd
,
2230 sim_kind
== SIM_OPEN_DEBUG
,
2232 if (prog_bfd
== NULL
)
2235 bfd_close (prog_bfd
);
2240 sim_create_inferior (sd
, prog_bfd
, argv
, env
)
2242 struct _bfd
*prog_bfd
;
2246 /* Clear the registers. */
2247 memset (&saved_state
, 0,
2248 (char*)&saved_state
.asregs
.end_of_registers
- (char*)&saved_state
);
2251 if (prog_bfd
!= NULL
)
2252 saved_state
.asregs
.pc
= bfd_get_start_address (prog_bfd
);
2254 /* Record the program's arguments. */
2261 sim_do_command (sd
, cmd
)
2265 char *sms_cmd
= "set-memory-size";
2268 if (cmd
== NULL
|| *cmd
== '\0')
2273 cmdsize
= strlen (sms_cmd
);
2274 if (strncmp (cmd
, sms_cmd
, cmdsize
) == 0 && strchr (" \t", cmd
[cmdsize
]) != NULL
)
2276 parse_and_set_memory_size (cmd
+ cmdsize
+ 1);
2278 else if (strcmp (cmd
, "help") == 0)
2280 (callback
->printf_filtered
) (callback
, "List of SH simulator commands:\n\n");
2281 (callback
->printf_filtered
) (callback
, "set-memory-size <n> -- Set the number of address bits to use\n");
2282 (callback
->printf_filtered
) (callback
, "\n");
2286 (callback
->printf_filtered
) (callback
, "Error: \"%s\" is not a valid SH simulator command.\n", cmd
);
2291 sim_set_callbacks (p
)