Detailed analysis of ArmLinux Operating System Call Process

Source: Internet
Author: User
Article Title: detailed analysis of the ArmLinux Operating System Call process. Linux is a technology channel of the IT lab in China. Includes basic categories such as desktop applications, Linux system management, kernel research, embedded systems, and open source.

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 the swi Soft Interrupt.

     
      
# 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 an 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 triggers the interruption, interrupt number 0x900005 stored in [lr, #-4] address, processor jump to arch/arm/kernel/entry-common.S vector_swi read the interrupt number in [lr, #-4] address, then query the sys_call_table system call table in the arch/arm/kernel/entry-common.S. defined in S, __nr_open corresponds to the sequence number in the table

     
      
.... 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 process the actual open action. Note: The files of some function data used are as follows: arch/arm/kernel/call. 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 here
     

_ Syscall_start:

Source program:

     
      
ENTRY (vector_swi) save_user_regs zero_fp get_scno // dump the interrupt number in [lr, #-4] To scno (r7) arm710_bug_check scno, ip # ifdef CONFIG_ALIGNMENT_TRAP ldr ip, _ cr_alignment ldr ip, [ip] mcr p15, 0, ip, c1, c0 @ update control register # endif enable_irq ip str r4, [sp, #-S_OFF]! @ Push every th arg get_current_task tsk ldr ip, [tsk, # TSK_PTRACE] @ check for syscall tracing bic 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 = 0x05 eor scno, scno, # OS _NUMBER <20 @ check OS number // sys_call_table indicates CILS. S content adr tbl, sys_call_table @ load syscall table pointer tst ip, # PT_TRAC ESYS @ are we tracing syscils? Bne _ sys_trace adrsvc al, lr, ret_fast_syscall @ return address cmp scno, # nr_syscils @ check upper syscall limit // execute the sys_open function ldrcc pc, [tbl, scno, lsl #2] @ call sys _ * routine add r1, sp, # S_OFF2: mov why, #0 @ no longer a real syscall cmp scno, # ARMSWI_OFFSET er0 or, scno, # OS _NUMBER <20 @ put OS number back bcs SYMBOL_NAME (arm_syscall) B SYMBOL_NAME (sys_ni_syscall) @ not private func /** This is the 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_OFF mov 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, label adr \ cond \ reg, \ label. endm // disassembly: // add lr, pc, #16; lr = _ sys_trace _ Return */adrsvc al, lr, _ sys_trace_return @ return address add r1, sp, # S_R0 + S_OFF @ pointer to regs cmp scno, # nr_syscils @ check upper syscall limit ldmccia r1, {r0-r3} @ have to reload r0-r3 ldrcc pc, [tbl, scno, lsl #2] @ call sys _ * routine B 2b _ sys_trace_return: str r0, [sp, # S_R0 + S_OFF]! @ Save returned r0 mov r1, sp mov 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.