Everyone knows that if a Linux application wants to access the kernel, it must use a system call to switch from usr mode to svc mode. Let's take a look at its implementation process.
System call is a service provided by the OS operating system. User programs use various system calls to reference various services provided by the kernel. The execution of system calls causes user programs to fall into the kernel, and the falling action is completed by the SWI soft interrupt.
The soft interrupt corresponding to the Linux 2.4.19 kernel system call corresponding to the at91rm9200 processor is defined as follows:
#if defined(__thumb__) //thumb模式
#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 the OS_NUMBER "" 20 operation value
#define __NR_open (__NR_SYSCALL_BASE+ 5) //0x900005
For example, the open system call, the library function will eventually call __syscall (open), which is expanded to swi #__NR_open after macro expansion, that is, swi #0x900005 triggers an interrupt, and the interrupt number 0x900005 is stored in the address [lr, #-4]. The processor jumps to vector_swi in arch/arm/kernel/entry-common.S to read the interrupt number in the address [lr, #-4], and then queries the sys_call_table system call table in arch/arm/kernel/entry-common.S. The content of this table is defined in arch/arm/kernel/calls.S, and the corresponding sequence number of __NR_open in the table is
__syscall_start:
。。.
.long SYMBOL_NAME(sys_open) //5th
。。.
The content in sys_call_table[5] is passed to pc, and the system enters the sys_open function to process the actual open action.
Note: The files where some function data are used are as follows
arch/arm/kernel/calls.S declares the system call function
include/asm-arm/unistd.h defines the call number rules for system calls
vector_swi is 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 "calls.S" //Link the contents of calls.S here 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 fifth 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 open system call number in the above example, scno=0x900005
//eor scno,scno,#0x900000
//After that scno=0x05
eor scno, scno, #OS_NUMBER 《《 20 @ check OS number
//The sys_call_table item is the content of calls.S
adr tbl, sys_call_table @ load syscall table pointer
tst ip, #PT_TRACESYS @ are we tracing syscalls?
bne __sys_trace
adrsvc al, lr, ret_fast_syscall @ return address
cmp scno, #NR_syscalls @ check upper syscall limit
//Execute 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 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)
/*
//2007-07-01 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_syscalls @ 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 “calls.S”
Previous article:ARM architecture: How to pass more than four function call parameters
Next article:The difference and usage of ARM function pointer and pointer function
- Popular Resources
- Popular amplifiers
- Naxin Micro and Xinxian jointly launched the NS800RT series of real-time control MCUs
- How to learn embedded systems based on ARM platform
- Summary of jffs2_scan_eraseblock issues
- Application of SPCOMM Control in Serial Communication of Delphi7.0
- Using TComm component to realize serial communication in Delphi environment
- Bar chart code for embedded development practices
- Embedded Development Learning (10)
- Embedded Development Learning (8)
- Embedded Development Learning (6)
Professor at Beihang University, dedicated to promoting microcontrollers and embedded systems for over 20 years.
- Intel promotes AI with multi-dimensional efforts in technology, application, and ecology
- ChinaJoy Qualcomm Snapdragon Theme Pavilion takes you to experience the new changes in digital entertainment in the 5G era
- Infineon's latest generation IGBT technology platform enables precise control of speed and position
- Two test methods for LED lighting life
- Don't Let Lightning Induced Surges Scare You
- Application of brushless motor controller ML4425/4426
- Easy identification of LED power supply quality
- World's first integrated photovoltaic solar system completed in Israel
- Sliding window mean filter for avr microcontroller AD conversion
- What does call mean in the detailed explanation of ABB robot programming instructions?
- STMicroelectronics discloses its 2027-2028 financial model and path to achieve its 2030 goals
- 2024 China Automotive Charging and Battery Swapping Ecosystem Conference held in Taiyuan
- State-owned enterprises team up to invest in solid-state battery giant
- The evolution of electronic and electrical architecture is accelerating
- The first! National Automotive Chip Quality Inspection Center established
- BYD releases self-developed automotive chip using 4nm process, with a running score of up to 1.15 million
- GEODNET launches GEO-PULSE, a car GPS navigation device
- Should Chinese car companies develop their own high-computing chips?
- Infineon and Siemens combine embedded automotive software platform with microcontrollers to provide the necessary functions for next-generation SDVs
- Continental launches invisible biometric sensor display to monitor passengers' vital signs
- Please recommend a PAL video signal equalization chip or amplifier chip
- EEWORLD University ----TI Precision Laboratory - Isolation
- New courses are online at the beginning of the school year! Learn the latest TI training courses and win gifts
- After reviewing ten wireless sports Bluetooth headsets, I will teach you how to buy headsets under 300 yuan
- This week's highlights
- When encountering refurbished chips again, how to identify new and old chips?
- Intel invests $600 million in Clearwire, optimistic about WiMAX technology
- Brushless motor MOS
- JPEG encoding
- How are the engineers in Hubei and Wuhan doing during this epidemic?