Running a kernel in user land ?

Question about which tools to use, bugs, the best way to implement a function, etc should go here. Don't forget to see if your question is answered in the wiki first! When in doubt post here.
Post Reply
ineo
Posts: 19
Joined: Wed Oct 18, 2006 3:20 am

Running a kernel in user land ?

Post by ineo »

Hello !

I guess most of you have already heard of User Mode Linux.
I am interested in knowing if any of you already thought of running its own kernel as a guest kernel, in user land.

If you already thought about it or if you know how it is done for other OSes, please share your knowledge.

I plan to introduce this feature in my kernel as soon as paging works properly, because I think it might be a wonderful way to debug it. Running it as a guest OS allow me to debug it with all the tools you have for standard development without the need of an emulator. Of course part of the OS cannot be tested that way, but it stills looks very promising to me.

Regards,
INeo
User avatar
AndrewAPrice
Member
Member
Posts: 2309
Joined: Mon Jun 05, 2006 11:00 pm
Location: USA (and Australia)

Post by AndrewAPrice »

You can't run the entire kernel in user land. You could have a stage one kernel that loads the stage two kernel as a user process.
My OS is Perception.
ineo
Posts: 19
Joined: Wed Oct 18, 2006 3:20 am

Post by ineo »

MessiahAndrw wrote:You can't run the entire kernel in user land. You could have a stage one kernel that loads the stage two kernel as a user process.
Yes I thought I could define a specific architecture as a wrapper for my core OS functions. This way I could emulate the low level stuff that cannot be done in userland, and still test higher level stuff.

A bit like coLinux.

I am still documenting on that to see how much work it represents to have such a feature. Maybe it is not worth it, but since I have a microkernel, writing it for another architecture should be fast enough.
anon19287473
Member
Member
Posts: 97
Joined: Thu Mar 15, 2007 2:27 pm

Re: Running a kernel in user land ?

Post by anon19287473 »

ineo wrote:Hello !

I guess most of you have already heard of User Mode Linux.
I am interested in knowing if any of you already thought of running its own kernel as a guest kernel, in user land.

If you already thought about it or if you know how it is done for other OSes, please share your knowledge.

I plan to introduce this feature in my kernel as soon as paging works properly, because I think it might be a wonderful way to debug it. Running it as a guest OS allow me to debug it with all the tools you have for standard development without the need of an emulator. Of course part of the OS cannot be tested that way, but it stills looks very promising to me.

Regards,
INeo
It may be PLAUSIBLE, but probably not worth the work. It would be possible in an OS like DOS, or DexOS (i think), which give you full hardware access.
User avatar
mystran
Member
Member
Posts: 670
Joined: Thu Mar 08, 2007 11:08 am

Post by mystran »

Whether there's any point in doing that depends on what you want to debug..

I would suggest you instead try to debug those parts of your system that are easy to separate from rest of it. Say, trivial example would be a heap manager (often called malloc) which you could just take and dump to some random program like your webbrowser to deal with (easy to do in Linux, never tried on anything else).

Same would go with a GUI. Or a filesystem. Those will need a bit more wrapper code around them, but still a lot less than running a full system on top of another.

Once you've dealt with the easy parts, just use a normal emulator to debug. Bochs for example has lots of nice features to help you with, including the ability to debug stuff running inside it (if you compile that in), with a normal debugger (GDB mainly, though you should be able to use frontends I think).

And ofcourse providing support for GDB over serial line isn't very hard either, once your kernel has reached the point where it doesn't crash every 2 seconds.... until then I'd just debug in Bochs. :)
The real problem with goto is not with the control transfer, but with environments. Properly tail-recursive closures get both right.
anon19287473
Member
Member
Posts: 97
Joined: Thu Mar 15, 2007 2:27 pm

AROS

Post by anon19287473 »

I would look at AROS. It's an Amiga clone, for x86. They first developed it with Linux as a host system, using wrapper on top of X11, and then when they had full functionality, started to write a native kernel beneath it. Something to look at.
User avatar
mystran
Member
Member
Posts: 670
Joined: Thu Mar 08, 2007 11:08 am

Post by mystran »

AROS has the advantage of running everything in a single virtual memory space, which simplifies the whole thing a LOT, because in order to actually separate memory spaces running on top of another OS you need to use several processes, one of each memory space, at which point you need to use shared memory to have globally mapped regions, and need some voodoo if your kernel ever needs to switch memory space on the fly...

Alternatively one could completely swap out each process on context switch time, swapping the other in, essentially replacing the memory space without really using separate spaces. Probably easier to leverage existing virtual memory manager, though this strategy can't work for simulating SMP kernels (unless you do a hybrid and simulate each CPU in a separate process, yet replacing memory contents on switch in each process).

No idea if Usermode Linux does either.. Linux is known to run with or without virtual memory after all. If you design your kernel to not rely on existense of virtual memory, such that it can be run without it, then it'll ofcourse be easier to run in usermode.
The real problem with goto is not with the control transfer, but with environments. Properly tail-recursive closures get both right.
ineo
Posts: 19
Joined: Wed Oct 18, 2006 3:20 am

Post by ineo »

Thanks for your answers.

Finally I will try to implement some kind of wrapper on top of the POSIX API. Since I am doing a microkernel the modules should be able to run properly with this wrappers.

The gdb over serial is probably the best idea for kernel mode debugging.

At least I will experiment that way, and I come back to you as soon as I have any news or problem ;)
User avatar
mystran
Member
Member
Posts: 670
Joined: Thu Mar 08, 2007 11:08 am

Post by mystran »

Well, yeah, for running userspace servers in a microkernel system, I think it's workable to write a small wrapper library that provides some kind of (not necessarily efficient) implementation of the microkernel services on top of a host OS and then just run them on said host OS as normal processes.. :)

As a hint, you might want to write a small server on the host which implements some of the functionality of the microkernel, and to which your OS servers can connect through unix sockets (using a library looking like your native interface). :)
The real problem with goto is not with the control transfer, but with environments. Properly tail-recursive closures get both right.
Post Reply