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