- BX_EXIT(exitcode) is called in several places, but the exitcode has been

completely ignored and Bochs has always been returning 0.  Now Bochs should
  exit with the proper exit code.
- implementation: BX_EXIT(exitcode) calls SIM->quit_sim(exitcode).
  quit_sim stores the exit code in the SIM object, then uses longjmp
  to unwind the stack and return to main().  main() calls
  SIM->get_exit_code() to retrieve the exit code and returns it.
- If you are wondering why we don't just call exit(exitcode), it is
  because in the wxWindows interface all of the CPU simulation runs as one
  thread while the user interface runs as another thread.  With the longjmp
  technique the simulation thread ends cleanly and it is possible to
  start a new simulation thread without making a new process.
This commit is contained in:
Bryce Denney 2002-12-16 06:43:02 +00:00
parent 3d4c99fa84
commit 6b21b27e60
3 changed files with 11 additions and 5 deletions

View File

@ -1,5 +1,5 @@
/////////////////////////////////////////////////////////////////////////
// $Id: siminterface.cc,v 1.90 2002-12-12 18:31:19 bdenney Exp $
// $Id: siminterface.cc,v 1.91 2002-12-16 06:43:02 bdenney Exp $
/////////////////////////////////////////////////////////////////////////
//
// See siminterface.h for description of the siminterface concept.
@ -37,6 +37,7 @@ class bx_real_sim_c : public bx_simulator_interface_c {
int enabled;
// save context to jump to if we must quit unexpectedly
jmp_buf *quit_context;
int exit_code;
public:
bx_real_sim_c ();
virtual ~bx_real_sim_c ();
@ -68,6 +69,7 @@ public:
virtual const char *get_log_level_name (int level);
virtual int get_max_log_level ();
virtual void quit_sim (int code);
virtual int get_exit_code () { return exit_code; }
virtual int get_default_rc (char *path, int len);
virtual int read_rc (char *path);
virtual int write_rc (char *path, int overwrite);
@ -225,6 +227,7 @@ bx_real_sim_c::bx_real_sim_c ()
for (i=0; i<registry_alloc_size; i++)
param_registry[i] = NULL;
quit_context = NULL;
exit_code = 0;
}
// called by constructor of bx_param_c, so that every parameter that is
@ -313,7 +316,8 @@ bx_real_sim_c::get_max_log_level ()
void
bx_real_sim_c::quit_sim (int code) {
BX_INFO (("quit_sim called"));
BX_INFO (("quit_sim called with exit code %d", code));
exit_code = code;
// use longjmp to quit cleanly, no matter where in the stack we are.
//fprintf (stderr, "using longjmp() to jump directly to the quit context!\n");
if (quit_context != NULL) {

View File

@ -1,5 +1,5 @@
/////////////////////////////////////////////////////////////////////////
// $Id: siminterface.h,v 1.94 2002-12-12 18:31:19 bdenney Exp $
// $Id: siminterface.h,v 1.95 2002-12-16 06:43:01 bdenney Exp $
/////////////////////////////////////////////////////////////////////////
//
// Before I can describe what this file is for, I have to make the
@ -1200,6 +1200,8 @@ public:
// telling it that bochs has stopped.
virtual void quit_sim (int code) {}
virtual int get_exit_code () { return 0; }
virtual int get_default_rc (char *path, int len) {return -1;}
virtual int read_rc (char *path) {return -1;}
virtual int write_rc (char *rc, int overwrite) {return -1;}

View File

@ -1,5 +1,5 @@
/////////////////////////////////////////////////////////////////////////
// $Id: main.cc,v 1.209 2002-12-16 02:49:55 yakovlev Exp $
// $Id: main.cc,v 1.210 2002-12-16 06:43:01 bdenney Exp $
/////////////////////////////////////////////////////////////////////////
//
// Copyright (C) 2002 MandrakeSoft S.A.
@ -1532,7 +1532,7 @@ int bxmain () {
char buf[16];
fgets (buf, sizeof(buf), stdin);
#endif
return 0;
return SIM->get_exit_code ();
}
#if defined(__WXMSW__)