From 128423edc6820119997ae4a9875f27508aee13b4 Mon Sep 17 00:00:00 2001 From: Koen Zandberg Date: Tue, 26 Jan 2021 13:42:52 +0100 Subject: [PATCH] cpu/fe310: Use newlib_syscalls_default stub implementations This switches the fe310 to use the common newlib_syscalls_default implementation. --- cpu/fe310/Makefile | 4 - cpu/fe310/Makefile.dep | 2 +- cpu/fe310/cpu.c | 4 - cpu/fe310/nano/Makefile | 3 - cpu/fe310/nano/nanostubs.c | 176 ------------------------------------- 5 files changed, 1 insertion(+), 188 deletions(-) delete mode 100644 cpu/fe310/nano/Makefile delete mode 100644 cpu/fe310/nano/nanostubs.c diff --git a/cpu/fe310/Makefile b/cpu/fe310/Makefile index 98076f3201..7faccb7655 100644 --- a/cpu/fe310/Makefile +++ b/cpu/fe310/Makefile @@ -4,8 +4,4 @@ MODULE = cpu # add a list of subdirectories, that should also be built DIRS = periph vendor -ifneq (1,$(PICOLIBC)) - DIRS += nano -endif - include $(RIOTBASE)/Makefile.base diff --git a/cpu/fe310/Makefile.dep b/cpu/fe310/Makefile.dep index d5de24f900..9a183a3c08 100644 --- a/cpu/fe310/Makefile.dep +++ b/cpu/fe310/Makefile.dep @@ -2,7 +2,7 @@ ifneq (,$(filter picolibc,$(FEATURES_USED))) USEMODULE += picolibc else USEMODULE += newlib_nano - USEMODULE += newlib_syscalls_fe310 + USEMODULE += newlib_syscalls_default endif USEMODULE += sifive_drivers_fe310 diff --git a/cpu/fe310/cpu.c b/cpu/fe310/cpu.c index ebf80274d9..f38fdc0c7e 100644 --- a/cpu/fe310/cpu.c +++ b/cpu/fe310/cpu.c @@ -115,10 +115,6 @@ void cpu_init(void) /* Initialize stdio */ stdio_init(); -#ifndef _PICOLIBC__ - /* Initialize newlib-nano library stubs */ - nanostubs_init(); -#endif /* PICOLIBC */ /* Initialize static peripheral */ periph_init(); diff --git a/cpu/fe310/nano/Makefile b/cpu/fe310/nano/Makefile deleted file mode 100644 index 7e05da389e..0000000000 --- a/cpu/fe310/nano/Makefile +++ /dev/null @@ -1,3 +0,0 @@ -MODULE = newlib_syscalls_fe310 - -include $(RIOTBASE)/Makefile.base diff --git a/cpu/fe310/nano/nanostubs.c b/cpu/fe310/nano/nanostubs.c deleted file mode 100644 index 914baff797..0000000000 --- a/cpu/fe310/nano/nanostubs.c +++ /dev/null @@ -1,176 +0,0 @@ -/* - * Copyright (C) 2017 Ken Rabold - * - * This file is subject to the terms and conditions of the GNU Lesser - * General Public License v2.1. See the file LICENSE in the top level - * directory for more details. - */ - -/** - * @ingroup cpu_fe310 - * @{ - * - * @file nanostubs.c - * @brief Implementation of the Newlib-nano for SiFive FE310 - * - * @author Ken Rabold - * @} - */ - -#include -#include -#include -#include -#include - -#include "sched.h" -#include "thread.h" -#include "irq.h" -#include "cpu.h" -#include "stdio_uart.h" - -extern char _sheap; /* Heap markers from fe310.ld file */ -extern char _eheap; -char *heap_top = &_sheap + 4; - -/** - * @brief Initialize the Newlib-nano functions (also forces inclusion of stubs for linking) - */ -void nanostubs_init(void) -{ -#if defined(MODULE_STDIO_UART) - /* STDIO redirected to UART, no line buffering */ - setvbuf(stdout, NULL, _IONBF, 0); -#endif -} - -void _init(void) -{ -} - -void _fini(void) -{ -} - -void *_sbrk(ptrdiff_t incr) -{ - unsigned int state = irq_disable(); - void *res = heap_top; - - /* Allocate memory from heap */ - if ((heap_top + incr > &_eheap) || (heap_top + incr < &_sheap)) { - errno = ENOMEM; - res = (void *) -1; - } - else { - heap_top += incr; - } - - irq_restore(state); - return res; -} - -int _open(const char *name, int flags, int mode) -{ - (void) name; - (void) flags; - (void) mode; - errno = ENODEV; - return -1; -} - -_ssize_t _read(int fd, void *buffer, size_t count) -{ -#if defined(MODULE_STDIO_UART) - if (fd == STDIN_FILENO) { - return stdio_read(buffer, count); - } - errno = EBADF; - return -1; -#else - (void) fd; - (void) buffer; - (void) count; - errno = ENODEV; - return -1; -#endif -} - -_ssize_t _write(int fd, const void *data, size_t count) -{ -#if defined(MODULE_STDIO_UART) - if (fd == STDOUT_FILENO || fd == STDERR_FILENO) { - return stdio_write(data, count); - } - errno = EBADF; - return -1; -#else - (void) fd; - (void) data; - (void) count; - errno = ENODEV; - return -1; -#endif -} - -int _close(int fd) -{ - (void) fd; - errno = ENODEV; - return -1; -} - -int _isatty(int fd) -{ - errno = 0; - - if (fd == STDIN_FILENO || fd == STDOUT_FILENO || fd == STDERR_FILENO) { - return 1; - } - - return 0; -} - -int _fstat(int fd, struct stat *st) -{ - (void) fd; - (void) st; - errno = ENODEV; - return -1; -} - -_off_t _lseek(int fd, _off_t pos, int dir) -{ - (void) fd; - (void) pos; - (void) dir; - errno = ENODEV; - return -1; -} - -int _gettimeofday(struct timeval *tp, void *tzp) -{ - (void) tp; - (void) tzp; - errno = EINVAL; - return -1; -} - -int _getpid(void) -{ - return thread_getpid(); -} - -int _kill(int pid, int sig) -{ - (void) pid; - (void) sig; - errno = EINVAL; - return -1; -} - -void _exit(int _status) -{ - (void) _status; - while(1); -}