1 /* parent.c -- ARMulator RDP comms code: ARM6 Instruction Emulator.
2 Copyright (C) 1994 Advanced RISC Machines Ltd.
4 This program is free software; you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation; either version 2 of the License, or
7 (at your option) any later version.
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
14 You should have received a copy of the GNU General Public License
15 along with this program; if not, write to the Free Software
16 Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA. */
18 /*****************************************************************/
19 /* The Parent process continues here... */
20 /* It waits on the socket and passes on RDP messages down a pipe */
21 /* to the ARMulator RDP to RDI interpreter. */
22 /*****************************************************************/
25 #include <sys/types.h>
30 #include "communicate.h"
32 /* The socket to the debugger */
35 /* The pipes between the two processes */
39 /* A pipe for handling SWI return values that goes straight from the */
40 /* parent to the ARMulator host interface, bypassing the child's RDP */
41 /* to RDI interpreter */
42 extern int DebuggerARMul[2];
44 /* The maximum number of file descriptors */
47 /* The child process id. */
54 unsigned char message, CPnum, exreturn;
55 ARMword mask, nbytes, messagetype;
59 struct fd_set readfds;
62 fprintf (stderr, "parent ()...\n");
70 fprintf (stderr, "Arghh! What is going on?\n");
73 MYwrite_char (debugsock, RDP_Reset);
81 /* Wait either for the ARMulator or the debugger */
84 FD_SET (kidmum[0], &readfds); /* Wait for messages from ARMulator */
85 FD_SET (debugsock, &readfds); /* Wait for messages from debugger */
88 fprintf (stderr, "Waiting for ARMulator or debugger... ");
91 while ((i = select (nfds, &readfds, (fd_set *) 0, (fd_set *) 0, 0)) < 0)
97 fprintf (stderr, "(%d/2)", i);
100 if (FD_ISSET (debugsock, &readfds))
103 fprintf (stderr, "->debugger\n");
106 /* Inside this rather large if statement with simply pass on a complete
107 message to the ARMulator. The reason we need to pass messages on one
108 at a time is that we have to know whether the message is an OSOpReply
109 or an info(stop), so that we can take different action in those
112 if (MYread_char (debugsock, &message))
118 /* Open and/or Initialise */
120 fprintf (stderr, "RDP Open\n");
122 if (MYread_char (debugsock, &c)) /* type */
125 if (MYread_word (debugsock, &x)) /* memory size */
128 MYwrite_char (mumkid[1], message);
129 MYwrite_char (mumkid[1], c);
130 MYwrite_word (mumkid[1], x);
133 passon (debugsock, mumkid[1], 1); /* speed */
138 /* Close and Finalise */
140 fprintf (stderr, "RDP Close\n");
142 MYwrite_char (mumkid[1], message);
146 /* Read Memory Address */
148 fprintf (stderr, "RDP Read Memory\n");
150 MYwrite_char (mumkid[1], message);
151 if (passon (debugsock, mumkid[1], 4))
152 goto panic_error; /* address */
153 if (MYread_word (debugsock, &nbytes))
154 goto panic_error; /* nbytes */
155 MYwrite_word (mumkid[1], nbytes);
159 /* Write Memory Address */
161 fprintf (stderr, "RDP Write Memory\n");
163 if (MYread_word (debugsock, &x))
164 goto panic_error; /* address */
166 if (MYread_word (debugsock, &y))
167 goto panic_error; /* nbytes */
169 MYwrite_char (mumkid[1], message);
170 MYwrite_word (mumkid[1], x);
171 MYwrite_word (mumkid[1], y);
172 passon (debugsock, mumkid[1], y); /* actual data */
178 fprintf (stderr, "RDP Read CPU\n");
180 if (MYread_char (debugsock, &c))
181 goto panic_error; /* mode */
183 if (MYread_word (debugsock, &mask))
184 goto panic_error; /* mask */
186 MYwrite_char (mumkid[1], message);
187 MYwrite_char (mumkid[1], c);
188 MYwrite_word (mumkid[1], mask);
192 /* Write CPU State */
194 fprintf (stderr, "RDP Write CPU\n");
196 if (MYread_char (debugsock, &c))
197 goto panic_error; /* mode */
199 if (MYread_word (debugsock, &x))
200 goto panic_error; /* mask */
202 MYwrite_char (mumkid[1], message);
203 MYwrite_char (mumkid[1], c);
204 MYwrite_word (mumkid[1], x);
205 for (k = 1, j = 0; k != 0x80000000; k *= 2, j++)
206 if ((k & x) && passon (debugsock, mumkid[1], 4))
211 /* Read Co-Processor State */
213 fprintf (stderr, "RDP Read CP state\n");
215 if (MYread_char (debugsock, &CPnum))
218 if (MYread_word (debugsock, &mask))
221 MYwrite_char (mumkid[1], message);
222 MYwrite_char (mumkid[1], CPnum);
223 MYwrite_word (mumkid[1], mask);
227 /* Write Co-Processor State */
229 fprintf (stderr, "RDP Write CP state\n");
231 if (MYread_char (debugsock, &CPnum))
234 if (MYread_word (debugsock, &mask))
237 MYwrite_char (mumkid[1], message);
238 MYwrite_char (mumkid[1], c);
239 MYwrite_char (mumkid[1], x);
240 for (k = 1, j = 0; k != 0x80000000; k *= 2, j++)
243 if ((c == 1 || c == 2) && k <= 128)
245 /* FP register = 12 bytes + 4 bytes format */
246 if (passon (debugsock, mumkid[1], 16))
251 /* Normal register = 4 bytes */
252 if (passon (debugsock, mumkid[1], 4))
261 fprintf (stderr, "RDP Set Breakpoint\n");
263 if (MYread_word (debugsock, &x))
264 goto panic_error; /* address */
266 if (MYread_char (debugsock, &c))
267 goto panic_error; /* type */
269 MYwrite_char (mumkid[1], message);
270 MYwrite_word (mumkid[1], x);
271 MYwrite_char (mumkid[1], c);
272 if (((c & 0xf) >= 5) && passon (debugsock, mumkid[1], 4))
273 goto panic_error; /* bound */
277 /* Clear Breakpoint */
279 fprintf (stderr, "RDP Clear Breakpoint\n");
281 MYwrite_char (mumkid[1], message);
282 if (passon (debugsock, mumkid[1], 4))
283 goto panic_error; /* point */
289 fprintf (stderr, "RDP Set Watchpoint\n");
291 if (MYread_word (debugsock, &x))
292 goto panic_error; /* address */
294 if (MYread_char (debugsock, &c))
295 goto panic_error; /* type */
297 if (MYread_char (debugsock, &d))
298 goto panic_error; /* datatype */
300 MYwrite_char (mumkid[1], message);
301 MYwrite_word (mumkid[1], x);
302 MYwrite_char (mumkid[1], c);
303 MYwrite_char (mumkid[1], d);
304 if (((c & 0xf) >= 5) && passon (debugsock, mumkid[1], 4))
305 goto panic_error; /* bound */
309 /* Clear Watchpoint */
311 fprintf (stderr, "RDP Clear Watchpoint\n");
313 MYwrite_char (mumkid[1], message);
314 if (passon (debugsock, mumkid[1], 4))
315 goto panic_error; /* point */
321 fprintf (stderr, "RDP Execute\n");
324 /* LEAVE THIS ONE 'TIL LATER... */
325 /* NEED TO WORK THINGS OUT */
327 /* NO ASCYNCHROUS RUNNING */
329 if (MYread_char (debugsock, &c))
330 goto panic_error; /* return */
332 /* Remember incase bit 7 is set and we have to send back a word */
335 MYwrite_char (mumkid[1], message);
336 MYwrite_char (mumkid[1], c);
342 fprintf (stderr, "RDP Step\n");
345 if (MYread_char (debugsock, &c))
346 goto panic_error; /* return */
348 if (MYread_word (debugsock, &x))
349 goto panic_error; /* ninstr */
351 MYwrite_char (mumkid[1], message);
352 MYwrite_char (mumkid[1], c);
353 MYwrite_word (mumkid[1], x);
359 fprintf (stderr, "RDP Info\n");
361 /* INFO TARGET, SET RDI LEVEL */
362 if (MYread_word (debugsock, &messagetype))
363 goto panic_error; /* info */
368 MYwrite_char (mumkid[1], message);
369 MYwrite_word (mumkid[1], messagetype);
372 case RDISet_RDILevel:
373 MYwrite_char (mumkid[1], message);
374 MYwrite_word (mumkid[1], messagetype);
375 if (passon (debugsock, mumkid[1], 1))
376 goto panic_error; /* argument */
380 /* Got to pass on a string argument */
381 MYwrite_char (mumkid[1], message);
382 MYwrite_word (mumkid[1], messagetype);
385 if (MYread_char (debugsock, &c))
388 MYwrite_char (mumkid[1], c);
394 kill (child, SIGUSR1);
395 MYwrite_char (debugsock, RDP_Return);
396 MYwrite_char (debugsock, RDIError_UserInterrupt);
399 case RDIVector_Catch:
400 MYread_word (debugsock, &x);
401 MYwrite_char (mumkid[1], message);
402 MYwrite_word (mumkid[1], messagetype);
403 MYwrite_word (mumkid[1], x);
407 MYwrite_char (mumkid[1], message);
408 MYwrite_word (mumkid[1], messagetype);
412 MYwrite_char (mumkid[1], message);
413 MYwrite_word (mumkid[1], messagetype);
417 fprintf (stderr, "Unrecognized RDIInfo request %d\n",
424 /* OS Operation Reply */
426 fprintf (stderr, "RDP OS Reply\n");
428 MYwrite_char (mumkid[1], message);
429 if (MYread_char (debugsock, &message))
431 MYwrite_char (mumkid[1], message);
434 case 0: /* return value i.e. nothing else. */
437 case 1: /* returns a byte... */
438 if (MYread_char (debugsock, &c))
441 MYwrite_char (mumkid[1], c);
444 case 2: /* returns a word... */
445 if (MYread_word (debugsock, &x))
448 MYwrite_word (mumkid[1], x);
456 fprintf (stderr, "RDP Reset\n");
458 MYwrite_char (mumkid[1], message);
462 /* Hmm.. bad RDP operation */
463 fprintf (stderr, "RDP Bad RDP request (%d)\n", message);
464 MYwrite_char (debugsock, RDP_Return);
465 MYwrite_char (debugsock, RDIError_UnimplementedMessage);
470 if (FD_ISSET (kidmum[0], &readfds))
473 fprintf (stderr, "->ARMulator\n");
475 /* Anything we get from the ARMulator has to go to the debugger... */
476 /* It is that simple! */
478 passon (kidmum[0], debugsock, 1);