home *** CD-ROM | disk | FTP | other *** search
/ InfoMagic Source Code 1993 July / THE_SOURCE_CODE_CD_ROM.iso / gnu / gdb-4.9 / sim / h8500 / run.c < prev    next >
Encoding:
C/C++ Source or Header  |  1993-05-12  |  2.1 KB  |  106 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 "bfd.h"
  25. #include "sysdep.h"
  26.  
  27. int
  28. main (ac, av)
  29.      int ac;
  30.      char **av;
  31. {
  32.   bfd *abfd;
  33.   bfd_vma start_address;
  34.   asection *s;
  35.   int i;
  36.   int verbose = 0;
  37.   int trace = 0;
  38.   char *name = "";
  39.   for (i = 1; i < ac; i++)
  40.     {
  41.       if (strcmp (av[i], "-v") == 0)
  42.     {
  43.       verbose = 1;
  44.     }
  45.       else if (strcmp (av[i], "-t") == 0)
  46.     {
  47.       trace = 1;
  48.     }
  49.       else if (strcmp (av[i], "-c") == 0)
  50.     {
  51.       int csize;
  52.       csize = atoi (av[i + 1]);
  53.       sim_csize (csize);
  54.       i++;
  55.     }
  56.       else
  57.     {
  58.       name = av[i];
  59.     }
  60.     }
  61.   if (verbose)
  62.     {
  63.       printf ("run %s\n", name);
  64.     }
  65.   abfd = bfd_openr (name, "coff-h8500");
  66.   if (abfd)
  67.     {
  68.  
  69.       if (bfd_check_format (abfd, bfd_object))
  70.     {
  71.  
  72.       for (s = abfd->sections; s; s = s->next)
  73.         {
  74.           unsigned char *buffer = malloc (bfd_section_size (abfd, s));
  75.           bfd_get_section_contents (abfd,
  76.                     s,
  77.                     buffer,
  78.                     0,
  79.                     bfd_section_size (abfd, s));
  80.           sim_write (s->vma, buffer, bfd_section_size (abfd, s));
  81.         }
  82.  
  83.       start_address = bfd_get_start_address (abfd);
  84.       sim_set_pc (start_address);
  85.       if (trace)
  86.         {
  87.           int done = 0;
  88.           while (!done)
  89.         {
  90.           done = sim_trace ();
  91.         }
  92.         }
  93.       else
  94.         {
  95.           sim_resume (0, 0);
  96.         }
  97.       if (verbose)
  98.         sim_info ();
  99.  
  100.       return 0;
  101.     }
  102.     }
  103.  
  104.   return 1;
  105. }
  106.