« Good for fear of God | Main | The Wrath of Open Source »

Bochs on Mac OS X

After spending a great deal of time playing with GRUB and installing Operating Systems in Virtual PC, I took a gamble with another emulation environment for developing low level x86 software. What I thought would be another one of my immensely time sapping mind games of exploration, turned out to produce a development environment which became absolutely essential in the development of an x86 kernel.

Bochs is an open source emulator of the x86 architecture. I had brushed it away earlier, because I figured it would only run on x86 hardware itself, and hadn't heard of anyone using it on the Mac. Well, in a roundabout manner, I eventually came to attempting a compile of Bochs on OS X, and discovered it not only compiled very easily, but ran well. I then discovered an OS X port which came with Applescripts to launch the software, and a GUI for the actual display of the environment. Excellent stuff, but still no huge advantage over Virtual PC, and the configuration was starting to look overwhelming.

But, being the pedantic geek that I am, I continued investigating the software. Using the example OS image provided with the OS X Bochs package as a starting point, I found that simple modifications to the configuration file were all that was necessary to boot the disk images I had been playing with with Virtual PC. I persevered with the process, and managed to install FreeDOS on a hard disk image, so I could run my kernel within the Bochs environment. Already this was looking better than Virtual PC, because I could set the configuration file to way I liked it, and then didn't have to worry about capturing and releasing disk images everytime I re-ran the emulation. So I had a bit of time-saving functionality there, but it had cost me several days setting it up.

The real reward came when I investigated the debugging options of Bochs. I must say I wasn't expecting much. Enabling debugging required a recompilation of the source, with custom options, so I grabbed a hold of the source and followed the install instructions. Configuration and compilation was impressively smooth and the debug version of Bochs ran well. But it wasn't all that useful - all general debugging investigation (disassembly, memory dumps, register dumps) had to be invoked by hand repeatably, which was going to be a real hassle. But there was a mention of a GUI for the Bochs debugger, called bfe, so I had myself a look at that.

Amazingly enough, the debugger compiled almost straight out of the box, and ran very cleanly in the X11 environment. There was a small difficultly in getting the GUI to execute the command line application because of the funny interaction between the command line bochs app, the Mac OS X GUI and the X11 debugger. I was very happy to find that I could copy the shell execution line from the Bochs Applescript and use it in configuring bfe. That is, I passed "cd /usr/local/bochs/myOS; exec /usr/local/bochs/bochs.app/Contents/MacOS/bochs" to bfe as the path to the bochs executable. Works beautifully! Running bfe from the X11 prompt opens a clean GUI. Hitting the "start Bochs" button lauches the OS X GUI for Bochs, using the configuration script in myOS, and I can then debug my application while it executes in another window.

When one considers what combination of technologies being used here - emulation of x86 on PowerPC using an app designed for x86 compiled on PowerPC, executed in a OS X GUI, debugged from a X11 app - it really is amazing it works at all, let alone works so smoothly. I'm left with an awesome development environment for low-level x86 development, in particular for kernel development, which still gives me the advantages of developing on OS X - the rest of the applications, excellent X11 environment, great interaction between the command line and GUI layers, stable disk image platform. Of course, if I had realised the environment was possible a couple of months earlier, the university assignment to develop a kernel would have been a significantly simpler experience.

Well, just in case anyone else wants to do similar development - it is possible, and highly recommended!

Comments

hello. im a beginning comp geek with a powerbook g4. Though i love comps and everything about them, i dont know c++ or much else. i really want bochs on my comp but ihave no cluse where to start or what to do. Maybe u could help me. i tried downloading the binary file and it was easy to install, but when i ran it ............................................................................................................................................................................................. You can also start bochs with the -q option to skip these menus.

1. Restore factory default configuration
2. Read options from...
3. Edit options
4. Save options to...
5. Begin simulation
6. Quit now

Please choose one: [2] 5
00000000000i[ ] installing carbon module as the Bochs GUI
00000000000i[ ] Bochs x86 Emulator 2.1.1
00000000000i[ ] February 08, 2004
00000000000i[ ] System configuration
00000000000i[ ] processors: 1
00000000000i[ ] A20 line support: yes
00000000000i[ ] APIC support: no
00000000000i[ ] CPU configuration
00000000000i[ ] level: 5
00000000000i[ ] fpu support: yes
00000000000i[ ] paging support: yes, tlb enabled: yes
00000000000i[ ] mmx support: yes
00000000000i[ ] sse support: no
00000000000i[ ] v8086 mode support: yes
00000000000i[ ] 3dnow! support: no
00000000000i[ ] PAE support: no
00000000000i[ ] PGE support: no
00000000000i[ ] PSE support: no
00000000000i[ ] x86-64 support: no
00000000000i[ ] SEP support: no
00000000000i[ ] Optimization configuration
00000000000i[ ] Guest2HostTLB support: yes
00000000000i[ ] RepeatSpeedups support: yes
00000000000i[ ] Icache support: yes
00000000000i[ ] Host Asm support: yes
00000000000e[ ] No romimage to load. Is your bochsrc file loaded/valid ?
00000000000i[MEM0 ] allocated memory at 0x1008000. after alignment, vector=0x1008000
00000000000i[MEM0 ] 4.00MB
00000000000p[MEM0 ] >>PANIC<< ROM: System BIOS image undefined.
00000000000i[SYS ] Last time is 0
00000000000i[ ] restoring default signal behavior
========================================================================
Bochs is exiting with the following message:
[MEM0 ] ROM: System BIOS image undefined.
========================================================================
00000000000i[CTRL ] quit_sim called with exit code 1
[Process completed] .............................................................................................................................................................................................
Bochs version doesnt really matter. Also once it is installed will i have to install anthing else (windows xp...) for a more clear version of what it said go to http://www.delorie.com/djgpp/bugs/show.cgi?000368)

note:people have encountered the same problem as me but the answer is always for windows pcs and not mac os's

Post a comment