1
votes

While reading the vector_swi() routine for arm linux system call, I found that r0-r12 registers are copied to the kernel stack(below is the code)

ENTRY(vector_swi)
#ifdef CONFIG_CPU_V7M
    v7m_exception_entry
#else
    sub sp, sp, #S_FRAME_SIZE
    stmia   sp, {r0 - r12}          @ Calling r0 - r12 

As per my understanding, during system call arm enters into svc mode and jumps to vector_swi() routine and begins execution. The sp register of svc mode(sp_svc)points to kernel stack. r0-r12 registers are copied to the kernel stack.

My question is how is the sp (sp_svc) register setup?

How does it know the address of kernel stack? Is this kernel stack same as the process's(the process that called system call) kernel stack?

1

1 Answers

3
votes

On the arm32 architecture, sp (r13) is banked, which means there are physically separate registers for USR and SVC modes.

For each userspace thread, the corresponding kernel thread always exists, and has its stack allocated and the SVC mode r13 points there. On system call entry, the software-visible r13 is switched to the one for SVC mode, and the instructions you point to are executed after that.