diff options
-rw-r--r-- | qtmips_gui/mainwindow.cpp | 5 | ||||
-rw-r--r-- | qtmips_gui/terminaldock.cpp | 6 | ||||
-rw-r--r-- | qtmips_gui/terminaldock.h | 1 | ||||
-rw-r--r-- | qtmips_osemu/ossyscall.cpp | 34 | ||||
-rw-r--r-- | qtmips_osemu/ossyscall.h | 3 |
5 files changed, 45 insertions, 4 deletions
diff --git a/qtmips_gui/mainwindow.cpp b/qtmips_gui/mainwindow.cpp index 0482b11..5174949 100644 --- a/qtmips_gui/mainwindow.cpp +++ b/qtmips_gui/mainwindow.cpp @@ -148,8 +148,9 @@ void MainWindow::create_core(const machine::MachineConfig &config) { set_speed(); // Update machine speed to current settings #if 1 - machine->register_exception_handler(machine::EXCAUSE_SYSCALL, - new osemu::OsSyscallExceptionHandler); + osemu::OsSyscallExceptionHandler *osemu_handler = new osemu::OsSyscallExceptionHandler; + machine->register_exception_handler(machine::EXCAUSE_SYSCALL, osemu_handler); + connect(osemu_handler, SIGNAL(char_written(int,uint)), terminal, SLOT(tx_byte(int,uint))); #endif // Connect machine signals and slots diff --git a/qtmips_gui/terminaldock.cpp b/qtmips_gui/terminaldock.cpp index 31e8c68..4b394a6 100644 --- a/qtmips_gui/terminaldock.cpp +++ b/qtmips_gui/terminaldock.cpp @@ -70,3 +70,9 @@ void TerminalDock::tx_byte(unsigned int data) { else append_cursor->insertText(QString(QChar(data))); } + +void TerminalDock::tx_byte(int fd, unsigned int data) +{ + (void)fd; + tx_byte(data); +} diff --git a/qtmips_gui/terminaldock.h b/qtmips_gui/terminaldock.h index b0c76cf..7154e81 100644 --- a/qtmips_gui/terminaldock.h +++ b/qtmips_gui/terminaldock.h @@ -53,6 +53,7 @@ public: public slots: void tx_byte(unsigned int data); + void tx_byte(int fd, unsigned int data); private: QVBoxLayout *layout_box; diff --git a/qtmips_osemu/ossyscall.cpp b/qtmips_osemu/ossyscall.cpp index 584a011..e030076 100644 --- a/qtmips_osemu/ossyscall.cpp +++ b/qtmips_osemu/ossyscall.cpp @@ -63,7 +63,7 @@ static const mips_syscall_desc_t mips_syscall_args[] = { MIPS_SYS(sys_exit , 1, syscall_default_handler) MIPS_SYS(sys_fork , 0, syscall_default_handler) MIPS_SYS(sys_read , 3, syscall_default_handler) - MIPS_SYS(sys_write , 3, syscall_default_handler) + MIPS_SYS(sys_write , 3, do_sys_write) MIPS_SYS(sys_open , 3, syscall_default_handler) /* 4005 */ MIPS_SYS(sys_close , 1, syscall_default_handler) MIPS_SYS(sys_waitpid , 3, syscall_default_handler) @@ -440,6 +440,7 @@ bool OsSyscallExceptionHandler::handle_exception(Core *core, Registers *regs, MemoryAccess *mem_data = core->get_mem_data(); MemoryAccess *mem_program = core->get_mem_program(); + (void)mem_program; #if 1 printf("Exception cause %d instruction PC 0x%08lx next PC 0x%08lx jump branch PC 0x%08lx " @@ -554,10 +555,39 @@ int OsSyscallExceptionHandler::do_sys_writev(std::uint32_t &result, Core *core, std::uint32_t iov_len = mem->read_word(iov + 4); iov += 8; for (std::uint32_t i = 0; i < iov_len; i++) { - printf("%c", mem->read_byte(iov_base++)); + int ch = mem->read_byte(iov_base++); + printf("%c", ch); + emit char_written(fd, ch); } result += iov_len; } return 0; } + +// ssize_t write(int fd, const void *buf, size_t count); +int OsSyscallExceptionHandler::do_sys_write(std::uint32_t &result, Core *core, + std::uint32_t syscall_num, + std::uint32_t a1, std::uint32_t a2, std::uint32_t a3, + std::uint32_t a4, std::uint32_t a5, std::uint32_t a6, + std::uint32_t a7, std::uint32_t a8) { + (void)core; (void)syscall_num; + (void)a1; (void)a2; (void)a3; (void)a4; (void)a5; (void)a6; (void)a7; (void)a8; + + result = 0; + int fd = a1; + std::uint32_t buf = a2; + int size = a3; + MemoryAccess *mem = core->get_mem_data(); + + printf("sys_write to fd %d\n", fd); + + result += size; + while (size-- > 0) { + int ch = mem->read_byte(buf++); + printf("%c", ch); + emit char_written(fd, ch); + } + + return 0; +} diff --git a/qtmips_osemu/ossyscall.h b/qtmips_osemu/ossyscall.h index 3897327..b42fe21 100644 --- a/qtmips_osemu/ossyscall.h +++ b/qtmips_osemu/ossyscall.h @@ -64,6 +64,9 @@ public: OSSYCALL_HANDLER_DECLARE(syscall_default_handler); OSSYCALL_HANDLER_DECLARE(do_sys_set_thread_area); OSSYCALL_HANDLER_DECLARE(do_sys_writev); + OSSYCALL_HANDLER_DECLARE(do_sys_write); +signals: + void char_written(int fd, unsigned int val); }; #undef OSSYCALL_HANDLER_DECLARE |