7/30 release from Andrew
[deliverable/binutils-gdb.git] / sim / ppc / sim_calls.c
index e262e05a153b721e52dce64adf8d55f6e62accbd..6fdca6a3aa6887afb7d99a4a56964c40a8c6c39e 100644 (file)
@@ -1,6 +1,6 @@
 /*  This file is part of the program psim.
 
-    Copyright (C) 1994-1995, Andrew Cagney <cagney@highland.com.au>
+    Copyright (C) 1994-1996, Andrew Cagney <cagney@highland.com.au>
 
     This program is free software; you can redistribute it and/or modify
     it under the terms of the GNU General Public License as published by
 
 #include <signal.h> /* FIXME - should be machine dependant version */
 #include <stdarg.h>
-#include <stdlib.h>
-#include <string.h>
 #include <ctype.h>
 
-#include "basics.h"
 #include "psim.h"
+#include "options.h"
 
-#include "../../gdb/defs.h"
+#ifdef HAVE_STDLIB_H
+#include <stdlib.h>
+#endif
 
-#include "devices.h"
+#ifdef HAVE_STRING_H
+#include <string.h>
+#else
+#ifdef HAVE_STRINGS_H
+#include <strings.h>
+#endif
+#endif
+
+#include "../../gdb/defs.h"
 
 #include "../../gdb/remote-sim.h"
 #include "../../gdb/callback.h"
 /* Structures used by the simulator, for gdb just have static structures */
 
 static psim *simulator;
-static char *register_names[] = REGISTER_NAMES;
-static int print_info = 0;
+static device *root_device;
+static const char *register_names[] = REGISTER_NAMES;
 
 void
 sim_open (char *args)
 {
-  int i;
-
+  /* Note: The simulation is not created by sim_open() because
+     complete information is not yet available */
   /* trace the call */
   TRACE(trace_gdb, ("sim_open(args=%s) called\n", args ? args : "(null)"));
 
+  if (root_device != NULL)
+    printf_filtered("Warning - re-open of simulator leaks memory\n");
+  root_device = psim_tree();
+  simulator = NULL;
+
   if (args) {
     char **argv = buildargv(args);
-    int argp = 0;
-    int argc;
-    for (argc = 0; argv[argc]; argc++);
-
-    while (argp < argc) {
-      if (*argv[argp] != '-')
-       error ("Argument is not an option '%s'", argv[argp]);
-
-      else {
-       /* check arguments -- note, main.c also contains argument processing
-          code for the standalone emulator.  */
-       char *p = argv[argp] + 1;
-       while (*p != '\0') {
-         switch (*p) {
-         default:
-           printf_filtered("Usage:\n\ttarget sim [ -t <trace-option> ]\n");
-           trace_usage();
-           error ("");
-           break;
-         case 't':
-           argp += 1;
-           if (argv[argp] == NULL)
-             error("Missing <trace> option for -t\n");
-           trace_option(argv[argp]); /* better fail if NULL */
-           break;
-         case 'I':
-           print_info = 1;
-           break;
-         }
-       }
-      }
-      argp += 1;
-    }
+    psim_options(root_device, argv);
+    freeargv(argv);
   }
 
-  /* do something */
-  TRACE(trace_tbd, ("sim_open() - TBD - should parse the arguments\n"));
-  TRACE(trace_tbd, ("sim_open() - TBD - can not create simulator here as do not have description of it\n"));
+  if (ppc_trace[trace_opts])
+    print_options ();
 }
 
 
@@ -97,10 +78,8 @@ void
 sim_close (int quitting)
 {
   TRACE(trace_gdb, ("sim_close(quitting=%d) called\n", quitting));
-  if (print_info)
-    psim_print_info (simulator, 1);
-
-  /* nothing to do */
+  if (ppc_trace[trace_print_info] && simulator != NULL)
+    psim_print_info (simulator, ppc_trace[trace_print_info]);
 }
 
 
@@ -118,7 +97,7 @@ sim_load (char *prog, int from_tty)
 
   /* create the simulator */
   TRACE(trace_gdb, ("sim_load() - first time, create the simulator\n"));
-  simulator = psim_create(argv[0]);
+  simulator = psim_create(argv[0], root_device);
 
   /* bring in all the data section */
   psim_init(simulator);
