syscalls.c 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185
  1. /**
  2. *****************************************************************************
  3. **
  4. ** File : syscalls.c
  5. **
  6. ** Author : Auto-generated by STM32CubeIDE
  7. **
  8. ** Abstract : STM32CubeIDE Minimal System calls file
  9. **
  10. ** For more information about which c-functions
  11. ** need which of these lowlevel functions
  12. ** please consult the Newlib libc-manual
  13. **
  14. ** Environment : STM32CubeIDE MCU
  15. **
  16. ** Distribution: The file is distributed as is, without any warranty
  17. ** of any kind.
  18. **
  19. *****************************************************************************
  20. **
  21. ** <h2><center>&copy; COPYRIGHT(c) 2018 STMicroelectronics</center></h2>
  22. **
  23. ** Redistribution and use in source and binary forms, with or without modification,
  24. ** are permitted provided that the following conditions are met:
  25. ** 1. Redistributions of source code must retain the above copyright notice,
  26. ** this list of conditions and the following disclaimer.
  27. ** 2. Redistributions in binary form must reproduce the above copyright notice,
  28. ** this list of conditions and the following disclaimer in the documentation
  29. ** and/or other materials provided with the distribution.
  30. ** 3. Neither the name of STMicroelectronics nor the names of its contributors
  31. ** may be used to endorse or promote products derived from this software
  32. ** without specific prior written permission.
  33. **
  34. ** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
  35. ** AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  36. ** IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  37. ** DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
  38. ** FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  39. ** DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
  40. ** SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
  41. ** CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
  42. ** OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  43. ** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  44. **
  45. **
  46. *****************************************************************************
  47. */
  48. /* Includes */
  49. #include <sys/stat.h>
  50. #include <stdlib.h>
  51. #include <errno.h>
  52. #include <stdio.h>
  53. #include <signal.h>
  54. #include <time.h>
  55. #include <sys/time.h>
  56. #include <sys/times.h>
  57. /* Variables */
  58. //#undef errno
  59. extern int errno;
  60. extern int __io_putchar(int ch) __attribute__((weak));
  61. extern int __io_getchar(void) __attribute__((weak));
  62. register char * stack_ptr asm("sp");
  63. char *__env[1] = { 0 };
  64. char **environ = __env;
  65. /* Functions */
  66. void initialise_monitor_handles()
  67. {
  68. }
  69. int _getpid(void)
  70. {
  71. return 1;
  72. }
  73. int _kill(int pid, int sig)
  74. {
  75. errno = EINVAL;
  76. return -1;
  77. }
  78. void _exit (int status)
  79. {
  80. _kill(status, -1);
  81. while (1) {} /* Make sure we hang here */
  82. }
  83. __attribute__((weak)) int _read(int file, char *ptr, int len)
  84. {
  85. int DataIdx;
  86. for (DataIdx = 0; DataIdx < len; DataIdx++)
  87. {
  88. *ptr++ = __io_getchar();
  89. }
  90. return len;
  91. }
  92. __attribute__((weak)) int _write(int file, char *ptr, int len)
  93. {
  94. int DataIdx;
  95. for (DataIdx = 0; DataIdx < len; DataIdx++)
  96. {
  97. __io_putchar(*ptr++);
  98. }
  99. return len;
  100. }
  101. int _close(int file)
  102. {
  103. return -1;
  104. }
  105. int _fstat(int file, struct stat *st)
  106. {
  107. st->st_mode = S_IFCHR;
  108. return 0;
  109. }
  110. int _isatty(int file)
  111. {
  112. return 1;
  113. }
  114. int _lseek(int file, int ptr, int dir)
  115. {
  116. return 0;
  117. }
  118. int _open(char *path, int flags, ...)
  119. {
  120. /* Pretend like we always fail */
  121. return -1;
  122. }
  123. int _wait(int *status)
  124. {
  125. errno = ECHILD;
  126. return -1;
  127. }
  128. int _unlink(char *name)
  129. {
  130. errno = ENOENT;
  131. return -1;
  132. }
  133. int _times(struct tms *buf)
  134. {
  135. return -1;
  136. }
  137. int _stat(char *file, struct stat *st)
  138. {
  139. st->st_mode = S_IFCHR;
  140. return 0;
  141. }
  142. int _link(char *old, char *new)
  143. {
  144. errno = EMLINK;
  145. return -1;
  146. }
  147. int _fork(void)
  148. {
  149. errno = EAGAIN;
  150. return -1;
  151. }
  152. int _execve(char *name, char **argv, char **env)
  153. {
  154. errno = ENOMEM;
  155. return -1;
  156. }