diff options
Diffstat (limited to 'os')
-rw-r--r-- | os/Makefile | 19 | ||||
-rw-r--r-- | os/src/close.c | 14 | ||||
-rw-r--r-- | os/src/fclose.c | 8 | ||||
-rw-r--r-- | os/src/fflush.c | 7 | ||||
-rw-r--r-- | os/src/fio.c | 2 | ||||
-rw-r--r-- | os/src/fopen.c | 8 | ||||
-rw-r--r-- | os/src/fprintf.c | 14 | ||||
-rw-r--r-- | os/src/fread.c | 7 | ||||
-rw-r--r-- | os/src/free.c | 8 | ||||
-rw-r--r-- | os/src/fstat.c | 27 | ||||
-rw-r--r-- | os/src/fwrite.c | 7 | ||||
-rw-r--r-- | os/src/init.c | 9 | ||||
-rw-r--r-- | os/src/isatty.c | 15 | ||||
-rw-r--r-- | os/src/lseek.c | 27 | ||||
-rw-r--r-- | os/src/malloc.c | 23 | ||||
-rw-r--r-- | os/src/open.c | 17 | ||||
-rw-r--r-- | os/src/printf.c | 14 | ||||
-rw-r--r-- | os/src/read.c | 24 | ||||
-rw-r--r-- | os/src/romfs.c | 2 | ||||
-rw-r--r-- | os/src/sbrk.c | 21 | ||||
-rw-r--r-- | os/src/semifs.c | 2 | ||||
-rw-r--r-- | os/src/sprintf.c | 14 | ||||
-rw-r--r-- | os/src/write.c | 24 |
23 files changed, 19 insertions, 294 deletions
diff --git a/os/Makefile b/os/Makefile index 37dbf56..763f907 100644 --- a/os/Makefile +++ b/os/Makefile @@ -6,6 +6,7 @@ include $(ROOTDIR)/common.mk include config.mk include $(ROOTDIR)/FreeRTOS/config.mk include $(ROOTDIR)/arch/config.mk +include $(ROOTDIR)/libc/config.mk TARGET_SRCS = \ src/init.c \ @@ -17,25 +18,7 @@ src/hash-djb2.c \ src/osdebug.c \ src/romfs.c \ \ -src/close.c \ -src/fstat.c \ -src/isatty.c \ -src/lseek.c \ -src/open.c \ -src/read.c \ src/sbrk.c \ -src/write.c \ -\ -src/fclose.c \ -src/fflush.c \ -src/fopen.c \ -src/fprintf.c \ -src/fread.c \ -src/free.c \ -src/fwrite.c \ -src/malloc.c \ -src/printf.c \ -src/sprintf.c \ ifeq ($(CPU),arm) TARGET_SRCS += src/semifs.c diff --git a/os/src/close.c b/os/src/close.c deleted file mode 100644 index 5da8b2c..0000000 --- a/os/src/close.c +++ /dev/null @@ -1,14 +0,0 @@ -#include <reent.h> -#include <errno.h> -#include "fio.h" -#include "osdebug.h" - -int _close_r(struct _reent * reent, int fd) { -// DBGOUT("_close_r(%p, %i)\r\n", reent, fd); - if (!fio_is_open(fd)) { - reent->_errno = EBADF; - return -1; - } - - return fio_close(fd); -} diff --git a/os/src/fclose.c b/os/src/fclose.c deleted file mode 100644 index 4c4c3fc..0000000 --- a/os/src/fclose.c +++ /dev/null @@ -1,8 +0,0 @@ -#include <stdio.h> -#include <reent.h> -#include "osdebug.h" - -int fclose(FILE * fp) { -// DBGOUT("fclose(%p)\r\n", fp); - return _fclose_r(_impure_ptr, fp); -} diff --git a/os/src/fflush.c b/os/src/fflush.c deleted file mode 100644 index 84e2c67..0000000 --- a/os/src/fflush.c +++ /dev/null @@ -1,7 +0,0 @@ -#include <stdio.h> -#include "osdebug.h" - -int fflush(FILE * file) { -// DBGOUT("fflush(%p)\r\n", file); - return _fflush_r(_impure_ptr, file); -} diff --git a/os/src/fio.c b/os/src/fio.c index 432f7e2..d579bf4 100644 --- a/os/src/fio.c +++ b/os/src/fio.c @@ -3,9 +3,11 @@ #include <FreeRTOS.h> #include <semphr.h> #include <unistd.h> +#ifdef USE_NEWLIB #include <sys/types.h> #include <sys/stat.h> #include <fcntl.h> +#endif #include "fio.h" #include "filesystem.h" #include "osdebug.h" diff --git a/os/src/fopen.c b/os/src/fopen.c deleted file mode 100644 index 22ac269..0000000 --- a/os/src/fopen.c +++ /dev/null @@ -1,8 +0,0 @@ -#include <stdio.h> -#include <reent.h> -#include "osdebug.h" - -FILE * fopen(const char * path, const char * mode) { -// DBGOUT("fopen(\"%s\", \"%s\")\r\n", path, mode); - return _fopen_r(_impure_ptr, path, mode); -} diff --git a/os/src/fprintf.c b/os/src/fprintf.c deleted file mode 100644 index a56ed33..0000000 --- a/os/src/fprintf.c +++ /dev/null @@ -1,14 +0,0 @@ -#include <reent.h> -#include <stdio.h> -#include <stdarg.h> -#include "osdebug.h" - -int fprintf(FILE * file, const char * fmt, ...) { - int r; - va_list ap; -// DBGOUT("fprintf(%p, %p, ...)\r\n", file, fmt); - va_start(ap, fmt); - r = _vfprintf_r(_impure_ptr, file, fmt, ap); - va_end(ap); - return r; -} diff --git a/os/src/fread.c b/os/src/fread.c deleted file mode 100644 index 3f39c1e..0000000 --- a/os/src/fread.c +++ /dev/null @@ -1,7 +0,0 @@ -#include <stdio.h> -#include "osdebug.h" - -size_t fread(void * ptr, size_t size, size_t nmemb, FILE * file) { -// DBGOUT("fread(%p, %i, %i, %p)\r\n", ptr, size, nmemb, file); - return _fread_r(_impure_ptr, ptr, size, nmemb, file); -} diff --git a/os/src/free.c b/os/src/free.c deleted file mode 100644 index a011077..0000000 --- a/os/src/free.c +++ /dev/null @@ -1,8 +0,0 @@ -#include <reent.h> -#include <malloc.h> -#include "osdebug.h" - -void free(void * ptr) { -// DBGOUT("free(%p)\r\n", ptr); - _free_r(_impure_ptr, ptr); -} diff --git a/os/src/fstat.c b/os/src/fstat.c deleted file mode 100644 index a7c251f..0000000 --- a/os/src/fstat.c +++ /dev/null @@ -1,27 +0,0 @@ -#include <reent.h> -#include <sys/stat.h> -#include <string.h> -#include <errno.h> -#include "fio.h" -#include "osdebug.h" - -int _fstat_r(struct _reent * reent, int fd, struct stat * buf) { - off_t c; -// DBGOUT("_fstat_r(%p, %i, %p)\r\n", reent, fd, buf); - memset(buf, 0, sizeof(struct stat)); - - if (!fio_is_open(fd)) { - reent->_errno = EBADF; - return -1; - } - - buf->st_mode = S_IFCHR; - buf->st_blksize = 1024; - c = fio_seek(fd, 0, SEEK_CUR); - if (c >= 0) { - buf->st_size = fio_seek(fd, 0, SEEK_END); - fio_seek(fd, c, SEEK_SET); - } - - return 0; -} diff --git a/os/src/fwrite.c b/os/src/fwrite.c deleted file mode 100644 index 6a10db0..0000000 --- a/os/src/fwrite.c +++ /dev/null @@ -1,7 +0,0 @@ -#include <stdio.h> -#include "osdebug.h" - -size_t fwrite(const void * ptr, size_t size, size_t nmemb, FILE * file) { -// DBGOUT("fwrite(%p, %i, %i, %p)\r\n", ptr, size, nmemb, file); - return _fwrite_r(_impure_ptr, ptr, size, nmemb, file); -} diff --git a/os/src/init.c b/os/src/init.c index 5ab7899..edbae0a 100644 --- a/os/src/init.c +++ b/os/src/init.c @@ -1,4 +1,5 @@ #include <stdlib.h> +#include <stdio.h> #include <BoardConsole.h> void __libc_init_array(); @@ -27,3 +28,11 @@ void _start() { atexit(__libc_fini_array); exit(main(0, NULL, NULL)); } + +void startup_memcpy(void * dest, const void * src, size_t n) { + memcpy(dest, src, n); +} + +void startup_memset(void * dest, int c, size_t n) { + memset(dest, c, n); +} diff --git a/os/src/isatty.c b/os/src/isatty.c deleted file mode 100644 index b37a9dc..0000000 --- a/os/src/isatty.c +++ /dev/null @@ -1,15 +0,0 @@ -#include <unistd.h> -#include <reent.h> -#include <errno.h> -#include "fio.h" -#include "osdebug.h" - -int _isatty_r(struct _reent * reent, int fd) { -// DBGOUT("_isatty_r(%p, %i)\r\n", reent, fd); - if (!fio_is_open(fd)) { - reent->_errno = EBADF; - return 0; - } - reent->_errno = EINVAL; - return 0; -} diff --git a/os/src/lseek.c b/os/src/lseek.c deleted file mode 100644 index 1e904a5..0000000 --- a/os/src/lseek.c +++ /dev/null @@ -1,27 +0,0 @@ -#include <reent.h> -#include <osdebug.h> -#include <errno.h> -#include "fio.h" -#include "osdebug.h" - -_off_t _lseek_r(struct _reent * reent, int fd, _off_t seek, int wheel) { - off_t r; -// DBGOUT("_lseek_r(%p, %i, %i, %i)\r\n", reent, fd, seek, wheel); - - if ((wheel != SEEK_SET) && (wheel != SEEK_CUR) && (wheel != SEEK_END)) { - reent->_errno = EINVAL; - return -1; - } - - if (!fio_is_open(fd)) { - reent->_errno = EBADF; - return -1; - } - - r = fio_seek(fd, seek, wheel); - - if (r < 0) - reent->_errno = EINVAL; - - return r; -} diff --git a/os/src/malloc.c b/os/src/malloc.c deleted file mode 100644 index 3d867d0..0000000 --- a/os/src/malloc.c +++ /dev/null @@ -1,23 +0,0 @@ -#include <reent.h> -#include <malloc.h> -#include <FreeRTOS.h> -#include <semphr.h> -#include "osdebug.h" - -static xSemaphoreHandle malloc_sem = NULL; - -__attribute__((constructor)) static void malloc_init() { - malloc_sem = xSemaphoreCreateMutex(); -} - -void * malloc(size_t size) { - void * ptr; -// DBGOUT("malloc(%i)\r\n", size); - - if (malloc_sem) - xSemaphoreTake(malloc_sem, portMAX_DELAY); - ptr =_malloc_r(_impure_ptr, size); - if (malloc_sem) - xSemaphoreGive(malloc_sem); - return ptr; -} diff --git a/os/src/open.c b/os/src/open.c deleted file mode 100644 index 5298fd8..0000000 --- a/os/src/open.c +++ /dev/null @@ -1,17 +0,0 @@ -#include <stdio.h> -#include <reent.h> -#include <errno.h> -#include "fio.h" -#include "filesystem.h" -#include "osdebug.h" - -int _open_r(struct _reent * reent, const char * path, int flags, int mode) { -// DBGOUT("_open_r(%p, \"%s\", flags, mode)\r\n", reent, path, flags, mode); - int r = fs_open(path, flags, mode); - - if (r >= 0) - return r; - - reent->_errno = EACCES; - return -1; -} diff --git a/os/src/printf.c b/os/src/printf.c deleted file mode 100644 index 80b6b94..0000000 --- a/os/src/printf.c +++ /dev/null @@ -1,14 +0,0 @@ -#include <reent.h> -#include <stdio.h> -#include <stdarg.h> -#include <osdebug.h> - -int printf(const char * fmt, ...) { - int r; - va_list ap; -// DBGOUT("printf(\"%p\", ...)\r\n", fmt); - va_start(ap, fmt); - r = _vprintf_r(_impure_ptr, fmt, ap); - va_end(ap); - return r; -} diff --git a/os/src/read.c b/os/src/read.c deleted file mode 100644 index 845092b..0000000 --- a/os/src/read.c +++ /dev/null @@ -1,24 +0,0 @@ -#include <reent.h> -#include <osdebug.h> -#include <errno.h> -#include "fio.h" - -_ssize_t _read_r(struct _reent * reent, int fd, void * buf, size_t size) { - _ssize_t r; - -// DBGOUT("_read_r(%p, %i, %p, %i)\r\n", reent, fd, buf, size); - - if (!fio_is_open(fd)) { - reent->_errno = EBADF; - return -1; - } - - r = fio_read(fd, buf, size); - - if (r < 0) { - reent->_errno = EINVAL; - return -1; - } - - return r; -} diff --git a/os/src/romfs.c b/os/src/romfs.c index 2d11d96..df55f48 100644 --- a/os/src/romfs.c +++ b/os/src/romfs.c @@ -2,9 +2,11 @@ #include <FreeRTOS.h> #include <semphr.h> #include <unistd.h> +#ifdef USE_NEWLIB #include <sys/types.h> #include <sys/stat.h> #include <fcntl.h> +#endif #include "fio.h" #include "filesystem.h" #include "romfs.h" diff --git a/os/src/sbrk.c b/os/src/sbrk.c index 53efe1e..fcb6b7a 100644 --- a/os/src/sbrk.c +++ b/os/src/sbrk.c @@ -9,27 +9,15 @@ #include "osdebug.h" -// Mostly stolen from mbed-freertos - extern uintptr_t __heap_start; extern uintptr_t __stack_start; -/* Low-level bulk RAM allocator -- used by Newlib's Malloc */ -static void *heap_end = (void *) &__heap_start; - -static xSemaphoreHandle sbrk_sem = NULL; - -__attribute__((constructor)) static void sbrk_init() { - sbrk_sem = xSemaphoreCreateMutex(); -} +static void * heap_end = (void *) &__heap_start; -void *_sbrk_r(struct _reent *ptr, ptrdiff_t incr) { +void * sbrk(ptrdiff_t incr) { void *prev_heap_end, *next_heap_end, *ret; void *stack_min = (void *) &__stack_start; - if (sbrk_sem) - xSemaphoreTake(sbrk_sem, portMAX_DELAY); - prev_heap_end = heap_end; /* Align to always be on 8-byte boundaries */ @@ -37,15 +25,12 @@ void *_sbrk_r(struct _reent *ptr, ptrdiff_t incr) { /* Check if this allocation would exceed the end of the ram - would probably get into the stack first however */ if (next_heap_end > stack_min) { - ptr->_errno = ENOMEM; + _impure_ptr->_errno = ENOMEM; ret = NULL; } else { heap_end = next_heap_end; ret = (void *)prev_heap_end; } - if (sbrk_sem) - xSemaphoreGive(sbrk_sem); - return ret; } diff --git a/os/src/semifs.c b/os/src/semifs.c index fc7d0b1..1d92dc2 100644 --- a/os/src/semifs.c +++ b/os/src/semifs.c @@ -22,7 +22,9 @@ #include <string.h> #include <errno.h> #include <stdint.h> +#ifdef USE_NEWLIB #include <fcntl.h> +#endif #include <angel.h> diff --git a/os/src/sprintf.c b/os/src/sprintf.c deleted file mode 100644 index 755d780..0000000 --- a/os/src/sprintf.c +++ /dev/null @@ -1,14 +0,0 @@ -#include <reent.h> -#include <stdio.h> -#include <stdarg.h> -#include <osdebug.h> - -int sprintf(char * str, const char * fmt, ...) { - int r; - va_list ap; -// DBGOUT("sprintf(%p, %p, ...)\r\n", str, fmt); - va_start(ap, fmt); - r = _vsprintf_r(_impure_ptr, str, fmt, ap); - va_end(ap); - return r; -} diff --git a/os/src/write.c b/os/src/write.c deleted file mode 100644 index c54e304..0000000 --- a/os/src/write.c +++ /dev/null @@ -1,24 +0,0 @@ -#include <reent.h> -#include <osdebug.h> -#include <errno.h> -#include "fio.h" - -_ssize_t _write_r(struct _reent * reent, int fd, const void * buf, size_t size) { - _ssize_t r; - -// DBGOUT("_write_r(%p, %i, %p, %i)\r\n", reent, fd, buf, size); - - if (!fio_is_open(fd)) { - reent->_errno = EBADF; - return -1; - } - - r = fio_write(fd, buf, size); - - if (r < 0) { - reent->_errno = EINVAL; - return -1; - } - - return r; -} |