Emulating a CPU in software is quite a trick. A programmer has to fool the operating system and the software running on top of the operating system into believing that it is on genuine hardware. This requires meticulously emulating every single instruction and mode that the CPU has to offer which is immensely complex. SourceForge.net’s August 2004 project of the month is Bochs, a x86 emulator (386, 486, Pentium and Pentium Pro). Its emulation is robust enough to allow Linux, Windows 95, and Windows NT to run on top of it. The emulator runs under many hardware platforms and operating systems, including Windows, Linux and Mac OS X, so if you want to run Windows under OS X, you can do it! Bochs, pronounced ‘box’, is one of the top 100 projects on SourceForge.net boasting over a million downloads since its inception on SF.net. The SF.net team is proud to make Bochs, August 2004, project of the month.
Description of project:
Bochs is a program that simulates a complete Intel x86 computer. It can be configured to act like a 386, 486, Pentium, or Pentium Pro. Bochs interprets every instruction from power-up to reboot, and has device models for all of the standard PC peripherals: keyboard, mouse, VGA card/monitor, disks, timer chips, network card, etc. Because Bochs simulates the whole PC environment, the software running in the simulation “believes” it is running on a real machine. This approach allows Bochs to run a wide variety of software with no modification, include most popular x86 operating systems: Windows, all Linux flavors, all BSD flavors, and more.
Bochs differs from many x86 emulators because it is written in portableC++ code. While this is a disadvantage in terms of performance, it allowsBochs to run equally well on a wide variety of platforms; it runs on Windows and *nix, and should run on any *nix-like system on which it compiles. No special code is needed to run on a given host architecture. Bochs includes a debugger that allows efficient debugging of even operating system code.
Bochs was written by Kevin Lawton starting in 1994. It began as acommercial product, but in March 2000, Mandrakesoft bought Bochs and madeit open source under the GNU LGPL. In March 2001, Kevin helped a fewdevelopers to move all Bochs activities from bochs.com tohttp://bochs.sourceforge.net. Since then the Bochs Project has settledinto its new home, and around release times has even been the mostactive project of the week at SourceForge.net.
- Development Status: 4 – Beta
- Environment: Other Environment, Win32 (MS Windows), X11 Applications
- Intended Audience: Developers, End Users/Desktop
- License: GNU Library or Lesser General Public License (LGPL)
- Natural Language: English
- Operating System: OS Independent
- Programming Language: C++
- Topic: Emulators
Why and how did you get started?
Bryce: I was working at a processor design company and we needed to betterunderstand how Linux worked with multiple processors. I searched forprocessor emulators and found that Bochs was a great starting point.My first project was adding some multiprocessor emulation features toBochs so that I could run the Linux SMP kernel and study it. At thetime, the project did not really have a home, only a mailing list witha lot of patches floating around. Several of us on the mailing listdid some research and found that SourceForge.net would provide all of theservices we needed to host the project.
Christophe: I joined the project just before Bochs 1.4 was released. At that timeI was writing a free VGA BIOS to be used with Bochs and Plex86. Istarted fixing small issues that were annoying me, like the inabilityto use Bochs on X11 with a French keyboard. Then Bryce offered me to join the developers team, probably because he was fed up with applying my patches to the CVS. 😉
Stanislav: I started with a simple Technion project in computer architectureand as a part of project I added to Bochs some little enhancements.I found that Bochs was missing some significant featuresthat I could implement and contribute. I continued todo so even after I graduated.
Greg: I found out about Bochs from a slashdot post about x86 virtualization technologies. That was early 2001, and not much was going on. I coordinated with Kevin and Bryce on the move to SourceForge.net, and then set to work improving the timing model of the bochs system. I’ve also put in some work on several devices, helping to make Bochs interfaces feel faster to the end user.
What is the intended audience?
Bryce: Bochs has many possible uses, and different people use it for differentthings. Many people use it to run applications in a second operatingsystem without needing two different computers or dual-booting. RunningWindows software on a non-x86 workstation or on an x86 Unix box are commonuses. Also, because every hardware instruction and every line ofsimulator code is accessible, Bochs is used extensively for debugging newoperating systems. If you were writing boot code for your home-brewed x86operating system and it didn’t work right, booting it in Bochs could giveyou great visibility into what is really going on. The Bochs debugger letsyou simulate quickly or slowly, pausing whenever you want to look at thecontents of memory or the CPU registers. Or, if you wanted to study whichparts of a program take the most time, you could use Bochs to measure howoften certain pieces of the code were executed.
Greg: Bochs is most useful for OS developers who need to see detailed debugging information on their system as it is running. It is also useful for people generally interested in system emulation, but is often too slow for these purposes. Many people also use it for running old games, where a slow machine can be as much a benefit as a hinderance.
How many people do you believe are using your software?
Bryce: It is hard to estimate how many people have tried Bochs or use it on aregular basis, but a few statistics give an indication. Thebochs-developers mailing list, which is the primary source of news on bugsand releases, has over 450 subscribers. The latest version has beendownloaded over 100,000 times from SourceForge.net.
What are a couple of notable examples of how people are using your software?
Bryce: Bochs has been used as a teaching tool in operating systems classes, inwhich students used and modified it to learn how the PC hardware works. Asa final project the students had to add a new peripheral device, so theyhad to learn all about I/O ports, interrupts, and device drivers. Inindustry, it is used to support legacy applications on modern hardware,and as a reference model when testing new x86-compatible hardware.
Christophe: In the May 2004 issue of Login:, a French magazine about alternativecomputing and OSS, Bochs is provided on the accompanying CD-ROMfor people to test ReactOS without installing anything on theirhard disk. In the June 2004 issue of GNU/Linux Magazine France there is thefirst article of a series about writing a simple OS. Bochs and Qemuare presented and used as valuable development tools (simulator,debugger, log traces).
Greg: I know the author of Minix usually points to Bochs as a good environment to test Minix in.
What gave you an indication that your project was becoming successful?
Bryce: When our 2.0 release annoucement was on the front page of slashdot.com, several of my family members saw it and asked me about it.
What has been your biggest surprise?
Christophe: I was quite surprised to learn that Bochs was actually used for aMIT OS course.
Greg: When we moved to SourceForge.net we were amazed how we jumped to be one of the top downloads. It seemed like there was a lot of pent-up demand to get Bochs going again.
What has been your biggest challenge?
Bryce: Time management. For me, serious software development requires large chunks of time without interruption. One hour at a time is not long enough to get much done.There are months when I can contribute a lot, and others when I can barelykeep up with the email traffic.
Christophe: I wished I had more time to work on Bochs. Reading and answeringemail, testing patches, reproducing and fixing bugs, and researchfor feature requests and new version releases take a lot of time,and I can’t keep up with the current pace.
Greg: Dealing with an all-volunteer team of developers. There are a lot of big projects that everyone agrees need to be done, but no one has the time to tackle because it’s a big job that can’t really be divided among multiple developers.
Why do you think your project has been so well received?
Bryce: Bochs lets people do things that are very difficult or expensiveotherwise. Commerical PC emulators are pricey, especially ones that allowyou to stop and look inside the machine while it runs. Also, thedevelopers’ mailing list is very active and helps people get going in theright direction.
Greg: At least for a while, Bochs provided the only good method for free system emulation.
Where do you see your project going?
Bryce: We always continue to improve the emulation of peripherals such as networkcards and graphics cards. Each operating system uses the hardware inslightly different ways, so it’s a never-ending process.
Greg: With the development of system emulation in Qemu, Bochs may refocus on being a good tool for OS development. This has always been Bochs’s strength.
What’s on your project wish list?
Bryce: Improving video quality, emulation speed, supporting newer types ofperipherals, being able to save the machine state and restore it later.
Greg: Someone willing to take the time to implement dynamic translation and really speed things up.
What are you most proud of?
Bryce: I’m proud that I helped to re-energize this project back in 2002. Afterit had gone for several years without regular maintenance, our team gaveBochs a new Web site, code repository, and bug and feature tracking, andstarted releasing code again. As some of the original developershave faded in and out of the picture, others have stepped in to continuethe work. More than anything else, that convinces me that the project isalive and well.
Christophe: There are a few personal achievement I’m proud of, like implementingCD-ROM booting in the BIOS, but the thing I’m mostly proud of isversion 2.0, for the numerous improvements and features contributedby all the regular and occasional developers.
If you could change something about the project, what would it be?
Bryce: It would help to have a designated leader who could consistently devote half or full time to the project, and help to set priorities and a common vision. Some of our subprojects can be completed by one person in his spare time, but others require more planning and coordination than we can typically muster.
Christophe: Speed! This is the ubiquitous criticism about Bochs. Unfortunately,big speed improvements means radical changes in the architecture.
How do you coordinate the project?
Bryce: We discuss roadmaps and ideas on the mailing list, or on IRC. This helpsto set priorities and divide up tasks. But often, since all of us arevolunteers with limited time and energy, the projects that get done arethe ones that some developer finds the most useful or interesting. Weaccept patches from the community after testing them out.
Toward release time, we coordinate our efforts more. We do a featurefreeze, and one person takes charge of building release candidates (whicheveryone helps to test and fix), then the release itself. We use CVS tagsand branches to keep releases clean.
Greg: Mostly people do what interests them. We also make a lot of effort to keep OSes working, so most testing consists of trying to boot OSes and ensuring that they work.
Do you work on the project full-time, or do you have another job?
We all have day jobs.
If you work on the project part-time, how much time would you say you spend, per week, on it?
Bryce: 1 to 30 hours, varies. Lately, closer to 1.
Christophe: It depends on how much spare time I have left after my day workand family. These days, it’s between 2 and 10 hours a week.
Greg: 1-2 hours. I’m no longer a primary developer.
What is your development environment like?
Bryce: Primary development machine: Red Hat Linux, gcc, gdb, gprof, valgrind.For Windows builds: Windows 98, Microsoft VC++ 6.0, Cygwin
Christophe: My development environment is composed of two PC machines, an Athlondesktop and a PIII laptop, both running Debian GNU/Linux. My favoritetools are mozilla, vi, gcc and gdb. I also have access to a PC running Windows 98 and Visual C++ for the Win32 builds, and to a G3 Mac running Debian GNU/Linux forbig-endian testing and debugging.
Feb 7, 2004: Bochs 2.1.1 fixed several bugs in 2.1
Jan 11, 2004: Bochs 2.1 improved color display, added 3DNow! and PNI instructions, added PCI and USB cards, and supports VMware hard disk formats.
Dec 21, 2002: Bochs v2.0 : 2x emulation speedup, AMD x86-64, MMX,SSE, SSE2 instructions, wxWindows and SVGAlib ports, up to 8 harddisks/CD-ROMs, TUN/TAP network interface, and many I/O deviceimprovements, Mac OS X/Carbon interface, updated Mac OS 9 port.
How can others contribute?
We currently need help with the following tasks:
- PC hardware gurus: Mouse, interrupt controller, timer, IDE controller,network card, keyboard, VGA… Most of our bug reports and featurerequests are due to incomplete C++ models of the various PC devices. Toimprove this, we need PC hardware gurus who know where to find the specsfor this stuff and improve the hardware models for Bochs. Working onmodels is a fun way to learn how things work, and unlike designing a realhard disk, you can test out your changes on a real operating systemimmediately!
- Disk Images: Our collection of disk images is getting out of date. It would be great to have small or large images of a variety of free operating systems.
- Documentation: Adding installation help and other useful information into the docs.
We have a project to-do list, and we welcome anybody interested in working on one of these issues.
Some of the items are rather simple and can be implemented by singleindividuals. Other items are quite complex and development needsto be coordinated. So, if somebody want to contribute, please dropus a note in the developers mailing list, so we know which issue isbeing worked on, and we can exchange ideas on the subject.
Anyone who has a lot of time to burn who would like to redo the core processor routines for speed would be great.