diff --git a/bare-metal-bsp/libwrap/libwrap.mk b/bare-metal-bsp/libwrap/libwrap.mk index fc5e8da..345e993 100644 --- a/bare-metal-bsp/libwrap/libwrap.mk +++ b/bare-metal-bsp/libwrap/libwrap.mk @@ -24,16 +24,36 @@ LIBWRAP_SRCS := \ sys/times.c \ sys/sbrk.c \ sys/_exit.c \ + sys/puts.c \ misc/write_hex.c \ sys/printf.c LIBWRAP_SRCS := $(foreach f,$(LIBWRAP_SRCS),$(LIBWRAP_DIR)/$(f)) LIBWRAP_OBJS := $(LIBWRAP_SRCS:.c=.o) -LIBWRAP_SYMS := malloc free \ - open lseek read write fstat stat close link unlink \ - execve fork getpid kill wait \ - isatty times sbrk _exit +LIBWRAP_SYMS := \ + malloc \ + open \ + lseek _lseek\ + read _read\ + write _write\ + fstat _fstat\ + stat \ + close _close\ + link \ + unlink \ + execve \ + fork \ + getpid \ + kill \ + wait \ + isatty \ + times \ + sbrk _sbrk\ + _exit \ + puts _puts\ + printf \ + sprintf LIBWRAP := libwrap.a diff --git a/bare-metal-bsp/libwrap/sys/_exit.c b/bare-metal-bsp/libwrap/sys/_exit.c index 9a5f484..7dab930 100644 --- a/bare-metal-bsp/libwrap/sys/_exit.c +++ b/bare-metal-bsp/libwrap/sys/_exit.c @@ -5,6 +5,7 @@ extern volatile uint32_t tohost; extern volatile uint32_t fromhost; +void write_hex(int fd, uint32_t hex); void __wrap__exit(int code) { diff --git a/bare-metal-bsp/libwrap/sys/close.c b/bare-metal-bsp/libwrap/sys/close.c index e4f8e14..5f047c8 100644 --- a/bare-metal-bsp/libwrap/sys/close.c +++ b/bare-metal-bsp/libwrap/sys/close.c @@ -2,8 +2,12 @@ #include #include "stub.h" +#include "weak_under_alias.h" int __wrap_close(int fd) { return _stub(EBADF); } + +weak_under_alias(close); + diff --git a/bare-metal-bsp/libwrap/sys/fstat.c b/bare-metal-bsp/libwrap/sys/fstat.c index 6ea3e6a..41ad12c 100644 --- a/bare-metal-bsp/libwrap/sys/fstat.c +++ b/bare-metal-bsp/libwrap/sys/fstat.c @@ -4,6 +4,7 @@ #include #include #include "stub.h" +#include "weak_under_alias.h" int __wrap_fstat(int fd, struct stat* st) { @@ -14,3 +15,5 @@ int __wrap_fstat(int fd, struct stat* st) return _stub(EBADF); } + +weak_under_alias(fstat); diff --git a/bare-metal-bsp/libwrap/sys/lseek.c b/bare-metal-bsp/libwrap/sys/lseek.c index 46f58fa..74488c7 100644 --- a/bare-metal-bsp/libwrap/sys/lseek.c +++ b/bare-metal-bsp/libwrap/sys/lseek.c @@ -4,6 +4,7 @@ #include #include #include "stub.h" +#include "weak_under_alias.h" off_t __wrap_lseek(int fd, off_t ptr, int dir) { @@ -12,3 +13,6 @@ off_t __wrap_lseek(int fd, off_t ptr, int dir) return _stub(EBADF); } + +weak_under_alias(lseek); + diff --git a/bare-metal-bsp/libwrap/sys/puts.c b/bare-metal-bsp/libwrap/sys/puts.c new file mode 100644 index 0000000..50d6437 --- /dev/null +++ b/bare-metal-bsp/libwrap/sys/puts.c @@ -0,0 +1,28 @@ +/* See LICENSE of license details. */ + +#include +#include +#include +#include + +#include "platform.h" +#include "stub.h" +#include "weak_under_alias.h" + +int __wrap_puts(const char *s) +{ + while (*s != '\0') { + while (UART0_REG(UART_REG_TXFIFO) & 0x80000000) ; + UART0_REG(UART_REG_TXFIFO) = *s; + + if (*s == '\n') { + while (UART0_REG(UART_REG_TXFIFO) & 0x80000000) ; + UART0_REG(UART_REG_TXFIFO) = '\r'; + } + + ++s; + } + + return 0; +} +weak_under_alias(puts); diff --git a/bare-metal-bsp/libwrap/sys/sbrk.c b/bare-metal-bsp/libwrap/sys/sbrk.c index 6e6b36a..a43c191 100644 --- a/bare-metal-bsp/libwrap/sys/sbrk.c +++ b/bare-metal-bsp/libwrap/sys/sbrk.c @@ -1,6 +1,7 @@ /* See LICENSE of license details. */ #include +#include "weak_under_alias.h" void *__wrap_sbrk(ptrdiff_t incr) { @@ -14,3 +15,5 @@ void *__wrap_sbrk(ptrdiff_t incr) curbrk += incr; return curbrk - incr; } + +weak_under_alias(sbrk);