1 /* Remote debugging with the XLNT Designs, Inc (XDI) NetROM.
2 Copyright 1990, 1991, 1992, 1995 Free Software Foundation, Inc.
6 15050 Avenue of Science, Suite 106
10 Adapted from work done at Cygnus Support in remote-nindy.c,
11 later merged in by Stan Shebs at Cygnus.
13 This file is part of GDB.
15 This program is free software; you can redistribute it and/or modify
16 it under the terms of the GNU General Public License as published by
17 the Free Software Foundation; either version 2 of the License, or
18 (at your option) any later version.
20 This program is distributed in the hope that it will be useful,
21 but WITHOUT ANY WARRANTY; without even the implied warranty of
22 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
23 GNU General Public License for more details.
25 You should have received a copy of the GNU General Public License
26 along with this program; if not, write to the Free Software
27 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */
42 #include <sys/types.h>
43 #include <sys/socket.h>
44 #include <sys/ioctl.h>
45 #include <netinet/in.h>
52 /* Packet header found on every packet sent to/from GDB. */
54 typedef struct gpkthdr
{
55 unsigned char csum
; /* Check sum */
56 unsigned char seq_num
; /* Sequence number */
57 unsigned short len
; /* Number of bytes in packet */
58 unsigned char cmd
; /* GDB command */
60 unsigned long addr
; /* Address if needed */
61 unsigned long datalen
; /* # of bytes to read/write */
64 #define GDB_START_DELIMITER '['
65 #define GDB_END_DELIMITER ']'
69 #define GDB_QUERY_CMD 0x01
70 #define GDB_STATUS 0x02
71 #define GDB_READ_REGS 0x03
72 #define GDB_WRITE_REGS 0x04
73 #define GDB_READ_MEM 0x05
74 #define GDB_WRITE_MEM 0x06
75 #define GDB_CONTINUE 0x07
82 #define GDB_READ_REG_RESP 0x13
83 #define GDB_READ_MEM_RESP 0x14
84 #define GDB_WRITE_REG_RESP 0x15
85 #define GDB_WRITE_MEM_RESP 0x16
87 #define GDB_BP_TRAP "05"
88 #define GDB_BUSERR_TRAP "10"
89 #define GDB_ILLOP_TRAP "40"
91 #define GDB_ACK_VALUE "OK"
93 /* Default ports used to talk with the NetROM. */
95 #define DEFAULT_NETROM_TARGET_PORT 1235
96 #define DEFAULT_NETROM_LOAD_PORT 1236
97 #define DEFAULT_NETROM_CONTROL_PORT 1237
99 #define UC(b) (((long)b)&0xff)
101 #define NROM_BUF_SIZE 2048
102 #define MAX_SEND_ATTEMPTS 10
103 #define READ_BUF_SIZE 2048
105 /* Definitions for filetype. */
107 #define BINARY_FTYPE 0
111 #if 0 /* for debugging, if anyone cares */
112 static char *GCMDTYPE
[] = {
134 "GDB_WRITE_REG_RESP",
139 static void nrom_attach
PARAMS ((char *, int));
141 static int nrom_can_run
PARAMS ((void));
143 static void nrom_close
PARAMS ((int));
145 static void nrom_create_inferior
PARAMS ((char *, char *, char **));
147 static void nrom_detach
PARAMS ((char *, int));
149 static void nrom_fetch_registers
PARAMS ((int));
151 static void nrom_files_info
PARAMS ((struct target_ops
*));
153 static void nrom_kill
PARAMS ((void));
155 static void nrom_load
PARAMS ((char *, int));
157 static void nrom_mourn
PARAMS ((void));
159 static void nrom_open
PARAMS ((char *,int));
161 static void nrom_resume
PARAMS ((int, int, enum target_signal
));
163 static void nrom_prepare_to_store
PARAMS ((void));
165 static void nrom_store_registers
PARAMS ((int));
167 static int nrom_wait
PARAMS ((int pid
, struct target_waitstatus
*status
));
169 static int nrom_xfer_inferior_memory
PARAMS ((CORE_ADDR
, char *, int, int,
170 struct target_ops
*));
172 static int nrom_write_inferior_memory
PARAMS ((CORE_ADDR
, char *, int));
174 static int nrom_read_inferior_memory
PARAMS ((CORE_ADDR
, char *, int));
178 static void nrom_set_target_port
PARAMS ((char *, int));
180 static void nrom_set_control_port
PARAMS ((char *, int));
182 static void nrom_set_load_port
PARAMS ((char *, int));
184 static void nrom_set_ipaddr
PARAMS ((char *, int));
186 static void nrom_set_filetype
PARAMS ((char *, int));
188 static void nrom_show_status
PARAMS ((char *, int));
190 static void nrom_passthru
PARAMS ((char *, int));
192 /* Packet functions. */
194 static void build_pkt
PARAMS ((int, unsigned char *, long,
195 unsigned char *, unsigned long, unsigned long,
198 static int compute_csum
PARAMS ((unsigned char *, int));
201 static void dump_pkt
PARAMS ((GPKTHDR
*, unsigned char *));
204 static int get_seq_number
PARAMS ((void));
206 static char *hex2mem
PARAMS ((char *, char *, int));
208 static char *mem2hex
PARAMS ((char *, char *, int));
210 static void nrom_send
PARAMS ((int, char *, int, long, long, char *));
212 static void send_query_cmd
PARAMS ((void));
214 static int send_pkt
PARAMS ((int, char *, int, long, int));
216 static int read_pkt
PARAMS ((char *));
218 static void send_query_cmd
PARAMS ((void));
220 static int tohex
PARAMS ((int));
222 static int parse_pkt
PARAMS ((unsigned char *, GPKTHDR
*, char *));
224 static int writen
PARAMS ((int, char *, int));
226 /* Private globals. */
228 /* We talk to the NetROM over these sockets. */
230 static int nrom_load_sock
= -1;
231 static int nrom_targ_sock
= -1;
232 static int nrom_ctrl_sock
= -1;
234 static serial_t load_desc
= NULL
;
235 static serial_t targ_desc
= NULL
;
236 static serial_t ctrl_desc
= NULL
;
238 /* For binding to the socket we ned a sockaddr_in structure. */
240 static struct sockaddr_in nrom_sin
;
242 /* The IP Address of the NetROM is needed so we know who to talk to. */
244 static unsigned long nrom_ipaddr
= 0;
246 static int load_port
= DEFAULT_NETROM_LOAD_PORT
;
247 static int target_port
= DEFAULT_NETROM_TARGET_PORT
;
248 static int control_port
= DEFAULT_NETROM_CONTROL_PORT
;
250 static int nrom_filetype
= BINARY_FTYPE
;
252 static unsigned char host_seq_num
= 0;
254 static char hexchars
[] = "0123456789abcdef";
256 static char freadbuf
[READ_BUF_SIZE
];
258 static char readbuf
[NROM_BUF_SIZE
];
259 static int bufdata
= 0;
260 static int bufindex
= 0;
262 static char workbuf
[NROM_BUF_SIZE
];
263 static char sendbuf
[NROM_BUF_SIZE
];
265 static char nrom_hostname
[100];
267 /* Forward data declaration. */
269 extern struct target_ops nrom_ops
;
271 /* This routine builds a packet to send to gdb running on the host. */
274 build_pkt (cmd
, data
, datalen
, pkt
, addr
, len
, seq
)
290 phdr
.len
= sizeof(GPKTHDR
) + datalen
;
293 phdr
.pad
[0] = phdr
.pad
[1] = phdr
.pad
[2] = 0;
296 /* Convert packet header to ASCII. */
297 dptr
= mem2hex ((char *) &phdr
, pkt
, sizeof(GPKTHDR
));
299 /* Calculate pkt length now that it is converted. */
300 plen
= (int) ((unsigned long)dptr
- (unsigned long)pkt
) + datalen
;
301 /* Put data in packet. */
303 memcpy (dptr
, data
, datalen
);
305 /* Compute checksum. For computing checksum we skip first two bytes
306 since this is where the checksum will go. */
308 csum
= compute_csum (pktptr
, plen
- 2);
309 *pkt
++ = hexchars
[csum
>> 4];
310 *pkt
++ = hexchars
[csum
% 16];
316 compute_csum (data
, len
)
331 #if 0 /* for debugging, if anyone cares */
339 printf_filtered ("PACKET: csum = %x,seq = %d,len = %d\n",hdr
->csum
,hdr
->seq_num
,
342 printf_filtered ("cmd = %s,addr = %x, datalen = %d\n", GCMDTYPE
[hdr
->cmd
],
343 hdr
->addr
,hdr
->datalen
);
346 for (i
= 0; i
< hdr
->datalen
* 2; i
++)
347 printf_filtered ("%x",data
[i
]);
348 printf_filtered ("\n");
356 return host_seq_num
++;
363 if ((ch
>= 'a') && (ch
<= 'f'))
364 return (ch
- 'a' + 10);
365 if((ch
>= 'A') && (ch
<= 'F'))
366 return ((ch
- 'A') + 10);
367 if ((ch
>= '0') && (ch
<= '9'))
372 /* Convert the hex array pointed to by buf into binary to be placed in mem
373 return a pointer to the character AFTER the last byte written. */
376 hex2mem(buf
, mem
, count
)
384 for (i
= 0; i
< count
; i
++)
386 ch
= hex(*buf
++) << 4;
387 ch
= ch
+ hex(*buf
++);
393 /* Convert the memory pointed to by mem into hex, placing result in buf
394 return a pointer to the last char put in buf (null) */
397 mem2hex (mem
, buf
, count
)
405 for (i
= 0; i
< count
; i
++)
408 *buf
++ = hexchars
[ch
>> 4];
409 *buf
++ = hexchars
[ch
% 16];
415 /* Scan input from the remote system, until STRING is found. If BUF is non-
416 zero, then collect input until we have collected either STRING or BUFLEN-1
417 chars. In either case we terminate BUF with a 0. If input overflows BUF
418 because STRING can't be found, return -1, else return number of chars in BUF
419 (minus the terminating NUL). Note that in the non-overflow case, STRING
420 will be at the end of BUF. */
433 c
= SERIAL_READCHAR (ctrl_desc
, 5);
446 fputc_unfiltered (c
, gdb_stdout
);
455 nrom_control_send (s
, nbytes
)
459 SERIAL_WRITE (ctrl_desc
, s
, nbytes
);
471 open_socket (name
, port
)
478 sprintf (sockname
, "%s:%d", name
, port
);
479 desc
= SERIAL_OPEN (sockname
);
481 perror_with_name (sockname
);
486 /* Download a file specified in ARGS to the netROM. */
489 nrom_load (args
, fromtty
)
493 int fd
, rd_amt
, fsize
;
494 struct sockaddr_in sin
;
497 char *downloadstring
= "download 0\n";
499 /* Tell the netrom to get ready to download. */
500 if (nrom_control_send (downloadstring
, strlen (downloadstring
)) < 0)
501 error ("nrom_load: control_send() of `%s' failed", downloadstring
);
503 expect ("Waiting for a connection...\n");
505 load_desc
= open_socket (nrom_hostname
, load_port
);
507 pbfd
= bfd_openr (args
, 0);
511 if (!bfd_check_format (pbfd
, bfd_object
))
512 error ("\"%s\": not in executable format: %s",
513 args
, bfd_errmsg (bfd_get_error ()));
515 for (section
= pbfd
->sections
; section
; section
= section
->next
)
517 if (bfd_get_section_flags (pbfd
, section
) & SEC_ALLOC
)
519 bfd_vma section_address
;
520 unsigned long section_size
;
521 const char *section_name
;
523 section_name
= bfd_get_section_name (pbfd
, section
);
524 section_address
= bfd_get_section_vma (pbfd
, section
);
525 section_size
= bfd_section_size (pbfd
, section
);
527 if (bfd_get_section_flags (pbfd
, section
) & SEC_LOAD
)
531 printf_filtered ("[Loading section %s at %x (%d bytes)]\n",
532 section_name
, section_address
,
537 while (section_size
> 0)
542 count
= min (section_size
, 1024);
544 bfd_get_section_contents (pbfd
, section
, buffer
, fptr
,
547 SERIAL_WRITE (load_desc
, buffer
, count
);
548 section_address
+= count
;
550 section_size
-= count
;
553 else /* BSS and such */
555 printf_filtered ("[section %s: not loading]\n",
562 error ("\"%s\": Could not open", args
);
564 SERIAL_CLOSE (load_desc
);
568 /* This is called not only when we first attach, but also when the
569 user types "run" after having attached. */
572 nrom_create_inferior (execfile
, args
, env
)
579 /* Open a connection to the remote NetROM devices. */
582 nrom_open (name
, from_tty
)
588 if (!name
|| strchr (name
, '/') || strchr (name
, ':'))
590 "To open a NetROM connection, you must specify the hostname\n\
591 or IP address of the NetROM device you wish to use.");
593 strcpy (nrom_hostname
, name
);
595 target_preopen (from_tty
);
597 unpush_target (&nrom_ops
);
599 targ_desc
= open_socket (nrom_hostname
, target_port
);
600 ctrl_desc
= open_socket (nrom_hostname
, control_port
);
602 push_target (&nrom_ops
);
605 printf_filtered ("Connected to NetROM device \"%s\"\n", nrom_hostname
);
614 /* Close out all files and local state before this target loses control. */
617 nrom_close (quitting
)
621 SERIAL_CLOSE (load_desc
);
623 SERIAL_CLOSE (targ_desc
);
625 SERIAL_CLOSE (ctrl_desc
);
632 /* Attach to the target that is already loaded and possibly running */
635 nrom_attach (args
, from_tty
)
643 printf_filtered ("Attaching to NetROM\n");
645 /* clear any pending data on the socket */
646 printf_filtered ("Waiting for pending data to arrive... ");
649 printf_filtered ("that's long enough!\n");
652 if (ioctl(nrom_targ_sock
, FIONREAD
, &nwaiting
) != 0)
654 /* couldn't determine data left */
655 perror("nrom_attach: ioctl FIONREAD");
658 else if (nwaiting
> 0)
660 /* flush incoming data */
661 while (nwaiting
!= 0)
663 if (read (nrom_targ_sock
, buf
, 1) < 0)
665 perror("nrom_attach: read");
668 if (remote_debug
> 2)
669 putc(buf
[0], stdout
);
679 printf_filtered ("Pending data removed\n");
681 /* We will get a task spawn event immediately. */
683 target_has_execution
= 1;
689 /* Terminate the open connection to the remote debugger. Use this
690 when you want to detach and do something else with your gdb. */
693 nrom_detach (args
, from_tty
)
699 printf_filtered ("Ending remote debugging\n");
702 /* Tell the remote machine to resume. */
705 nrom_prepare_to_store()
710 nrom_resume (pid
, step
, siggnal
)
712 enum target_signal siggnal
;
715 send_pkt (GDB_STEP
, NULL
, 0, 0, 0);
717 send_pkt (GDB_CONTINUE
, NULL
, 0, 0, 0);
720 /* Wait until the remote machine stops, then return,
721 storing status in STATUS just as `wait' would. */
724 nrom_wait (pid
, status
)
726 struct target_waitstatus
*status
;
728 static char pkt
[NROM_BUF_SIZE
], inbuf
[NROM_BUF_SIZE
];
731 status
->kind
= TARGET_WAITKIND_EXITED
;
732 status
->value
.integer
= 0;
736 if (read_pkt (pkt
) == -1)
739 if (parse_pkt (pkt
, &phdr
, inbuf
) < 0)
742 printf_filtered ("Bad packet in nrom_wait\n");
747 /* Got good packet. Verify command is right. */
748 if (phdr
.cmd
!= GDB_STATUS
)
750 /* Wrong response. Resend command. */
754 /* Packet is fine. Exit loop. */
759 /* Read the remote registers. */
762 nrom_fetch_registers (regno
)
765 char buf
[NROM_BUF_SIZE
];
766 char regs
[REGISTER_BYTES
];
770 printf_filtered ("reg no is %d\n",regno
);
773 nrom_send (GDB_READ_REGS
, NULL
, 0, -1, 0, buf
);
774 memcpy (regs
, buf
, REGISTER_BYTES
);
775 for (i
= 0; i
< NUM_REGS
; i
++)
776 supply_register (i
, ®s
[REGISTER_BYTE(i
)]);
778 nrom_send (GDB_READ_REGS
, NULL
, 0, regno
, 0, buf
);
780 supply_register(regno
,buf
);
783 memcpy (regs
, buf
, REGISTER_BYTES
);
784 for (i
= 0; i
< NUM_REGS
; i
++)
785 supply_register (i
, ®s
[REGISTER_BYTE(i
)]);
791 nrom_send (cmd
, data
, datalen
, addr
, len
, resp
)
800 char inbuf
[NROM_BUF_SIZE
];
804 while (send_pkt (cmd
, data
, datalen
, addr
, len
) < 0)
806 if (read_pkt (inbuf
) != -1)
808 if (parse_pkt (inbuf
, &phdr
, resp
) < 0)
810 if (phdr
.cmd
!= GDB_NACK
)
817 nrom_set_filetype (args
, fromtty
)
822 nrom_filetype
= BINARY_FTYPE
;
823 else if (args
[0] == 'm')
824 nrom_filetype
= MOTO_SREC
;
825 else if (args
[0] == 'i')
826 nrom_filetype
= INTEL_HEX
;
828 printf_filtered ("Unknown file type\n");
832 nrom_set_ipaddr (args
, fromtty
)
839 unsigned long newip
= 0;
841 /* First do a check to see if they typed in a hostname. */
843 error ("Please enter a hostname or IP address");
845 h
= gethostbyname (args
);
848 /* It is a hostname. We just need the ipaddress. */
849 memcpy (&nrom_ipaddr
, h
->h_addr
, h
->h_length
);
853 /* Better be in decimal dot notation,ie. xx.xx.xx.xx */
854 if (isdigit (args
[0]) && strchr (args
, '.'))
861 while((*args
) && (*args
!= '.'))
868 val
= (int) strtol (buf
, NULL
, 10);
871 error ("Invalid IP address");
874 newip
|= val
<< (8 * j
);
881 error ("Invalid host name/address");
888 nrom_set_load_port (args
, fromtty
)
892 load_port
= (int) strtol (args
, NULL
, 10);
896 nrom_set_target_port (args
, from_tty
)
900 target_port
= (int) strtol (args
, NULL
, 10);
904 nrom_set_control_port (args
, fromtty
)
908 control_port
= (int) strtol (args
, NULL
, 10);
912 nrom_show_status (args
,from_tty
)
918 i
= (unsigned char *)&nrom_ipaddr
;
920 printf_filtered ("NetROM target port is %d\n", target_port
);
921 printf_filtered ("NetROM download port is %d\n", load_port
);
922 printf_filtered ("NetROM debug control port is %d\n", control_port
);
924 printf_filtered ("NetROM IP Address is %d.%d.%d.%d\n",
925 UC(i
[0]), UC(i
[1]), UC(i
[2]), UC(i
[3]));
926 if (nrom_filetype
== BINARY_FTYPE
)
927 printf_filtered ("download filetype is binary\n");
928 else if (nrom_filetype
== MOTO_SREC
)
929 printf_filtered ("download filetype is moto-srec\n");
930 else if (nrom_filetype
== INTEL_HEX
)
931 printf_filtered ("download filetype is intel-hex\n");
934 /* Pass arguments directly to the NetROM. */
937 nrom_passthru (args
, fromtty
)
943 sprintf(buf
, "%s\n", args
);
944 if (nrom_control_send (buf
, strlen (buf
)) < 0)
945 error ("nrom_reset: control_send() of `%s'failed", args
);
949 nrom_store_registers (regno
)
952 char buf
[NROM_BUF_SIZE
];
957 for (i
= 0; i
< REGISTER_BYTES
; i
++)
959 *p
++ = tohex ((registers
[i
] >> 4) & 0xf);
960 *p
++ = tohex (registers
[i
] & 0xf);
963 nrom_send (GDB_WRITE_REGS
, buf
, REGISTER_BYTES
* 2, 0, REGISTER_BYTES
* 2,
968 nrom_xfer_inferior_memory (memaddr
, myaddr
, len
, write
, target
)
973 struct target_ops
*target
;
976 return nrom_write_inferior_memory (memaddr
, myaddr
, len
);
978 return nrom_read_inferior_memory (memaddr
, myaddr
, len
);
981 /* Copy LEN bytes of data from debugger memory at MYADDR
982 to inferior's memory at MEMADDR. Returns errno value. */
985 nrom_write_inferior_memory (memaddr
, myaddr
, len
)
990 char buf
[NROM_BUF_SIZE
],obuf
[NROM_BUF_SIZE
];
995 for (i
= 0; i
< len
; i
++)
997 *p
++ = tohex ((myaddr
[i
] >> 4) & 0xf);
998 *p
++ = tohex (myaddr
[i
] & 0xf);
1001 nrom_send (GDB_WRITE_MEM
, obuf
, len
* 2, memaddr
, len
, buf
);
1006 /* Read LEN bytes from inferior memory at MEMADDR. Put the result
1007 at debugger address MYADDR. Returns errno value. */
1010 nrom_read_inferior_memory (memaddr
, myaddr
, len
)
1015 char buf
[NROM_BUF_SIZE
];
1017 nrom_send (GDB_READ_MEM
, NULL
, 0, memaddr
, len
, buf
);
1018 memcpy (myaddr
, buf
, len
);
1023 nrom_files_info (ignore
)
1024 struct target_ops
*ignore
;
1031 unpush_target (&nrom_ops
);
1032 generic_mourn_inferior ();
1035 /* Convert a packet into its parts and verify check sum. */
1038 parse_pkt (pkt
, hdr
, data
)
1043 unsigned char xcsum
;
1044 unsigned char *dptr
;
1046 /* Build packet header from received data. */
1047 hex2mem (pkt
, (char *) hdr
, sizeof(GPKTHDR
));
1048 if (remote_debug
> 1)
1050 printf_filtered ("Packet received: csum = %x,seq number = %x,len = %d\n",
1051 hdr
->csum
,hdr
->seq_num
,hdr
->len
);
1052 printf_filtered ("cmd = %x,addr = %x,datalen = %d\n",
1053 hdr
->cmd
,hdr
->addr
,hdr
->datalen
);
1055 /* Skip first two bytes of packet when computing checksum. */
1056 dptr
= (sizeof(GPKTHDR
) * 2) + pkt
;
1058 if (remote_debug
> 1)
1060 printf_filtered ("Computing checksum over pkt %s\n",pkt
);
1061 printf_filtered ("Of length %d\n",strlen(pkt
));
1063 xcsum
= compute_csum (pkt
, strlen (pkt
));
1064 if (xcsum
!= hdr
->csum
)
1067 printf_filtered ("Checksum failure: computed %x, received %x\n",xcsum
,
1072 /* Copy data portion to callers data buffer converting from ASCII
1073 to data as we go. */
1074 hex2mem (dptr
, data
, hdr
->datalen
);
1083 struct sockaddr_in from
;
1084 int from_len
= sizeof(from
);
1095 /* Don't let us get wedged if the target is losing. */
1102 /* Perform read on socket. This will wait. */
1103 bufdata
= recvfrom (nrom_targ_sock
, readbuf
, n
, 0, &from
, &from_len
);
1106 printf_filtered ("Error on socket read of %d\n",errno
);
1109 if (remote_debug
> 2)
1111 readbuf
[bufdata
] = '\0';
1112 printf_filtered ("Received %d bytes. Data is %s\n",
1117 /* skip stuff between packets */
1118 while (gotstart
== 0 && bufdata
!= 0
1119 && readbuf
[bufindex
] != GDB_START_DELIMITER
)
1125 /* look for a start if we haven't seen one */
1126 if (gotstart
== 0 && bufdata
!= 0
1127 && readbuf
[bufindex
] == GDB_START_DELIMITER
)
1134 /* copy packet data */
1137 while (bufdata
&& readbuf
[bufindex
] != GDB_END_DELIMITER
)
1139 *p
= readbuf
[bufindex
];
1144 if (total_len
> NROM_BUF_SIZE
)
1146 error ("read_pkt: packet length exceeds %d\n",
1152 if (remote_debug
> 2)
1153 printf_filtered ("Packet is '%s'\n", pkt
);
1156 /* Make sure this is the end of the packet. */
1157 if (gotstart
!= 0 && bufdata
!= 0
1158 && readbuf
[bufindex
] == GDB_END_DELIMITER
)
1163 /* Ensure that the packet is terminated. */
1165 if (remote_debug
> 2)
1166 printf_filtered ("Returning '%s'\n", pkt
);
1175 while (send_pkt (GDB_QUERY_CMD
, NULL
, 0, 0, 0) < 0)
1180 send_pkt (cmd
, data
, datalen
, addr
, len
)
1189 struct sockaddr_in mysin
;
1194 /* Get a sequence number for this packet. */
1195 seq
= get_seq_number ();
1196 /* Build the packet. */
1197 build_pkt (cmd
, data
, datalen
, workbuf
, addr
, len
, seq
);
1198 /* Put delimiters around the pkt. */
1199 memset (sendbuf
, 0, NROM_BUF_SIZE
);
1200 sendbuf
[0] = GDB_START_DELIMITER
;
1201 strcat (sendbuf
, workbuf
);
1202 c
[0] = GDB_END_DELIMITER
;
1204 strcat (sendbuf
, c
);
1206 /* Send the packet out on our socket. */
1207 if (remote_debug
> 1)
1208 printf_filtered ("Sending pkt: %s\n", sendbuf
);
1209 mysin
.sin_family
= AF_INET
;
1210 mysin
.sin_port
= target_port
;
1211 mysin
.sin_addr
.S_un
.S_addr
= nrom_ipaddr
;
1214 while (send_cnt
< MAX_SEND_ATTEMPTS
)
1216 if (sendto (nrom_targ_sock
, sendbuf
, strlen(sendbuf
), 0, &mysin
,
1217 sizeof(struct sockaddr_in
)) < 0)
1219 printf_filtered ("sendto error of %d\n", errno
);
1225 if (send_cnt
>= MAX_SEND_ATTEMPTS
)
1227 printf_filtered ("Socket send failed after %d tries\n",
1235 /* Convert number NIB to a hex digit. */
1244 return 'a' + nib
- 10;
1247 /* snatched from Stevens, pp279+ */
1250 writen (sock
, ptr
, nbytes
)
1255 int nleft
, nwritten
;
1261 nwritten
= write (sock
, buf
, nleft
);
1267 return (nbytes
- nleft
);
1270 /* Define the target vector. */
1272 struct target_ops nrom_ops
= {
1273 "nrom", /* to_shortname */
1274 "Remote XDI `NetROM' target", /* to_longname */
1275 "Remote debug using a NetROM over Ethernet",
1276 nrom_open
, /* to_open */
1281 nrom_wait
, /* to_wait */
1282 nrom_fetch_registers
, /* to_fetch_registers */
1283 nrom_store_registers
, /* to_store_registers */
1284 nrom_prepare_to_store
, /* to_prepare_to_store */
1285 nrom_xfer_inferior_memory
, /* to_xfer_memory */
1286 nrom_files_info
, /* to_files_info */
1287 NULL
, /* to_insert_breakpoint */
1288 NULL
, /* to_remove_breakpoint */
1297 nrom_create_inferior
, /* to_create_inferior */
1300 0, /* to_notice_signals */
1302 download_stratum
, /* to_stratum */
1308 0, /* to_has_execution */
1309 NULL
, /* sections */
1310 NULL
, /* sections_end */
1311 OPS_MAGIC
/* to_magic */
1315 _initialize_remote_nrom ()
1317 add_target (&nrom_ops
);
1319 /* Add some commands for helpers. */
1320 add_cmd ("nrom_ipaddr", no_class
, nrom_set_ipaddr
,
1321 "Set the IP Address of the NetROM\n",
1323 add_cmd ("target_port", no_class
, nrom_set_target_port
,
1324 "Set the Port to use for NetROM target communication\n",
1326 add_cmd ("load_port", no_class
, nrom_set_load_port
,
1327 "Set the Port to use for NetROM downloads\n",
1329 add_cmd ("control_port", no_class
, nrom_set_control_port
,
1330 "Set the Port to use for NetROM debugger services\n",
1332 add_cmd ("nrom_filetype", no_class
, nrom_set_filetype
,
1333 "Set the filetype to use on NetROM downloads",
1336 add_cmd ("nrom", no_class
, nrom_show_status
,
1337 "Show the current NetROM status\n",
1340 add_cmd ("nrom", no_class
, nrom_passthru
,
1341 "Pass arguments as command to NetROM",