system calls

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
pepito

system calls

Post by pepito »

I like to know which way is better to implement system calls:

1) Call gates
2) Interrupts

Why?

Thank you

pepito
mikeleany

RE:system calls

Post by mikeleany »

Whichever way you want, because it's your OS. I'm going with call gates though, because they have a built-in way of passing parameters between privilege levels. You can also have more call gates than you can interrupts, but that doesn't really matter too much, because you can use one interrupt (or call gate) for multiple functions.
pepito

RE:system calls

Post by pepito »

How the 'built-in way of passing parameters' works? It sounds interesting!
mikeleany

RE:system calls

Post by mikeleany »

What I meant was that with interrupts, you (usually) can't pass parameters on the stack in protected mode, because your interrupt service routing (ISR) is usually more privileged than your application, so when your ISR is called, the processor switches to a different stack for a different privilege level. So any parameters you may have tried to pass to the interrupt on the stack wouldn't be on the new stack. Of course, there are ways that you can get around that, and some people just pass the parameters through registers instead of pushing them onto the stack.
With a call gate, you still have the stack switch, but the difference is that you can tell the CPU to copy your parameters from the old stack to the new stack for you.
To learn more about call gates, stack switching and interrupts, I suggest you refer to section 4.8 (especially 4.8.2 - 4.8.5) and chapter 5 of the Intel Manual Volume 3.
http://developer.intel.com/design/Pentium4/manuals/
pepito

RE:system calls

Post by pepito »

Thank you very much, I'll see the manual...

pepito
pepito

RE:system calls

Post by pepito »

I read the manual and I try to write a little example, but it fails.

I just insert a call gate (DPL=3, 0 parameters) at my GDT, and call it from the KERNEL (DPL=0) with the instruction:

call 0x820:0

But the computer restart!

What's wrong?
Where may I get some working example?

Thank you.
pepito

RE:system calls

Post by pepito »

I get it works!
I was an error at the GDT, but now is working...

Thank you xSadar!
Post Reply