What is the need of using two different stacks in same program? How does trap change the current stack of program from user stack to kernel stack? How does it come back to user
The context of a process (psw, state of registers,pc...) is saved in the PCB of the process, in the kernel space of memory, not in the stack. Yes, there is one stack for each user process and more, one stack for each thread in the user space memory. In the kernel, the data structures are shared by the multiples codes of the function in the kernel. The stack is used for the call of procedure and for the local variables, not for saving the context.