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

  1. /* front end to the simulator.
  2.  
  3.    Written by Steve Chamberlain of Cygnus Support.
  4.    sac@cygnus.com
  5.  
  6.    This file is part of H8/300 sim
  7.  
  8.  
  9.         THIS SOFTWARE IS NOT COPYRIGHTED
  10.  
  11.    Cygnus offers the following for use in the public domain.  Cygnus
  12.    makes no warranty with regard to the software or it's performance
  13.    and the user accepts the software "AS IS" with all faults.
  14.  
  15.    CYGNUS DISCLAIMS ANY WARRANTIES, EXPRESS OR IMPLIED, WITH REGARD TO
  16.    THIS SOFTWARE INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  17.    MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
  18.  
  19. */
  20.  
  21. #include <varargs.h>
  22. #include <stdio.h>
  23. #include "bfd.h"
  24. #include "sysdep.h"
  25. #include "remote-sim.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.  
  40.   for (i = 1; i < ac; i++)
  41.     {
  42.       if (strcmp(av[i],"-v") == 0)
  43.     verbose++;
  44.       
  45.       else if (strcmp(av[i],"-t") == 0) 
  46.     {
  47.       trace = 1;
  48.     }
  49.       else if (strcmp(av[i],"-c") == 0) 
  50.     {
  51.       sim_csize(atoi(av[i+1]));
  52.       i++;
  53.     }
  54.       else if (strcmp(av[i],"-h") == 0) 
  55.     set_h8300h (1);
  56.       else 
  57.     name = av[i];
  58.     }
  59.  
  60.   if (verbose)
  61.     printf ("run %s\n", name);
  62.  
  63.   abfd = bfd_openr (name, "coff-h8300");
  64.   if (abfd) 
  65.     {
  66.       if (bfd_check_format(abfd, bfd_object)) 
  67.     {
  68.       if (abfd->arch_info->mach == bfd_mach_h8300h)
  69.         set_h8300h (1);
  70.  
  71.       for (s = abfd->sections; s; s=s->next) 
  72.         {
  73.           char *buffer = malloc(bfd_section_size(abfd,s));
  74.           bfd_get_section_contents(abfd, s, buffer, 0, bfd_section_size(abfd,s));
  75.           sim_write(s->vma, buffer, bfd_section_size(abfd,s));
  76.         }
  77.  
  78.       start_address = bfd_get_start_address(abfd);
  79.       sim_create_inferior (start_address, NULL, NULL);
  80.       sim_resume(0,0);
  81.       if (verbose)
  82.         sim_info (verbose - 1);
  83.       return 0;
  84.     }
  85.     }
  86.  
  87.   return 1;
  88. }
  89.  
  90. void
  91. printf_filtered (va_alist)
  92.      va_dcl
  93. {
  94.   char *msg;
  95.   va_list args;
  96.  
  97.   va_start (args);
  98.   msg = va_arg (args, char *);
  99.   vfprintf (stdout, msg, args);
  100.   va_end (args);
  101. }
  102.