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.
Mechanisms for switching to kernel mode from user mode...
Mechanisms for switching to kernel mode from user mode...
H Technology Solutions - Business Operating System Specialists
Re: Mechanisms for switching to kernel mode from user mode...
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...
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...
- Colonel Kernel
- Member
- Posts: 1437
- Joined: Tue Oct 17, 2006 6:06 pm
- Location: Vancouver, BC, Canada
- Contact:
Re: Mechanisms for switching to kernel mode from user mode...
-10 points for using a cliché that's at least 15 years old.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?
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).
Top three reasons why my OS project died:
- Too much overtime at work
- Got married
- My brain got stuck in an infinite loop while trying to design the memory manager
Re: Mechanisms for switching to kernel mode from user mode...
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).
http://wiki.osdev.org/System_Calls
You even don't have to stick to your original choice (linux didn't and windows didn't).