README.txt 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177
  1. syscall/README.txt
  2. ==================
  3. This directory supports a syscall layer from communication between a
  4. monolithic, kernel-mode NuttX kernel and a separately built, user-mode
  5. application set.
  6. With most MCUs, NuttX is built as a flat, single executable image
  7. containing the NuttX RTOS along with all application code. The RTOS code
  8. and the application run in the same address space and at the same kernel-
  9. mode privileges. In order to exploit security features of certain
  10. processors, an alternative build model is also supported: NuttX can
  11. be built separately as a monolithic, kernel-mode module and the applications
  12. can be added as a separately built, user-mode module.
  13. The syscall layer provided in this directory serves as the communication
  14. layer from the user-mode application into the kernel-mode RTOS. The
  15. switch from user-mode to kernel-mode is accomplished using software
  16. interrupts (SWIs). SWIs are implemented differently and named differently
  17. by different manufacturers but all work essentially the same: A special
  18. instruction is executed in user-mode that causes a software generated
  19. interrupt. The software generated interrupt is caught within the kernel
  20. and handle in kernel-mode.
  21. Header Files
  22. ============
  23. include/syscall.h
  24. This header file supports general access to SWI facilities. It is simply
  25. a wrapper file that includes include/sys/syscall.h and
  26. include/arch/syscall.h.
  27. include/sys/syscall.h
  28. The SWIs received by the kernel are distinguish by a code that identifies
  29. how to process the SWI. This header file defines all such codes understood
  30. by the NuttX kernel.
  31. include/arch/syscall.h (or arch/<cpu>/include/syscall.h)
  32. This header file is provided by the platform-specific logic and declares
  33. (or defines) the mechanism for providing software interrupts on this
  34. platform. The following functions must be declared (or defined) in this
  35. header file:
  36. - SWI with SYS_ call number and one parameter
  37. uintptr_t sys_call0(unsigned int nbr);
  38. - SWI with SYS_ call number and one parameter
  39. uintptr_t sys_call1(unsigned int nbr, uintptr_t parm1);
  40. - SWI with SYS_ call number and two parameters
  41. uintptr_t sys_call2(unsigned int nbr, uintptr_t parm1, uintptr_t parm2);
  42. - SWI with SYS_ call number and three parameters
  43. uintptr_t sys_call3(unsigned int nbr, uintptr_t parm1,
  44. uintptr_t parm2, uintptr_t parm3);
  45. - SWI with SYS_ call number and four parameters
  46. uintptr_t sys_call4(unsigned int nbr, uintptr_t parm1, uintptr_t parm2,
  47. uintptr_t parm3, uintptr_t parm4);
  48. - SWI with SYS_ call number and five parameters
  49. uintptr_t sys_call5(unsigned int nbr, uintptr_t parm1, uintptr_t parm2,
  50. uintptr_t parm3, uintptr_t parm4, uintptr_t parm5);
  51. - SWI with SYS_ call number and six parameters
  52. uintptr_t sys_call6(unsigned int nbr, uintptr_t parm1, uintptr_t parm2,
  53. uintptr_t parm3, uintptr_t parm4, uintptr_t parm5,
  54. uintptr_t parm6);
  55. Syscall Database
  56. ================
  57. Sycall information is maintained in a database. That "database" is
  58. implemented as a simple comma-separated-value file, syscall.csv. Most
  59. spreadsheets programs will accept this format and can be used to maintain
  60. the syscall database.
  61. The format of the CSV file for each line is:
  62. Field 1: Function name
  63. Field 2: The header file that contains the function prototype
  64. Field 3: Condition for compilation
  65. Field 4: The type of function return value.
  66. Field 5 - N+5: The type of each of the N formal parameters of the function
  67. Fields N+5 - : If the last parameter is "...", then the following fields
  68. provide the type and number of of possible optional parameters.
  69. See note below about variadic functions
  70. Each type field has a format as follows:
  71. type name:
  72. For all simpler types
  73. formal type | actual type:
  74. For array types where the form of the formal (eg. int parm[2])
  75. differs from the type of actual passed parameter (eg. int*). This
  76. is necessary because you cannot do simple casts to array types.
  77. formal type | union member actual type | union member fieldname:
  78. A similar situation exists for unions. For example, the formal
  79. parameter type union sigval -- You cannot cast a uintptr_t to
  80. a union sigval, but you can cast to the type of one of the union
  81. member types when passing the actual parameter. Similarly, we
  82. cannot cast a union sigval to a uinptr_t either. Rather, we need
  83. to cast a specific union member fieldname to uintptr_t.
  84. Variadic Functions:
  85. General variadic functions which may have an arbitrary number of argument
  86. or arbitrary types cannot be represented as system calls. syslog() is a
  87. good example. Normally you would work around this by using the non-
  88. variadic form of the OS interface that accepts a va_list as an argument,
  89. vsyslog() in this case.
  90. There there are many functions that have a variadic form but take only
  91. one or two arguments optional arguments. There can be handled as system
  92. calls, but only by treating them as though they had a fixed number of
  93. arguments.
  94. These are are handled in syscall.csv by appending the number and type of
  95. optional arguments. For example, consider the open() OS interface. Its
  96. prototype is:
  97. int open(const char *path, int oflag, ...);
  98. In reality, open may take only a single optional argument of type mode_t
  99. and is represented in syscall.cvs like this:
  100. "open","fcntl.h","","int","const char*","int","...","mode_t"
  101. The existence of the "mode_t" tells tools/mksyscall that there is at most
  102. one optional parameter and, if present, it is of type mode_t.
  103. NOTE: This CSV file is used both to support the generate of trap information,
  104. but also for the generation of symbol tables. See nuttx/tools/README.txt
  105. and nuttx/lib/README.txt for further information.
  106. Auto-Generated Files
  107. ====================
  108. Stubs and proxies for the sycalls are automatically generated from this CSV
  109. database. Here the following definition is used:
  110. Proxy - A tiny bit of code that executes in the user space. A proxy
  111. has exactly the same function prototype as does the "real" function
  112. for which it proxies. However, it only serves to map the function
  113. call into a syscall, marshaling all of the system call parameters
  114. as necessary.
  115. Stub - Another tiny bit of code that executes within the NuttX kernel
  116. that is used to map a software interrupt received by the kernel to
  117. a kernel function call. The stubs receive the marshaled system
  118. call data, and perform the actually kernel function call (in
  119. kernel-mode) on behalf of the proxy function.
  120. Sub-Directories
  121. ===============
  122. stubs - Autogenerated stub files are placed in this directory.
  123. proxies - Autogenerated proxy files are placed in this directory.
  124. mksyscall
  125. =========
  126. mksyscall is C program that is used used during the initial NuttX build
  127. by the logic in the top-level syscall/ directory. Information about the
  128. stubs and proxies is maintained in a comma separated value (CSV) file
  129. in the syscall/ directory. The mksyscall program will accept this CVS
  130. file as input and generate all of the required proxy or stub files as
  131. output. See tools/README.txt for additional information.