From 76d6839e6f65eb75c4c1b942cc1f348d3443681f Mon Sep 17 00:00:00 2001 From: Ben Pfaff Date: Mon, 3 Apr 2006 21:27:09 +0000 Subject: [PATCH] First stab at Bochs 2.2.6 upgrade (not yet tested). --- src/misc/bochs-2.1.1.patch | 271 -------------------------- src/misc/bochs-2.2.6-big-endian.patch | 63 ++++++ src/misc/bochs-2.2.6-build.sh | 29 +++ src/misc/bochs-2.2.6-jitter.patch | 51 +++++ src/misc/bochs-2.2.6.README | 23 +++ src/utils/pintos | 19 +- 6 files changed, 173 insertions(+), 283 deletions(-) delete mode 100644 src/misc/bochs-2.1.1.patch create mode 100644 src/misc/bochs-2.2.6-big-endian.patch create mode 100755 src/misc/bochs-2.2.6-build.sh create mode 100644 src/misc/bochs-2.2.6-jitter.patch create mode 100644 src/misc/bochs-2.2.6.README diff --git a/src/misc/bochs-2.1.1.patch b/src/misc/bochs-2.1.1.patch deleted file mode 100644 index 3d542f6..0000000 --- a/src/misc/bochs-2.1.1.patch +++ /dev/null @@ -1,271 +0,0 @@ -The first two patches are needed for Bochs to properly compile and run -under Solaris on Sparc. If you're not compiling on Solaris, don't -apply them. The first should probably be handled by Autoconf; I'm not -sure why it isn't. The second is needed to make GCC accept X.h's -frequent use of "extern foo(...)", because use of an implicit int -return type is forbidden in C++. - -The third patch makes the gdb stubs work on Solaris/Sparc, by doing -proper byteswapping. It should be harmless elsewhere. - -The fourth patch enables the serial device under Solaris and disables -tty setup at the same time. Tty setup is a pain when you want to -connect a serial port to stdout and it doesn't work under Solaris -anyway. This patch is useful everywhere with `pintos', but may not be -wanted elsewhere. - -The remaining patches add the `jitter' feature described in the -project documentation, in which timer interrupts are delivered at -random intervals. - -To apply all the patches, cd into the Bochs directory, then type - patch -p1 < $PINTOSROOT/src/misc/bochs-2.1.1.patch -You will have to supply the proper path to the patch, of course. You -can provide the --dry-run option to patch if you want to test whether -the patch would apply cleanly before actually patching. - -To apply a subset of the patches, use a text editor to delete the -unwanted patches, then follow the above instructions. - -Here's a ./configure invocation for Bochs that works optimally with -the `pintos' utility: - ./configure --with-x --with-x11 --with-term --with-nogui -If you want the gdb stub, add --enable-gdb-stub -If you want the internal debugger, add --enable-debugger - -Here are the commands used to build and install all the versions of -Bochs we make available on the elaines: - -cd /tmp && tar xzf ~/bochs-2.1.1.tar.gz && cd bochs-2.1.1 -patch -p1 < $PINTOSROOT/src/misc/bochs-2.1.1.patch -PREFIX="/usr/class/cs140/`uname -m`" -CFGOPTS="--with-x --with-x11 --with-term --with-nogui --prefix=$PREFIX" -(mkdir plain && - cd plain && - ../configure $CFGOPTS && - make && - make install) -(mkdir with-gdb && - cd with-gdb && - ../configure --enable-gdb-stub $CFGOPTS && - make && - cp bochs $PREFIX/bin/bochs-gdb) -(mkdir with-dbg && - cd with-dbg && - ../configure --enable-debugger $CFGOPTS && - make && - cp bochs $PREFIX/bin/bochs-dbg) - -diff -urp orig/bochs-2.1.1/Makefile.in bochs-2.1.1/Makefile.in ---- orig/bochs-2.1.1/Makefile.in 2004-02-11 14:28:02.000000000 -0800 -+++ bochs-2.1.1/Makefile.in 2004-09-13 15:05:26.281550000 -0700 -@@ -92,7 +92,7 @@ CXX = @CXX@ - CFLAGS = @CFLAGS@ @GUI_CFLAGS@ $(MCH_CFLAGS) $(FLA_FLAGS) @DEFINE_PLUGIN_PATH@ -DBX_SHARE_PATH='"$(sharedir)"' - CXXFLAGS = @CXXFLAGS@ @GUI_CXXFLAGS@ $(MCH_CFLAGS) $(FLA_FLAGS) @DEFINE_PLUGIN_PATH@ -DBX_SHARE_PATH='"$(sharedir)"' - --LDFLAGS = @LDFLAGS@ -+LDFLAGS = @LDFLAGS@ -lsocket - LIBS = @LIBS@ - # To compile with readline: - # linux needs just -lreadline - -diff -urp orig/bochs-2.1.1/gui/Makefile.in bochs-2.1.1/gui/Makefile.in ---- orig/bochs-2.1.1/gui/Makefile.in 2003-11-28 07:07:28.000000000 -0800 -+++ bochs-2.1.1/gui/Makefile.in 2004-09-13 15:05:09.402039000 -0700 -@@ -44,7 +44,7 @@ SHELL = /bin/sh - @SET_MAKE@ - - CXX = @CXX@ --CXXFLAGS = $(BX_INCDIRS) @CXXFLAGS@ @GUI_CXXFLAGS@ -+CXXFLAGS = $(BX_INCDIRS) @CXXFLAGS@ @GUI_CXXFLAGS@ -fms-extensions - LOCAL_CXXFLAGS = - LDFLAGS = @LDFLAGS@ - LIBS = @LIBS@ - - -diff -urp orig/bochs-2.1.1/gdbstub.cc bochs-2.1.1/gdbstub.cc ---- orig/bochs-2.1.1/gdbstub.cc 2004-02-11 14:28:41.000000000 -0800 -+++ bochs-2.1.1/gdbstub.cc 2004-09-13 16:41:59.652988000 -0700 -@@ -474,11 +475,13 @@ static void debug_loop(void) - case 'P': - { - int reg; -- int value; -+ Bit8u vbits[4]; -+ Bit32u value; - char* ebuf; - - reg = strtoul(&buffer[1], &ebuf, 16); -- value = ntohl(strtoul(ebuf + 1, &ebuf, 16)); -+ hex2mem(ebuf + 1, vbits, sizeof value); -+ ReadHostDWordFromLittleEndian(vbits, value); - - BX_INFO (("reg %d set to %x", reg, value)); - -@@ -527,35 +530,36 @@ static void debug_loop(void) - } - - case 'g': -- registers[0] = EAX; -- registers[1] = ECX; -- registers[2] = EDX; -- registers[3] = EBX; -- registers[4] = ESP; -- registers[5] = EBP; -- registers[6] = ESI; -- registers[7] = EDI; -+ WriteHostDWordToLittleEndian(registers + 0, EAX); -+ WriteHostDWordToLittleEndian(registers + 1, ECX); -+ WriteHostDWordToLittleEndian(registers + 2, EDX); -+ WriteHostDWordToLittleEndian(registers + 3, EBX); -+ WriteHostDWordToLittleEndian(registers + 4, ESP); -+ WriteHostDWordToLittleEndian(registers + 5, EBP); -+ WriteHostDWordToLittleEndian(registers + 6, ESI); -+ WriteHostDWordToLittleEndian(registers + 7, EDI); - if (last_stop_reason == GDBSTUB_EXECUTION_BREAKPOINT) - { -- registers[8] = EIP + 1; -+ WriteHostDWordToLittleEndian(registers + 8, EIP + 1); - } - else - { -- registers[8] = EIP; -+ WriteHostDWordToLittleEndian(registers + 8, EIP); - } -- registers[9] = BX_CPU_THIS_PTR read_eflags(); -- registers[10] = -- BX_CPU_THIS_PTR sregs[BX_SEG_REG_CS].selector.value; -- registers[11] = -- BX_CPU_THIS_PTR sregs[BX_SEG_REG_SS].selector.value; -- registers[12] = -- BX_CPU_THIS_PTR sregs[BX_SEG_REG_DS].selector.value; -- registers[13] = -- BX_CPU_THIS_PTR sregs[BX_SEG_REG_ES].selector.value; -- registers[14] = -- BX_CPU_THIS_PTR sregs[BX_SEG_REG_FS].selector.value; -- registers[15] = -- BX_CPU_THIS_PTR sregs[BX_SEG_REG_GS].selector.value; -+ WriteHostDWordToLittleEndian(registers + 9, -+ BX_CPU_THIS_PTR read_eflags()); -+ WriteHostDWordToLittleEndian(registers + 10, -+ BX_CPU_THIS_PTR sregs[BX_SEG_REG_CS].selector.value); -+ WriteHostDWordToLittleEndian(registers + 11, -+ BX_CPU_THIS_PTR sregs[BX_SEG_REG_SS].selector.value); -+ WriteHostDWordToLittleEndian(registers + 12, -+ BX_CPU_THIS_PTR sregs[BX_SEG_REG_DS].selector.value); -+ WriteHostDWordToLittleEndian(registers + 13, -+ BX_CPU_THIS_PTR sregs[BX_SEG_REG_ES].selector.value); -+ WriteHostDWordToLittleEndian(registers + 14, -+ BX_CPU_THIS_PTR sregs[BX_SEG_REG_FS].selector.value); -+ WriteHostDWordToLittleEndian(registers + 15, -+ BX_CPU_THIS_PTR sregs[BX_SEG_REG_GS].selector.value); - mem2hex((char *)registers, obuf, NUMREGSBYTES); - put_reply(obuf); - break; - -diff -urp bochs-2.1.1-upstream/iodev/serial.cc bochs-2.1.1/iodev/serial.cc ---- tmp/bochs-2.1.1/iodev/serial.cc 2004-02-11 14:28:54.000000000 -0800 -+++ bochs-2.1.1/iodev/serial.cc 2005-06-01 20:26:01.000000000 -0700 -@@ -53,7 +53,7 @@ - #endif - #endif - --#if defined(__NetBSD__) || defined(__FreeBSD__) || defined(__OpenBSD__) || defined(__linux__) || defined(__GNU__) || defined(__APPLE__) -+#if defined(__NetBSD__) || defined(__FreeBSD__) || defined(__OpenBSD__) || defined(__linux__) || defined(__GNU__) || defined(__APPLE__) || defined(__sun__) - #define SERIAL_ENABLE - #endif - -@@ -118,10 +118,11 @@ bx_serial_c::init(void) - - #ifdef SERIAL_ENABLE - if (strlen(bx_options.com[0].Odev->getptr ()) > 0) { -- tty_id = open(bx_options.com[0].Odev->getptr (), O_RDWR|O_NONBLOCK,600); -+ tty_id = open(bx_options.com[0].Odev->getptr (), O_RDWR,600); - if (tty_id < 0) - BX_PANIC(("open of %s (%s) failed\n", - "com1", bx_options.com[0].Odev->getptr ())); -+#if 0 - BX_DEBUG(("tty_id: %d",tty_id)); - tcgetattr(tty_id, &term_orig); - bcopy((caddr_t) &term_orig, (caddr_t) &term_new, sizeof(struct termios)); -@@ -145,6 +148,7 @@ bx_serial_c::init(void) - term_new.c_cc[VTIME] = 0; - //term_new.c_iflag |= IXOFF; - tcsetattr(tty_id, TCSAFLUSH, &term_new); -+#endif - } - #endif /* def SERIAL_ENABLE */ - // nothing for now -@@ -955,7 +968,7 @@ bx_serial_c::rx_timer(void) - } - if (rdy) { - chbuf = data; --#elif defined(SERIAL_ENABLE) -+#elif 0 && defined(SERIAL_ENABLE) - if ((tty_id >= 0) && (select(tty_id + 1, &fds, NULL, NULL, &tval) == 1)) { - (void) read(tty_id, &chbuf, 1); - BX_DEBUG(("read: '%c'",chbuf)); - -diff -urp bochs-2.1.1.orig/bochs.h bochs-2.1.1/bochs.h ---- bochs-2.1.1.orig/bochs.h 2004-02-11 14:28:03.000000000 -0800 -+++ bochs-2.1.1/bochs.h 2004-09-20 17:02:01.000000000 -0700 -@@ -757,4 +757,6 @@ int bx_init_hardware (); - - #endif - -+extern int jitter; -+ - #endif /* BX_BOCHS_H */ -diff -urp bochs-2.1.1.orig/iodev/pit82c54.cc bochs-2.1.1/iodev/pit82c54.cc ---- bochs-2.1.1.orig/iodev/pit82c54.cc 2004-02-11 14:28:53.000000000 -0800 -+++ bochs-2.1.1/iodev/pit82c54.cc 2004-09-20 17:18:24.000000000 -0700 -@@ -28,6 +28,7 @@ - - #include "bochs.h" - #include "pit82c54.h" -+#include - #define LOG_THIS this-> - - -@@ -356,7 +357,13 @@ pit_82C54::clock(Bit8u cnum) { - case 2: - if(thisctr.count_written) { - if(thisctr.triggerGATE || thisctr.first_pass) { -- set_count(thisctr, thisctr.inlatch); -+ unsigned n = thisctr.inlatch; -+ if (jitter) { -+ 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 -urp bochs-2.1.1.orig/iodev/pit_wrap.cc bochs-2.1.1/iodev/pit_wrap.cc -diff -urp bochs-2.1.1.orig/iodev/serial.cc bochs-2.1.1/iodev/serial.cc -diff -urp bochs-2.1.1.orig/main.cc bochs-2.1.1/main.cc ---- bochs-2.1.1.orig/main.cc 2004-02-11 14:28:41.000000000 -0800 -+++ bochs-2.1.1/main.cc 2004-09-20 17:15:39.000000000 -0700 -@@ -58,6 +58,7 @@ - - - int bochsrc_include_count = 0; -+int jitter = 0; - - extern "C" { - #include -@@ -2022,6 +2024,13 @@ bx_init_main (int argc, char *argv[]) - else if (!strcmp ("-q", argv[arg])) { - SIM->get_param_enum(BXP_BOCHS_START)->set (BX_QUICK_START); - } -+ 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]; diff --git a/src/misc/bochs-2.2.6-big-endian.patch b/src/misc/bochs-2.2.6-big-endian.patch new file mode 100644 index 0000000..be95dae --- /dev/null +++ b/src/misc/bochs-2.2.6-big-endian.patch @@ -0,0 +1,63 @@ +diff -urp bochs-2.2.6/gdbstub.cc bochs-2.2.6.orig/gdbstub.cc +--- bochs-2.2.6/gdbstub.cc 2006-04-03 13:47:39.000000000 -0700 ++++ bochs-2.2.6.orig/gdbstub.cc 2006-01-17 09:15:29.000000000 -0800 +@@ -672,36 +672,35 @@ static void debug_loop(void) + + case 'g': + #if !BX_SUPPORT_X86_64 +- WriteHostDWordToLittleEndian(registers + 0, EAX); +- WriteHostDWordToLittleEndian(registers + 1, ECX); +- WriteHostDWordToLittleEndian(registers + 2, EDX); +- WriteHostDWordToLittleEndian(registers + 3, EBX); +- WriteHostDWordToLittleEndian(registers + 4, ESP); +- WriteHostDWordToLittleEndian(registers + 5, EBP); +- WriteHostDWordToLittleEndian(registers + 6, ESI); +- WriteHostDWordToLittleEndian(registers + 7, EDI); ++ registers[0] = EAX; ++ registers[1] = ECX; ++ registers[2] = EDX; ++ registers[3] = EBX; ++ registers[4] = ESP; ++ registers[5] = EBP; ++ registers[6] = ESI; ++ registers[7] = EDI; + if (last_stop_reason == GDBSTUB_EXECUTION_BREAKPOINT) + { +- WriteHostDWordToLittleEndian(registers + 8, EIP + 1); ++ registers[8] = EIP + 1; + } + else + { +- WriteHostDWordToLittleEndian(registers + 8, EIP); ++ registers[8] = EIP; + } +- WriteHostDWordToLittleEndian(registers + 9, +- BX_CPU_THIS_PTR read_eflags()); +- WriteHostDWordToLittleEndian(registers + 10, +- BX_CPU_THIS_PTR sregs[BX_SEG_REG_CS].selector.value); +- WriteHostDWordToLittleEndian(registers + 11, +- BX_CPU_THIS_PTR sregs[BX_SEG_REG_SS].selector.value); +- WriteHostDWordToLittleEndian(registers + 12, +- BX_CPU_THIS_PTR sregs[BX_SEG_REG_DS].selector.value); +- WriteHostDWordToLittleEndian(registers + 13, +- BX_CPU_THIS_PTR sregs[BX_SEG_REG_ES].selector.value); +- WriteHostDWordToLittleEndian(registers + 14, +- BX_CPU_THIS_PTR sregs[BX_SEG_REG_FS].selector.value); +- WriteHostDWordToLittleEndian(registers + 15, +- BX_CPU_THIS_PTR sregs[BX_SEG_REG_GS].selector.value); ++ registers[9] = BX_CPU_THIS_PTR read_eflags(); ++ registers[10] = ++ BX_CPU_THIS_PTR sregs[BX_SEG_REG_CS].selector.value; ++ registers[11] = ++ BX_CPU_THIS_PTR sregs[BX_SEG_REG_SS].selector.value; ++ registers[12] = ++ BX_CPU_THIS_PTR sregs[BX_SEG_REG_DS].selector.value; ++ registers[13] = ++ BX_CPU_THIS_PTR sregs[BX_SEG_REG_ES].selector.value; ++ registers[14] = ++ BX_CPU_THIS_PTR sregs[BX_SEG_REG_FS].selector.value; ++ registers[15] = ++ BX_CPU_THIS_PTR sregs[BX_SEG_REG_GS].selector.value; + mem2hex((char *)registers, obuf, NUMREGSBYTES); + #else + #define PUTREG(buf, val, len) do { \ diff --git a/src/misc/bochs-2.2.6-build.sh b/src/misc/bochs-2.2.6-build.sh new file mode 100755 index 0000000..bdf38b0 --- /dev/null +++ b/src/misc/bochs-2.2.6-build.sh @@ -0,0 +1,29 @@ +#! /bin/sh -e + +if test -z "$SRCDIR" || test -z "$PINTOSROOT" || test -z "$DSTDIR"; then + echo "usage: env SRCDIR= PINTOSDIR= DSTDIR= $0" + echo " where contains bochs-2.2.6.tar.gz" + echo " and is the root of the pintos source tree" + echo " and is the installation prefix (e.g. /usr/local)" + exit 1 +fi + +cd /tmp +mkdir $$ +cd $$ +mkdir bochs-2.2.6 +tar xzf $SRCDIR/bochs-2.2.6.tar.gz +cd bochs-2.2.6 +patch -p1 < $PINTOSDIR/src/misc/bochs-2.2.6-*.patch + +CFGOPTS="--with-x --with-x11 --with-term --with-nogui --prefix=$DSTDIR" +(mkdir plain && + cd plain && + ../configure $CFGOPTS --enable-gdb-stub && + make && + make install) +(mkdir with-dbg && + cd with-dbg && + ../configure --enable-debugger $CFGOPTS && + make && + cp bochs $DSTDIR/bin/bochs-dbg) diff --git a/src/misc/bochs-2.2.6-jitter.patch b/src/misc/bochs-2.2.6-jitter.patch new file mode 100644 index 0000000..9bba0eb --- /dev/null +++ b/src/misc/bochs-2.2.6-jitter.patch @@ -0,0 +1,51 @@ +diff -urp bochs-2.2.6/iodev/pit82c54.cc bochs-2.2.6.orig/iodev/pit82c54.cc +--- bochs-2.2.6/iodev/pit82c54.cc 2006-04-03 14:00:27.000000000 -0700 ++++ bochs-2.2.6.orig/iodev/pit82c54.cc 2006-01-08 12:39:08.000000000 -0800 +@@ -28,7 +28,6 @@ + + #include "iodev.h" + #include "pit82c54.h" +-#include + #define LOG_THIS this-> + + +@@ -360,13 +359,7 @@ pit_82C54::clock(Bit8u cnum) { + case 2: + if(thisctr.count_written) { + if(thisctr.triggerGATE || thisctr.first_pass) { +- unsigned n = thisctr.inlatch; +- if (jitter) { +- n *= (double) rand() / RAND_MAX; +- if (n < 5) +- n = 5; +- } +- set_count(thisctr, n); ++ set_count(thisctr, thisctr.inlatch); + thisctr.next_change_time=(thisctr.count_binary-1) & 0xFFFF; + thisctr.null_count=0; + if(thisctr.inlatch==1) { +diff -urp bochs-2.2.6/main.cc bochs-2.2.6.orig/main.cc +--- bochs-2.2.6/main.cc 2006-04-03 14:00:54.000000000 -0700 ++++ bochs-2.2.6.orig/main.cc 2006-01-22 04:31:15.000000000 -0800 +@@ -105,7 +105,6 @@ BOCHSAPI BX_CPU_C bx_cpu; + #endif + + char *bochsrc_filename = NULL; +-int jitter = 0; + + void bx_print_header () + { +@@ -460,13 +459,6 @@ int bx_init_main (int argc, char *argv[] + else if (!strcmp ("-q", argv[arg])) { + SIM->get_param_enum(BXP_BOCHS_START)->set (BX_QUICK_START); + } +- 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]; diff --git a/src/misc/bochs-2.2.6.README b/src/misc/bochs-2.2.6.README new file mode 100644 index 0000000..cd5bc96 --- /dev/null +++ b/src/misc/bochs-2.2.6.README @@ -0,0 +1,23 @@ +This version of Pintos is designed for use with Bochs 2.2.6. A few +patches for this version of Bochs are included: + + bochs-2.2.6-big-endian.patch + + Makes the gdb stubs work on big-endian systems such as + Solaris/Sparc, by doing proper byteswapping. It should be + harmless elsewhere. + + bochs-2.2.6-jitter.patch + + Adds the `jitter' feature described in the project documentation, + in which timer interrupts are delivered at random intervals. + +To apply all the patches, cd into the Bochs directory, then type + patch -p1 < $PINTOSDIR/src/misc/bochs-2.2.6-big-endian.patch + patch -p1 < $PINTOSDIR/src/misc/bochs-2.2.6-jitter.patch +You will have to supply the proper $PINTOSDIR, of course. You can use +patch's --dry-run option if you want to test whether the patches would +apply cleanly before trying to apply them. + +Sample commands to build and install Bochs for Pintos are supplied in +bochs-2.2.6-build.sh. diff --git a/src/utils/pintos b/src/utils/pintos index 83954bb..eee6384 100755 --- a/src/utils/pintos +++ b/src/utils/pintos @@ -364,26 +364,20 @@ sub run_vm { # Runs Bochs. sub run_bochs { # Select Bochs binary based on the chosen debugger. - my ($bin); - if ($debug eq 'none') { - $bin = 'bochs'; - } elsif ($debug eq 'monitor') { - $bin = 'bochs-dbg'; - } elsif ($debug eq 'gdb') { - $bin = 'bochs-gdb'; - } + my ($bin) = $debug eq 'monitor' ? 'bochs-dbg' : 'bochs'; # Write bochsrc.txt configuration file. open (BOCHSRC, ">", "bochsrc.txt") or die "bochsrc.txt: create: $!\n"; print BOCHSRC <