home *** CD-ROM | disk | FTP | other *** search
/ InfoMagic Source Code 1993 July / THE_SOURCE_CODE_CD_ROM.iso / gnu / gdb-4.9 / sim / z8k / iface.c < prev    next >
Encoding:
C/C++ Source or Header  |  1993-05-12  |  2.6 KB  |  154 lines

  1. /* gdb->simulator interface.
  2.    Copyright (C) 1992, 1993 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 "../include/wait.h"
  25.  
  26. int
  27. sim_clear_breakpoints ()
  28. {
  29.   return 1;
  30. }
  31.  
  32. void
  33. sim_set_pc (addr)
  34.      int addr;
  35. {
  36.   tm_store_register (REG_PC, addr);
  37. }
  38.  
  39. void
  40. sim_store_register (regno, value)
  41.      int regno;
  42.      int value;
  43. {
  44.   tm_store_register (regno, value);
  45. }
  46.  
  47. int
  48. sim_fetch_register (regno, buf)
  49.      int regno;
  50.      char *buf;
  51. {
  52.   tm_fetch_register (regno, buf);
  53.   return 1;
  54. }
  55.  
  56. void
  57. sim_write (where, what, howmuch)
  58.      long int where;
  59.      char *what;
  60.      int howmuch;
  61. {
  62.   int i;
  63.  
  64.   for (i = 0; i < howmuch; i++)
  65.     tm_write_byte (where + i, what[i]);
  66. }
  67.  
  68. void
  69. sim_read (where, what, howmuch)
  70.      long int where;
  71.      char *what;
  72.      int howmuch;
  73. {
  74.   int i;
  75.  
  76.   for (i = 0; i < howmuch; i++)
  77.     what[i] = tm_read_byte (where + i);
  78.  
  79. }
  80.  
  81. static
  82. void 
  83. control_c (sig, code, scp, addr)
  84.      int sig;
  85.      int code;
  86.      char *scp;
  87.      char *addr;
  88. {
  89.   tm_exception (SIM_INTERRUPT);
  90. }
  91.  
  92. void
  93. sim_resume (step, sig)
  94.      int step;
  95.      int sig;
  96. {
  97.   void (*prev) ();
  98.  
  99.   prev = signal (SIGINT, control_c);
  100.   tm_resume (step);
  101.   signal (SIGINT, prev);
  102. }
  103.  
  104. int
  105. sim_stop_signal ()
  106. {
  107.   int a;
  108.  
  109.   switch (tm_signal ())
  110.     {
  111.     case SIM_DIV_ZERO:
  112.       WSETSTOP (a, SIGFPE);
  113.       break;
  114.     case SIM_INTERRUPT:
  115.       WSETSTOP (a, SIGINT);
  116.       break;
  117.     case SIM_BAD_INST:
  118.       WSETSTOP (a, SIGILL);
  119.       break;
  120.     case SIM_BREAKPOINT:
  121.       WSETSTOP (a, SIGTRAP);
  122.       break;
  123.     case SIM_SINGLE_STEP:
  124.       WSETSTOP (a, SIGTRAP);
  125.       break;
  126.     case SIM_BAD_SYSCALL:
  127.       WSETSTOP (a, SIGSYS);
  128.       break;
  129.     case SIM_BAD_ALIGN:
  130.       WSETSTOP (a, SIGSEGV);
  131.       break;
  132.     case SIM_DONE:
  133.       WSETEXIT (a, 1);
  134.       break;
  135.     default:
  136.       abort ();
  137.     }
  138.   return a;
  139. }
  140.  
  141. void
  142. sim_info (x)
  143.      sim_state_type *x;
  144. {
  145.   tm_state (x);
  146. }
  147.  
  148. void
  149. sim_info_print (x)
  150.      sim_state_type *x;
  151. {
  152.   tm_info_print (x);
  153. }
  154.