Page 1 of 1
Mechanisms for switching to kernel mode from user mode...
Posted: Thu Jan 07, 2010 7:33 am
by jasonc122
Afternoon all,
Just fishing for ideas on different ways operating systems go from executing user mode code to kernel mode code. How does your OS achieve this?
I know that Micro$oft Winblows uses an INT instruction to make the jump from user mode to kernel mode. Does anybody know how Linux gets to kernel mode from user mode code?
Thanks in advance.
Re: Mechanisms for switching to kernel mode from user mode...
Posted: Thu Jan 07, 2010 7:44 am
by AJ
Hi,
Traditionally, Linux uses Int 0x80 for system calls, but it depends what you want. For fast system calls, see SYSENTER/SYSEXIT and SYSCALL/SYSRET. If you want legacy support, you'll also need to provide an interrupt mechanism, though.
If the purpose of you asking this question is for task preemption, use a timer (LAPIC timer if available, PIT otherwise?) on the appropriate IRQ.
Cheers,
Adam
Edit: Of course, you can always use call gates, but with SYSENTER / SYSCALL, these are now legacy too...
Re: Mechanisms for switching to kernel mode from user mode...
Posted: Thu Jan 07, 2010 10:09 am
by Colonel Kernel
jasonc122 wrote:I know that Micro$oft Winblows uses an INT instruction to make the jump from user mode to kernel mode. Does anybody know how Linux gets to kernel mode from user mode code?
-10 points for using a cliché that's at least 15 years old.
Windows will use different mechanisms depending on what the hardware supports. INT was used before sysenter/sysexit/syscall/sysret came along. Now, the OS creates thunks that use whatever instruction is appropriate for the CPU it's running on. Apps call ntdll.dll, which in turn calls these thunks, so apps don't need to be re-compiled to use a different system call mechanism (ntdll.dll doesn't need to be recompiled either, since the thunks are generated on-the-fly).
Re: Mechanisms for switching to kernel mode from user mode...
Posted: Thu Jan 07, 2010 3:39 pm
by skyking
Why bother asking before reading the Wiki?
http://wiki.osdev.org/System_Calls
You even don't have to stick to your original choice (linux didn't and windows didn't).