summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--.gitignore4
-rw-r--r--bsp/env/common.mk33
-rw-r--r--bsp/env/freedom-e300-arty/init.c1
-rw-r--r--bsp/env/freedom-e300-hifive1/init.c1
-rw-r--r--bsp/env/syscall.c190
-rw-r--r--bsp/libwrap/libwrap.mk54
-rw-r--r--bsp/libwrap/misc/write_hex.c19
-rw-r--r--bsp/libwrap/stdlib/malloc.c17
-rw-r--r--bsp/libwrap/sys/_exit.c17
-rw-r--r--bsp/libwrap/sys/close.c9
-rw-r--r--bsp/libwrap/sys/execve.c9
-rw-r--r--bsp/libwrap/sys/fork.c9
-rw-r--r--bsp/libwrap/sys/fstat.c16
-rw-r--r--bsp/libwrap/sys/getpid.c6
-rw-r--r--bsp/libwrap/sys/isatty.c11
-rw-r--r--bsp/libwrap/sys/kill.c9
-rw-r--r--bsp/libwrap/sys/link.c9
-rw-r--r--bsp/libwrap/sys/lseek.c14
-rw-r--r--bsp/libwrap/sys/open.c9
-rw-r--r--bsp/libwrap/sys/openat.c9
-rw-r--r--bsp/libwrap/sys/read.c30
-rw-r--r--bsp/libwrap/sys/sbrk.c16
-rw-r--r--bsp/libwrap/sys/stat.c10
-rw-r--r--bsp/libwrap/sys/stub.h10
-rw-r--r--bsp/libwrap/sys/times.c10
-rw-r--r--bsp/libwrap/sys/unlink.c9
-rw-r--r--bsp/libwrap/sys/wait.c9
-rw-r--r--bsp/libwrap/sys/write.c29
-rw-r--r--software/demo_gpio/.gitignore1
-rw-r--r--software/demo_gpio/Makefile2
-rw-r--r--software/dhrystone/.gitignore1
-rw-r--r--software/dhrystone/Makefile5
-rw-r--r--software/dhrystone/dhry_printf.c4
-rw-r--r--software/dhrystone/dhry_stubs.c15
-rw-r--r--software/hello/.gitignore1
-rw-r--r--software/hello/Makefile2
36 files changed, 379 insertions, 221 deletions
diff --git a/.gitignore b/.gitignore
new file mode 100644
index 0000000..0b8d3e8
--- /dev/null
+++ b/.gitignore
@@ -0,0 +1,4 @@
+*.o
+*.a
+work/
+toolchain/
diff --git a/bsp/env/common.mk b/bsp/env/common.mk
index 8d91805..0f5e9a1 100644
--- a/bsp/env/common.mk
+++ b/bsp/env/common.mk
@@ -1,5 +1,13 @@
# See LICENSE for license details.
+ifndef _SIFIVE_MK_COMMON
+_SIFIVE_MK_COMMON := # defined
+
+.PHONY: all
+all: $(TARGET)
+
+include $(BSP_BASE)/libwrap/libwrap.mk
+
BOARD ?= freedom-e300-hifive1
ENV_DIR = $(BSP_BASE)/env
PLATFORM_DIR = $(ENV_DIR)/$(BOARD)
@@ -7,28 +15,32 @@ PLATFORM_DIR = $(ENV_DIR)/$(BOARD)
ASM_SRCS += $(PLATFORM_DIR)/start.S
ASM_SRCS += $(PLATFORM_DIR)/entry.S
C_SRCS += $(PLATFORM_DIR)/init.c
-C_SRCS += $(ENV_DIR)/syscall.c
LINKER_SCRIPT := $(PLATFORM_DIR)/link.lds
-INCLUDES += -I.
INCLUDES += -I$(BSP_BASE)/include
INCLUDES += -I$(ENV_DIR)
INCLUDES += -I$(PLATFORM_DIR)
-CC := $(BSP_BASE)/../toolchain/bin/riscv32-unknown-elf-gcc
+TOOL_DIR = $(BSP_BASE)/../toolchain/bin
-LDFLAGS += -T $(LINKER_SCRIPT) -nostdlib -nostartfiles -lc -lgcc
+CC := $(TOOL_DIR)/riscv32-unknown-elf-gcc
+AR := $(TOOL_DIR)/riscv32-unknown-elf-ar
+
+LDFLAGS += -T $(LINKER_SCRIPT) -nostartfiles
LDFLAGS += -L$(ENV_DIR)
-ASM_OBJS := $(patsubst %.S,%.o,$(ASM_SRCS))
-C_OBJS := $(patsubst %.c,%.o,$(C_SRCS))
+ASM_OBJS := $(ASM_SRCS:.S=.o)
+C_OBJS := $(C_SRCS:.c=.o)
LINK_OBJS += $(ASM_OBJS) $(C_OBJS)
+LINK_DEPS += $(LINKER_SCRIPT)
+
+CLEAN_OBJS += $(TARGET) $(LINK_OBJS)
CFLAGS += -g
-$(TARGET): $(LINK_OBJS) $(LINKER_SCRIPT)
+$(TARGET): $(LINK_OBJS) $(LINK_DEPS)
$(CC) $(CFLAGS) $(INCLUDES) $(LINK_OBJS) -o $@ $(LDFLAGS)
$(ASM_OBJS): %.o: %.S $(HEADERS)
@@ -37,9 +49,8 @@ $(ASM_OBJS): %.o: %.S $(HEADERS)
$(C_OBJS): %.o: %.c $(HEADERS)
$(CC) $(CFLAGS) $(INCLUDES) -c -o $@ $<
-all: $(TARGET)
-
+.PHONY: clean
clean:
- rm -f $(TARGET) $(LINK_OBJS)
+ rm -f $(CLEAN_OBJS)
-.PHONY: all clean
+endif # _SIFIVE_MK_COMMON
diff --git a/bsp/env/freedom-e300-arty/init.c b/bsp/env/freedom-e300-arty/init.c
index 1f26b19..a7e368e 100644
--- a/bsp/env/freedom-e300-arty/init.c
+++ b/bsp/env/freedom-e300-arty/init.c
@@ -1,5 +1,6 @@
//See LICENSE for license details.
#include <stdint.h>
+#include <stdio.h>
#include <unistd.h>
#include "platform.h"
diff --git a/bsp/env/freedom-e300-hifive1/init.c b/bsp/env/freedom-e300-hifive1/init.c
index 268d41e..c088079 100644
--- a/bsp/env/freedom-e300-hifive1/init.c
+++ b/bsp/env/freedom-e300-hifive1/init.c
@@ -1,4 +1,5 @@
#include <stdint.h>
+#include <stdio.h>
#include <unistd.h>
#include "platform.h"
diff --git a/bsp/env/syscall.c b/bsp/env/syscall.c
deleted file mode 100644
index 1b5de50..0000000
--- a/bsp/env/syscall.c
+++ /dev/null
@@ -1,190 +0,0 @@
-// See LICENSE for license details.
-
-/* This is an incomplete version of a syscall library,
- * which really only supports simple reads and writes over UART.
- */
-
-#include <stdint.h>
-#include <stdlib.h>
-#include <stddef.h>
-#include <unistd.h>
-#include <errno.h>
-#include <sys/stat.h>
-#include <sys/times.h>
-#include <stdio.h>
-#include <string.h>
-
-#include "platform.h"
-
-void write_hex(int fd, uint32_t hex)
-{
- uint8_t ii;
- uint8_t jj;
- char towrite;
- write(fd , "0x", 2);
- for (ii = 8 ; ii > 0; ii--) {
- jj = ii - 1;
- uint8_t digit = ((hex & (0xF << (jj*4))) >> (jj*4));
- towrite = digit < 0xA ? ('0' + digit) : ('A' + (digit - 0xA));
- write(fd, &towrite, 1);
- }
-}
-
-void _exit(int code)
-{
- //volatile uint32_t* leds = (uint32_t*) (GPIO_BASE_ADDR + GPIO_OUT_OFFSET);
- const char * message = "\nProgam has exited with code:";
-
- //*leds = (~(code));
-
- write(STDERR_FILENO, message, strlen(message));
- write_hex(STDERR_FILENO, code);
- write(STDERR_FILENO, "\n", 1);
-
- while (1) ;
-}
-
-void *sbrk(ptrdiff_t incr)
-{
- extern char _end[];
- extern char _heap_end[];
- static char *curbrk = _end;
-
- if ((curbrk + incr < _end) || (curbrk + incr > _heap_end))
- return NULL - 1;
-
- curbrk += incr;
- return curbrk - incr;
-}
-
-static int stub(int err)
-{
- return -1;
-}
-
-int open(const char* name, int flags, int mode)
-{
- return stub(ENOENT);
-}
-
-int openat(int dirfd, const char* name, int flags, int mode)
-{
- return stub(ENOENT);
-}
-
-int close(int fd)
-{
- return stub(EBADF);
-}
-
-int execve(const char* name, char* const argv[], char* const env[])
-{
- return stub(ENOMEM);
-}
-
-int fork()
-{
- return stub(EAGAIN);
-}
-
-int fstat(int fd, struct stat *st)
-{
- if (isatty(fd)) {
- st->st_mode = S_IFCHR;
- return 0;
- }
-
- return stub(EBADF);
-}
-
-int getpid()
-{
- return 1;
-}
-
-int isatty(int fd)
-{
- if (fd == STDOUT_FILENO || fd == STDERR_FILENO)
- return 1;
-
- return 0;
-}
-
-int kill(int pid, int sig)
-{
- return stub(EINVAL);
-}
-
-int link(const char *old_name, const char *new_name)
-{
- return stub(EMLINK);
-}
-
-off_t lseek(int fd, off_t ptr, int dir)
-{
- if (isatty(fd))
- return 0;
-
- return stub(EBADF);
-}
-
-ssize_t read(int fd, void* ptr, size_t len)
-{
- uint8_t * current = (uint8_t *)ptr;
- volatile uint32_t * uart_rx = (uint32_t *)(UART0_BASE_ADDR + UART_REG_RXFIFO);
- volatile uint8_t * uart_rx_cnt = (uint8_t *)(UART0_BASE_ADDR + UART_REG_RXCTRL + 2);
-
- ssize_t result = 0;
-
- if (isatty(fd)) {
- for (current = (uint8_t *)ptr;
- (current < ((uint8_t *)ptr) + len) && (*uart_rx_cnt > 0);
- current ++) {
- *current = *uart_rx;
- result++;
- }
- return result;
- }
-
- return stub(EBADF);
-}
-
-int stat(const char* file, struct stat* st)
-{
- return stub(EACCES);
-}
-
-clock_t times(struct tms* buf)
-{
- return stub(EACCES);
-}
-
-int unlink(const char* name)
-{
- return stub(ENOENT);
-}
-
-int wait(int* status)
-{
- return stub(ECHILD);
-}
-
-ssize_t write(int fd, const void* ptr, size_t len)
-{
- const uint8_t * current = (const char *)ptr;
-
- if (isatty(fd)) {
- for (size_t jj = 0; jj < len; jj++) {
- while (UART0_REG(UART_REG_TXFIFO) & 0x80000000) ;
- UART0_REG(UART_REG_TXFIFO) = current[jj];
-
- if (current[jj] == '\n') {
- while (UART0_REG(UART_REG_TXFIFO) & 0x80000000) ;
- UART0_REG(UART_REG_TXFIFO) = '\r';
- }
- }
- return len;
- }
-
- return stub(EBADF);
-}
diff --git a/bsp/libwrap/libwrap.mk b/bsp/libwrap/libwrap.mk
new file mode 100644
index 0000000..313ed00
--- /dev/null
+++ b/bsp/libwrap/libwrap.mk
@@ -0,0 +1,54 @@
+# See LICENSE for license details.
+
+ifndef _SIFIVE_MK_LIBWRAP
+_SIFIVE_MK_LIBWRAP := # defined
+
+LIBWRAP_DIR := $(dir $(lastword $(MAKEFILE_LIST)))
+LIBWRAP_DIR := $(LIBWRAP_DIR:/=)
+
+LIBWRAP_SRCS := \
+ stdlib/malloc.c \
+ sys/open.c \
+ sys/lseek.c \
+ sys/read.c \
+ sys/write.c \
+ sys/fstat.c \
+ sys/stat.c \
+ sys/close.c \
+ sys/link.c \
+ sys/unlink.c \
+ sys/execve.c \
+ sys/fork.c \
+ sys/getpid.c \
+ sys/kill.c \
+ sys/wait.c \
+ sys/isatty.c \
+ sys/times.c \
+ sys/sbrk.c \
+ sys/_exit.c \
+ misc/write_hex.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 := libwrap.a
+
+LINK_DEPS += $(LIBWRAP)
+
+LDFLAGS += $(foreach s,$(LIBWRAP_SYMS),-Wl,--wrap=$(s))
+LDFLAGS += -L. -Wl,--start-group -lwrap -lc -Wl,--end-group
+
+CLEAN_OBJS += $(LIBWRAP_OBJS)
+
+$(LIBWRAP_OBJS): %.o: %.c $(HEADERS)
+ $(CC) $(CFLAGS) $(INCLUDES) -c -o $@ $<
+
+$(LIBWRAP): $(LIBWRAP_OBJS)
+ $(AR) rcs $@ $^
+
+endif # _SIFIVE_MK_LIBWRAP
diff --git a/bsp/libwrap/misc/write_hex.c b/bsp/libwrap/misc/write_hex.c
new file mode 100644
index 0000000..e678bdc
--- /dev/null
+++ b/bsp/libwrap/misc/write_hex.c
@@ -0,0 +1,19 @@
+/* See LICENSE of license details. */
+
+#include <stdint.h>
+#include <unistd.h>
+#include "platform.h"
+
+void write_hex(int fd, uint32_t hex)
+{
+ uint8_t ii;
+ uint8_t jj;
+ char towrite;
+ write(fd , "0x", 2);
+ for (ii = 8 ; ii > 0; ii--) {
+ jj = ii - 1;
+ uint8_t digit = ((hex & (0xF << (jj*4))) >> (jj*4));
+ towrite = digit < 0xA ? ('0' + digit) : ('A' + (digit - 0xA));
+ write(fd, &towrite, 1);
+ }
+}
diff --git a/bsp/libwrap/stdlib/malloc.c b/bsp/libwrap/stdlib/malloc.c
new file mode 100644
index 0000000..8f4f432
--- /dev/null
+++ b/bsp/libwrap/stdlib/malloc.c
@@ -0,0 +1,17 @@
+/* See LICENSE for license details. */
+
+/* These functions are intended for embedded RV32 systems and are
+ obviously incorrect in general. */
+
+void* __wrap_malloc(unsigned long sz)
+{
+ extern void* sbrk(long);
+ void* res = sbrk(sz);
+ if ((long)res == -1)
+ return 0;
+ return res;
+}
+
+void __wrap_free(void* ptr)
+{
+}
diff --git a/bsp/libwrap/sys/_exit.c b/bsp/libwrap/sys/_exit.c
new file mode 100644
index 0000000..7261891
--- /dev/null
+++ b/bsp/libwrap/sys/_exit.c
@@ -0,0 +1,17 @@
+/* See LICENSE of license details. */
+
+#include <unistd.h>
+#include "platform.h"
+
+void __wrap__exit(int code)
+{
+//volatile uint32_t* leds = (uint32_t*) (GPIO_BASE_ADDR + GPIO_OUT_OFFSET);
+ const char message[] = "\nProgam has exited with code:";
+//*leds = (~(code));
+
+ write(STDERR_FILENO, message, sizeof(message) - 1);
+ write_hex(STDERR_FILENO, code);
+ write(STDERR_FILENO, "\n", 1);
+
+ for (;;);
+}
diff --git a/bsp/libwrap/sys/close.c b/bsp/libwrap/sys/close.c
new file mode 100644
index 0000000..e4f8e14
--- /dev/null
+++ b/bsp/libwrap/sys/close.c
@@ -0,0 +1,9 @@
+/* See LICENSE of license details. */
+
+#include <errno.h>
+#include "stub.h"
+
+int __wrap_close(int fd)
+{
+ return _stub(EBADF);
+}
diff --git a/bsp/libwrap/sys/execve.c b/bsp/libwrap/sys/execve.c
new file mode 100644
index 0000000..6178a01
--- /dev/null
+++ b/bsp/libwrap/sys/execve.c
@@ -0,0 +1,9 @@
+/* See LICENSE of license details. */
+
+#include <errno.h>
+#include "stub.h"
+
+int __wrap_execve(const char* name, char* const argv[], char* const env[])
+{
+ return _stub(ENOMEM);
+}
diff --git a/bsp/libwrap/sys/fork.c b/bsp/libwrap/sys/fork.c
new file mode 100644
index 0000000..13a3e65
--- /dev/null
+++ b/bsp/libwrap/sys/fork.c
@@ -0,0 +1,9 @@
+/* See LICENSE of license details. */
+
+#include <errno.h>
+#include "stub.h"
+
+int fork(void)
+{
+ return _stub(EAGAIN);
+}
diff --git a/bsp/libwrap/sys/fstat.c b/bsp/libwrap/sys/fstat.c
new file mode 100644
index 0000000..6ea3e6a
--- /dev/null
+++ b/bsp/libwrap/sys/fstat.c
@@ -0,0 +1,16 @@
+/* See LICENSE of license details. */
+
+#include <errno.h>
+#include <unistd.h>
+#include <sys/stat.h>
+#include "stub.h"
+
+int __wrap_fstat(int fd, struct stat* st)
+{
+ if (isatty(fd)) {
+ st->st_mode = S_IFCHR;
+ return 0;
+ }
+
+ return _stub(EBADF);
+}
diff --git a/bsp/libwrap/sys/getpid.c b/bsp/libwrap/sys/getpid.c
new file mode 100644
index 0000000..5aa510b
--- /dev/null
+++ b/bsp/libwrap/sys/getpid.c
@@ -0,0 +1,6 @@
+/* See LICENSE of license details. */
+
+int __wrap_getpid(void)
+{
+ return 1;
+}
diff --git a/bsp/libwrap/sys/isatty.c b/bsp/libwrap/sys/isatty.c
new file mode 100644
index 0000000..55eab0a
--- /dev/null
+++ b/bsp/libwrap/sys/isatty.c
@@ -0,0 +1,11 @@
+/* See LICENSE of license details. */
+
+#include <unistd.h>
+
+int __wrap_isatty(int fd)
+{
+ if (fd == STDOUT_FILENO || fd == STDERR_FILENO)
+ return 1;
+
+ return 0;
+}
diff --git a/bsp/libwrap/sys/kill.c b/bsp/libwrap/sys/kill.c
new file mode 100644
index 0000000..9c56632
--- /dev/null
+++ b/bsp/libwrap/sys/kill.c
@@ -0,0 +1,9 @@
+/* See LICENSE of license details. */
+
+#include <errno.h>
+#include "stub.h"
+
+int __wrap_kill(int pid, int sig)
+{
+ return _stub(EINVAL);
+}
diff --git a/bsp/libwrap/sys/link.c b/bsp/libwrap/sys/link.c
new file mode 100644
index 0000000..9340cad
--- /dev/null
+++ b/bsp/libwrap/sys/link.c
@@ -0,0 +1,9 @@
+/* See LICENSE of license details. */
+
+#include <errno.h>
+#include "stub.h"
+
+int __wrap_link(const char *old_name, const char *new_name)
+{
+ return _stub(EMLINK);
+}
diff --git a/bsp/libwrap/sys/lseek.c b/bsp/libwrap/sys/lseek.c
new file mode 100644
index 0000000..46f58fa
--- /dev/null
+++ b/bsp/libwrap/sys/lseek.c
@@ -0,0 +1,14 @@
+/* See LICENSE of license details. */
+
+#include <errno.h>
+#include <unistd.h>
+#include <sys/types.h>
+#include "stub.h"
+
+off_t __wrap_lseek(int fd, off_t ptr, int dir)
+{
+ if (isatty(fd))
+ return 0;
+
+ return _stub(EBADF);
+}
diff --git a/bsp/libwrap/sys/open.c b/bsp/libwrap/sys/open.c
new file mode 100644
index 0000000..d1871f9
--- /dev/null
+++ b/bsp/libwrap/sys/open.c
@@ -0,0 +1,9 @@
+/* See LICENSE of license details. */
+
+#include <errno.h>
+#include "stub.h"
+
+int __wrap_open(const char* name, int flags, int mode)
+{
+ return _stub(ENOENT);
+}
diff --git a/bsp/libwrap/sys/openat.c b/bsp/libwrap/sys/openat.c
new file mode 100644
index 0000000..7f1c945
--- /dev/null
+++ b/bsp/libwrap/sys/openat.c
@@ -0,0 +1,9 @@
+/* See LICENSE of license details. */
+
+#include <errno.h>
+#include "stub.h"
+
+int __wrap_openat(int dirfd, const char* name, int flags, int mode)
+{
+ return _stub(ENOENT);
+}
diff --git a/bsp/libwrap/sys/read.c b/bsp/libwrap/sys/read.c
new file mode 100644
index 0000000..4e57f08
--- /dev/null
+++ b/bsp/libwrap/sys/read.c
@@ -0,0 +1,30 @@
+/* See LICENSE of license details. */
+
+#include <stdint.h>
+#include <errno.h>
+#include <unistd.h>
+#include <sys/types.h>
+
+#include "platform.h"
+#include "stub.h"
+
+ssize_t __wrap_read(int fd, void* ptr, size_t len)
+{
+ uint8_t * current = (uint8_t *)ptr;
+ volatile uint32_t * uart_rx = (uint32_t *)(UART0_BASE_ADDR + UART_REG_RXFIFO);
+ volatile uint8_t * uart_rx_cnt = (uint8_t *)(UART0_BASE_ADDR + UART_REG_RXCTRL + 2);
+
+ ssize_t result = 0;
+
+ if (isatty(fd)) {
+ for (current = (uint8_t *)ptr;
+ (current < ((uint8_t *)ptr) + len) && (*uart_rx_cnt > 0);
+ current ++) {
+ *current = *uart_rx;
+ result++;
+ }
+ return result;
+ }
+
+ return _stub(EBADF);
+}
diff --git a/bsp/libwrap/sys/sbrk.c b/bsp/libwrap/sys/sbrk.c
new file mode 100644
index 0000000..6e6b36a
--- /dev/null
+++ b/bsp/libwrap/sys/sbrk.c
@@ -0,0 +1,16 @@
+/* See LICENSE of license details. */
+
+#include <stddef.h>
+
+void *__wrap_sbrk(ptrdiff_t incr)
+{
+ extern char _end[];
+ extern char _heap_end[];
+ static char *curbrk = _end;
+
+ if ((curbrk + incr < _end) || (curbrk + incr > _heap_end))
+ return NULL - 1;
+
+ curbrk += incr;
+ return curbrk - incr;
+}
diff --git a/bsp/libwrap/sys/stat.c b/bsp/libwrap/sys/stat.c
new file mode 100644
index 0000000..1ccc2f4
--- /dev/null
+++ b/bsp/libwrap/sys/stat.c
@@ -0,0 +1,10 @@
+/* See LICENSE of license details. */
+
+#include <errno.h>
+#include <sys/stat.h>
+#include "stub.h"
+
+int __wrap_stat(const char* file, struct stat* st)
+{
+ return _stub(EACCES);
+}
diff --git a/bsp/libwrap/sys/stub.h b/bsp/libwrap/sys/stub.h
new file mode 100644
index 0000000..fb5e5be
--- /dev/null
+++ b/bsp/libwrap/sys/stub.h
@@ -0,0 +1,10 @@
+/* See LICENSE of license details. */
+#ifndef _SIFIVE_SYS_STUB_H
+#define _SIFIVE_SYS_STUB_H
+
+static inline int _stub(int err)
+{
+ return -1;
+}
+
+#endif /* _SIFIVE_SYS_STUB_H */
diff --git a/bsp/libwrap/sys/times.c b/bsp/libwrap/sys/times.c
new file mode 100644
index 0000000..26a9566
--- /dev/null
+++ b/bsp/libwrap/sys/times.c
@@ -0,0 +1,10 @@
+/* See LICENSE of license details. */
+
+#include <errno.h>
+#include <sys/times.h>
+#include "stub.h"
+
+clock_t __wrap_times(struct tms* buf)
+{
+ return _stub(EACCES);
+}
diff --git a/bsp/libwrap/sys/unlink.c b/bsp/libwrap/sys/unlink.c
new file mode 100644
index 0000000..b62b1ba
--- /dev/null
+++ b/bsp/libwrap/sys/unlink.c
@@ -0,0 +1,9 @@
+/* See LICENSE of license details. */
+
+#include <errno.h>
+#include "stub.h"
+
+int __wrap_unlink(const char* name)
+{
+ return _stub(ENOENT);
+}
diff --git a/bsp/libwrap/sys/wait.c b/bsp/libwrap/sys/wait.c
new file mode 100644
index 0000000..ea3225b
--- /dev/null
+++ b/bsp/libwrap/sys/wait.c
@@ -0,0 +1,9 @@
+/* See LICENSE of license details. */
+
+#include <errno.h>
+#include "stub.h"
+
+int wait(int* status)
+{
+ return _stub(ECHILD);
+}
diff --git a/bsp/libwrap/sys/write.c b/bsp/libwrap/sys/write.c
new file mode 100644
index 0000000..d00eb17
--- /dev/null
+++ b/bsp/libwrap/sys/write.c
@@ -0,0 +1,29 @@
+/* See LICENSE of license details. */
+
+#include <stdint.h>
+#include <errno.h>
+#include <unistd.h>
+#include <sys/types.h>
+
+#include "platform.h"
+#include "stub.h"
+
+ssize_t __wrap_write(int fd, const void* ptr, size_t len)
+{
+ const uint8_t * current = (const char *)ptr;
+
+ if (isatty(fd)) {
+ for (size_t jj = 0; jj < len; jj++) {
+ while (UART0_REG(UART_REG_TXFIFO) & 0x80000000) ;
+ UART0_REG(UART_REG_TXFIFO) = current[jj];
+
+ if (current[jj] == '\n') {
+ while (UART0_REG(UART_REG_TXFIFO) & 0x80000000) ;
+ UART0_REG(UART_REG_TXFIFO) = '\r';
+ }
+ }
+ return len;
+ }
+
+ return _stub(EBADF);
+}
diff --git a/software/demo_gpio/.gitignore b/software/demo_gpio/.gitignore
new file mode 100644
index 0000000..35566c7
--- /dev/null
+++ b/software/demo_gpio/.gitignore
@@ -0,0 +1 @@
+demo_gpio
diff --git a/software/demo_gpio/Makefile b/software/demo_gpio/Makefile
index 0a0b148..04a11b7 100644
--- a/software/demo_gpio/Makefile
+++ b/software/demo_gpio/Makefile
@@ -1,7 +1,7 @@
TARGET = demo_gpio
C_SRCS += demo_gpio.c
C_SRCS += plic_driver.c
-CFLAGS += -fno-builtin-printf -DUSE_PLIC -DUSE_M_TIME
+CFLAGS += -O2 -fno-builtin-printf -DUSE_PLIC -DUSE_M_TIME
BSP_BASE = ../../bsp
include $(BSP_BASE)/env/common.mk
diff --git a/software/dhrystone/.gitignore b/software/dhrystone/.gitignore
new file mode 100644
index 0000000..eb51a6c
--- /dev/null
+++ b/software/dhrystone/.gitignore
@@ -0,0 +1 @@
+dhrystone
diff --git a/software/dhrystone/Makefile b/software/dhrystone/Makefile
index 2058ca1..a55b1ec 100644
--- a/software/dhrystone/Makefile
+++ b/software/dhrystone/Makefile
@@ -5,10 +5,11 @@ C_SRCS := dhry_stubs.c dhry_printf.c
HEADERS := dhry.h
DHRY_SRCS := dhry_1.c dhry_2.c
-DHRY_CFLAGS := -O2 -DTIME -fno-inline -Wno-implicit
+DHRY_CFLAGS := -O2 -DTIME -fno-inline -fno-builtin-printf -Wno-implicit
XLEN ?= 32
-CFLAGS := -Dscanf=dhry_scanf -Dprintf=dhry_printf -Os -fno-common
+CFLAGS := -Os -fno-common
+LDFLAGS := -Wl,--wrap=scanf -Wl,--wrap=printf
DHRY_OBJS := $(patsubst %.c,%.o,$(DHRY_SRCS))
LINK_OBJS := $(DHRY_OBJS)
diff --git a/software/dhrystone/dhry_printf.c b/software/dhrystone/dhry_printf.c
index 1fdaac4..025d231 100644
--- a/software/dhrystone/dhry_printf.c
+++ b/software/dhrystone/dhry_printf.c
@@ -246,7 +246,7 @@ static void vprintfmt(void (*putch)(int, void**), void **putdat, const char *fmt
}
}
-int printf(const char* fmt, ...)
+int __wrap_printf(const char* fmt, ...)
{
va_list ap;
va_start(ap, fmt);
@@ -257,7 +257,7 @@ int printf(const char* fmt, ...)
return 0; // incorrect return value, but who cares, anyway?
}
-int sprintf(char* str, const char* fmt, ...)
+int __wrap_sprintf(char* str, const char* fmt, ...)
{
va_list ap;
char* str0 = str;
diff --git a/software/dhrystone/dhry_stubs.c b/software/dhrystone/dhry_stubs.c
index d384bf1..d3bd14c 100644
--- a/software/dhrystone/dhry_stubs.c
+++ b/software/dhrystone/dhry_stubs.c
@@ -12,20 +12,7 @@ long time(void)
}
// set the number of dhrystone iterations
-void scanf(const char* fmt, int* n)
+void __wrap_scanf(const char* fmt, int* n)
{
*n = 1500000;
}
-
-// simple memory allocator
-void* malloc(unsigned long sz)
-{
- extern void* sbrk(long);
- void* res = sbrk(sz);
- if ((long)res == -1)
- return 0;
- return res;
-}
-
-// simple memory deallocator
-void free(void* ptr) {}
diff --git a/software/hello/.gitignore b/software/hello/.gitignore
new file mode 100644
index 0000000..ce01362
--- /dev/null
+++ b/software/hello/.gitignore
@@ -0,0 +1 @@
+hello
diff --git a/software/hello/Makefile b/software/hello/Makefile
index c0c5c55..058621c 100644
--- a/software/hello/Makefile
+++ b/software/hello/Makefile
@@ -1,6 +1,6 @@
TARGET = hello
C_SRCS += hello.c
-CFLAGS += -fno-builtin-printf
+CFLAGS += -O2 -fno-builtin-printf
BSP_BASE = ../../bsp
include $(BSP_BASE)/env/common.mk