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