Detailed analysis of ARM Linux operating system calling process.

Source: Internet
Author: User
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.

The Soft Interrupt definitions for Linux kernel system calls corresponding to the at91rm9200 processor are 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 // 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, the interrupt code 0x900005 is stored in the [LR, #-4] address, and the processor jumps to arch/ARM/kernel/entry-Common. in S, vector_swi reads the interrupt number in [LR, #-4] address, and then queries the sys_call_table system call table in arch/ARM/kernel/entry-common.S, the table content is in arch/ARM/kernel/CILS. defined in S, __nr_open corresponds to the sequence number in the table

_ Syscall_start:

...
. Long symbol_name (sys_open) // 5th
...
Pass the content in sys_call_table [5] to the PC. The system enters the sys_open function to process the actual open action.

Note: Some function data files used are as follows:
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.S
Vector_irq is defined in arch/ARM/kernel/entry-armv.S
Vector_fiq is defined in arch/ARM/kernel/entry-armv.S

Sys_call_table is defined in arch/ARM/kernel/entry-common.S:
. Type sys_call_table, # object
Entry (sys_call_table)
# Include "call. s" // link the content in call. s in sequence

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]
// Therefore, for the open system call number scno = 0x900005 in the preceding example
// EOR scno, scno, #0x900000
// Then scno = 0x05
EOR scno, scno, # OS _number <20 @ check OS number
// Sys_call_table content whose entry is CILS. s
Adr tbl, sys_call_table @ load syscall table pointer
Tst IP, # pt_tracesys @ 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_off
2: mov why, #0 @ no longer a real syscall
CMP scno, # armswi_offset
EOR r0, 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
// Corresponding 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, # object
Entry (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.