1 /* support routines for interpreted instructions
2 Copyright (C) 1992, 1993 Free Software Foundation, Inc.
4 This file is part of Z8KSIM
6 Z8KSIM is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2, or (at your option)
11 Z8KSIM is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with Z8KZIM; if not, write to the Free Software
18 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
33 #ifdef HAVE_SYS_TIMES_H
34 #include <sys/times.h>
36 #include <sys/types.h>
38 #include <sys/param.h>
39 #include "gdb/callback.h"
40 #include "gdb/remote-sim.h"
43 static int get_now
PARAMS ((void));
44 static int now_persec
PARAMS ((void));
45 static int put_long
PARAMS ((sim_state_type
* context
, int ptr
, int value
));
46 static int put_short
PARAMS ((sim_state_type
* context
, int ptr
, int value
));
53 #ifdef HAVE_SYS_TIMES_H
57 return b
.tms_utime
+ b
.tms_stime
;
70 /* #define LOG /* define this to print instruction use counts */
73 #define INLINE __inline__
79 /* This holds the entire cpu context */
80 static sim_state_type the_state
;
84 sim_state_type
*context
;
87 context
->exception
= SIM_BAD_INST
;
93 sim_state_type
*context
;
101 sim_state_type
*context
;
109 sim_state_type
*context
;
115 /* Table of bit counts for all byte values */
117 char the_parity
[256] =
119 0, 1, 1, 2, 1, 2, 2, 3, 1, 2, 2, 3, 2, 3, 3, 4, 1, 2, 2, 3, 2, 3, 3,
120 4, 2, 3, 3, 4, 3, 4, 4, 5, 1, 2, 2, 3, 2, 3, 3, 4, 2, 3, 3, 4, 3, 4,
121 4, 5, 2, 3, 3, 4, 3, 4, 4, 5, 3, 4, 4, 5, 4, 5, 5, 6, 1, 2, 2, 3, 2,
122 3, 3, 4, 2, 3, 3, 4, 3, 4, 4, 5, 2, 3, 3, 4, 3, 4, 4, 5, 3, 4, 4, 5,
123 4, 5, 5, 6, 2, 3, 3, 4, 3, 4, 4, 5, 3, 4, 4, 5, 4, 5, 5, 6, 3, 4, 4,
124 5, 4, 5, 5, 6, 4, 5, 5, 6, 5, 6, 6, 7, 1, 2, 2, 3, 2, 3, 3, 4, 2, 3,
125 3, 4, 3, 4, 4, 5, 2, 3, 3, 4, 3, 4, 4, 5, 3, 4, 4, 5, 4, 5, 5, 6, 2,
126 3, 3, 4, 3, 4, 4, 5, 3, 4, 4, 5, 4, 5, 5, 6, 3, 4, 4, 5, 4, 5, 5, 6,
127 4, 5, 5, 6, 5, 6, 6, 7, 2, 3, 3, 4, 3, 4, 4, 5, 3, 4, 4, 5, 4, 5, 5,
128 6, 3, 4, 4, 5, 4, 5, 5, 6, 4, 5, 5, 6, 5, 6, 6, 7, 3, 4, 4, 5, 4, 5,
129 5, 6, 4, 5, 5, 6, 5, 6, 6, 7, 4, 5, 5, 6, 5, 6, 6, 7, 5, 6, 6, 7, 6,
144 put_short (context
, ptr
, value
)
145 sim_state_type
*context
;
149 put_word_mem_da (context
, ptr
, value
);
154 put_long (context
, ptr
, value
)
155 sim_state_type
*context
;
160 put_long_mem_da (context
, ptr
, value
);
164 #define aptr(x) ((sitoptr(x)) + (char *)(context->memory))
167 static int arg_index
; /* Translate a z8k system call into a host system call */
169 support_call (context
, sc
)
170 sim_state_type
*context
;
178 int olderrno
= errno
;
183 args
[arg_index
++] = context
->regs
[0].word
<< 16 | context
->regs
[1].word
;
186 context
->exception
= SIM_DONE
;
191 ret
= close ((int) (args
[0]));
195 ret
= creat (aptr (args
[0]), args
[1]);
199 ret
= isatty (args
[0]);
203 ret
= open (aptr (args
[0]), args
[1], args
[2]);
207 ret
= lseek (args
[0], (off_t
) args
[1], args
[2]);
211 ret
= read (args
[0], aptr (args
[1]), args
[2]);
215 ret
= write (args
[0],aptr (args
[1]), args
[2]);
225 put_long_mem_da (context
,
236 struct stat host_stat
;
238 buf
= sitoptr (args
[1]);
239 ret
= fstat (fd
, &host_stat
);
240 buf
= put_short (context
, buf
, host_stat
.st_dev
);
241 buf
= put_short (context
, buf
, host_stat
.st_ino
);
242 /* FIXME: Isn't mode_t 4 bytes? */
243 buf
= put_short (context
, buf
, host_stat
.st_mode
);
244 buf
= put_short (context
, buf
, host_stat
.st_nlink
);
245 buf
= put_short (context
, buf
, host_stat
.st_uid
);
246 buf
= put_short (context
, buf
, host_stat
.st_uid
);
247 buf
= put_short (context
, buf
, host_stat
.st_rdev
);
248 buf
= put_long (context
, buf
, host_stat
.st_size
);
249 buf
= put_long (context
, buf
, host_stat
.st_atime
);
254 context
->exception
= SIM_BAD_SYSCALL
;
258 context
->regs
[2].word
= ret
;
259 context
->regs
[3].word
= retnext
;
260 context
->regs
[5].word
= errno
;
263 /* support for the stdcall calling convention */
264 context
->regs
[6].word
= retnext
;
265 context
->regs
[7].word
= ret
;
270 #undef get_word_mem_da
273 get_word_mem_da (context
, addr
)
274 sim_state_type
*context
;
277 return (get_byte_mem_da (context
, addr
) << 8) | (get_byte_mem_da (context
, addr
+ 1));
283 get_word_reg (context
, reg
) sim_state_type
287 return context
->regs
[reg
].word
;
296 tm_store_register (regno
, value
)
304 the_state
.sometimes_pc
= value
;
308 put_word_reg (&the_state
, regno
, value
);
333 tm_fetch_register (regno
, buf
)
341 swap_long (buf
, the_state
.cycles
);
344 swap_long (buf
, the_state
.insts
);
348 swap_long (buf
, the_state
.ticks
);
351 swap_long (buf
, the_state
.sometimes_pc
);
357 swap_long (buf
, get_long_reg (&the_state
, 14));
361 swap_long (buf
, get_word_reg (&the_state
, 15));
370 swap_long (buf
, get_long_reg
376 get_word_reg (&the_state
, 10));
383 get_word_reg (&the_state
, regno
));
392 int now
= get_now ();
397 extern int (*(sfop_table
[])) ();
398 extern int (*(bfop_table
[])) ();
399 int (*((*table
))) ();
400 sim_state_type
*context
= &the_state
;
404 context
->exception
= SIM_SINGLE_STEP
;
408 context
->exception
= 0;
411 pc
= context
->sometimes_pc
;
415 pc
= MAP_PHYSICAL_TO_LOGICAL (pc
);
425 word
= get_word_mem_da (context
, pc
);
426 p
= op_info_table
+ word
;
431 pc
= table
[p
->exec
] (context
, pc
, word
);
435 while (!context
->exception
);
439 context
->sometimes_pc
= MAP_LOGICAL_TO_PHYSICAL (pc
);
440 context
->ticks
+= get_now () - now
;
446 return the_state
.exception
;
453 double timetaken
= (double) x
->ticks
/ (double) now_persec ();
454 double virttime
= x
->cycles
/ 4.0e6
;
456 printf ("instructions executed : %9d\n", x
->insts
);
457 printf ("cycles counted : %9d \n", x
->cycles
);
458 printf ("cycles / inst : %9.1f \n", (double) x
->cycles
/ (double) x
->insts
);
459 printf ("virtual time taked (at 4 Mhz) : %9.1f \n", virttime
);
460 printf ("real time taken : %9.1f \n", timetaken
);
464 printf ("virtual instructions per second : %9.1f\n", x
->insts
/ timetaken
);
465 printf ("emulation speed : %9.1f%%\n", virttime
/ timetaken
* 100.0);
471 for (i
= 0; quick
[i
]; i
++)
473 log
[quick
[i
]] += 100000;
477 for (i
= 0; i
< 64 * 1024; i
++)
481 printf (" /*%7d*/ 0x%x,\n", log
[i
], i
);
497 for (r
= 0; r
< 16; r
++)
502 printf ("=%04x ", get_word_reg (&the_state
,
504 for (m
= -4; m
< 8; m
++)
509 get_word_mem_da (&the_state
, (0xfffe & get_word_reg (&the_state
, r
)) + m
* 2));
515 printf ("%9d %9d %08x ", the_state
.cycles
,
516 the_state
.insts
, the_state
.sometimes_pc
);
518 for (i
= 0; i
< 6; i
++)
520 buffer
[i
] = get_byte_mem_da (&the_state
,
521 the_state
.sometimes_pc
+ i
);
524 print_insn_z8001 (the_state
.sometimes_pc
, buffer
, stdout
);
528 if (the_state
.exception
!= SIM_SINGLE_STEP
)
544 the_state
.exception
= x
;
552 return sim_read_byte (&the_state
, x
);
560 sim_write_byte (&the_state
, x
, y
);
563 #define SIGN(x) ((x) & MASK)
564 normal_flags_32(context
,d
,sa
,sb
,sub
)
565 sim_state_type
*context
;
573 context
->broken_flags
= 0;
579 PSW_OVERFLOW
= (SIGN(sa
) != SIGN(sb
)) && (SIGN(d
) == SIGN(sb
));
581 PSW_OVERFLOW
= (SIGN(sa
) == SIGN(sb
)) && (SIGN(d
) != SIGN(sb
));
583 PSW_SIGN
= ((int)d
) <0;
587 normal_flags_16(context
,d
,sal
,sbl
,sub
)
588 sim_state_type
*context
;
592 unsigned short int sub
;
594 unsigned short sa
= sal
;
595 unsigned short sb
= sbl
;
598 context
->broken_flags
= 0;
600 PSW_CARRY
= sal
< sbl
;
602 PSW_CARRY
= (d
& 0x10000) != 0;
605 PSW_OVERFLOW
= (SIGN(sa
) != SIGN(sb
)) && (SIGN(d
) == SIGN(sb
));
607 PSW_OVERFLOW
= (SIGN(sa
) == SIGN(sb
)) && (SIGN(d
) != SIGN(sb
));
609 PSW_SIGN
= ((short int)d
) <0;
610 PSW_ZERO
= ((short)d
) == 0;
613 normal_flags_8(context
,d
,sa
,sb
,sub
)
614 sim_state_type
*context
;
622 context
->broken_flags
= 0;
628 PSW_OVERFLOW
= (SIGN(sa
) != SIGN(sb
)) && (SIGN(d
) == SIGN(sb
));
630 PSW_OVERFLOW
= (SIGN(sa
) == SIGN(sb
)) && (SIGN(d
) != SIGN(sb
));
631 PSW_SIGN
= ((char)d
) <0;
637 is_cond_true (context
, c
)
638 sim_state_type
*context
;
648 return (PSW_ZERO
| (PSW_SIGN
^ PSW_OVERFLOW
)) & 1; /*LE */
650 return (~(PSW_ZERO
| (PSW_SIGN
^ PSW_OVERFLOW
))) & 1; /*GT */
652 return (PSW_SIGN
& 1); /* sign */
654 return (~(PSW_SIGN
)) & 1; /* not sign */
656 return ((PSW_CARRY
| PSW_ZERO
) & 1); /* ule*/
658 return ((~(PSW_CARRY
| PSW_ZERO
)) & 1); /* ugt */
660 return (PSW_OVERFLOW
& 1);/* overflow */
662 return (~(PSW_OVERFLOW
)) & 1; /* not overflow */
664 return (PSW_SIGN
^ PSW_OVERFLOW
) & 1; /* LT */
666 return (~(PSW_SIGN
^ PSW_OVERFLOW
)) & 1; /* GE */
668 return (PSW_ZERO
) & 1; /* zero */
670 return ((~PSW_ZERO
) & 1); /* not zero */
672 return (PSW_CARRY
) & 1; /* carry */
674 return (~PSW_CARRY
) & 1; /* not carry */
682 sim_state_type
*context
;
688 /* We can calculate what the flags would have been by
689 looking at the src and dst and size of the operation */
691 if (context
->broken_flags
)
701 /* see if we can short-cut the nasty flag calcs */
703 switch (size
= context
->size
)
709 srca
= (char) (context
->srca
);
710 srcb
= (char) (context
->srcb
);
711 dst
= (char) (context
->dst
);
715 srca
= (short) (context
->srca
);
716 srcb
= (short) (context
->srcb
);
717 dst
= (short) (context
->dst
);
721 srca
= (long) (context
->srca
);
722 srcb
= (long) (context
->srcb
);
723 dst
= (long) (context
->dst
);
742 if (is_cond_true (context
, c
) != ans
)
750 if (is_cond_true (context
, c
) != ans
)
758 if (is_cond_true (context
, c
) != ans
)
766 if (is_cond_true (context
, c
) != ans
)
774 /* Can't fake it, we'll have to work out the flags the
777 makeflags (context
, mask
);
780 /* don't know how to fake a test, inspect the flags
783 return is_cond_true (context
, c
);
This page took 0.045768 seconds and 4 git commands to generate.