regs.c revision 2d45b1a8e26a36a9f85dc49e721c4390ca93dc40
1#if HAVE_CONFIG_H
2#include "config.h"
3#endif
4
5#include <sys/types.h>
6#include <sys/ptrace.h>
7
8#include <asm/ptrace_offsets.h>
9#include <asm/rse.h>
10
11#include <stddef.h>
12#include "debug.h"
13#include "ltrace.h"
14
15void *get_instruction_pointer(struct process *proc)
16{
17	unsigned long ip = ptrace(PTRACE_PEEKUSER, proc->pid, PT_CR_IIP, 0);
18	unsigned long slot =
19	    (ptrace(PTRACE_PEEKUSER, proc->pid, PT_CR_IPSR, 0) >> 41) & 3;
20
21	return (void *)(ip | slot);
22}
23
24void set_instruction_pointer(struct process *proc, void *addr)
25{
26
27	unsigned long newip = (unsigned long)addr;
28	int slot = (int)addr & 0xf;
29	unsigned long psr = ptrace(PTRACE_PEEKUSER, proc->pid, PT_CR_IPSR, 0);
30
31	psr &= ~(3UL << 41);
32	psr |= (unsigned long)(slot & 0x3) << 41;
33
34	newip &= ~0xfUL;
35
36	ptrace(PTRACE_POKEUSER, proc->pid, PT_CR_IIP, (long)newip);
37	ptrace(PTRACE_POKEUSER, proc->pid, PT_CR_IPSR, psr);
38}
39
40void *get_stack_pointer(struct process *proc)
41{
42	return (void *)ptrace(PTRACE_PEEKUSER, proc->pid, PT_R12, 0);
43}
44
45void *get_return_addr(struct process *proc, void *stack_pointer)
46{
47	return (void *)ptrace(PTRACE_PEEKUSER, proc->pid, PT_B0, 0);
48}
49