blob: 61946fe8c0853295125d8ce16f2371e28ccf6b96 [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;
73extern void send_sigtrap(struct task_struct *tsk, struct pt_regs *regs, int error_code);
74
75/*
76 * user_mode_vm(regs) determines whether a register set came from user mode.
77 * This is true if V8086 mode was enabled OR if the register set was from
78 * protected mode with RPL-3 CS value. This tricky test checks that with
79 * one comparison. Many places in the kernel can bypass this full check
80 * if they have already ruled out V8086 mode, so user_mode(regs) can be used.
81 */
82static inline int user_mode(struct pt_regs *regs)
83{
H. Peter Anvin65ea5b02008-01-30 13:30:56 +010084 return (regs->cs & SEGMENT_RPL_MASK) == USER_RPL;
Thomas Gleixner8fc37f22007-10-23 22:37:24 +020085}
86static inline int user_mode_vm(struct pt_regs *regs)
87{
H. Peter Anvin65ea5b02008-01-30 13:30:56 +010088 return ((regs->cs & SEGMENT_RPL_MASK) |
89 (regs->flags & VM_MASK)) >= USER_RPL;
Thomas Gleixner8fc37f22007-10-23 22:37:24 +020090}
91static inline int v8086_mode(struct pt_regs *regs)
92{
H. Peter Anvin65ea5b02008-01-30 13:30:56 +010093 return (regs->flags & VM_MASK);
Thomas Gleixner8fc37f22007-10-23 22:37:24 +020094}
95
H. Peter Anvin65ea5b02008-01-30 13:30:56 +010096#define instruction_pointer(regs) ((regs)->ip)
97#define frame_pointer(regs) ((regs)->bp)
Jan Blunck77f28782007-11-14 17:00:42 -080098#define stack_pointer(regs) ((unsigned long)(regs))
H. Peter Anvin65ea5b02008-01-30 13:30:56 +010099#define regs_return_value(regs) ((regs)->ax)
Thomas Gleixner8fc37f22007-10-23 22:37:24 +0200100
101extern unsigned long profile_pc(struct pt_regs *regs);
102#endif /* __KERNEL__ */
103
104#else /* __i386__ */
105
H. Peter Anvin65ea5b02008-01-30 13:30:56 +0100106#ifndef __KERNEL__
107
Thomas Gleixner8fc37f22007-10-23 22:37:24 +0200108struct pt_regs {
109 unsigned long r15;
110 unsigned long r14;
111 unsigned long r13;
112 unsigned long r12;
113 unsigned long rbp;
114 unsigned long rbx;
115/* arguments: non interrupts/non tracing syscalls only save upto here*/
116 unsigned long r11;
117 unsigned long r10;
118 unsigned long r9;
119 unsigned long r8;
120 unsigned long rax;
121 unsigned long rcx;
122 unsigned long rdx;
123 unsigned long rsi;
124 unsigned long rdi;
125 unsigned long orig_rax;
126/* end of arguments */
127/* cpu exception frame or undefined */
128 unsigned long rip;
129 unsigned long cs;
130 unsigned long eflags;
131 unsigned long rsp;
132 unsigned long ss;
133/* top of stack page */
134};
135
H. Peter Anvin65ea5b02008-01-30 13:30:56 +0100136#else /* __KERNEL__ */
137
138struct pt_regs {
139 unsigned long r15;
140 unsigned long r14;
141 unsigned long r13;
142 unsigned long r12;
143 unsigned long bp;
144 unsigned long bx;
145/* arguments: non interrupts/non tracing syscalls only save upto here*/
146 unsigned long r11;
147 unsigned long r10;
148 unsigned long r9;
149 unsigned long r8;
150 unsigned long ax;
151 unsigned long cx;
152 unsigned long dx;
153 unsigned long si;
154 unsigned long di;
155 unsigned long orig_ax;
156/* end of arguments */
157/* cpu exception frame or undefined */
158 unsigned long ip;
159 unsigned long cs;
160 unsigned long flags;
161 unsigned long sp;
162 unsigned long ss;
163/* top of stack page */
164};
Thomas Gleixner8fc37f22007-10-23 22:37:24 +0200165
166#define user_mode(regs) (!!((regs)->cs & 3))
167#define user_mode_vm(regs) user_mode(regs)
H. Peter Anvin65ea5b02008-01-30 13:30:56 +0100168#define v8086_mode(regs) 0 /* No V86 mode support in long mode */
169#define instruction_pointer(regs) ((regs)->ip)
170#define frame_pointer(regs) ((regs)->bp)
171#define stack_pointer(regs) ((regs)->sp)
172#define regs_return_value(regs) ((regs)->ax)
Thomas Gleixner8fc37f22007-10-23 22:37:24 +0200173
174extern unsigned long profile_pc(struct pt_regs *regs);
175void signal_fault(struct pt_regs *regs, void __user *frame, char *where);
176
177struct task_struct;
178
179extern unsigned long
180convert_rip_to_linear(struct task_struct *child, struct pt_regs *regs);
181
Thomas Gleixner8fc37f22007-10-23 22:37:24 +0200182#endif /* __KERNEL__ */
183#endif /* !__i386__ */
Roland McGrathefd1ca52008-01-30 13:30:46 +0100184
185#ifdef __KERNEL__
186
Roland McGrath7f232342008-01-30 13:30:48 +0100187/*
188 * These are defined as per linux/ptrace.h, which see.
189 */
190#define arch_has_single_step() (1)
191extern void user_enable_single_step(struct task_struct *);
192extern void user_disable_single_step(struct task_struct *);
193
Roland McGrath10faa812008-01-30 13:30:54 +0100194extern void user_enable_block_step(struct task_struct *);
195#ifdef CONFIG_X86_DEBUGCTLMSR
196#define arch_has_block_step() (1)
197#else
198#define arch_has_block_step() (boot_cpu_data.x86 >= 6)
199#endif
200
Roland McGrathefd1ca52008-01-30 13:30:46 +0100201struct user_desc;
202extern int do_get_thread_area(struct task_struct *p, int idx,
203 struct user_desc __user *info);
204extern int do_set_thread_area(struct task_struct *p, int idx,
205 struct user_desc __user *info, int can_allocate);
206
207#endif /* __KERNEL__ */
208
Thomas Gleixner8fc37f22007-10-23 22:37:24 +0200209#endif /* !__ASSEMBLY__ */
210
Thomas Gleixner96a388d2007-10-11 11:20:03 +0200211#endif