Patches to make Bochs 2.6.2 work with Pintos
[pintos-anon] / src / misc / bochs-2.6.2-jitter-plus-segv.patch
diff --git a/src/misc/bochs-2.6.2-jitter-plus-segv.patch b/src/misc/bochs-2.6.2-jitter-plus-segv.patch
new file mode 100644 (file)
index 0000000..b6ad247
--- /dev/null
@@ -0,0 +1,135 @@
+diff --git a/bochs.h b/bochs.h
+index c2d6c6b..d37cf12 100644
+--- a/bochs.h
++++ b/bochs.h
+@@ -392,6 +392,7 @@ BOCHSAPI extern logfunc_t *genlog;
+ void bx_gdbstub_init(void);
+ void bx_gdbstub_break(void);
+ int bx_gdbstub_check(unsigned int eip);
++void bx_gdbstub_exception(unsigned int nr);
+ #define GDBSTUB_STOP_NO_REASON   (0xac0)
+ #if BX_SUPPORT_SMP
+@@ -589,4 +590,6 @@ BX_CPP_INLINE Bit64u bx_bswap64(Bit64u val64)
+ #define CopyHostQWordLittleEndian(hostAddrDst,  hostAddrSrc) \
+     (* (Bit64u *)(hostAddrDst)) = (* (Bit64u *)(hostAddrSrc));
++extern int jitter;
++
+ #endif  /* BX_BOCHS_H */
+diff --git a/cpu/exception.cc b/cpu/exception.cc
+index db38d1b..b2c5f29 100644
+--- a/cpu/exception.cc
++++ b/cpu/exception.cc
+@@ -914,6 +914,10 @@ void BX_CPU_C::exception(unsigned vector, Bit16u error_code)
+   BX_CPU_THIS_PTR last_exception_type = exception_type;
++#if BX_GDBSTUB
++  bx_gdbstub_exception(vector);
++#endif
++
+   if (real_mode()) {
+     push_error = 0; // not INT, no error code pushed
+     error_code = 0;
+diff --git a/gdbstub.cc b/gdbstub.cc
+index da600b4..577938d 100644
+--- a/gdbstub.cc
++++ b/gdbstub.cc
+@@ -49,6 +49,7 @@ static int last_stop_reason = GDBSTUB_STOP_NO_REASON;
+ #define GDBSTUB_EXECUTION_BREAKPOINT    (0xac1)
+ #define GDBSTUB_TRACE                   (0xac2)
+ #define GDBSTUB_USER_BREAK              (0xac3)
++#define GDBSTUB_EXCEPTION_0E            (0xac4)
+ static bx_list_c *gdbstub_list;
+ static int listen_socket_fd;
+@@ -317,6 +318,12 @@ int bx_gdbstub_check(unsigned int eip)
+   return GDBSTUB_STOP_NO_REASON;
+ }
++void bx_gdbstub_exception(unsigned int nr) 
++{
++    if (nr == 0x0e)
++        last_stop_reason = GDBSTUB_EXCEPTION_0E;
++}
++
+ static int remove_breakpoint(unsigned addr, int len)
+ {
+   if (len != 1)
+@@ -487,6 +494,10 @@ static void debug_loop(void)
+         {
+           write_signal(&buf[1], SIGTRAP);
+         }
++        else if (last_stop_reason == GDBSTUB_EXCEPTION_0E)
++        {
++          write_signal(&buf[1], SIGSEGV);
++        }
+         else
+         {
+           write_signal(&buf[1], 0);
+@@ -514,6 +525,10 @@ static void debug_loop(void)
+         {
+           write_signal(&buf[1], SIGTRAP);
+         }
++        else if (last_stop_reason == GDBSTUB_EXCEPTION_0E)
++        {
++          write_signal(&buf[1], SIGSEGV);
++        }
+         else
+         {
+           write_signal(&buf[1], SIGTRAP);
+diff --git a/iodev/pit82c54.cc b/iodev/pit82c54.cc
+index 09dcd8e..7e335d4 100644
+--- a/iodev/pit82c54.cc
++++ b/iodev/pit82c54.cc
+@@ -49,6 +49,7 @@
+ #include "iodev.h"
+ #include "pit82c54.h"
++#include <stdlib.h>
+ #define LOG_THIS this->
+@@ -410,7 +411,14 @@ void BX_CPP_AttrRegparmN(1) pit_82C54::clock(Bit8u cnum)
+       case 2:
+         if (thisctr.count_written) {
+           if (thisctr.triggerGATE || thisctr.first_pass) {
+-            set_count(thisctr, thisctr.inlatch);
++            //set_count(thisctr, thisctr.inlatch);
++            unsigned n = thisctr.inlatch;
++            if (jitter && n > 5) {
++                n *= (double) rand() / RAND_MAX;
++                if (n < 5)
++                    n = 5;
++            }
++            set_count(thisctr, n);
+             thisctr.next_change_time=(thisctr.count_binary-1) & 0xFFFF;
+             thisctr.null_count=0;
+             if (thisctr.inlatch==1) {
+diff --git a/main.cc b/main.cc
+index 0f11e31..008f05f 100644
+--- a/main.cc
++++ b/main.cc
+@@ -101,6 +101,7 @@ BOCHSAPI BX_CPU_C bx_cpu;
+ BOCHSAPI BX_MEM_C bx_mem;
+ char *bochsrc_filename = NULL;
++int jitter = 0;
+ void bx_print_header()
+ {
+@@ -639,6 +640,13 @@ int bx_init_main(int argc, char *argv[])
+       else SIM->get_param_string(BXPN_DEBUGGER_LOG_FILENAME)->set(argv[arg]);
+     }
+ #endif
++    else if (!strcmp ("-j", argv[arg])) {
++      if (++arg >= argc) BX_PANIC(("-j must be followed by a number"));
++      else {
++        jitter = 1;
++        srand (atoi (argv[arg]));
++      }
++    }
+     else if (!strcmp("-f", argv[arg])) {
+       if (++arg >= argc) BX_PANIC(("-f must be followed by a filename"));
+       else bochsrc_filename = argv[arg];