Kévin Redon | 69b92d9 | 2019-01-24 16:39:20 +0100 | [diff] [blame] | 1 | /** |
| 2 | * \file |
| 3 | * |
| 4 | * \brief Syscalls for SAM0 (GCC). |
| 5 | * |
| 6 | * Copyright (c) 2015-2018 Microchip Technology Inc. and its subsidiaries. |
| 7 | * |
| 8 | * \asf_license_start |
| 9 | * |
| 10 | * \page License |
| 11 | * |
| 12 | * Subject to your compliance with these terms, you may use Microchip |
| 13 | * software and any derivatives exclusively with Microchip products. |
| 14 | * It is your responsibility to comply with third party license terms applicable |
| 15 | * to your use of third party software (including open source software) that |
| 16 | * may accompany Microchip software. |
| 17 | * |
| 18 | * THIS SOFTWARE IS SUPPLIED BY MICROCHIP "AS IS". NO WARRANTIES, |
| 19 | * WHETHER EXPRESS, IMPLIED OR STATUTORY, APPLY TO THIS SOFTWARE, |
| 20 | * INCLUDING ANY IMPLIED WARRANTIES OF NON-INFRINGEMENT, MERCHANTABILITY, |
| 21 | * AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT WILL MICROCHIP BE |
| 22 | * LIABLE FOR ANY INDIRECT, SPECIAL, PUNITIVE, INCIDENTAL OR CONSEQUENTIAL |
| 23 | * LOSS, DAMAGE, COST OR EXPENSE OF ANY KIND WHATSOEVER RELATED TO THE |
| 24 | * SOFTWARE, HOWEVER CAUSED, EVEN IF MICROCHIP HAS BEEN ADVISED OF THE |
| 25 | * POSSIBILITY OR THE DAMAGES ARE FORESEEABLE. TO THE FULLEST EXTENT |
| 26 | * ALLOWED BY LAW, MICROCHIP'S TOTAL LIABILITY ON ALL CLAIMS IN ANY WAY |
| 27 | * RELATED TO THIS SOFTWARE WILL NOT EXCEED THE AMOUNT OF FEES, IF ANY, |
| 28 | * THAT YOU HAVE PAID DIRECTLY TO MICROCHIP FOR THIS SOFTWARE. |
| 29 | * |
| 30 | * \asf_license_stop |
| 31 | * |
| 32 | */ |
| 33 | |
| 34 | #include <stdio.h> |
| 35 | #include <stdarg.h> |
| 36 | #include <sys/types.h> |
| 37 | #include <sys/stat.h> |
| 38 | |
| 39 | #ifdef __cplusplus |
| 40 | extern "C" { |
| 41 | #endif |
| 42 | |
| 43 | #undef errno |
| 44 | extern int errno; |
| 45 | extern int _end; |
| 46 | |
| 47 | extern caddr_t _sbrk(int incr); |
| 48 | extern int link(char *old, char *_new); |
| 49 | extern int _close(int file); |
| 50 | extern int _fstat(int file, struct stat *st); |
| 51 | extern int _isatty(int file); |
| 52 | extern int _lseek(int file, int ptr, int dir); |
| 53 | extern void _exit(int status); |
| 54 | extern void _kill(int pid, int sig); |
| 55 | extern int _getpid(void); |
| 56 | |
| 57 | /** |
| 58 | * \brief Replacement of C library of _sbrk |
| 59 | */ |
| 60 | extern caddr_t _sbrk(int incr) |
| 61 | { |
| 62 | static unsigned char *heap = NULL; |
| 63 | unsigned char * prev_heap; |
| 64 | |
| 65 | if (heap == NULL) { |
| 66 | heap = (unsigned char *)&_end; |
| 67 | } |
| 68 | prev_heap = heap; |
| 69 | |
| 70 | heap += incr; |
| 71 | |
| 72 | return (caddr_t)prev_heap; |
| 73 | } |
| 74 | |
| 75 | /** |
| 76 | * \brief Replacement of C library of link |
| 77 | */ |
| 78 | extern int link(char *old, char *_new) |
| 79 | { |
| 80 | (void)old, (void)_new; |
| 81 | return -1; |
| 82 | } |
| 83 | |
| 84 | /** |
| 85 | * \brief Replacement of C library of _close |
| 86 | */ |
| 87 | extern int _close(int file) |
| 88 | { |
| 89 | (void)file; |
| 90 | return -1; |
| 91 | } |
| 92 | |
| 93 | /** |
| 94 | * \brief Replacement of C library of _fstat |
| 95 | */ |
| 96 | extern int _fstat(int file, struct stat *st) |
| 97 | { |
| 98 | (void)file; |
| 99 | st->st_mode = S_IFCHR; |
| 100 | |
| 101 | return 0; |
| 102 | } |
| 103 | |
| 104 | /** |
| 105 | * \brief Replacement of C library of _isatty |
| 106 | */ |
| 107 | extern int _isatty(int file) |
| 108 | { |
| 109 | (void)file; |
| 110 | return 1; |
| 111 | } |
| 112 | |
| 113 | /** |
| 114 | * \brief Replacement of C library of _lseek |
| 115 | */ |
| 116 | extern int _lseek(int file, int ptr, int dir) |
| 117 | { |
| 118 | (void)file, (void)ptr, (void)dir; |
| 119 | return 0; |
| 120 | } |
| 121 | |
| 122 | /** |
| 123 | * \brief Replacement of C library of _exit |
| 124 | */ |
| 125 | extern void _exit(int status) |
| 126 | { |
| 127 | printf("Exiting with status %d.\n", status); |
| 128 | |
| 129 | for (;;) |
| 130 | ; |
| 131 | } |
| 132 | |
| 133 | /** |
| 134 | * \brief Replacement of C library of _kill |
| 135 | */ |
| 136 | extern void _kill(int pid, int sig) |
| 137 | { |
| 138 | (void)pid, (void)sig; |
| 139 | return; |
| 140 | } |
| 141 | |
| 142 | /** |
| 143 | * \brief Replacement of C library of _getpid |
| 144 | */ |
| 145 | extern int _getpid(void) |
| 146 | { |
| 147 | return -1; |
| 148 | } |
| 149 | |
| 150 | #ifdef __cplusplus |
| 151 | } |
| 152 | #endif |