* configure.in: Call AC_CONFIG_HEADER. Don't try to use
[deliverable/binutils-gdb.git] / sim / h8300 / run.c
index 59797ca79d4029f5ec496e054d69384af0d540d2..97841269a7035708934f3fb78c1fb63383f34759 100644 (file)
 
 */
 
+#include "config.h"
+
+#include <varargs.h>
+#include <stdio.h>
+#ifdef HAVE_STDLIB_H
+#include <stdlib.h>
+#endif
+#include "getopt.h"
 #include "bfd.h"
-#include "sysdep.h"
+#include "remote-sim.h"
+
+void usage();
+extern int optind;
+extern char *optarg;
 
 int
-main(ac,av)
-int ac;
-char **av;
+main (ac, av)
+     int ac;
+     char **av;
 {
   bfd *abfd;
   bfd_vma start_address;
@@ -33,46 +45,79 @@ char **av;
   int verbose = 0;
   int trace = 0;
   char *name = "";
-  for (i = 1; i < ac; i++)
-  {
-    if (strcmp(av[i],"-v") == 0) 
-    {
-      verbose = 1;
-    }
-    else if (strcmp(av[i],"-t") == 0) 
-    {
-      trace = 1;
-    }
 
-    else 
-    {
-      name = av[i];
-    }
-  }
+  while ((i = getopt (ac, av, "c:htv")) != EOF)
+    switch (i) 
+      {
+      case 'c':
+       sim_csize (atoi (optarg));
+       break;
+      case 'h':
+       set_h8300h (1);
+       break;
+      case 't':
+       trace = 1;
+       break;
+      case 'v':
+       verbose = 1;
+       break;
+      default:
+       usage();
+      }
+  ac -= optind;
+  av += optind;
+
+  if (ac != 1)
+    usage();
+
+  name = *av;
+
   if (verbose)
-  {
-    printf("run %s\n", name);
-  }
-  abfd = bfd_openr(name,"coff-h8300");
-  if (abfd) {
-      
-    if (bfd_check_format(abfd, bfd_object)) 
+    printf ("run %s\n", name);
+
+  abfd = bfd_openr (name, "coff-h8300");
+  if (abfd) 
     {
+      if (bfd_check_format(abfd, bfd_object)) 
+       {
+         if (abfd->arch_info->mach == bfd_mach_h8300h)
+           set_h8300h (1);
 
-      for (s = abfd->sections; s; s=s->next) 
-      {
-       char *buffer = malloc(bfd_section_size(abfd,s));
-       bfd_get_section_contents(abfd, s, buffer, 0, bfd_section_size(abfd,s));
-       sim_write(s->vma, buffer, bfd_section_size(abfd,s));
-      }
+         for (s = abfd->sections; s; s=s->next) 
+           {
+             char *buffer = malloc(bfd_section_size(abfd,s));
+             bfd_get_section_contents(abfd, s, buffer, 0, bfd_section_size(abfd,s));
+             sim_write(s->vma, buffer, bfd_section_size(abfd,s));
+           }
 
-      start_address = bfd_get_start_address(abfd);
-      sim_store_register(
-                        9,start_address);
-      sim_resume(0,0);
-      return 0;
+         start_address = bfd_get_start_address(abfd);
+         sim_create_inferior (start_address, NULL, NULL);
+         sim_resume(0,0);
+         if (verbose)
+           sim_info (verbose - 1);
+         return 0;
+       }
     }
-  }
 
   return 1;
 }
+
+void
+printf_filtered (va_alist)
+     va_dcl
+{
+  char *msg;
+  va_list args;
+
+  va_start (args);
+  msg = va_arg (args, char *);
+  vfprintf (stdout, msg, args);
+  va_end (args);
+}
+
+void
+usage()
+{
+  fprintf (stderr, "usage: run [-tv] program\n");
+  exit (1);
+}
This page took 0.024433 seconds and 4 git commands to generate.