Implementation Principles of ARM Linux system calls

Source: Internet
Author: User
We all know that Linux applications must use system calls to access the kernel to switch from USR mode to SVC mode. Let's take a look at its implementation process. System calling is a service provided by the operating system of the operating system. User Programs reference various services provided by the kernel through various system calls. The execution of system calls puts user programs into the kernel, this is completed by SWI soft interruption. The Soft Interrupt corresponding to the Linux kernel system call corresponding to the at91rm9200 processor is defined as follows: # If defined (_ thumb _) // thumb mode # DEFINE _ syscall (name) \ "Push {R7} \ n \ t" \ "mov R7, #" _ sys1 (_ nR _ # name) "\ n \ t" \ "SWI 0 \ n \ t" \ "Pop {R7}" # else // arm mode # DEFINE _ syscall (name) "SWI \ t" _ sys1 (_ nR _ # Name) "\ n \ t" # endif # DEFINE _ sys2 (X) # X # DEFINE _ sys1 (x) _ sys2 (X) # DEFINE _ nr_syscall_base 0x900000 // This is OS _number <20 operation value # DEFINE _ nr_open (_ nr_syscall_base + 5) // 0x900005 For example: When the open system is called, the library function will eventually call _ syscall (Open). After the macro is expanded, it is SWI #__ nr_open, that is, SWI #0x900005 trigger interrupt, interrupt number 0x900005 stored in [LR, #-4] address, processor jump to arch/ARM/kernel/entry-common.S vector_swi read [LR, #-4] The interrupt number in the address, and then query the sys_call_table system call table in arch/ARM/kernel/entry-common.S. in S, the sequence number of __nr_open in the table is _ syscall_start :.... long symbol_name (sys_open) // 5th... pass the content in sys_call_table [5] to the PC, and the system enters the sys_open function to handle the actual open action.: The file where some function data is used, as shown below: ARCH/ARM/kernel/CILS. s declares the system call function include/ASM-arm/unistd. h defines the call number rules for system calls vector_swi defined in arch/ARM/kernel/entry-common.Svector_IRQ defined in arch/ARM/kernel/entry-armv.Svector_FIQ defined in arch/ARM/kernel/entry-armv.Sarch/ARM/ sys_call_table is defined in the kernel/entry-common.S :. type sys_call_table, # objectentry (sys_call_table) # include "CILS. s "// set CILS. the content in S is sequentially linked to the source program here: entry (vector_swi) save_user_regszero_fpget _ Scno // dump the interrupt number in [LR, #-4] To scno (r7) arm710_bug_check scno, IP # ifdef config_alignment_trapldr IP, _ cr_alignmentldr IP, [IP] MCR P15, 0, IP, C1, C0 @ update control register # endifenable_irq ipstr R4, [Sp, #-s_off]! @ Push ipvth argget_current_task tskldr IP, [Tsk, # tsk_ptrace] @ check for syscall tracingbic scno, scno, #0xff000000 @ mask off SWI op-code // # define OS _number 9 [entry-header.S] // so for the above example open system call number scno = 0x900005 // EOR scno, scno, #0x900000 // and then scno = 0x05eor scno, scno, # OS _number <20 @ check OS number // sys_call_table indicates CILS. s content adr tbl, sys_call_table @ load syscall table pointertst IP, # pt_tracesys @ Are we tracing syscils? BNE _ sys_traceadrsvc Al, LR, ret_fast_syscall @ return addresscmp scno, # nr_syscils @ check upper syscall limit // execute sys_open function ldrcc PC, [TBL, scno, LSL #2] @ call sys _ * routineadd R1, SP, # s_off2: mov why, #0 @ no longer a real syscallcmp scno, # armswi_offseteor r0, scno, # OS _number <20 @ put OS number backbcs symbol_name (arm_syscall) B symbol_name (sys_ni_syscall) @ not private func/** this is t He really slow path. we're re going to be doing * context switches, and waiting for our parent to respond. */_ sys_trace: Add R1, SP, # s_offmov r0, #0 @ trace entry [IP = 0] BL symbol_name (syscall_trace) // gliethttp [entry-header.S] // like ADR, but force SVC mode (if required ). macro adrsvc, Cond, Reg, labeladr \ cond \ Reg, \ label. endm // disassembly: // Add LR, PC, #16; LR = _ sys_trace_return */adrsvc al, LR, _ sys_trace_return @ return addressadd R1, SP, # s_r0 + s_off @ pointer to regscmp scno, # nr_syscils @ check upper syscall limitldmccia R1, {R0-R3} @ have to reload R0-r3ldrcc PC, [TBL, scno, LSL #2] @ call sys _ * routineb 2B _ sys_trace_return: Str r0, [Sp, # s_r0 + s_off]! @ Save returned r0mov R1, spmov r0, #1 @ trace exit [IP = 1] BL symbol_name (syscall_trace) B ret_disable_irq.align 5 # ifdef config_alignment_trap.type _ cr_alignment, # object _ cr_alignment :. word symbol_name (cr_alignment) # endif. type sys_call_table, # objectentry (sys_call_table) # include "CILS. s"

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.