diff --git a/riscv_cpu.c b/riscv_cpu.c index f582def..ab9ae6d 100644 --- a/riscv_cpu.c +++ b/riscv_cpu.c @@ -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 @@ -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"); diff --git a/riscv_machine.c b/riscv_machine.c index bd9aa98..d5afcb8 100644 --- a/riscv_machine.c +++ b/riscv_machine.c @@ -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; @@ -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