Based on patches from H.J. Lu <hjl@nynexst.com>:
[deliverable/binutils-gdb.git] / gdb / sparcl-tdep.c
CommitLineData
0e887539
SG
1/* Target dependent code for the Fujitsu SPARClite for GDB, the GNU debugger.
2 Copyright 1994, 1995 Free Software Foundation, Inc.
b955f680
KH
3
4This file is part of GDB.
5
6This program is free software; you can redistribute it and/or modify
7it under the terms of the GNU General Public License as published by
8the Free Software Foundation; either version 2 of the License, or
9(at your option) any later version.
10
11This program is distributed in the hope that it will be useful,
12but WITHOUT ANY WARRANTY; without even the implied warranty of
13MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14GNU General Public License for more details.
15
16You should have received a copy of the GNU General Public License
17along with this program; if not, write to the Free Software
18Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */
19
20#include "defs.h"
21#include "gdbcore.h"
22#include "breakpoint.h"
0e887539
SG
23#include "target.h"
24#include "serial.h"
25#include <sys/types.h>
26#include <sys/time.h>
45993f61
SC
27
28#if defined(__GO32__) || defined(WIN32)
29#undef HAVE_SOCKETS
30#else
31#define HAVE_SOCKETS
32#endif
33
34
35#ifdef HAVE_SOCKETS
4887063b 36#include <unistd.h>
0e887539
SG
37#include <sys/socket.h>
38#include <netinet/in.h>
39#include <netdb.h>
a76ef70a 40#endif
0e887539
SG
41
42extern struct target_ops sparclite_ops; /* Forward decl */
43extern struct target_ops remote_ops;
44
45static char *remote_target_name = NULL;
46static serial_t remote_desc = NULL;
0e887539 47static int serial_flag;
45993f61 48#ifdef HAVE_SOCKETS
a76ef70a
SG
49static int udp_fd = -1;
50#endif
0e887539
SG
51
52static serial_t open_tty PARAMS ((char *name));
53static int send_resp PARAMS ((serial_t desc, char c));
54static void close_tty PARAMS ((int ignore));
45993f61 55#ifdef HAVE_SOCKETS
0e887539
SG
56static int recv_udp_buf PARAMS ((int fd, unsigned char *buf, int len, int timeout));
57static int send_udp_buf PARAMS ((int fd, unsigned char *buf, int len));
a76ef70a 58#endif
0e887539
SG
59static void sparclite_open PARAMS ((char *name, int from_tty));
60static void sparclite_close PARAMS ((int quitting));
61static void download PARAMS ((char *target_name, char *args, int from_tty,
62 void (*write_routine) (bfd *from_bfd,
63 asection *from_sec,
64 file_ptr from_addr,
65 bfd_vma to_addr, int len),
66 void (*start_routine) (bfd_vma entry)));
67static void sparclite_serial_start PARAMS ((bfd_vma entry));
68static void sparclite_serial_write PARAMS ((bfd *from_bfd, asection *from_sec,
69 file_ptr from_addr,
70 bfd_vma to_addr, int len));
45993f61 71#ifdef HAVE_SOCKETS
0e887539
SG
72static unsigned short calc_checksum PARAMS ((unsigned char *buffer,
73 int count));
74static void sparclite_udp_start PARAMS ((bfd_vma entry));
75static void sparclite_udp_write PARAMS ((bfd *from_bfd, asection *from_sec,
76 file_ptr from_addr, bfd_vma to_addr,
77 int len));
a76ef70a 78#endif
0e887539 79static void sparclite_download PARAMS ((char *filename, int from_tty));
b955f680
KH
80
81#define DDA2_SUP_ASI 0xb000000
82#define DDA1_SUP_ASI 0xb0000
83
84#define DDA2_ASI_MASK 0xff000000
85#define DDA1_ASI_MASK 0xff0000
86#define DIA2_SUP_MODE 0x8000
87#define DIA1_SUP_MODE 0x4000
88#define DDA2_ENABLE 0x100
89#define DDA1_ENABLE 0x80
90#define DIA2_ENABLE 0x40
91#define DIA1_ENABLE 0x20
92#define DSINGLE_STEP 0x10
93#define DDV_TYPE_MASK 0xc
94#define DDV_TYPE_LOAD 0x0
95#define DDV_TYPE_STORE 0x4
96#define DDV_TYPE_ACCESS 0x8
97#define DDV_TYPE_ALWAYS 0xc
98#define DDV_COND 0x2
99#define DDV_MASK 0x1
100
101int
c746aa85
SG
102sparclite_insert_watchpoint (addr, len, type)
103 CORE_ADDR addr;
104 int len;
105 int type;
b955f680 106{
c746aa85 107 CORE_ADDR dcr;
b955f680
KH
108
109 dcr = read_register (DCR_REGNUM);
110
111 if (!(dcr & DDA1_ENABLE))
b955f680 112 {
c746aa85
SG
113 write_register (DDA1_REGNUM, addr);
114 dcr &= ~(DDA1_ASI_MASK | DDV_TYPE_MASK);
115 dcr |= (DDA1_SUP_ASI | DDA1_ENABLE);
116 if (type == 1)
117 {
118 write_register (DDV1_REGNUM, 0);
119 write_register (DDV2_REGNUM, 0xffffffff);
120 dcr |= (DDV_TYPE_LOAD & (~DDV_COND & ~DDV_MASK));
121 }
122 else if (type == 0)
123 {
124 write_register (DDV1_REGNUM, 0);
125 write_register (DDV2_REGNUM, 0xffffffff);
126 dcr |= (DDV_TYPE_STORE & (~DDV_COND & ~DDV_MASK));
127 }
128 else
129 {
130 write_register (DDV1_REGNUM, 0);
131 write_register (DDV2_REGNUM, 0xffffffff);
132 dcr |= (DDV_TYPE_ACCESS);
133 }
134 write_register (DCR_REGNUM, dcr);
b955f680 135 }
b955f680 136 else if (!(dcr & DDA2_ENABLE))
b955f680 137 {
c746aa85
SG
138 write_register (DDA2_REGNUM, addr);
139 dcr &= ~(DDA2_ASI_MASK & DDV_TYPE_MASK);
140 dcr |= (DDA2_SUP_ASI | DDA2_ENABLE);
141 if (type == 1)
142 {
143 write_register (DDV1_REGNUM, 0);
144 write_register (DDV2_REGNUM, 0xffffffff);
145 dcr |= (DDV_TYPE_LOAD & ~DDV_COND & ~DDV_MASK);
146 }
147 else if (type == 0)
148 {
149 write_register (DDV1_REGNUM, 0);
150 write_register (DDV2_REGNUM, 0xffffffff);
151 dcr |= (DDV_TYPE_STORE & ~DDV_COND & ~DDV_MASK);
152 }
153 else
154 {
155 write_register (DDV1_REGNUM, 0);
156 write_register (DDV2_REGNUM, 0xffffffff);
157 dcr |= (DDV_TYPE_ACCESS);
158 }
159 write_register (DCR_REGNUM, dcr);
b955f680 160 }
b955f680
KH
161 else
162 return -1;
163
164 return 0;
165}
166
167int
c746aa85
SG
168sparclite_remove_watchpoint (addr, len, type)
169 CORE_ADDR addr;
170 int len;
171 int type;
b955f680 172{
c746aa85 173 CORE_ADDR dcr, dda1, dda2;
b955f680
KH
174
175 dcr = read_register (DCR_REGNUM);
176 dda1 = read_register (DDA1_REGNUM);
177 dda2 = read_register (DDA2_REGNUM);
178
c746aa85 179 if ((dcr & DDA1_ENABLE) && addr == dda1)
b955f680 180 write_register (DCR_REGNUM, (dcr & ~DDA1_ENABLE));
c746aa85 181 else if ((dcr & DDA2_ENABLE) && addr == dda2)
b955f680 182 write_register (DCR_REGNUM, (dcr & ~DDA2_ENABLE));
b955f680
KH
183 else
184 return -1;
185
186 return 0;
187}
188
189int
c746aa85
SG
190sparclite_insert_hw_breakpoint (addr, len)
191 CORE_ADDR addr;
192 int len;
b955f680 193{
c746aa85 194 CORE_ADDR dcr;
b955f680
KH
195
196 dcr = read_register (DCR_REGNUM);
197
c746aa85
SG
198 if (!(dcr & DIA1_ENABLE))
199 {
200 write_register (DIA1_REGNUM, addr);
201 write_register (DCR_REGNUM, (dcr | DIA1_ENABLE | DIA1_SUP_MODE));
202 }
203 else if (!(dcr & DIA2_ENABLE))
204 {
205 write_register (DIA2_REGNUM, addr);
206 write_register (DCR_REGNUM, (dcr | DIA2_ENABLE | DIA2_SUP_MODE));
207 }
b955f680
KH
208 else
209 return -1;
210
211 return 0;
212}
213
214int
c746aa85
SG
215sparclite_remove_hw_breakpoint (addr, shadow)
216 CORE_ADDR addr;
217 int shadow;
b955f680 218{
c746aa85 219 CORE_ADDR dcr, dia1, dia2;
b955f680
KH
220
221 dcr = read_register (DCR_REGNUM);
222 dia1 = read_register (DIA1_REGNUM);
223 dia2 = read_register (DIA2_REGNUM);
224
c746aa85 225 if ((dcr & DIA1_ENABLE) && addr == dia1)
b955f680 226 write_register (DCR_REGNUM, (dcr & ~DIA1_ENABLE));
c746aa85 227 else if ((dcr & DIA2_ENABLE) && addr == dia2)
b955f680 228 write_register (DCR_REGNUM, (dcr & ~DIA2_ENABLE));
b955f680
KH
229 else
230 return -1;
c746aa85 231
b955f680
KH
232 return 0;
233}
234
235int
c746aa85
SG
236sparclite_check_watch_resources (type, cnt, ot)
237 int type;
238 int cnt;
239 int ot;
b955f680 240{
c746aa85
SG
241 if (type == bp_hardware_breakpoint)
242 if (TARGET_HW_BREAK_LIMIT == 0)
243 return 0;
244 else if (cnt <= TARGET_HW_BREAK_LIMIT)
245 return 1;
246 else
247 if (TARGET_HW_WATCH_LIMIT == 0)
248 return 0;
249 else if (ot)
250 return -1;
251 else if (cnt <= TARGET_HW_WATCH_LIMIT)
252 return 1;
b955f680
KH
253 return -1;
254}
255
256CORE_ADDR
c746aa85 257sparclite_stopped_data_address ()
b955f680
KH
258{
259 CORE_ADDR dsr, dda1, dda2;
260
261 dsr = read_register (DSR_REGNUM);
262 dda1 = read_register (DDA1_REGNUM);
263 dda2 = read_register (DDA2_REGNUM);
264
c746aa85
SG
265 if (dsr & 0x10)
266 return dda1;
267 else if (dsr & 0x20)
268 return dda2;
269 else
270 return 0;
b955f680 271}
0e887539
SG
272\f
273static serial_t
274open_tty (name)
275 char *name;
276{
277 serial_t desc;
278
279 desc = SERIAL_OPEN (name);
280 if (!desc)
281 perror_with_name (name);
282
283 if (baud_rate != -1)
284 {
285 if (SERIAL_SETBAUDRATE (desc, baud_rate))
286 {
287 SERIAL_CLOSE (desc);
288 perror_with_name (name);
289 }
290 }
291
292 SERIAL_RAW (desc);
293
294 SERIAL_FLUSH_INPUT (desc);
295
296 return desc;
297}
298
299static int
300send_resp (desc, c)
301 serial_t desc;
302 char c;
303{
304 int i;
305
306 SERIAL_WRITE (desc, &c, 1);
307 i = SERIAL_READCHAR (desc, 2);
308
309 if (i >= 0)
310 return i;
311
312 switch (i)
313 {
314 case SERIAL_ERROR:
315 perror_with_name ("Remote communication error");
316 case SERIAL_TIMEOUT:
317 error ("Remote timeout");
318 case SERIAL_EOF:
319 error ("Remote connection closed");
320 }
321}
322
323static void
324close_tty (ignore)
325 int ignore;
326{
327 if (!remote_desc)
328 return;
329
330 SERIAL_CLOSE (remote_desc);
331
332 remote_desc = NULL;
333}
334
45993f61 335#ifdef HAVE_SOCKETS
0e887539
SG
336static int
337recv_udp_buf (fd, buf, len, timeout)
338 int fd, len;
339 unsigned char *buf;
340 int timeout;
341{
342 int cc;
343 fd_set readfds;
344
345 FD_ZERO (&readfds);
346 FD_SET (fd, &readfds);
347
348 if (timeout >= 0)
349 {
350 struct timeval timebuf;
351
352 timebuf.tv_sec = timeout;
353 timebuf.tv_usec = 0;
354 cc = select (fd + 1, &readfds, 0, 0, &timebuf);
355 }
356 else
357 cc = select (fd + 1, &readfds, 0, 0, 0);
358
359 if (cc == 0)
360 return 0;
361
362 if (cc != 1)
363 perror_with_name ("recv_udp_buf: Bad return value from select:");
364
365 cc = recv (fd, buf, len, 0);
366
367 if (cc < 0)
368 perror_with_name ("Got an error from recv: ");
369}
370
371static int
372send_udp_buf (fd, buf, len)
373 int fd, len;
374 unsigned char *buf;
375{
376 int cc;
377
378 cc = send (fd, buf, len, 0);
379
380 if (cc == len)
381 return;
382
383 if (cc < 0)
384 perror_with_name ("Got an error from send: ");
385
386 error ("Short count in send: tried %d, sent %d\n", len, cc);
387}
a76ef70a 388#endif /* __GO32__ */
0e887539
SG
389
390static void
391sparclite_open (name, from_tty)
392 char *name;
393 int from_tty;
394{
395 struct cleanup *old_chain;
396 int c;
397 char *p;
398
399 if (!name)
400 error ("You need to specify what device or hostname is associated with the SparcLite board.");
401
402 target_preopen (from_tty);
403
404 unpush_target (&sparclite_ops);
405
406 if (remote_target_name)
407 free (remote_target_name);
408
409 remote_target_name = strsave (name);
410
411 /* We need a 'serial' or 'udp' keyword to disambiguate host:port, which can
412 mean either a serial port on a terminal server, or the IP address of a
413 SPARClite demo board. If there's no colon, then it pretty much has to be
414 a local device (except for DOS... grrmble) */
415
416 p = strchr (name, ' ');
417
418 if (p)
419 {
420 *p++ = '\000';
421 while ((*p != '\000') && isspace (*p)) p++;
422
423 if (strncmp (name, "serial", strlen (name)) == 0)
424 serial_flag = 1;
425 else if (strncmp (name, "udp", strlen (name)) == 0)
426 serial_flag = 0;
427 else
428 error ("Must specify either `serial' or `udp'.");
429 }
430 else
431 {
432 p = name;
433
434 if (!strchr (name, ':'))
435 serial_flag = 1; /* No colon is unambiguous (local device) */
436 else
437 error ("Usage: target sparclite serial /dev/ttyb\n\
438or: target sparclite udp host");
439 }
440
441 if (serial_flag)
442 {
443 remote_desc = open_tty (p);
444
445 old_chain = make_cleanup (close_tty, 0);
446
447 c = send_resp (remote_desc, 0x00);
448
449 if (c != 0xaa)
450 error ("Unknown response (0x%x) from SparcLite. Try resetting the board.",
451 c);
452
453 c = send_resp (remote_desc, 0x55);
454
455 if (c != 0x55)
456 error ("Sparclite appears to be ill.");
457 }
458 else
459 {
45993f61 460#ifdef HAVE_SOCKETS
0e887539
SG
461 struct hostent *he;
462 struct sockaddr_in sockaddr;
463 unsigned char buffer[100];
464 int cc;
465
466 /* Setup the socket. Must be raw UDP. */
467
468 he = gethostbyname (p);
469
470 if (!he)
471 error ("No such host %s.", p);
472
473 udp_fd = socket (PF_INET, SOCK_DGRAM, 0);
474
475 old_chain = make_cleanup (close, udp_fd);
476
477 sockaddr.sin_family = PF_INET;
478 sockaddr.sin_port = htons(7000);
479 memcpy (&sockaddr.sin_addr.s_addr, he->h_addr, sizeof (struct in_addr));
480
481 if (connect (udp_fd, &sockaddr, sizeof(sockaddr)))
482 perror_with_name ("Connect failed");
483
484 buffer[0] = 0x5;
485 buffer[1] = 0;
486
487 send_udp_buf (udp_fd, buffer, 2); /* Request version */
488 cc = recv_udp_buf (udp_fd, buffer, sizeof(buffer), 5); /* Get response */
489 if (cc == 0)
490 error ("SPARClite isn't responding.");
491
492 if (cc < 3)
493 error ("SPARClite appears to be ill.");
a76ef70a
SG
494#else
495 error ("UDP downloading is not supported for DOS hosts.");
496#endif /* __GO32__ */
0e887539
SG
497 }
498
499 printf_unfiltered ("[SPARClite appears to be alive]\n");
500
501 push_target (&sparclite_ops);
502
503 discard_cleanups (old_chain);
504
505 return;
506}
507
508static void
509sparclite_close (quitting)
510 int quitting;
511{
512 if (serial_flag)
513 close_tty (0);
45993f61 514#ifdef HAVE_SOCKETS
0e887539
SG
515 else
516 if (udp_fd != -1)
517 close (udp_fd);
a76ef70a 518#endif
0e887539
SG
519}
520
521#define LOAD_ADDRESS 0x40000000
522
523static void
524download (target_name, args, from_tty, write_routine, start_routine)
525 char *target_name;
526 char *args;
527 int from_tty;
528 void (*write_routine)();
529 void (*start_routine)();
530{
531 struct cleanup *old_chain;
532 asection *section;
533 bfd *pbfd;
534 bfd_vma entry;
535 int i;
536#define WRITESIZE 1024
537 char *filename;
538 int quiet;
539 int nostart;
540
541 quiet = 0;
542 nostart = 0;
543 filename = NULL;
544
545 while (*args != '\000')
546 {
547 char *arg;
548
549 while (isspace (*args)) args++;
550
551 arg = args;
552
553 while ((*args != '\000') && !isspace (*args)) args++;
554
555 if (*args != '\000')
556 *args++ = '\000';
557
558 if (*arg != '-')
559 filename = arg;
560 else if (strncmp (arg, "-quiet", strlen (arg)) == 0)
561 quiet = 1;
562 else if (strncmp (arg, "-nostart", strlen (arg)) == 0)
563 nostart = 1;
564 else
565 error ("unknown option `%s'", arg);
566 }
567
568 if (!filename)
569 filename = get_exec_file (1);
570
571 pbfd = bfd_openr (filename, gnutarget);
572 if (pbfd == NULL)
573 {
574 perror_with_name (filename);
575 return;
576 }
577 old_chain = make_cleanup (bfd_close, pbfd);
578
579 if (!bfd_check_format (pbfd, bfd_object))
580 error ("\"%s\" is not an object file: %s", filename,
581 bfd_errmsg (bfd_get_error ()));
582
583 for (section = pbfd->sections; section; section = section->next)
584 {
585 if (bfd_get_section_flags (pbfd, section) & SEC_LOAD)
586 {
587 bfd_vma section_address;
588 bfd_size_type section_size;
589 file_ptr fptr;
590
591 section_address = bfd_get_section_vma (pbfd, section);
592 /* Adjust sections from a.out files, since they don't
593 carry their addresses with. */
594 if (bfd_get_flavour (pbfd) == bfd_target_aout_flavour)
595 section_address += LOAD_ADDRESS;
596
597 section_size = bfd_get_section_size_before_reloc (section);
598
599 if (!quiet)
600 printf_filtered ("[Loading section %s at 0x%x (%d bytes)]\n",
601 bfd_get_section_name (pbfd, section),
602 section_address,
603 section_size);
604
605 fptr = 0;
606 while (section_size > 0)
607 {
608 int count;
609 static char inds[] = "|/-\\";
610 static int k = 0;
611
612 QUIT;
613
614 count = min (section_size, WRITESIZE);
615
616 write_routine (pbfd, section, fptr, section_address, count);
617
618 if (!quiet)
619 {
620 printf_unfiltered ("\r%c", inds[k++ % 4]);
621 gdb_flush (gdb_stdout);
622 }
623
624 section_address += count;
625 fptr += count;
626 section_size -= count;
627 }
628 }
629 }
630
631 if (!nostart)
632 {
633 entry = bfd_get_start_address (pbfd);
634
635 if (!quiet)
636 printf_unfiltered ("[Starting %s at 0x%x]\n", filename, entry);
637
638 start_routine (entry);
639 }
640
641 do_cleanups (old_chain);
642}
643
644static void
645sparclite_serial_start (entry)
646 bfd_vma entry;
647{
648 char buffer[5];
649 int i;
650
651 buffer[0] = 0x03;
652 store_unsigned_integer (buffer + 1, 4, entry);
653
654 SERIAL_WRITE (remote_desc, buffer, 1 + 4);
655 i = SERIAL_READCHAR (remote_desc, 2);
656 if (i != 0x55)
657 error ("Can't start SparcLite. Error code %d\n", i);
658}
659
660static void
661sparclite_serial_write (from_bfd, from_sec, from_addr, to_addr, len)
662 bfd *from_bfd;
663 asection *from_sec;
664 file_ptr from_addr;
665 bfd_vma to_addr;
666 int len;
667{
668 char buffer[4 + 4 + WRITESIZE]; /* addr + len + data */
669 unsigned char checksum;
670 int i;
671
672 store_unsigned_integer (buffer, 4, to_addr); /* Address */
673 store_unsigned_integer (buffer + 4, 4, len); /* Length */
674
675 bfd_get_section_contents (from_bfd, from_sec, buffer + 8, from_addr, len);
676
677 checksum = 0;
678 for (i = 0; i < len; i++)
679 checksum += buffer[8 + i];
680
681 i = send_resp (remote_desc, 0x01);
682
683 if (i != 0x5a)
684 error ("Bad response from load command (0x%x)", i);
685
686 SERIAL_WRITE (remote_desc, buffer, 4 + 4 + len);
687 i = SERIAL_READCHAR (remote_desc, 2);
688 if (i < 0)
689 error ("I/O error in serial code. Return code %d\n", i);
690
691 if (i != checksum)
692 error ("Bad checksum from load command (0x%x)", i);
693}
694
45993f61 695#ifdef HAVE_SOCKETS
a76ef70a 696
0e887539
SG
697static unsigned short
698calc_checksum (buffer, count)
699 unsigned char *buffer;
700 int count;
701{
702 unsigned short checksum;
703
704 checksum = 0;
705 for (; count > 0; count -= 2, buffer += 2)
706 checksum += (*buffer << 8) | *(buffer + 1);
707
708 if (count != 0)
709 checksum += *buffer << 8;
710
711 return checksum;
712}
713
714static void
715sparclite_udp_start (entry)
716 bfd_vma entry;
717{
718 unsigned char buffer[6];
719 int i;
720
721 buffer[0] = 0x3;
722 buffer[1] = 0;
723 buffer[2] = entry >> 24;
724 buffer[3] = entry >> 16;
725 buffer[4] = entry >> 8;
726 buffer[5] = entry;
727
728 send_udp_buf (udp_fd, buffer, 6); /* Send start addr */
729 i = recv_udp_buf (udp_fd, buffer, sizeof(buffer), -1); /* Get response */
730
731 if (i < 1 || buffer[0] != 0x55)
732 error ("Failed to take start address.");
733}
734
735static void
736sparclite_udp_write (from_bfd, from_sec, from_addr, to_addr, len)
737 bfd *from_bfd;
738 asection *from_sec;
739 file_ptr from_addr;
740 bfd_vma to_addr;
741 int len;
742{
743 unsigned char buffer[2000];
744 unsigned short checksum;
745 static int pkt_num = 0;
746 static unsigned long old_addr = -1;
747 int i;
748
749 while (1)
750 {
751 if (to_addr != old_addr)
752 {
753 buffer[0] = 0x1; /* Load command */
754 buffer[1] = 0x1; /* Loading address */
755 buffer[2] = to_addr >> 24;
756 buffer[3] = to_addr >> 16;
757 buffer[4] = to_addr >> 8;
758 buffer[5] = to_addr;
759
760 checksum = 0;
761 for (i = 0; i < 6; i++)
762 checksum += buffer[i];
763 checksum &= 0xff;
764
765 send_udp_buf (udp_fd, buffer, 6);
766 i = recv_udp_buf (udp_fd, buffer, sizeof buffer, -1);
767
768 if (i < 1)
769 error ("Got back short checksum for load addr.");
770
771 if (checksum != buffer[0])
772 error ("Got back bad checksum for load addr.");
773
774 pkt_num = 0; /* Load addr resets packet seq # */
775 old_addr = to_addr;
776 }
777
778 bfd_get_section_contents (from_bfd, from_sec, buffer + 6, from_addr,
779 len);
780
781 checksum = calc_checksum (buffer + 6, len);
782
783 buffer[0] = 0x1; /* Load command */
784 buffer[1] = 0x2; /* Loading data */
785 buffer[2] = pkt_num >> 8;
786 buffer[3] = pkt_num;
787 buffer[4] = checksum >> 8;
788 buffer[5] = checksum;
789
790 send_udp_buf (udp_fd, buffer, len + 6);
791 i = recv_udp_buf (udp_fd, buffer, sizeof buffer, 3);
792
793 if (i == 0)
794 {
795 fprintf_unfiltered (gdb_stderr, "send_data: timeout sending %d bytes to address 0x%x retrying\n", len, to_addr);
796 continue;
797 }
798
799 if (buffer[0] != 0xff)
800 error ("Got back bad response for load data.");
801
802 old_addr += len;
803 pkt_num++;
804
805 return;
806 }
807}
808
a76ef70a
SG
809#endif /* __GO32__ */
810
0e887539
SG
811static void
812sparclite_download (filename, from_tty)
813 char *filename;
814 int from_tty;
815{
816 if (!serial_flag)
45993f61 817#ifdef HAVE_SOCKETS
0e887539
SG
818 download (remote_target_name, filename, from_tty, sparclite_udp_write,
819 sparclite_udp_start);
a76ef70a
SG
820#else
821 abort (); /* sparclite_open should prevent this! */
822#endif
0e887539
SG
823 else
824 download (remote_target_name, filename, from_tty, sparclite_serial_write,
825 sparclite_serial_start);
826}
827\f
828/* Define the target subroutine names */
829
830static struct target_ops sparclite_ops =
831{
832 "sparclite", /* to_shortname */
833 "SPARClite remote target", /* to_longname */
834 "Use a remote SPARClite target board via a serial line, using a gdb-specific protocol.\n\
835Specify the serial device it is connected to (e.g. /dev/ttya).", /* to_doc */
836 sparclite_open, /* to_open */
837 sparclite_close, /* to_close */
838 0, /* to_attach */
839 0, /* to_detach */
840 0, /* to_resume */
841 0, /* to_wait */
842 0, /* to_fetch_registers */
843 0, /* to_store_registers */
844 0, /* to_prepare_to_store */
845 0, /* to_xfer_memory */
846 0, /* to_files_info */
847 0, /* to_insert_breakpoint */
848 0, /* to_remove_breakpoint */
849 0, /* to_terminal_init */
850 0, /* to_terminal_inferior */
851 0, /* to_terminal_ours_for_output */
852 0, /* to_terminal_ours */
853 0, /* to_terminal_info */
854 0, /* to_kill */
855 sparclite_download, /* to_load */
856 0, /* to_lookup_symbol */
857 0, /* to_create_inferior */
858 0, /* to_mourn_inferior */
859 0, /* to_can_run */
860 0, /* to_notice_signals */
861 0, /* to_stop */
a76ef70a 862 download_stratum, /* to_stratum */
0e887539
SG
863 0, /* to_next */
864 0, /* to_has_all_memory */
865 0, /* to_has_memory */
866 0, /* to_has_stack */
867 0, /* to_has_registers */
868 0, /* to_has_execution */
869 0, /* sections */
870 0, /* sections_end */
871 OPS_MAGIC /* to_magic */
872 };
873
874void
875_initialize_sparcl_tdep ()
876{
877 add_target (&sparclite_ops);
878}
This page took 0.176281 seconds and 4 git commands to generate.