Mechanisms for switching to kernel mode from user mode...

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!
Locked
jasonc122
Member
Member
Posts: 27
Joined: Fri Jan 01, 2010 7:51 am

Mechanisms for switching to kernel mode from user mode...

Post 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.
H Technology Solutions - Business Operating System Specialists
User avatar
AJ
Member
Member
Posts: 2646
Joined: Sun Oct 22, 2006 7:01 am
Location: Devon, UK
Contact:

Re: Mechanisms for switching to kernel mode from user mode...

Post 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...
User avatar
Colonel Kernel
Member
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...

Post 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. :roll:

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:
  1. Too much overtime at work
  2. Got married
  3. My brain got stuck in an infinite loop while trying to design the memory manager
Don't let this happen to you!
skyking
Member
Member
Posts: 174
Joined: Sun Jan 06, 2008 8:41 am

Re: Mechanisms for switching to kernel mode from user mode...

Post 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).
Locked