From: bje Date: Thu, 31 Jan 2002 23:03:53 +0000 (+0000) Subject: 2002-01-25 Ben Elliston X-Git-Url: http://git.osdn.net/view?a=commitdiff_plain;h=6a5f43a0062304c09d2fbf4c3a4b684dade7f0e8;p=pf3gnuchains%2Fsourceware.git 2002-01-25 Ben Elliston * libgloss.h (libgloss::SYS_argc): New enumerator. (libgloss::SYS_argnlen, libgloss::SYS_argn): Likewise. (libgloss::SYS_unsupported): Raise its value. * gloss.cxx (gloss32::gloss32): Virtualise "command-line". (gloss32::get_command_line): New method. (gloss32::set_command_line): Likewise. (gloss32::set_string [string&]): Call char* version. (gloss32::set_string [char*]): Implement. (gloss32::syscall_trap): Handle SYS_argc, SYS_argn, SYS_argnlen. (gloss32::do_sys_argc): New method. (gloss32::do_sys_argn): Likewise. (gloss32::do_sys_argnlen): Likewise. * gloss.h (gloss32::set_string): New method which has a length parameter for binary data and null-terminated strings. (gloss32::do_sys_argc): Declare. (gloss32::do_sys_argn): Likewise. (gloss32::do_sys_argnlen): Likewise. (gloss32::command_line): Change type to vector. (gloss32::get_command_line): New virtual attribute callback. (gloss32::set_command_line): Likewise. --- diff --git a/sid/component/gloss/ChangeLog b/sid/component/gloss/ChangeLog index 6eb0468901..b73aae9f5d 100644 --- a/sid/component/gloss/ChangeLog +++ b/sid/component/gloss/ChangeLog @@ -1,3 +1,26 @@ +2002-01-25 Ben Elliston + + * libgloss.h (libgloss::SYS_argc): New enumerator. + (libgloss::SYS_argnlen, libgloss::SYS_argn): Likewise. + (libgloss::SYS_unsupported): Raise its value. + * gloss.cxx (gloss32::gloss32): Virtualise "command-line". + (gloss32::get_command_line): New method. + (gloss32::set_command_line): Likewise. + (gloss32::set_string [string&]): Call char* version. + (gloss32::set_string [char*]): Implement. + (gloss32::syscall_trap): Handle SYS_argc, SYS_argn, SYS_argnlen. + (gloss32::do_sys_argc): New method. + (gloss32::do_sys_argn): Likewise. + (gloss32::do_sys_argnlen): Likewise. + * gloss.h (gloss32::set_string): New method which has a length + parameter for binary data and null-terminated strings. + (gloss32::do_sys_argc): Declare. + (gloss32::do_sys_argn): Likewise. + (gloss32::do_sys_argnlen): Likewise. + (gloss32::command_line): Change type to vector. + (gloss32::get_command_line): New virtual attribute callback. + (gloss32::set_command_line): Likewise. + 2001-11-30 Frank Ch. Eigler * gloss.cxx (write): Add missing ios:: namespace prefix. diff --git a/sid/component/gloss/gloss.cxx b/sid/component/gloss/gloss.cxx index 3211d43591..bc136fe208 100644 --- a/sid/component/gloss/gloss.cxx +++ b/sid/component/gloss/gloss.cxx @@ -1,6 +1,6 @@ // gloss.cxx - Gloss routines. -*- C++ -*- -// Copyright (C) 1999, 2000 Red Hat. +// Copyright (C) 1999, 2000, 2001, 2002 Red Hat. // This file is part of SID and is licensed under the GPL. // See the file COPYING.SID for conditions for redistribution. @@ -42,11 +42,12 @@ gloss32::gloss32() : rx_pin(this, &gloss32::rx_handler), cpu (0), cpu_memory_bus (0), - command_line(""), syscall_numbering_scheme("libgloss"), max_fds(32), verbose_p(false) { + command_line.push_back (""); + // ??? There's a naming disconnect between "cpu" and "target_memory". add_accessor("target-memory", &this->cpu_memory_bus); @@ -64,7 +65,11 @@ gloss32::gloss32() : add_uni_relation("cpu", &this->cpu); - add_attribute("command-line", &this->command_line, "setting"); + add_attribute_virtual("command-line", this, + &gloss32::get_command_line, + &gloss32::set_command_line, + "setting"); + add_attribute("syscall-numbering-scheme", &this->syscall_numbering_scheme, "setting"); add_attribute("verbose?", &this->verbose_p, "setting"); @@ -80,6 +85,45 @@ gloss32::~gloss32() throw() delete [] fd_table; } +string +gloss32::get_command_line () +{ + string cline; + for (std::vector::const_iterator it = command_line.begin(); + it != command_line.end (); + it++) + { + cline += *it; + if (it + 1 != command_line.end ()) + cline += " "; + } + return cline; +} + +component::status +gloss32::set_command_line (const string& cline) +{ + vector argv = sidutil::tokenize (cline, " "); + command_line.clear(); + + if (argv.empty()) + { + command_line.push_back (""); + return component::bad_value; + } + + // Insert all non-empty strings into command_line. + for (std::vector::iterator it = argv.begin(); + it != argv.end (); + it++) + { + if (*it != "") + command_line.push_back (*it); + } + + return command_line.empty() ? component::bad_value : component::ok; +} + void gloss32::reset_pin_handler(host_int_4 ignore) { @@ -196,7 +240,7 @@ gloss32::get_string (address32 address, string& value, unsigned length = 0) } bool -gloss32::set_string(address32 address, const string& value) +gloss32::set_string (address32 address, const char* value, unsigned length) { if (! this->cpu_memory_bus) { @@ -206,12 +250,12 @@ gloss32::set_string(address32 address, const string& value) if (verbose_p) { - cerr << "Writing " << value.size() << " byte(s) to target memory at " + cerr << "Writing " << length << " byte(s) to target memory at " << make_numeric_attribute (address, ios::hex | ios::showbase) << ": "; } - for (unsigned i = 0; i < value.size(); i++) + for (unsigned i = 0; i < length; i++) { char c = value[i]; little_int_1 byte = c; @@ -241,6 +285,12 @@ gloss32::set_string(address32 address, const string& value) } bool +gloss32::set_string(address32 address, const string& value) +{ + return set_string (address, value.c_str(), value.length () + 1); +} + +bool gloss32::get_halfword (address32 addr, sid::host_int_2& value) { if (! cpu_memory_bus) @@ -728,6 +778,15 @@ gloss32::syscall_trap() case libgloss::SYS_unlink: do_sys_unlink(); break; + case libgloss::SYS_argc: + do_sys_argc(); + break; + case libgloss::SYS_argnlen: + do_sys_argnlen(); + break; + case libgloss::SYS_argn: + do_sys_argn(); + break; default: do_nonstandard_target_syscalls (syscall); break; @@ -744,6 +803,60 @@ gloss32::do_nonstandard_target_syscalls (int32 target_syscall) } void +gloss32::do_sys_argc () +{ + set_int_result (command_line.size ()); + set_error_result (0); +} + +void +gloss32::do_sys_argnlen () +{ + int32 n; + get_int_argument(1, n); + + if (n < command_line.size ()) + { + set_int_result (command_line[n].length ()); + set_error_result (0); + } + else + { + set_int_result (-1); + set_error_result (newlib::eInval); + } +} + +void +gloss32::do_sys_argn () +{ + int32 n, str_ptr; + get_int_argument (1, n); + get_int_argument(2, str_ptr); + + if (n < command_line.size ()) + { + // Include the NULL byte. + int i = command_line[n].length () + 1; + if (set_string (str_ptr, command_line[n])) + { + set_int_result (i); + set_error_result (0); + } + else + { + set_int_result (-1); + set_error_result (newlib::eFault); + } + } + else + { + set_int_result (-1); + set_error_result (newlib::eInval); + } +} + +void gloss32::do_sys_time() { int32 timetp, rv; diff --git a/sid/component/gloss/gloss.h b/sid/component/gloss/gloss.h index 626ce5a127..bc063ccb20 100644 --- a/sid/component/gloss/gloss.h +++ b/sid/component/gloss/gloss.h @@ -1,7 +1,7 @@ // gloss.h - Basic process emulation plus ROM monitor support. // -*- C++ -*- -// Copyright (C) 1999, 2000, 2001 Red Hat. +// Copyright (C) 1999, 2000, 2001, 2002 Red Hat. // This file is part of SID and is licensed under the GPL. // See the file COPYING.SID for conditions for redistribution. @@ -121,6 +121,7 @@ protected: // Calling get_string with length = 0 indicates that there is no // imposed length limit; read from memory until a NUL is encountered. bool set_string(address32 address, const string& value); + bool set_string(address32 address, const char* value, unsigned length); bool get_string(address32 address, string& value, unsigned length = 0); // Get the value of the cpu's program counter. @@ -149,6 +150,9 @@ protected: void do_sys_gettimeofday(); void do_sys_times(); void do_sys_unlink(); + void do_sys_argc(); + void do_sys_argn(); + void do_sys_argnlen(); virtual void do_nonstandard_target_syscalls(int32 syscall); virtual bool target_to_host_open_flags (int open_flags, int& flags); virtual int32 target_to_host_syscall (int32 syscall); @@ -157,7 +161,9 @@ protected: virtual void fault_trap(host_int_4 trap_type, host_int_4 trap_code); // For Unix process emulation. - string command_line; + vector command_line; + string get_command_line (); + component::status set_command_line (const string& cmd_line); // System calls. diff --git a/sid/component/gloss/libgloss.h b/sid/component/gloss/libgloss.h index 19ca33c3a4..bf9e545c4b 100644 --- a/sid/component/gloss/libgloss.h +++ b/sid/component/gloss/libgloss.h @@ -1,6 +1,6 @@ // libgloss.h - Interface details for libgloss. -*- C++ -*- -// Copyright (C) 1999, 2000, 2001 Red Hat. +// Copyright (C) 1999, 2000, 2001, 2002 Red Hat. // This file is part of SID and is licensed under the GPL. // See the file COPYING.SID for conditions for redistribution. @@ -38,7 +38,10 @@ public: SYS_time = 18, SYS_gettimeofday = 19, SYS_times = 20, - SYS_unsupported = 99 // arbitrary syscall number, unsupported by default gloss component + SYS_argc = 172, + SYS_argnlen = 173, + SYS_argn = 174, + SYS_unsupported = 255 // arbitrary syscall number, unsupported by default gloss component }; };