x86: unify pt_regs accessors ptrace.h
[sfrench/cifs-2.6.git] / include / asm-x86 / ptrace.h
1 #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
7
8 #ifndef __ASSEMBLY__
9
10 #ifdef __KERNEL__
11
12 /* the DS BTS struct is used for ptrace as well */
13 #include <asm/ds.h>
14
15 struct task_struct;
16 extern void ptrace_bts_take_timestamp(struct task_struct *, enum bts_qualifier);
17
18 #endif /* __KERNEL__ */
19
20
21 #ifdef __i386__
22 /* this struct defines the way the registers are stored on the
23    stack during a system call. */
24
25 #ifndef __KERNEL__
26
27 struct 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;
38         /* int  gs; */
39         long orig_eax;
40         long eip;
41         int  xcs;
42         long eflags;
43         long esp;
44         int  xss;
45 };
46
47 #else /* __KERNEL__ */
48
49 struct 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 };
68
69 #include <asm/vm86.h>
70 #include <asm/segment.h>
71
72 struct task_struct;
73
74 extern unsigned long
75 convert_ip_to_linear(struct task_struct *child, struct pt_regs *regs);
76
77 extern void send_sigtrap(struct task_struct *tsk, struct pt_regs *regs, int error_code);
78
79 #define regs_return_value(regs) ((regs)->ax)
80
81 extern unsigned long profile_pc(struct pt_regs *regs);
82 #endif /* __KERNEL__ */
83
84 #else /* __i386__ */
85
86 #ifndef __KERNEL__
87
88 struct 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
116 #else /* __KERNEL__ */
117
118 struct 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 };
145
146 #define regs_return_value(regs) ((regs)->ax)
147
148 extern unsigned long profile_pc(struct pt_regs *regs);
149 void signal_fault(struct pt_regs *regs, void __user *frame, char *where);
150
151 struct task_struct;
152
153 extern unsigned long
154 convert_ip_to_linear(struct task_struct *child, struct pt_regs *regs);
155
156 #endif /* __KERNEL__ */
157 #endif /* !__i386__ */
158
159 #ifdef __KERNEL__
160
161 /*
162  * 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  */
168 static 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
177 static 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
187 static 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
196 static 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
205 static inline unsigned long instruction_pointer(struct pt_regs *regs)
206 {
207         return regs->ip;
208 }
209
210 static inline unsigned long frame_pointer(struct pt_regs *regs)
211 {
212         return regs->bp;
213 }
214
215 /*
216  * These are defined as per linux/ptrace.h, which see.
217  */
218 #define arch_has_single_step()  (1)
219 extern void user_enable_single_step(struct task_struct *);
220 extern void user_disable_single_step(struct task_struct *);
221
222 extern 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
229 struct user_desc;
230 extern int do_get_thread_area(struct task_struct *p, int idx,
231                               struct user_desc __user *info);
232 extern 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
237 #endif /* !__ASSEMBLY__ */
238
239 #endif