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

  1. /* run front end support for Z8KSIM
  2.    Copyright (C) 1987, 1992 Free Software Foundation, Inc.
  3.  
  4. This file is part of Z8KSIM
  5.  
  6. Z8KSIM 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. Z8KSIM 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 Z8KSIM; see the file COPYING.  If not, write to
  18. the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.  */
  19.  
  20. #include <stdio.h>
  21. #include "bfd.h"
  22. #include "tm.h"
  23. #include "sysdep.h"
  24.  
  25. main(ac,av)
  26. int ac;
  27. char **av;
  28. {
  29.   bfd *abfd;
  30.   bfd_vma start_address;
  31.   asection *s;
  32.   int i;
  33.   int verbose = 0;
  34.   int trace = 0;
  35.   char *name = "";
  36.   for (i = 1; i < ac; i++)
  37.   {
  38.     if (strcmp(av[i],"-v") == 0) 
  39.     {
  40.       verbose = 1;
  41.     }
  42.     else if (strcmp(av[i],"-t") == 0) 
  43.     {
  44.       trace = 1;
  45.     }
  46.  
  47.     else 
  48.     {
  49.       name = av[i];
  50.     }
  51.   }
  52.   if (verbose)
  53.   {
  54.     printf("run %s\n", name);
  55.   }
  56.   abfd = bfd_openr(name,"coff-z8k");
  57.  
  58.   if (abfd) {
  59.       
  60.     if (bfd_check_format(abfd, bfd_object)) 
  61.     {
  62.       if (abfd->arch_info->mach == bfd_mach_z8001)
  63.       {
  64.     extern int sim_z8001_mode;
  65.     sim_z8001_mode = 1;
  66.       }
  67.       for (s = abfd->sections; s; s=s->next) 
  68.       {
  69.     char *buffer = malloc(bfd_section_size(abfd,s));
  70.     bfd_get_section_contents(abfd, s, buffer, 0, bfd_section_size(abfd,s));
  71.     sim_write(s->vma, buffer, bfd_section_size(abfd,s));
  72.       }
  73.  
  74.       start_address = bfd_get_start_address(abfd);
  75.       sim_create_inferior (start_address, NULL, NULL);
  76.       if (trace) 
  77.       {
  78.     int done = 0;
  79.     while (!done) 
  80.     {
  81.       done = sim_trace();
  82.     }
  83.       }
  84.       else 
  85.       { 
  86.     sim_resume(0,0);
  87.       }
  88.       if (verbose) 
  89.       {
  90.     sim_info(0);
  91.       }
  92.       return 0;
  93.     }
  94.   }
  95.  
  96.   return 1;
  97. }
  98.