Add cris support in strace
[openwrt/svn-archive/archive.git] / utils / strace / patches-4.5.16 / 010-cris_support.patch
1 diff -Naur strace-4.5.16.ori/config.h.in strace-4.5.16/config.h.in
2 --- strace-4.5.16.ori/config.h.in 2008-08-04 20:11:11.000000000 +0200
3 +++ strace-4.5.16/config.h.in 2008-08-04 20:48:28.000000000 +0200
4 @@ -403,6 +403,12 @@
5 /* Define for the AMD x86-64 architecture. */
6 #undef X86_64
7
8 +/* Define for the CRISv10 architecture. */
9 +#undef CRISV10
10 +
11 +/* Define for the CRISv32 architecture. */
12 +#undef CRISV32
13 +
14 /* Enable GNU extensions on systems that have them. */
15 #ifndef _GNU_SOURCE
16 # undef _GNU_SOURCE
17 diff -Naur strace-4.5.16.ori/configure strace-4.5.16/configure
18 --- strace-4.5.16.ori/configure 2008-08-04 20:11:11.000000000 +0200
19 +++ strace-4.5.16/configure 2008-08-04 21:15:39.000000000 +0200
20 @@ -2539,6 +2539,22 @@
21 _ACEOF
22
23 ;;
24 +cris|crisv10)
25 + arch=crisv10
26 +
27 +cat >>confdefs.h <<\_ACEOF
28 +#define CRISV10 1
29 +_ACEOF
30 +
31 + ;;
32 +crisv32)
33 + arch=crisv32
34 +
35 +cat >>confdefs.h <<\_ACEOF
36 +#define CRISV32 1
37 +_ACEOF
38 +
39 + ;;
40 *)
41 { echo "$as_me:$LINENO: result: NO!" >&5
42 echo "${ECHO_T}NO!" >&6; }
43 diff -Naur strace-4.5.16.ori/configure.ac strace-4.5.16/configure.ac
44 --- strace-4.5.16.ori/configure.ac 2008-08-04 20:11:11.000000000 +0200
45 +++ strace-4.5.16/configure.ac 2008-08-04 20:50:58.000000000 +0200
46 @@ -111,6 +111,14 @@
47 AC_MSG_RESULT([NO!])
48 AC_MSG_ERROR([architecture $host_cpu is not supported by strace])
49 ;;
50 +cris|crisv10)
51 + arch=crisv10
52 + AC_DEFINE([CRISV10], 1, [Define for the CRISv10 architecture.])
53 + ;;
54 +crisv32)
55 + arch=crisv32
56 + AC_DEFINE([CRISV32], 1, [Define for the CRISv32 architecture.])
57 + ;;
58 esac
59 AC_MSG_RESULT($arch)
60
61 diff -Naur strace-4.5.16.ori/process.c strace-4.5.16/process.c
62 --- strace-4.5.16.ori/process.c 2008-08-04 20:11:11.000000000 +0200
63 +++ strace-4.5.16/process.c 2008-08-04 21:18:30.000000000 +0200
64 @@ -548,7 +548,7 @@
65 # define ARG_PTID (known_scno(tcp) == SYS_clone2 ? 3 : 2)
66 # define ARG_CTID (known_scno(tcp) == SYS_clone2 ? 4 : 3)
67 # define ARG_TLS (known_scno(tcp) == SYS_clone2 ? 5 : 4)
68 -# elif defined S390 || defined S390X
69 +# elif defined S390 || defined S390X || defined CRISV10 || defined CRISV32
70 # define ARG_STACK 0
71 # define ARG_FLAGS 1
72 # define ARG_PTID 2
73 @@ -704,6 +704,10 @@
74 0x100000 | new) < 0)
75 return -1;
76 return 0;
77 +#elif defined(CRISV10) || defined(CRISV32)
78 + if (ptrace(PTRACE_POKEUSER, tcp->pid, (char*)(4*PT_R9), new) < 0)
79 + return -1;
80 + return 0;
81 #elif defined(ARM)
82 /* Some kernels support this, some (pre-2.6.16 or so) don't. */
83 # ifndef PTRACE_SET_SYSCALL
84 @@ -2934,6 +2938,77 @@
85 { uoff(regs.r0), "r0" },
86 { uoff(regs.r12_orig), "orig_r12" },
87 #endif
88 +#ifdef CRISV10
89 + { 4*PT_FRAMETYPE, "4*PT_FRAMETYPE" },
90 + { 4*PT_ORIG_R10, "4*PT_ORIG_R10" },
91 + { 4*PT_R13, "4*PT_R13" },
92 + { 4*PT_R12, "4*PT_R12" },
93 + { 4*PT_R11, "4*PT_R11" },
94 + { 4*PT_R10, "4*PT_R10" },
95 + { 4*PT_R9, "4*PT_R9" },
96 + { 4*PT_R8, "4*PT_R8" },
97 + { 4*PT_R7, "4*PT_R7" },
98 + { 4*PT_R6, "4*PT_R6" },
99 + { 4*PT_R5, "4*PT_R5" },
100 + { 4*PT_R4, "4*PT_R4" },
101 + { 4*PT_R3, "4*PT_R3" },
102 + { 4*PT_R2, "4*PT_R2" },
103 + { 4*PT_R1, "4*PT_R1" },
104 + { 4*PT_R0, "4*PT_R0" },
105 + { 4*PT_MOF, "4*PT_MOF" },
106 + { 4*PT_DCCR, "4*PT_DCCR" },
107 + { 4*PT_SRP, "4*PT_SRP" },
108 + { 4*PT_IRP, "4*PT_IRP" },
109 + { 4*PT_CSRINSTR, "4*PT_CSRINSTR" },
110 + { 4*PT_CSRADDR, "4*PT_CSRADDR" },
111 + { 4*PT_CSRDATA, "4*PT_CSRDATA" },
112 + { 4*PT_USP, "4*PT_USP" },
113 +#endif
114 +#ifdef CRISV32
115 + { 4*PT_ORIG_R10, "4*PT_ORIG_R10" },
116 + { 4*PT_R0, "4*PT_R0" },
117 + { 4*PT_R1, "4*PT_R1" },
118 + { 4*PT_R2, "4*PT_R2" },
119 + { 4*PT_R3, "4*PT_R3" },
120 + { 4*PT_R4, "4*PT_R4" },
121 + { 4*PT_R5, "4*PT_R5" },
122 + { 4*PT_R6, "4*PT_R6" },
123 + { 4*PT_R7, "4*PT_R7" },
124 + { 4*PT_R8, "4*PT_R8" },
125 + { 4*PT_R9, "4*PT_R9" },
126 + { 4*PT_R10, "4*PT_R10" },
127 + { 4*PT_R11, "4*PT_R11" },
128 + { 4*PT_R12, "4*PT_R12" },
129 + { 4*PT_R13, "4*PT_R13" },
130 + { 4*PT_ACR, "4*PT_ACR" },
131 + { 4*PT_SRS, "4*PT_SRS" },
132 + { 4*PT_MOF, "4*PT_MOF" },
133 + { 4*PT_SPC, "4*PT_SPC" },
134 + { 4*PT_CCS, "4*PT_CCS" },
135 + { 4*PT_SRP, "4*PT_SRP" },
136 + { 4*PT_ERP, "4*PT_ERP" },
137 + { 4*PT_EXS, "4*PT_EXS" },
138 + { 4*PT_EDA, "4*PT_EDA" },
139 + { 4*PT_USP, "4*PT_USP" },
140 + { 4*PT_PPC, "4*PT_PPC" },
141 + { 4*PT_BP_CTRL, "4*PT_BP_CTRL" },
142 + { 4*PT_BP+4, "4*PT_BP+4" },
143 + { 4*PT_BP+8, "4*PT_BP+8" },
144 + { 4*PT_BP+12, "4*PT_BP+12" },
145 + { 4*PT_BP+16, "4*PT_BP+16" },
146 + { 4*PT_BP+20, "4*PT_BP+20" },
147 + { 4*PT_BP+24, "4*PT_BP+24" },
148 + { 4*PT_BP+28, "4*PT_BP+28" },
149 + { 4*PT_BP+32, "4*PT_BP+32" },
150 + { 4*PT_BP+36, "4*PT_BP+36" },
151 + { 4*PT_BP+40, "4*PT_BP+40" },
152 + { 4*PT_BP+44, "4*PT_BP+44" },
153 + { 4*PT_BP+48, "4*PT_BP+48" },
154 + { 4*PT_BP+52, "4*PT_BP+52" },
155 + { 4*PT_BP+56, "4*PT_BP+56" },
156 +#endif
157 +
158 +#if !defined(CRISV10) && !defined(CRISV32)
159 #if !defined(S390) && !defined(S390X) && !defined(MIPS) && !defined(SPARC64) && !defined(AVR32)
160 { uoff(u_fpvalid), "offsetof(struct user, u_fpvalid)" },
161 #endif
162 @@ -2971,6 +3046,7 @@
163 #if defined(I386) || defined(X86_64)
164 { uoff(u_debugreg), "offsetof(struct user, u_debugreg)" },
165 #endif /* I386 */
166 +#endif /* !CRISV10/!CRISV32 */
167 #endif /* !IA64 */
168 #endif /* !ALPHA */
169 #endif /* !POWERPC/!SPARC */
170 diff -Naur strace-4.5.16.ori/signal.c strace-4.5.16/signal.c
171 --- strace-4.5.16.ori/signal.c 2007-08-02 03:15:59.000000000 +0200
172 +++ strace-4.5.16/signal.c 2008-08-04 20:57:04.000000000 +0200
173 @@ -1449,9 +1449,38 @@
174 }
175 return 0;
176 #else
177 +#if defined(CRISV10) || defined(CRISV32)
178 + struct sigcontext sc;
179 +
180 + if (entering(tcp)) {
181 + long regs[PT_MAX+1];
182 +
183 + tcp->u_arg[0] = 0;
184 +
185 + if (ptrace(PTRACE_GETREGS, tcp->pid, NULL, (long)regs) < 0) {
186 + perror("sigreturn: PTRACE_GETREGS");
187 + return 0;
188 + }
189 + if (umove(tcp, regs[PT_USP], &sc) < 0)
190 + return 0;
191 + tcp->u_arg[0] = 1;
192 + tcp->u_arg[1] = sc.oldmask;
193 + } else {
194 + sigset_t sigm;
195 +
196 + long_to_sigset(tcp->u_arg[1], &sigm);
197 + tcp->u_rval = tcp->u_error = 0;
198 + if (tcp->u_arg[0] == 0)
199 + return 0;
200 + tcp->auxstr = sprintsigmask("mask now ", &sigm, 0);
201 + return RVAL_NONE | RVAL_STR;
202 + }
203 + return 0;
204 +#else
205 #warning No sys_sigreturn() for this architecture
206 #warning (no problem, just a reminder :-)
207 return 0;
208 +#endif /* !CRISV10/!CRISV32 */
209 #endif /* MIPS */
210 #endif /* SPARC || SPARC64 */
211 #endif /* ALPHA */
212 diff -Naur strace-4.5.16.ori/syscall.c strace-4.5.16/syscall.c
213 --- strace-4.5.16.ori/syscall.c 2008-08-04 20:11:11.000000000 +0200
214 +++ strace-4.5.16/syscall.c 2008-08-04 21:02:28.000000000 +0200
215 @@ -809,6 +809,8 @@
216 static long r9;
217 #elif defined(X86_64)
218 static long rax;
219 +#elif defined(CRISV10) || defined(CRISV32)
220 + static long r10;
221 #elif defined(AVR32)
222 static struct pt_regs regs;
223 #endif
224 @@ -1294,7 +1296,10 @@
225 return 0;
226 }
227 }
228 -#endif /* AVR32 */
229 +#elif defined(CRISV10) || defined(CRISV32)
230 + if (upeek(pid, 4*PT_R9, &scno) < 0)
231 + return -1;
232 +#endif /* CRISV10/CRISV32 */
233 #endif /* LINUX */
234 #ifdef SUNOS4
235 if (upeek(pid, uoff(u_arg[7]), &scno) < 0)
236 @@ -1489,6 +1494,14 @@
237 fprintf(stderr, "stray syscall exit: r8 = %ld\n", r8);
238 return 0;
239 }
240 +#elif defined(CRISV10) || defined(CRISV32)
241 + if (upeek(pid, 4*PT_R10, &r10) < 0)
242 + return -1;
243 + if (r10 != -ENOSYS && !(tcp->flags & TCB_INSYSCALL)) {
244 + if (debug)
245 + fprintf(stderr, "stray syscall exit: r10 = %ld\n", r10);
246 + return 0;
247 + }
248 #endif
249 #endif /* LINUX */
250 return 1;
251 @@ -1663,6 +1676,17 @@
252 tcp->u_rval = regs.r12;
253 u_error = 0;
254 }
255 +#else
256 +#if defined(CRISV10) || defined(CRISV32)
257 + if (r10 && (unsigned) -r10 < nerrnos) {
258 + tcp->u_rval = -1;
259 + u_error = -r10;
260 + }
261 + else {
262 + tcp->u_rval = r10;
263 + u_error = 0;
264 + }
265 +#endif /* CRISV10/CRISV32 */
266 #endif /* AVR32 */
267 #endif /* SH64 */
268 #endif /* SH */
269 @@ -2175,6 +2199,23 @@
270 tcp->u_arg[3] = regs.r9;
271 tcp->u_arg[4] = regs.r5;
272 tcp->u_arg[5] = regs.r3;
273 +#elif defined(CRISV10) || defined(CRISV32)
274 + {
275 + int i;
276 + static const int crisregs[] = {
277 + 4*PT_ORIG_R10, 4*PT_R11, 4*PT_R12,
278 + 4*PT_R13, 4*PT_MOF, 4*PT_SRP
279 + };
280 +
281 + if (tcp->scno >= 0 && tcp->scno < nsyscalls)
282 + tcp->u_nargs = sysent[tcp->scno].nargs;
283 + else
284 + tcp->u_nargs = 0;
285 + for (i = 0; i < tcp->u_nargs; i++) {
286 + if (upeek(pid, crisregs[i], &tcp->u_arg[i]) < 0)
287 + return -1;
288 + }
289 + }
290 #else /* Other architecture (like i386) (32bits specific) */
291 {
292 int i;
293 diff -Naur strace-4.5.16.ori/util.c strace-4.5.16/util.c
294 --- strace-4.5.16.ori/util.c 2008-08-04 20:11:11.000000000 +0200
295 +++ strace-4.5.16/util.c 2008-08-04 21:05:37.000000000 +0200
296 @@ -1079,6 +1079,12 @@
297 #elif defined(AVR32)
298 if (upeek(tcp->pid, REG_PC, &pc) < 0)
299 return -1;
300 +#elif defined(CRISV10)
301 + if (upeek(tcp->pid, 4*PT_IRP, &pc) < 0)
302 + return -1;
303 +#elif defined(CRISV32)
304 + if (upeek(tcp->pid, 4*PT_ERP, &pc) < 0)
305 + return -1;
306 #endif
307 return pc;
308 #endif /* LINUX */
309 @@ -1235,6 +1241,22 @@
310 return;
311 }
312 tprintf("[%08lx] ", pc);
313 +#elif defined(CRISV10)
314 + long pc;
315 +
316 + if (upeek(tcp->pid, 4*PT_IRP, &pc) < 0) {
317 + PRINTBADPC;
318 + return;
319 + }
320 + tprintf("[%08lx] ", (unsigned long)pc);
321 +#elif defined(CRISV32)
322 + long pc;
323 +
324 + if (upeek(tcp->pid, 4*PT_ERP, &pc) < 0) {
325 + PRINTBADPC;
326 + return;
327 + }
328 + tprintf("[%08lx] ", (unsigned long)pc);
329 #endif /* !architecture */
330 #endif /* LINUX */
331
332 @@ -1419,6 +1441,13 @@
333 # elif defined (AVR32)
334 # define arg0_offset (REG_R12)
335 # define arg1_offset (REG_R11)
336 +# elif defined CRISV10 || defined CRISV32
337 +# define arg0_offset (4*PT_R11)
338 +# define arg1_offset (4*PT_ORIG_R10)
339 +# define restore_arg0(tcp, state, val) 0
340 +# define restore_arg1(tcp, state, val) 0
341 +# define arg0_index 1
342 +# define arg1_index 0
343 # else
344 # define arg0_offset 0
345 # define arg1_offset 4