From a8586578bb7a9dbbbca7b39a9f92058e3f551f9d Mon Sep 17 00:00:00 2001 From: John Ousterhout Date: Thu, 17 Dec 2015 11:33:52 -0800 Subject: [PATCH] Patches to make Bochs 2.6.2 work with Pintos (patches provided by David Mazieres). --- src/misc/bochs-2.6.2-banner-stderr.patch | 32 +++++ src/misc/bochs-2.6.2-block-device-check.patch | 12 ++ src/misc/bochs-2.6.2-build.sh | 33 +++++ src/misc/bochs-2.6.2-jitter-plus-segv.patch | 135 ++++++++++++++++++ src/misc/bochs-2.6.2-xrandr-pkgconfig.patch | 14 ++ 5 files changed, 226 insertions(+) create mode 100644 src/misc/bochs-2.6.2-banner-stderr.patch create mode 100644 src/misc/bochs-2.6.2-block-device-check.patch create mode 100755 src/misc/bochs-2.6.2-build.sh create mode 100644 src/misc/bochs-2.6.2-jitter-plus-segv.patch create mode 100644 src/misc/bochs-2.6.2-xrandr-pkgconfig.patch diff --git a/src/misc/bochs-2.6.2-banner-stderr.patch b/src/misc/bochs-2.6.2-banner-stderr.patch new file mode 100644 index 0000000..8587142 --- /dev/null +++ b/src/misc/bochs-2.6.2-banner-stderr.patch @@ -0,0 +1,32 @@ +diff -Naur bochs-2.6.2/main.cc bochs-2.6.2.new/main.cc +--- bochs-2.6.2/main.cc 2014-01-06 23:29:42.000000001 -0800 ++++ bochs-2.6.2.new/main.cc 2014-01-06 22:33:42.000000001 -0800 +@@ -105,23 +105,23 @@ + + void bx_print_header() + { +- printf("%s\n", divider); ++ fprintf(stderr, "%s\n", divider); + char buffer[128]; + sprintf (buffer, "Bochs x86 Emulator %s\n", VER_STRING); +- bx_center_print(stdout, buffer, 72); ++ bx_center_print(stderr, buffer, 72); + if (REL_STRING[0]) { + sprintf(buffer, "%s\n", REL_STRING); +- bx_center_print(stdout, buffer, 72); ++ bx_center_print(stderr, buffer, 72); + #ifdef __DATE__ + #ifdef __TIME__ + sprintf(buffer, "Compiled on %s at %s\n", __DATE__, __TIME__); + #else + sprintf(buffer, "Compiled on %s\n", __DATE__); + #endif +- bx_center_print(stdout, buffer, 72); ++ bx_center_print(stderr, buffer, 72); + #endif + } +- printf("%s\n", divider); ++ fprintf(stderr, "%s\n", divider); + } + + #if BX_WITH_CARBON diff --git a/src/misc/bochs-2.6.2-block-device-check.patch b/src/misc/bochs-2.6.2-block-device-check.patch new file mode 100644 index 0000000..a0b930c --- /dev/null +++ b/src/misc/bochs-2.6.2-block-device-check.patch @@ -0,0 +1,12 @@ +diff -Naur bochs-2.6.2/iodev/hdimage/hdimage.cc bochs-2.6.2.new/iodev/hdimage/hdimage.cc +--- bochs-2.6.2/iodev/hdimage/hdimage.cc 2013-03-08 10:25:32.000000001 -0800 ++++ bochs-2.6.2.new/iodev/hdimage/hdimage.cc 2014-01-10 06:54:24.000000001 -0800 +@@ -200,7 +200,7 @@ + return -1; + } + #ifdef linux +- if (stat_buf.st_rdev) { // Is this a special device file (e.g. /dev/sde) ? ++ if (S_ISBLK(stat_buf.st_mode)) { // Is this a special device file (e.g. /dev/sde) ? + ioctl(fd, BLKGETSIZE64, fsize); // yes it's! + } + else diff --git a/src/misc/bochs-2.6.2-build.sh b/src/misc/bochs-2.6.2-build.sh new file mode 100755 index 0000000..7dc85fe --- /dev/null +++ b/src/misc/bochs-2.6.2-build.sh @@ -0,0 +1,33 @@ +#! /bin/sh -e + +if test -z "$SRCDIR" || test -z "$PINTOSDIR" || test -z "$DSTDIR"; then + echo "usage: env SRCDIR= PINTOSDIR= DSTDIR= sh $0" + echo " where contains bochs-2.6.2.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.6.2 +tar xzf $SRCDIR/bochs-2.6.2.tar.gz +cd bochs-2.6.2 +cat $PINTOSDIR/src/misc/bochs-2.6.2-jitter-plus-segv.patch | patch -p1 +cat $PINTOSDIR/src/misc/bochs-2.6.2-xrandr-pkgconfig.patch | patch -p1 +cat $PINTOSDIR/src/misc/bochs-2.6.2-banner-stderr.patch | patch -p1 +cat $PINTOSDIR/src/misc/bochs-2.6.2-block-device-check.patch | patch -p1 +CFGOPTS="--with-x --with-x11 --with-term --with-nogui --prefix=$DSTDIR" +mkdir plain && + cd plain && + ../configure $CFGOPTS --enable-gdb-stub && + make && + make install && + cd .. +mkdir with-dbg && + cd with-dbg && + ../configure --enable-debugger --disable-debugger-gui $CFGOPTS && + make && + cp bochs $DSTDIR/bin/bochs-dbg && + cd .. diff --git a/src/misc/bochs-2.6.2-jitter-plus-segv.patch b/src/misc/bochs-2.6.2-jitter-plus-segv.patch new file mode 100644 index 0000000..b6ad247 --- /dev/null +++ b/src/misc/bochs-2.6.2-jitter-plus-segv.patch @@ -0,0 +1,135 @@ +diff --git a/bochs.h b/bochs.h +index c2d6c6b..d37cf12 100644 +--- a/bochs.h ++++ b/bochs.h +@@ -392,6 +392,7 @@ BOCHSAPI extern logfunc_t *genlog; + void bx_gdbstub_init(void); + void bx_gdbstub_break(void); + int bx_gdbstub_check(unsigned int eip); ++void bx_gdbstub_exception(unsigned int nr); + #define GDBSTUB_STOP_NO_REASON (0xac0) + + #if BX_SUPPORT_SMP +@@ -589,4 +590,6 @@ BX_CPP_INLINE Bit64u bx_bswap64(Bit64u val64) + #define CopyHostQWordLittleEndian(hostAddrDst, hostAddrSrc) \ + (* (Bit64u *)(hostAddrDst)) = (* (Bit64u *)(hostAddrSrc)); + ++extern int jitter; ++ + #endif /* BX_BOCHS_H */ +diff --git a/cpu/exception.cc b/cpu/exception.cc +index db38d1b..b2c5f29 100644 +--- a/cpu/exception.cc ++++ b/cpu/exception.cc +@@ -914,6 +914,10 @@ void BX_CPU_C::exception(unsigned vector, Bit16u error_code) + + BX_CPU_THIS_PTR last_exception_type = exception_type; + ++#if BX_GDBSTUB ++ bx_gdbstub_exception(vector); ++#endif ++ + if (real_mode()) { + push_error = 0; // not INT, no error code pushed + error_code = 0; +diff --git a/gdbstub.cc b/gdbstub.cc +index da600b4..577938d 100644 +--- a/gdbstub.cc ++++ b/gdbstub.cc +@@ -49,6 +49,7 @@ static int last_stop_reason = GDBSTUB_STOP_NO_REASON; + #define GDBSTUB_EXECUTION_BREAKPOINT (0xac1) + #define GDBSTUB_TRACE (0xac2) + #define GDBSTUB_USER_BREAK (0xac3) ++#define GDBSTUB_EXCEPTION_0E (0xac4) + + static bx_list_c *gdbstub_list; + static int listen_socket_fd; +@@ -317,6 +318,12 @@ int bx_gdbstub_check(unsigned int eip) + return GDBSTUB_STOP_NO_REASON; + } + ++void bx_gdbstub_exception(unsigned int nr) ++{ ++ if (nr == 0x0e) ++ last_stop_reason = GDBSTUB_EXCEPTION_0E; ++} ++ + static int remove_breakpoint(unsigned addr, int len) + { + if (len != 1) +@@ -487,6 +494,10 @@ static void debug_loop(void) + { + write_signal(&buf[1], SIGTRAP); + } ++ else if (last_stop_reason == GDBSTUB_EXCEPTION_0E) ++ { ++ write_signal(&buf[1], SIGSEGV); ++ } + else + { + write_signal(&buf[1], 0); +@@ -514,6 +525,10 @@ static void debug_loop(void) + { + write_signal(&buf[1], SIGTRAP); + } ++ else if (last_stop_reason == GDBSTUB_EXCEPTION_0E) ++ { ++ write_signal(&buf[1], SIGSEGV); ++ } + else + { + write_signal(&buf[1], SIGTRAP); +diff --git a/iodev/pit82c54.cc b/iodev/pit82c54.cc +index 09dcd8e..7e335d4 100644 +--- a/iodev/pit82c54.cc ++++ b/iodev/pit82c54.cc +@@ -49,6 +49,7 @@ + + #include "iodev.h" + #include "pit82c54.h" ++#include + #define LOG_THIS this-> + + +@@ -410,7 +411,14 @@ void BX_CPP_AttrRegparmN(1) pit_82C54::clock(Bit8u cnum) + case 2: + if (thisctr.count_written) { + if (thisctr.triggerGATE || thisctr.first_pass) { +- set_count(thisctr, thisctr.inlatch); ++ //set_count(thisctr, thisctr.inlatch); ++ unsigned n = thisctr.inlatch; ++ if (jitter && n > 5) { ++ 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 --git a/main.cc b/main.cc +index 0f11e31..008f05f 100644 +--- a/main.cc ++++ b/main.cc +@@ -101,6 +101,7 @@ BOCHSAPI BX_CPU_C bx_cpu; + BOCHSAPI BX_MEM_C bx_mem; + + char *bochsrc_filename = NULL; ++int jitter = 0; + + void bx_print_header() + { +@@ -639,6 +640,13 @@ int bx_init_main(int argc, char *argv[]) + else SIM->get_param_string(BXPN_DEBUGGER_LOG_FILENAME)->set(argv[arg]); + } + #endif ++ 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.6.2-xrandr-pkgconfig.patch b/src/misc/bochs-2.6.2-xrandr-pkgconfig.patch new file mode 100644 index 0000000..b92f814 --- /dev/null +++ b/src/misc/bochs-2.6.2-xrandr-pkgconfig.patch @@ -0,0 +1,14 @@ +diff -Naur bochs-2.6.2.orig/configure bochs-2.6.2/configure +--- bochs-2.6.2.orig/configure 2014-01-06 16:39:03.000000000 -0800 ++++ bochs-2.6.2/configure 2014-01-06 16:39:23.000000000 -0800 +@@ -24202,8 +24202,8 @@ + fi + + if test "$PKGCONFIG" != not_found; then +- X_CFLAGS="`pkg-config --cflags x11`" +- X_LIBS="`pkg-config --libs x11` $XPM_LIB -lXrandr" ++ X_CFLAGS="`pkg-config --cflags x11 xrandr`" ++ X_LIBS="`pkg-config --libs x11 xrandr` $XPM_LIB" + else + X_LIBS="$X_LIBS -lX11 $XPM_LIB -lXrandr" + fi -- 2.30.2