Page 1 of 1
Using an emulator to test my OS?
Posted: Wed Aug 22, 2007 9:44 pm
by michaelg1987
I've been reading a lot on making my own (absolutely minimal) operating system, and I've got some code. The code compiles, I have a kernel image file, but the thing is, I don't know how to test it.
I've used QEMU before, but never for this purpose. I don't want to have to reboot my computer all the time in order to test my OS, and I was wondering if someone could explain to me how I can get my image to boot using QEMU - I have checked many resources, and while they all give advice on how to configure QEMU, they don't actually tell me how to get my binary, for instance, into an image file with a bootloader or something. Am I missing some terribly obvious resource? Apologies in advance if I am.
Posted: Wed Aug 22, 2007 10:03 pm
by JackScott
Would you mind telling me (us) the following things? Without them, we are really guessing.
- Are you using GRUB?
- Build environment? (Cygwin, UNIX, MinGW, etc)
The gist of the whole idea is that you create a file, mount it on loopback, and then write to the mounted file as if it were a filesystem (but this only works on UNIX, mostly).
The easiest way on Windows, if you are using GRUB, is to download a GRUB disk image off the net, write it to a floppy using rawwrite or similar, then write your kernel to the floppy. From there you can use rawwrite again to create another disk image, or use the floppy directly in QEMU.
http://www.osdev.org/wiki/Loopback_Device
http://www.osdev.org/wiki/RAWRITE
Hope this has been helpful.
Posted: Wed Aug 22, 2007 10:15 pm
by michaelg1987
I'm compiling under Linux, and uh, as for GRUB - I assume I should, it seems like the way to go from everything I read, I just don't know how to use it with my kernel.
Posted: Wed Aug 22, 2007 10:51 pm
by JackScott
If you haven't already, check out
http://www.osdev.org/wiki/Bare_bones for information on how to interface GRUB with your kernel. Once you've done that, and created a kernel binary, it's time to write it onto a disk image. If you have no preference otherwise, it's best probably to use the mount/loopback method, which is described in the link I gave in my last post (
http://www.osdev.org/wiki/Loopback_Device).
The instructions in part 1.1 are probably the most useful to you, but also remember to copy your kernel onto the image before you unmount. It might also be useful to edit the /boot/grub/menu.lst file before you unmount as well.
Posted: Wed Aug 22, 2007 11:06 pm
by michaelg1987
I figured out how to load it, via floppy image and loopback. My next question, do I HAVE to make it the size of a floppy? I see the next part of the tutorial about formatting bigger images and stuff, but it doesn't explicitly say if it'd be legal to just make the image bigger. Not a big concern right now, my kernel is tiny (12KB I think). Thanks for the links.
Posted: Thu Aug 23, 2007 1:35 am
by JamesM
Yes - It gets loaded via an emulated floppy-disk-driver, so it has to be the correct size. Bigger images should be used as HDDs and loaded via your own ATA driver. (Or CD-ROMs, if you work that way.)
Posted: Thu Aug 23, 2007 2:28 am
by AJ
Although you can use sparse HD images which only consume as much data as is on the virtual drive (plus some control info, I think).
Cheers,
Adam
Posted: Thu Aug 23, 2007 6:53 am
by jerryleecooper
You can load your OS as a floppy image using the "-fda" option of qemu even if it's not the same size of a real floppy. Im doing it all the times. But be sure not to read past the limit of your file, or else you get errors. The only emulator that I know that request floppy images to be of the exact size is Virtual PC, but you don't want to use that. My OS text console is all blinking with that emulator, and it gives stranges errors sometimes.
Posted: Thu Aug 23, 2007 7:43 am
by Combuster
jerryleecooper wrote:(...) Virtual PC, but you don't want to use that (...) it gives stranges errors sometimes.
VirtualPC is a proper emulator. If it can't run your OS properly, I suggest you search the fault in your code rather than Microsoft's. VPC not working is usually an indication that there are bugs in your code qemu or bochs are unable to detect. So far, many of the bugs I have experienced inside VPC also (would have) occured on real hardware.
Posted: Thu Aug 23, 2007 7:59 am
by jerryleecooper
I had a strange error, it was supposed to work
I have done everything right
But...
I had my bootloader not working. Happened that my floppy disk was formatted as 1680k at least, I think I didn't copied my kernel correctly.
SO I reformated the diskette, recopied my small kernel (32.5k) and now it's working. But there's the weird blinking, and the cursor is blinking also. But it's a shame my bootloader code doesn't support more than 1440k floppies size, really a shame. It's probably the floppy drive too? It's usb, a Mitsumi.
Posted: Thu Aug 23, 2007 10:23 am
by AJ
Combuster wrote:jerryleecooper wrote:(...) Virtual PC, but you don't want to use that (...) it gives stranges errors sometimes.
VirtualPC is a proper emulator. If it can't run your OS properly, I suggest you search the fault in your code
Hi,
I've found a couple of exceptions to this (with VPC 2004). Firstly, it doesn't seem to like some methods of using a separate TSS to handle double fault exceptions. At the time, I looked this up on the MS forums and it seems to be an 'official' oversight.
Secondly, I had some problems with being able to set the VME bit in CR4, but did not get the functionality of VME that works on real hardware, Bochs and VirtualBox. At the time, others also seemed to report having noticed the same issue.
Generally, however, I would absolutely agree though - always check your code for errors before assuming it is a problem with VPC.
Cheers,
Adam
Posted: Thu Aug 23, 2007 9:16 pm
by AndrewAPrice
I use QEMU and sometimes Bochs when I need extra debugging info. Why do I use these? Because they can be invoked by the command line. This makes them simple to run.
My workflow turns into:
- CTRL-S in source file.
- Double click build script.
- Did it compile?
- - Yes - Double click run script.
- - No - Rip hair out.
Posted: Fri Aug 24, 2007 12:13 am
by viki
I use (cygwin-ddd) or (mingw-insight) and grub-gdb-stub and for debugging purpose it works really nice. I've made a tutor about it with a simple kernels in asm and c (in polish) but I'm thinkin to translate it.