Updated to use Bochs 2.6.11
[pintos-anon] / src / misc / bochs-2.6.11-jitter-plus-segv.patch
1 diff -ru bochs-2.6.11.dist/bochs.h bochs-2.6.11/bochs.h
2 --- bochs-2.6.11.dist/bochs.h   2019-12-19 23:42:07.299552000 -0800
3 +++ bochs-2.6.11/bochs.h        2021-01-17 17:28:08.093933541 -0800
4 @@ -409,6 +409,7 @@
5  void bx_gdbstub_init(void);
6  void bx_gdbstub_break(void);
7  int bx_gdbstub_check(unsigned int eip);
8 +void bx_gdbstub_exception(unsigned int nr);
9  #define GDBSTUB_STOP_NO_REASON   (0xac0)
10  
11  #if BX_SUPPORT_SMP
12 @@ -664,4 +665,6 @@
13  
14  #endif
15  
16 +extern int jitter;
17 +
18  #endif  /* BX_BOCHS_H */
19 Only in bochs-2.6.11: bochs.h.orig
20 diff -ru bochs-2.6.11.dist/cpu/exception.cc bochs-2.6.11/cpu/exception.cc
21 --- bochs-2.6.11.dist/cpu/exception.cc  2019-12-26 08:48:33.074097000 -0800
22 +++ bochs-2.6.11/cpu/exception.cc       2021-01-17 17:28:08.093933541 -0800
23 @@ -991,6 +991,10 @@
24  
25    BX_CPU_THIS_PTR last_exception_type = exception_type;
26  
27 +#if BX_GDBSTUB
28 +  bx_gdbstub_exception(vector);
29 +#endif
30 +
31    if (real_mode()) {
32      push_error = 0; // not INT, no error code pushed
33      error_code = 0;
34 Only in bochs-2.6.11/cpu: exception.cc.orig
35 diff -ru bochs-2.6.11.dist/gdbstub.cc bochs-2.6.11/gdbstub.cc
36 --- bochs-2.6.11.dist/gdbstub.cc        2017-03-06 13:30:05.467768000 -0800
37 +++ bochs-2.6.11/gdbstub.cc     2021-01-17 17:28:35.270952903 -0800
38 @@ -50,6 +50,7 @@
39  #define GDBSTUB_EXECUTION_BREAKPOINT    (0xac1)
40  #define GDBSTUB_TRACE                   (0xac2)
41  #define GDBSTUB_USER_BREAK              (0xac3)
42 +#define GDBSTUB_EXCEPTION_0E            (0xac4)
43  
44  static bx_list_c *gdbstub_list;
45  static int listen_socket_fd;
46 @@ -319,6 +320,12 @@
47    return GDBSTUB_STOP_NO_REASON;
48  }
49  
50 +void bx_gdbstub_exception(unsigned int nr)
51 +{
52 +    if (nr == 0x0e)
53 +        last_stop_reason = GDBSTUB_EXCEPTION_0E;
54 +}
55 +
56  static int remove_breakpoint(Bit64u addr, int len)
57  {
58    if (len != 1)
59 @@ -489,6 +496,10 @@
60          {
61            write_signal(&buf[1], SIGTRAP);
62          }
63 +        else if (last_stop_reason == GDBSTUB_EXCEPTION_0E)
64 +        {
65 +          write_signal(&buf[1], SIGSEGV);
66 +        }
67          else
68          {
69            write_signal(&buf[1], 0);
70 @@ -516,6 +527,10 @@
71          {
72            write_signal(&buf[1], SIGTRAP);
73          }
74 +        else if (last_stop_reason == GDBSTUB_EXCEPTION_0E)
75 +        {
76 +          write_signal(&buf[1], SIGSEGV);
77 +        }
78          else
79          {
80            write_signal(&buf[1], SIGTRAP);
81 Only in bochs-2.6.11: gdbstub.cc.orig
82 Only in bochs-2.6.11: gdbstub.cc~
83 diff -ru bochs-2.6.11.dist/iodev/pit82c54.cc bochs-2.6.11/iodev/pit82c54.cc
84 --- bochs-2.6.11.dist/iodev/pit82c54.cc 2018-05-14 11:17:04.955283000 -0700
85 +++ bochs-2.6.11/iodev/pit82c54.cc      2021-01-17 17:28:08.097266918 -0800
86 @@ -49,6 +49,7 @@
87  
88  #include "iodev.h"
89  #include "pit82c54.h"
90 +#include <stdlib.h>
91  #define LOG_THIS this->
92  
93  
94 @@ -410,7 +411,14 @@
95        case 2:
96          if (thisctr.count_written) {
97            if (thisctr.triggerGATE || thisctr.first_pass) {
98 -            set_count(thisctr, thisctr.inlatch);
99 +            //set_count(thisctr, thisctr.inlatch);
100 +            unsigned n = thisctr.inlatch;
101 +            if (jitter && n > 5) {
102 +                n *= (double) rand() / RAND_MAX;
103 +                if (n < 5)
104 +                    n = 5;
105 +            }
106 +            set_count(thisctr, n);
107              thisctr.next_change_time=(thisctr.count_binary-1) & 0xFFFF;
108              thisctr.null_count=0;
109              if (thisctr.inlatch==1) {
110 diff -ru bochs-2.6.11.dist/main.cc bochs-2.6.11/main.cc
111 --- bochs-2.6.11.dist/main.cc   2020-01-02 08:19:02.083668000 -0800
112 +++ bochs-2.6.11/main.cc        2021-01-17 17:28:08.097266918 -0800
113 @@ -94,6 +94,7 @@
114  BOCHSAPI BX_MEM_C bx_mem;
115  
116  char *bochsrc_filename = NULL;
117 +int jitter = 0;
118  
119  size_t bx_get_timestamp(char *buffer)
120  {
121 @@ -705,6 +706,13 @@
122        else SIM->get_param_string(BXPN_DEBUGGER_LOG_FILENAME)->set(argv[arg]);
123      }
124  #endif
125 +    else if (!strcmp ("-j", argv[arg])) {
126 +      if (++arg >= argc) BX_PANIC(("-j must be followed by a number"));
127 +      else {
128 +        jitter = 1;
129 +        srand (atoi (argv[arg]));
130 +      }
131 +    }
132      else if (!strcmp("-f", argv[arg])) {
133        if (++arg >= argc) BX_PANIC(("-f must be followed by a filename"));
134        else bochsrc_filename = argv[arg];
135 Only in bochs-2.6.11: main.cc.orig