Imported Upstream version 0.7.2
[platform/upstream/ltrace.git] / sysdeps / linux-gnu / ppc / regs.c
1 /*
2  * This file is part of ltrace.
3  * Copyright (C) 2002,2008,2009 Juan Cespedes
4  * Copyright (C) 2009 Juan Cespedes
5  * Copyright (C) 2008 Luis Machado, IBM Corporation
6  *
7  * This program is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU General Public License as
9  * published by the Free Software Foundation; either version 2 of the
10  * License, or (at your option) any later version.
11  *
12  * This program is distributed in the hope that it will be useful, but
13  * WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
15  * General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with this program; if not, write to the Free Software
19  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
20  * 02110-1301 USA
21  */
22
23 #include "config.h"
24
25 #include <sys/types.h>
26 #include <sys/ptrace.h>
27 #include <asm/ptrace.h>
28 #include <errno.h>
29 #include <error.h>
30
31 #include "proc.h"
32 #include "common.h"
33
34 #if (!defined(PTRACE_PEEKUSER) && defined(PTRACE_PEEKUSR))
35 # define PTRACE_PEEKUSER PTRACE_PEEKUSR
36 #endif
37
38 #if (!defined(PTRACE_POKEUSER) && defined(PTRACE_POKEUSR))
39 # define PTRACE_POKEUSER PTRACE_POKEUSR
40 #endif
41
42 void *
43 get_instruction_pointer(Process *proc) {
44         return (void *)ptrace(PTRACE_PEEKUSER, proc->pid, sizeof(long)*PT_NIP, 0);
45 }
46
47 void
48 set_instruction_pointer(Process *proc, void *addr)
49 {
50         if (ptrace(PTRACE_POKEUSER, proc->pid, sizeof(long)*PT_NIP, addr) != 0)
51                 error(0, errno, "set_instruction_pointer");
52 }
53
54 void *
55 get_stack_pointer(Process *proc) {
56         return (void *)ptrace(PTRACE_PEEKUSER, proc->pid, sizeof(long)*PT_R1, 0);
57 }
58
59 void *
60 get_return_addr(Process *proc, void *stack_pointer) {
61         return (void *)ptrace(PTRACE_PEEKUSER, proc->pid, sizeof(long)*PT_LNK, 0);
62 }
63
64 void
65 set_return_addr(Process *proc, void *addr) {
66         ptrace(PTRACE_POKEUSER, proc->pid, sizeof(long)*PT_LNK, addr);
67 }
68
69 /* Grab the value of CTR registers.  */
70 void *
71 get_count_register (Process *proc) {
72         return (void *) ptrace (PTRACE_PEEKUSER, proc->pid,
73                                 sizeof (long) * PT_CTR, 0);
74 }