42fafc5cd4ab98a7dbb2a695fc71cb65f0ae32eb
[pintos-anon] / src / misc / bochs-2.1.1.patch
1 The first two patches are needed for Bochs to properly compile and run
2 under Solaris on Sparc.  If you're not compiling on Solaris, don't
3 apply them.  The first should probably be handled by Autoconf; I'm not
4 sure why it isn't.  The second is needed to make GCC accept X.h's
5 frequent use of "extern foo(...)", because use of an implicit int
6 return type is forbidden in C++.
7
8 The third patch makes the gdb stubs work on Solaris/Sparc, by doing
9 proper byteswapping.  It should be harmless elsewhere.
10
11 The fourth patch enables the serial device under Solaris and disables
12 tty setup at the same time.  Tty setup is a pain when you want to
13 connect a serial port to stdout and it doesn't work under Solaris
14 anyway.  This patch is useful everywhere with `pintos', but may not be
15 wanted elsewhere.
16
17 The remaining patches add the `jitter' feature described in the
18 project documentation, in which timer interrupts are delivered at
19 random intervals.
20
21 To apply all the patches, cd into the Bochs directory, then type
22         patch -p1 < $PINTOSROOT/src/misc/bochs-2.1.1.patch
23 You will have to supply the proper path to the patch, of course.  You
24 can provide the --dry-run option to patch if you want to test whether
25 the patch would apply cleanly before actually patching.
26
27 To apply a subset of the patches, use a text editor to delete the
28 unwanted patches, then follow the above instructions.
29
30 Here's a ./configure invocation for Bochs that works optimally with
31 the `pintos' utility:
32         ./configure --with-x --with-x11 --with-term --with-nogui
33 If you want the gdb stub, add --enable-gdb-stub
34 If you want the internal debugger, add --enable-debugger
35
36 Here are the commands used to build and install all the versions of
37 Bochs we make available on the elaines:
38
39 cd /tmp && tar xzf ~/bochs-2.1.1.tar.gz && cd bochs-2.1.1
40 patch -p1 < $PINTOSROOT/src/misc/bochs-2.1.1.patch
41 CFGOPTS="--with-x --with-x11 --with-term --with-nogui --prefix=/usr/class/cs140/i386"
42 (mkdir plain &&
43  cd plain && 
44  ../configure $CFGOPTS && 
45  make && 
46  make install)
47 (mkdir with-gdb &&
48  cd with-gdb &&
49  ../configure --enable-gdb-stub $CFGOPTS &&
50  make &&
51  cp bochs /usr/class/cs140/i386/bin/bochs-gdb)
52 (mkdir with-dbg &&
53  cd with-dbg &&
54  ../configure --enable-debugger $CFGOPTS &&
55  make &&
56  cp bochs /usr/class/cs140/i386/bin/bochs-dbg)
57
58 diff -urp orig/bochs-2.1.1/Makefile.in bochs-2.1.1/Makefile.in
59 --- orig/bochs-2.1.1/Makefile.in        2004-02-11 14:28:02.000000000 -0800
60 +++ bochs-2.1.1/Makefile.in     2004-09-13 15:05:26.281550000 -0700
61 @@ -92,7 +92,7 @@ CXX = @CXX@
62  CFLAGS = @CFLAGS@ @GUI_CFLAGS@ $(MCH_CFLAGS) $(FLA_FLAGS) @DEFINE_PLUGIN_PATH@ -DBX_SHARE_PATH='"$(sharedir)"'
63  CXXFLAGS = @CXXFLAGS@ @GUI_CXXFLAGS@ $(MCH_CFLAGS) $(FLA_FLAGS) @DEFINE_PLUGIN_PATH@ -DBX_SHARE_PATH='"$(sharedir)"'
64  
65 -LDFLAGS = @LDFLAGS@
66 +LDFLAGS = @LDFLAGS@ -lsocket
67  LIBS = @LIBS@
68  # To compile with readline:
69  #   linux needs just -lreadline
70
71 diff -urp orig/bochs-2.1.1/gui/Makefile.in bochs-2.1.1/gui/Makefile.in
72 --- orig/bochs-2.1.1/gui/Makefile.in    2003-11-28 07:07:28.000000000 -0800
73 +++ bochs-2.1.1/gui/Makefile.in 2004-09-13 15:05:09.402039000 -0700
74 @@ -44,7 +44,7 @@ SHELL = /bin/sh
75  @SET_MAKE@
76  
77  CXX = @CXX@
78 -CXXFLAGS = $(BX_INCDIRS) @CXXFLAGS@  @GUI_CXXFLAGS@
79 +CXXFLAGS = $(BX_INCDIRS) @CXXFLAGS@  @GUI_CXXFLAGS@ -fms-extensions
80  LOCAL_CXXFLAGS =
81  LDFLAGS = @LDFLAGS@
82  LIBS = @LIBS@
83
84
85 diff -urp orig/bochs-2.1.1/gdbstub.cc bochs-2.1.1/gdbstub.cc
86 --- orig/bochs-2.1.1/gdbstub.cc 2004-02-11 14:28:41.000000000 -0800
87 +++ bochs-2.1.1/gdbstub.cc      2004-09-13 16:41:59.652988000 -0700
88 @@ -474,11 +475,13 @@ static void debug_loop(void)
89            case 'P':
90                {
91                   int reg;
92 -                 int value;
93 +                 Bit8u vbits[4];
94 +                 Bit32u value;
95                   char* ebuf;
96                   
97                   reg = strtoul(&buffer[1], &ebuf, 16);
98 -                 value = ntohl(strtoul(ebuf + 1, &ebuf, 16));
99 +                 hex2mem(ebuf + 1, vbits, sizeof value);
100 +                 ReadHostDWordFromLittleEndian(vbits, value);
101                   
102                   BX_INFO (("reg %d set to %x", reg, value));
103                   
104 @@ -527,35 +530,36 @@ static void debug_loop(void)
105                }
106              
107            case 'g':
108 -            registers[0] = EAX;
109 -            registers[1] = ECX;
110 -            registers[2] = EDX;
111 -            registers[3] = EBX;
112 -            registers[4] = ESP;
113 -            registers[5] = EBP;
114 -            registers[6] = ESI;
115 -            registers[7] = EDI;
116 +            WriteHostDWordToLittleEndian(registers + 0, EAX);
117 +            WriteHostDWordToLittleEndian(registers + 1, ECX);
118 +            WriteHostDWordToLittleEndian(registers + 2, EDX);
119 +            WriteHostDWordToLittleEndian(registers + 3, EBX);
120 +            WriteHostDWordToLittleEndian(registers + 4, ESP);
121 +            WriteHostDWordToLittleEndian(registers + 5, EBP);
122 +            WriteHostDWordToLittleEndian(registers + 6, ESI);
123 +            WriteHostDWordToLittleEndian(registers + 7, EDI);
124              if (last_stop_reason == GDBSTUB_EXECUTION_BREAKPOINT)
125                {
126 -                 registers[8] = EIP + 1;
127 +                WriteHostDWordToLittleEndian(registers + 8, EIP + 1);
128                }
129              else
130                {
131 -                 registers[8] = EIP;
132 +                WriteHostDWordToLittleEndian(registers + 8, EIP);
133                }
134 -            registers[9] = BX_CPU_THIS_PTR read_eflags();
135 -            registers[10] = 
136 -              BX_CPU_THIS_PTR sregs[BX_SEG_REG_CS].selector.value;
137 -            registers[11] = 
138 -              BX_CPU_THIS_PTR sregs[BX_SEG_REG_SS].selector.value;
139 -            registers[12] = 
140 -              BX_CPU_THIS_PTR sregs[BX_SEG_REG_DS].selector.value;
141 -            registers[13] = 
142 -              BX_CPU_THIS_PTR sregs[BX_SEG_REG_ES].selector.value;
143 -            registers[14] = 
144 -              BX_CPU_THIS_PTR sregs[BX_SEG_REG_FS].selector.value;
145 -            registers[15] = 
146 -              BX_CPU_THIS_PTR sregs[BX_SEG_REG_GS].selector.value;
147 +            WriteHostDWordToLittleEndian(registers + 9,
148 +                                         BX_CPU_THIS_PTR read_eflags());
149 +            WriteHostDWordToLittleEndian(registers + 10,
150 +              BX_CPU_THIS_PTR sregs[BX_SEG_REG_CS].selector.value);
151 +            WriteHostDWordToLittleEndian(registers + 11,
152 +              BX_CPU_THIS_PTR sregs[BX_SEG_REG_SS].selector.value);
153 +            WriteHostDWordToLittleEndian(registers + 12,
154 +              BX_CPU_THIS_PTR sregs[BX_SEG_REG_DS].selector.value);
155 +            WriteHostDWordToLittleEndian(registers + 13,
156 +              BX_CPU_THIS_PTR sregs[BX_SEG_REG_ES].selector.value);
157 +            WriteHostDWordToLittleEndian(registers + 14,
158 +              BX_CPU_THIS_PTR sregs[BX_SEG_REG_FS].selector.value);
159 +            WriteHostDWordToLittleEndian(registers + 15,
160 +              BX_CPU_THIS_PTR sregs[BX_SEG_REG_GS].selector.value);
161              mem2hex((char *)registers, obuf, NUMREGSBYTES);
162              put_reply(obuf);
163              break;
164
165 diff -u tmp/bochs-2.1.1/iodev/serial.cc bochs-2.1.1/iodev/serial.cc
166 --- tmp/bochs-2.1.1/iodev/serial.cc     2004-02-11 14:28:54.000001000 -0800
167 +++ bochs-2.1.1/iodev/serial.cc 2004-09-14 23:02:04.000001000 -0700
168 @@ -53,7 +53,7 @@
169  #endif
170  #endif
171  
172 -#if defined(__NetBSD__) || defined(__FreeBSD__) || defined(__OpenBSD__) || defined(__linux__) || defined(__GNU__) || defined(__APPLE__)
173 +#if defined(__NetBSD__) || defined(__FreeBSD__) || defined(__OpenBSD__) || defined(__linux__) || defined(__GNU__) || defined(__APPLE__) || defined(__sun__)
174  #define SERIAL_ENABLE
175  #endif
176  
177 @@ -122,6 +122,7 @@
178      if (tty_id < 0)
179        BX_PANIC(("open of %s (%s) failed\n",
180                  "com1", bx_options.com[0].Odev->getptr ()));
181 +#if 0
182      BX_DEBUG(("tty_id: %d",tty_id));
183      tcgetattr(tty_id, &term_orig);
184      bcopy((caddr_t) &term_orig, (caddr_t) &term_new, sizeof(struct termios));
185 @@ -145,6 +146,7 @@
186      term_new.c_cc[VTIME] = 0;
187      //term_new.c_iflag |= IXOFF;
188      tcsetattr(tty_id, TCSAFLUSH, &term_new);
189 +#endif
190    }
191  #endif   /* def SERIAL_ENABLE */
192    // nothing for now
193
194 diff -urp bochs-2.1.1.orig/bochs.h bochs-2.1.1/bochs.h
195 --- bochs-2.1.1.orig/bochs.h    2004-02-11 14:28:03.000000000 -0800
196 +++ bochs-2.1.1/bochs.h 2004-09-20 17:02:01.000000000 -0700
197 @@ -757,4 +757,6 @@ int bx_init_hardware ();
198  
199  #endif
200  
201 +extern int jitter;
202 +
203  #endif  /* BX_BOCHS_H */
204 diff -urp bochs-2.1.1.orig/iodev/pit82c54.cc bochs-2.1.1/iodev/pit82c54.cc
205 --- bochs-2.1.1.orig/iodev/pit82c54.cc  2004-02-11 14:28:53.000000000 -0800
206 +++ bochs-2.1.1/iodev/pit82c54.cc       2004-09-20 17:18:24.000000000 -0700
207 @@ -28,6 +28,7 @@
208  
209  #include "bochs.h"
210  #include "pit82c54.h"
211 +#include <stdlib.h>
212  #define LOG_THIS this->
213  
214  
215 @@ -356,7 +357,13 @@ pit_82C54::clock(Bit8u cnum) {
216        case 2:
217         if(thisctr.count_written) {
218           if(thisctr.triggerGATE || thisctr.first_pass) {
219 -           set_count(thisctr, thisctr.inlatch);
220 +            unsigned n = thisctr.inlatch;
221 +            if (jitter) {
222 +                n *= (double) rand() / RAND_MAX;
223 +                if (n < 5)
224 +                    n = 5;
225 +            }
226 +           set_count(thisctr, n);
227             thisctr.next_change_time=(thisctr.count_binary-1) & 0xFFFF;
228             thisctr.null_count=0;
229             if(thisctr.inlatch==1) {
230 diff -urp bochs-2.1.1.orig/iodev/pit_wrap.cc bochs-2.1.1/iodev/pit_wrap.cc
231 diff -urp bochs-2.1.1.orig/iodev/serial.cc bochs-2.1.1/iodev/serial.cc
232 diff -urp bochs-2.1.1.orig/main.cc bochs-2.1.1/main.cc
233 --- bochs-2.1.1.orig/main.cc    2004-02-11 14:28:41.000000000 -0800
234 +++ bochs-2.1.1/main.cc 2004-09-20 17:15:39.000000000 -0700
235 @@ -58,6 +58,7 @@
236  
237  
238  int bochsrc_include_count = 0;
239 +int jitter = 0;
240  
241  extern "C" {
242  #include <signal.h>
243 @@ -2022,6 +2024,13 @@ bx_init_main (int argc, char *argv[])
244      else if (!strcmp ("-q", argv[arg])) {
245        SIM->get_param_enum(BXP_BOCHS_START)->set (BX_QUICK_START);
246      }
247 +    else if (!strcmp ("-j", argv[arg])) {
248 +      if (++arg >= argc) BX_PANIC(("-j must be followed by a number"));
249 +      else {
250 +        jitter = 1;
251 +        srand (atoi (argv[arg]));
252 +      }
253 +    }
254      else if (!strcmp ("-f", argv[arg])) {
255        if (++arg >= argc) BX_PANIC(("-f must be followed by a filename"));
256        else bochsrc_filename = argv[arg];