Nuttx operating system (5): system call

1.1.1 nuttx system call

Since the application and address space are divided into M-Mode and U-Mode accessible, it is necessary to provide a communication channel between the two. In principle, the kernel should not directly access the application's functions or services, while the application needs Access kernel services, so you only need to provide an interface for applications to access kernel services.

In the nuttx system, the mksyscall tool is used to generate interfaces for users to call and interfaces for use in the kernel based on the file system.csv. During compilation, libproxies.a and libstubs.a are generated.

mksyscall -p system.csv generates an interface for users to call;

mksyscall -s system.csv generates the interface called in the kernel;

The system call interface is defined in syscall/syscall.csv. The first parameter identifies the function name, the second parameter identifies the header file required by this interface, the third parameter identifies the return value type of the function, and the subsequent parameters identify the parameter types required by this interface;

Ø The corresponding system call interface in the kernel

In sys/syscall.h, obtain the enumeration value corresponding to the interface through enum:

After expansion:

enum

{

SYS__exit = 0,

SYS_accept,

…,

SYS_massyscall

}

In syscall/syscall_stublookup.c, the system call interface is managed through an array:

After expansion:

uintptr_t g_stublookup[SYS_nsyscalls] =

{

uintptr_t STUB__exit(int nptr,int),

uintptr_t STUB_accept(int nptr, uintptr_t parm1, uintptr_t parm2, uintptr_t parm3),

}

The kernel interface corresponding to Stub is as follows:

Ø The user system call interface is implemented as follows:

Use mksyscall -p system.csv to generate an interface for users to call.

The part that implements this function in Nuttx is called a system call. Similar to Linux, the ecall command is used as a bridge to achieve U-Mode/M-Mode conversion, and parameters are passed through general-purpose registers.

In the nuttx system, 7 system call functions are provided: sys_call0 ~ sys_call6, which respectively correspond to the scenario where the system call contains 0 ~ 6 parameters. The parameters are passed through a0 ~ a6, where a0 is used to pass syscall no, a1 ~ a6 The meaning is determined by the specific syscall. For example, if syscall no is 0, it is to realize the dump of the task context, then a1 is used to transfer the destination address of the context dump, and a2~a6 are not used.

Since system calls are implemented through ecall, the processing of ecall is handled in interrupts. The corresponding processing function riscv_swint (ecall for machion/ecall for user) is registered during system initialization.

Guess you like

Origin blog.csdn.net/u012294613/article/details/132161858