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 / z8k / run.c < prev    next >
C/C++ Source or Header  |  1995-09-08  |  2KB  |  116 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 Z8KZIM; if not, write to the Free Software
  18. Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.  */
  19.  
  20. #include <stdio.h>
  21. #include "bfd.h"
  22. #include "tm.h"
  23.  
  24. void usage();
  25. extern int optind;
  26.  
  27. main(ac,av)
  28. int ac;
  29. char **av;
  30. {
  31.   bfd *abfd;
  32.   bfd_vma start_address;
  33.   asection *s;
  34.   int i;
  35.   int verbose = 0;
  36.   int trace = 0;
  37.   char *name = "";
  38.  
  39.   while ((i = getopt (ac, av, "tv")) != EOF) 
  40.     switch (i)
  41.       {
  42.       case 't':
  43.     trace = 1;
  44.     break;
  45.       case 'v':
  46.     verbose = 1;
  47.     break;
  48.       default:
  49.     usage();
  50.       }
  51.   ac -= optind;
  52.   av += optind;
  53.  
  54.   if (ac != 1)
  55.     usage();
  56.  
  57.   name = *av;
  58.  
  59.   if (verbose)
  60.   {
  61.     printf("run %s\n", name);
  62.   }
  63.   abfd = bfd_openr(name,"coff-z8k");
  64.  
  65.   if (abfd) {
  66.       
  67.     if (bfd_check_format(abfd, bfd_object)) 
  68.     {
  69.       if (abfd->arch_info->mach == bfd_mach_z8001)
  70.       {
  71.     extern int sim_z8001_mode;
  72.     sim_z8001_mode = 1;
  73.       }
  74.       for (s = abfd->sections; s; s=s->next) 
  75.       {
  76.     char *buffer = malloc(bfd_section_size(abfd,s));
  77.     bfd_get_section_contents(abfd, s, buffer, 0, bfd_section_size(abfd,s));
  78.     sim_write(s->vma, buffer, bfd_section_size(abfd,s));
  79.       }
  80.  
  81.       start_address = bfd_get_start_address(abfd);
  82.       sim_create_inferior (start_address, NULL, NULL);
  83.       if (trace) 
  84.       {
  85.     int done = 0;
  86.     while (!done) 
  87.     {
  88.       done = sim_trace();
  89.     }
  90.       }
  91.       else 
  92.       { 
  93.     sim_resume(0,0);
  94.       }
  95.       if (verbose) 
  96.       {
  97.     sim_info(0);
  98.       }
  99.       {
  100.     char b[4];
  101.      sim_fetch_register (2,b);
  102.     return b[1];
  103.       }
  104.     }
  105.   }
  106.  
  107.   return 1;
  108. }
  109.  
  110. void
  111. usage()
  112. {
  113.   fprintf (stderr, "usage: run [-tv] program\n");
  114.   exit (1);
  115. }
  116.