From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 1731 invoked by alias); 25 Jan 2002 03:21:55 -0000 Mailing-List: contact sid-help@sources.redhat.com; run by ezmlm Precedence: bulk List-Subscribe: List-Archive: List-Post: List-Help: , Sender: sid-owner@sources.redhat.com Received: (qmail 1688 invoked from network); 25 Jan 2002 03:21:49 -0000 Received: from unknown (HELO hypatia.brisbane.redhat.com) (202.83.74.3) by sources.redhat.com with SMTP; 25 Jan 2002 03:21:49 -0000 Received: from scooby.brisbane.redhat.com (scooby.brisbane.redhat.com [172.16.5.228]) by hypatia.brisbane.redhat.com (8.11.6/8.11.6) with ESMTP id g0P3LkY30002 for ; Fri, 25 Jan 2002 13:21:47 +1000 Received: by scooby.brisbane.redhat.com (Postfix, from userid 500) id 4A4BE10932; Fri, 25 Jan 2002 14:21:46 +1100 (EST) From: Ben Elliston MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit Message-ID: <15440.53066.47081.565065@scooby.brisbane.redhat.com> Date: Thu, 24 Jan 2002 19:21:00 -0000 To: sid@sources.redhat.com Subject: gloss patch for argc/argv retrieval X-Mailer: VM 6.75 under 21.1 (patch 14) "Cuyahoga Valley" XEmacs Lucid X-SW-Source: 2002-q1/txt/msg00009.txt.bz2 It is currently possible for a SID configuration to set the gloss "command-line" attribute for process emulation. However I noted that the gloss component doesn't do much with it -- except store it. The following patch adds a number of new syscalls to enable software running on target CPUs to request the argc and argv variables passed in from the outside world. I'd be grateful of some feedback (especially with respect to the choice of the enumerator values for the syscall enum). Comments? Cheers, Ben 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. Index: gloss.cxx =================================================================== RCS file: /cvs/cvsfiles/devo/sid/component/gloss/gloss.cxx,v retrieving revision 1.40 diff -u -r1.40 gloss.cxx --- gloss.cxx 2001/12/01 00:57:01 1.40 +++ gloss.cxx 2002/01/25 03:01:45 @@ -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 @@ 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); @@ -63,8 +64,12 @@ add_attribute_ro_value ("tk tty", string("hw-visual-tty"), "gui"); add_uni_relation("cpu", &this->cpu); + + add_attribute_virtual("command-line", this, + &gloss32::get_command_line, + &gloss32::set_command_line, + "setting"); - add_attribute("command-line", &this->command_line, "setting"); add_attribute("syscall-numbering-scheme", &this->syscall_numbering_scheme, "setting"); add_attribute("verbose?", &this->verbose_p, "setting"); @@ -80,6 +85,45 @@ 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 @@ } 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 @@ 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 @@ } 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 @@ 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; @@ -741,6 +800,60 @@ cerr << "Unimplemented syscall " << target_syscall << endl; set_int_result(-1); set_error_result(newlib::eNoSys); +} + +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 Index: gloss.h =================================================================== RCS file: /cvs/cvsfiles/devo/sid/component/gloss/gloss.h,v retrieving revision 1.23 diff -u -r1.23 gloss.h --- gloss.h 2002/01/03 01:41:54 1.23 +++ gloss.h 2002/01/25 03:01:45 @@ -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 @@ // 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 @@ 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 @@ 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. Index: libgloss.h =================================================================== RCS file: /cvs/cvsfiles/devo/sid/component/gloss/libgloss.h,v retrieving revision 1.7 diff -u -r1.7 libgloss.h --- libgloss.h 2002/01/03 01:41:54 1.7 +++ libgloss.h 2002/01/25 03:01:45 @@ -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 @@ 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 }; };