diff --git a/env/moonlight/bsp_read.c b/env/moonlight/bsp_read.c new file mode 100644 index 0000000..7909286 --- /dev/null +++ b/env/moonlight/bsp_read.c @@ -0,0 +1,19 @@ +#include +#include +#include +#include + +ssize_t _bsp_read(int fd, void *ptr, size_t len) { + uint8_t *current = (uint8_t *)ptr; + volatile uint32_t *uart_rx = (uint32_t *)0xFFFF0000; + ssize_t result = 0; + if (isatty(fd)) { + for (current = (uint8_t *)ptr; (current < ((uint8_t *)ptr) + len); + current++) { + *current = *uart_rx; + result++; + } + return result; + } + return EOF; +} diff --git a/env/moonlight/bsp_write.c b/env/moonlight/bsp_write.c new file mode 100644 index 0000000..a10f78e --- /dev/null +++ b/env/moonlight/bsp_write.c @@ -0,0 +1,18 @@ +/* See LICENSE of license details. */ + +#include +#include +#include +#include + +ssize_t _bsp_write(int fd, const void *ptr, size_t len) { + const uint8_t *current = (const uint8_t *)ptr; + if (isatty(fd)) { + for (size_t jj = 0; jj < len; jj++) { + *((uint32_t *)0xFFFF0000) = current[jj]; + } + return len; + } + + return 1; +} diff --git a/env/moonlight/platform.h b/env/moonlight/platform.h index bb7527a..8452816 100644 --- a/env/moonlight/platform.h +++ b/env/moonlight/platform.h @@ -4,40 +4,39 @@ #define _ISS_PLATFORM_H #if __riscv_xlen == 32 -#define MCAUSE_INT 0x80000000UL -#define MCAUSE_CAUSE 0x000003FFUL +#define MCAUSE_INT 0x80000000UL +#define MCAUSE_CAUSE 0x000003FFUL #else -#define MCAUSE_INT 0x8000000000000000UL -#define MCAUSE_CAUSE 0x00000000000003FFUL +#define MCAUSE_INT 0x8000000000000000UL +#define MCAUSE_CAUSE 0x00000000000003FFUL #endif #define APB_BUS -#include "ehrenberg/devices/gpio.h" -#include "ehrenberg/devices/uart.h" -#include "ehrenberg/devices/timer.h" -#include "ehrenberg/devices/aclint.h" -#include "ehrenberg/devices/qspi.h" -#include "ehrenberg/devices/i2s.h" -#include "ehrenberg/devices/camera.h" -#include "ehrenberg/devices/dma.h" -#include "ehrenberg/devices/msg_if.h" +#include "minres/devices/aclint.h" +#include "minres/devices/camera.h" +#include "minres/devices/dma.h" +#include "minres/devices/gpio.h" +#include "minres/devices/i2s.h" +#include "minres/devices/msg_if.h" +#include "minres/devices/qspi.h" +#include "minres/devices/timer.h" +#include "minres/devices/uart.h" -#define PERIPH(TYPE, ADDR) ((volatile TYPE*) (ADDR)) +#define PERIPH(TYPE, ADDR) ((volatile TYPE *)(ADDR)) #define APB_BASE 0xF0000000 -#define gpio PERIPH(gpio_t, APB_BASE+0x0000) -#define uart PERIPH(uart_t, APB_BASE+0x1000) -#define timer PERIPH(timercounter_t, APB_BASE+0x20000) -#define aclint PERIPH(aclint_t, APB_BASE+0x30000) -#define irq PERIPH(irq_t, APB_BASE+0x40000) -#define qspi PERIPH(qspi_t, APB_BASE+0x50000) -#define i2s PERIPH(i2s_t, APB_BASE+0x90000) -#define camera PERIPH(camera_t, APB_BASE+0xA0000) -#define dma PERIPH(dma_t, APB_BASE+0xB0000) -#define msgif PERIPH(msgif_t, APB_BASE+0xC0000) - +#define gpio PERIPH(gpio_t, APB_BASE + 0x0000) +#define uart PERIPH(uart_t, APB_BASE + 0x1000) +#define timer PERIPH(timercounter_t, APB_BASE + 0x20000) +#define aclint PERIPH(aclint_t, APB_BASE + 0x30000) +#define irq PERIPH(irq_t, APB_BASE + 0x40000) +#define qspi PERIPH(qspi_t, APB_BASE + 0x50000) +#define i2s PERIPH(i2s_t, APB_BASE + 0x90000) +#define camera PERIPH(camera_t, APB_BASE + 0xA0000) +#define dma PERIPH(dma_t, APB_BASE + 0xB0000) +#define msgif PERIPH(msgif_t, APB_BASE + 0xC0000) #define XIP_START_LOC 0xE0040000 #define RAM_START_LOC 0x80000000