views:

547

answers:

5

I like programming challenges, and writing a kernel seems a programming challenge.

Unfortunately, kernels are particularly hard to test because they are basically the core of operating systems and so they can't be easily ran on top of an operating system.

However, I know about applications called Virtual Machines that can emulate computer hardware.

What is the easiest/best way to develop and test kernels(C+Assembly) using Virtual Machines?

A: 

Probably just setting up a machine (x86, I guess), and then investigate exactly how it behaves during boot. There should be one or more files in the host machine's file system that act as the virtual machine's file system, and then you'd need to put some boot sector information there that causes your in-development kernel to boot.

That would of course mean that the build system on the host has a way to write the kernel to the virtual machine's file system, which might vary in difficulty.

Picking one at random, bochs seems to http://bochs.sourceforge.net/doc/docbook/user/index.html">support editing the boot media from the outside using standard tools like dd etc.

unwind
A: 

It's straightforward. Set up a virtual machine, write your kernel, copy it to the virtual machine, boot the virtual machine.

You'll need to be more specific if you want more specific advice.

jalf
+8  A: 

While BOCHS seems to be better at letting you know when something goes horribly wrong with your pet OS... it is very slooooow! I use VirtualPC for general purpose testing and BOCHS when things get murky.

Also, you will more than likely be booting the OS every 2 minutes, so it helps to have some sort of automated way to build a boot image & fire off the Virtual PC.

I built a GRUB boot floppy image with all the necessary stuff to get it to boot the Kernel.Bin from the root. I use a batch file to copy this file to the virtual project directory, use FAT Image Generator to copy my kernel to the image. Then just launch the VirtualPC project. Vola!

Excerpt from my batch file:

COPY Images\Base.vfd Images\Boot.vfd /Y
fat_imgen.exe modify Images\Boot.vfd -f Source\Bin\KERNEL.BIN
COPY Images\Boot.vfd Emulators\VirtualPC\ /Y
START Emulators\VirtualPC\MyOS.vmc

One last suggestion: Set the VirtualPC process priority to low - trust me on this one! I'd be happy to exchange some code!

Tools: DGJPP, NASM, GRUB.
Code: osdev.org, osdever.net

NTDLS
I don't have a floppy disk reader in my computer, but I guess I don't need one for floppy images. Your instructions seem accurate except that I use Linux... anything particular for that OS?
luiscubal
Well, here I fall short – My Linux experience is very limited. From what I understand: Creating a floppy image and copying files to it is much simpler than in windows, but any answers from me in that arena would probably just be misdirecting. However, look into VMWare for Linux. It's Good stuff!
NTDLS
Linux: the compiler is obviously gcc, not djgpp (which itself is a port of gcc).
Tadeusz A. Kadłubowski
A: 

You might be interested in looking at HelenOS. Its a from scratch microkernel that has been ported to many architectures (boots just fine on bare metal) developed using simulators such as Simics and QEMU.

We use a static grub that is copied to the final ISO during the build process. Some things just have to be that way until the OS becomes self hosting. I highly recommend NOT implementing your own userspace C library unless you really do want to do everything from scratch .. you'll become self hosting much sooner :)

Though Simics is non-free, I highly recommend it (and its built in debugging/profiling tools) while making your kernel. Once you have some kind of kernel console and logger in place, QEMU does a very nice job.

Tim Post
A: 

The first question that you need to ask yourself is what hardware architecture are you targeting? I'll assume for the sake of this discussion that you are targeting the IA_32 architecture, which would probably be a wise choice as there is plenty of readily-available documentation on that processor.

If you're truly serious about this undertaking, then you will definitely want to run your debug/code/build/deploy cycle against an emulator or VM. Someone mentioned BOCHS, which is very popular. If emulation speed is your thing, there is also an emulator called Qemu that is faster than BOCHS.

I'd suggest that your development environment run under Linux or Windows, which again would probably be a wise choice due to the available documentation for those dev environments.

Make is your friend. Use it to automate the build/execute process. I'd advise you to pick your toolsets/compilers up front, and spend some time learning them well. It will save you in the long run.

Petey