Skip to content

Commit

Permalink
BL808_UART_FIFO_RDATA_OFFSET (0x3000208c) returns the Input Char
Browse files Browse the repository at this point in the history
  • Loading branch information
lupyuen committed Jan 20, 2024
1 parent 3d2430d commit 63cba62
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 4 deletions.
21 changes: 18 additions & 3 deletions riscv_cpu.c
Original file line number Diff line number Diff line change
Expand Up @@ -382,10 +382,15 @@ int target_read_slow(RISCVCPUState *s, mem_uint_t *pval,
if (!pr) {
//// Begin Test: Intercept Memory-Mapped I/O
switch(paddr) {
case 0x30002084: // uart_fifo_config_1: Is UART Ready?
ret = 32 // UART TX is always ready, default TX FIFO Available is 32
| (1 << 8); // UART RX FIFO Available is always 1
case 0x30002084: { // uart_fifo_config_1: Is UART Ready?
char read_input(void);
uint8_t rx_avail = (read_input() == 0) // Check input buffer
? 0 // No input available
: 1; // One char available
ret = 32 // UART TX is always ready, default TX FIFO Available is 32
| (rx_avail << 8); // UART RX FIFO Available depends on input buffer
break;
}

// Console Input: BL808_UART_INT_STS (0x30002020) must return UART_INT_STS_URX_END_INT (1 << 1)
case 0x30002020:
Expand All @@ -397,6 +402,16 @@ int target_read_slow(RISCVCPUState *s, mem_uint_t *pval,
puts("read BL808_UART_INT_MASK");
ret = 0; break;

// Console Input: BL808_UART_FIFO_RDATA_OFFSET (0x3000208c) returns the Input Char
case 0x3000208c: {
char read_input(void);
ret = read_input();

// Clear the Input Buffer
void set_input(char ch);
set_input(0);
break;
}
default: // Unknown Memory-Mapped I/O
#ifdef DUMP_INVALID_MEM_ACCESS
printf("target_read_slow: invalid physical address 0x");
Expand Down
16 changes: 15 additions & 1 deletion virtio.c
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,9 @@ static void virtio_mmio_write(void *opaque, uint32_t offset,
static uint32_t virtio_pci_read(void *opaque, uint32_t offset, int size_log2);
static void virtio_pci_write(void *opaque, uint32_t offset,
uint32_t val, int size_log2);

void virtio_ack_irq(VIRTIODevice *device0);
void set_input(char ch);

static void virtio_reset(VIRTIODevice *s)
{
Expand Down Expand Up @@ -1334,8 +1336,9 @@ int virtio_console_get_write_len(VIRTIODevice *s)
int virtio_console_write_data(VIRTIODevice *s, const uint8_t *buf, int buf_len)
{
//// To handle a keypress, we trigger the UART3 Interrupt.
//// TODO: Pass the keypress to VM Guest
//// Pass the keypress to VM Guest
printf("[%c]\n", buf[0]); ////
set_input(buf[0]);
s->int_status |= 1;
set_irq(s->irq, 1);

Expand Down Expand Up @@ -2690,4 +2693,15 @@ void virtio_ack_irq(VIRTIODevice *device0) {
set_irq(device->irq, 0);
// }
}

//// Remember and return the Input Char
static char input_char = 0;

void set_input(char ch) {
input_char = ch;
}

char read_input(void) {
return input_char;
}
//// End Test

0 comments on commit 63cba62

Please sign in to comment.