syscalls.c 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208
  1. /**
  2. *****************************************************************************
  3. **
  4. ** File : syscalls.c
  5. **
  6. ** Author : Auto-generated by TrueSTUDIO for STM32
  7. **
  8. ** Abstract : TrueSTUDIO 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. ** Target : STMicroelectronics STM32
  15. **
  16. ** Distribution: The file is distributed ¡°as is,¡± without any warranty
  17. ** of any kind.
  18. **
  19. *****************************************************************************
  20. ** @attention
  21. **
  22. ** <h2><center>&copy; COPYRIGHT(c) 2019 STMicroelectronics</center></h2>
  23. **
  24. ** Redistribution and use in source and binary forms, with or without modification,
  25. ** are permitted provided that the following conditions are met:
  26. ** 1. Redistributions of source code must retain the above copyright notice,
  27. ** this list of conditions and the following disclaimer.
  28. ** 2. Redistributions in binary form must reproduce the above copyright notice,
  29. ** this list of conditions and the following disclaimer in the documentation
  30. ** and/or other materials provided with the distribution.
  31. ** 3. Neither the name of STMicroelectronics nor the names of its contributors
  32. ** may be used to endorse or promote products derived from this software
  33. ** without specific prior written permission.
  34. **
  35. ** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
  36. ** AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  37. ** IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  38. ** DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
  39. ** FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  40. ** DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
  41. ** SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
  42. ** CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
  43. ** OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  44. ** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  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. caddr_t _sbrk(int incr)
  102. {
  103. extern char end asm("end");
  104. static char *heap_end;
  105. char *prev_heap_end;
  106. if (heap_end == 0)
  107. heap_end = &end;
  108. prev_heap_end = heap_end;
  109. if (heap_end + incr > stack_ptr)
  110. {
  111. // write(1, "Heap and stack collision\n", 25);
  112. // abort();
  113. errno = ENOMEM;
  114. return (caddr_t) -1;
  115. }
  116. heap_end += incr;
  117. return (caddr_t) prev_heap_end;
  118. }
  119. int _close(int file)
  120. {
  121. return -1;
  122. }
  123. int _fstat(int file, struct stat *st)
  124. {
  125. st->st_mode = S_IFCHR;
  126. return 0;
  127. }
  128. int _isatty(int file)
  129. {
  130. return 1;
  131. }
  132. int _lseek(int file, int ptr, int dir)
  133. {
  134. return 0;
  135. }
  136. int _open(char *path, int flags, ...)
  137. {
  138. /* Pretend like we always fail */
  139. return -1;
  140. }
  141. int _wait(int *status)
  142. {
  143. errno = ECHILD;
  144. return -1;
  145. }
  146. int _unlink(char *name)
  147. {
  148. errno = ENOENT;
  149. return -1;
  150. }
  151. int _times(struct tms *buf)
  152. {
  153. return -1;
  154. }
  155. int _stat(char *file, struct stat *st)
  156. {
  157. st->st_mode = S_IFCHR;
  158. return 0;
  159. }
  160. int _link(char *old, char *new)
  161. {
  162. errno = EMLINK;
  163. return -1;
  164. }
  165. int _fork(void)
  166. {
  167. errno = EAGAIN;
  168. return -1;
  169. }
  170. int _execve(char *name, char **argv, char **env)
  171. {
  172. errno = ENOMEM;
  173. return -1;
  174. }