Page 1 of 1

using qemu to test kernel

Posted: Sun Mar 16, 2008 10:07 am
by kc1
Hi i need to find a way to use qemu to test my kernel, can someone point me to a tutorial on os development and running it in qemu, i need to know how to get qemu to create a floppy image and then be able to install grub

Posted: Sun Mar 16, 2008 10:12 am
by gzaloprgm
http://jamesmolloy.co.uk/tutorial_html/ ... setup.html

There you can see how to create the image with grub and your kernel.

Emulation with qemu is very easy, just exec "qemu -fda image.img" and it should work.

Cheers

Gonzalo

Posted: Sun Mar 16, 2008 12:31 pm
by Brynet-Inc
Personally, I would add a few extra arguments to that... specify memory size perhaps.

To actually "create" an image, use either qemu-img or manually with dd.

Posted: Sun Mar 16, 2008 5:39 pm
by codemastersnake
I would suggest you to use BOCHS as it is a better emulator. and provides more debugging information.

You can always read qemu readme. It's excellently documented.

Posted: Sun Mar 16, 2008 5:53 pm
by Combuster
I would suggest you to use BOCHS as it is a better emulator.
Define 'Better' - both bochs and qemu have their strong points. Bochs has extensive debugging facilities, Qemu has raw speed bochs can only dream of. Whichever you use is basically a matter of taste.

Posted: Sun Mar 16, 2008 6:09 pm
by codemastersnake
Correction: Bochs is Good and Better because it has more debugging facilities than Qemu. Also you can control many aspects of a Bochs Machine.

Posted: Sun Mar 16, 2008 8:00 pm
by Brynet-Inc
Snake wrote:Also you can control many aspects of a Bochs Machine.
Anything specially? While agree the debugging features provided by Bochs are plentiful, QEMU includes it's own bag of goodies. ;)

Posted: Sun Mar 16, 2008 8:03 pm
by pcmattman
Snake wrote:Also you can control many aspects of a Bochs Machine.
The QEMU manual pages relating to only the command line options are many times bigger than the Bochs ones, and you can do more complex things when setting up QEMU through the command line (setting up an entire usermode network stack for all emulators, for instance).

My only problem with QEMU is that it crashes on my system whenever the kernel triple faults.

Posted: Sun Mar 16, 2008 9:14 pm
by Brendan
Hi,
pcmattman wrote:The QEMU manual pages relating to only the command line options are many times bigger than the Bochs ones, and you can do more complex things when setting up QEMU through the command line (setting up an entire usermode network stack for all emulators, for instance).
I still haven't figured out how to get Qemu to emulate an Opteron, a Pentium or an 80486 or something else; which is very useful if you want to know if your kernel works on a wide variety of CPUs (e.g. with/without PAE, with/without FPU/32Now/MMX/SSE1/SSE2/SSE3/SSE4, with/without global pages, with/without RDTSC, with/without syscall/sysenter, etc).... ;)

Apart from that, the only difference is debugging capabilities and speed. Bochs has better debugging capabilities, and Bochs has better speed (because it's slower, which makes it easier for me to see where my code needs improvement).

Qemu will also emulate other (non-80x86) architectures, but that's not very useful to me at the moment.


Cheers,

Brendan

Posted: Mon Mar 17, 2008 12:31 am
by Brynet-Inc
Brendan wrote:I still haven't figured out how to get Qemu to emulate an Opteron, a Pentium or an 80486 or something else; which is very useful if you want to know if your kernel works on a wide variety of CPUs (e.g. with/without PAE, with/without FPU/32Now/MMX/SSE1/SSE2/SSE3/SSE4, with/without global pages, with/without RDTSC, with/without syscall/sysenter, etc).... ;)
I believe qemu 0.9.1 has partial support for customizing the emulated CPU.
QEMU Changelog wrote: -CPU model selection support (J. Mayer, Paul Brook, Herve Poussineau)
Perhaps "qemu -M ?" will list a few additional targets? (I'm still using 0.9.0...).

EDIT: I was wrong, type "-cpu ?" to get a list of all CPU models qemu can emulate.

I should note, there are quite a few changes in the 0.9.1 release.. some *really* cool command line options. 8)

Posted: Mon Mar 17, 2008 1:17 am
by xyzzy
pcmattman wrote:My only problem with QEMU is that it crashes on my system whenever the kernel triple faults.
This is fixed in the CVS repo, now it properly dies with an error an a register dump (which is *very* useful)
Brendan wrote:I still haven't figured out how to get Qemu to emulate an Opteron, a Pentium or an 80486 or something else; which is very useful if you want to know if your kernel works on a wide variety of CPUs (e.g. with/without PAE, with/without FPU/32Now/MMX/SSE1/SSE2/SSE3/SSE4, with/without global pages, with/without RDTSC, with/without syscall/sysenter, etc).... ;)
Edit the source ;)
Brendan wrote:Apart from that, the only difference is debugging capabilities and speed. Bochs has better debugging capabilities, and Bochs has better speed (because it's slower, which makes it easier for me to see where my code needs improvement).
I personally prefer debugging with QEMU by attaching GDB to it. Works fine for me.

Posted: Mon Mar 17, 2008 2:08 am
by Brendan
Hi,
Brynet-Inc wrote:I believe qemu 0.9.1 has partial support for customizing the emulated CPU.
I hope so (I haven't tried 0.9.1 yet either) :)
Brynet-Inc wrote:I should note, there are quite a few changes in the 0.9.1 release.. some *really* cool command line options. 8)
The main thing I'm hoping for is an EFI BIOS - last time I looked there was an EFI BIOS available for Qemu, but it only worked for the unstable/CVS version of Qemu (which didn't seem to work on my machine at the time).

There is one more issue with Qemu though - for SMP (for e.g. on my machine, IIRC) one emulated CPU runs for about 500000000 instructions, then the next emulated CPU runs for about 500000000 instructions, then the next CPU, etc. This improves performance (which isn't important to me), but also severely reduces the chance of finding race conditions and reentrancy problems in the guest OS's code (which is extremely important to me).



Cheers,

Brendan

Posted: Mon Mar 17, 2008 2:13 am
by xyzzy
Brendan wrote:The main thing I'm hoping for is an EFI BIOS - last time I looked there was an EFI BIOS available for Qemu, but it only worked for the unstable/CVS version of Qemu (which didn't seem to work on my machine at the time).
I tried the EFI stuff a while ago and I couldn't get it working, even with the CVS version. If it works for 0.9.1 however, that would be really cool.