update include path

This commit is contained in:
Gabriel Konecny 2024-05-31 09:21:57 +02:00
parent 9407d2cec5
commit c94eb7c61a
12 changed files with 140 additions and 141 deletions

2
env/entry.S vendored
View File

@ -41,7 +41,7 @@ trap_entry:
csrr a0, mcause
csrr a1, mepc
mv a2, sp
call trap
call handle_trap
csrw mepc, a0
#ifndef __riscv_abi_rve
addi sp, sp, -8*REGBYTES

View File

@ -1,9 +1,10 @@
#include <math.h>
#include <stdint.h>
#include <stdlib.h>
#include <math.h>
#include "encoding.h"
#if defined(SEMIHOSTING)
#define EBREAK_OPCODE 0x00100073
#define EBREAK_MCAUSE 0x00000003
@ -12,8 +13,8 @@
int sh_missing_host = 0;
void trap()
{ //ToDo: Check why macro CSR_MEPC and others are not resolved
void trap() { // ToDo: Check why macro CSR_MEPC and others are not
// resolved
uint32_t mepc = read_csr(0x341); // Address of trap
uint32_t mtval = read_csr(0x343); // Instruction value of trap
uint32_t mcause = read_csr(0x342); // Reason for the trap
@ -22,11 +23,9 @@ void trap()
// This trap was caused by an EBREAK...
int aligned = ((mepc - 4) & 0x0f) == 0;
if (aligned
&& *(uint32_t *)mepc == EBREAK_OPCODE
&& *(uint32_t *)(mepc-4) == SLLI_X0_X0_0X1F_OPCODE
&& *(uint32_t *)(mepc+4) == SRAI_X0_X0_0X07_OPCODE)
{
if (aligned && *(uint32_t *)mepc == EBREAK_OPCODE &&
*(uint32_t *)(mepc - 4) == SLLI_X0_X0_0X1F_OPCODE &&
*(uint32_t *)(mepc + 4) == SRAI_X0_X0_0X07_OPCODE) {
// The EBREAK was part of the semihosting call. (See semihosting.c)
//
// If a debugger were connected, this would have resulted in a CPU halt,
@ -53,8 +52,9 @@ void trap()
}
// Trap was issued for another reason than an EBREAK.
// Replace the code below with whatever trap handler you'd normally use. (e.g. interrupt
// processing.)
// Replace the code below with whatever trap handler you'd normally use. (e.g.
// interrupt processing.)
while (1)
;
}
#endif

View File

@ -1,9 +1,11 @@
/* See LICENSE of license details. */
#include <unistd.h>
#include "platform.h"
#include "weak_under_alias.h"
#include <unistd.h>
#if defined(SEMIHOSTING)
#include "semihosting.h"
#endif
#if defined(BOARD_hifive1)
static volatile uint32_t tohost;
@ -15,8 +17,7 @@ extern volatile uint32_t fromhost;
void write_hex(int fd, uint32_t hex);
void __wrap_exit(int code)
{
void __wrap_exit(int code) {
/*#if defined(SEMIHOSTING)
sh_exit();
return;
@ -30,6 +31,7 @@ void __wrap_exit(int code)
write(STDERR_FILENO, "\n", 1);
tohost = code + 1;
write(STDERR_FILENO, "\x04", 1);
for (;;);
for (;;)
;
}
weak_under_alias(exit);

View File

@ -1,12 +1,13 @@
/* See LICENSE of license details. */
#include <errno.h>
#include "stub.h"
#include "weak_under_alias.h"
#include <errno.h>
#if defined(SEMIHOSTING)
#include "semihosting.h"
#endif
int __wrap_close(int fd)
{
int __wrap_close(int fd) {
#if defined(SEMIHOTING)
int i = sh_close(fd);
return i;
@ -15,4 +16,3 @@ int __wrap_close(int fd)
}
weak_under_alias(close);

View File

@ -1,8 +1,10 @@
/* See LICENSE of license details. */
#include "semihosting.h"
#include "weak_under_alias.h"
#include <unistd.h>
#if defined(SEMIHOSTING)
#include "semihosting.h"
#endif
int __wrap_isatty(int fd) {
#if defined(SEMIHOSTING)

View File

@ -1,14 +1,15 @@
/* See LICENSE of license details. */
#include <errno.h>
#include <unistd.h>
#include <sys/types.h>
#include "stub.h"
#include "weak_under_alias.h"
#include <errno.h>
#include <sys/types.h>
#include <unistd.h>
#if defined(SEMIHOSTING)
#include "semihosting.h"
#endif
off_t __wrap_lseek(int fd, off_t ptr, int dir)
{
off_t __wrap_lseek(int fd, off_t ptr, int dir) {
#if defined(SEMIHOSTING)
if (sh_istty(fd))
return 0;
@ -22,4 +23,3 @@ off_t __wrap_lseek(int fd, off_t ptr, int dir)
}
weak_under_alias(lseek);

View File

@ -1,12 +1,13 @@
/* See LICENSE of license details. */
#include <errno.h>
#include "stub.h"
#include "weak_under_alias.h"
#include <errno.h>
#if defined(SEMIHOSTING)
#include "semihosting.h"
#endif
int __wrap_open(const char* name, int flags, int mode)
{
int __wrap_open(const char *name, int flags, int mode) {
#if defined(SEMIHOSTING)
int fd = sh_open(name, mode);
return fd;

View File

@ -3,46 +3,36 @@
#include <stdarg.h>
#include <stddef.h>
#include <stdio.h>
#include <stdint.h>
#include <stdio.h>
#include <string.h>
#include <unistd.h>
//#include "semihosting.h"
#undef putchar
int putchar(int ch)
{
return write(STDOUT_FILENO, &ch, 1) == 1 ? ch : -1;
}
int putchar(int ch) { return write(STDOUT_FILENO, &ch, 1) == 1 ? ch : -1; }
size_t strnlen (const char *str, size_t n)
{
size_t strnlen(const char *str, size_t n) {
const char *start = str;
while (n-- > 0 && *str) str++;
while (n-- > 0 && *str)
str++;
return str - start;
}
static void fprintf_putch(int ch, void** data)
{
putchar(ch);
}
static void sprintf_putch(int ch, void** data)
{
static void fprintf_putch(int ch, void **data) { putchar(ch); }
static void sprintf_putch(int ch, void **data) {
char **pstr = (char **)data;
**pstr = ch;
(*pstr)++;
}
static unsigned long getuint(va_list *ap, int lflag)
{
static unsigned long getuint(va_list *ap, int lflag) {
if (lflag)
return va_arg(*ap, unsigned long);
else
return va_arg(*ap, unsigned int);
}
static long getint(va_list *ap, int lflag)
{
static long getint(va_list *ap, int lflag) {
if (lflag)
return va_arg(*ap, long);
else
@ -50,13 +40,12 @@ static long getint(va_list *ap, int lflag)
}
static inline void printnum(void (*putch)(int, void **), void **putdat,
unsigned long num, unsigned base, int width, int padc)
{
unsigned long num, unsigned base, int width,
int padc) {
unsigned digs[sizeof(num) * 8];
int pos = 0;
while (1)
{
while (1) {
digs[pos++] = num % base;
if (num < base)
break;
@ -71,8 +60,7 @@ static inline void printnum(void (*putch)(int, void**), void **putdat,
}
static inline void print_double(void (*putch)(int, void **), void **putdat,
double num, int width, int prec)
{
double num, int width, int prec) {
union {
double d;
uint64_t u;
@ -101,8 +89,8 @@ static inline void print_double(void (*putch)(int, void**), void **putdat,
putch(*p, putdat);
}
static void vprintfmt(void (*putch)(int, void**), void **putdat, const char *fmt, va_list ap)
{
static void vprintfmt(void (*putch)(int, void **), void **putdat,
const char *fmt, va_list ap) {
register const char *p;
const char *last_fmt;
register int ch;
@ -189,7 +177,8 @@ static void vprintfmt(void (*putch)(int, void**), void **putdat, const char *fmt
if (width > 0 && padc != '-')
for (width -= strnlen(p, precision); width > 0; width--)
putch(padc, putdat);
for (; (ch = *p) != '\0' && (precision < 0 || --precision >= 0); width--) {
for (; (ch = *p) != '\0' && (precision < 0 || --precision >= 0);
width--) {
putch(ch, putdat);
p++;
}
@ -236,8 +225,7 @@ static void vprintfmt(void (*putch)(int, void**), void **putdat, const char *fmt
}
}
int __wrap_printf(const char* fmt, ...)
{
int __wrap_printf(const char *fmt, ...) {
va_list ap;
va_start(ap, fmt);
@ -247,8 +235,7 @@ int __wrap_printf(const char* fmt, ...)
return 0; // incorrect return value, but who cares, anyway?
}
int __wrap_sprintf(char* str, const char* fmt, ...)
{
int __wrap_sprintf(char *str, const char *fmt, ...) {
va_list ap;
char *str0 = str;
va_start(ap, fmt);

View File

@ -6,9 +6,11 @@
#include <unistd.h>
#include "platform.h"
#include "semihosting.h"
#include "stub.h"
#include "weak_under_alias.h"
#if defined(SEMIHOSTING)
#include "semihosting.h"
#endif
int __wrap_puts(const char *s) {
#if defined(SEMIHOSTING)

View File

@ -6,9 +6,11 @@
#include <unistd.h>
#include "platform.h"
#include "semihosting.h"
#include "stub.h"
#include "weak_under_alias.h"
#if defined(SEMIHOSTING)
#include "semihosting.h"
#endif
ssize_t __wrap_read(int fd, void *ptr, size_t len) {
uint8_t *current = (uint8_t *)ptr;

View File

@ -1,12 +1,13 @@
/* See LICENSE of license details. */
#include <errno.h>
#include "stub.h"
#include "weak_under_alias.h"
#include <errno.h>
#if defined(SEMIHOSTING)
#include "semihosting.h"
#endif
int __wrap_unlink(const char* name)
{
int __wrap_unlink(const char *name) {
#if defined(SEMIHOSTING)
return sh_remove(name);
#endif

View File

@ -6,9 +6,11 @@
#include <unistd.h>
#include "platform.h"
#include "semihosting.h"
#include "stub.h"
#include "weak_under_alias.h"
#if defined(SEMIHOSTING)
#include "semihosting.h"
#endif
ssize_t __wrap_write(int fd, const void *ptr, size_t len) {
const uint8_t *current = (const uint8_t *)ptr;