fixes hifive1 build

This commit is contained in:
Eyck Jentzsch 2023-11-24 11:39:23 +01:00
parent 77ca8a01b4
commit 0188d404de
3 changed files with 26 additions and 14 deletions

View File

@ -45,6 +45,7 @@ else
endif
CFLAGS += -mabi=$(RISCV_ABI)
CFLAGS += -mcmodel=medany
CFLAGS += -DBOARD_$(BOARD)
TRIPLET?=riscv64-unknown-elf
CXX=$(TOOL_DIR)$(TRIPLET)-c++

View File

@ -4,8 +4,14 @@
#include "platform.h"
#include "weak_under_alias.h"
#if defined(BOARD_hifive1)
static volatile uint32_t tohost;
static volatile uint32_t fromhost;
#else
extern volatile uint32_t tohost;
extern volatile uint32_t fromhost;
#endif
void write_hex(int fd, uint32_t hex);
void __wrap_exit(int code)

View File

@ -11,23 +11,28 @@
ssize_t __wrap_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);
#if defined(BOARD_hifive1)
uint8_t * current = (uint8_t *)ptr;
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);
#else
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);
#endif
ssize_t result = 0;
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++;
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 result;
}
return _stub(EBADF);
return _stub(EBADF);
}
weak_under_alias(read);