Using an emulator to test my OS?
-
- Posts: 4
- Joined: Wed Aug 22, 2007 9:39 pm
Using an emulator to test my OS?
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.
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.
- JackScott
- Member
- Posts: 1036
- Joined: Thu Dec 21, 2006 3:03 am
- Location: Hobart, Australia
- Mastodon: https://aus.social/@jackscottau
- Matrix: @JackScottAU:matrix.org
- GitHub: https://github.com/JackScottAU
- Contact:
Would you mind telling me (us) the following things? Without them, we are really guessing.
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.
- Are you using GRUB?
- Build environment? (Cygwin, UNIX, MinGW, etc)
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.
-
- Posts: 4
- Joined: Wed Aug 22, 2007 9:39 pm
- JackScott
- Member
- Posts: 1036
- Joined: Thu Dec 21, 2006 3:03 am
- Location: Hobart, Australia
- Mastodon: https://aus.social/@jackscottau
- Matrix: @JackScottAU:matrix.org
- GitHub: https://github.com/JackScottAU
- Contact:
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.
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.
-
- Posts: 4
- Joined: Wed Aug 22, 2007 9:39 pm
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.
- jerryleecooper
- Member
- Posts: 233
- Joined: Mon Aug 06, 2007 6:32 pm
- Location: Canada
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.
- Combuster
- 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:
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.jerryleecooper wrote:(...) Virtual PC, but you don't want to use that (...) it gives stranges errors sometimes.
- jerryleecooper
- Member
- Posts: 233
- Joined: Mon Aug 06, 2007 6:32 pm
- Location: Canada
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.
Hi,Combuster wrote:VirtualPC is a proper emulator. If it can't run your OS properly, I suggest you search the fault in your codejerryleecooper wrote:(...) Virtual PC, but you don't want to use that (...) it gives stranges errors sometimes.
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
- AndrewAPrice
- Member
- Posts: 2309
- Joined: Mon Jun 05, 2006 11:00 pm
- Location: USA (and Australia)
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.
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.
My OS is Perception.