Adding semihosting support for bmsp

This commit is contained in:
gabriel
2024-04-08 14:36:22 +02:00
parent 39ee91af7d
commit e83f7996bc
14 changed files with 175 additions and 7 deletions

View File

@ -3,6 +3,7 @@
#include <unistd.h>
#include "platform.h"
#include "weak_under_alias.h"
#include "semihosting.h"
#if defined(BOARD_hifive1)
static volatile uint32_t tohost;
@ -16,6 +17,10 @@ void write_hex(int fd, uint32_t hex);
void __wrap_exit(int code)
{
#if defined(SEMIHOSTING)
sh_exit();
return;
#endif
//volatile uint32_t* leds = (uint32_t*) (GPIO_BASE_ADDR + GPIO_OUT_OFFSET);
const char message[] = "\nProgam has exited with code:";
//*leds = (~(code));

View File

@ -3,9 +3,14 @@
#include <errno.h>
#include "stub.h"
#include "weak_under_alias.h"
#include "semihosting.h"
int __wrap_close(int fd)
{
#if defined(SEMIHOTING)
int i = sh_close(fd);
return i;
#endif
return _stub(EBADF);
}

View File

@ -2,9 +2,14 @@
#include <unistd.h>
#include "weak_under_alias.h"
#include "semihosting.h"
int __wrap_isatty(int fd)
{
#if defined(SEMIHOSTING)
int i = sh_istty(fd);
return i;
#endif
if (fd == STDOUT_FILENO || fd == STDERR_FILENO)
return 1;

View File

@ -5,9 +5,16 @@
#include <sys/types.h>
#include "stub.h"
#include "weak_under_alias.h"
#include "semihosting.h"
off_t __wrap_lseek(int fd, off_t ptr, int dir)
{
#if defined(SEMIHOSTING)
if(sh_istty(fd))
return 0;
sh_seek();
return ptr;
#endif
if (isatty(fd))
return 0;

View File

@ -3,9 +3,14 @@
#include <errno.h>
#include "stub.h"
#include "weak_under_alias.h"
#include "semihosting.h"
int __wrap_open(const char* name, int flags, int mode)
{
#if defined(SEMIHOSTING)
int fd = sh_open(name, mode);
return fd;
#endif
return _stub(ENOENT);
}
weak_under_alias(open);

View File

@ -7,6 +7,7 @@
#include <stdint.h>
#include <string.h>
#include <unistd.h>
#include "semihosting.h"
#undef putchar
int putchar(int ch)
@ -114,7 +115,11 @@ static void vprintfmt(void (*putch)(int, void**), void **putdat, const char *fmt
if (ch == '\0')
return;
fmt++;
#if defined(SEMIHOSTING)
sh_writec(ch);
#else
putch(ch, putdat);
#endif
}
fmt++;

View File

@ -8,9 +8,14 @@
#include "platform.h"
#include "stub.h"
#include "weak_under_alias.h"
#include "semihosting.h"
int __wrap_puts(const char *s)
{
#if defined(SEMIHOSTING)
sh_write0(s);
return 0;
#endif
while (*s != '\0') {
#if defined(BOARD_ehrenberg)
while (uart_get_tx_free(uart)==0) ;

View File

@ -10,10 +10,15 @@
#include "platform.h"
#include "stub.h"
#include "weak_under_alias.h"
#include "semihosting.h"
ssize_t __wrap_read(int fd, void* ptr, size_t len)
{
uint8_t * current = (uint8_t *)ptr;
#if defined(SEMIHOSTING)
sh_read(current, fd, len);
return;
#endif
#if defined(BOARD_hifive1)
volatile uint32_t * uart_rx = (uint32_t *)(UART0_CTRL_ADDR + UART_REG_RXFIFO);
volatile uint8_t * uart_rx_cnt = (uint8_t *)(UART0_CTRL_ADDR + UART_REG_RXCTRL + 2);

View File

@ -3,9 +3,13 @@
#include <errno.h>
#include "stub.h"
#include "weak_under_alias.h"
#include "semihosting.h"
int __wrap_unlink(const char* name)
{
#if defined(SEMIHOSTING)
return sh_remove(name);
#endif
return _stub(ENOENT);
}
weak_under_alias(unlink);

View File

@ -8,10 +8,15 @@
#include "platform.h"
#include "stub.h"
#include "weak_under_alias.h"
#include "semihosting.h"
ssize_t __wrap_write(int fd, const void* ptr, size_t len)
{
const uint8_t * current = (const uint8_t *)ptr;
#if defined(SEMIHOSTING)
sh_write(current, fd);
return len;
#endif
if (isatty(fd)) {
for (size_t jj = 0; jj < len; jj++) {
#if defined(BOARD_ehrenberg)