blob: ffc320389f40a011ac6c66ef9c453fce23e38c34 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
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
Linus Torvalds1da177e2005-04-16 15:20:36 -070012
David Daney0926bf92008-09-23 00:11:26 -070013#include <linux/compiler.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070014#include <linux/linkage.h>
Yoichi Yuasaf6a31762008-10-25 17:30:35 +090015#include <linux/types.h>
Atsushi Nemoto8f9a2b32006-09-07 01:00:22 +090016#include <asm/isadep.h>
David Howells61730c52012-10-09 09:47:14 +010017#include <uapi/asm/ptrace.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070018
David Daney8f657932013-05-22 22:35:56 +000019/*
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 */
23struct pt_regs {
24#ifdef CONFIG_32BIT
25 /* Pad bytes for argument save space on the stack. */
Alex Smithe90e6fd2014-07-23 14:40:11 +010026 unsigned long pad0[8];
David Daney8f657932013-05-22 22:35:56 +000027#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;
David Daney8f657932013-05-22 22:35:56 +000042#ifdef CONFIG_CPU_CAVIUM_OCTEON
David Daneyac655fb2015-01-15 16:11:05 +030043 unsigned long long mpl[6]; /* MTM{0-5} */
44 unsigned long long mtp[6]; /* MTP{0-5} */
David Daney8f657932013-05-22 22:35:56 +000045#endif
46} __aligned(8);
47
David Daney0926bf92008-09-23 00:11:26 -070048struct task_struct;
49
Alex Smitha79ebea2014-07-23 14:40:13 +010050extern int ptrace_getregs(struct task_struct *child,
51 struct user_pt_regs __user *data);
52extern int ptrace_setregs(struct task_struct *child,
53 struct user_pt_regs __user *data);
Ralf Baechled302d052008-10-11 16:18:57 +010054
55extern int ptrace_getfpregs(struct task_struct *child, __u32 __user *data);
56extern int ptrace_setfpregs(struct task_struct *child, __u32 __user *data);
57
David Daney0926bf92008-09-23 00:11:26 -070058extern int ptrace_get_watch_regs(struct task_struct *child,
59 struct pt_watch_regs __user *addr);
60extern int ptrace_set_watch_regs(struct task_struct *child,
61 struct pt_watch_regs __user *addr);
62
Linus Torvalds1da177e2005-04-16 15:20:36 -070063/*
64 * Does the process account for user or for system time?
65 */
66#define user_mode(regs) (((regs)->cp0_status & KU_MASK) == KU_USER)
67
Eric Parisd7e75282012-01-03 14:23:06 -050068static inline int is_syscall_success(struct pt_regs *regs)
69{
70 return !regs->regs[7];
71}
72
73static inline long regs_return_value(struct pt_regs *regs)
74{
75 if (is_syscall_success(regs))
76 return regs->regs[2];
77 else
78 return -regs->regs[2];
79}
80
Linus Torvalds1da177e2005-04-16 15:20:36 -070081#define instruction_pointer(regs) ((regs)->cp0_epc)
82#define profile_pc(regs) instruction_pointer(regs)
83
Markos Chandras4c21b8f2014-01-22 14:40:03 +000084extern asmlinkage long syscall_trace_enter(struct pt_regs *regs, long syscall);
Ralf Baechle8b659a32011-05-19 09:21:29 +010085extern asmlinkage void syscall_trace_leave(struct pt_regs *regs);
Linus Torvalds1da177e2005-04-16 15:20:36 -070086
Joe Perchesff2d8b12012-01-12 17:17:21 -080087extern void die(const char *, struct pt_regs *) __noreturn;
Ralf Baechle2d911e92006-12-10 15:02:17 +000088
Yury Polyanskiyce384d82010-04-26 00:53:10 -040089static inline void die_if_kernel(const char *str, struct pt_regs *regs)
Ralf Baechle2d911e92006-12-10 15:02:17 +000090{
91 if (unlikely(!user_mode(regs)))
92 die(str, regs);
93}
94
Ralf Baechlebaf9ff72012-10-09 21:16:07 +020095#define current_pt_regs() \
96({ \
97 unsigned long sp = (unsigned long)__builtin_frame_address(0); \
98 (struct pt_regs *)((sp | (THREAD_SIZE - 1)) + 1 - 32) - 1; \
99})
100
Ralf Baechlec0ff3c52012-08-17 08:22:04 +0200101/* Helpers for working with the user stack pointer */
102
103static inline unsigned long user_stack_pointer(struct pt_regs *regs)
104{
105 return regs->regs[29];
106}
107
108static inline void user_stack_pointer_set(struct pt_regs *regs,
109 unsigned long val)
110{
111 regs->regs[29] = val;
112}
113
Linus Torvalds1da177e2005-04-16 15:20:36 -0700114#endif /* _ASM_PTRACE_H */