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., 675 Mass Ave, Cambridge, MA 02139, 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
)) {
102 fprintf (stderr
, "->debugger\n");
105 /* Inside this rather large if statement with simply pass on a complete
106 message to the ARMulator. The reason we need to pass messages on one
107 at a time is that we have to know whether the message is an OSOpReply
108 or an info(stop), so that we can take different action in those
111 if (MYread_char (debugsock
, &message
))
117 /* Open and/or Initialise */
119 fprintf (stderr
, "RDP Open\n");
121 if (MYread_char(debugsock
, &c
)) /* type */
124 if (MYread_word(debugsock
, &x
)) /* memory size */
127 MYwrite_char (mumkid
[1], message
);
128 MYwrite_char (mumkid
[1], c
);
129 MYwrite_word (mumkid
[1], x
);
132 passon (debugsock
, mumkid
[1], 1); /* speed */
137 /* Close and Finalise */
139 fprintf(stderr
, "RDP Close\n");
141 MYwrite_char (mumkid
[1], message
);
145 /* Read Memory Address */
147 fprintf (stderr
, "RDP Read Memory\n");
149 MYwrite_char (mumkid
[1], message
);
150 if (passon (debugsock
, mumkid
[1], 4))
151 goto panic_error
; /* address */
152 if (MYread_word(debugsock
, &nbytes
))
153 goto panic_error
; /* nbytes */
154 MYwrite_word (mumkid
[1], nbytes
);
158 /* Write Memory Address */
160 fprintf (stderr
, "RDP Write Memory\n");
162 if (MYread_word (debugsock
, &x
))
163 goto panic_error
; /* address */
165 if (MYread_word (debugsock
, &y
))
166 goto panic_error
; /* nbytes */
168 MYwrite_char (mumkid
[1], message
);
169 MYwrite_word (mumkid
[1], x
);
170 MYwrite_word (mumkid
[1], y
);
171 passon (debugsock
, mumkid
[1], y
); /* actual data */
177 fprintf (stderr
, "RDP Read CPU\n");
179 if (MYread_char(debugsock
, &c
))
180 goto panic_error
; /* mode */
182 if (MYread_word (debugsock
, &mask
))
183 goto panic_error
; /* mask */
185 MYwrite_char (mumkid
[1], message
);
186 MYwrite_char (mumkid
[1], c
);
187 MYwrite_word (mumkid
[1], mask
);
191 /* Write CPU State */
193 fprintf (stderr
, "RDP Write CPU\n");
195 if (MYread_char (debugsock
, &c
))
196 goto panic_error
; /* mode */
198 if (MYread_word (debugsock
, &x
))
199 goto panic_error
; /* mask */
201 MYwrite_char (mumkid
[1], message
);
202 MYwrite_char (mumkid
[1], c
);
203 MYwrite_word (mumkid
[1], x
);
204 for (k
= 1, j
= 0; k
!= 0x80000000; k
*= 2, j
++)
206 && 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
);
273 && passon(debugsock
, mumkid
[1], 4))
274 goto panic_error
; /* bound */
278 /* Clear Breakpoint */
280 fprintf (stderr
, "RDP Clear Breakpoint\n");
282 MYwrite_char (mumkid
[1], message
);
283 if (passon (debugsock
, mumkid
[1], 4))
284 goto panic_error
; /* point */
290 fprintf (stderr
, "RDP Set Watchpoint\n");
292 if (MYread_word (debugsock
, &x
))
293 goto panic_error
; /* address */
295 if (MYread_char(debugsock
, &c
))
296 goto panic_error
; /* type */
298 if (MYread_char (debugsock
, &d
))
299 goto panic_error
; /* datatype */
301 MYwrite_char (mumkid
[1], message
);
302 MYwrite_word (mumkid
[1], x
);
303 MYwrite_char (mumkid
[1], c
);
304 MYwrite_char (mumkid
[1], d
);
306 && passon(debugsock
, mumkid
[1], 4))
307 goto panic_error
; /* bound */
311 /* Clear Watchpoint */
313 fprintf (stderr
, "RDP Clear Watchpoint\n");
315 MYwrite_char (mumkid
[1], message
);
316 if (passon (debugsock
, mumkid
[1], 4))
317 goto panic_error
; /* point */
323 fprintf (stderr
, "RDP Execute\n");
326 /* LEAVE THIS ONE 'TIL LATER... */
327 /* NEED TO WORK THINGS OUT */
329 /* NO ASCYNCHROUS RUNNING */
331 if (MYread_char(debugsock
, &c
))
332 goto panic_error
; /* return */
334 /* Remember incase bit 7 is set and we have to send back a word */
337 MYwrite_char(mumkid
[1], message
);
338 MYwrite_char(mumkid
[1], c
);
344 fprintf (stderr
, "RDP Step\n");
347 if (MYread_char(debugsock
, &c
))
348 goto panic_error
; /* return */
350 if (MYread_word(debugsock
, &x
))
351 goto panic_error
; /* ninstr */
353 MYwrite_char (mumkid
[1], message
);
354 MYwrite_char (mumkid
[1], c
);
355 MYwrite_word (mumkid
[1], x
);
361 fprintf (stderr
, "RDP Info\n");
363 /* INFO TARGET, SET RDI LEVEL */
364 if (MYread_word (debugsock
, &messagetype
))
365 goto panic_error
; /* info */
370 MYwrite_char (mumkid
[1], message
);
371 MYwrite_word (mumkid
[1], messagetype
);
374 case RDISet_RDILevel
:
375 MYwrite_char (mumkid
[1], message
);
376 MYwrite_word (mumkid
[1], messagetype
);
377 if (passon (debugsock
, mumkid
[1], 1))
378 goto panic_error
; /* argument */
382 /* Got to pass on a string argument */
383 MYwrite_char (mumkid
[1], message
);
384 MYwrite_word (mumkid
[1], messagetype
);
387 if (MYread_char (debugsock
, &c
))
390 MYwrite_char (mumkid
[1], c
);
395 kill (child
, SIGUSR1
);
396 MYwrite_char (debugsock
, RDP_Return
);
397 MYwrite_char (debugsock
, RDIError_UserInterrupt
);
400 case RDIVector_Catch
:
401 MYread_word (debugsock
, &x
);
402 MYwrite_char (mumkid
[1], message
);
403 MYwrite_word (mumkid
[1], messagetype
);
404 MYwrite_word (mumkid
[1], x
);
408 MYwrite_char (mumkid
[1], message
);
409 MYwrite_word (mumkid
[1], messagetype
);
413 MYwrite_char (mumkid
[1], message
);
414 MYwrite_word (mumkid
[1], messagetype
);
418 fprintf (stderr
, "Unrecognized RDIInfo request %d\n",
425 /* OS Operation Reply */
427 fprintf (stderr
, "RDP OS Reply\n");
429 MYwrite_char (mumkid
[1], message
);
430 if (MYread_char (debugsock
, &message
))
432 MYwrite_char (mumkid
[1], message
);
435 case 0: /* return value i.e. nothing else.*/
438 case 1: /* returns a byte... */
439 if (MYread_char(debugsock
, &c
))
442 MYwrite_char (mumkid
[1], c
);
445 case 2: /* returns a word... */
446 if (MYread_word(debugsock
, &x
))
449 MYwrite_word (mumkid
[1], x
);
457 fprintf (stderr
, "RDP Reset\n");
459 MYwrite_char (mumkid
[1], message
);
463 /* Hmm.. bad RDP operation */
464 fprintf (stderr
, "RDP Bad RDP request (%d)\n", message
);
465 MYwrite_char (debugsock
, RDP_Return
);
466 MYwrite_char (debugsock
, RDIError_UnimplementedMessage
);
471 if (FD_ISSET (kidmum
[0], &readfds
))
474 fprintf (stderr
, "->ARMulator\n");
476 /* Anything we get from the ARMulator has to go to the debugger... */
477 /* It is that simple! */
479 passon (kidmum
[0], debugsock
, 1);