From ae5f878d6acadabaa671a7a30b87e16eb1d718a7 Mon Sep 17 00:00:00 2001 From: Megan Wachs Date: Wed, 30 Nov 2016 10:55:18 -0800 Subject: Bump Everything to Match new Freedom Repo (#8) * Bump tool versions * Use version of OpenOCD which can load programs into flash * Bump OpenOCD to Handle ISSI Flash Programming * Update Header files * add initial support for hifive1 * add dhrystone * add clock helper functions * add openocd cfg file * Demo_GPIO checkpoint -- compiles and runs but no blinky LEDs * Remove riscv-tests submodule * Remove FPGA files, as they are no longer relevant to this Repository * Add openocd_upload script * Add Pinmux Mappings Adding the pinmux mappings to the Platform Header * Add IOF Mappings to platform header * Re-order the IOF Mapping declarations * Add more useful things to platform headers * Get GPIO Demo working again (except interrupts aren't working) * Update README with more OS packages needed A bare ubuntu-16.04.1-server installation could not run `make tools` without these packages. * bump openocd to get SCKDIV fix * Remove duplicated help text for run_debug target * Add package to README that is needed for openocd build Without this package I was seeing two different failures like below when running `make tools`. /home/scottj/freedom-e-sdk/openocd/configure: line 4533: syntax error near unexpected token `0.23' /home/scottj/freedom-e-sdk/openocd/configure: line 4533: `PKG_PROG_PKG_CONFIG(0.23)' Makefile:70: recipe for target '/home/scottj/freedom-e-sdk/toolchain/bin/openocd' failed make: *** [/home/scottj/freedom-e-sdk/toolchain/bin/openocd] Error 2 ... or ... + autoconf configure.ac:12: error: possibly undefined macro: AC_MSG_WARN If this token and others are legitimate, please use m4_pattern_allow. See the Autoconf documentation. configure.ac:240: error: possibly undefined macro: AC_MSG_NOTICE configure.ac:342: error: possibly undefined macro: AC_DEFINE Makefile:70: recipe for target '/home/scottj/freedom-e-sdk/toolchain/bin/openocd' failed make: *** [/home/scottj/freedom-e-sdk/toolchain/bin/openocd] Error 1 * Bump OpenOCD to not overwrite SCKDIV when flashing * Roll back CoreMark --- bsp/env/syscall.c | 190 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 190 insertions(+) create mode 100644 bsp/env/syscall.c (limited to 'bsp/env/syscall.c') diff --git a/bsp/env/syscall.c b/bsp/env/syscall.c new file mode 100644 index 0000000..1b5de50 --- /dev/null +++ b/bsp/env/syscall.c @@ -0,0 +1,190 @@ +// 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 +#include +#include +#include +#include +#include +#include +#include +#include + +#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); +} -- cgit v1.2.3