xref: /openbmc/linux/arch/mips/include/asm/ptrace.h (revision d2999e1b)
1 /*
2  * This file is subject to the terms and conditions of the GNU General Public
3  * License.  See the file "COPYING" in the main directory of this archive
4  * for more details.
5  *
6  * Copyright (C) 1994, 95, 96, 97, 98, 99, 2000 by Ralf Baechle
7  * Copyright (C) 1999, 2000 Silicon Graphics, Inc.
8  */
9 #ifndef _ASM_PTRACE_H
10 #define _ASM_PTRACE_H
11 
12 
13 #include <linux/compiler.h>
14 #include <linux/linkage.h>
15 #include <linux/types.h>
16 #include <asm/isadep.h>
17 #include <uapi/asm/ptrace.h>
18 
19 /*
20  * This struct defines the way the registers are stored on the stack during a
21  * system call/exception. As usual the registers k0/k1 aren't being saved.
22  */
23 struct pt_regs {
24 #ifdef CONFIG_32BIT
25 	/* Pad bytes for argument save space on the stack. */
26 	unsigned long pad0[6];
27 #endif
28 
29 	/* Saved main processor registers. */
30 	unsigned long regs[32];
31 
32 	/* Saved special registers. */
33 	unsigned long cp0_status;
34 	unsigned long hi;
35 	unsigned long lo;
36 #ifdef CONFIG_CPU_HAS_SMARTMIPS
37 	unsigned long acx;
38 #endif
39 	unsigned long cp0_badvaddr;
40 	unsigned long cp0_cause;
41 	unsigned long cp0_epc;
42 #ifdef CONFIG_CPU_CAVIUM_OCTEON
43 	unsigned long long mpl[3];	  /* MTM{0,1,2} */
44 	unsigned long long mtp[3];	  /* MTP{0,1,2} */
45 #endif
46 } __aligned(8);
47 
48 struct task_struct;
49 
50 extern int ptrace_getregs(struct task_struct *child, __s64 __user *data);
51 extern int ptrace_setregs(struct task_struct *child, __s64 __user *data);
52 
53 extern int ptrace_getfpregs(struct task_struct *child, __u32 __user *data);
54 extern int ptrace_setfpregs(struct task_struct *child, __u32 __user *data);
55 
56 extern int ptrace_get_watch_regs(struct task_struct *child,
57 	struct pt_watch_regs __user *addr);
58 extern int ptrace_set_watch_regs(struct task_struct *child,
59 	struct pt_watch_regs __user *addr);
60 
61 /*
62  * Does the process account for user or for system time?
63  */
64 #define user_mode(regs) (((regs)->cp0_status & KU_MASK) == KU_USER)
65 
66 static inline int is_syscall_success(struct pt_regs *regs)
67 {
68 	return !regs->regs[7];
69 }
70 
71 static inline long regs_return_value(struct pt_regs *regs)
72 {
73 	if (is_syscall_success(regs))
74 		return regs->regs[2];
75 	else
76 		return -regs->regs[2];
77 }
78 
79 #define instruction_pointer(regs) ((regs)->cp0_epc)
80 #define profile_pc(regs) instruction_pointer(regs)
81 
82 extern asmlinkage long syscall_trace_enter(struct pt_regs *regs, long syscall);
83 extern asmlinkage void syscall_trace_leave(struct pt_regs *regs);
84 
85 extern void die(const char *, struct pt_regs *) __noreturn;
86 
87 static inline void die_if_kernel(const char *str, struct pt_regs *regs)
88 {
89 	if (unlikely(!user_mode(regs)))
90 		die(str, regs);
91 }
92 
93 #define current_pt_regs()						\
94 ({									\
95 	unsigned long sp = (unsigned long)__builtin_frame_address(0);	\
96 	(struct pt_regs *)((sp | (THREAD_SIZE - 1)) + 1 - 32) - 1;	\
97 })
98 
99 /* Helpers for working with the user stack pointer */
100 
101 static inline unsigned long user_stack_pointer(struct pt_regs *regs)
102 {
103 	return regs->regs[29];
104 }
105 
106 static inline void user_stack_pointer_set(struct pt_regs *regs,
107 	unsigned long val)
108 {
109 	regs->regs[29] = val;
110 }
111 
112 #endif /* _ASM_PTRACE_H */
113