home *** CD-ROM | disk | FTP | other *** search
/ Fresh Fish 9 / FreshFishVol9-CD2.bin / bbs / gnu / gdb-4.14-src.lha / gdb-4.14 / sim / z8k / iface.c < prev    next >
Encoding:
C/C++ Source or Header  |  1994-05-19  |  3.2 KB  |  178 lines

  1. /* gdb->simulator interface.
  2.    Copyright (C) 1992, 1993, 1994 Free Software Foundation, Inc.
  3.  
  4. This file is part of Z8KSIM
  5.  
  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)
  9. any later version.
  10.  
  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.
  15.  
  16. You should have received a copy of the GNU General Public License
  17. along with Z8KSIM; see the file COPYING.  If not, write to
  18. the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.  */
  19.  
  20. #include <ansidecl.h>
  21. #include "sim.h"
  22. #include "tm.h"
  23. #include "signal.h"
  24. #include "remote-sim.h"
  25.  
  26. void
  27. sim_store_register (regno, value)
  28.      int regno;
  29.      unsigned char *value;
  30. {
  31.   /* FIXME: Review the computation of regval.  */
  32.   int regval = (value[0] << 24) | (value[1] << 16) | (value[2] << 8) | value[3];
  33.  
  34.   tm_store_register (regno, regval);
  35. }
  36.  
  37. void
  38. sim_fetch_register (regno, buf)
  39.      int regno;
  40.      unsigned char *buf;
  41. {
  42.   tm_fetch_register (regno, buf);
  43. }
  44.  
  45. int
  46. sim_write (where, what, howmuch)
  47.      SIM_ADDR where;
  48.      unsigned char *what;
  49.      int howmuch;
  50. {
  51.   int i;
  52.  
  53.   for (i = 0; i < howmuch; i++)
  54.     tm_write_byte (where + i, what[i]);
  55.   return howmuch;
  56. }
  57.  
  58. int
  59. sim_read (where, what, howmuch)
  60.      SIM_ADDR where;
  61.      unsigned char *what;
  62.      int howmuch;
  63. {
  64.   int i;
  65.  
  66.   for (i = 0; i < howmuch; i++)
  67.     what[i] = tm_read_byte (where + i);
  68.   return howmuch;
  69. }
  70.  
  71. static void 
  72. control_c (sig, code, scp, addr)
  73.      int sig;
  74.      int code;
  75.      char *scp;
  76.      char *addr;
  77. {
  78.   tm_exception (SIM_INTERRUPT);
  79. }
  80.  
  81. void
  82. sim_resume (step, sig)
  83.      int step;
  84.      int sig;
  85. {
  86.   void (*prev) ();
  87.  
  88.   prev = signal (SIGINT, control_c);
  89.   tm_resume (step);
  90.   signal (SIGINT, prev);
  91. }
  92.  
  93. void
  94. sim_stop_reason (reason, sigrc)
  95.      enum sim_stop *reason;
  96.      int *sigrc;
  97. {
  98.   switch (tm_signal ())
  99.     {
  100.     case SIM_DIV_ZERO:
  101.       *sigrc = SIGFPE;
  102.       break;
  103.     case SIM_INTERRUPT:
  104.       *sigrc = SIGINT;
  105.       break;
  106.     case SIM_BAD_INST:
  107.       *sigrc = SIGILL;
  108.       break;
  109.     case SIM_BREAKPOINT:
  110.       *sigrc = SIGTRAP;
  111.       break;
  112.     case SIM_SINGLE_STEP:
  113.       *sigrc = SIGTRAP;
  114.       break;
  115.     case SIM_BAD_SYSCALL:
  116.       *sigrc = SIGSYS;
  117.       break;
  118.     case SIM_BAD_ALIGN:
  119.       *sigrc = SIGSEGV;
  120.       break;
  121.     case SIM_DONE:
  122.       *sigrc = 1;
  123.       *reason = sim_exited;
  124.       return;
  125.     default:
  126.       abort ();
  127.     }
  128.   *reason = sim_stopped;
  129. }
  130.  
  131. void
  132. sim_info (verbose)
  133.      int verbose;
  134. {
  135.   sim_state_type x;
  136.  
  137.   tm_state (&x);
  138.   tm_info_print (&x);
  139. }
  140.  
  141. void
  142. sim_open (args)
  143.      char *args;
  144. {
  145.   /* nothing to do */
  146. }
  147.  
  148. void
  149. sim_close (quitting)
  150.      int quitting;
  151. {
  152.   /* nothing to do */
  153. }
  154.  
  155. int
  156. sim_load (prog, from_tty)
  157.      char *prog;
  158.      int from_tty;
  159. {
  160.   /* Return non-zero so gdb will handle it.  */
  161.   return 1;
  162. }
  163.  
  164. void
  165. sim_create_inferior (start_address, argv, env)
  166.      SIM_ADDR start_address;
  167.      char **argv;
  168.      char **env;
  169. {
  170.   tm_store_register (REG_PC, start_address);
  171. }
  172.  
  173. void
  174. sim_kill ()
  175. {
  176.   /* nothing to do */
  177. }
  178.