+2002-01-25 Ben Elliston <bje@redhat.com>
+
+ * 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<string>.
+ (gloss32::get_command_line): New virtual attribute callback.
+ (gloss32::set_command_line): Likewise.
+
2001-11-30 Frank Ch. Eigler <fche@redhat.com>
* gloss.cxx (write): Add missing ios:: namespace prefix.
// 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.
rx_pin(this, &gloss32::rx_handler),
cpu (0),
cpu_memory_bus (0),
- command_line("<unknown>"),
syscall_numbering_scheme("libgloss"),
max_fds(32),
verbose_p(false)
{
+ command_line.push_back ("<unknown>");
+
// ??? There's a naming disconnect between "cpu" and "target_memory".
add_accessor("target-memory", &this->cpu_memory_bus);
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");
delete [] fd_table;
}
+string
+gloss32::get_command_line ()
+{
+ string cline;
+ for (std::vector<string>::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<string> argv = sidutil::tokenize (cline, " ");
+ command_line.clear();
+
+ if (argv.empty())
+ {
+ command_line.push_back ("<unknown>");
+ return component::bad_value;
+ }
+
+ // Insert all non-empty strings into command_line.
+ for (std::vector<string>::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)
{
}
bool
-gloss32::set_string(address32 address, const string& value)
+gloss32::set_string (address32 address, const char* value, unsigned length)
{
if (! this->cpu_memory_bus)
{
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;
}
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)
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;
}
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;
// 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.
// 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.
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);
virtual void fault_trap(host_int_4 trap_type, host_int_4 trap_code);
// For Unix process emulation.
- string command_line;
+ vector<string> command_line;
+ string get_command_line ();
+ component::status set_command_line (const string& cmd_line);
// System calls.