OpenCores
URL https://opencores.org/ocsvn/or1k/or1k/trunk

Subversion Repositories or1k

[/] [or1k/] [trunk/] [gdb-5.0/] [gdb/] [ptx4-nat.c] - Diff between revs 105 and 1765

Go to most recent revision | Only display areas with differences | Details | Blame | View Log

Rev 105 Rev 1765
/* Native-dependent code for ptx 4.0
/* Native-dependent code for ptx 4.0
   Copyright 1988, 1989, 1991, 1992 Free Software Foundation, Inc.
   Copyright 1988, 1989, 1991, 1992 Free Software Foundation, Inc.
 
 
   This file is part of GDB.
   This file is part of GDB.
 
 
   This program is free software; you can redistribute it and/or modify
   This program is free software; you can redistribute it and/or modify
   it under the terms of the GNU General Public License as published by
   it under the terms of the GNU General Public License as published by
   the Free Software Foundation; either version 2 of the License, or
   the Free Software Foundation; either version 2 of the License, or
   (at your option) any later version.
   (at your option) any later version.
 
 
   This program is distributed in the hope that it will be useful,
   This program is distributed in the hope that it will be useful,
   but WITHOUT ANY WARRANTY; without even the implied warranty of
   but WITHOUT ANY WARRANTY; without even the implied warranty of
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   GNU General Public License for more details.
   GNU General Public License for more details.
 
 
   You should have received a copy of the GNU General Public License
   You should have received a copy of the GNU General Public License
   along with this program; if not, write to the Free Software
   along with this program; if not, write to the Free Software
   Foundation, Inc., 59 Temple Place - Suite 330,
   Foundation, Inc., 59 Temple Place - Suite 330,
   Boston, MA 02111-1307, USA.  */
   Boston, MA 02111-1307, USA.  */
 
 
#include "defs.h"
#include "defs.h"
#include "inferior.h"
#include "inferior.h"
#include "gdbcore.h"
#include "gdbcore.h"
#include <sys/procfs.h>
#include <sys/procfs.h>
#include <sys/ptrace.h>
#include <sys/ptrace.h>
#include <sys/param.h>
#include <sys/param.h>
#include <fcntl.h>
#include <fcntl.h>
 
 
/*  Given a pointer to a general register set in /proc format (gregset_t *),
/*  Given a pointer to a general register set in /proc format (gregset_t *),
   unpack the register contents and supply them as gdb's idea of the current
   unpack the register contents and supply them as gdb's idea of the current
   register values. */
   register values. */
 
 
void
void
supply_gregset (gregsetp)
supply_gregset (gregsetp)
     gregset_t *gregsetp;
     gregset_t *gregsetp;
{
{
  supply_register (EAX_REGNUM, (char *) &(*gregsetp)[EAX]);
  supply_register (EAX_REGNUM, (char *) &(*gregsetp)[EAX]);
  supply_register (EDX_REGNUM, (char *) &(*gregsetp)[EDX]);
  supply_register (EDX_REGNUM, (char *) &(*gregsetp)[EDX]);
  supply_register (ECX_REGNUM, (char *) &(*gregsetp)[ECX]);
  supply_register (ECX_REGNUM, (char *) &(*gregsetp)[ECX]);
  supply_register (EBX_REGNUM, (char *) &(*gregsetp)[EBX]);
  supply_register (EBX_REGNUM, (char *) &(*gregsetp)[EBX]);
  supply_register (ESI_REGNUM, (char *) &(*gregsetp)[ESI]);
  supply_register (ESI_REGNUM, (char *) &(*gregsetp)[ESI]);
  supply_register (EDI_REGNUM, (char *) &(*gregsetp)[EDI]);
  supply_register (EDI_REGNUM, (char *) &(*gregsetp)[EDI]);
  supply_register (ESP_REGNUM, (char *) &(*gregsetp)[UESP]);
  supply_register (ESP_REGNUM, (char *) &(*gregsetp)[UESP]);
  supply_register (EBP_REGNUM, (char *) &(*gregsetp)[EBP]);
  supply_register (EBP_REGNUM, (char *) &(*gregsetp)[EBP]);
  supply_register (EIP_REGNUM, (char *) &(*gregsetp)[EIP]);
  supply_register (EIP_REGNUM, (char *) &(*gregsetp)[EIP]);
  supply_register (EFLAGS_REGNUM, (char *) &(*gregsetp)[EFL]);
  supply_register (EFLAGS_REGNUM, (char *) &(*gregsetp)[EFL]);
}
}
 
 
void
void
fill_gregset (gregsetp, regno)
fill_gregset (gregsetp, regno)
     gregset_t *gregsetp;
     gregset_t *gregsetp;
     int regno;
     int regno;
{
{
  int regi;
  int regi;
 
 
  for (regi = 0; regi < NUM_REGS; regi++)
  for (regi = 0; regi < NUM_REGS; regi++)
    {
    {
      if ((regno == -1) || (regno == regi))
      if ((regno == -1) || (regno == regi))
        {
        {
          (*gregsetp)[regi] = *(greg_t *) & registers[REGISTER_BYTE (regi)];
          (*gregsetp)[regi] = *(greg_t *) & registers[REGISTER_BYTE (regi)];
        }
        }
    }
    }
}
}
 
 
#if defined (FP0_REGNUM)
#if defined (FP0_REGNUM)
 
 
/*  Given a pointer to a floating point register set in /proc format
/*  Given a pointer to a floating point register set in /proc format
   (fpregset_t *), unpack the register contents and supply them as gdb's
   (fpregset_t *), unpack the register contents and supply them as gdb's
   idea of the current floating point register values. */
   idea of the current floating point register values. */
 
 
