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