From 6334436f8c1037e3dad082f22131b3b06d79b17c Mon Sep 17 00:00:00 2001 From: bje Date: Tue, 4 Sep 2001 03:43:07 +0000 Subject: [PATCH] 2001-09-04 Ben Elliston * gloss.h (do_sys_fstat): Declare. (gloss32::get_halfword): Likewise. (gloss32::set_halfword): Likewise. * gloss.cxx (gloss32::syscall_trap): Handle libgloss::SYS_fstat. (gloss32::get_halfword): New method. (gloss32::set_halfword): Likewise. (gloss32::do_sys_fstat): Likewise. --- sid/component/gloss/ChangeLog | 10 +++ sid/component/gloss/gloss.cxx | 151 ++++++++++++++++++++++++++++++++++++++++++ sid/component/gloss/gloss.h | 4 ++ 3 files changed, 165 insertions(+) diff --git a/sid/component/gloss/ChangeLog b/sid/component/gloss/ChangeLog index 455e4c405d..cfd038fd39 100644 --- a/sid/component/gloss/ChangeLog +++ b/sid/component/gloss/ChangeLog @@ -1,3 +1,13 @@ +2001-09-04 Ben Elliston + + * gloss.h (do_sys_fstat): Declare. + (gloss32::get_halfword): Likewise. + (gloss32::set_halfword): Likewise. + * gloss.cxx (gloss32::syscall_trap): Handle libgloss::SYS_fstat. + (gloss32::get_halfword): New method. + (gloss32::set_halfword): Likewise. + (gloss32::do_sys_fstat): Likewise. + 2001-08-12 Richard Henderson * gloss.cxx (gloss32::read): Fix argument type mismatch for min. diff --git a/sid/component/gloss/gloss.cxx b/sid/component/gloss/gloss.cxx index 03091796d5..a975ecc42b 100644 --- a/sid/component/gloss/gloss.cxx +++ b/sid/component/gloss/gloss.cxx @@ -19,12 +19,16 @@ #include #include +#include +#include #include // Some usings not mentioned in gloss.h. using sid::little_int_1; +using sid::little_int_2; using sid::little_int_4; +using sid::big_int_2; using sid::big_int_4; using sidutil::parse_attribute; @@ -234,6 +238,104 @@ gloss32::set_string(address32 address, const string& value) } bool +gloss32::get_halfword (address32 addr, sid::host_int_2& value) +{ + if (! cpu_memory_bus) + { + if (verbose_p) + cerr << "*** CPU memory bus not configure!" << endl; + return false; + } + + if (verbose_p) + { + cerr << "Reading word from target memory at " + << make_numeric_attribute (addr, ios::hex | ios::showbase) + << ":"; + } + + while (true) + { + bus::status s; + + if (endian == sidutil::endian_big) + { + big_int_2 word; + s = cpu_memory_bus->read (addr, word); + value = word; + } + else + { + little_int_2 word; + s = cpu_memory_bus->read (addr, word); + value = word; + } + + if (s == bus::ok) + break; + else + { + if (verbose_p) + cerr << "failed" << endl; + return false; + } + } + if (verbose_p) + cerr << make_numeric_attribute (value, ios::hex | ios::showbase) << endl; + + return true; +} + +bool +gloss32::set_halfword(address32 addr, sid::host_int_2 value) +{ + if (! cpu_memory_bus) + { + if (verbose_p) + cerr << "*** Target memory bus not configured!" << endl; + return false; + } + + if (verbose_p) + { + cerr << "Write word " << make_numeric_attribute (value, ios::hex | ios::showbase) + << " to target memory at " + << make_numeric_attribute (addr, ios::hex | ios::showbase); + } + + while (true) + { + bus::status s; + + if (this->endian == sidutil::endian_big) + { + big_int_2 word = value; + s = this->cpu_memory_bus->write(addr, word); + } + else + { + little_int_2 word = value; + s = this->cpu_memory_bus->write(addr, word); + } + + if (s == bus::ok) + break; + else + { + if (verbose_p) + cerr << ": failed" << endl; + return false; + } + } + + if (verbose_p) + cerr << endl; + + return true; +} + + +bool gloss32::get_word(address32 address, int32& value) { if (! cpu_memory_bus) @@ -560,6 +662,9 @@ gloss32::syscall_trap() case libgloss::SYS_lseek: do_sys_lseek(); break; + case libgloss::SYS_fstat: + do_sys_fstat(); + break; case libgloss::SYS_close: do_sys_close(); break; @@ -707,6 +812,52 @@ gloss32::do_sys_lseek() } void +gloss32::do_sys_fstat() +{ + struct stat st; + int32 handle, ptr; + + get_int_argument (1, handle); + get_int_argument (2, ptr); + + if (verbose_p) + cerr << "*** fstat (" << handle << "," << ptr << ")" << endl; + + int fd = lookup_fd (handle); + if (fd < 0) + { + set_host_error_result (EBADF); + set_int_result (-1); + } + + int rc = ::fstat (fd, &st); + if (rc < 0) + { + set_host_error_result (errno); + set_int_result (-1); + } + + set_int_result (::fstat (handle, &st)); + + // Populate struct stat in target memory. + set_halfword (ptr, st.st_dev); + ptr += 2; + set_halfword (ptr, st.st_ino); + ptr += 2; + set_word (ptr, st.st_mode); + ptr += 4; + set_halfword (ptr, st.st_nlink); + ptr += 2; + set_halfword (ptr, st.st_uid); + ptr += 2; + set_halfword (ptr, st.st_gid); + ptr += 2; + set_halfword (ptr, st.st_rdev); + ptr += 2; + set_word (ptr, st.st_size); +} + +void gloss32::do_sys_read() { int32 handle, str_ptr, str_length; diff --git a/sid/component/gloss/gloss.h b/sid/component/gloss/gloss.h index fa592aa627..b6ffca69ce 100644 --- a/sid/component/gloss/gloss.h +++ b/sid/component/gloss/gloss.h @@ -110,6 +110,9 @@ protected: virtual bool set_error_result(int32 target_errno); bool set_host_error_result (int32 host_errno); + bool get_halfword(address32 address, sid::host_int_2& value); + bool set_halfword(address32 address, sid::host_int_2 value); + // Get/set a word in memory, taking into account the cpu's endianness. bool get_word(address32 address, int32& value); bool set_word(address32 address, int32 value); @@ -140,6 +143,7 @@ protected: void do_sys_open(); void do_sys_close(); void do_sys_lseek(); + void do_sys_fstat(); void do_sys_time(); void do_sys_gettimeofday(); void do_sys_times(); -- 2.11.0