Page 1 of 1

Two kernels? One in ring 0 another in ring 3?

Posted: Sun Mar 16, 2008 12:10 pm
by piranha
So, I got usermode working...
anyway...
Because when you move into usermode you get everything including the kernel code after the call switched, why not fork() the kernel?
Does anyone see a problem with this form of code?

Code: Select all

int ul;
if(!(ul=fork())) MoveToUserMode(); //Creates a second kernel process, one in usermode

if(!ul){
    //Usermode
    execute_init; //Note: The actual code for these are long asm() commands
    exit;
}

if(!ul){
    //Usermode kernel
    for(;;) delay(100); //Sleeps for a second and repeats (basically do nothing for now)
} else {
    //Kernel mode kernel
    for(;;) schedule();
}
It does work, just does anyone see problems?

-JL

Posted: Sun Mar 16, 2008 12:23 pm
by cyr1x
What is the point of having a kernel in Ring3, it can't do anything, as it isn't a normal thread.

Posted: Sun Mar 16, 2008 12:30 pm
by piranha
Doesn't this code

Code: Select all

MoveToUserLand();

if(!fork())
      init();

for(;;);
moves everything to userland? Including the kernel code after it? I tried calling a kernel function after all that and it general protection faulted.

-JL

Posted: Sun Mar 16, 2008 12:33 pm
by cyr1x
That doesn't surprise me. As the kernel assumes/needs to run in Ring0 to handle syscalls, paging, etc..

Posted: Sun Mar 16, 2008 12:36 pm
by piranha
Right, well, this way the following kernel code does run in ring0.

The other now exits, probably better.

-JL

Re: Two kernels? One in ring 0 another in ring 3?

Posted: Sun Mar 16, 2008 4:34 pm
by Brendan
Hi,
piranha wrote:Because when you move into usermode you get everything including the kernel code after the call switched, why not fork() the kernel?
If there's anything in the kernel that can run at CPL=3, then it should be removed from the kernel and put into a library or something. That leaves a total of zero bytes of kernel code that's actually useful at CPL=3 .. ;)


Cheers,

Brendan

Posted: Sat Mar 22, 2008 1:17 pm
by davidv1992
Actually, I don't agree with you on that. Some functions normally handled by a kernel could actually be done in user mode, whilst it would be still an advantage to have them close to the kernel. Things like drivers higher up in a driver stack that do not call hardware directly (ie do not use ports or listen to interupts in a direct way, only through some lower (bus) level driver)

Posted: Sat Mar 22, 2008 2:07 pm
by cyr1x
This would likely be a nanokernel, but the point in this thread was to have the _same_ code in ring0 and ring3.

Posted: Sun Mar 23, 2008 11:07 am
by t0xic