Make tests public. Rewrite most tests. Add tests.
[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 PREFIX="/usr/class/cs140/`uname -m`"
42 CFGOPTS="--with-x --with-x11 --with-term --with-nogui --prefix=$PREFIX"
43 (mkdir plain &&
44  cd plain && 
45  ../configure $CFGOPTS && 
46  make && 
47  make install)
48 (mkdir with-gdb &&
49  cd with-gdb &&
50  ../configure --enable-gdb-stub $CFGOPTS &&
51  make &&
52  cp bochs $PREFIX/bin/bochs-gdb)
53 (mkdir with-dbg &&
54  cd with-dbg &&
55  ../configure --enable-debugger $CFGOPTS &&
56  make &&
57  cp bochs $PREFIX/bin/bochs-dbg)
58
59 diff -urp orig/bochs-2.1.1/Makefile.in bochs-2.1.1/Makefile.in
60 --- orig/bochs-2.1.1/Makefile.in        2004-02-11 14:28:02.000000000 -0800
61 +++ bochs-2.1.1/Makefile.in     2004-09-13 15:05:26.281550000 -0700
62 @@ -92,7 +92,7 @@ CXX = @CXX@
63  CFLAGS = @CFLAGS@ @GUI_CFLAGS@ $(MCH_CFLAGS) $(FLA_FLAGS) @DEFINE_PLUGIN_PATH@ -DBX_SHARE_PATH='"$(sharedir)"'
64  CXXFLAGS = @CXXFLAGS@ @GUI_CXXFLAGS@ $(MCH_CFLAGS) $(FLA_FLAGS) @DEFINE_PLUGIN_PATH@ -DBX_SHARE_PATH='"$(sharedir)"'
65  
66 -LDFLAGS = @LDFLAGS@
67 +LDFLAGS = @LDFLAGS@ -lsocket
68  LIBS = @LIBS@
69  # To compile with readline:
70  #   linux needs just -lreadline
71
72 diff -urp orig/bochs-2.1.1/gui/Makefile.in bochs-2.1.1/gui/Makefile.in
73 --- orig/bochs-2.1.1/gui/Makefile.in    2003-11-28 07:07:28.000000000 -0800
74 +++ bochs-2.1.1/gui/Makefile.in 2004-09-13 15:05:09.402039000 -0700
75 @@ -44,7 +44,7 @@ SHELL = /bin/sh
76  @SET_MAKE@
77  
78  CXX = @CXX@
79 -CXXFLAGS = $(BX_INCDIRS) @CXXFLAGS@  @GUI_CXXFLAGS@
80 +CXXFLAGS = $(BX_INCDIRS) @CXXFLAGS@  @GUI_CXXFLAGS@ -fms-extensions
81  LOCAL_CXXFLAGS =
82  LDFLAGS = @LDFLAGS@
83  LIBS = @LIBS@
84
85
86 diff -urp orig/bochs-2.1.1/gdbstub.cc bochs-2.1.1/gdbstub.cc
87 --- orig/bochs-2.1.1/gdbstub.cc 2004-02-11 14:28:41.000000000 -0800
88 +++ bochs-2.1.1/gdbstub.cc      2004-09-13 16:41:59.652988000 -0700
89 @@ -474,11 +475,13 @@ static void debug_loop(void)
90            case 'P':
91                {
92                   int reg;
93 -                 int value;
94 +                 Bit8u vbits[4];
95 +                 Bit32u value;
96                   char* ebuf;
97                   
98                   reg = strtoul(&buffer[1], &ebuf, 16);
99 -                 value = ntohl(strtoul(ebuf + 1, &ebuf, 16));
100 +                 hex2mem(ebuf + 1, vbits, sizeof value);
101 +                 ReadHostDWordFromLittleEndian(vbits, value);
102                   
103                   BX_INFO (("reg %d set to %x", reg, value));
104                   
105 @@ -527,35 +530,36 @@ static void debug_loop(void)
106                }
107              
108            case 'g':
109 -            registers[0] = EAX;
110 -            registers[1] = ECX;
111 -            registers[2] = EDX;
112 -            registers[3] = EBX;
113 -            registers[4] = ESP;
114 -            registers[5] = EBP;
115 -            registers[6] = ESI;
116 -            registers[7] = EDI;
117 +            WriteHostDWordToLittleEndian(registers + 0, EAX);
118 +            WriteHostDWordToLittleEndian(registers + 1, ECX);
119 +            WriteHostDWordToLittleEndian(registers + 2, EDX);
120 +            WriteHostDWordToLittleEndian(registers + 3, EBX);
121 +            WriteHostDWordToLittleEndian(registers + 4, ESP);
122 +            WriteHostDWordToLittleEndian(registers + 5, EBP);
123 +            WriteHostDWordToLittleEndian(registers + 6, ESI);
124 +            WriteHostDWordToLittleEndian(registers + 7, EDI);
125              if (last_stop_reason == GDBSTUB_EXECUTION_BREAKPOINT)
126                {
127 -                 registers[8] = EIP + 1;
128 +                WriteHostDWordToLittleEndian(registers + 8, EIP + 1);
129                }
130              else
131                {
132 -                 registers[8] = EIP;
133 +                WriteHostDWordToLittleEndian(registers + 8, EIP);
134                }
135 -            registers[9] = BX_CPU_THIS_PTR read_eflags();
136 -            registers[10] = 
137 -              BX_CPU_THIS_PTR sregs[BX_SEG_REG_CS].selector.value;
138 -            registers[11] = 
139 -              BX_CPU_THIS_PTR sregs[BX_SEG_REG_SS].selector.value;
140 -            registers[12] = 
141 -              BX_CPU_THIS_PTR sregs[BX_SEG_REG_DS].selector.value;
142 -            registers[13] = 
143 -              BX_CPU_THIS_PTR sregs[BX_SEG_REG_ES].selector.value;
144 -            registers[14] = 
145 -              BX_CPU_THIS_PTR sregs[BX_SEG_REG_FS].selector.value;
146 -            registers[15] = 
147 -              BX_CPU_THIS_PTR sregs[BX_SEG_REG_GS].selector.value;
148 +            WriteHostDWordToLittleEndian(registers + 9,
149 +                                         BX_CPU_THIS_PTR read_eflags());
150 +            WriteHostDWordToLittleEndian(registers + 10,
151 +              BX_CPU_THIS_PTR sregs[BX_SEG_REG_CS].selector.value);
152 +            WriteHostDWordToLittleEndian(registers + 11,
153 +              BX_CPU_THIS_PTR sregs[BX_SEG_REG_SS].selector.value);
154 +            WriteHostDWordToLittleEndian(registers + 12,
155 +              BX_CPU_THIS_PTR sregs[BX_SEG_REG_DS].selector.value);
156 +            WriteHostDWordToLittleEndian(registers + 13,
157 +              BX_CPU_THIS_PTR sregs[BX_SEG_REG_ES].selector.value);
158 +            WriteHostDWordToLittleEndian(registers + 14,
159 +              BX_CPU_THIS_PTR sregs[BX_SEG_REG_FS].selector.value);
160 +            WriteHostDWordToLittleEndian(registers + 15,
161 +              BX_CPU_THIS_PTR sregs[BX_SEG_REG_GS].selector.value);
162              mem2hex((char *)registers, obuf, NUMREGSBYTES);
163              put_reply(obuf);
164              break;
165
166 diff -urp bochs-2.1.1-upstream/iodev/serial.cc bochs-2.1.1/iodev/serial.cc
167 --- tmp/bochs-2.1.1/iodev/serial.cc     2004-02-11 14:28:54.000000000 -0800
168 +++ bochs-2.1.1/iodev/serial.cc 2005-06-01 20:26:01.000000000 -0700
169 @@ -53,7 +53,7 @@
170  #endif
171  #endif
172  
173 -#if defined(__NetBSD__) || defined(__FreeBSD__) || defined(__OpenBSD__) || defined(__linux__) || defined(__GNU__) || defined(__APPLE__)
174 +#if defined(__NetBSD__) || defined(__FreeBSD__) || defined(__OpenBSD__) || defined(__linux__) || defined(__GNU__) || defined(__APPLE__) || defined(__sun__)
175  #define SERIAL_ENABLE
176  #endif
177  
178 @@ -118,10 +118,11 @@ bx_serial_c::init(void)
179  
180  #ifdef SERIAL_ENABLE
181    if (strlen(bx_options.com[0].Odev->getptr ()) > 0) {
182 -    tty_id = open(bx_options.com[0].Odev->getptr (), O_RDWR|O_NONBLOCK,600);
183 +    tty_id = open(bx_options.com[0].Odev->getptr (), O_RDWR,600);
184      if (tty_id < 0)
185        BX_PANIC(("open of %s (%s) failed\n",
186                  "com1", bx_options.com[0].Odev->getptr ()));
187 +#if 0
188      BX_DEBUG(("tty_id: %d",tty_id));
189      tcgetattr(tty_id, &term_orig);
190      bcopy((caddr_t) &term_orig, (caddr_t) &term_new, sizeof(struct termios));
191 @@ -145,6 +148,7 @@ bx_serial_c::init(void)
192      term_new.c_cc[VTIME] = 0;
193      //term_new.c_iflag |= IXOFF;
194      tcsetattr(tty_id, TCSAFLUSH, &term_new);
195 +#endif
196    }
197  #endif   /* def SERIAL_ENABLE */
198    // nothing for now
199 @@ -955,7 +968,7 @@ bx_serial_c::rx_timer(void)
200      }
201      if (rdy) {
202        chbuf = data;
203 -#elif defined(SERIAL_ENABLE)
204 +#elif 0 && defined(SERIAL_ENABLE)
205      if ((tty_id >= 0) && (select(tty_id + 1, &fds, NULL, NULL, &tval) == 1)) {
206        (void) read(tty_id, &chbuf, 1);
207        BX_DEBUG(("read: '%c'",chbuf));
208
209 diff -urp bochs-2.1.1.orig/bochs.h bochs-2.1.1/bochs.h
210 --- bochs-2.1.1.orig/bochs.h    2004-02-11 14:28:03.000000000 -0800
211 +++ bochs-2.1.1/bochs.h 2004-09-20 17:02:01.000000000 -0700
212 @@ -757,4 +757,6 @@ int bx_init_hardware ();
213  
214  #endif
215  
216 +extern int jitter;
217 +
218  #endif  /* BX_BOCHS_H */
219 diff -urp bochs-2.1.1.orig/iodev/pit82c54.cc bochs-2.1.1/iodev/pit82c54.cc
220 --- bochs-2.1.1.orig/iodev/pit82c54.cc  2004-02-11 14:28:53.000000000 -0800
221 +++ bochs-2.1.1/iodev/pit82c54.cc       2004-09-20 17:18:24.000000000 -0700
222 @@ -28,6 +28,7 @@
223  
224  #include "bochs.h"
225  #include "pit82c54.h"
226 +#include <stdlib.h>
227  #define LOG_THIS this->
228  
229  
230 @@ -356,7 +357,13 @@ pit_82C54::clock(Bit8u cnum) {
231        case 2:
232         if(thisctr.count_written) {
233           if(thisctr.triggerGATE || thisctr.first_pass) {
234 -           set_count(thisctr, thisctr.inlatch);
235 +            unsigned n = thisctr.inlatch;
236 +            if (jitter) {
237 +                n *= (double) rand() / RAND_MAX;
238 +                if (n < 5)
239 +                    n = 5;
240 +            }
241 +           set_count(thisctr, n);
242             thisctr.next_change_time=(thisctr.count_binary-1) & 0xFFFF;
243             thisctr.null_count=0;
244             if(thisctr.inlatch==1) {
245 diff -urp bochs-2.1.1.orig/iodev/pit_wrap.cc bochs-2.1.1/iodev/pit_wrap.cc
246 diff -urp bochs-2.1.1.orig/iodev/serial.cc bochs-2.1.1/iodev/serial.cc
247 diff -urp bochs-2.1.1.orig/main.cc bochs-2.1.1/main.cc
248 --- bochs-2.1.1.orig/main.cc    2004-02-11 14:28:41.000000000 -0800
249 +++ bochs-2.1.1/main.cc 2004-09-20 17:15:39.000000000 -0700
250 @@ -58,6 +58,7 @@
251  
252  
253  int bochsrc_include_count = 0;
254 +int jitter = 0;
255  
256  extern "C" {
257  #include <signal.h>
258 @@ -2022,6 +2024,13 @@ bx_init_main (int argc, char *argv[])
259      else if (!strcmp ("-q", argv[arg])) {
260        SIM->get_param_enum(BXP_BOCHS_START)->set (BX_QUICK_START);
261      }
262 +    else if (!strcmp ("-j", argv[arg])) {
263 +      if (++arg >= argc) BX_PANIC(("-j must be followed by a number"));
264 +      else {
265 +        jitter = 1;
266 +        srand (atoi (argv[arg]));
267 +      }
268 +    }
269      else if (!strcmp ("-f", argv[arg])) {
270        if (++arg >= argc) BX_PANIC(("-f must be followed by a filename"));
271        else bochsrc_filename = argv[arg];