Fix bug in jitter reported by Godmar Back (BIOS wouldn't finish
[pintos-anon] / src / misc / bochs-2.2.6-jitter.patch
1 diff -urp bochs-2.2.6/iodev/pit82c54.cc bochs-2.2.6.orig/iodev/pit82c54.cc
2 --- bochs-2.2.6.orig/iodev/pit82c54.cc  2006-01-08 12:39:08.000000000 -0800
3 +++ bochs-2.2.6/iodev/pit82c54.cc       2006-04-03 14:00:27.000000000 -0700
4 @@ -28,6 +28,7 @@
5  
6  #include "iodev.h"
7  #include "pit82c54.h"
8 +#include <stdlib.h>
9  #define LOG_THIS this->
10  
11  
12 @@ -359,7 +360,13 @@
13        case 2:
14         if(thisctr.count_written) {
15           if(thisctr.triggerGATE || thisctr.first_pass) {
16 -           set_count(thisctr, thisctr.inlatch);
17 +            unsigned n = thisctr.inlatch;
18 +            if (jitter && n > 5) {
19 +                n *= (double) rand() / RAND_MAX;
20 +                if (n < 5)
21 +                    n = 5;
22 +            }
23 +           set_count(thisctr, n);
24             thisctr.next_change_time=(thisctr.count_binary-1) & 0xFFFF;
25             thisctr.null_count=0;
26             if(thisctr.inlatch==1) {
27 diff -urp bochs-2.2.6/main.cc bochs-2.2.6.orig/main.cc
28 --- bochs-2.2.6.orig/main.cc    2006-01-22 04:31:15.000000000 -0800
29 +++ bochs-2.2.6/main.cc 2006-04-03 14:00:54.000000000 -0700
30 @@ -105,6 +105,7 @@
31  #endif
32  
33  char *bochsrc_filename = NULL;
34 +int jitter = 0;
35  
36  void bx_print_header ()
37  {
38 @@ -459,6 +460,13 @@
39      else if (!strcmp ("-q", argv[arg])) {
40        SIM->get_param_enum(BXP_BOCHS_START)->set (BX_QUICK_START);
41      }
42 +    else if (!strcmp ("-j", argv[arg])) {
43 +      if (++arg >= argc) BX_PANIC(("-j must be followed by a number"));
44 +      else {
45 +        jitter = 1;
46 +        srand (atoi (argv[arg]));
47 +      }
48 +    }
49      else if (!strcmp ("-f", argv[arg])) {
50        if (++arg >= argc) BX_PANIC(("-f must be followed by a filename"));
51        else bochsrc_filename = argv[arg];
52 diff -up /home/blp/cs140/bochs-2.2.6/bochs.h\~ /home/blp/cs140/bochs-2.2.6/bochs.h
53 --- bochs-2.2.6/bochs.h.orig    2006-01-28 08:16:02.000000000 -0800
54 +++ bochs-2.2.6/bochs.h 2006-04-03 14:03:54.000000000 -0700
55 @@ -698,4 +698,6 @@ int bx_init_hardware ();
56  
57  #endif
58  
59 +extern int jitter;
60 +
61  #endif  /* BX_BOCHS_H */