972
edits
[unchecked revision] | [unchecked revision] |
m (Interwiki) |
m (Bot: Replace deprecated source tag with syntaxhighlight) |
||
(21 intermediate revisions by 15 users not shown) | |||
Line 1:
{{Emulators}}
'''Bochs''' is a steadily improving simulator for the [[:Category:x86|IA32]] platform. Among other niceties (such as removing the need for a reboot to test your latest kernel build, just restart Bochs), it offers detailed debugging functionality that can help greatly during kernel development.▼
▲'''Bochs''' is a steadily improving
It is strongly suggested to get two installations of Bochs - in addition to the out-of-the-box version (which might well be one of the binary downloads), you should also compile a second instance with the internal debugger enabled - so when something strange occurs that your 'normal' debugging tools can't trace, you can cross-check it with the debug version. You may also wish to enable (and use) the debug i/o ports.▼
▲It is strongly suggested to get two installations of Bochs - in addition to the out-of-the-box version (which might well be one of the binary downloads), you should also compile a second instance with the internal debugger enabled - so when something strange occurs that your 'normal' debugging tools can't trace, you can cross-check it with the debug version. You may also wish to enable (and use) the debug
==Frequent error messages==
===Running in Bogus Memory===
You sent your code pointer (
=== 3rd exception with no resolution===
The CPU didn't manage to invoke an exception handler and would normally [[Triple Fault|triple fault]]. This is probably due to a bad [[Interrupt Descriptor Table|IDT]] register content, or a bad IDT descriptor. Sometimes (but less likely), it can also be due to a severe bug in your exception handler code. Check your exception works with "illegal"
<syntaxhighlight lang="asm">
push 0xf001
pop ds
mov ax, ~[ds:0x12345678]
</syntaxhighlight>
In several cases, there are other error messages prior to this one which can provide more details in the error. Some common messages that might be displayed:
Line 28 ⟶ 32:
===I/O Operand Size===
Bochs performs some
=== fetch_raw_descriptor: LDTR.valid=0 ===
Many of you have said "but ... I do not have an LDT and I read it wasn't mandatory!?". You're right. And so is
If you're still stuck, download the Bochs
==Differences between Bochs and real hardware==
;Bochs enables
:Your PC doesn't necessarily do so. Sometimes there's a BIOS option, sometimes there isn't. Check your code that enables
;Bochs wipes out its memory
:In Bochs, memory is always filled with zero until you (or the BIOS) put something else. On a normal PC, uninitialized memory tends to contain garbage (most often all-ones) or traces of previous executions. Check your pointers, initialize them, print your code on paper if necessary.
;Bochs does not properly emulate CPU cache/TLB
:Although Bochs does have these constructs, they do not work the same as a regular CPU cache or TLB and do not change based on which CPU is being emulated. If you're not handling caching or TLB refreshes correctly, behavior may differ in Bochs vs. hardware (i.e. it may work on Bochs but not on hardware, or vice versa).
;Bochs floppy has no errors
:In a
;Bochs is flexible about returning to real mode
:
;Bochs' timer is not
:(unless you configure it closer to real time). Waiting for 2 second on bochs will let any virtual device that needs 2 seconds to be ready be ready, but that could be just 0.02 seconds for you ... or that could be 200 seconds.
Line 82 ⟶ 89:
display_library: x, options="gui_debug"
In a Windows environment, add this line to your bochsrc.bxrc
display_library: win32, options="gui_debug"
It seems that on Windows, the "option" flag (what the above line used to read) will be accepted, but the GUI window will not appear.
===I/O debugger macros===
Some useful macros when Bochs is compiled with the I/O debug ports enabled (<tt>port_e9_hack: enabled=1</tt> if Bochs 2.4 or newer, <tt>configure --port-e9-hack</tt> if not):
<syntaxhighlight lang="c">
//outputs a character to the debug console
#define BochsConsolePrintChar(c) outportb(0xe9, c)
//stops simulation and breaks into the debug console
#define BochsBreak() outportw(0x8A00,0x8A00); outportw(0x8A00,0x08AE0);
</syntaxhighlight>
===Magic Breakpoint===
When you're using
You should put the following line in your
magic_break: enabled=1
On older versions, enabling the debugger alone doesn't compile in magic breakpoint support, you will also need to
===Debugging SMP===
Line 112 ⟶ 127:
Bochs places an automatic breakpoint just before the BIOS loads, this can be automatically skipped by putting <tt>continue</tt> as the first command in the said file.
===Debugging Triple Faults===
When using the internal debugger, you may change this line in your Bochs configuration file:
reset_on_triple_fault 0
This line disables the emulator reset on a Triple fault, enabling you to debug the code after a Triple fault occured (Very useful while implementing paging).
==Compiling Bochs from Source==
Bochs has many compile-time configuration options, some of which conflict, and therefore a binary distribution of Bochs may not be suitable for your purposes. I found it was best to compile my own copy of Bochs to be sure I had the features that I needed. Also, you should consider using the CVS snapshot version of Bochs if the released version is old and not working for you. I found this was necessary up until version 2.4 was released, for example. On Ubuntu, you may have to run
<syntaxhighlight lang="bash">
sudo apt-get install libgtk2.0-dev
</syntaxhighlight>
and enter your password. On other linux distros, try the equivalent.
The array of Bochs configuration options can be confusing, and you cannot assume the defaults are going to be sensible. These are the options I use, this can get you started:
<syntaxhighlight lang="bash">
./configure --enable-smp \
--enable-cpu-level=6 \
--enable-all-optimizations \
--enable-x86-64 \
Line 128 ⟶ 156:
--enable-debugger-gui \
--enable-logging \
--enable-fpu \
--enable-3dnow \
Line 137 ⟶ 164:
--disable-plugins \
--disable-docbook \
--with-x --with-x11 --with-term --with-sdl2
</syntaxhighlight>
A few notes:
* If you are on Windows, that last line should probably read "--with-win32".
* Bochs has GDB-stub support, and its own internal debugger. These cannot be compiled into the same Bochs binary. The internal debugger is very useful, it is --enable-debugger▼
* On Linux, using SDL as the display library over X11 is preferable as the performance appears to increase greatly on some setups
* The GDB-stub in Bochs does not support SMP, last time I checked.▼
▲* Bochs has GDB
* If you do not enable PCI, then the Intel Multiprocessing tables will not appear in memory.
* I was unable to successfully load the GUI debugger without specifying <tt>--disable-plugins</tt>. Otherwise, I get dynamic loading symbol errors.
* Post-2.4.2 several of the CPU specific options were folded into the CPU-level specification and are therefore deprecated. They have been removed from the example above.
* The default compile does not support x86-64, --enable-x86-64 will turn it on
* On many Linux distributions it is possible to install Bochs via a package manager. For example, on distributions that use apt-get we can do
<syntaxhighlight lang="bash">
sudo apt-get install bochs
sudo apt-get install bochs-x
</syntaxhighlight>
to install Bochs and the X11 plugin (which may crash on ubuntu/linux mint: install the sdl plugin and use sdl instead of x as the display library in this case). Note that there is a big chance that the graphical debugger is not enabled in the binaries from the package manager.
==See Also==
Line 156 ⟶ 192:
===External Links===
*[http://bochs.sourceforge.net Bochs Homepage]
*[http://bochs.sourceforge.net/doc/docbook/user/internal-debugger.html Bochs internal debugger commands documentation]
*[http://www.codeproject.com/system/MakingOS_2.asp CodeProject article on using Bochs]
|