Page 1 of 1

Interruptable kernel syscalls - again...

Posted: Wed Oct 17, 2007 3:36 pm
by mutex
I have been away from my oscode for some time now.. Had a rough time last time when i got stuck with the interruptable syscalls..

Now.. I have a couple of questions.

1. How many have software task switching using the tss just for context/stack switch
2. How many have syscalls working?
3. How many have interruptable syscalls??

I assume you all have atleast ring0 & 3 for kernel and user space..

My design is like this:
task code + task stack + task kernel stack for kernel work

In theory my design should be ok, but i have an issue with this. Interruptable syscalls work, but it seems that on exit from the syscall some stack/flags/segments gets fucked up.. Im not been able to isolate it down yet since i broke down last time :D

If someone have 1+2+3 implemented, and have some good tips about this i would appriciate it. I assume there are multiple pits to fall into in this area... :)

Posted: Wed Oct 17, 2007 4:08 pm
by Combuster
Well, my previous kernel had software task switching - with a single TSS so all I needed to do was to change esp0 in addition to changing the rest of the CPU state. If that qualifies, then I have point 1
I certainly have point 2 and 3.

Basically, all I did was making the task switcher independent of the privilege level it preempted. I push all the (segment) registers to the stack, record the current ESP then pick a new task, restore ESP, overwrite TSS.ESP0 with the new value, pop all the registers then IRET. This should get the original state back in all cases.
For the syscalls I used a simple INT instruction for all common cases. I had some code dealing with systenter/syscall and related things but I never bothered to complete it since it isn't really important.
Basically what it boils down to is not to depend on whatever is already present on the stack and having a kernel stack for each thread.

I wrote my implementation in assembly, you can find it here:
http://dimensionalrift.homelinux.net/co ... stage3.asm

Posted: Wed Oct 17, 2007 4:55 pm
by mutex
Thanks alot.

Im sure my design theory is right, and it just boils down to the correct implementation and bugs that haven't been sorted out i guess, but anyway i needed some comfort to get my hopes up again ready for fixing it :D Beeing stuck in same problem for a long time kills the motivation.

I'll look into your code just to get an overview and see how your structure around the task switching is.. I might get some ideas.

Nice assembly btw.. Havent coded pure asm for many years, but in late 90's i did some demostuff with a firend.. Now we only work on high level tools such as C :lol:

I'll try to fix up my problems in the code and get going.. I have very mouch higher level code in place so its basically just a urge to get the interruptable kernel working to really unleash the potential of my hobby code :)

-
Thomas

Re: Interruptable kernel syscalls - again...

Posted: Thu Oct 18, 2007 1:33 am
by JamesM
thomasnilsen wrote:I have been away from my oscode for some time now.. Had a rough time last time when i got stuck with the interruptable syscalls..
They can be a *****!
Now.. I have a couple of questions.

1. How many have software task switching using the tss just for context/stack switch
Me! I use software task switching, so one TSS for all tasks and I push the registers to the kernel stack manually.
2. How many have syscalls working?
Me! I have two types of syscall:

Standard ones that use an interrupt interface: This is used for fork(), and yield() so far only (they require a pushed context to operate)

The other interface uses sysenter/sysexit pairs and is the basis for most of my kernel-land functions. This enables me to just do

Code: Select all

void func()
{
  START_KERNEL;
  do_stuff();
  END_KERNEL_VOID;
}
For a syscall. Easy! :)
3. How many have interruptable syscalls??
Me! All important stuff like the kernel heap operations are locked via mutexes.


Any more specific info just ask.