Developing kernels and testing them in virtual machines

后端 未结 5 678
执念已碎
执念已碎 2020-12-28 10:36

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

Unfortunately, kernels are particularly hard to test because they are basically th

相关标签:
5条回答
  • 2020-12-28 10:46

    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.

    0 讨论(0)
  • 2020-12-28 10:51

    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.

    0 讨论(0)
  • 2020-12-28 10:53

    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.

    0 讨论(0)
  • 2020-12-28 11:01

    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

    0 讨论(0)
  • 2020-12-28 11:03

    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 support editing the boot media from the outside using standard tools like dd etc.

    0 讨论(0)
提交回复
热议问题