Linux 2.6.21-rc3
[linux-2.6/next.git] / arch / um / include / sysdep-x86_64 / ptrace.h
blob66cb400c2c92bb18e103036ff299e76b52512b96
1 /*
2 * Copyright 2003 PathScale, Inc.
4 * Licensed under the GPL
5 */
7 #ifndef __SYSDEP_X86_64_PTRACE_H
8 #define __SYSDEP_X86_64_PTRACE_H
10 #include "uml-config.h"
11 #include "user_constants.h"
12 #include "sysdep/faultinfo.h"
14 #define MAX_REG_OFFSET (UM_FRAME_SIZE)
15 #define MAX_REG_NR ((MAX_REG_OFFSET) / sizeof(unsigned long))
17 #ifdef UML_CONFIG_MODE_TT
18 #include "sysdep/sc.h"
19 #endif
21 #ifdef UML_CONFIG_MODE_SKAS
22 #include "skas_ptregs.h"
24 #define REGS_IP(r) ((r)[HOST_IP])
25 #define REGS_SP(r) ((r)[HOST_SP])
27 #define REGS_RBX(r) ((r)[HOST_RBX])
28 #define REGS_RCX(r) ((r)[HOST_RCX])
29 #define REGS_RDX(r) ((r)[HOST_RDX])
30 #define REGS_RSI(r) ((r)[HOST_RSI])
31 #define REGS_RDI(r) ((r)[HOST_RDI])
32 #define REGS_RBP(r) ((r)[HOST_RBP])
33 #define REGS_RAX(r) ((r)[HOST_RAX])
34 #define REGS_R8(r) ((r)[HOST_R8])
35 #define REGS_R9(r) ((r)[HOST_R9])
36 #define REGS_R10(r) ((r)[HOST_R10])
37 #define REGS_R11(r) ((r)[HOST_R11])
38 #define REGS_R12(r) ((r)[HOST_R12])
39 #define REGS_R13(r) ((r)[HOST_R13])
40 #define REGS_R14(r) ((r)[HOST_R14])
41 #define REGS_R15(r) ((r)[HOST_R15])
42 #define REGS_CS(r) ((r)[HOST_CS])
43 #define REGS_EFLAGS(r) ((r)[HOST_EFLAGS])
44 #define REGS_SS(r) ((r)[HOST_SS])
46 #define HOST_FS_BASE 21
47 #define HOST_GS_BASE 22
48 #define HOST_DS 23
49 #define HOST_ES 24
50 #define HOST_FS 25
51 #define HOST_GS 26
53 /* Also defined in asm/ptrace-x86_64.h, but not in libc headers. So, these
54 * are already defined for kernel code, but not for userspace code.
56 #ifndef FS_BASE
57 /* These aren't defined in ptrace.h, but exist in struct user_regs_struct,
58 * which is what x86_64 ptrace actually uses.
60 #define FS_BASE (HOST_FS_BASE * sizeof(long))
61 #define GS_BASE (HOST_GS_BASE * sizeof(long))
62 #define DS (HOST_DS * sizeof(long))
63 #define ES (HOST_ES * sizeof(long))
64 #define FS (HOST_FS * sizeof(long))
65 #define GS (HOST_GS * sizeof(long))
66 #endif
68 #define REGS_FS_BASE(r) ((r)[HOST_FS_BASE])
69 #define REGS_GS_BASE(r) ((r)[HOST_GS_BASE])
70 #define REGS_DS(r) ((r)[HOST_DS])
71 #define REGS_ES(r) ((r)[HOST_ES])
72 #define REGS_FS(r) ((r)[HOST_FS])
73 #define REGS_GS(r) ((r)[HOST_GS])
75 #define REGS_ORIG_RAX(r) ((r)[HOST_ORIG_RAX])
77 #define REGS_SET_SYSCALL_RETURN(r, res) REGS_RAX(r) = (res)
79 #define REGS_RESTART_SYSCALL(r) IP_RESTART_SYSCALL(REGS_IP(r))
81 #define REGS_SEGV_IS_FIXABLE(r) SEGV_IS_FIXABLE((r)->trap_type)
83 #define REGS_FAULT_ADDR(r) ((r)->fault_addr)
85 #define REGS_FAULT_WRITE(r) FAULT_WRITE((r)->fault_type)
87 #define REGS_TRAP(r) ((r)->trap_type)
89 #define REGS_ERR(r) ((r)->fault_type)
91 #endif
93 #include "choose-mode.h"
95 /* XXX */
96 union uml_pt_regs {
97 #ifdef UML_CONFIG_MODE_TT
98 struct tt_regs {
99 long syscall;
100 unsigned long orig_rax;
101 void *sc;
102 struct faultinfo faultinfo;
103 } tt;
104 #endif
105 #ifdef UML_CONFIG_MODE_SKAS
106 struct skas_regs {
107 /* x86_64 ptrace uses sizeof(user_regs_struct) as its register
108 * file size, while i386 uses FRAME_SIZE. Therefore, we need
109 * to use UM_FRAME_SIZE here instead of HOST_FRAME_SIZE.
111 unsigned long regs[MAX_REG_NR];
112 unsigned long fp[HOST_FP_SIZE];
113 struct faultinfo faultinfo;
114 long syscall;
115 int is_user;
116 } skas;
117 #endif
120 #define EMPTY_UML_PT_REGS { }
122 /* XXX */
123 extern int mode_tt;
125 #define UPT_RBX(r) __CHOOSE_MODE(SC_RBX(UPT_SC(r)), REGS_RBX((r)->skas.regs))
126 #define UPT_RCX(r) __CHOOSE_MODE(SC_RCX(UPT_SC(r)), REGS_RCX((r)->skas.regs))
127 #define UPT_RDX(r) __CHOOSE_MODE(SC_RDX(UPT_SC(r)), REGS_RDX((r)->skas.regs))
128 #define UPT_RSI(r) __CHOOSE_MODE(SC_RSI(UPT_SC(r)), REGS_RSI((r)->skas.regs))
129 #define UPT_RDI(r) __CHOOSE_MODE(SC_RDI(UPT_SC(r)), REGS_RDI((r)->skas.regs))
130 #define UPT_RBP(r) __CHOOSE_MODE(SC_RBP(UPT_SC(r)), REGS_RBP((r)->skas.regs))
131 #define UPT_RAX(r) __CHOOSE_MODE(SC_RAX(UPT_SC(r)), REGS_RAX((r)->skas.regs))
132 #define UPT_R8(r) __CHOOSE_MODE(SC_R8(UPT_SC(r)), REGS_R8((r)->skas.regs))
133 #define UPT_R9(r) __CHOOSE_MODE(SC_R9(UPT_SC(r)), REGS_R9((r)->skas.regs))
134 #define UPT_R10(r) __CHOOSE_MODE(SC_R10(UPT_SC(r)), REGS_R10((r)->skas.regs))
135 #define UPT_R11(r) __CHOOSE_MODE(SC_R11(UPT_SC(r)), REGS_R11((r)->skas.regs))
136 #define UPT_R12(r) __CHOOSE_MODE(SC_R12(UPT_SC(r)), REGS_R12((r)->skas.regs))
137 #define UPT_R13(r) __CHOOSE_MODE(SC_R13(UPT_SC(r)), REGS_R13((r)->skas.regs))
138 #define UPT_R14(r) __CHOOSE_MODE(SC_R14(UPT_SC(r)), REGS_R14((r)->skas.regs))
139 #define UPT_R15(r) __CHOOSE_MODE(SC_R15(UPT_SC(r)), REGS_R15((r)->skas.regs))
140 #define UPT_CS(r) __CHOOSE_MODE(SC_CS(UPT_SC(r)), REGS_CS((r)->skas.regs))
141 #define UPT_FS_BASE(r) \
142 __CHOOSE_MODE(SC_FS_BASE(UPT_SC(r)), REGS_FS_BASE((r)->skas.regs))
143 #define UPT_FS(r) __CHOOSE_MODE(SC_FS(UPT_SC(r)), REGS_FS((r)->skas.regs))
144 #define UPT_GS_BASE(r) \
145 __CHOOSE_MODE(SC_GS_BASE(UPT_SC(r)), REGS_GS_BASE((r)->skas.regs))
146 #define UPT_GS(r) __CHOOSE_MODE(SC_GS(UPT_SC(r)), REGS_GS((r)->skas.regs))
147 #define UPT_DS(r) __CHOOSE_MODE(SC_DS(UPT_SC(r)), REGS_DS((r)->skas.regs))
148 #define UPT_ES(r) __CHOOSE_MODE(SC_ES(UPT_SC(r)), REGS_ES((r)->skas.regs))
149 #define UPT_CS(r) __CHOOSE_MODE(SC_CS(UPT_SC(r)), REGS_CS((r)->skas.regs))
150 #define UPT_SS(r) __CHOOSE_MODE(SC_SS(UPT_SC(r)), REGS_SS((r)->skas.regs))
151 #define UPT_ORIG_RAX(r) \
152 __CHOOSE_MODE((r)->tt.orig_rax, REGS_ORIG_RAX((r)->skas.regs))
154 #define UPT_IP(r) __CHOOSE_MODE(SC_IP(UPT_SC(r)), REGS_IP((r)->skas.regs))
155 #define UPT_SP(r) __CHOOSE_MODE(SC_SP(UPT_SC(r)), REGS_SP((r)->skas.regs))
157 #define UPT_EFLAGS(r) \
158 __CHOOSE_MODE(SC_EFLAGS(UPT_SC(r)), REGS_EFLAGS((r)->skas.regs))
159 #define UPT_SC(r) ((r)->tt.sc)
160 #define UPT_SYSCALL_NR(r) __CHOOSE_MODE((r)->tt.syscall, (r)->skas.syscall)
161 #define UPT_SYSCALL_RET(r) UPT_RAX(r)
163 extern int user_context(unsigned long sp);
165 #define UPT_IS_USER(r) \
166 CHOOSE_MODE(user_context(UPT_SP(r)), (r)->skas.is_user)
168 #define UPT_SYSCALL_ARG1(r) UPT_RDI(r)
169 #define UPT_SYSCALL_ARG2(r) UPT_RSI(r)
170 #define UPT_SYSCALL_ARG3(r) UPT_RDX(r)
171 #define UPT_SYSCALL_ARG4(r) UPT_R10(r)
172 #define UPT_SYSCALL_ARG5(r) UPT_R8(r)
173 #define UPT_SYSCALL_ARG6(r) UPT_R9(r)
175 struct syscall_args {
176 unsigned long args[6];
179 #define SYSCALL_ARGS(r) ((struct syscall_args) \
180 { .args = { UPT_SYSCALL_ARG1(r), \
181 UPT_SYSCALL_ARG2(r), \
182 UPT_SYSCALL_ARG3(r), \
183 UPT_SYSCALL_ARG4(r), \
184 UPT_SYSCALL_ARG5(r), \
185 UPT_SYSCALL_ARG6(r) } } )
187 #define UPT_REG(regs, reg) \
188 ({ unsigned long val; \
189 switch(reg){ \
190 case R8: val = UPT_R8(regs); break; \
191 case R9: val = UPT_R9(regs); break; \
192 case R10: val = UPT_R10(regs); break; \
193 case R11: val = UPT_R11(regs); break; \
194 case R12: val = UPT_R12(regs); break; \
195 case R13: val = UPT_R13(regs); break; \
196 case R14: val = UPT_R14(regs); break; \
197 case R15: val = UPT_R15(regs); break; \
198 case RIP: val = UPT_IP(regs); break; \
199 case RSP: val = UPT_SP(regs); break; \
200 case RAX: val = UPT_RAX(regs); break; \
201 case RBX: val = UPT_RBX(regs); break; \
202 case RCX: val = UPT_RCX(regs); break; \
203 case RDX: val = UPT_RDX(regs); break; \
204 case RSI: val = UPT_RSI(regs); break; \
205 case RDI: val = UPT_RDI(regs); break; \
206 case RBP: val = UPT_RBP(regs); break; \
207 case ORIG_RAX: val = UPT_ORIG_RAX(regs); break; \
208 case CS: val = UPT_CS(regs); break; \
209 case SS: val = UPT_SS(regs); break; \
210 case FS_BASE: val = UPT_FS_BASE(regs); break; \
211 case GS_BASE: val = UPT_GS_BASE(regs); break; \
212 case DS: val = UPT_DS(regs); break; \
213 case ES: val = UPT_ES(regs); break; \
214 case FS : val = UPT_FS (regs); break; \
215 case GS: val = UPT_GS(regs); break; \
216 case EFLAGS: val = UPT_EFLAGS(regs); break; \
217 default : \
218 panic("Bad register in UPT_REG : %d\n", reg); \
219 val = -1; \
221 val; \
225 #define UPT_SET(regs, reg, val) \
226 ({ unsigned long __upt_val = val; \
227 switch(reg){ \
228 case R8: UPT_R8(regs) = __upt_val; break; \
229 case R9: UPT_R9(regs) = __upt_val; break; \
230 case R10: UPT_R10(regs) = __upt_val; break; \
231 case R11: UPT_R11(regs) = __upt_val; break; \
232 case R12: UPT_R12(regs) = __upt_val; break; \
233 case R13: UPT_R13(regs) = __upt_val; break; \
234 case R14: UPT_R14(regs) = __upt_val; break; \
235 case R15: UPT_R15(regs) = __upt_val; break; \
236 case RIP: UPT_IP(regs) = __upt_val; break; \
237 case RSP: UPT_SP(regs) = __upt_val; break; \
238 case RAX: UPT_RAX(regs) = __upt_val; break; \
239 case RBX: UPT_RBX(regs) = __upt_val; break; \
240 case RCX: UPT_RCX(regs) = __upt_val; break; \
241 case RDX: UPT_RDX(regs) = __upt_val; break; \
242 case RSI: UPT_RSI(regs) = __upt_val; break; \
243 case RDI: UPT_RDI(regs) = __upt_val; break; \
244 case RBP: UPT_RBP(regs) = __upt_val; break; \
245 case ORIG_RAX: UPT_ORIG_RAX(regs) = __upt_val; break; \
246 case CS: UPT_CS(regs) = __upt_val; break; \
247 case SS: UPT_SS(regs) = __upt_val; break; \
248 case FS_BASE: UPT_FS_BASE(regs) = __upt_val; break; \
249 case GS_BASE: UPT_GS_BASE(regs) = __upt_val; break; \
250 case DS: UPT_DS(regs) = __upt_val; break; \
251 case ES: UPT_ES(regs) = __upt_val; break; \
252 case FS: UPT_FS(regs) = __upt_val; break; \
253 case GS: UPT_GS(regs) = __upt_val; break; \
254 case EFLAGS: UPT_EFLAGS(regs) = __upt_val; break; \
255 default : \
256 panic("Bad register in UPT_SET : %d\n", reg); \
257 break; \
259 __upt_val; \
262 #define UPT_SET_SYSCALL_RETURN(r, res) \
263 CHOOSE_MODE(SC_SET_SYSCALL_RETURN(UPT_SC(r), (res)), \
264 REGS_SET_SYSCALL_RETURN((r)->skas.regs, (res)))
266 #define UPT_RESTART_SYSCALL(r) \
267 CHOOSE_MODE(SC_RESTART_SYSCALL(UPT_SC(r)), \
268 REGS_RESTART_SYSCALL((r)->skas.regs))
270 #define UPT_SEGV_IS_FIXABLE(r) \
271 CHOOSE_MODE(SC_SEGV_IS_FIXABLE(UPT_SC(r)), \
272 REGS_SEGV_IS_FIXABLE(&r->skas))
274 #define UPT_FAULTINFO(r) \
275 CHOOSE_MODE((&(r)->tt.faultinfo), (&(r)->skas.faultinfo))
277 #endif