home *** CD-ROM | disk | FTP | other *** search
/ Fresh Fish 9 / FreshFishVol9-CD2.bin / bbs / gnu / gdb-4.14-src.lha / gdb-4.14 / gdb / mipsv4-nat.c < prev    next >
Encoding:
C/C++ Source or Header  |  1994-04-08  |  4.0 KB  |  149 lines

  1. /* Native support for MIPS running SVR4, for GDB.
  2.    Copyright 1994 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. #include "target.h"
  24.  
  25. #include <sys/time.h>
  26. #include <sys/procfs.h>
  27. #include <setjmp.h>        /* For JB_XXX.  */
  28.  
  29. /* Size of elements in jmpbuf */
  30.  
  31. #define JB_ELEMENT_SIZE 4
  32.  
  33. /*
  34.  * See the comment in m68k-tdep.c regarding the utility of these functions.
  35.  *
  36.  * These definitions are from the MIPS SVR4 ABI, so they may work for
  37.  * any MIPS SVR4 target.
  38.  */
  39.  
  40. void 
  41. supply_gregset (gregsetp)
  42.      gregset_t *gregsetp;
  43. {
  44.   register int regi;
  45.   register greg_t *regp = &(*gregsetp)[0];
  46.  
  47.   for(regi = 0; regi <= CXT_RA; regi++)
  48.     supply_register (regi, (char *)(regp + regi));
  49.  
  50.   supply_register (PC_REGNUM, (char *)(regp + CXT_EPC));
  51.   supply_register (HI_REGNUM, (char *)(regp + CXT_MDHI));
  52.   supply_register (LO_REGNUM, (char *)(regp + CXT_MDLO));
  53.   supply_register (CAUSE_REGNUM, (char *)(regp + CXT_CAUSE));
  54. }
  55.  
  56. void
  57. fill_gregset (gregsetp, regno)
  58.      gregset_t *gregsetp;
  59.      int regno;
  60. {
  61.   int regi;
  62.   register greg_t *regp = &(*gregsetp)[0];
  63.  
  64.   for (regi = 0; regi <= 32; regi++)
  65.     if ((regno == -1) || (regno == regi))
  66.       *(regp + regi) = *(greg_t *) ®isters[REGISTER_BYTE (regi)];
  67.  
  68.   if ((regno == -1) || (regno == PC_REGNUM))
  69.     *(regp + CXT_EPC) = *(greg_t *) ®isters[REGISTER_BYTE (PC_REGNUM)];
  70.  
  71.   if ((regno == -1) || (regno == CAUSE_REGNUM))
  72.     *(regp + CXT_CAUSE) = *(greg_t *) ®isters[REGISTER_BYTE (PS_REGNUM)];
  73.  
  74.   if ((regno == -1) || (regno == HI_REGNUM))
  75.     *(regp + CXT_MDHI) = *(greg_t *) ®isters[REGISTER_BYTE (HI_REGNUM)];
  76.  
  77.   if ((regno == -1) || (regno == LO_REGNUM))
  78.     *(regp + CXT_MDLO) = *(greg_t *) ®isters[REGISTER_BYTE (LO_REGNUM)];
  79. }
  80.  
  81. /*
  82.  * Now we do the same thing for floating-point registers.
  83.  * We don't bother to condition on FP0_REGNUM since any
  84.  * reasonable MIPS configuration has an R3010 in it.
  85.  *
  86.  * Again, see the comments in m68k-tdep.c.
  87.  */
  88.  
  89. void
  90. supply_fpregset (fpregsetp)
  91.      fpregset_t *fpregsetp;
  92. {
  93.   register int regi;
  94.  
  95.   for (regi = 0; regi < 32; regi++)
  96.     supply_register (FP0_REGNUM + regi,
  97.              (char *)&fpregsetp->fp_r.fp_regs[regi]);
  98.  
  99.   supply_register (FCRCS_REGNUM, (char *)&fpregsetp->fp_csr);
  100.  
  101.   /* FIXME: how can we supply FCRIR_REGNUM?  The ABI doesn't tell us. */
  102. }
  103.  
  104. void
  105. fill_fpregset (fpregsetp, regno)
  106.      fpregset_t *fpregsetp;
  107.      int regno;
  108. {
  109.   int regi;
  110.   char *from, *to;
  111.  
  112.   for (regi = FP0_REGNUM; regi < FP0_REGNUM + 32; regi++)
  113.     {
  114.       if ((regno == -1) || (regno == regi))
  115.     {
  116.       from = (char *) ®isters[REGISTER_BYTE (regi)];
  117.       to = (char *) &(fpregsetp->fp_r.fp_regs[regi - FP0_REGNUM]);
  118.       memcpy(to, from, REGISTER_RAW_SIZE (regi));
  119.     }
  120.     }
  121.  
  122.   if ((regno == -1) || (regno == FCRCS_REGNUM))
  123.     fpregsetp->fp_csr = *(unsigned *) ®isters[REGISTER_BYTE(FCRCS_REGNUM)];
  124. }
  125.  
  126.  
  127. /* Figure out where the longjmp will land.
  128.    We expect the first arg to be a pointer to the jmp_buf structure from which
  129.    we extract the pc (_JB_PC) that we will land at.  The pc is copied into PC.
  130.    This routine returns true on success. */
  131.  
  132. int
  133. get_longjmp_target (pc)
  134.      CORE_ADDR *pc;
  135. {
  136.   char buf[TARGET_PTR_BIT / TARGET_CHAR_BIT];
  137.   CORE_ADDR jb_addr;
  138.  
  139.   jb_addr = read_register (A0_REGNUM);
  140.  
  141.   if (target_read_memory (jb_addr + _JB_PC * JB_ELEMENT_SIZE, buf,
  142.               TARGET_PTR_BIT / TARGET_CHAR_BIT))
  143.     return 0;
  144.  
  145.   *pc = extract_address (buf, TARGET_PTR_BIT / TARGET_CHAR_BIT);
  146.  
  147.   return 1;
  148. }
  149.