/* XMODEM support for GDB, the GNU debugger.
- Copyright 1995 Free Software Foundation, Inc.
+ Copyright 1995, 2000, 2001 Free Software Foundation, Inc.
-This file is part of GDB.
+ This file is part of GDB.
-This program is free software; you can redistribute it and/or modify
-it under the terms of the GNU General Public License as published by
-the Free Software Foundation; either version 2 of the License, or
-(at your option) any later version.
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2 of the License, or
+ (at your option) any later version.
-This program is distributed in the hope that it will be useful,
-but WITHOUT ANY WARRANTY; without even the implied warranty of
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-GNU General Public License for more details.
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
-You should have received a copy of the GNU General Public License
-along with this program; if not, write to the Free Software
-Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
+ You should have received a copy of the GNU General Public License
+ along with this program; if not, write to the Free Software
+ Foundation, Inc., 59 Temple Place - Suite 330,
+ Boston, MA 02111-1307, USA. */
#include "defs.h"
#include "serial.h"
static int crcflag; /* Sez we are using CRC's instead of cksums */
static int
-readchar (desc, timeout)
- serial_t desc;
- int timeout;
+readchar (struct serial *desc, int timeout)
{
int c;
- c = SERIAL_READCHAR (desc, timeout);
+ c = serial_readchar (desc, timeout);
if (remote_debug > 0)
- fputc_unfiltered (c, gdb_stderr);
+ fputc_unfiltered (c, gdb_stdlog);
if (c >= 0)
return c;
/* Call this to init the fast CRC-16 calculation table. */
static void
-crcinit ()
+crcinit (void)
{
static int crctab_inited = 0;
int val;
crc ^= CRC16;
}
- crctab [val] = crc;
+ crctab[val] = crc;
}
crctab_inited = 1;
/* Calculate a CRC-16 for the LEN byte message pointed at by P. */
static unsigned short
-docrc (p, len)
- unsigned char *p;
- int len;
+docrc (unsigned char *p, int len)
{
unsigned short crc = 0;
while (len-- > 0)
- crc = (crc << 8) ^ crctab [(crc >> 8) ^ *p++];
+ crc = (crc << 8) ^ crctab[(crc >> 8) ^ *p++];
return crc;
}
send NAK or CRC request. */
int
-xmodem_init_xfer (desc)
- serial_t desc;
+xmodem_init_xfer (struct serial *desc)
{
int c;
int i;
}
/* Take 128 bytes of data and make a packet out of it.
- *
- * Each packet looks like this:
- * +-----+-------+-------+------+-----+
- * | SOH | Seq1. | Seq2. | data | SUM |
- * +-----+-------+-------+------+-----+
- * SOH = 0x01
- * Seq1 = The sequence number.
- * Seq2 = The complement of the sequence number.
- * Data = A 128 bytes of data.
- * SUM = Add the contents of the 128 bytes and use the low-order
- * 8 bits of the result.
+
+ * Each packet looks like this:
+ * +-----+-------+-------+------+-----+
+ * | SOH | Seq1. | Seq2. | data | SUM |
+ * +-----+-------+-------+------+-----+
+ * SOH = 0x01
+ * Seq1 = The sequence number.
+ * Seq2 = The complement of the sequence number.
+ * Data = A 128 bytes of data.
+ * SUM = Add the contents of the 128 bytes and use the low-order
+ * 8 bits of the result.
*
* send_xmodem_packet fills in the XMODEM fields of PACKET and sends it to the
* remote system. PACKET must be XMODEM_PACKETSIZE bytes long. The data must
*/
void
-xmodem_send_packet (desc, packet, len, hashmark)
- serial_t desc;
- unsigned char *packet;
- int len;
- int hashmark;
+xmodem_send_packet (struct serial *desc, unsigned char *packet, int len, int hashmark)
{
int i;
int retries;
int pktlen;
int datasize;
-
+
/* build the packet header */
packet[1] = blknum;
packet[2] = ~blknum;
blknum++;
-
+
if (len <= XMODEM_DATASIZE)
{
packet[0] = SOH;
datasize = XMODEM_1KDATASIZE;
}
else
- abort (); /* Packet way too large */
+ internal_error (__FILE__, __LINE__, "failed internal consistency check"); /* Packet way too large */
/* Add ^Z padding if packet < 128 (or 1024) bytes */
for (i = 3; i < datasize + 3; i++)
sum += packet[i];
- packet[3 + datasize] = sum; /* add the checksum */
+ packet[3 + datasize] = sum; /* add the checksum */
pktlen = datasize + 4;
}
{
int c;
- SERIAL_WRITE (desc, packet, pktlen);
+ serial_write (desc, packet, pktlen);
c = readchar (desc, 3);
switch (c)
}
}
- SERIAL_WRITE (desc, "\004", 1); /* Send an EOT */
+ serial_write (desc, "\004", 1); /* Send an EOT */
error ("xmodem_send_packet: Excessive retries.");
}
/* Finish off the transfer. Send out the EOT, and wait for an ACK. */
void
-xmodem_finish_xfer (desc)
- serial_t desc;
+xmodem_finish_xfer (struct serial *desc)
{
int retries;
{
int c;
- SERIAL_WRITE (desc, "\004", 1); /* Send an EOT */
+ serial_write (desc, "\004", 1); /* Send an EOT */
c = readchar (desc, 3);
switch (c)