blob: 0ad9a2b7f8c0a779db65499b0a205522cd61cb74 [file] [log] [blame]
Thomas Gleixner8fc37f22007-10-23 22:37:24 +02001#ifndef _ASM_X86_PTRACE_H
2#define _ASM_X86_PTRACE_H
3
4#include <linux/compiler.h> /* For __user */
5#include <asm/ptrace-abi.h>
6
Markus Metzgereee3af42008-01-30 13:31:09 +01007
Thomas Gleixner8fc37f22007-10-23 22:37:24 +02008#ifndef __ASSEMBLY__
9
Markus Metzgereee3af42008-01-30 13:31:09 +010010#ifdef __KERNEL__
11
Markus Metzgera95d67f2008-01-30 13:31:20 +010012/* the DS BTS struct is used for ptrace as well */
Markus Metzgereee3af42008-01-30 13:31:09 +010013#include <asm/ds.h>
14
15struct task_struct;
16extern void ptrace_bts_take_timestamp(struct task_struct *, enum bts_qualifier);
17
18#endif /* __KERNEL__ */
19
20
Thomas Gleixner8fc37f22007-10-23 22:37:24 +020021#ifdef __i386__
22/* this struct defines the way the registers are stored on the
23 stack during a system call. */
24
H. Peter Anvin65ea5b02008-01-30 13:30:56 +010025#ifndef __KERNEL__
26
Thomas Gleixner8fc37f22007-10-23 22:37:24 +020027struct pt_regs {
28 long ebx;
29 long ecx;
30 long edx;
31 long esi;
32 long edi;
33 long ebp;
34 long eax;
35 int xds;
36 int xes;
37 int xfs;
H. Peter Anvin65ea5b02008-01-30 13:30:56 +010038 /* int gs; */
Thomas Gleixner8fc37f22007-10-23 22:37:24 +020039 long orig_eax;
40 long eip;
41 int xcs;
42 long eflags;
43 long esp;
44 int xss;
45};
46
H. Peter Anvin65ea5b02008-01-30 13:30:56 +010047#else /* __KERNEL__ */
48
49struct pt_regs {
50 long bx;
51 long cx;
52 long dx;
53 long si;
54 long di;
55 long bp;
56 long ax;
57 int ds;
58 int es;
59 int fs;
60 /* int gs; */
61 long orig_ax;
62 long ip;
63 int cs;
64 long flags;
65 long sp;
66 int ss;
67};
Thomas Gleixner8fc37f22007-10-23 22:37:24 +020068
69#include <asm/vm86.h>
70#include <asm/segment.h>
71
72struct task_struct;
Harvey Harrisonf2857ce2008-01-30 13:33:12 +010073
74extern unsigned long
75convert_ip_to_linear(struct task_struct *child, struct pt_regs *regs);
76
Thomas Gleixner8fc37f22007-10-23 22:37:24 +020077extern void send_sigtrap(struct task_struct *tsk, struct pt_regs *regs, int error_code);
78
H. Peter Anvin65ea5b02008-01-30 13:30:56 +010079#define regs_return_value(regs) ((regs)->ax)
Thomas Gleixner8fc37f22007-10-23 22:37:24 +020080
81extern unsigned long profile_pc(struct pt_regs *regs);
82#endif /* __KERNEL__ */
83
84#else /* __i386__ */
85
H. Peter Anvin65ea5b02008-01-30 13:30:56 +010086#ifndef __KERNEL__
87
Thomas Gleixner8fc37f22007-10-23 22:37:24 +020088struct pt_regs {
89 unsigned long r15;
90 unsigned long r14;
91 unsigned long r13;
92 unsigned long r12;
93 unsigned long rbp;
94 unsigned long rbx;
95/* arguments: non interrupts/non tracing syscalls only save upto here*/
96 unsigned long r11;
97 unsigned long r10;
98 unsigned long r9;
99 unsigned long r8;
100 unsigned long rax;
101 unsigned long rcx;
102 unsigned long rdx;
103 unsigned long rsi;
104 unsigned long rdi;
105 unsigned long orig_rax;
106/* end of arguments */
107/* cpu exception frame or undefined */
108 unsigned long rip;
109 unsigned long cs;
110 unsigned long eflags;
111 unsigned long rsp;
112 unsigned long ss;
113/* top of stack page */
114};
115
H. Peter Anvin65ea5b02008-01-30 13:30:56 +0100116#else /* __KERNEL__ */
117
118struct pt_regs {
119 unsigned long r15;
120 unsigned long r14;
121 unsigned long r13;
122 unsigned long r12;
123 unsigned long bp;
124 unsigned long bx;
125/* arguments: non interrupts/non tracing syscalls only save upto here*/
126 unsigned long r11;
127 unsigned long r10;
128 unsigned long r9;
129 unsigned long r8;
130 unsigned long ax;
131 unsigned long cx;
132 unsigned long dx;
133 unsigned long si;
134 unsigned long di;
135 unsigned long orig_ax;
136/* end of arguments */
137/* cpu exception frame or undefined */
138 unsigned long ip;
139 unsigned long cs;
140 unsigned long flags;
141 unsigned long sp;
142 unsigned long ss;
143/* top of stack page */
144};
Thomas Gleixner8fc37f22007-10-23 22:37:24 +0200145
H. Peter Anvin65ea5b02008-01-30 13:30:56 +0100146#define regs_return_value(regs) ((regs)->ax)
Thomas Gleixner8fc37f22007-10-23 22:37:24 +0200147
148extern unsigned long profile_pc(struct pt_regs *regs);
149void signal_fault(struct pt_regs *regs, void __user *frame, char *where);
150
151struct task_struct;
152
153extern unsigned long
Harvey Harrison37cd9cf2008-01-30 13:33:12 +0100154convert_ip_to_linear(struct task_struct *child, struct pt_regs *regs);
Thomas Gleixner8fc37f22007-10-23 22:37:24 +0200155
Thomas Gleixner8fc37f22007-10-23 22:37:24 +0200156#endif /* __KERNEL__ */
157#endif /* !__i386__ */
Roland McGrathefd1ca52008-01-30 13:30:46 +0100158
159#ifdef __KERNEL__
160
Roland McGrath7f232342008-01-30 13:30:48 +0100161/*
Harvey Harrison90d43d72008-01-30 13:33:16 +0100162 * user_mode_vm(regs) determines whether a register set came from user mode.
163 * This is true if V8086 mode was enabled OR if the register set was from
164 * protected mode with RPL-3 CS value. This tricky test checks that with
165 * one comparison. Many places in the kernel can bypass this full check
166 * if they have already ruled out V8086 mode, so user_mode(regs) can be used.
167 */
168static inline int user_mode(struct pt_regs *regs)
169{
170#ifdef CONFIG_X86_32
171 return (regs->cs & SEGMENT_RPL_MASK) == USER_RPL;
172#else
173 return !!(regs->cs & 3);
174#endif
175}
176
177static inline int user_mode_vm(struct pt_regs *regs)
178{
179#ifdef CONFIG_X86_32
180 return ((regs->cs & SEGMENT_RPL_MASK) |
181 (regs->flags & VM_MASK)) >= USER_RPL;
182#else
183 return user_mode(regs);
184#endif
185}
186
187static inline int v8086_mode(struct pt_regs *regs)
188{
189#ifdef CONFIG_X86_32
190 return (regs->flags & VM_MASK);
191#else
192 return 0; /* No V86 mode support in long mode */
193#endif
194}
195
196static inline unsigned long stack_pointer(struct pt_regs *regs)
197{
198#ifdef CONFIG_X86_32
199 return (unsigned long)regs;
200#else
201 return regs->sp;
202#endif
203}
204
205static inline unsigned long instruction_pointer(struct pt_regs *regs)
206{
207 return regs->ip;
208}
209
210static inline unsigned long frame_pointer(struct pt_regs *regs)
211{
212 return regs->bp;
213}
214
215/*
Roland McGrath7f232342008-01-30 13:30:48 +0100216 * These are defined as per linux/ptrace.h, which see.
217 */
218#define arch_has_single_step() (1)
219extern void user_enable_single_step(struct task_struct *);
220extern void user_disable_single_step(struct task_struct *);
221
Roland McGrath10faa812008-01-30 13:30:54 +0100222extern void user_enable_block_step(struct task_struct *);
223#ifdef CONFIG_X86_DEBUGCTLMSR
224#define arch_has_block_step() (1)
225#else
226#define arch_has_block_step() (boot_cpu_data.x86 >= 6)
227#endif
228
Roland McGrathefd1ca52008-01-30 13:30:46 +0100229struct user_desc;
230extern int do_get_thread_area(struct task_struct *p, int idx,
231 struct user_desc __user *info);
232extern int do_set_thread_area(struct task_struct *p, int idx,
233 struct user_desc __user *info, int can_allocate);
234
235#endif /* __KERNEL__ */
236
Thomas Gleixner8fc37f22007-10-23 22:37:24 +0200237#endif /* !__ASSEMBLY__ */
238
Thomas Gleixner96a388d2007-10-11 11:20:03 +0200239#endif