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

Discussions on more advanced topics such as monolithic vs micro-kernels, transactional memory models, and paging vs segmentation should go here. Use this forum to expand and improve the wiki!
Post Reply
User avatar
piranha
Member
Member
Posts: 1391
Joined: Thu Dec 21, 2006 7:42 pm
Location: Unknown. Momentum is pretty certain, however.
Contact:

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

Post 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
SeaOS: Adding VT-x, networking, and ARM support
dbittman on IRC, @danielbittman on twitter
https://dbittman.github.io
cyr1x
Member
Member
Posts: 207
Joined: Tue Aug 21, 2007 1:41 am
Location: Germany

Post by cyr1x »

What is the point of having a kernel in Ring3, it can't do anything, as it isn't a normal thread.
User avatar
piranha
Member
Member
Posts: 1391
Joined: Thu Dec 21, 2006 7:42 pm
Location: Unknown. Momentum is pretty certain, however.
Contact:

Post 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
SeaOS: Adding VT-x, networking, and ARM support
dbittman on IRC, @danielbittman on twitter
https://dbittman.github.io
cyr1x
Member
Member
Posts: 207
Joined: Tue Aug 21, 2007 1:41 am
Location: Germany

Post by cyr1x »

That doesn't surprise me. As the kernel assumes/needs to run in Ring0 to handle syscalls, paging, etc..
User avatar
piranha
Member
Member
Posts: 1391
Joined: Thu Dec 21, 2006 7:42 pm
Location: Unknown. Momentum is pretty certain, however.
Contact:

Post by piranha »

Right, well, this way the following kernel code does run in ring0.

The other now exits, probably better.

-JL
SeaOS: Adding VT-x, networking, and ARM support
dbittman on IRC, @danielbittman on twitter
https://dbittman.github.io
User avatar
Brendan
Member
Member
Posts: 8561
Joined: Sat Jan 15, 2005 12:00 am
Location: At his keyboard!
Contact:

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

Post 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
For all things; perfection is, and will always remain, impossible to achieve in practice. However; by striving for perfection we create things that are as perfect as practically possible. Let the pursuit of perfection be our guide.
davidv1992
Member
Member
Posts: 223
Joined: Thu Jul 05, 2007 8:58 am

Post 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)
cyr1x
Member
Member
Posts: 207
Joined: Tue Aug 21, 2007 1:41 am
Location: Germany

Post by cyr1x »

This would likely be a nanokernel, but the point in this thread was to have the _same_ code in ring0 and ring3.
User avatar
t0xic
Member
Member
Posts: 216
Joined: Sat May 05, 2007 3:16 pm
Location: VA
Contact:

Post by t0xic »

Post Reply