aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPavel Pisa <pisa@cmp.felk.cvut.cz>2019-02-14 00:42:42 +0100
committerPavel Pisa <pisa@cmp.felk.cvut.cz>2019-02-14 00:42:42 +0100
commit4392124e26e699df38cf34dbbac6baeaa243271c (patch)
tree88c76aa34f0c3a15bc6eaaf00a37ccaaffc2db9e
parent0916bef42e28218b08b05342d5b571b8a45afb5a (diff)
downloadqtmips-4392124e26e699df38cf34dbbac6baeaa243271c.tar.gz
qtmips-4392124e26e699df38cf34dbbac6baeaa243271c.tar.bz2
qtmips-4392124e26e699df38cf34dbbac6baeaa243271c.zip
Implemented sys_set_thread_area and sys_writev syscalls.
The example Linux program compiled against musl library reaches main and displays printf output. Signed-off-by: Pavel Pisa <pisa@cmp.felk.cvut.cz>
-rw-r--r--qtmips_osemu/ossyscall.cpp47
-rw-r--r--qtmips_osemu/ossyscall.h18
2 files changed, 57 insertions, 8 deletions
diff --git a/qtmips_osemu/ossyscall.cpp b/qtmips_osemu/ossyscall.cpp
index 79052da..584a011 100644
--- a/qtmips_osemu/ossyscall.cpp
+++ b/qtmips_osemu/ossyscall.cpp
@@ -205,7 +205,7 @@ static const mips_syscall_desc_t mips_syscall_args[] = {
MIPS_SYS(sys_flock , 2, syscall_default_handler)
MIPS_SYS(sys_msync , 3, syscall_default_handler)
MIPS_SYS(sys_readv , 3, syscall_default_handler) /* 4145 */
- MIPS_SYS(sys_writev , 3, syscall_default_handler)
+ MIPS_SYS(sys_writev , 3, do_sys_writev)
MIPS_SYS(sys_cacheflush , 3, syscall_default_handler)
MIPS_SYS(sys_cachectl , 3, syscall_default_handler)
MIPS_SYS(sys_sysmips , 4, syscall_default_handler)
@@ -342,7 +342,7 @@ static const mips_syscall_desc_t mips_syscall_args[] = {
MIPS_SYS(sys_add_key , 5, syscall_default_handler)
MIPS_SYS(sys_request_key, 4, syscall_default_handler)
MIPS_SYS(sys_keyctl , 5, syscall_default_handler)
- MIPS_SYS(sys_set_thread_area, 1, syscall_default_handler)
+ MIPS_SYS(sys_set_thread_area, 1, do_sys_set_thread_area)
MIPS_SYS(sys_inotify_init, 0, syscall_default_handler)
MIPS_SYS(sys_inotify_add_watch, 3, syscall_default_handler) /* 4285 */
MIPS_SYS(sys_inotify_rm_watch, 2, syscall_default_handler)
@@ -514,7 +514,50 @@ int OsSyscallExceptionHandler::syscall_default_handler(std::uint32_t &result, Co
(unsigned long)a3, (unsigned long)a4);
#endif
+ (void)core; (void)syscall_num;
(void)a1; (void)a2; (void)a3; (void)a4; (void)a5; (void)a6; (void)a7; (void)a8;
result = 0;
return 0;
}
+
+int OsSyscallExceptionHandler::do_sys_set_thread_area(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;
+ core->set_c0_userlocal(a1);
+ result = 0;
+ return 0;
+}
+
+// ssize_t writev(int fd, const struct iovec *iov, int iovcnt);
+int OsSyscallExceptionHandler::do_sys_writev(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 iov = a2;
+ int iovcnt = a3;
+ MemoryAccess *mem = core->get_mem_data();
+
+ printf("sys_writev to fd %d\n", fd);
+
+ while (iovcnt-- > 0) {
+ std::uint32_t iov_base = mem->read_word(iov);
+ 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++));
+ }
+ result += iov_len;
+ }
+
+ return 0;
+}
diff --git a/qtmips_osemu/ossyscall.h b/qtmips_osemu/ossyscall.h
index f2c8137..3897327 100644
--- a/qtmips_osemu/ossyscall.h
+++ b/qtmips_osemu/ossyscall.h
@@ -47,6 +47,13 @@
namespace osemu {
+#define OSSYCALL_HANDLER_DECLARE(name) \
+int name(std::uint32_t &result, machine::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)
+
class OsSyscallExceptionHandler : public machine::ExceptionHandler {
Q_OBJECT
public:
@@ -54,14 +61,13 @@ public:
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);
- int syscall_default_handler(std::uint32_t &result, machine::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);
-
+ OSSYCALL_HANDLER_DECLARE(syscall_default_handler);
+ OSSYCALL_HANDLER_DECLARE(do_sys_set_thread_area);
+ OSSYCALL_HANDLER_DECLARE(do_sys_writev);
};
+#undef OSSYCALL_HANDLER_DECLARE
+
}
#endif // OSSYCALL_H