public inbox for sid@sourceware.org
 help / color / mirror / Atom feed
* gloss patch for argc/argv retrieval
@ 2002-01-24 19:21 Ben Elliston
  2002-01-25  8:37 ` Frank Ch. Eigler
  2002-01-30 22:02 ` Ben Elliston
  0 siblings, 2 replies; 7+ messages in thread
From: Ben Elliston @ 2002-01-24 19:21 UTC (permalink / raw)
  To: sid

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  <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.

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("<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);
 
@@ -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<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)
 {
@@ -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<string> 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
   };
 };
 

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: gloss patch for argc/argv retrieval
  2002-01-24 19:21 gloss patch for argc/argv retrieval Ben Elliston
@ 2002-01-25  8:37 ` Frank Ch. Eigler
  2002-01-25 10:06   ` Thomas Fitzsimmons
                     ` (2 more replies)
  2002-01-30 22:02 ` Ben Elliston
  1 sibling, 3 replies; 7+ messages in thread
From: Frank Ch. Eigler @ 2002-01-25  8:37 UTC (permalink / raw)
  To: Ben Elliston; +Cc: sid

[-- Attachment #1: Type: text/plain, Size: 682 bytes --]

Hi -

On Fri, Jan 25, 2002 at 02:21:46PM +1100, Ben Elliston wrote:
> 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 suspect a single system call, like ARM ANGEL's "get entire command
line as a string" would be sufficient.  Are you planning to add
support for this system call to some libgloss ports also?


- FChE

[-- Attachment #2: Type: application/pgp-signature, Size: 232 bytes --]

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: gloss patch for argc/argv retrieval
  2002-01-25  8:37 ` Frank Ch. Eigler
@ 2002-01-25 10:06   ` Thomas Fitzsimmons
  2002-01-25 14:16   ` Ben Elliston
       [not found]   ` <15441.55603.150572.158514.cygnus.project.sid@scooby.brisbane.redhat.com>
  2 siblings, 0 replies; 7+ messages in thread
From: Thomas Fitzsimmons @ 2002-01-25 10:06 UTC (permalink / raw)
  To: Ben Elliston; +Cc: sid

On Fri, 2002-01-25 at 11:37, Frank Ch. Eigler wrote:
> Hi -
> 
> On Fri, Jan 25, 2002 at 02:21:46PM +1100, Ben Elliston wrote:
> > 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 suspect a single system call, like ARM ANGEL's "get entire command
> line as a string" would be sufficient.  Are you planning to add
> support for this system call to some libgloss ports also?
> 

If you are, you should look at the i386 gloss port, which has support
for a __get_program_arguments syscall, number 184. The implementation is
in devo/libstub/generic-stub.c in the __get_program_args function.

Tom

-- 
Thomas Fitzsimmons
Red Hat Canada Limited        e-mail: fitzsim@redhat.com
2323 Yonge Street, Suite 300
Toronto, ON M4P2C9

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: gloss patch for argc/argv retrieval
  2002-01-25  8:37 ` Frank Ch. Eigler
  2002-01-25 10:06   ` Thomas Fitzsimmons
@ 2002-01-25 14:16   ` Ben Elliston
       [not found]   ` <15441.55603.150572.158514.cygnus.project.sid@scooby.brisbane.redhat.com>
  2 siblings, 0 replies; 7+ messages in thread
From: Ben Elliston @ 2002-01-25 14:16 UTC (permalink / raw)
  To: Frank Ch. Eigler; +Cc: sid

>>>>> "FChE" == Frank Ch Eigler <fche@redhat.com> writes:

  >> 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.  [...]
  >> [...]

  FChE> I suspect a single system call, like ARM ANGEL's "get entire command
  FChE> line as a string" would be sufficient.  Are you planning to add
  FChE> support for this system call to some libgloss ports also?

For some targets like the SH, it is not sufficient.  If you inspect
the newlib source, you'll see SYS_argn, SYS_argnlen, etc.  I suppose
each port could translation between a single syscall, but as soon as
more than one target requires these services, the gloss component
might as well provide them.

Ben

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: gloss patch for argc/argv retrieval
       [not found]   ` <15441.55603.150572.158514.cygnus.project.sid@scooby.brisbane.redhat.com>
@ 2002-01-25 15:14     ` Frank Ch. Eigler
  2002-01-25 15:23       ` Ben Elliston
  0 siblings, 1 reply; 7+ messages in thread
From: Frank Ch. Eigler @ 2002-01-25 15:14 UTC (permalink / raw)
  To: Ben Elliston; +Cc: sid


bje wrote:

>   FChE> I suspect a single system call, like ARM ANGEL's "get entire command
>   FChE> line as a string" would be sufficient.  [...]
> 
> For some targets like the SH, it is not sufficient.  If you inspect
> the newlib source, you'll see SYS_argn, SYS_argnlen, etc.  [...]

Sure .. but has this code ever been *run*?  Does it matter enough to
make this basic facility more complex?  The initial input is a single
plain string.  If some targets are willing to undertake parsing it
(arm, analogously linux) into argc/argv in target code, we can let the
others do that too.


- FChE

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: gloss patch for argc/argv retrieval
  2002-01-25 15:14     ` Frank Ch. Eigler
@ 2002-01-25 15:23       ` Ben Elliston
  0 siblings, 0 replies; 7+ messages in thread
From: Ben Elliston @ 2002-01-25 15:23 UTC (permalink / raw)
  To: Frank Ch. Eigler; +Cc: sid

>>>>> "FChE" == Frank Ch Eigler <fche@redhat.com> writes:

  >> For some targets like the SH, it is not sufficient.  If you inspect
  >> the newlib source, you'll see SYS_argn, SYS_argnlen, etc.  [...]

  FChE> Sure .. but has this code ever been *run*?  Does it matter enough to

Yes, it is used.

Ben

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: gloss patch for argc/argv retrieval
  2002-01-24 19:21 gloss patch for argc/argv retrieval Ben Elliston
  2002-01-25  8:37 ` Frank Ch. Eigler
@ 2002-01-30 22:02 ` Ben Elliston
  1 sibling, 0 replies; 7+ messages in thread
From: Ben Elliston @ 2002-01-30 22:02 UTC (permalink / raw)
  To: sid

>>>>> "Ben" == Ben Elliston <bje@redhat.com> writes:

  Ben> It is currently possible for a SID configuration to set the gloss
  Ben> "command-line" attribute for process emulation.  However I noted that
  Ben> the gloss component doesn't do much with it -- except store it.

  Ben> The following patch adds a number of new syscalls to enable software
  Ben> running on target CPUs to request the argc and argv variables passed
  Ben> in from the outside world.  I'd be grateful of some feedback
  Ben> (especially with respect to the choice of the enumerator values for
  Ben> the syscall enum).  Comments?

Does anyone have any violent objections with this change?  If not, I
will commit it tomorrow morning.

Ben

^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2002-01-31  6:02 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2002-01-24 19:21 gloss patch for argc/argv retrieval Ben Elliston
2002-01-25  8:37 ` Frank Ch. Eigler
2002-01-25 10:06   ` Thomas Fitzsimmons
2002-01-25 14:16   ` Ben Elliston
     [not found]   ` <15441.55603.150572.158514.cygnus.project.sid@scooby.brisbane.redhat.com>
2002-01-25 15:14     ` Frank Ch. Eigler
2002-01-25 15:23       ` Ben Elliston
2002-01-30 22:02 ` Ben Elliston

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).