uml: kernel_thread shouldn't panic
[pv_ops_mirror.git] / arch / um / include / sysdep-i386 / ptrace.h
blob52b398bcafcf73ad738cbff7d6e0bd754eb7ddae
1 /*
2 * Copyright (C) 2000, 2001, 2002 Jeff Dike (jdike@karaya.com)
3 * Licensed under the GPL
4 */
6 #ifndef __SYSDEP_I386_PTRACE_H
7 #define __SYSDEP_I386_PTRACE_H
9 #include "uml-config.h"
10 #include "user_constants.h"
11 #include "sysdep/faultinfo.h"
12 #include "choose-mode.h"
14 #define MAX_REG_NR (UM_FRAME_SIZE / sizeof(unsigned long))
15 #define MAX_REG_OFFSET (UM_FRAME_SIZE)
17 #ifdef UML_CONFIG_PT_PROXY
18 extern void update_debugregs(int seq);
19 #else
20 static inline void update_debugregs(int seq) {}
21 #endif
24 /* syscall emulation path in ptrace */
26 #ifndef PTRACE_SYSEMU
27 #define PTRACE_SYSEMU 31
28 #endif
30 void set_using_sysemu(int value);
31 int get_using_sysemu(void);
32 extern int sysemu_supported;
34 #ifdef UML_CONFIG_MODE_TT
35 #include "sysdep/sc.h"
36 #endif
38 #ifdef UML_CONFIG_MODE_SKAS
40 #include "skas_ptregs.h"
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])
59 #define REGS_SET_SYSCALL_RETURN(r, res) REGS_EAX(r) = (res)
61 #define REGS_RESTART_SYSCALL(r) IP_RESTART_SYSCALL(REGS_IP(r))
63 #endif
64 #ifndef PTRACE_SYSEMU_SINGLESTEP
65 #define PTRACE_SYSEMU_SINGLESTEP 32
66 #endif
68 union uml_pt_regs {
69 #ifdef UML_CONFIG_MODE_TT
70 struct tt_regs {
71 long syscall;
72 void *sc;
73 struct faultinfo faultinfo;
74 } tt;
75 #endif
76 #ifdef UML_CONFIG_MODE_SKAS
77 struct skas_regs {
78 unsigned long regs[MAX_REG_NR];
79 unsigned long fp[HOST_FP_SIZE];
80 unsigned long xfp[HOST_XFP_SIZE];
81 struct faultinfo faultinfo;
82 long syscall;
83 int is_user;
84 } skas;
85 #endif
88 #define EMPTY_UML_PT_REGS { }
90 extern int mode_tt;
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))
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)
135 extern int user_context(unsigned long sp);
137 #define UPT_IS_USER(r) \
138 CHOOSE_MODE(user_context(UPT_SP(r)), (r)->skas.is_user)
140 struct syscall_args {
141 unsigned long args[6];
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) } } )
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; \
176 val; \
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; \
204 } while (0)
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)))
210 #define UPT_RESTART_SYSCALL(r) \
211 CHOOSE_MODE(SC_RESTART_SYSCALL(UPT_SC(r)), \
212 REGS_RESTART_SYSCALL((r)->skas.regs))
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)
218 #define UPT_FAULTINFO(r) \
219 CHOOSE_MODE((&(r)->tt.faultinfo), (&(r)->skas.faultinfo))
221 #endif
224 * Overrides for Emacs so that we follow Linus's tabbing style.
225 * Emacs will notice this stuff at the end of the file and automatically
226 * adjust the settings for this buffer only. This must remain at the end
227 * of the file.
228 * ---------------------------------------------------------------------------
229 * Local variables:
230 * c-file-style: "linux"
231 * End: