Question

I know that when a system call occurs then a software interrupt is generated. This software interrupt makes the cpu mode to switch from user mode to kernel mode. As per my understanding, during the hardware interrupt context switch happens from the user (process) context to interrupt context. But does the same thing happens during the software interrupt also? I tried lot of documentation also but I could not infer a satisfied answer.

Was it helpful?

Solution

The system call interrupt handler is run in interrupt context, just like any other interrupt handler, but it just switches to the kernel code and then immediately leaves interrupt context.

Please note that most modern CPUs do not implement system calls with software interrupts but with something like SYSCALL.

OTHER TIPS

In case of ARM processors and linux kernel,

During the software interrupt control jumps to the vector_swi routine defined in http://lxr.free-electrons.com/source/arch/arm/kernel/entry-common.S.

346 /*============================================================================= 347 * SWI handler
348 *-----------------------------------------------------------------------------
349 */
350
351 .align 5
352 ENTRY(vector_swi)
353 #ifdef CONFIG_CPU_V7M
354 v7m_exception_entry
355 #else
356 sub sp, sp, #S_FRAME_SIZE
.
.
.
461 sub lr, lr, #4
462 str lr, [sp, #S_PC]
463 b ret_fast_syscall
464 #endif
465 ENDPROC(vector_swi)

The current execution context is stored at the stack of the same process which executed the swi instruction. And system starts executing routine defined above.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top