using qemu to test kernel

Question about which tools to use, bugs, the best way to implement a function, etc should go here. Don't forget to see if your question is answered in the wiki first! When in doubt post here.
Post Reply
kc1
Posts: 3
Joined: Sat Mar 15, 2008 12:48 pm

using qemu to test kernel

Post 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
User avatar
gzaloprgm
Member
Member
Posts: 141
Joined: Sun Sep 23, 2007 4:53 pm
Location: Buenos Aires, Argentina
Contact:

Post 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
User avatar
Brynet-Inc
Member
Member
Posts: 2426
Joined: Tue Oct 17, 2006 9:29 pm
Libera.chat IRC: brynet
Location: Canada
Contact:

Post 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.
Image
Twitter: @canadianbryan. Award by smcerm, I stole it. Original was larger.
User avatar
codemastersnake
Member
Member
Posts: 148
Joined: Sun Nov 07, 2004 12:00 am
Contact:

Post 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.
User avatar
Combuster
Member
Member
Posts: 9301
Joined: Wed Oct 18, 2006 3:45 am
Libera.chat IRC: [com]buster
Location: On the balcony, where I can actually keep 1½m distance
Contact:

Post 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.
"Certainly avoid yourself. He is a newbie and might not realize it. You'll hate his code deeply a few years down the road." - Sortie
[ My OS ] [ VDisk/SFS ]
User avatar
codemastersnake
Member
Member
Posts: 148
Joined: Sun Nov 07, 2004 12:00 am
Contact:

Post 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.
User avatar
Brynet-Inc
Member
Member
Posts: 2426
Joined: Tue Oct 17, 2006 9:29 pm
Libera.chat IRC: brynet
Location: Canada
Contact:

Post 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. ;)
Image
Twitter: @canadianbryan. Award by smcerm, I stole it. Original was larger.
pcmattman
Member
Member
Posts: 2566
Joined: Sun Jan 14, 2007 9:15 pm
Libera.chat IRC: miselin
Location: Sydney, Australia (I come from a land down under!)
Contact:

Post 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.
User avatar
Brendan
Member
Member
Posts: 8561
Joined: Sat Jan 15, 2005 12:00 am
Location: At his keyboard!
Contact:

Post 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
For all things; perfection is, and will always remain, impossible to achieve in practice. However; by striving for perfection we create things that are as perfect as practically possible. Let the pursuit of perfection be our guide.
User avatar
Brynet-Inc
Member
Member
Posts: 2426
Joined: Tue Oct 17, 2006 9:29 pm
Libera.chat IRC: brynet
Location: Canada
Contact:

Post 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)
Image
Twitter: @canadianbryan. Award by smcerm, I stole it. Original was larger.
xyzzy
Member
Member
Posts: 391
Joined: Wed Jul 25, 2007 8:45 am
Libera.chat IRC: aejsmith
Location: London, UK
Contact:

Post 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.
User avatar
Brendan
Member
Member
Posts: 8561
Joined: Sat Jan 15, 2005 12:00 am
Location: At his keyboard!
Contact:

Post 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
For all things; perfection is, and will always remain, impossible to achieve in practice. However; by striving for perfection we create things that are as perfect as practically possible. Let the pursuit of perfection be our guide.
xyzzy
Member
Member
Posts: 391
Joined: Wed Jul 25, 2007 8:45 am
Libera.chat IRC: aejsmith
Location: London, UK
Contact:

Post 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.
Post Reply