home *** CD-ROM | disk | FTP | other *** search
/ Fresh Fish 9 / FreshFishVol9-CD2.bin / bbs / gnu / gdb-4.14-src.lha / gdb-4.14 / gdb / sun3-nat.c < prev    next >
Encoding:
C/C++ Source or Header  |  1993-11-02  |  4.2 KB  |  139 lines

  1. /* Host-dependent code for Sun-3 for GDB, the GNU debugger.
  2.    Copyright 1986, 1987, 1989, 1991, 1992 Free Software Foundation, Inc.
  3.  
  4. This file is part of GDB.
  5.  
  6. This program 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 of the License, or
  9. (at your option) any later version.
  10.  
  11. This program 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 this program; if not, write to the Free Software
  18. Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.  */
  19.  
  20. #include "defs.h"
  21. #include "inferior.h"
  22. #include "gdbcore.h"
  23.  
  24. #include <sys/ptrace.h>
  25. #define KERNEL        /* To get floating point reg definitions */
  26. #include <machine/reg.h>
  27.  
  28. void
  29. fetch_inferior_registers (regno)
  30.      int regno;
  31. {
  32.   struct regs inferior_registers;
  33. #ifdef FP0_REGNUM
  34.   struct fp_status inferior_fp_registers;
  35. #endif
  36.   extern char registers[];
  37.  
  38.   registers_fetched ();
  39.   
  40.   ptrace (PTRACE_GETREGS, inferior_pid,
  41.       (PTRACE_ARG3_TYPE) &inferior_registers);
  42. #ifdef FP0_REGNUM
  43.   ptrace (PTRACE_GETFPREGS, inferior_pid,
  44.       (PTRACE_ARG3_TYPE) &inferior_fp_registers);
  45. #endif 
  46.   
  47.   memcpy (registers, &inferior_registers, 16 * 4);
  48. #ifdef FP0_REGNUM
  49.   memcpy (®isters[REGISTER_BYTE (FP0_REGNUM)], &inferior_fp_registers,
  50.      sizeof inferior_fp_registers.fps_regs);
  51. #endif 
  52.   *(int *)®isters[REGISTER_BYTE (PS_REGNUM)] = inferior_registers.r_ps;
  53.   *(int *)®isters[REGISTER_BYTE (PC_REGNUM)] = inferior_registers.r_pc;
  54. #ifdef FP0_REGNUM
  55.   memcpy (®isters[REGISTER_BYTE (FPC_REGNUM)],
  56.      &inferior_fp_registers.fps_control,
  57.      sizeof inferior_fp_registers - sizeof inferior_fp_registers.fps_regs);
  58. #endif 
  59. }
  60.  
  61. /* Store our register values back into the inferior.
  62.    If REGNO is -1, do this for all registers.
  63.    Otherwise, REGNO specifies which register (so we can save time).  */
  64.  
  65. void
  66. store_inferior_registers (regno)
  67.      int regno;
  68. {
  69.   struct regs inferior_registers;
  70. #ifdef FP0_REGNUM
  71.   struct fp_status inferior_fp_registers;
  72. #endif
  73.   extern char registers[];
  74.  
  75.   memcpy (&inferior_registers, registers, 16 * 4);
  76. #ifdef FP0_REGNUM
  77.   memcpy (&inferior_fp_registers, ®isters[REGISTER_BYTE (FP0_REGNUM)],
  78.      sizeof inferior_fp_registers.fps_regs);
  79. #endif
  80.   inferior_registers.r_ps = *(int *)®isters[REGISTER_BYTE (PS_REGNUM)];
  81.   inferior_registers.r_pc = *(int *)®isters[REGISTER_BYTE (PC_REGNUM)];
  82.  
  83. #ifdef FP0_REGNUM
  84.   memcpy (&inferior_fp_registers.fps_control,
  85.      ®isters[REGISTER_BYTE (FPC_REGNUM)],
  86.      sizeof inferior_fp_registers - sizeof inferior_fp_registers.fps_regs);
  87. #endif
  88.  
  89.   ptrace (PTRACE_SETREGS, inferior_pid,
  90.       (PTRACE_ARG3_TYPE) &inferior_registers);
  91. #if FP0_REGNUM
  92.   ptrace (PTRACE_SETFPREGS, inferior_pid,
  93.       (PTRACE_ARG3_TYPE) &inferior_fp_registers);
  94. #endif
  95. }
  96.  
  97.  
  98. /* All of this stuff is only relevant if both host and target are sun3.  */
  99. /* Machine-dependent code for pulling registers out of a Sun-3 core file. */
  100.  
  101. void
  102. fetch_core_registers (core_reg_sect, core_reg_size, which, reg_addr)
  103.      char *core_reg_sect;
  104.      unsigned core_reg_size;
  105.      int which;
  106.      unsigned int reg_addr;    /* Unused in this version */
  107. {
  108.   extern char registers[];
  109.   struct regs *regs = (struct regs *) core_reg_sect;
  110.  
  111.   if (which == 0) {
  112.     if (core_reg_size < sizeof (struct regs))
  113.       error ("Can't find registers in core file");
  114.  
  115.     memcpy (registers, (char *)regs, 16 * 4);
  116.     supply_register (PS_REGNUM, (char *)®s->r_ps);
  117.     supply_register (PC_REGNUM, (char *)®s->r_pc);
  118.  
  119.   } else if (which == 2) {
  120.  
  121. #define fpustruct  ((struct fpu *) core_reg_sect)
  122.  
  123.     if (core_reg_size >= sizeof (struct fpu))
  124.       {
  125. #ifdef FP0_REGNUM
  126.     memcpy (®isters[REGISTER_BYTE (FP0_REGNUM)],
  127.           fpustruct->f_fpstatus.fps_regs,
  128.           sizeof fpustruct->f_fpstatus.fps_regs);
  129.     memcpy (®isters[REGISTER_BYTE (FPC_REGNUM)],
  130.           &fpustruct->f_fpstatus.fps_control,
  131.           sizeof fpustruct->f_fpstatus - 
  132.         sizeof fpustruct->f_fpstatus.fps_regs);
  133. #endif
  134.       }
  135.     else
  136.       fprintf_unfiltered (gdb_stderr, "Couldn't read float regs from core file\n");
  137.   }
  138. }
  139.