From fc3571602f19d86ca86c25dd204f8662782e62d6 Mon Sep 17 00:00:00 2001 From: Pavel Pisa Date: Sat, 9 Mar 2019 20:37:54 +0100 Subject: Updated read and write, added open, close, ftruncate syscalls and fs_root option. When operating system emulation root directory (fs_root) are selected then open() syscall opens real host system files in this limited subtree. When fs_root is not set then console is mapped to all read, write, open and close calls. Signed-off-by: Pavel Pisa --- qtmips_osemu/ossyscall.h | 27 ++++++++++++++++++++++++++- 1 file changed, 26 insertions(+), 1 deletion(-) (limited to 'qtmips_osemu/ossyscall.h') diff --git a/qtmips_osemu/ossyscall.h b/qtmips_osemu/ossyscall.h index bcb202f..2f8f54a 100644 --- a/qtmips_osemu/ossyscall.h +++ b/qtmips_osemu/ossyscall.h @@ -37,6 +37,8 @@ #define OSSYCALL_H #include +#include +#include #include #include #include @@ -57,7 +59,8 @@ int name(std::uint32_t &result, machine::Core *core, \ class OsSyscallExceptionHandler : public machine::ExceptionHandler { Q_OBJECT public: - OsSyscallExceptionHandler(bool known_syscall_stop = false, bool unknown_syscall_stop = false); + OsSyscallExceptionHandler(bool known_syscall_stop = false, bool unknown_syscall_stop = false, + QString fs_root = ""); 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, @@ -69,17 +72,39 @@ public: OSSYCALL_HANDLER_DECLARE(do_sys_write); OSSYCALL_HANDLER_DECLARE(do_sys_readv); OSSYCALL_HANDLER_DECLARE(do_sys_read); + OSSYCALL_HANDLER_DECLARE(do_sys_open); + OSSYCALL_HANDLER_DECLARE(do_sys_close); + OSSYCALL_HANDLER_DECLARE(do_sys_ftruncate); OSSYCALL_HANDLER_DECLARE(do_sys_brk); OSSYCALL_HANDLER_DECLARE(do_sys_mmap2); signals: void char_written(int fd, unsigned int val); void rx_byte_pool(int fd, unsigned int &data, bool &available); private: + enum FdMapping { + FD_UNUSED = -1, + FD_INVALID = -1, + FD_TERMINAL = -2, + }; + std::int32_t write_mem(machine::MemoryAccess *mem, std::uint32_t addr, + const QVector &data, std::uint32_t count); + std::int32_t read_mem(machine::MemoryAccess *mem, std::uint32_t addr, + QVector &data, std::uint32_t count); + std::int32_t write_io(int fd, const QVector &data, std::uint32_t count); + std::int32_t read_io(int fd, QVector &data, std::uint32_t count, bool add_nl_at_eof); + int allocate_fd(int val = FD_UNUSED); + int file_open(QString fname, int flags, int mode); + int targetfd_to_fd(int targetfd); + void close_fd(int targetfd); + QString filepath_to_host(QString path); + + QVector fd_mapping; std::uint32_t brk_limit; std::uint32_t anonymous_base; std::uint32_t anonymous_last; bool known_syscall_stop; bool unknown_syscall_stop; + QString fs_root; }; #undef OSSYCALL_HANDLER_DECLARE -- cgit v1.2.3