Testbed Idea: Simulate a kernels environment with C/posix
Posted: Tue Apr 01, 2008 9:38 am
Hi,
while developing my kernel I often screw up. No surprise there. But esspecially early in the game that means the system just crashes. You have no debugger, printk often doesn't work and so on.
So when possible I've written code under linux as normal programs. I've written little wrapper functions that map my kernel functions unto the usual C functions. For example I have a kmalloc() that just calls malloc(). That way I can for example write and debug the code for a list or heap using gdb, valgrind, printf and so on.
Now I'm wondering if one couldn't take this a step further. With mmap() and mprotect() you have control over virtual memory and page mapping. With that you can simulate an MMU. Depending on how low level you want to get you could even provide a shadow page table and catch all write accesses to it and emulate the change with mmap()/mprotect(). Or more highlevel you could have map_page(), unmap_page() or something.
You can implement timer interrupts with alarm() and signal handling for multitasking.
Obviously keyboard input and console output is trivial too.
I wonder if one couldn't implement the XEN paravirtual API with a little bit of C as the lowest level and a collection of higher level modules with common interfaces. Like a kalloc()/kfree() in a memory module.
That way people could pick prooven modules and test their code against it when they experience problems running it in their kernel directly. Think how much easier writing the console driver for your own kernel would be if you could printf() debug info. Or your own printk() function with printf() debugs whats going on?
What do you think? Anyone interested?
MfG
Mrvn
while developing my kernel I often screw up. No surprise there. But esspecially early in the game that means the system just crashes. You have no debugger, printk often doesn't work and so on.
So when possible I've written code under linux as normal programs. I've written little wrapper functions that map my kernel functions unto the usual C functions. For example I have a kmalloc() that just calls malloc(). That way I can for example write and debug the code for a list or heap using gdb, valgrind, printf and so on.
Now I'm wondering if one couldn't take this a step further. With mmap() and mprotect() you have control over virtual memory and page mapping. With that you can simulate an MMU. Depending on how low level you want to get you could even provide a shadow page table and catch all write accesses to it and emulate the change with mmap()/mprotect(). Or more highlevel you could have map_page(), unmap_page() or something.
You can implement timer interrupts with alarm() and signal handling for multitasking.
Obviously keyboard input and console output is trivial too.
I wonder if one couldn't implement the XEN paravirtual API with a little bit of C as the lowest level and a collection of higher level modules with common interfaces. Like a kalloc()/kfree() in a memory module.
That way people could pick prooven modules and test their code against it when they experience problems running it in their kernel directly. Think how much easier writing the console driver for your own kernel would be if you could printf() debug info. Or your own printk() function with printf() debugs whats going on?
What do you think? Anyone interested?
MfG
Mrvn