2002-08-17 03:19:06 +02:00
|
|
|
/*
|
|
|
|
* PowerPC register context support
|
|
|
|
*
|
|
|
|
* Copyright (C) 2002 Marcus Meissner, SuSE Linux AG.
|
|
|
|
*
|
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
* version 2.1 of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* Lesser General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
|
|
|
* License along with this library; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "config.h"
|
|
|
|
|
|
|
|
#ifdef __powerpc__
|
|
|
|
|
|
|
|
#include <assert.h>
|
|
|
|
#include <errno.h>
|
|
|
|
#include <sys/types.h>
|
|
|
|
#ifdef HAVE_SYS_REG_H
|
|
|
|
# include <sys/reg.h>
|
|
|
|
#endif
|
2003-09-06 01:08:26 +02:00
|
|
|
#include <stdarg.h>
|
2002-08-17 03:19:06 +02:00
|
|
|
#include <unistd.h>
|
|
|
|
#ifdef HAVE_SYS_PTRACE_H
|
|
|
|
# include <sys/ptrace.h>
|
|
|
|
#endif
|
|
|
|
|
2003-05-12 05:07:45 +02:00
|
|
|
#ifndef PTRACE_PEEKUSER
|
|
|
|
# ifdef PT_READ_D
|
|
|
|
# define PTRACE_PEEKUSER PT_READ_D
|
|
|
|
# endif
|
|
|
|
#endif /* PTRACE_PEEKUSER */
|
|
|
|
|
|
|
|
#ifndef PTRACE_POKEUSER
|
|
|
|
# ifdef PT_WRITE_D
|
|
|
|
# define PTRACE_POKEUSER PT_WRITE_D
|
|
|
|
# endif
|
|
|
|
#endif /* PTRACE_POKEUSER */
|
|
|
|
|
2003-09-06 01:08:26 +02:00
|
|
|
#include "windef.h"
|
2002-08-17 03:19:06 +02:00
|
|
|
|
2003-02-14 21:27:09 +01:00
|
|
|
#include "file.h"
|
2002-08-17 03:19:06 +02:00
|
|
|
#include "thread.h"
|
|
|
|
#include "request.h"
|
|
|
|
|
|
|
|
/* retrieve a thread context */
|
2005-11-02 15:12:13 +01:00
|
|
|
static void get_thread_context_ptrace( struct thread *thread, unsigned int flags, CONTEXT *context )
|
2002-08-17 03:19:06 +02:00
|
|
|
{
|
2003-03-11 02:48:53 +01:00
|
|
|
int pid = get_ptrace_pid(thread);
|
2005-12-21 20:06:42 +01:00
|
|
|
if (flags & CONTEXT_INTEGER)
|
2002-08-17 03:19:06 +02:00
|
|
|
{
|
|
|
|
#define XREG(x,y) if (ptrace( PTRACE_PEEKUSER, pid, (void*)(x<<2), &context->y) == -1) goto error;
|
|
|
|
#define IREG(x) if (ptrace( PTRACE_PEEKUSER, pid, (void*)(x<<2), &context->Gpr##x) == -1) goto error;
|
2005-12-21 20:06:42 +01:00
|
|
|
IREG(0); IREG(1); IREG(2); IREG(3); IREG(4); IREG(5); IREG(6);
|
|
|
|
IREG(7); IREG(8); IREG(9); IREG(10); IREG(11); IREG(12); IREG(13);
|
|
|
|
IREG(14); IREG(15); IREG(16); IREG(17); IREG(18); IREG(19);
|
|
|
|
IREG(20); IREG(21); IREG(22); IREG(23); IREG(24); IREG(25);
|
|
|
|
IREG(26); IREG(27); IREG(28); IREG(29); IREG(30); IREG(31);
|
2002-08-17 03:19:06 +02:00
|
|
|
#undef IREG
|
2005-12-21 20:06:42 +01:00
|
|
|
XREG(37,Xer);
|
|
|
|
XREG(38,Cr);
|
|
|
|
context->ContextFlags |= CONTEXT_INTEGER;
|
|
|
|
}
|
|
|
|
if (flags & CONTEXT_CONTROL)
|
|
|
|
{
|
|
|
|
XREG(32,Iar);
|
|
|
|
XREG(33,Msr);
|
|
|
|
XREG(35,Ctr);
|
|
|
|
XREG(36,Lr); /* 36 is LNK ... probably Lr ? */
|
|
|
|
context->ContextFlags |= CONTEXT_CONTROL;
|
2002-08-17 03:19:06 +02:00
|
|
|
}
|
|
|
|
if (flags & CONTEXT_FLOATING_POINT)
|
|
|
|
{
|
|
|
|
#define FREG(x) if (ptrace( PTRACE_PEEKUSER, pid, (void*)((48+x*2)<<2), &context->Fpr##x) == -1) goto error;
|
|
|
|
FREG(0);
|
|
|
|
FREG(1);
|
|
|
|
FREG(2);
|
|
|
|
FREG(3);
|
|
|
|
FREG(4);
|
|
|
|
FREG(5);
|
|
|
|
FREG(6);
|
|
|
|
FREG(7);
|
|
|
|
FREG(8);
|
|
|
|
FREG(9);
|
|
|
|
FREG(10);
|
|
|
|
FREG(11);
|
|
|
|
FREG(12);
|
|
|
|
FREG(13);
|
|
|
|
FREG(14);
|
|
|
|
FREG(15);
|
|
|
|
FREG(16);
|
|
|
|
FREG(17);
|
|
|
|
FREG(18);
|
|
|
|
FREG(19);
|
|
|
|
FREG(20);
|
|
|
|
FREG(21);
|
|
|
|
FREG(22);
|
|
|
|
FREG(23);
|
|
|
|
FREG(24);
|
|
|
|
FREG(25);
|
|
|
|
FREG(26);
|
|
|
|
FREG(27);
|
|
|
|
FREG(28);
|
|
|
|
FREG(29);
|
|
|
|
FREG(30);
|
|
|
|
FREG(31);
|
|
|
|
XREG((48+32*2),Fpscr);
|
2005-12-21 20:06:42 +01:00
|
|
|
context->ContextFlags |= CONTEXT_FLOATING_POINT;
|
2002-08-17 03:19:06 +02:00
|
|
|
}
|
|
|
|
return;
|
|
|
|
error:
|
|
|
|
file_set_error();
|
|
|
|
}
|
|
|
|
#undef XREG
|
|
|
|
#undef IREG
|
|
|
|
#undef FREG
|
|
|
|
|
|
|
|
#define XREG(x,y) if (ptrace( PTRACE_POKEUSER, pid, (void*)(x<<2), &context->y) == -1) goto error;
|
|
|
|
#define IREG(x) if (ptrace( PTRACE_POKEUSER, pid, (void*)(x<<2), &context->Gpr##x) == -1) goto error;
|
|
|
|
#define FREG(x) if (ptrace( PTRACE_POKEUSER, pid, (void*)((48+x*2)<<2), &context->Fpr##x) == -1) goto error;
|
|
|
|
/* set a thread context */
|
2005-11-02 15:12:13 +01:00
|
|
|
static void set_thread_context_ptrace( struct thread *thread, unsigned int flags, const CONTEXT *context )
|
2002-08-17 03:19:06 +02:00
|
|
|
{
|
2003-03-11 02:48:53 +01:00
|
|
|
int pid = get_ptrace_pid(thread);
|
2002-08-17 03:19:06 +02:00
|
|
|
if (flags & CONTEXT_FULL)
|
|
|
|
{
|
|
|
|
if (flags & CONTEXT_INTEGER)
|
|
|
|
{
|
|
|
|
IREG(0); IREG(1); IREG(2); IREG(3); IREG(4); IREG(5); IREG(6);
|
|
|
|
IREG(7); IREG(8); IREG(9); IREG(10); IREG(11); IREG(12); IREG(13);
|
|
|
|
IREG(14); IREG(15); IREG(16); IREG(17); IREG(18); IREG(19);
|
|
|
|
IREG(20); IREG(21); IREG(22); IREG(23); IREG(24); IREG(25);
|
|
|
|
IREG(26); IREG(27); IREG(28); IREG(29); IREG(30); IREG(31);
|
|
|
|
XREG(37,Xer);
|
|
|
|
XREG(38,Cr);
|
|
|
|
|
|
|
|
}
|
|
|
|
if (flags & CONTEXT_CONTROL)
|
|
|
|
{
|
2002-08-30 02:00:57 +02:00
|
|
|
XREG(32,Iar);
|
2002-08-17 03:19:06 +02:00
|
|
|
XREG(33,Msr);
|
|
|
|
XREG(35,Ctr);
|
2002-08-30 02:00:57 +02:00
|
|
|
XREG(36,Lr);
|
2002-08-17 03:19:06 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
if (flags & CONTEXT_FLOATING_POINT)
|
|
|
|
{
|
|
|
|
FREG(0);
|
|
|
|
FREG(1);
|
|
|
|
FREG(2);
|
|
|
|
FREG(3);
|
|
|
|
FREG(4);
|
|
|
|
FREG(5);
|
|
|
|
FREG(6);
|
|
|
|
FREG(7);
|
|
|
|
FREG(8);
|
|
|
|
FREG(9);
|
|
|
|
FREG(10);
|
|
|
|
FREG(11);
|
|
|
|
FREG(12);
|
|
|
|
FREG(13);
|
|
|
|
FREG(14);
|
|
|
|
FREG(15);
|
|
|
|
FREG(16);
|
|
|
|
FREG(17);
|
|
|
|
FREG(18);
|
|
|
|
FREG(19);
|
|
|
|
FREG(20);
|
|
|
|
FREG(21);
|
|
|
|
FREG(22);
|
|
|
|
FREG(23);
|
|
|
|
FREG(24);
|
|
|
|
FREG(25);
|
|
|
|
FREG(26);
|
|
|
|
FREG(27);
|
|
|
|
FREG(28);
|
|
|
|
FREG(29);
|
|
|
|
FREG(30);
|
|
|
|
FREG(31);
|
|
|
|
#undef FREG
|
|
|
|
XREG((48+32*2),Fpscr);
|
|
|
|
}
|
|
|
|
return;
|
|
|
|
error:
|
|
|
|
file_set_error();
|
|
|
|
}
|
|
|
|
#undef XREG
|
|
|
|
#undef IREG
|
|
|
|
#undef FREG
|
|
|
|
|
|
|
|
#define IREG(x) to->Gpr##x = from->Gpr##x;
|
|
|
|
#define FREG(x) to->Fpr##x = from->Fpr##x;
|
|
|
|
#define CREG(x) to->x = from->x;
|
|
|
|
/* copy a context structure according to the flags */
|
2005-12-21 20:06:42 +01:00
|
|
|
static void copy_context( CONTEXT *to, const CONTEXT *from, unsigned int flags )
|
2002-08-17 03:19:06 +02:00
|
|
|
{
|
|
|
|
if (flags & CONTEXT_CONTROL)
|
|
|
|
{
|
|
|
|
CREG(Msr);
|
|
|
|
CREG(Ctr);
|
2002-08-30 02:00:57 +02:00
|
|
|
CREG(Iar);
|
2005-12-21 20:06:42 +01:00
|
|
|
to->ContextFlags |= CONTEXT_CONTROL;
|
2002-08-17 03:19:06 +02:00
|
|
|
}
|
|
|
|
if (flags & CONTEXT_INTEGER)
|
|
|
|
{
|
|
|
|
IREG(0); IREG(1); IREG(2); IREG(3); IREG(4); IREG(5); IREG(6);
|
|
|
|
IREG(7); IREG(8); IREG(9); IREG(10); IREG(11); IREG(12); IREG(13);
|
|
|
|
IREG(14); IREG(15); IREG(16); IREG(17); IREG(18); IREG(19);
|
|
|
|
IREG(20); IREG(21); IREG(22); IREG(23); IREG(24); IREG(25);
|
|
|
|
IREG(26); IREG(27); IREG(28); IREG(29); IREG(30); IREG(31);
|
|
|
|
CREG(Xer);
|
|
|
|
CREG(Cr);
|
2005-12-21 20:06:42 +01:00
|
|
|
to->ContextFlags |= CONTEXT_INTEGER;
|
2002-08-17 03:19:06 +02:00
|
|
|
}
|
|
|
|
if (flags & CONTEXT_FLOATING_POINT)
|
|
|
|
{
|
|
|
|
FREG(0);
|
|
|
|
FREG(1);
|
|
|
|
FREG(2);
|
|
|
|
FREG(3);
|
|
|
|
FREG(4);
|
|
|
|
FREG(5);
|
|
|
|
FREG(6);
|
|
|
|
FREG(7);
|
|
|
|
FREG(8);
|
|
|
|
FREG(9);
|
|
|
|
FREG(10);
|
|
|
|
FREG(11);
|
|
|
|
FREG(12);
|
|
|
|
FREG(13);
|
|
|
|
FREG(14);
|
|
|
|
FREG(15);
|
|
|
|
FREG(16);
|
|
|
|
FREG(17);
|
|
|
|
FREG(18);
|
|
|
|
FREG(19);
|
|
|
|
FREG(20);
|
|
|
|
FREG(21);
|
|
|
|
FREG(22);
|
|
|
|
FREG(23);
|
|
|
|
FREG(24);
|
|
|
|
FREG(25);
|
|
|
|
FREG(26);
|
|
|
|
FREG(27);
|
|
|
|
FREG(28);
|
|
|
|
FREG(29);
|
|
|
|
FREG(30);
|
|
|
|
FREG(31);
|
|
|
|
CREG(Fpscr);
|
2005-12-21 20:06:42 +01:00
|
|
|
to->ContextFlags |= CONTEXT_FLOATING_POINT;
|
2002-08-17 03:19:06 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* retrieve the current instruction pointer of a thread */
|
|
|
|
void *get_thread_ip( struct thread *thread )
|
|
|
|
{
|
|
|
|
CONTEXT context;
|
2002-08-30 02:00:57 +02:00
|
|
|
context.Iar = 0;
|
2002-08-17 03:19:06 +02:00
|
|
|
if (suspend_for_ptrace( thread ))
|
|
|
|
{
|
2005-11-02 15:12:13 +01:00
|
|
|
get_thread_context_ptrace( thread, CONTEXT_CONTROL, &context );
|
2003-03-04 23:18:43 +01:00
|
|
|
resume_after_ptrace( thread );
|
2002-08-17 03:19:06 +02:00
|
|
|
}
|
2002-08-30 02:00:57 +02:00
|
|
|
return (void *)context.Iar;
|
2002-08-17 03:19:06 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/* determine if we should continue the thread in single-step mode */
|
|
|
|
int get_thread_single_step( struct thread *thread )
|
|
|
|
{
|
|
|
|
CONTEXT context;
|
|
|
|
if (thread->context) return 0;
|
2005-11-02 15:12:13 +01:00
|
|
|
get_thread_context_ptrace( thread, CONTEXT_CONTROL, &context );
|
2002-08-17 03:19:06 +02:00
|
|
|
#ifndef MSR_SE
|
|
|
|
# define MSR_SE (1<<10)
|
|
|
|
#endif
|
|
|
|
return (context.Msr & MSR_SE) != 0;
|
|
|
|
}
|
|
|
|
|
2003-03-22 22:00:09 +01:00
|
|
|
/* send a signal to a specific thread */
|
2006-02-14 12:24:32 +01:00
|
|
|
int tkill( int tgid, int pid, int sig )
|
2003-03-22 22:00:09 +01:00
|
|
|
{
|
|
|
|
/* FIXME: should do something here */
|
|
|
|
errno = ENOSYS;
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2005-11-02 15:12:13 +01:00
|
|
|
/* retrieve the thread context */
|
|
|
|
void get_thread_context( struct thread *thread, CONTEXT *context, unsigned int flags )
|
2002-08-17 03:19:06 +02:00
|
|
|
{
|
2005-11-02 15:12:13 +01:00
|
|
|
if (thread->context) /* thread is inside an exception event or suspended */
|
2002-08-17 03:19:06 +02:00
|
|
|
{
|
2005-11-02 15:12:13 +01:00
|
|
|
copy_context( context, thread->context, flags );
|
2002-08-17 03:19:06 +02:00
|
|
|
}
|
2005-11-02 15:12:13 +01:00
|
|
|
else if (flags && suspend_for_ptrace( thread ))
|
2002-08-17 03:19:06 +02:00
|
|
|
{
|
2005-11-02 15:12:13 +01:00
|
|
|
get_thread_context_ptrace( thread, flags, context );
|
|
|
|
resume_after_ptrace( thread );
|
2002-08-17 03:19:06 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2005-11-02 15:12:13 +01:00
|
|
|
/* set the thread context */
|
|
|
|
void set_thread_context( struct thread *thread, const CONTEXT *context, unsigned int flags )
|
2002-08-17 03:19:06 +02:00
|
|
|
{
|
2005-11-02 15:12:13 +01:00
|
|
|
if (thread->context) /* thread is inside an exception event or suspended */
|
2002-08-17 03:19:06 +02:00
|
|
|
{
|
2005-11-02 15:12:13 +01:00
|
|
|
copy_context( thread->context, context, flags );
|
2002-08-17 03:19:06 +02:00
|
|
|
}
|
2005-11-02 15:12:13 +01:00
|
|
|
else if (flags && suspend_for_ptrace( thread ))
|
2002-08-17 03:19:06 +02:00
|
|
|
{
|
2005-11-02 15:12:13 +01:00
|
|
|
set_thread_context_ptrace( thread, flags, context );
|
|
|
|
resume_after_ptrace( thread );
|
2002-08-17 03:19:06 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif /* __powerpc__ */
|