System Call note-based on ARM

Source: Internet
Author: User

Related Files in kernel:

ARCH/ARM/kernel/CILS. s declares the system call function and sys_call_table
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.

==========================================================

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. The user program uses various system calls to reference various services provided by the kernel. The execution of system calls puts the user program into the kernel, this is completed by SWI soft interruption.

# DEFINE _ syscall (name) "SWI/t" _ sys1 (_ nR _ # Name) "/n/t" // arm Mode

# 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). The macro is SWI #__ nr_open, that is, SWI #0x900005 triggers the interruption, 0 X in the [LR, #-4] address, the processor jumps to the ARCH/ARM/kernel/entry-common.S vector_swi read [LR, #-4] address in the interrupt number, 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
_ 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.

 

========================================================== ==========

In section 2.6.21, you will find that you cannot avoid this concept. What is Eabi?

In the kernel, the interview with Eabi and oabi is actually relative to the method of system calling. Of course, the system we call is limited to the arm system.
Eabi (Extended Abi) is a new method of calling the system.

MoV R7, # num
SWI 0x0

The original system call method is as follows,
SWI (# num | 0x900000) (0x900000 is a magic value)

That is to say, the original call method (old Abi) is implemented by following the call number in the SWI command. Now it is based on the value in R7.

Now let's look at two macros. One is
Config_oabi_compat indicates compatibility with the old Abi.

The other is
Config_aeabi indicates specifying the current method as Eabi.

These two macros can be configured at the same time, neither deserve nor can be configured.

You can refer to: http://free-electrons.com/doc/arm-linux.pdf

========================================================== ========================

Vector_swi defined in arch/ARM/kernel/entry-common.S

Ret_fast_syscall ret_slow_syscall ret_from_fork call-calls.S-to-init-syscalltable

 

ARCH/ARM/kernel/entry-header.S

Restore_user_regs

Store_user_sp_lr

Load_user_sp_lr

 

Scno. req R7 @ syscall number
TBL. req R8 @ syscall table pointer
Why. req R8 @ Linux syscall (! = 0)
Tsk. req R9 @ current thread_info

 

Asmlinkage... parameters must be retrieved from the stack rather than the Register

 

Stack switching refer to the Register mode in ARM architecture reference

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.