How does Linux remember its kernel stack pointer?

I know that on Linux there are two types of stack: a user stack for each user thread and Kernel Stack for kernel threads (but 1 process). Interrupts, more precisely, interrupt procedures, are bridges between these two modes, the kernel (0) and the user (3). The interrupt vector table allows the processor to load the right instruction address into the PC register, but how does the stack pointer register change when it switches in kernel mode? Subroutines indicate where is the kernel stack before its first instruction? Or does the processor use two stack pointer registers (do I really doubt it)?

How does “return from interrupt” know where to return? Is the circuit board stored on the kernel stack or elsewhere?

Please feel free to fix it, I said it is true.

Many thanks for your help.

+4
source share
1 answer

The kernel kernel stack in the Linux kernel is stored in task_struct->stack. Where and how this happens depends entirely on the platform. Some platforms may not save it as described above. But then you can use task_stack_page()to search the stack.

and

When you enter the interrupt handler, the PC is stored in the kernel stack. When you return from Interrupt, this computer boots from the kernel stack.

+2
source

All Articles