Blame backends/s390_initreg.c

Packit 032894
/* Fetch live process registers from TID.
Packit 032894
   Copyright (C) 2013 Red Hat, Inc.
Packit 032894
   This file is part of elfutils.
Packit 032894
Packit 032894
   This file is free software; you can redistribute it and/or modify
Packit 032894
   it under the terms of either
Packit 032894
Packit 032894
     * the GNU Lesser General Public License as published by the Free
Packit 032894
       Software Foundation; either version 3 of the License, or (at
Packit 032894
       your option) any later version
Packit 032894
Packit 032894
   or
Packit 032894
Packit 032894
     * the GNU General Public License as published by the Free
Packit 032894
       Software Foundation; either version 2 of the License, or (at
Packit 032894
       your option) any later version
Packit 032894
Packit 032894
   or both in parallel, as here.
Packit 032894
Packit 032894
   elfutils is distributed in the hope that it will be useful, but
Packit 032894
   WITHOUT ANY WARRANTY; without even the implied warranty of
Packit 032894
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
Packit 032894
   General Public License for more details.
Packit 032894
Packit 032894
   You should have received copies of the GNU General Public License and
Packit 032894
   the GNU Lesser General Public License along with this program.  If
Packit 032894
   not, see <http://www.gnu.org/licenses/>.  */
Packit 032894
Packit 032894
#ifdef HAVE_CONFIG_H
Packit 032894
# include <config.h>
Packit 032894
#endif
Packit 032894
Packit 032894
#include "system.h"
Packit 032894
#include <assert.h>
Packit 032894
#if defined(__s390__) && defined(__linux__)
Packit 032894
# include <sys/user.h>
Packit 032894
# include <sys/ptrace.h>
Packit 032894
# include <asm/ptrace.h>
Packit 032894
#endif
Packit 032894
Packit 032894
#define BACKEND s390_
Packit 032894
#include "libebl_CPU.h"
Packit 032894
Packit 032894
bool
Packit 032894
s390_set_initial_registers_tid (pid_t tid __attribute__ ((unused)),
Packit 032894
			  ebl_tid_registers_t *setfunc __attribute__ ((unused)),
Packit 032894
				void *arg __attribute__ ((unused)))
Packit 032894
{
Packit 032894
#if !defined(__s390__) || !defined(__linux__)
Packit 032894
  return false;
Packit 032894
#else /* __s390__ */
Packit 032894
  struct user user_regs;
Packit 032894
  ptrace_area parea;
Packit 032894
  parea.process_addr = (uintptr_t) &user_regs;
Packit 032894
  parea.kernel_addr = 0;
Packit 032894
  parea.len = sizeof (user_regs);
Packit 032894
  if (ptrace (PTRACE_PEEKUSR_AREA, tid, &parea, NULL) != 0)
Packit 032894
    return false;
Packit 032894
  /* If we run as s390x we get the 64-bit registers of tid.
Packit 032894
     But -m31 executable seems to use only the 32-bit parts of its
Packit 032894
     registers so we ignore the upper half.  */
Packit 032894
  Dwarf_Word dwarf_regs[16];
Packit 032894
  for (unsigned u = 0; u < 16; u++)
Packit 032894
    dwarf_regs[u] = user_regs.regs.gprs[u];
Packit 032894
  if (! setfunc (0, 16, dwarf_regs, arg))
Packit 032894
    return false;
Packit 032894
  /* Avoid conversion double -> integer.  */
Packit 032894
  eu_static_assert (sizeof user_regs.regs.fp_regs.fprs[0]
Packit 032894
		    == sizeof dwarf_regs[0]);
Packit 032894
  for (unsigned u = 0; u < 16; u++)
Packit 032894
    {
Packit 032894
      // Store the double bits as is in the Dwarf_Word without conversion.
Packit 032894
      union
Packit 032894
	{
Packit 032894
	  double d;
Packit 032894
	  Dwarf_Word w;
Packit 032894
	} fpr = { .d = user_regs.regs.fp_regs.fprs[u] };
Packit 032894
      dwarf_regs[u] = fpr.w;
Packit 032894
    }
Packit 032894
Packit 032894
  if (! setfunc (16, 16, dwarf_regs, arg))
Packit 032894
    return false;
Packit 032894
  dwarf_regs[0] = user_regs.regs.psw.addr;
Packit 032894
  return setfunc (-1, 1, dwarf_regs, arg);
Packit 032894
#endif /* __s390__ */
Packit 032894
}
Packit 032894
Packit 032894
void
Packit 032894
s390_normalize_pc (Ebl *ebl __attribute__ ((unused)), Dwarf_Addr *pc)
Packit 032894
{
Packit 032894
  assert (ebl->class == ELFCLASS32);
Packit 032894
Packit 032894
  /* Clear S390 bit 31.  */
Packit 032894
  *pc &= (1U << 31) - 1;
Packit 032894
}