blob: b864031de712bdcd8d4db718e6c41e990b2f07e4 [file] [log] [blame]
Ian Wienand5570a772006-02-17 02:00:00 +01001#if HAVE_CONFIG_H
2#include "config.h"
3#endif
4
5#include <sys/types.h>
6#include <sys/ptrace.h>
7
Ian Wienand2d45b1a2006-02-20 22:48:07 +01008#include <asm/ptrace_offsets.h>
9#include <asm/rse.h>
Ian Wienand5570a772006-02-17 02:00:00 +010010
11#include <stddef.h>
12#include "debug.h"
13#include "ltrace.h"
14
Ian Wienand2d45b1a2006-02-20 22:48:07 +010015void *get_instruction_pointer(struct process *proc)
16{
Ian Wienand5570a772006-02-17 02:00:00 +010017 unsigned long ip = ptrace(PTRACE_PEEKUSER, proc->pid, PT_CR_IIP, 0);
Ian Wienand2d45b1a2006-02-20 22:48:07 +010018 unsigned long slot =
19 (ptrace(PTRACE_PEEKUSER, proc->pid, PT_CR_IPSR, 0) >> 41) & 3;
20
21 return (void *)(ip | slot);
Ian Wienand5570a772006-02-17 02:00:00 +010022}
23
Ian Wienand2d45b1a2006-02-20 22:48:07 +010024void set_instruction_pointer(struct process *proc, void *addr)
25{
Ian Wienand5570a772006-02-17 02:00:00 +010026
27 unsigned long newip = (unsigned long)addr;
Olaf Heringa841f652006-09-15 01:57:49 +020028 unsigned long slot = (unsigned long)addr & 0xf;
Ian Wienand5570a772006-02-17 02:00:00 +010029 unsigned long psr = ptrace(PTRACE_PEEKUSER, proc->pid, PT_CR_IPSR, 0);
Ian Wienand2d45b1a2006-02-20 22:48:07 +010030
Ian Wienand5570a772006-02-17 02:00:00 +010031 psr &= ~(3UL << 41);
Olaf Heringa841f652006-09-15 01:57:49 +020032 psr |= (slot & 0x3) << 41;
Ian Wienand2d45b1a2006-02-20 22:48:07 +010033
Ian Wienand5570a772006-02-17 02:00:00 +010034 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
Ian Wienand2d45b1a2006-02-20 22:48:07 +010040void *get_stack_pointer(struct process *proc)
41{
Ian Wienand5570a772006-02-17 02:00:00 +010042 return (void *)ptrace(PTRACE_PEEKUSER, proc->pid, PT_R12, 0);
43}
44
Ian Wienand2d45b1a2006-02-20 22:48:07 +010045void *get_return_addr(struct process *proc, void *stack_pointer)
46{
Ian Wienand5570a772006-02-17 02:00:00 +010047 return (void *)ptrace(PTRACE_PEEKUSER, proc->pid, PT_B0, 0);
48}