home *** CD-ROM | disk | FTP | other *** search
/ Fresh Fish 9 / FreshFishVol9-CD2.bin / bbs / gnu / gdb-4.14-src.lha / gdb-4.14 / sim / h8500 / run.c < prev   
Encoding:
C/C++ Source or Header  |  1994-05-19  |  2.3 KB  |  123 lines

  1. /* run front end support for H8/500
  2.    Copyright (C) 1987, 1992 Free Software Foundation, Inc.
  3.  
  4. This file is part of H8300 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 <varargs.h>
  25. #include <stdio.h>
  26. #include "../../bfd/bfd.h"
  27. #include "sysdep.h"
  28. #include "remote-sim.h"
  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 if (strcmp (av[i], "-c") == 0)
  54.     {
  55.       int csize;
  56.       csize = atoi (av[i + 1]);
  57.       sim_csize (csize);
  58.       i++;
  59.     }
  60.       else
  61.     {
  62.       name = av[i];
  63.     }
  64.     }
  65.   if (verbose)
  66.     {
  67.       printf ("run %s\n", name);
  68.     }
  69.   abfd = bfd_openr (name, "coff-h8500");
  70.   if (abfd)
  71.     {
  72.  
  73.       if (bfd_check_format (abfd, bfd_object))
  74.     {
  75.  
  76.       for (s = abfd->sections; s; s = s->next)
  77.         {
  78.           unsigned char *buffer = malloc (bfd_section_size (abfd, s));
  79.           bfd_get_section_contents (abfd,
  80.                     s,
  81.                     buffer,
  82.                     0,
  83.                     bfd_section_size (abfd, s));
  84.           sim_write (s->vma, buffer, bfd_section_size (abfd, s));
  85.         }
  86.  
  87.       start_address = bfd_get_start_address (abfd);
  88.       sim_create_inferior (start_address, NULL, NULL);
  89.       if (trace)
  90.         {
  91.           int done = 0;
  92.           while (!done)
  93.         {
  94.           done = sim_trace ();
  95.         }
  96.         }
  97.       else
  98.         {
  99.           sim_resume (0, 0);
  100.         }
  101.       if (verbose)
  102.         sim_info (0);
  103.  
  104.       return 0;
  105.     }
  106.     }
  107.  
  108.   return 1;
  109. }
  110.  
  111. void
  112. printf_filtered (va_alist)
  113.      va_dcl
  114. {
  115.   char *msg;
  116.   va_list args;
  117.  
  118.   va_start (args);
  119.   msg = va_arg (args, char *);
  120.   vfprintf (stdout, msg, args);
  121.   va_end (args);
  122. }
  123.