System calls
The function implementation body in kernel space, provided to the application to use, is a system call.
Work flow
1. Switch from user space to kernel space via soft interrupt (Swi). Entry-common. The entry (VECTOR_SWI) in S is used to handle soft interrupts. System calls typically remove the system call number from the R7 register.
2. Find the calling system call function from the system call table by the system call number. is also a calls. s file to find the function that corresponds to the system call number.
Implementing system Calls
1. Open .../kernel/printk.c, add system call function
void Sys_iprint () {
PRINTK ("This is a new system call!\n");
}
2. Open .../arch/arm/kernel/calls. S, add system call entry
Call (Sys_iprint)
3. Open .../arch/arm/include/asm/unistd.h, conditional system call number
#define __NR_IPRINT (__nr_syscall_base+365)
4. Recompile the kernel
Make clean
Make Uimage arch=arm cross_compile=arm-liunx-
5. Writing the application
//System Call Interfacevoidipirnt () {__asm__ ("Ldr R7, =365\n" "swi\n" : : :"Memory" );}intMainintargcChar**argv) {ipirnt (); return 0;}
6. Compiling the application
Arc-linux-gcc–static Syscall.c–o Syscall
[Country EMBED strategy] [109] [Linux system calls]