@@ -144,8 +123,8 @@ sim_read (SIM_ADDR mem, unsigned char *buf, int length)
 {
   int result = psim_read_memory(simulator, MAX_NR_PROCESSORS,
                                buf, mem, length);
-  TRACE(trace_gdb, ("sim_read(mem=0x%x, buf=0x%x, length=%d) = %d\n",
-                   mem, buf, length, result));
+  TRACE(trace_gdb, ("sim_read(mem=0x%lx, buf=0x%lx, length=%d) = %d\n",
+                   (long)mem, (long)buf, length, result));
   return result;
 }
 
@@ -156,8 +135,8 @@ sim_write (SIM_ADDR mem, unsigned char *buf, int length)
   int result = psim_write_memory(simulator, MAX_NR_PROCESSORS,
                                 buf, mem, length,
                                 1/*violate_ro*/);
-  TRACE(trace_gdb, ("sim_write(mem=0x%x, buf=0x%x, length=%d) = %d\n",
-                   mem, buf, length, result));
+  TRACE(trace_gdb, ("sim_write(mem=0x%lx, buf=0x%lx, length=%d) = %d\n",
+                   (long)mem, (long)buf, length, result));
   return result;
 }
 
@@ -168,8 +147,8 @@ sim_fetch_register (int regno, unsigned char *buf)
   if (simulator == NULL) {
     return;
   }
-  TRACE(trace_gdb, ("sim_fetch_register(regno=%d(%s), buf=0x%x)\n",
-                   regno, register_names[regno], buf));
+  TRACE(trace_gdb, ("sim_fetch_register(regno=%d(%s), buf=0x%lx)\n",
+                   regno, register_names[regno], (long)buf));
   psim_read_register(simulator, MAX_NR_PROCESSORS,
                     buf, register_names[regno],
                     raw_transfer);
@@ -181,8 +160,8 @@ sim_store_register (int regno, unsigned char *buf)
 {
   if (simulator == NULL)
     return;
-  TRACE(trace_gdb, ("sim_store_register(regno=%d(%s), buf=0x%x)\n",
-                   regno, register_names[regno], buf));
+  TRACE(trace_gdb, ("sim_store_register(regno=%d(%s), buf=0x%lx)\n",
+                   regno, register_names[regno], (long)buf));
   psim_write_register(simulator, MAX_NR_PROCESSORS,
                      buf, register_names[regno],
                      raw_transfer);
@@ -257,8 +236,8 @@ sim_stop_reason (enum sim_stop *reason, int *sigrc)
   
   }
 
-  TRACE(trace_gdb, ("sim_stop_reason(reason=0x%x(%d), sigrc=0x%x(%d))\n",
-                   reason, *reason, sigrc, *sigrc));
+  TRACE(trace_gdb, ("sim_stop_reason(reason=0x%lx(%ld), sigrc=0x%lx(%ld))\n",
+                   (long)reason, (long)*reason, (long)sigrc, (long)*sigrc));
 }
 
 
@@ -274,7 +253,6 @@ void
 sim_resume (int step, int siggnal)
 {
   void (*prev) ();
-  unsigned_word program_counter;
 
   TRACE(trace_gdb, ("sim_resume(step=%d, siggnal=%d)\n",
                    step, siggnal));
@@ -291,9 +269,15 @@ sim_resume (int step, int siggnal)
 }
 
 void
-sim_do_command(char *cmd)
+sim_do_command (char *cmd)
 {
-  TRACE(trace_gdb, ("sim_do_commands(cmd=%s) called\n", cmd));
+  TRACE(trace_gdb, ("sim_do_commands(cmd=%s) called\n",
+                   cmd ? cmd : "(null)"));
+  if (cmd) {
+    char **argv = buildargv(cmd);
+    psim_options(root_device, argv);
+    freeargv(argv);
+  }
 }
 
 void
@@ -310,7 +294,7 @@ zalloc(long size)
   void *memory = (void*)xmalloc(size);
   if (memory == NULL)
     error("xmalloc failed\n");
-  bzero(memory, size);
+  memset(memory, 0, size);
   return memory;
 }
 
@@ -318,3 +302,8 @@ void zfree(void *data)
 {
   mfree(NULL, data);
 }
+
+void flush_stdoutput(void)
+{
+  gdb_flush (gdb_stdout);
+}
This page took 0.031622 seconds and 4 git commands to generate.