On Sun, 2012-04-08 at 11:35 +0100, Julius Baxter wrote: 
> 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.

Hi Julius,

Well done spotting this - it certainly needs fixing. Not sure how it
remained unnoticed for so long. In particular GNU regression tests I am
sure rely on the RC for determining success or failure.

I don't think it needs to be an option. Or1ksim should always return the
underlying RC. Up to the calling script to ignore the result if it
wishes.

It is not correct for sim_done to look in R3, since it is called in all
sorts of places when the program must terminate, and only in the case of
l.nop 1 is the value in R3 of any relevance. In particular you might get
a RC of 0, when the underlying program has a serious error.

I suggest that sim_done be given a parameter, and the calling location
decide what to pass there. In the case of l.nop 1, it should pass the
value in R3.

Not sure what to do in the other cases. In the case of peaceful
termination through other means (e.g. quit from the interactive
console), is zero the correct RC? What about if the user hits ctrl-C?
What if the suspend bit is set in the power management SPR? Accessing an
invalid register (actually that ought to be an assertion, not a test)?
Failure when setting up RSP?

The trouble is we have a 32-bit result, but there are more than 2^32
possible outcomes.

Maybe the simplest approach is to use the RC if set by l.nop 1, and use
zero in all other cases?

HTH,


Jeremy

> 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.opencores.org/listinfo/openrisc

-- 
Tel:      +44 (1590) 610184
Cell:     +44 (7970) 676050
SkypeID: jeremybennett
Email:   [email protected]
Web:     www.embecosm.com

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

Reply via email to