home *** CD-ROM | disk | FTP | other *** search
/ Geek Gadgets 1 / ADE-1.bin / ade-dist / gdb-4.16-base.tgz / gdb-4.16-base.tar / fsf / gdb / sim / h8500 / run.c < prev   
Encoding:
C/C++ Source or Header  |  1995-09-08  |  2.7 KB  |  149 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 H8/500 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 this program; if not, write to the Free Software
  18. Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.  */
  19.  
  20.  
  21. /* Steve Chamberlain
  22.    sac@cygnus.com */
  23.  
  24. #include "config.h"
  25.  
  26. #include <varargs.h>
  27. #include <stdio.h>
  28. #include <signal.h>
  29. #ifdef HAVE_STDLIB_H
  30. #include <stdlib.h>
  31. #endif
  32. #include "getopt.h"
  33. #include "bfd.h"
  34. #include "remote-sim.h"
  35.  
  36. void usage();
  37. extern int optind;
  38. extern char *optarg;
  39.  
  40. int
  41. main (ac, av)
  42.      int ac;
  43.      char **av;
  44. {
  45.   bfd *abfd;
  46.   bfd_vma start_address;
  47.   asection *s;
  48.   int i;
  49.   int verbose = 0;
  50.   int trace = 0;
  51.   char *name = "";
  52.  
  53.   while ((i = getopt (ac, av, "c:tv")) != EOF)
  54.     switch (i) 
  55.       {
  56.       case 'c':
  57.     sim_csize (atoi (optarg));
  58.     break;
  59.       case 't':
  60.     trace = 1;
  61.     break;
  62.       case 'v':
  63.     verbose = 1;
  64.     break;
  65.       default:
  66.     usage();
  67.       }
  68.   ac -= optind;
  69.   av += optind;
  70.  
  71.   if (ac != 1)
  72.     usage();
  73.  
  74.   name = *av;
  75.  
  76.   if (verbose)
  77.     {
  78.       printf ("run %s\n", name);
  79.     }
  80.   abfd = bfd_openr (name, "coff-h8500");
  81.   if (abfd)
  82.     {
  83.  
  84.       if (bfd_check_format (abfd, bfd_object))
  85.     {
  86.  
  87.       for (s = abfd->sections; s; s = s->next)
  88.         {
  89.           unsigned char *buffer = malloc (bfd_section_size (abfd, s));
  90.           bfd_get_section_contents (abfd,
  91.                     s,
  92.                     buffer,
  93.                     0,
  94.                     bfd_section_size (abfd, s));
  95.           sim_write (s->vma, buffer, bfd_section_size (abfd, s));
  96.         }
  97.  
  98.       start_address = bfd_get_start_address (abfd);
  99.       sim_create_inferior (start_address, NULL, NULL);
  100.       if (trace)
  101.         {
  102.           int done = 0;
  103.           while (!done)
  104.         {
  105.           done = sim_trace ();
  106.         }
  107.         }
  108.       else
  109.         {
  110.           sim_resume (0, 0);
  111.         }
  112.       if (verbose)
  113.         sim_info (0);
  114.  
  115.       {
  116.         enum sim_stop reason;
  117.         int sigrc;
  118.  
  119.         sim_stop_reason (&reason, &sigrc);
  120.         if (sigrc == SIGQUIT)
  121.           return 0;
  122.         return sigrc;
  123.       }
  124.     }
  125.     }
  126.  
  127.   return 1;
  128. }
  129.  
  130. void
  131. printf_filtered (va_alist)
  132.      va_dcl
  133. {
  134.   char *msg;
  135.   va_list args;
  136.  
  137.   va_start (args);
  138.   msg = va_arg (args, char *);
  139.   vfprintf (stdout, msg, args);
  140.   va_end (args);
  141. }
  142.  
  143. void
  144. usage()
  145. {
  146.   fprintf (stderr, "usage: run [-tv] program\n");
  147.   exit (1);
  148. }
  149.