2 * Copyright 2003 PathScale, Inc.
4 * Licensed under the GPL
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"
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
53 #define REGS_FS_BASE(r) ((r)[HOST_FS_BASE])
54 #define REGS_GS_BASE(r) ((r)[HOST_GS_BASE])
55 #define REGS_DS(r) ((r)[HOST_DS])
56 #define REGS_ES(r) ((r)[HOST_ES])
57 #define REGS_FS(r) ((r)[HOST_FS])
58 #define REGS_GS(r) ((r)[HOST_GS])
60 #define REGS_ORIG_RAX(r) ((r)[HOST_ORIG_RAX])
62 #define REGS_SET_SYSCALL_RETURN(r, res) REGS_RAX(r) = (res)
64 #define REGS_RESTART_SYSCALL(r) IP_RESTART_SYSCALL(REGS_IP(r))
66 #define REGS_SEGV_IS_FIXABLE(r) SEGV_IS_FIXABLE((r)->trap_type)
68 #define REGS_FAULT_ADDR(r) ((r)->fault_addr)
70 #define REGS_FAULT_WRITE(r) FAULT_WRITE((r)->fault_type)
72 #define REGS_TRAP(r) ((r)->trap_type)
74 #define REGS_ERR(r) ((r)->fault_type)
78 #include "choose-mode.h"
82 #ifdef UML_CONFIG_MODE_TT
85 unsigned long orig_rax;
87 struct faultinfo faultinfo;
90 #ifdef UML_CONFIG_MODE_SKAS
93 unsigned long regs[27];
95 struct faultinfo faultinfo;
102 #define EMPTY_UML_PT_REGS { }
107 #define UPT_RBX(r) __CHOOSE_MODE(SC_RBX(UPT_SC(r)), REGS_RBX((r)->skas.regs))
108 #define UPT_RCX(r) __CHOOSE_MODE(SC_RCX(UPT_SC(r)), REGS_RCX((r)->skas.regs))
109 #define UPT_RDX(r) __CHOOSE_MODE(SC_RDX(UPT_SC(r)), REGS_RDX((r)->skas.regs))
110 #define UPT_RSI(r) __CHOOSE_MODE(SC_RSI(UPT_SC(r)), REGS_RSI((r)->skas.regs))
111 #define UPT_RDI(r) __CHOOSE_MODE(SC_RDI(UPT_SC(r)), REGS_RDI((r)->skas.regs))
112 #define UPT_RBP(r) __CHOOSE_MODE(SC_RBP(UPT_SC(r)), REGS_RBP((r)->skas.regs))
113 #define UPT_RAX(r) __CHOOSE_MODE(SC_RAX(UPT_SC(r)), REGS_RAX((r)->skas.regs))
114 #define UPT_R8(r) __CHOOSE_MODE(SC_R8(UPT_SC(r)), REGS_R8((r)->skas.regs))
115 #define UPT_R9(r) __CHOOSE_MODE(SC_R9(UPT_SC(r)), REGS_R9((r)->skas.regs))
116 #define UPT_R10(r) __CHOOSE_MODE(SC_R10(UPT_SC(r)), REGS_R10((r)->skas.regs))
117 #define UPT_R11(r) __CHOOSE_MODE(SC_R11(UPT_SC(r)), REGS_R11((r)->skas.regs))
118 #define UPT_R12(r) __CHOOSE_MODE(SC_R12(UPT_SC(r)), REGS_R12((r)->skas.regs))
119 #define UPT_R13(r) __CHOOSE_MODE(SC_R13(UPT_SC(r)), REGS_R13((r)->skas.regs))
120 #define UPT_R14(r) __CHOOSE_MODE(SC_R14(UPT_SC(r)), REGS_R14((r)->skas.regs))
121 #define UPT_R15(r) __CHOOSE_MODE(SC_R15(UPT_SC(r)), REGS_R15((r)->skas.regs))
122 #define UPT_CS(r) __CHOOSE_MODE(SC_CS(UPT_SC(r)), REGS_CS((r)->skas.regs))
123 #define UPT_FS(r) __CHOOSE_MODE(SC_FS(UPT_SC(r)), REGS_FS((r)->skas.regs))
124 #define UPT_GS(r) __CHOOSE_MODE(SC_GS(UPT_SC(r)), REGS_GS((r)->skas.regs))
125 #define UPT_DS(r) __CHOOSE_MODE(SC_DS(UPT_SC(r)), REGS_DS((r)->skas.regs))
126 #define UPT_ES(r) __CHOOSE_MODE(SC_ES(UPT_SC(r)), REGS_ES((r)->skas.regs))
127 #define UPT_CS(r) __CHOOSE_MODE(SC_CS(UPT_SC(r)), REGS_CS((r)->skas.regs))
128 #define UPT_ORIG_RAX(r) \
129 __CHOOSE_MODE((r)->tt.orig_rax, REGS_ORIG_RAX((r)->skas.regs))
131 #define UPT_IP(r) __CHOOSE_MODE(SC_IP(UPT_SC(r)), REGS_IP((r)->skas.regs))
132 #define UPT_SP(r) __CHOOSE_MODE(SC_SP(UPT_SC(r)), REGS_SP((r)->skas.regs))
134 #define UPT_EFLAGS(r) \
135 __CHOOSE_MODE(SC_EFLAGS(UPT_SC(r)), REGS_EFLAGS((r)->skas.regs))
136 #define UPT_SC(r) ((r)->tt.sc)
137 #define UPT_SYSCALL_NR(r) __CHOOSE_MODE((r)->tt.syscall, (r)->skas.syscall)
138 #define UPT_SYSCALL_RET(r) UPT_RAX(r)
140 extern int user_context(unsigned long sp);
142 #define UPT_IS_USER(r) \
143 CHOOSE_MODE(user_context(UPT_SP(r)), (r)->skas.is_user)
145 #define UPT_SYSCALL_ARG1(r) UPT_RDI(r)
146 #define UPT_SYSCALL_ARG2(r) UPT_RSI(r)
147 #define UPT_SYSCALL_ARG3(r) UPT_RDX(r)
148 #define UPT_SYSCALL_ARG4(r) UPT_R10(r)
149 #define UPT_SYSCALL_ARG5(r) UPT_R8(r)
150 #define UPT_SYSCALL_ARG6(r) UPT_R9(r)
152 struct syscall_args {
153 unsigned long args[6];
156 #define SYSCALL_ARGS(r) ((struct syscall_args) \
157 { .args = { UPT_SYSCALL_ARG1(r), \
158 UPT_SYSCALL_ARG2(r), \
159 UPT_SYSCALL_ARG3(r), \
160 UPT_SYSCALL_ARG4(r), \
161 UPT_SYSCALL_ARG5(r), \
162 UPT_SYSCALL_ARG6(r) } } )
164 #define UPT_REG(regs, reg) \
165 ({ unsigned long val; \
167 case R8: val = UPT_R8(regs); break; \
168 case R9: val = UPT_R9(regs); break; \
169 case R10: val = UPT_R10(regs); break; \
170 case R11: val = UPT_R11(regs); break; \
171 case R12: val = UPT_R12(regs); break; \
172 case R13: val = UPT_R13(regs); break; \
173 case R14: val = UPT_R14(regs); break; \
174 case R15: val = UPT_R15(regs); break; \
175 case RIP: val = UPT_IP(regs); break; \
176 case RSP: val = UPT_SP(regs); break; \
177 case RAX: val = UPT_RAX(regs); break; \
178 case RBX: val = UPT_RBX(regs); break; \
179 case RCX: val = UPT_RCX(regs); break; \
180 case RDX: val = UPT_RDX(regs); break; \
181 case RSI: val = UPT_RSI(regs); break; \
182 case RDI: val = UPT_RDI(regs); break; \
183 case RBP: val = UPT_RBP(regs); break; \
184 case ORIG_RAX: val = UPT_ORIG_RAX(regs); break; \
185 case CS: val = UPT_CS(regs); break; \
186 case DS: val = UPT_DS(regs); break; \
187 case ES: val = UPT_ES(regs); break; \
188 case FS: val = UPT_FS(regs); break; \
189 case GS: val = UPT_GS(regs); break; \
190 case EFLAGS: val = UPT_EFLAGS(regs); break; \
192 panic("Bad register in UPT_REG : %d\n", reg); \
199 #define UPT_SET(regs, reg, val) \
200 ({ unsigned long __upt_val = val; \
202 case R8: UPT_R8(regs) = __upt_val; break; \
203 case R9: UPT_R9(regs) = __upt_val; break; \
204 case R10: UPT_R10(regs) = __upt_val; break; \
205 case R11: UPT_R11(regs) = __upt_val; break; \
206 case R12: UPT_R12(regs) = __upt_val; break; \
207 case R13: UPT_R13(regs) = __upt_val; break; \
208 case R14: UPT_R14(regs) = __upt_val; break; \
209 case R15: UPT_R15(regs) = __upt_val; break; \
210 case RIP: UPT_IP(regs) = __upt_val; break; \
211 case RSP: UPT_SP(regs) = __upt_val; break; \
212 case RAX: UPT_RAX(regs) = __upt_val; break; \
213 case RBX: UPT_RBX(regs) = __upt_val; break; \
214 case RCX: UPT_RCX(regs) = __upt_val; break; \
215 case RDX: UPT_RDX(regs) = __upt_val; break; \
216 case RSI: UPT_RSI(regs) = __upt_val; break; \
217 case RDI: UPT_RDI(regs) = __upt_val; break; \
218 case RBP: UPT_RBP(regs) = __upt_val; break; \
219 case ORIG_RAX: UPT_ORIG_RAX(regs) = __upt_val; break; \
220 case CS: UPT_CS(regs) = __upt_val; break; \
221 case DS: UPT_DS(regs) = __upt_val; break; \
222 case ES: UPT_ES(regs) = __upt_val; break; \
223 case FS: UPT_FS(regs) = __upt_val; break; \
224 case GS: UPT_GS(regs) = __upt_val; break; \
225 case EFLAGS: UPT_EFLAGS(regs) = __upt_val; break; \
227 panic("Bad register in UPT_SET : %d\n", reg); \
233 #define UPT_SET_SYSCALL_RETURN(r, res) \
234 CHOOSE_MODE(SC_SET_SYSCALL_RETURN(UPT_SC(r), (res)), \
235 REGS_SET_SYSCALL_RETURN((r)->skas.regs, (res)))
237 #define UPT_RESTART_SYSCALL(r) \
238 CHOOSE_MODE(SC_RESTART_SYSCALL(UPT_SC(r)), \
239 REGS_RESTART_SYSCALL((r)->skas.regs))
241 #define UPT_SEGV_IS_FIXABLE(r) \
242 CHOOSE_MODE(SC_SEGV_IS_FIXABLE(UPT_SC(r)), \
243 REGS_SEGV_IS_FIXABLE(&r->skas))
245 #define UPT_FAULTINFO(r) \
246 CHOOSE_MODE((&(r)->tt.faultinfo), (&(r)->skas.faultinfo))