Looking inside the Bochs hardware emulator

138

Author: JT Smith

By Russell C. Pavlicek

Most people in the Open Source community are aware of VMware, a commercial
product which allows you to run a guest operating system on your Linux or
Windows system. Some people are aware of Plex86, an Open Source project
which is working to accomplish a similar goal. But not that many people
seem cognizant of an older project: Bochs.

Unlike VMware, Bochs (pronounced “box”) does Pentium machine hardware emulation. This makes performance under Bochs much slower than that
of VMware. But because Bochs emulates the hardware, it can be used on other
hardware architectures like Alpha and SPARC. So you can run Windows 95 on
your SPARC box, or FreeDOS on your Alpha. For example, one of the
accompanying screen shots is an x86 Linux booting on my SPARCstation 10.
My SPARC box is too slow to make things really usable, but a faster
CPU could make it possible to run x86 applications on a non-x86
architecture.

The Bochs distribution comes with a 10 MB disk image of DLX
Linux, which can be quickly booted and tested to
give you some idea how fast Bochs will run on your platform.

The bochs.sourceforge.net Web site lists several successful installations of Bochs, including Linux, NetBSD, OpenBSD, Windows 95, and Windows NT. In addition, Bochs has been successfully compiled on host
platforms including Linux, multiple Unixes, Windows, and Mac OS.

Installation

The software installation is painless. There are binary versions
available for many common platforms, including an RPM package, which
installed easily on my Mandrake 7.2 box. For less common platforms, like
SuSE Linux 7.3 on SPARC, there are source tarballs and RPMs. I was able
to build Bochs on my SPARCstation from the source package without any
fuss. A simple configure; make; make install sequence produced a
working package and even automatically downloaded the DLX Linux disk
image.

Bochs screenshot
Configuring the system is not overly difficult. As Bochs emulates an x86
processing environment, it allows you to emulate disk drives as well. You
can choose to have the floppy point to the physical device or a container
file. Likewise, the hard drives and CDROM can point to actual devices or
files that simulate the disk contents.

The Bochs environment is controlled by a single configuration file.
There is a large sample configuration file included that documents many
of the possible settings available under Bochs. There is also a short
sample configuration file which can be used to boot the DLX Linux image
file. After I modified the DLX configuration sample to point to the hard
drive image file, the Linux system booted right up.

Installing Windows 95

I decided to give Bochs a real once-over by installing an unforgiving and
cantankerous operating system: Windows 95. Using an old copy of Windows
95 I had on the shelf and my 1 GHz Athlon system running Mandrake Linux, I
went through the relatively straightforward configuration process. I
connected the Bochs virtual floppy and virtual CDROM to the real floppy
and CDROM on my system. I then generated a 483 MB virtual hard drive using
the Linux dd command following the instructions on the Bochs Web site.

I installed Windows 95 using the suggested configuration in the Bochs
online documentation. I told Windows that I would specify the hardware
and then selected generic components, like a standard VGA monitor, PS/2
mouse, and generic IDE interface. The first phase of the installation was
painless, but slow. I could have gone out to lunch during the software
load. A hot lunch. With dessert. And a dessert cordial. Yes, it was
really that slow.

Bochs screenshot

Once the Windows installation needed to be rebooted inside Bochs, I found
I had a problem. The new system rebooted and then seemed to hang while
the log file slowly grew to massive proportions. A little research on the
Bochs Sourceforge.net site revealed that the version of Bochs I was
using had a bug in the serial driver (a fix is apparently in the current
CVS tree). So I rebooted Windows under Bochs in safe mode and disabled
the serial device. That allowed me to continue with the Windows
configuration.

Another problem I ran into was a bug that prevents you from providing
input to “scandisk” while it is running. If you accidentally cause
corruption on the disk such that scandisk would normally prompt you for
input, you are stuck. The process will hang at that point, necessitating
a crash of the system. Unfortunately, the crash will cause scandisk to
run again upon restart and the problem will repeat ad nauseam. The Bochs
Web site mentions this problem, but the only workaround I found is to
avoid the need to interact with scandisk. So, upon rebooting, I chose to
drop to the DOS prompt instead of restarting Windows. Using the command
scandisk /autofix /nosave /nosummary C:, I repaired the drive without
interaction. Then I rebooted the emulated machine and restarted Windows.

Once the system was running, many operations were usable, but on the slow
side. The speed was uneven due to the effects of the hardware
emulation. For example, on my machine, individual windows opened
and closed with acceptable speed. But intense disk access was painfully
slow. Even simple graphics, like watching a playing card move across the
screen in Freecell, were sluggish. But many other interactive actions
(like pull-down menus and user interfaces) moved at a usable
pace. It was clear that some applications would be usable,
even with the performance penalty.

But why not just use Wine?

Even though Bochs is much slower than programs run under the Wine project, it still has advantages. As previously
mentioned, because Bochs provides hardware emulation, non-x86 systems can
use it, unlike Wine. Bochs not only supports Windows as a client
operating system, but Linux, DOS, and other x86 operating systems as well.

Also, Wine has to chase the ever-mobile Windows APIs. Because Bochs
emulates the hardware environment, once an operating system boots, just
about any program that normally runs on that operating system is likely to
work. It does not need to emulate any proprietary APIs that the operating
system might provide.

So, while there are times when Wine is a good solution, there are also
times to use Bochs. Programs that do not yet run under Wine may well
run under Bochs using a Windows operating system. Another option may be
Plex86, an Open Source project similar to VMware headed up by Kevin Lawton, the original author of Bochs.

Wrapping it all up

Bochs is certainly not the end-all and be-all of x86 platform emulators,
but it does work well (if slowly). Because it is Open Source, it can be ported to any number of operating systems and hardware
platforms. If you need to run an x86-based operating system in a sandbox,
check out Bochs.