void
void
supply_fpregset (fpregsetp)
supply_fpregset (fpregsetp)
     fpregset_t *fpregsetp;
     fpregset_t *fpregsetp;
{
{
  supply_fpu_registers ((struct fpusave *) &fpregsetp->fp_reg_set);
  supply_fpu_registers ((struct fpusave *) &fpregsetp->fp_reg_set);
  supply_fpa_registers ((struct fpasave *) &fpregsetp->f_wregs);
  supply_fpa_registers ((struct fpasave *) &fpregsetp->f_wregs);
}
}
 
 
/*  Given a pointer to a floating point register set in /proc format
/*  Given a pointer to a floating point register set in /proc format
   (fpregset_t *), update the register specified by REGNO from gdb's idea
   (fpregset_t *), update the register specified by REGNO from gdb's idea
   of the current floating point register set.  If REGNO is -1, update
   of the current floating point register set.  If REGNO is -1, update
   them all. */
   them all. */
 
 
void
void
fill_fpregset (fpregsetp, regno)
fill_fpregset (fpregsetp, regno)
     fpregset_t *fpregsetp;
     fpregset_t *fpregsetp;
     int regno;
     int regno;
{
{
  int regi;
  int regi;
  char *to;
  char *to;
  char *from;
  char *from;
 
 
  /* FIXME: see m68k-tdep.c for an example, for the m68k. */
  /* FIXME: see m68k-tdep.c for an example, for the m68k. */
}
}
 
 
#endif /* defined (FP0_REGNUM) */
#endif /* defined (FP0_REGNUM) */
 
 
/*
/*
 * This doesn't quite do the same thing as the procfs.c version, but give
 * This doesn't quite do the same thing as the procfs.c version, but give
 * it the same name so we don't have to put an ifdef in solib.c.
 * it the same name so we don't have to put an ifdef in solib.c.
 */
 */
