blob: 04204f3592983a231b33a957d6fe8f4d54ecd7fc [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
7#ifndef __ASSEMBLY__
8
9#ifdef __i386__
10/* this struct defines the way the registers are stored on the
11 stack during a system call. */
12
13struct pt_regs {
14 long ebx;
15 long ecx;
16 long edx;
17 long esi;
18 long edi;
19 long ebp;
20 long eax;
21 int xds;
22 int xes;
23 int xfs;
24 /* int xgs; */
25 long orig_eax;
26 long eip;
27 int xcs;
28 long eflags;
29 long esp;
30 int xss;
31};
32
Thomas Gleixner96a388d2007-10-11 11:20:03 +020033#ifdef __KERNEL__
Thomas Gleixner8fc37f22007-10-23 22:37:24 +020034
35#include <asm/vm86.h>
36#include <asm/segment.h>
37
38struct task_struct;
39extern void send_sigtrap(struct task_struct *tsk, struct pt_regs *regs, int error_code);
40
41/*
42 * user_mode_vm(regs) determines whether a register set came from user mode.
43 * This is true if V8086 mode was enabled OR if the register set was from
44 * protected mode with RPL-3 CS value. This tricky test checks that with
45 * one comparison. Many places in the kernel can bypass this full check
46 * if they have already ruled out V8086 mode, so user_mode(regs) can be used.
47 */
48static inline int user_mode(struct pt_regs *regs)
49{
50 return (regs->xcs & SEGMENT_RPL_MASK) == USER_RPL;
51}
52static inline int user_mode_vm(struct pt_regs *regs)
53{
54 return ((regs->xcs & SEGMENT_RPL_MASK) | (regs->eflags & VM_MASK)) >= USER_RPL;
55}
56static inline int v8086_mode(struct pt_regs *regs)
57{
58 return (regs->eflags & VM_MASK);
59}
60
61#define instruction_pointer(regs) ((regs)->eip)
62#define frame_pointer(regs) ((regs)->ebp)
Jan Blunck77f28782007-11-14 17:00:42 -080063#define stack_pointer(regs) ((unsigned long)(regs))
Thomas Gleixner8fc37f22007-10-23 22:37:24 +020064#define regs_return_value(regs) ((regs)->eax)
65
66extern unsigned long profile_pc(struct pt_regs *regs);
67#endif /* __KERNEL__ */
68
69#else /* __i386__ */
70
71struct pt_regs {
72 unsigned long r15;
73 unsigned long r14;
74 unsigned long r13;
75 unsigned long r12;
76 unsigned long rbp;
77 unsigned long rbx;
78/* arguments: non interrupts/non tracing syscalls only save upto here*/
79 unsigned long r11;
80 unsigned long r10;
81 unsigned long r9;
82 unsigned long r8;
83 unsigned long rax;
84 unsigned long rcx;
85 unsigned long rdx;
86 unsigned long rsi;
87 unsigned long rdi;
88 unsigned long orig_rax;
89/* end of arguments */
90/* cpu exception frame or undefined */
91 unsigned long rip;
92 unsigned long cs;
93 unsigned long eflags;
94 unsigned long rsp;
95 unsigned long ss;
96/* top of stack page */
97};
98
99#ifdef __KERNEL__
100
101#define user_mode(regs) (!!((regs)->cs & 3))
102#define user_mode_vm(regs) user_mode(regs)
103#define instruction_pointer(regs) ((regs)->rip)
104#define frame_pointer(regs) ((regs)->rbp)
105#define stack_pointer(regs) ((regs)->rsp)
106#define regs_return_value(regs) ((regs)->rax)
107
108extern unsigned long profile_pc(struct pt_regs *regs);
109void signal_fault(struct pt_regs *regs, void __user *frame, char *where);
110
111struct task_struct;
112
Roland McGrath962ff382008-01-30 13:30:52 +0100113extern unsigned long ptrace_get_debugreg(struct task_struct *child, int n);
114extern int ptrace_set_debugreg(struct task_struct *child, int n, unsigned long);
115
Thomas Gleixner8fc37f22007-10-23 22:37:24 +0200116extern unsigned long
117convert_rip_to_linear(struct task_struct *child, struct pt_regs *regs);
118
119enum {
120 EF_CF = 0x00000001,
121 EF_PF = 0x00000004,
122 EF_AF = 0x00000010,
123 EF_ZF = 0x00000040,
124 EF_SF = 0x00000080,
125 EF_TF = 0x00000100,
126 EF_IE = 0x00000200,
127 EF_DF = 0x00000400,
128 EF_OF = 0x00000800,
129 EF_IOPL = 0x00003000,
130 EF_IOPL_RING0 = 0x00000000,
131 EF_IOPL_RING1 = 0x00001000,
132 EF_IOPL_RING2 = 0x00002000,
133 EF_NT = 0x00004000, /* nested task */
134 EF_RF = 0x00010000, /* resume */
135 EF_VM = 0x00020000, /* virtual mode */
136 EF_AC = 0x00040000, /* alignment */
137 EF_VIF = 0x00080000, /* virtual interrupt */
138 EF_VIP = 0x00100000, /* virtual interrupt pending */
139 EF_ID = 0x00200000, /* id */
140};
141#endif /* __KERNEL__ */
142#endif /* !__i386__ */
Roland McGrathefd1ca52008-01-30 13:30:46 +0100143
144#ifdef __KERNEL__
145
Roland McGrath7f232342008-01-30 13:30:48 +0100146/*
147 * These are defined as per linux/ptrace.h, which see.
148 */
149#define arch_has_single_step() (1)
150extern void user_enable_single_step(struct task_struct *);
151extern void user_disable_single_step(struct task_struct *);
152
Roland McGrath10faa812008-01-30 13:30:54 +0100153extern void user_enable_block_step(struct task_struct *);
154#ifdef CONFIG_X86_DEBUGCTLMSR
155#define arch_has_block_step() (1)
156#else
157#define arch_has_block_step() (boot_cpu_data.x86 >= 6)
158#endif
159
Roland McGrathefd1ca52008-01-30 13:30:46 +0100160struct user_desc;
161extern int do_get_thread_area(struct task_struct *p, int idx,
162 struct user_desc __user *info);
163extern int do_set_thread_area(struct task_struct *p, int idx,
164 struct user_desc __user *info, int can_allocate);
165
166#endif /* __KERNEL__ */
167
Thomas Gleixner8fc37f22007-10-23 22:37:24 +0200168#endif /* !__ASSEMBLY__ */
169
Thomas Gleixner96a388d2007-10-11 11:20:03 +0200170#endif