blob: b45a72feb08cdf521638bdacb44b4aa261bb554d [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"
Jeff Dike36ca1192005-06-13 15:52:10 -070011#include "sysdep/faultinfo.h"
12#include "choose-mode.h"
Linus Torvalds1da177e2005-04-16 15:20:36 -070013
14#define MAX_REG_NR (UM_FRAME_SIZE / sizeof(unsigned long))
15#define MAX_REG_OFFSET (UM_FRAME_SIZE)
16
Paolo 'Blaisorblade' Giarrusso972410b2006-03-31 02:30:21 -080017#ifdef UML_CONFIG_PT_PROXY
Linus Torvalds1da177e2005-04-16 15:20:36 -070018extern void update_debugregs(int seq);
Paolo 'Blaisorblade' Giarrusso972410b2006-03-31 02:30:21 -080019#else
20static inline void update_debugregs(int seq) {}
21#endif
22
Linus Torvalds1da177e2005-04-16 15:20:36 -070023
24/* syscall emulation path in ptrace */
25
26#ifndef PTRACE_SYSEMU
27#define PTRACE_SYSEMU 31
28#endif
29
30void set_using_sysemu(int value);
31int get_using_sysemu(void);
32extern int sysemu_supported;
33
34#ifdef UML_CONFIG_MODE_TT
35#include "sysdep/sc.h"
36#endif
37
38#ifdef UML_CONFIG_MODE_SKAS
39
40#include "skas_ptregs.h"
41
42#define REGS_IP(r) ((r)[HOST_IP])
43#define REGS_SP(r) ((r)[HOST_SP])
44#define REGS_EFLAGS(r) ((r)[HOST_EFLAGS])
45#define REGS_EAX(r) ((r)[HOST_EAX])
46#define REGS_EBX(r) ((r)[HOST_EBX])
47#define REGS_ECX(r) ((r)[HOST_ECX])
48#define REGS_EDX(r) ((r)[HOST_EDX])
49#define REGS_ESI(r) ((r)[HOST_ESI])
50#define REGS_EDI(r) ((r)[HOST_EDI])
51#define REGS_EBP(r) ((r)[HOST_EBP])
52#define REGS_CS(r) ((r)[HOST_CS])
53#define REGS_SS(r) ((r)[HOST_SS])
54#define REGS_DS(r) ((r)[HOST_DS])
55#define REGS_ES(r) ((r)[HOST_ES])
56#define REGS_FS(r) ((r)[HOST_FS])
57#define REGS_GS(r) ((r)[HOST_GS])
58
59#define REGS_SET_SYSCALL_RETURN(r, res) REGS_EAX(r) = (res)
60
61#define REGS_RESTART_SYSCALL(r) IP_RESTART_SYSCALL(REGS_IP(r))
62
Linus Torvalds1da177e2005-04-16 15:20:36 -070063#endif
64#ifndef PTRACE_SYSEMU_SINGLESTEP
65#define PTRACE_SYSEMU_SINGLESTEP 32
66#endif
67
Linus Torvalds1da177e2005-04-16 15:20:36 -070068union uml_pt_regs {
69#ifdef UML_CONFIG_MODE_TT
70 struct tt_regs {
71 long syscall;
72 void *sc;
Bodo Stroesserc5784552005-05-05 16:15:31 -070073 struct faultinfo faultinfo;
Linus Torvalds1da177e2005-04-16 15:20:36 -070074 } tt;
75#endif
76#ifdef UML_CONFIG_MODE_SKAS
77 struct skas_regs {
Jeff Dikee46962f2006-12-06 20:34:54 -080078 unsigned long regs[MAX_REG_NR];
Linus Torvalds1da177e2005-04-16 15:20:36 -070079 unsigned long fp[HOST_FP_SIZE];
80 unsigned long xfp[HOST_XFP_SIZE];
Bodo Stroesserc5784552005-05-05 16:15:31 -070081 struct faultinfo faultinfo;
Linus Torvalds1da177e2005-04-16 15:20:36 -070082 long syscall;
83 int is_user;
84 } skas;
85#endif
86};
87
88#define EMPTY_UML_PT_REGS { }
89
90extern int mode_tt;
91
92#define UPT_SC(r) ((r)->tt.sc)
93#define UPT_IP(r) \
94 __CHOOSE_MODE(SC_IP(UPT_SC(r)), REGS_IP((r)->skas.regs))
95#define UPT_SP(r) \
96 __CHOOSE_MODE(SC_SP(UPT_SC(r)), REGS_SP((r)->skas.regs))
97#define UPT_EFLAGS(r) \
98 __CHOOSE_MODE(SC_EFLAGS(UPT_SC(r)), REGS_EFLAGS((r)->skas.regs))
99#define UPT_EAX(r) \
100 __CHOOSE_MODE(SC_EAX(UPT_SC(r)), REGS_EAX((r)->skas.regs))
101#define UPT_EBX(r) \
102 __CHOOSE_MODE(SC_EBX(UPT_SC(r)), REGS_EBX((r)->skas.regs))
103#define UPT_ECX(r) \
104 __CHOOSE_MODE(SC_ECX(UPT_SC(r)), REGS_ECX((r)->skas.regs))
105#define UPT_EDX(r) \
106 __CHOOSE_MODE(SC_EDX(UPT_SC(r)), REGS_EDX((r)->skas.regs))
107#define UPT_ESI(r) \
108 __CHOOSE_MODE(SC_ESI(UPT_SC(r)), REGS_ESI((r)->skas.regs))
109#define UPT_EDI(r) \
110 __CHOOSE_MODE(SC_EDI(UPT_SC(r)), REGS_EDI((r)->skas.regs))
111#define UPT_EBP(r) \
112 __CHOOSE_MODE(SC_EBP(UPT_SC(r)), REGS_EBP((r)->skas.regs))
113#define UPT_ORIG_EAX(r) \
114 __CHOOSE_MODE((r)->tt.syscall, (r)->skas.syscall)
115#define UPT_CS(r) \
116 __CHOOSE_MODE(SC_CS(UPT_SC(r)), REGS_CS((r)->skas.regs))
117#define UPT_SS(r) \
118 __CHOOSE_MODE(SC_SS(UPT_SC(r)), REGS_SS((r)->skas.regs))
119#define UPT_DS(r) \
120 __CHOOSE_MODE(SC_DS(UPT_SC(r)), REGS_DS((r)->skas.regs))
121#define UPT_ES(r) \
122 __CHOOSE_MODE(SC_ES(UPT_SC(r)), REGS_ES((r)->skas.regs))
123#define UPT_FS(r) \
124 __CHOOSE_MODE(SC_FS(UPT_SC(r)), REGS_FS((r)->skas.regs))
125#define UPT_GS(r) \
126 __CHOOSE_MODE(SC_GS(UPT_SC(r)), REGS_GS((r)->skas.regs))
127
128#define UPT_SYSCALL_ARG1(r) UPT_EBX(r)
129#define UPT_SYSCALL_ARG2(r) UPT_ECX(r)
130#define UPT_SYSCALL_ARG3(r) UPT_EDX(r)
131#define UPT_SYSCALL_ARG4(r) UPT_ESI(r)
132#define UPT_SYSCALL_ARG5(r) UPT_EDI(r)
133#define UPT_SYSCALL_ARG6(r) UPT_EBP(r)
134
135extern int user_context(unsigned long sp);
136
137#define UPT_IS_USER(r) \
138 CHOOSE_MODE(user_context(UPT_SP(r)), (r)->skas.is_user)
139
140struct syscall_args {
141 unsigned long args[6];
142};
143
144#define SYSCALL_ARGS(r) ((struct syscall_args) \
145 { .args = { UPT_SYSCALL_ARG1(r), \
146 UPT_SYSCALL_ARG2(r), \
147 UPT_SYSCALL_ARG3(r), \
148 UPT_SYSCALL_ARG4(r), \
149 UPT_SYSCALL_ARG5(r), \
150 UPT_SYSCALL_ARG6(r) } } )
151
152#define UPT_REG(regs, reg) \
153 ({ unsigned long val; \
154 switch(reg){ \
155 case EIP: val = UPT_IP(regs); break; \
156 case UESP: val = UPT_SP(regs); break; \
157 case EAX: val = UPT_EAX(regs); break; \
158 case EBX: val = UPT_EBX(regs); break; \
159 case ECX: val = UPT_ECX(regs); break; \
160 case EDX: val = UPT_EDX(regs); break; \
161 case ESI: val = UPT_ESI(regs); break; \
162 case EDI: val = UPT_EDI(regs); break; \
163 case EBP: val = UPT_EBP(regs); break; \
164 case ORIG_EAX: val = UPT_ORIG_EAX(regs); break; \
165 case CS: val = UPT_CS(regs); break; \
166 case SS: val = UPT_SS(regs); break; \
167 case DS: val = UPT_DS(regs); break; \
168 case ES: val = UPT_ES(regs); break; \
169 case FS: val = UPT_FS(regs); break; \
170 case GS: val = UPT_GS(regs); break; \
171 case EFL: val = UPT_EFLAGS(regs); break; \
172 default : \
173 panic("Bad register in UPT_REG : %d\n", reg); \
174 val = -1; \
175 } \
176 val; \
177 })
178
179
180#define UPT_SET(regs, reg, val) \
181 do { \
182 switch(reg){ \
183 case EIP: UPT_IP(regs) = val; break; \
184 case UESP: UPT_SP(regs) = val; break; \
185 case EAX: UPT_EAX(regs) = val; break; \
186 case EBX: UPT_EBX(regs) = val; break; \
187 case ECX: UPT_ECX(regs) = val; break; \
188 case EDX: UPT_EDX(regs) = val; break; \
189 case ESI: UPT_ESI(regs) = val; break; \
190 case EDI: UPT_EDI(regs) = val; break; \
191 case EBP: UPT_EBP(regs) = val; break; \
192 case ORIG_EAX: UPT_ORIG_EAX(regs) = val; break; \
193 case CS: UPT_CS(regs) = val; break; \
194 case SS: UPT_SS(regs) = val; break; \
195 case DS: UPT_DS(regs) = val; break; \
196 case ES: UPT_ES(regs) = val; break; \
197 case FS: UPT_FS(regs) = val; break; \
198 case GS: UPT_GS(regs) = val; break; \
199 case EFL: UPT_EFLAGS(regs) = val; break; \
200 default : \
201 panic("Bad register in UPT_SET : %d\n", reg); \
202 break; \
203 } \
204 } while (0)
205
206#define UPT_SET_SYSCALL_RETURN(r, res) \
207 CHOOSE_MODE(SC_SET_SYSCALL_RETURN(UPT_SC(r), (res)), \
208 REGS_SET_SYSCALL_RETURN((r)->skas.regs, (res)))
209
210#define UPT_RESTART_SYSCALL(r) \
211 CHOOSE_MODE(SC_RESTART_SYSCALL(UPT_SC(r)), \
212 REGS_RESTART_SYSCALL((r)->skas.regs))
213
214#define UPT_ORIG_SYSCALL(r) UPT_EAX(r)
215#define UPT_SYSCALL_NR(r) UPT_ORIG_EAX(r)
216#define UPT_SYSCALL_RET(r) UPT_EAX(r)
217
Bodo Stroesserc5784552005-05-05 16:15:31 -0700218#define UPT_FAULTINFO(r) \
219 CHOOSE_MODE((&(r)->tt.faultinfo), (&(r)->skas.faultinfo))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700220
221#endif