/* this could use elf_interpreter() from elfread.c */
/* this could use elf_interpreter() from elfread.c */
int
int
proc_iterate_over_mappings (func)
proc_iterate_over_mappings (func)
     int (*func) PARAMS ((int, CORE_ADDR));
     int (*func) PARAMS ((int, CORE_ADDR));
{
{
  vaddr_t curseg, memptr;
  vaddr_t curseg, memptr;
  pt_vseg_t pv;
  pt_vseg_t pv;
  int rv, cmperr;
  int rv, cmperr;
  sec_ptr interp_sec;
  sec_ptr interp_sec;
  char *interp_content;
  char *interp_content;
  int interp_fd, funcstat;
  int interp_fd, funcstat;
  unsigned int size;
  unsigned int size;
  char buf1[NBPG], buf2[NBPG];
  char buf1[NBPG], buf2[NBPG];
 
 
  /*
  /*
   * The following is really vile.  We can get the name of the
   * The following is really vile.  We can get the name of the
   * shared library from the exec_bfd, and we can get a list of
   * shared library from the exec_bfd, and we can get a list of
   * each virtual memory segment, but there is no simple way to
   * each virtual memory segment, but there is no simple way to
   * find the mapped segment from the shared library (ala
   * find the mapped segment from the shared library (ala
   * procfs's PIOCOPENMEM).  As a pretty nasty kludge, we
   * procfs's PIOCOPENMEM).  As a pretty nasty kludge, we
   * compare the virtual memory segment to the contents of the
   * compare the virtual memory segment to the contents of the
   * .interp file.  If they match, we assume that we've got the
   * .interp file.  If they match, we assume that we've got the
   * right one.
   * right one.
   */
   */
 
 
  /*
  /*
   * TODO: for attach, use XPT_OPENT to get the executable, in
   * TODO: for attach, use XPT_OPENT to get the executable, in
   * case we're attached without knowning the executable's
   * case we're attached without knowning the executable's
   * filename.
   * filename.
   */
   */
 
 
#ifdef VERBOSE_DEBUG
#ifdef VERBOSE_DEBUG
  printf ("proc_iter\n");
  printf ("proc_iter\n");
#endif
#endif
  interp_sec = bfd_get_section_by_name (exec_bfd, ".interp");
  interp_sec = bfd_get_section_by_name (exec_bfd, ".interp");
  if (!interp_sec)
  if (!interp_sec)
    {
    {
      return 0;
      return 0;
    }
    }
 
 
  size = bfd_section_size (exec_bfd, interp_sec);
  size = bfd_section_size (exec_bfd, interp_sec);
  interp_content = alloca (size);
  interp_content = alloca (size);
  if (0 == bfd_get_section_contents (exec_bfd, interp_sec,
  if (0 == bfd_get_section_contents (exec_bfd, interp_sec,
                                     interp_content, (file_ptr) 0, size))
                                     interp_content, (file_ptr) 0, size))
    {
    {
      return 0;
      return 0;
    }
    }
 
 
#ifdef VERBOSE_DEBUG
#ifdef VERBOSE_DEBUG
  printf ("proc_iter: \"%s\"\n", interp_content);
  printf ("proc_iter: \"%s\"\n", interp_content);
#endif
#endif
  interp_fd = open (interp_content, O_RDONLY, 0);
  interp_fd = open (interp_content, O_RDONLY, 0);
  if (-1 == interp_fd)
  if (-1 == interp_fd)
    {
    {
      return 0;
      return 0;
    }
    }
 
 
  curseg = 0;
  curseg = 0;
  while (1)
  while (1)
    {
    {
      rv = ptrace (PT_NEXT_VSEG, inferior_pid, &pv, curseg);
      rv = ptrace (PT_NEXT_VSEG, inferior_pid, &pv, curseg);
#ifdef VERBOSE_DEBUG
#ifdef VERBOSE_DEBUG
      printf ("PT_NEXT_VSEG: rv %d errno %d\n", rv, errno);
      printf ("PT_NEXT_VSEG: rv %d errno %d\n", rv, errno);
#endif
#endif
      if (-1 == rv)
      if (-1 == rv)
        break;
        break;
      if (0 == rv)
      if (0 == rv)
        break;
        break;
#ifdef VERBOSE_DEBUG
#ifdef VERBOSE_DEBUG
      printf ("pv.pv_start 0x%x pv_size 0x%x pv_prot 0x%x\n",
      printf ("pv.pv_start 0x%x pv_size 0x%x pv_prot 0x%x\n",
              pv.pv_start, pv.pv_size, pv.pv_prot);
              pv.pv_start, pv.pv_size, pv.pv_prot);
#endif
#endif
      curseg = pv.pv_start + pv.pv_size;
      curseg = pv.pv_start + pv.pv_size;
 
 
      rv = lseek (interp_fd, 0, SEEK_SET);
      rv = lseek (interp_fd, 0, SEEK_SET);
      if (-1 == rv)
      if (-1 == rv)
        {
        {
          perror ("lseek");
          perror ("lseek");
          close (interp_fd);
          close (interp_fd);
          return 0;
          return 0;
        }
        }
      for (memptr = pv.pv_start; memptr < pv.pv_start + pv.pv_size;
      for (memptr = pv.pv_start; memptr < pv.pv_start + pv.pv_size;
           memptr += NBPG)
           memptr += NBPG)
        {
        {
#ifdef VERBOSE_DEBUG
#ifdef VERBOSE_DEBUG
          printf ("memptr 0x%x\n", memptr);
          printf ("memptr 0x%x\n", memptr);
#endif
#endif
          rv = read (interp_fd, buf1, NBPG);
          rv = read (interp_fd, buf1, NBPG);
          if (-1 == rv)
          if (-1 == rv)
            {
            {
              perror ("read");
              perror ("read");
              close (interp_fd);
              close (interp_fd);
              return 0;
              return 0;
            }
            }
          rv = ptrace (PT_RDATA_PAGE, inferior_pid, buf2,
          rv = ptrace (PT_RDATA_PAGE, inferior_pid, buf2,
                       memptr);
                       memptr);
          if (-1 == rv)
          if (-1 == rv)
            {
            {
              perror ("ptrace");
              perror ("ptrace");
              close (interp_fd);
              close (interp_fd);
              return 0;
              return 0;
            }
            }
          cmperr = memcmp (buf1, buf2, NBPG);
          cmperr = memcmp (buf1, buf2, NBPG);
          if (cmperr)
          if (cmperr)
            break;
            break;
        }
        }
      if (0 == cmperr)
      if (0 == cmperr)
        {
        {
          /* this is it */
          /* this is it */
          funcstat = (*func) (interp_fd, pv.pv_start);
          funcstat = (*func) (interp_fd, pv.pv_start);
          break;
          break;
        }
        }
    }
    }
  close (interp_fd);
  close (interp_fd);
  return 0;
  return 0;
}
}
 
 

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.