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

  1. /* Intel 386 native support for SYSV systems (pre-SVR4).
  2.    Copyright (C) 1988, 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 "frame.h"
  22. #include "inferior.h"
  23. #include "language.h"
  24. #include "gdbcore.h"
  25.  
  26. #ifdef USG
  27. #include <sys/types.h>
  28. #endif
  29.  
  30. #include <sys/param.h>
  31. #include <sys/dir.h>
  32. #include <signal.h>
  33. #include <sys/user.h>
  34. #include <sys/ioctl.h>
  35. #include <fcntl.h>
  36.  
  37. #include <sys/file.h>
  38. #include <sys/stat.h>
  39.  
  40. #ifndef NO_SYS_REG_H
  41. #include <sys/reg.h>
  42. #endif
  43.  
  44. #include "ieee-float.h"
  45.  
  46. #include "target.h"
  47.  
  48. extern struct ext_format ext_format_i387;
  49.  
  50. /* this table must line up with REGISTER_NAMES in tm-i386v.h */
  51. /* symbols like 'EAX' come from <sys/reg.h> */
  52. static int regmap[] = 
  53. {
  54.   EAX, ECX, EDX, EBX,
  55.   UESP, EBP, ESI, EDI,
  56.   EIP, EFL, CS, SS,
  57.   DS, ES, FS, GS,
  58. };
  59.  
  60. /* blockend is the value of u.u_ar0, and points to the
  61.  * place where GS is stored
  62.  */
  63.  
  64. int
  65. i386_register_u_addr (blockend, regnum)
  66.      int blockend;
  67.      int regnum;
  68. {
  69. #if 0
  70.   /* this will be needed if fp registers are reinstated */
  71.   /* for now, you can look at them with 'info float'
  72.    * sys5 wont let you change them with ptrace anyway
  73.    */
  74.   if (regnum >= FP0_REGNUM && regnum <= FP7_REGNUM) 
  75.     {
  76.       int ubase, fpstate;
  77.       struct user u;
  78.       ubase = blockend + 4 * (SS + 1) - KSTKSZ;
  79.       fpstate = ubase + ((char *)&u.u_fpstate - (char *)&u);
  80.       return (fpstate + 0x1c + 10 * (regnum - FP0_REGNUM));
  81.     } 
  82.   else
  83. #endif
  84.     return (blockend + 4 * regmap[regnum]);
  85.   
  86. }
  87.  
  88. #if 0
  89. /* using FLOAT_INFO as is would be a problem.  FLOAT_INFO is called
  90.    via a command xxx and eventually calls ptrace without ever having
  91.    traversed the target vector.  This would be terribly impolite
  92.    behaviour for a sun4 hosted remote gdb.
  93.  
  94.    A fix might be to move this code into the "info registers" command.
  95.    rich@cygnus.com 15 Sept 92. */
  96. i386_float_info ()
  97. {
  98.   struct user u; /* just for address computations */
  99.   int i;
  100.   /* fpstate defined in <sys/user.h> */
  101.   struct fpstate *fpstatep;
  102.   char buf[sizeof (struct fpstate) + 2 * sizeof (int)];
  103.   unsigned int uaddr;
  104.   char fpvalid = 0;
  105.   unsigned int rounded_addr;
  106.   unsigned int rounded_size;
  107.   extern int corechan;
  108.   int skip;
  109.   
  110.   uaddr = (char *)&u.u_fpvalid - (char *)&u;
  111.   if (target_has_execution)
  112.     {
  113.       unsigned int data;
  114.       unsigned int mask;
  115.       
  116.       rounded_addr = uaddr & -sizeof (int);
  117.       data = ptrace (3, inferior_pid, (PTRACE_ARG3_TYPE) rounded_addr, 0);
  118.       mask = 0xff << ((uaddr - rounded_addr) * 8);
  119.       
  120.       fpvalid = ((data & mask) != 0);
  121.     } 
  122. #if 0
  123.   else 
  124.     {
  125.       if (lseek (corechan, uaddr, 0) < 0)
  126.     perror ("seek on core file");
  127.       if (myread (corechan, &fpvalid, 1) < 0) 
  128.     perror ("read on core file");
  129.       
  130.     }
  131. #endif    /* no core support yet */
  132.   
  133.   if (fpvalid == 0) 
  134.     {
  135.       printf ("no floating point status saved\n");
  136.       return;
  137.     }
  138.   
  139.   uaddr = (char *)&U_FPSTATE(u) - (char *)&u;
  140.   if (target_has_execution)
  141.     {
  142.       int *ip;
  143.       
  144.       rounded_addr = uaddr & -sizeof (int);
  145.       rounded_size = (((uaddr + sizeof (struct fpstate)) - uaddr) +
  146.               sizeof (int) - 1) / sizeof (int);
  147.       skip = uaddr - rounded_addr;
  148.       
  149.       ip = (int *)buf;
  150.       for (i = 0; i < rounded_size; i++) 
  151.     {
  152.       *ip++ = ptrace (3, inferior_pid, (PTRACE_ARG3_TYPE) rounded_addr, 0);
  153.       rounded_addr += sizeof (int);
  154.     }
  155.     } 
  156. #if 0
  157.   else 
  158.     {
  159.       if (lseek (corechan, uaddr, 0) < 0)
  160.     perror_with_name ("seek on core file");
  161.       if (myread (corechan, buf, sizeof (struct fpstate)) < 0) 
  162.     perror_with_name ("read from core file");
  163.       skip = 0;
  164.     }
  165. #endif    /* 0 */ 
  166.  
  167.   fpstatep = (struct fpstate *)(buf + skip);
  168.   print_387_status (fpstatep->status, (struct env387 *)fpstatep->state);
  169. }
  170.  
  171. #endif /* never */
  172.