Skip to content

Commit

Permalink
Print to Device Console instead of JavaScript Console
Browse files Browse the repository at this point in the history
  • Loading branch information
lupyuen committed Jan 16, 2024
1 parent 170abb0 commit 41383b8
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 3 deletions.
12 changes: 9 additions & 3 deletions riscv_cpu.c
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@
#include "iomem.h"
#include "riscv_cpu.h"

void print_console(void *machine0, const char *buf, int len);

#ifndef MAX_XLEN
#error MAX_XLEN must be defined
#endif
Expand Down Expand Up @@ -471,9 +473,13 @@ int target_write_slow(RISCVCPUState *s, target_ulong addr,
if (!pr) {
//// Begin Test: Intercept Memory-Mapped I/O
switch(paddr & 0xfffffffffffful) { // TODO: Why does NuttX write to 0x4000000030002088?
case 0x30002088: // uart_fifo_wdata: UART Output
putchar(val); break; // Print the character

case 0x30002088: { // uart_fifo_wdata: UART Output
// Print the character
char buf[1];
buf[0] = val;
print_console(NULL, buf, 1);
break;
}
default: // Unknown Memory-Mapped I/O
#ifdef DUMP_INVALID_MEM_ACCESS
printf("target_write_slow: invalid physical address 0x");
Expand Down
17 changes: 17 additions & 0 deletions riscv_machine.c
Original file line number Diff line number Diff line change
Expand Up @@ -956,6 +956,11 @@ static VirtMachine *riscv_machine_init(const VirtMachineParams *p)

/* virtio console */
if (p->console) {
//// Begin Test: Save the Console
const char *msg = "TinyEMU Emulator for Ox64 BL808 RISC-V SBC\r\n";
void print_console(RISCVMachine *machine0, const char *buf, int len);
print_console(s, msg, strlen(msg));
//// End Test
vbus->irq = &s->plic_irq[irq_num];
s->common.console_dev = virtio_console_init(vbus, p->console);
vbus->addr += VIRTIO_SIZE;
Expand Down Expand Up @@ -1119,3 +1124,15 @@ const VirtMachineClass riscv_machine_class = {
riscv_vm_send_mouse_event,
riscv_vm_send_key_event,
};

//// Begin Test: Print to Console
void print_console(RISCVMachine *machine0, const char *buf, int len) {
static RISCVMachine *machine = NULL;
if (machine0 != NULL) { machine = machine0; }
if (machine == NULL) { puts("print_console: machine is null"); return; }
machine->common.console->write_data(
machine->common.console->opaque,
(const uint8_t *)buf,
len);
}
//// End Test

0 comments on commit 41383b8

Please sign in to comment.