blob: 79d5b8fcd7b15d2e0419c6748f21704cda1b67b2 [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
10#ifdef __i386__
11/* this struct defines the way the registers are stored on the
12 stack during a system call. */
13
H. Peter Anvin65ea5b02008-01-30 13:30:56 +010014#ifndef __KERNEL__
15
Thomas Gleixner8fc37f22007-10-23 22:37:24 +020016struct pt_regs {
17 long ebx;
18 long ecx;
19 long edx;
20 long esi;
21 long edi;
22 long ebp;
23 long eax;
24 int xds;
25 int xes;
26 int xfs;
H. Peter Anvin65ea5b02008-01-30 13:30:56 +010027 /* int gs; */
Thomas Gleixner8fc37f22007-10-23 22:37:24 +020028 long orig_eax;
29 long eip;
30 int xcs;
31 long eflags;
32 long esp;
33 int xss;
34};
35
H. Peter Anvin65ea5b02008-01-30 13:30:56 +010036#else /* __KERNEL__ */
37
38struct pt_regs {
39 long bx;
40 long cx;
41 long dx;
42 long si;
43 long di;
44 long bp;
45 long ax;
46 int ds;
47 int es;
48 int fs;
49 /* int gs; */
50 long orig_ax;
51 long ip;
52 int cs;
53 long flags;
54 long sp;
55 int ss;
56};
Thomas Gleixner8fc37f22007-10-23 22:37:24 +020057
58#include <asm/vm86.h>
59#include <asm/segment.h>
60
Thomas Gleixner8fc37f22007-10-23 22:37:24 +020061#endif /* __KERNEL__ */
62
63#else /* __i386__ */
64
H. Peter Anvin65ea5b02008-01-30 13:30:56 +010065#ifndef __KERNEL__
66
Thomas Gleixner8fc37f22007-10-23 22:37:24 +020067struct pt_regs {
68 unsigned long r15;
69 unsigned long r14;
70 unsigned long r13;
71 unsigned long r12;
72 unsigned long rbp;
73 unsigned long rbx;
74/* arguments: non interrupts/non tracing syscalls only save upto here*/
75 unsigned long r11;
76 unsigned long r10;
77 unsigned long r9;
78 unsigned long r8;
79 unsigned long rax;
80 unsigned long rcx;
81 unsigned long rdx;
82 unsigned long rsi;
83 unsigned long rdi;
84 unsigned long orig_rax;
85/* end of arguments */
86/* cpu exception frame or undefined */
87 unsigned long rip;
88 unsigned long cs;
89 unsigned long eflags;
90 unsigned long rsp;
91 unsigned long ss;
92/* top of stack page */
93};
94
H. Peter Anvin65ea5b02008-01-30 13:30:56 +010095#else /* __KERNEL__ */
96
97struct pt_regs {
98 unsigned long r15;
99 unsigned long r14;
100 unsigned long r13;
101 unsigned long r12;
102 unsigned long bp;
103 unsigned long bx;
104/* arguments: non interrupts/non tracing syscalls only save upto here*/
105 unsigned long r11;
106 unsigned long r10;
107 unsigned long r9;
108 unsigned long r8;
109 unsigned long ax;
110 unsigned long cx;
111 unsigned long dx;
112 unsigned long si;
113 unsigned long di;
114 unsigned long orig_ax;
115/* end of arguments */
116/* cpu exception frame or undefined */
117 unsigned long ip;
118 unsigned long cs;
119 unsigned long flags;
120 unsigned long sp;
121 unsigned long ss;
122/* top of stack page */
123};
Thomas Gleixner8fc37f22007-10-23 22:37:24 +0200124
Thomas Gleixner8fc37f22007-10-23 22:37:24 +0200125#endif /* __KERNEL__ */
126#endif /* !__i386__ */
Roland McGrathefd1ca52008-01-30 13:30:46 +0100127
128#ifdef __KERNEL__
129
Harvey Harrisondbe35332008-01-30 13:33:16 +0100130/* the DS BTS struct is used for ptrace as well */
131#include <asm/ds.h>
132
133struct task_struct;
134
135extern void ptrace_bts_take_timestamp(struct task_struct *, enum bts_qualifier);
136
137extern unsigned long profile_pc(struct pt_regs *regs);
138
139extern unsigned long
140convert_ip_to_linear(struct task_struct *child, struct pt_regs *regs);
141
142#ifdef CONFIG_X86_32
143extern void send_sigtrap(struct task_struct *tsk, struct pt_regs *regs, int error_code);
144#else
145void signal_fault(struct pt_regs *regs, void __user *frame, char *where);
146#endif
147
148#define regs_return_value(regs) ((regs)->ax)
149
Roland McGrath7f232342008-01-30 13:30:48 +0100150/*
Harvey Harrison90d43d72008-01-30 13:33:16 +0100151 * user_mode_vm(regs) determines whether a register set came from user mode.
152 * This is true if V8086 mode was enabled OR if the register set was from
153 * protected mode with RPL-3 CS value. This tricky test checks that with
154 * one comparison. Many places in the kernel can bypass this full check
155 * if they have already ruled out V8086 mode, so user_mode(regs) can be used.
156 */
157static inline int user_mode(struct pt_regs *regs)
158{
159#ifdef CONFIG_X86_32
160 return (regs->cs & SEGMENT_RPL_MASK) == USER_RPL;
161#else
162 return !!(regs->cs & 3);
163#endif
164}
165
166static inline int user_mode_vm(struct pt_regs *regs)
167{
168#ifdef CONFIG_X86_32
169 return ((regs->cs & SEGMENT_RPL_MASK) |
170 (regs->flags & VM_MASK)) >= USER_RPL;
171#else
172 return user_mode(regs);
173#endif
174}
175
176static inline int v8086_mode(struct pt_regs *regs)
177{
178#ifdef CONFIG_X86_32
179 return (regs->flags & VM_MASK);
180#else
181 return 0; /* No V86 mode support in long mode */
182#endif
183}
184
185static inline unsigned long stack_pointer(struct pt_regs *regs)
186{
187#ifdef CONFIG_X86_32
188 return (unsigned long)regs;
189#else
190 return regs->sp;
191#endif
192}
193
194static inline unsigned long instruction_pointer(struct pt_regs *regs)
195{
196 return regs->ip;
197}
198
199static inline unsigned long frame_pointer(struct pt_regs *regs)
200{
201 return regs->bp;
202}
203
204/*
Roland McGrath7f232342008-01-30 13:30:48 +0100205 * These are defined as per linux/ptrace.h, which see.
206 */
207#define arch_has_single_step() (1)
208extern void user_enable_single_step(struct task_struct *);
209extern void user_disable_single_step(struct task_struct *);
210
Roland McGrath10faa812008-01-30 13:30:54 +0100211extern void user_enable_block_step(struct task_struct *);
212#ifdef CONFIG_X86_DEBUGCTLMSR
213#define arch_has_block_step() (1)
214#else
215#define arch_has_block_step() (boot_cpu_data.x86 >= 6)
216#endif
217
Roland McGrathefd1ca52008-01-30 13:30:46 +0100218struct user_desc;
219extern int do_get_thread_area(struct task_struct *p, int idx,
220 struct user_desc __user *info);
221extern int do_set_thread_area(struct task_struct *p, int idx,
222 struct user_desc __user *info, int can_allocate);
223
224#endif /* __KERNEL__ */
225
Thomas Gleixner8fc37f22007-10-23 22:37:24 +0200226#endif /* !__ASSEMBLY__ */
227
Thomas Gleixner96a388d2007-10-11 11:20:03 +0200228#endif