further semihosting support
This commit is contained in:
parent
e83f7996bc
commit
9aaf428620
|
@ -2,6 +2,7 @@
|
|||
#include <stdarg.h>
|
||||
#include <stddef.h>
|
||||
#include <string.h>
|
||||
#include <sys/types.h>
|
||||
|
||||
#include "semihosting.h"
|
||||
|
||||
|
@ -33,7 +34,7 @@
|
|||
|
||||
#define RISCV_SEMIHOSTING_CALL_NUMBER 7
|
||||
|
||||
/*typedef struct {
|
||||
typedef struct {
|
||||
char* str;
|
||||
int mode;
|
||||
size_t length;
|
||||
|
@ -48,9 +49,13 @@ typedef struct {
|
|||
|
||||
typedef struct {
|
||||
char* path;
|
||||
int len;
|
||||
size_t len;
|
||||
} RemoveVector;
|
||||
*/
|
||||
|
||||
typedef struct{
|
||||
int fd;
|
||||
off_t pos;
|
||||
} SeekVector;
|
||||
|
||||
static inline int __attribute__ ((always_inline)) call_host(int reason, void* arg) {
|
||||
#if 1
|
||||
|
@ -86,17 +91,22 @@ static inline int __attribute__ ((always_inline)) call_host(int reason, void* ar
|
|||
#endif
|
||||
}
|
||||
|
||||
/*
|
||||
int sh_errno(void) {
|
||||
return call_host(SEMIHOSTING_SYS_ERRNO, (void*)NULL);
|
||||
}
|
||||
|
||||
int sh_time(void) {
|
||||
return call_host(SEMIHOSTING_SYS_TIME, (void*)NULL);
|
||||
}
|
||||
}
|
||||
|
||||
void sh_seek(int file_handle, int pos) {
|
||||
int vec[2] = {file_handle, pos};
|
||||
int sh_remove(char* path) {
|
||||
size_t len = strlen(path);
|
||||
RemoveVector vec = {path, len};
|
||||
return call_host(SEMIHOSTING_SYS_REMOVE, &vec);
|
||||
}
|
||||
|
||||
void sh_seek(int file_handle, off_t pos) {
|
||||
SeekVector vec = {file_handle, pos};
|
||||
call_host(SEMIHOSTING_SYS_SEEK, &vec);
|
||||
return;
|
||||
}
|
||||
|
@ -135,13 +145,12 @@ int sh_iserror(int num) {
|
|||
int sh_istty(int file_handle) {
|
||||
return call_host(SEMIHOSTING_SYS_ISTTY, file_handle);
|
||||
}
|
||||
|
||||
/*
|
||||
int sh_remove(char* path) {
|
||||
int len = strlen(path);
|
||||
size_t len = strlen(path);
|
||||
RemoveVector vec = {path, len};
|
||||
return call_host(SEMIHOSTING_SYS_REMOVE, &vec);
|
||||
|
||||
}
|
||||
}*/
|
||||
|
||||
void sh_rename(char* old, char* new) {
|
||||
int old_len = strlen(old);
|
||||
|
@ -175,18 +184,22 @@ int sh_open(char* str, int mode) {
|
|||
//int length = 44;
|
||||
size_t length = strlen(str);
|
||||
OpenVector vec = {str, mode, length};
|
||||
int i = call_host(SEMIHOSTING_SYS_OPEN, &vec);
|
||||
return i;
|
||||
return call_host(SEMIHOSTING_SYS_OPEN, &vec);
|
||||
}
|
||||
|
||||
void sh_read(char* buf, int file_handle, size_t length) {
|
||||
OpenVector vec = {buf, file_handle, length};
|
||||
int i = call_host(SEMIHOSTING_SYS_READ, &vec);
|
||||
return i;
|
||||
} */
|
||||
}
|
||||
|
||||
int sh_clock(void)
|
||||
{
|
||||
int clock = call_host(SEMIHOSTING_SYS_CLOCK, (void*)NULL);
|
||||
return clock;
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
void sh_write(char* str, int file_handle) {
|
||||
return;
|
||||
}*/
|
|
@ -1,8 +1,11 @@
|
|||
#ifndef SEMIHOSTING_H
|
||||
#define SEMIHOSTING_H
|
||||
|
||||
#include <unistd.h>
|
||||
#include <sys/types.h>
|
||||
//int32_t trace_write(const char* buf, uint32_t nbyte);
|
||||
|
||||
void sh_seek(int, off_t);
|
||||
void sh_write0(const char* buf);
|
||||
void sh_writec(char c);
|
||||
char sh_readc(void);
|
||||
|
|
|
@ -17,10 +17,10 @@ void write_hex(int fd, uint32_t hex);
|
|||
|
||||
void __wrap_exit(int code)
|
||||
{
|
||||
#if defined(SEMIHOSTING)
|
||||
/*#if defined(SEMIHOSTING)
|
||||
sh_exit();
|
||||
return;
|
||||
#endif
|
||||
#endif*/
|
||||
//volatile uint32_t* leds = (uint32_t*) (GPIO_BASE_ADDR + GPIO_OUT_OFFSET);
|
||||
const char message[] = "\nProgam has exited with code:";
|
||||
//*leds = (~(code));
|
||||
|
|
|
@ -1,11 +1,10 @@
|
|||
/* See LICENSE of license details. */
|
||||
|
||||
#include <unistd.h>
|
||||
#include "weak_under_alias.h"
|
||||
#include "semihosting.h"
|
||||
#include "weak_under_alias.h"
|
||||
#include <unistd.h>
|
||||
|
||||
int __wrap_isatty(int fd)
|
||||
{
|
||||
int __wrap_isatty(int fd) {
|
||||
#if defined(SEMIHOSTING)
|
||||
int i = sh_istty(fd);
|
||||
return i;
|
||||
|
|
|
@ -12,7 +12,7 @@ off_t __wrap_lseek(int fd, off_t ptr, int dir)
|
|||
#if defined(SEMIHOSTING)
|
||||
if(sh_istty(fd))
|
||||
return 0;
|
||||
sh_seek();
|
||||
sh_seek(fd, ptr);
|
||||
return ptr;
|
||||
#endif
|
||||
if (isatty(fd))
|
||||
|
|
|
@ -7,7 +7,7 @@
|
|||
#include <stdint.h>
|
||||
#include <string.h>
|
||||
#include <unistd.h>
|
||||
#include "semihosting.h"
|
||||
//#include "semihosting.h"
|
||||
|
||||
#undef putchar
|
||||
int putchar(int ch)
|
||||
|
@ -115,11 +115,7 @@ 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++;
|
||||
|
||||
|
|
|
@ -5,6 +5,8 @@
|
|||
#include <unistd.h>
|
||||
#include <sys/types.h>
|
||||
|
||||
#include "../../include/tgc-vp/devices/uart.h"
|
||||
#include "../../env/tgc-vp/platform.h"
|
||||
#include "platform.h"
|
||||
#include "stub.h"
|
||||
#include "weak_under_alias.h"
|
||||
|
@ -15,7 +17,7 @@ int __wrap_puts(const char *s)
|
|||
#if defined(SEMIHOSTING)
|
||||
sh_write0(s);
|
||||
return 0;
|
||||
#endif
|
||||
#endif
|
||||
while (*s != '\0') {
|
||||
#if defined(BOARD_ehrenberg)
|
||||
while (uart_get_tx_free(uart)==0) ;
|
||||
|
|
|
@ -7,6 +7,8 @@
|
|||
#if defined(BOARD_ehrenberg)
|
||||
#include "platform.h"
|
||||
#endif
|
||||
#include "../../include/tgc-vp/devices/uart.h"
|
||||
#include "/scratch/gabriel/repos/Firmwares/bare-metal-bsp/env/tgc-vp/platform.h"
|
||||
#include "platform.h"
|
||||
#include "stub.h"
|
||||
#include "weak_under_alias.h"
|
||||
|
|
|
@ -5,6 +5,8 @@
|
|||
#include <unistd.h>
|
||||
#include <sys/types.h>
|
||||
|
||||
#include "../../include/tgc-vp/devices/uart.h"
|
||||
#include "../../env/tgc-vp/platform.h"
|
||||
#include "platform.h"
|
||||
#include "stub.h"
|
||||
#include "weak_under_alias.h"
|
||||
|
@ -12,11 +14,19 @@
|
|||
|
||||
ssize_t __wrap_write(int fd, const void* ptr, size_t len)
|
||||
{
|
||||
const uint8_t * current = (const uint8_t *)ptr;
|
||||
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++) {
|
||||
sh_writec(current[jj]);
|
||||
}
|
||||
return len;
|
||||
} else {
|
||||
sh_write(current, fd);
|
||||
return len;
|
||||
}
|
||||
//return len;
|
||||
#endif
|
||||
if (isatty(fd)) {
|
||||
for (size_t jj = 0; jj < len; jj++) {
|
||||
#if defined(BOARD_ehrenberg)
|
||||
|
|
Loading…
Reference in New Issue