home *** CD-ROM | disk | FTP | other *** search
/ Fresh Fish 9 / FreshFishVol9-CD2.bin / bbs / gnu / gdb-4.14-src.lha / gdb-4.14 / sim / w65 / run.c < prev    next >
Encoding:
C/C++ Source or Header  |  1995-01-16  |  2.1 KB  |  110 lines

  1. /* run front end support for W65
  2.    Copyright (C) 1995 Free Software Foundation, Inc.
  3.  
  4. This file is part of W65 SIM
  5.  
  6. GNU CC 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, or (at your option)
  9. any later version.
  10.  
  11. GNU CC 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 GNU CC; see the file COPYING.  If not, write to
  18. the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.  */
  19.  
  20.  
  21. /* Steve Chamberlain
  22.    sac@cygnus.com */
  23.  
  24. #include <stdio.h>
  25. #include "bfd.h"
  26. #include "sysdep.h"
  27.  
  28. extern printf();
  29.  
  30. int
  31. main (ac, av)
  32.      int ac;
  33.      char **av;
  34. {
  35.   bfd *abfd;
  36.   bfd_vma start_address;
  37.   asection *s;
  38.   int i;
  39.   int verbose = 0;
  40.   int trace = 0;
  41.   char *name = "";
  42.   
  43.   for (i = 1; i < ac; i++)
  44.     {
  45.       if (strcmp (av[i], "-v") == 0)
  46.     {
  47.       verbose = 1;
  48.     }
  49.       else if (strcmp (av[i], "-t") == 0)
  50.     {
  51.       trace = 1;
  52.     }
  53.       else
  54.     {
  55.       name = av[i];
  56.     }
  57.     }
  58.   if (verbose)
  59.     {
  60.       printf ("run %s\n", name);
  61.     }
  62.   abfd = bfd_openr (name, "coff-w65");
  63.   if (abfd)
  64.     {
  65.  
  66.       if (bfd_check_format (abfd, bfd_object))
  67.     {
  68.  
  69.       for (s = abfd->sections; s; s = s->next)
  70.         {
  71.           unsigned char *buffer = malloc (bfd_section_size (abfd, s));
  72.           bfd_get_section_contents (abfd,
  73.                     s,
  74.                     buffer,
  75.                     0,
  76.                     bfd_section_size (abfd, s));
  77.           sim_write (s->vma, buffer, bfd_section_size (abfd, s));
  78.           free (buffer);
  79.         }
  80.  
  81.       start_address = bfd_get_start_address (abfd);
  82.       sim_set_pc (start_address);
  83.       if (trace)
  84.         {
  85.           int done = 0;
  86.           while (!done)
  87.         {
  88.           done = sim_trace ();
  89.         }
  90.         }
  91.       else
  92.         {
  93.           sim_resume (0, 0);
  94.         }
  95.       if (verbose)
  96.         sim_info (printf, 0);
  97.  
  98.       /* Find out what was in r0 and return that */
  99.       {
  100.         unsigned char b[4];
  101.         sim_fetch_register(0, b);
  102.         return b[3];
  103.       }
  104.       
  105.     }
  106.     }
  107.  
  108.   return 1;
  109. }
  110.