1 /* Remote utility routines for the remote server for GDB.
2 Copyright (C) 1986, 1989, 1993 Free Software Foundation, Inc.
4 This file is part of GDB.
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2 of the License, or
9 (at your option) any later version.
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with this program; if not, write to the Free Software
18 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */
24 #include <sys/ioctl.h>
29 extern int remote_desc
;
30 extern int remote_debugging
;
40 void convert_ascii_to_int ();
41 void convert_int_to_ascii ();
42 void prepare_resume_reply ();
44 /* Open a connection to a remote debugger.
45 NAME is the filename used for communication. */
48 remote_open (name
, from_tty
)
56 remote_desc
= open (name
, O_RDWR
);
58 perror_with_name ("Could not open remote device");
60 ioctl (remote_desc
, TIOCGETP
, &sg
);
62 ioctl (remote_desc
, TIOCSETP
, &sg
);
64 fprintf (stderr
, "Remote debugging using %s\n", name
);
68 /* Convert hex digit A to a number. */
74 if (a
>= '0' && a
<= '9')
76 else if (a
>= 'a' && a
<= 'f')
79 error ("Reply contains invalid hex digit");
82 /* Convert number NIB to a hex digit. */
91 return 'a' + nib
- 10;
94 /* Send the command in BUF to the remote machine,
95 and read the reply into BUF.
96 Report an error if we get an error reply. */
106 error ("Remote failure reply: E");
109 /* Send a packet to the remote machine, with error checking.
110 The data of the packet is in BUF. */
117 unsigned char csum
= 0;
120 int cnt
= strlen (buf
);
123 /* Copy the packet into buffer BUF2, encapsulating it
124 and giving it a checksum. */
129 for (i
= 0; i
< cnt
; i
++)
135 *p
++ = tohex ((csum
>> 4) & 0xf);
136 *p
++ = tohex (csum
& 0xf);
138 /* Send it over and over until we get a positive ack. */
142 write (remote_desc
, buf2
, p
- buf2
);
143 read (remote_desc
, buf3
, 1);
145 while (buf3
[0] != '+');
152 while (read (remote_desc
, buf
, 1) != 1);
153 return buf
[0] & 0x7f;
156 /* Read a packet from the remote machine, with error checking,
157 and store it in BUF. */
164 unsigned char csum
, c
, c1
, c2
;
170 while ((c
= readchar ()) != '$');
183 c1
= fromhex (readchar ());
184 c2
= fromhex (readchar ());
185 if (csum
== (c1
<< 4) + c2
)
188 fprintf (stderr
, "Bad checksum, sentsum=0x%x, csum=0x%x, buf=%s\n",
189 (c1
<< 4) + c2
, csum
, buf
);
190 write (remote_desc
, "-", 1);
193 write (remote_desc
, "+", 1);
216 convert_int_to_ascii (from
, to
, n
)
225 nib
= ((ch
& 0xf0) >> 4) & 0x0f;
235 convert_ascii_to_int (from
, to
, n
)
242 nib1
= fromhex (*from
++);
243 nib2
= fromhex (*from
++);
244 *to
++ = (((nib1
& 0x0f) << 4) & 0xf0) | (nib2
& 0x0f);
253 extern char registers
[];
255 *buf
++ = tohex (regno
>> 4);
256 *buf
++ = tohex (regno
& 0xf);
258 convert_int_to_ascii (®isters
[REGISTER_BYTE (regno
)], buf
, 4);
266 prepare_resume_reply (buf
, status
, signal
)
268 unsigned char signal
;
275 nib
= ((signal
& 0xf0) >> 4);
276 *buf
++ = tohex (nib
);
278 *buf
++ = tohex (nib
);
280 buf
= outreg (PC_REGNUM
, buf
);
281 buf
= outreg (FP_REGNUM
, buf
);
282 buf
= outreg (SP_REGNUM
, buf
);
284 buf
= outreg (NPC_REGNUM
, buf
);
287 buf
= outreg (O7_REGNUM
, buf
);
294 decode_m_packet (from
, mem_addr_ptr
, len_ptr
)
296 unsigned int *mem_addr_ptr
, *len_ptr
;
300 *mem_addr_ptr
= *len_ptr
= 0;
302 while ((ch
= from
[i
++]) != ',')
304 *mem_addr_ptr
= *mem_addr_ptr
<< 4;
305 *mem_addr_ptr
|= fromhex (ch
) & 0x0f;
308 for (j
= 0; j
< 4; j
++)
310 if ((ch
= from
[i
++]) == 0)
312 *len_ptr
= *len_ptr
<< 4;
313 *len_ptr
|= fromhex (ch
) & 0x0f;
318 decode_M_packet (from
, mem_addr_ptr
, len_ptr
, to
)
320 unsigned int *mem_addr_ptr
, *len_ptr
;
324 *mem_addr_ptr
= *len_ptr
= 0;
326 while ((ch
= from
[i
++]) != ',')
328 *mem_addr_ptr
= *mem_addr_ptr
<< 4;
329 *mem_addr_ptr
|= fromhex (ch
) & 0x0f;
332 while ((ch
= from
[i
++]) != ':')
334 *len_ptr
= *len_ptr
<< 4;
335 *len_ptr
|= fromhex (ch
) & 0x0f;
338 convert_ascii_to_int (&from
[i
++], to
, *len_ptr
);
This page took 0.043014 seconds and 5 git commands to generate.