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