regs.c revision f728123bd75a65a6a1536e198c3c30719e494e71
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 "common.h"
14
15void *
16get_instruction_pointer(Process *proc) {
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
25set_instruction_pointer(Process *proc, void *addr) {
26
27	unsigned long newip = (unsigned long)addr;
28	unsigned long slot = (unsigned long)addr & 0xf;
29	unsigned long psr = ptrace(PTRACE_PEEKUSER, proc->pid, PT_CR_IPSR, 0);
30
31	psr &= ~(3UL << 41);
32	psr |= (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 *
41get_stack_pointer(Process *proc) {
42	return (void *)ptrace(PTRACE_PEEKUSER, proc->pid, PT_R12, 0);
43}
44
45void *
46get_return_addr(Process *proc, void *stack_pointer) {
47	return (void *)ptrace(PTRACE_PEEKUSER, proc->pid, PT_B0, 0);
48}
49