diff options
author | Pavel Pisa <pisa@cmp.felk.cvut.cz> | 2019-03-06 23:40:34 +0100 |
---|---|---|
committer | Pavel Pisa <pisa@cmp.felk.cvut.cz> | 2019-03-06 23:40:34 +0100 |
commit | 8d0f4806a7ad55710cb190e5a5c9388bd00c50a8 (patch) | |
tree | 16d5ac856513f44c4b1ecbccdebee151772f64e2 /qtmips_osemu | |
parent | 1536045c0d28113892abc9d1023ce395a0e82e94 (diff) | |
download | qtmips-8d0f4806a7ad55710cb190e5a5c9388bd00c50a8.tar.gz qtmips-8d0f4806a7ad55710cb190e5a5c9388bd00c50a8.tar.bz2 qtmips-8d0f4806a7ad55710cb190e5a5c9388bd00c50a8.zip |
Enable configuration of syscalls emulation and stop on exception.
Signed-off-by: Pavel Pisa <pisa@cmp.felk.cvut.cz>
Diffstat (limited to 'qtmips_osemu')
-rw-r--r-- | qtmips_osemu/ossyscall.cpp | 30 | ||||
-rw-r--r-- | qtmips_osemu/ossyscall.h | 5 |
2 files changed, 31 insertions, 4 deletions
diff --git a/qtmips_osemu/ossyscall.cpp b/qtmips_osemu/ossyscall.cpp index aeee079..fed4548 100644 --- a/qtmips_osemu/ossyscall.cpp +++ b/qtmips_osemu/ossyscall.cpp @@ -60,7 +60,7 @@ struct mips_syscall_desc_t { &OsSyscallExceptionHandler::handler}, static const mips_syscall_desc_t mips_syscall_args[] = { MIPS_SYS(sys_syscall , 8, syscall_default_handler) /* 4000 */ - MIPS_SYS(sys_exit , 1, syscall_default_handler) + MIPS_SYS(sys_exit , 1, do_sys_exit) MIPS_SYS(sys_fork , 0, syscall_default_handler) MIPS_SYS(sys_read , 3, do_sys_read) MIPS_SYS(sys_write , 3, do_sys_write) @@ -427,10 +427,13 @@ static const mips_syscall_desc_t mips_syscall_args[] = { const unsigned mips_syscall_args_size = sizeof(mips_syscall_args)/sizeof(*mips_syscall_args); -OsSyscallExceptionHandler::OsSyscallExceptionHandler() { +OsSyscallExceptionHandler::OsSyscallExceptionHandler(bool known_syscall_stop, + bool unknown_syscall_stop) { brk_limit = 0; anonymous_base = 0x60000000; anonymous_last = anonymous_base; + this->known_syscall_stop = known_syscall_stop; + this->unknown_syscall_stop = unknown_syscall_stop; } bool OsSyscallExceptionHandler::handle_exception(Core *core, Registers *regs, @@ -496,7 +499,8 @@ bool OsSyscallExceptionHandler::handle_exception(Core *core, Registers *regs, #endif status = (this->*sdesc->handler)(result, core, syscall_num, a1, a2, a3, a4, a5, a6, a7, a8); - emit core->stop_on_exception_reached(); + if (known_syscall_stop) + emit core->stop_on_exception_reached(); regs->write_gp(7, status); if (status < 0) @@ -524,6 +528,26 @@ int OsSyscallExceptionHandler::syscall_default_handler(std::uint32_t &result, Co (void)core; (void)syscall_num; (void)a1; (void)a2; (void)a3; (void)a4; (void)a5; (void)a6; (void)a7; (void)a8; result = 0; + if (unknown_syscall_stop) + emit core->stop_on_exception_reached(); + return 0; +} + +// void exit(int status); +int OsSyscallExceptionHandler::do_sys_exit(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 status = a1; + + printf("sys_exit status %d\n", status); + emit core->stop_on_exception_reached(); + return 0; } diff --git a/qtmips_osemu/ossyscall.h b/qtmips_osemu/ossyscall.h index 0c02699..bcb202f 100644 --- a/qtmips_osemu/ossyscall.h +++ b/qtmips_osemu/ossyscall.h @@ -57,12 +57,13 @@ int name(std::uint32_t &result, machine::Core *core, \ class OsSyscallExceptionHandler : public machine::ExceptionHandler { Q_OBJECT public: - OsSyscallExceptionHandler(); + OsSyscallExceptionHandler(bool known_syscall_stop = false, bool unknown_syscall_stop = false); bool handle_exception(machine::Core *core, machine::Registers *regs, machine::ExceptionCause excause, std::uint32_t inst_addr, std::uint32_t next_addr, std::uint32_t jump_branch_pc, bool in_delay_slot, std::uint32_t mem_ref_addr); OSSYCALL_HANDLER_DECLARE(syscall_default_handler); + OSSYCALL_HANDLER_DECLARE(do_sys_exit); OSSYCALL_HANDLER_DECLARE(do_sys_set_thread_area); OSSYCALL_HANDLER_DECLARE(do_sys_writev); OSSYCALL_HANDLER_DECLARE(do_sys_write); @@ -77,6 +78,8 @@ private: std::uint32_t brk_limit; std::uint32_t anonymous_base; std::uint32_t anonymous_last; + bool known_syscall_stop; + bool unknown_syscall_stop; }; #undef OSSYCALL_HANDLER_DECLARE |