The following patch adds the ability to make or1ksim return the
simulated program's return code when exiting, instead of 0 in the case
of a graceful exit of the simulation.

Index: sim-config.h
===================================================================
--- sim-config.h        (revision 793)
+++ sim-config.h        (working copy)
@@ -96,6 +96,8 @@
     int strict_npc;            /* JPB. NPC flushes pipeline when changed */
     int  quiet;                        /* Minimize message output */
     int  report_mem_errs;      /* Report out of memory accesses */
+    int  use_sim_returncode;   /* Return the returncode of the simulated app
+                                  when exiting */
   } sim;

   struct
Index: doc/or1ksim.texi
===================================================================
--- doc/or1ksim.texi    (revision 793)
+++ doc/or1ksim.texi    (working copy)
@@ -492,6 +492,10 @@
 This was the default behaviour up to @value{OR1KSIM} 0.4.0.  This flag is
 provided for those who wish to keep that behavior.

+@item --use-sim-return-code
+@cindex @code{--use-sim-return-code}
+Make @value{OR1KSIM} exit with the same return code as the simulated program.
+
 @item --strict-npc
 @cindex @code{--strict-npc}
 In real hardware, setting the next program counter (NPC, SPR 16),
Index: toplevel-support.c
===================================================================
--- toplevel-support.c  (revision 793)
+++ toplevel-support.c  (working copy)
@@ -443,7 +443,7 @@
 /*!Clean up

    Close an profile or log files, disconnect VAPI. Call any memory mapped
-   peripheral close down function. Exit with rc 0.                           */
+   peripheral close down function. Exit with rc depending on option set.     */
 /*---------------------------------------------------------------------------*/
 void
 sim_done ()
@@ -477,6 +477,9 @@
   done_memory_table ();
   mc_done ();

-  exit (0);
+  if (config.sim.use_sim_returncode)
+    exit ((int)cpu_state.reg[3]);
+  else
+    exit (0);

 }      /* sim_done() */
Index: sim-config.c
===================================================================
--- sim-config.c        (revision 793)
+++ sim-config.c        (working copy)
@@ -955,6 +955,7 @@
   struct arg_lit  *profile;
   struct arg_lit  *mprofile;
   struct arg_file *load_file;
+  struct arg_file *use_sim_returncode;
   struct arg_end  *end;

   /* Specify each argument, with fall back values */
@@ -980,6 +981,8 @@
                        "show virtual instruction address when tracing");
   report_mem_errs = arg_lit0 (NULL, "report-memory-errors",
                              "Report out of memory accesses");
+  use_sim_returncode = arg_lit0 (NULL, "use-sim-return-code",
+                                "exit simulator with return code of simulated 
program");
   strict_npc = arg_lit0 (NULL, "strict-npc", "setting NPC flushes pipeline");
   profile = arg_lit0 (NULL, "enable-profile", "enable profiling");
   mprofile = arg_lit0 (NULL, "enable-mprofile", "enable memory profiling");
@@ -1002,6 +1005,7 @@
     trace_phy,
     trace_virt,
     report_mem_errs,
+    use_sim_returncode,
     strict_npc,
     profile,
     mprofile,
@@ -1073,6 +1077,9 @@
   /* Request for memory errors */
   config.sim.report_mem_errs = report_mem_errs->count;

+  /* Use simulated return code when exiting */
+  config.sim.use_sim_returncode = use_sim_returncode->count;
+
   /* Process config file next (if given), so any other command args will
      override */
   if (0 == cfg_file->count)
Index: ChangeLog
===================================================================
--- ChangeLog   (revision 793)
+++ ChangeLog   (working copy)
@@ -1,3 +1,12 @@
+2012-04-08  Julius Baxter  <[email protected]>
+
+       * sim-config.h: <struct sim>: Added int use_sim_returncode.
+       * doc/or1ksim.texi: Added information about --use-sim-return-code
+       switch
+       * toplevel-support.c: (sim_done): Add check for use of simulated
+       program's return code - if so, fetch it from gpr3 and return it.
+       * sim-config.c: Add simulated return code support.
+
 2012-04-07  Jeremy Bennett  <[email protected]>

        * MAINTAINERS: Added.
_______________________________________________
OpenRISC mailing list
[email protected]
http://lists.openrisc.net/listinfo/openrisc

Reply via email to