| 1 | /**
|
|---|
| 2 | *****************************************************************************
|
|---|
| 3 | **
|
|---|
| 4 | ** File : syscalls.c
|
|---|
| 5 | **
|
|---|
| 6 | ** Author : Auto-generated by System workbench for STM32
|
|---|
| 7 | **
|
|---|
| 8 | ** Abstract : System Workbench 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>© 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 |
|
|---|
| 49 | /* Includes */
|
|---|
| 50 | #include <sys/stat.h>
|
|---|
| 51 | #include <stdlib.h>
|
|---|
| 52 | #include <errno.h>
|
|---|
| 53 | #include <stdio.h>
|
|---|
| 54 | #include <signal.h>
|
|---|
| 55 | #include <time.h>
|
|---|
| 56 | #include <sys/time.h>
|
|---|
| 57 | #include <sys/times.h>
|
|---|
| 58 |
|
|---|
| 59 |
|
|---|
| 60 | /* Variables */
|
|---|
| 61 | //#undef errno
|
|---|
| 62 | extern int errno;
|
|---|
| 63 | extern int __io_putchar(int ch) __attribute__((weak));
|
|---|
| 64 | extern int __io_getchar(void) __attribute__((weak));
|
|---|
| 65 |
|
|---|
| 66 | register char * stack_ptr asm("sp");
|
|---|
| 67 |
|
|---|
| 68 | char *__env[1] = { 0 };
|
|---|
| 69 | char **environ = __env;
|
|---|
| 70 |
|
|---|
| 71 |
|
|---|
| 72 | /* Functions */
|
|---|
| 73 | void initialise_monitor_handles()
|
|---|
| 74 | {
|
|---|
| 75 | }
|
|---|
| 76 |
|
|---|
| 77 | int _getpid(void)
|
|---|
| 78 | {
|
|---|
| 79 | return 1;
|
|---|
| 80 | }
|
|---|
| 81 |
|
|---|
| 82 | int _kill(int pid, int sig)
|
|---|
| 83 | {
|
|---|
| 84 | errno = EINVAL;
|
|---|
| 85 | return -1;
|
|---|
| 86 | }
|
|---|
| 87 |
|
|---|
| 88 | void _exit (int status)
|
|---|
| 89 | {
|
|---|
| 90 | _kill(status, -1);
|
|---|
| 91 | while (1) {} /* Make sure we hang here */
|
|---|
| 92 | }
|
|---|
| 93 |
|
|---|
| 94 | __attribute__((weak)) int _read(int file, char *ptr, int len)
|
|---|
| 95 | {
|
|---|
| 96 | int DataIdx;
|
|---|
| 97 |
|
|---|
| 98 | for (DataIdx = 0; DataIdx < len; DataIdx++)
|
|---|
| 99 | {
|
|---|
| 100 | *ptr++ = __io_getchar();
|
|---|
| 101 | }
|
|---|
| 102 |
|
|---|
| 103 | return len;
|
|---|
| 104 | }
|
|---|
| 105 |
|
|---|
| 106 | __attribute__((weak)) int _write(int file, char *ptr, int len)
|
|---|
| 107 | {
|
|---|
| 108 | int DataIdx;
|
|---|
| 109 |
|
|---|
| 110 | for (DataIdx = 0; DataIdx < len; DataIdx++)
|
|---|
| 111 | {
|
|---|
| 112 | __io_putchar(*ptr++);
|
|---|
| 113 | }
|
|---|
| 114 | return len;
|
|---|
| 115 | }
|
|---|
| 116 |
|
|---|
| 117 | caddr_t _sbrk(int incr)
|
|---|
| 118 | {
|
|---|
| 119 | extern char end asm("end");
|
|---|
| 120 | static char *heap_end;
|
|---|
| 121 | char *prev_heap_end;
|
|---|
| 122 |
|
|---|
| 123 | if (heap_end == 0)
|
|---|
| 124 | heap_end = &end;
|
|---|
| 125 |
|
|---|
| 126 | prev_heap_end = heap_end;
|
|---|
| 127 | if (heap_end + incr > stack_ptr)
|
|---|
| 128 | {
|
|---|
| 129 | // write(1, "Heap and stack collision\n", 25);
|
|---|
| 130 | // abort();
|
|---|
| 131 | errno = ENOMEM;
|
|---|
| 132 | return (caddr_t) -1;
|
|---|
| 133 | }
|
|---|
| 134 |
|
|---|
| 135 | heap_end += incr;
|
|---|
| 136 |
|
|---|
| 137 | return (caddr_t) prev_heap_end;
|
|---|
| 138 | }
|
|---|
| 139 |
|
|---|
| 140 | int _close(int file)
|
|---|
| 141 | {
|
|---|
| 142 | return -1;
|
|---|
| 143 | }
|
|---|
| 144 |
|
|---|
| 145 |
|
|---|
| 146 | int _fstat(int file, struct stat *st)
|
|---|
| 147 | {
|
|---|
| 148 | st->st_mode = S_IFCHR;
|
|---|
| 149 | return 0;
|
|---|
| 150 | }
|
|---|
| 151 |
|
|---|
| 152 | int _isatty(int file)
|
|---|
| 153 | {
|
|---|
| 154 | return 1;
|
|---|
| 155 | }
|
|---|
| 156 |
|
|---|
| 157 | int _lseek(int file, int ptr, int dir)
|
|---|
| 158 | {
|
|---|
| 159 | return 0;
|
|---|
| 160 | }
|
|---|
| 161 |
|
|---|
| 162 | int _open(char *path, int flags, ...)
|
|---|
| 163 | {
|
|---|
| 164 | /* Pretend like we always fail */
|
|---|
| 165 | return -1;
|
|---|
| 166 | }
|
|---|
| 167 |
|
|---|
| 168 | int _wait(int *status)
|
|---|
| 169 | {
|
|---|
| 170 | errno = ECHILD;
|
|---|
| 171 | return -1;
|
|---|
| 172 | }
|
|---|
| 173 |
|
|---|
| 174 | int _unlink(char *name)
|
|---|
| 175 | {
|
|---|
| 176 | errno = ENOENT;
|
|---|
| 177 | return -1;
|
|---|
| 178 | }
|
|---|
| 179 |
|
|---|
| 180 | int _times(struct tms *buf)
|
|---|
| 181 | {
|
|---|
| 182 | return -1;
|
|---|
| 183 | }
|
|---|
| 184 |
|
|---|
| 185 | int _stat(char *file, struct stat *st)
|
|---|
| 186 | {
|
|---|
| 187 | st->st_mode = S_IFCHR;
|
|---|
| 188 | return 0;
|
|---|
| 189 | }
|
|---|
| 190 |
|
|---|
| 191 | int _link(char *old, char *new)
|
|---|
| 192 | {
|
|---|
| 193 | errno = EMLINK;
|
|---|
| 194 | return -1;
|
|---|
| 195 | }
|
|---|
| 196 |
|
|---|
| 197 | int _fork(void)
|
|---|
| 198 | {
|
|---|
| 199 | errno = EAGAIN;
|
|---|
| 200 | return -1;
|
|---|
| 201 | }
|
|---|
| 202 |
|
|---|
| 203 | int _execve(char *name, char **argv, char **env)
|
|---|
| 204 | {
|
|---|
| 205 | errno = ENOMEM;
|
|---|
| 206 | return -1;
|
|---|
| 207 | }
|
|---|