blob: 661d495e2044888572abb7c7aeb4609dae07876b [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
2 * Copyright (C) 2000, 2001, 2002 Jeff Dike (jdike@karaya.com)
3 * Licensed under the GPL
4 */
5
6#ifndef __SYSDEP_I386_PTRACE_H
7#define __SYSDEP_I386_PTRACE_H
8
9#include "uml-config.h"
10#include "user_constants.h"
11
12#define MAX_REG_NR (UM_FRAME_SIZE / sizeof(unsigned long))
13#define MAX_REG_OFFSET (UM_FRAME_SIZE)
14
15extern void update_debugregs(int seq);
16
17/* syscall emulation path in ptrace */
18
19#ifndef PTRACE_SYSEMU
20#define PTRACE_SYSEMU 31
21#endif
22
23void set_using_sysemu(int value);
24int get_using_sysemu(void);
25extern int sysemu_supported;
26
27#ifdef UML_CONFIG_MODE_TT
28#include "sysdep/sc.h"
29#endif
30
31#ifdef UML_CONFIG_MODE_SKAS
32
33#include "skas_ptregs.h"
34
35#define REGS_IP(r) ((r)[HOST_IP])
36#define REGS_SP(r) ((r)[HOST_SP])
37#define REGS_EFLAGS(r) ((r)[HOST_EFLAGS])
38#define REGS_EAX(r) ((r)[HOST_EAX])
39#define REGS_EBX(r) ((r)[HOST_EBX])
40#define REGS_ECX(r) ((r)[HOST_ECX])
41#define REGS_EDX(r) ((r)[HOST_EDX])
42#define REGS_ESI(r) ((r)[HOST_ESI])
43#define REGS_EDI(r) ((r)[HOST_EDI])
44#define REGS_EBP(r) ((r)[HOST_EBP])
45#define REGS_CS(r) ((r)[HOST_CS])
46#define REGS_SS(r) ((r)[HOST_SS])
47#define REGS_DS(r) ((r)[HOST_DS])
48#define REGS_ES(r) ((r)[HOST_ES])
49#define REGS_FS(r) ((r)[HOST_FS])
50#define REGS_GS(r) ((r)[HOST_GS])
51
52#define REGS_SET_SYSCALL_RETURN(r, res) REGS_EAX(r) = (res)
53
54#define REGS_RESTART_SYSCALL(r) IP_RESTART_SYSCALL(REGS_IP(r))
55
56#define REGS_SEGV_IS_FIXABLE(r) SEGV_IS_FIXABLE((r)->trap_type)
57
58#define REGS_FAULT_ADDR(r) ((r)->fault_addr)
59
60#define REGS_FAULT_WRITE(r) FAULT_WRITE((r)->fault_type)
61
62#endif
63#ifndef PTRACE_SYSEMU_SINGLESTEP
64#define PTRACE_SYSEMU_SINGLESTEP 32
65#endif
66
67#include "choose-mode.h"
68
69union uml_pt_regs {
70#ifdef UML_CONFIG_MODE_TT
71 struct tt_regs {
72 long syscall;
73 void *sc;
74 } tt;
75#endif
76#ifdef UML_CONFIG_MODE_SKAS
77 struct skas_regs {
78 unsigned long regs[HOST_FRAME_SIZE];
79 unsigned long fp[HOST_FP_SIZE];
80 unsigned long xfp[HOST_XFP_SIZE];
81 unsigned long fault_addr;
82 unsigned long fault_type;
83 unsigned long trap_type;
84 long syscall;
85 int is_user;
86 } skas;
87#endif
88};
89
90#define EMPTY_UML_PT_REGS { }
91
92extern int mode_tt;
93
94#define UPT_SC(r) ((r)->tt.sc)
95#define UPT_IP(r) \
96 __CHOOSE_MODE(SC_IP(UPT_SC(r)), REGS_IP((r)->skas.regs))
97#define UPT_SP(r) \
98 __CHOOSE_MODE(SC_SP(UPT_SC(r)), REGS_SP((r)->skas.regs))
99#define UPT_EFLAGS(r) \
100 __CHOOSE_MODE(SC_EFLAGS(UPT_SC(r)), REGS_EFLAGS((r)->skas.regs))
101#define UPT_EAX(r) \
102 __CHOOSE_MODE(SC_EAX(UPT_SC(r)), REGS_EAX((r)->skas.regs))
103#define UPT_EBX(r) \
104 __CHOOSE_MODE(SC_EBX(UPT_SC(r)), REGS_EBX((r)->skas.regs))
105#define UPT_ECX(r) \
106 __CHOOSE_MODE(SC_ECX(UPT_SC(r)), REGS_ECX((r)->skas.regs))
107#define UPT_EDX(r) \
108 __CHOOSE_MODE(SC_EDX(UPT_SC(r)), REGS_EDX((r)->skas.regs))
109#define UPT_ESI(r) \
110 __CHOOSE_MODE(SC_ESI(UPT_SC(r)), REGS_ESI((r)->skas.regs))
111#define UPT_EDI(r) \
112 __CHOOSE_MODE(SC_EDI(UPT_SC(r)), REGS_EDI((r)->skas.regs))
113#define UPT_EBP(r) \
114 __CHOOSE_MODE(SC_EBP(UPT_SC(r)), REGS_EBP((r)->skas.regs))
115#define UPT_ORIG_EAX(r) \
116 __CHOOSE_MODE((r)->tt.syscall, (r)->skas.syscall)
117#define UPT_CS(r) \
118 __CHOOSE_MODE(SC_CS(UPT_SC(r)), REGS_CS((r)->skas.regs))
119#define UPT_SS(r) \
120 __CHOOSE_MODE(SC_SS(UPT_SC(r)), REGS_SS((r)->skas.regs))
121#define UPT_DS(r) \
122 __CHOOSE_MODE(SC_DS(UPT_SC(r)), REGS_DS((r)->skas.regs))
123#define UPT_ES(r) \
124 __CHOOSE_MODE(SC_ES(UPT_SC(r)), REGS_ES((r)->skas.regs))
125#define UPT_FS(r) \
126 __CHOOSE_MODE(SC_FS(UPT_SC(r)), REGS_FS((r)->skas.regs))
127#define UPT_GS(r) \
128 __CHOOSE_MODE(SC_GS(UPT_SC(r)), REGS_GS((r)->skas.regs))
129
130#define UPT_SYSCALL_ARG1(r) UPT_EBX(r)
131#define UPT_SYSCALL_ARG2(r) UPT_ECX(r)
132#define UPT_SYSCALL_ARG3(r) UPT_EDX(r)
133#define UPT_SYSCALL_ARG4(r) UPT_ESI(r)
134#define UPT_SYSCALL_ARG5(r) UPT_EDI(r)
135#define UPT_SYSCALL_ARG6(r) UPT_EBP(r)
136
137extern int user_context(unsigned long sp);
138
139#define UPT_IS_USER(r) \
140 CHOOSE_MODE(user_context(UPT_SP(r)), (r)->skas.is_user)
141
142struct syscall_args {
143 unsigned long args[6];
144};
145
146#define SYSCALL_ARGS(r) ((struct syscall_args) \
147 { .args = { UPT_SYSCALL_ARG1(r), \
148 UPT_SYSCALL_ARG2(r), \
149 UPT_SYSCALL_ARG3(r), \
150 UPT_SYSCALL_ARG4(r), \
151 UPT_SYSCALL_ARG5(r), \
152 UPT_SYSCALL_ARG6(r) } } )
153
154#define UPT_REG(regs, reg) \
155 ({ unsigned long val; \
156 switch(reg){ \
157 case EIP: val = UPT_IP(regs); break; \
158 case UESP: val = UPT_SP(regs); break; \
159 case EAX: val = UPT_EAX(regs); break; \
160 case EBX: val = UPT_EBX(regs); break; \
161 case ECX: val = UPT_ECX(regs); break; \
162 case EDX: val = UPT_EDX(regs); break; \
163 case ESI: val = UPT_ESI(regs); break; \
164 case EDI: val = UPT_EDI(regs); break; \
165 case EBP: val = UPT_EBP(regs); break; \
166 case ORIG_EAX: val = UPT_ORIG_EAX(regs); break; \
167 case CS: val = UPT_CS(regs); break; \
168 case SS: val = UPT_SS(regs); break; \
169 case DS: val = UPT_DS(regs); break; \
170 case ES: val = UPT_ES(regs); break; \
171 case FS: val = UPT_FS(regs); break; \
172 case GS: val = UPT_GS(regs); break; \
173 case EFL: val = UPT_EFLAGS(regs); break; \
174 default : \
175 panic("Bad register in UPT_REG : %d\n", reg); \
176 val = -1; \
177 } \
178 val; \
179 })
180
181
182#define UPT_SET(regs, reg, val) \
183 do { \
184 switch(reg){ \
185 case EIP: UPT_IP(regs) = val; break; \
186 case UESP: UPT_SP(regs) = val; break; \
187 case EAX: UPT_EAX(regs) = val; break; \
188 case EBX: UPT_EBX(regs) = val; break; \
189 case ECX: UPT_ECX(regs) = val; break; \
190 case EDX: UPT_EDX(regs) = val; break; \
191 case ESI: UPT_ESI(regs) = val; break; \
192 case EDI: UPT_EDI(regs) = val; break; \
193 case EBP: UPT_EBP(regs) = val; break; \
194 case ORIG_EAX: UPT_ORIG_EAX(regs) = val; break; \
195 case CS: UPT_CS(regs) = val; break; \
196 case SS: UPT_SS(regs) = val; break; \
197 case DS: UPT_DS(regs) = val; break; \
198 case ES: UPT_ES(regs) = val; break; \
199 case FS: UPT_FS(regs) = val; break; \
200 case GS: UPT_GS(regs) = val; break; \
201 case EFL: UPT_EFLAGS(regs) = val; break; \
202 default : \
203 panic("Bad register in UPT_SET : %d\n", reg); \
204 break; \
205 } \
206 } while (0)
207
208#define UPT_SET_SYSCALL_RETURN(r, res) \
209 CHOOSE_MODE(SC_SET_SYSCALL_RETURN(UPT_SC(r), (res)), \
210 REGS_SET_SYSCALL_RETURN((r)->skas.regs, (res)))
211
212#define UPT_RESTART_SYSCALL(r) \
213 CHOOSE_MODE(SC_RESTART_SYSCALL(UPT_SC(r)), \
214 REGS_RESTART_SYSCALL((r)->skas.regs))
215
216#define UPT_ORIG_SYSCALL(r) UPT_EAX(r)
217#define UPT_SYSCALL_NR(r) UPT_ORIG_EAX(r)
218#define UPT_SYSCALL_RET(r) UPT_EAX(r)
219
220#define UPT_SEGV_IS_FIXABLE(r) \
221 CHOOSE_MODE(SC_SEGV_IS_FIXABLE(UPT_SC(r)), \
222 REGS_SEGV_IS_FIXABLE(&r->skas))
223
224#define UPT_FAULT_ADDR(r) \
225 __CHOOSE_MODE(SC_FAULT_ADDR(UPT_SC(r)), REGS_FAULT_ADDR(&r->skas))
226
227#define UPT_FAULT_WRITE(r) \
228 CHOOSE_MODE(SC_FAULT_WRITE(UPT_SC(r)), REGS_FAULT_WRITE(&r->skas))
229
230#endif
231
232/*
233 * Overrides for Emacs so that we follow Linus's tabbing style.
234 * Emacs will notice this stuff at the end of the file and automatically
235 * adjust the settings for this buffer only. This must remain at the end
236 * of the file.
237 * ---------------------------------------------------------------------------
238 * Local variables:
239 * c-file-style: "linux"
240 * End:
241 */