Monday, October 20, 2014

How is a system call executed in ARM architecture?


  • In case of x86, interrupt vector 0x80 is used to invoke system call .here 
  • Whereas an exception(SWI) is used to invoke system calls in case of ARM . 
  • The ARM architecture supports seven types of exceptions.(read about ARM exceptions this)
  •  When an exception occurs, execution is forced from a fixed memory address corresponding to the type of exception. 
  • These fixed addresses are called the exception vectors. 
  • These vectors are same as the vectors of x86 interrupt descriptor table.
  • One of the seven exceptions is the software interrupt exception(SWI).
  •  Address of the function to be executed when this exception is raised is stored at the physical address 0x00000008. 
  • The Software Interrupt instruction (SWI) is used to generate the software interrupt exception.
  •  Linux uses this vector to invoke the system calls.
  •  When this exception is generated a function, vector_swi(), is called. 
  • vector_swi() is defined in <arch/arm/kernel/entry-common.S>. vector_swi() gets the system call number in the R7 general-purpose register and finds the system call address in the sys_call_table and invokes it. Registers R0-R6 are used to send arguments to the system calls.

 ENTRY(vector_swi)
354 #ifdef CONFIG_CPU_V7M
355         v7m_exception_entry
356 #else
357         sub     sp, sp, #S_FRAME_SIZE
358         stmia   sp, {r0 - r12}                  @ Calling r0 - r12
359  ARM(   add     r8, sp, #S_PC           )
360  ARM(   stmdb   r8, {sp, lr}^           )       @ Calling sp, lr
361  THUMB( mov     r8, sp                  )
362  THUMB( store_user_sp_lr r8, r10, S_SP  )       @ calling sp, lr
363         mrs     r8, spsr                        @ called from non-FIQ mode, so ok.
364         str     lr, [sp, #S_PC]                 @ Save calling PC
365         str     r8, [sp, #S_PSR]                @ Save CPSR
366         str     r0, [sp, #S_OLD_R0]             @ Save OLD_R0
367 #endif
368         zero_fp
369         alignment_trap ip, __cr_alignment
370         enable_irq
371         ct_user_exit
372         get_thread_info tsk
373 
374         /*
375          * Get the system call number.
376          */
.
.
.


1 comment:

  1. As the demand for AWS professionals continues to soar, choosing the right training institute is pivotal to your success. APTRON Solutions in Noida stands as a beacon of excellence, empowering individuals to master AWS and thrive in the cloud computing era. Elevate your career with our industry-centric AWS Training Institute in Noida and pave the way for a promising future in the world of cloud technology.

    ReplyDelete