Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
* FW: [PATCH] Commandline Support for the H8300 Simulator.
@ 2003-03-05 14:07 D.Venkatasubramanian, Noida
  2003-03-07 17:11 ` Andrew Cagney
  2003-03-07 17:22 ` Andrew Cagney
  0 siblings, 2 replies; 7+ messages in thread
From: D.Venkatasubramanian, Noida @ 2003-03-05 14:07 UTC (permalink / raw)
  To: 'gdb-patches@sources.redhat.com', Andrew Cagney

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

Hi Andrew,

Here are the patches for the GDB/Sim specific changes
only for commandline implementation.

Other portions of this patch can be viewed at :
http://sources.redhat.com/ml/gdb-patches/2003-02/msg00543.html

Thanks and Regards,

Venky


>-----Original Message-----
>From: Andrew Cagney [mailto:ac131313@redhat.com]
>Sent: Tuesday, March 04, 2003 9:49 PM
>To: D.Venkatasubramanian, Noida
>Subject: Re: [PATCH] Commandline Support for the H8300 Simulator.
>
>
>Can you please submit a patch containing just the GDB/sim specific 
>changes to gdb-patches@.
>
>Andrew
>


[-- Attachment #2: sim_ChangeLog.txt --]
[-- Type: text/plain, Size: 521 bytes --]

2003-02-22  D.Venkatasubramanian  <dvenkat@noida.hcltech.com>

	* compile.c: Added #define SET_CMDLINE_LOCATION to 
	set the location of 8-bit (256 locations) where the
	Command Line arguments would be stored.
	(decode): Added a TRAP to 0xcc for Commandline 
	processing using pseudo opcode O_SYS_CMDLINE.
	(sim_resume): Added handling of O_SYS_CMDLINE Trap.
	(sim_create_inferior): Setting a pointer to 
	Commandline Args array.
	* inst.h: Added a new variable ptr_CommandLine for
	storing pointer to Commandline array.

[-- Attachment #3: inst_h_patch.txt --]
[-- Type: text/plain, Size: 417 bytes --]

*** sim/h8300/inst.h.original	Wed Feb 19 15:28:24 2003
--- sim/h8300/inst.h.modified	Sat Feb 22 19:50:51 2003
*************** enum h8300_sim_state {
*** 66,71 ****
--- 66,74 ----
    SIM_STATE_RUNNING, SIM_STATE_EXITED, SIM_STATE_SIGNALLED, SIM_STATE_STOPPED
  };
  
+ /* For Command Line.  */
+ char **ptr_CommandLine; /* Pointer to command Line Arguments. */
+ 
  typedef struct
  {
    enum h8300_sim_state state;

[-- Attachment #4: compile_c_patch.txt --]
[-- Type: text/plain, Size: 7215 bytes --]

*** sim/h8300/compile.c.original	Wed Feb 19 15:28:09 2003
--- sim/h8300/compile.c.modified	Sat Feb 22 19:50:43 2003
*************** void sim_set_simcache_size PARAMS ((int)
*** 119,124 ****
--- 119,132 ----
  #define UEXTSHORT(x) ((x) & 0xffff)
  #define SEXTSHORT(x) ((short) (x))
  
+ #define SET_CMDLINE_LOCATION \
+   if (h8300smode) \
+     addr_cmdline = 0xffff00L; \
+   else if (h8300hmode) \
+     addr_cmdline = 0x2ff00L; \
+   else \
+     addr_cmdline = 0xff00L;
+ 
  static cpu_state_type cpu;
  
  int h8300hmode = 0;
*************** decode (int addr, unsigned char *data, d
*** 447,460 ****
  		  dst->opcode = q->how;
  		  dst->cycles = q->time;
  
! 		  /* And a jsr to 0xc4 is turned into a magic trap.  */
  
  		  if (dst->opcode == O (O_JSR, SB))
  		    {
! 		      if (dst->src.literal == 0xc4)
  			{
  			  dst->opcode = O (O_SYSCALL, SB);
  			}
  		    }
  
  		  dst->next_pc = addr + len / 2;
--- 455,475 ----
  		  dst->opcode = q->how;
  		  dst->cycles = q->time;
  
! 		  /* And a jsr to these locations are turned into magic
! 		     traps.  */
  
  		  if (dst->opcode == O (O_JSR, SB))
  		    {
! 		      switch (dst->src.literal)
  			{
+ 			case 0xc4:
  			  dst->opcode = O (O_SYSCALL, SB);
+ 			  break;
+ 			case 0xcc:
+ 			  dst->opcode = O (O_SYS_CMDLINE, SB);
+ 			  break;
  			}
+ 		      /* End of Processing for system calls.  */
  		    }
  
  		  dst->next_pc = addr + len / 2;
*************** sim_resume (SIM_DESC sd, int step, int s
*** 1389,1394 ****
--- 1404,1562 ----
  	    sim_callback->write_stdout (sim_callback, &c, 1);
  	  }
  	  goto next;
+ 	  
+ 	/* Trap for Command Line setup.  */
+ 	case O (O_SYS_CMDLINE, SB):
+ 	  {
+ 	    int i = 0;		/* Loop counter.  */
+ 	    int j = 0;		/* Loop counter.  */
+ 	    int ind_arg_len = 0;	/* Length of each argument.  */
+ 	    int no_of_args = 0;	/* The no. or cmdline args.  */
+ 	    int current_location = 0;	/* Location of string.  */
+ 	    int old_sp = 0;	/* The Initial Stack Pointer.  */
+ 	    int no_of_slots = 0;	/* No. of slots required on the stack
+ 					   for storing cmdline args.  */
+ 	    int sp_move = 0;	/* No. of locations by which the stack needs
+ 				   to grow.  */
+ 	    int new_sp = 0;	/* The final stack pointer location passed
+ 				   back.  */
+ 	    int *argv_ptrs;	/* Pointers of argv strings to be stored.  */
+ 	    int argv_ptrs_location = 0;	/* Location of pointers to cmdline
+ 					   args on the stack.  */
+ 	    int char_ptr_size = 0;	/* Size of a character pointer on
+ 					   target machine.  */
+ 	    int addr_cmdline = 0;	/* Memory location where cmdline has
+ 					   to be stored.  */
+ 	    int size_cmdline = 0;	/* Size of cmdline.  */
+ 
+ 	    /* Set the address of 256 free locations where command line is
+ 	       stored.  */
+ 	    SET_CMDLINE_LOCATION
+ 
+ 	    cpu.regs[0] = addr_cmdline;
+ 
+ 	    /* Counting the no. of commandline arguments.  */
+ 	    for (i = 0; ptr_CommandLine[i] != NULL; i++)
+ 	      continue;
+ 
+ 	    /* No. of arguments in the command line.  */
+ 	    no_of_args = i;
+ 
+ 	    /* Current location is just a temporary variable,which we are
+ 	       setting to the point to the start of our commandline string.  */
+ 	    current_location = addr_cmdline;
+ 
+ 	    /* Allocating space for storing pointers of the command line
+ 	       arguments.  */
+ 	    argv_ptrs = (int *) malloc (sizeof (int) * no_of_args);
+ 
+ 	    /* Setting char_ptr_size to the sizeof (char *) on the different
+ 	       architectures.  */
+ 	    if (h8300hmode || h8300smode)
+ 	      {
+ 		char_ptr_size = 4;
+ 	      }
+ 	    else
+ 	      {
+ 		char_ptr_size = 2;
+ 	      }
+ 
+ 	    for (i = 0; i < no_of_args; i++)
+ 	      {
+ 		ind_arg_len = 0;
+ 
+ 		/* The size of the commandline argument.  */
+ 		ind_arg_len = (strlen (ptr_CommandLine[i]) + 1);
+ 
+ 		/* The total size of the command line string.  */
+ 		size_cmdline += ind_arg_len;
+ 
+ 		/* As we have only 256 bytes, we need to provide a graceful
+ 		   exit. Anyways, a program using command line arguments 
+ 		   where we cannot store all the command line arguments
+ 		   given may behave unpredictably.  */
+ 		if (size_cmdline >= 256)
+ 		  {
+ 		    cpu.regs[0] = 0;
+ 		    goto next;
+ 		  }
+ 		else
+ 		  {
+ 		    /* current_location points to the memory where the next
+ 		       commandline argument is stored.  */
+ 		    argv_ptrs[i] = current_location;
+ 		    for (j = 0; j < ind_arg_len; j++)
+ 		      {
+ 			SET_MEMORY_B ((current_location +
+ 				       (sizeof (char) * j)),
+ 				      *(ptr_CommandLine[i] + 
+ 				       sizeof (char) * j));
+ 		      }
+ 
+ 		    /* Setting current_location to the starting of next
+ 		       argument.  */
+ 		    current_location += ind_arg_len;
+ 		  }
+ 	      }
+ 
+ 	    /* This is the original position of the stack pointer.  */
+ 	    old_sp = cpu.regs[7];
+ 
+ 	    /* We need space from the stack to store the pointers to argvs.  */
+ 	    /* As we will infringe on the stack, we need to shift the stack
+ 	       pointer so that the data is not overwritten. We calculate how
+ 	       much space is required.  */
+ 	    sp_move = (no_of_args) * (char_ptr_size);
+ 
+ 	    /* The final position of stack pointer, we have thus taken some
+ 	       space from the stack.  */
+ 	    new_sp = old_sp - sp_move;
+ 
+ 	    /* Temporary variable holding value where the argv pointers need
+ 	       to be stored.  */
+ 	    argv_ptrs_location = new_sp;
+ 
+ 	    /* The argv pointers are stored at sequential locations. As per
+ 	       the H8300 ABI.  */
+ 	    for (i = 0; i < no_of_args; i++)
+ 	      {
+ 		/* Saving the argv pointer.  */
+ 		if (h8300hmode || h8300smode)
+ 		  {
+ 		    SET_MEMORY_L (argv_ptrs_location, argv_ptrs[i]);
+ 		  }
+ 		else
+ 		  {
+ 		    SET_MEMORY_W (argv_ptrs_location, argv_ptrs[i]);
+ 		  }
+ 	
+ 		/* The next location where the pointer to the next argv
+ 		   string has to be stored.  */    
+ 		argv_ptrs_location += char_ptr_size;
+ 	      }
+ 
+ 	    /* Required by POSIX, Setting 0x0 at the end of the list of argv
+ 	       pointers.  */
+ 	    if (h8300hmode || h8300smode)
+ 	      {
+ 		SET_MEMORY_L (old_sp, 0x0);
+ 	      }
+ 	    else
+ 	      {
+ 		SET_MEMORY_W (old_sp, 0x0);
+ 	      }
+ 
+ 	    /* Freeing allocated memory.  */
+ 	    free (argv_ptrs);
+ 
+ 	    /* The no. of argv arguments are returned in Reg 0.  */
+ 	    cpu.regs[0] = no_of_args;
+ 	    /* The Pointer to argv in Register 1.  */
+ 	    cpu.regs[1] = new_sp;
+ 	    /* Setting the stack pointer to the new value.  */
+ 	    cpu.regs[7] = new_sp;
+ 	  }
+ 	  goto next;
  
  	  ONOT (O_NOT, rd = ~rd; v = 0;);
  	  OSHIFTS (O_SHLL,
*************** sim_create_inferior (SIM_DESC sd, struct
*** 2231,2236 ****
--- 2399,2411 ----
      cpu.pc = bfd_get_start_address (abfd);
    else
      cpu.pc = 0;
+ 
+   /* Command Line support.  */
+   if (argv != NULL)
+     {
+       ptr_CommandLine = argv;
+     }
+   
    return SIM_RC_OK;
  }
  

^ permalink raw reply	[flat|nested] 7+ messages in thread
* RE: FW: [PATCH] Commandline Support for the H8300 Simulator.
@ 2003-03-11  8:51 D.Venkatasubramanian, Noida
  0 siblings, 0 replies; 7+ messages in thread
From: D.Venkatasubramanian, Noida @ 2003-03-11  8:51 UTC (permalink / raw)
  To: Andrew Cagney, 'gdb-patches@sources.redhat.com'

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

Dear All,

Here's the patch to add myself to the MAINTAINER's file.

Thanks and Regards,

Venky

Index: MAINTAINERS
===================================================================
RCS file: /cvs/src/src/gdb/MAINTAINERS,v
retrieving revision 1.228
diff -u -3 -r1.228 MAINTAINERS
--- MAINTAINERS 4 Mar 2003 16:33:06 -0000       1.228
+++ MAINTAINERS 11 Mar 2003 07:31:22 -0000
@@ -392,6 +392,7 @@
 Jim Wilson                                     wilson@tuliptree.org
 Elena Zannoni                                  ezannoni@redhat.com
 Eli Zaretskii                                  eliz@gnu.org
+D. Venkatasubramanian                          dvenkat@noida.hcltech.com


------- Changeog entry --------

2003-03-11  D. Venkatasubramanian <dvenkat@noida.hcltech.com>

        * MAINTAINERS (write after approval): Add myself.

>-----Original Message-----
>From: Andrew Cagney [mailto:ac131313@redhat.com]
>Sent: Friday, March 07, 2003 10:42 PM
>To: D.Venkatasubramanian, Noida
>Cc: 'gdb-patches@sources.redhat.com'
>Subject: Re: FW: [PATCH] Commandline Support for the H8300 Simulator.
>
>
>Venky,
>
>Can you please add yourself to the MAINTAINERS file under write-after 
>approval.  Don't forget to to post the changelog/patch.
>
>Andrew
>




[-- Attachment #2: patch.txt --]
[-- Type: text/plain, Size: 477 bytes --]

Index: MAINTAINERS
===================================================================
RCS file: /cvs/src/src/gdb/MAINTAINERS,v
retrieving revision 1.228
diff -u -3 -r1.228 MAINTAINERS
--- MAINTAINERS	4 Mar 2003 16:33:06 -0000	1.228
+++ MAINTAINERS	11 Mar 2003 07:31:22 -0000
@@ -392,6 +392,7 @@
 Jim Wilson					wilson@tuliptree.org
 Elena Zannoni					ezannoni@redhat.com
 Eli Zaretskii					eliz@gnu.org
+D. Venkatasubramanian				dvenkat@noida.hcltech.com
 
 
 

^ permalink raw reply	[flat|nested] 7+ messages in thread
* RE: FW: [PATCH] Commandline Support for the H8300 Simulator.
@ 2003-03-17  9:34 D.Venkatasubramanian, Noida
  0 siblings, 0 replies; 7+ messages in thread
From: D.Venkatasubramanian, Noida @ 2003-03-17  9:34 UTC (permalink / raw)
  To: Andrew Cagney, gdb-patches

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

Hi Andrew,

I have done the changes you had suggested.
I am submitting the GDB part of the changes.

Is it OK?

Thanks and Regards,

Venky

>-----Original Message-----
>From: Andrew Cagney [mailto:ac131313@redhat.com]
>Sent: Friday, March 07, 2003 10:53 PM
>To: D.Venkatasubramanian, Noida; gdb-patches@sources.redhat.com
>Subject: Re: FW: [PATCH] Commandline Support for the H8300 Simulator.
>
>
>
>> 2003-02-22  D.Venkatasubramanian  <dvenkat@noida.hcltech.com>
>> 
>> 	* compile.c: Added #define SET_CMDLINE_LOCATION to 
>> 	set the location of 8-bit (256 locations) where the
>> 	Command Line arguments would be stored.
>> 	(decode): Added a TRAP to 0xcc for Commandline 
>> 	processing using pseudo opcode O_SYS_CMDLINE.
>> 	(sim_resume): Added handling of O_SYS_CMDLINE Trap.
>> 	(sim_create_inferior): Setting a pointer to 
>> 	Commandline Args array.
>> 	* inst.h: Added a new variable ptr_CommandLine for
>> 	storing pointer to Commandline array.
>> 
>> 
>> 
>> *** sim/h8300/inst.h.original	Wed Feb 19 15:28:24 2003
>> --- sim/h8300/inst.h.modified	Sat Feb 22 19:50:51 2003
>> *************** enum h8300_sim_state {
>> *** 66,71 ****
>> --- 66,74 ----
>>     SIM_STATE_RUNNING, SIM_STATE_EXITED, 
>SIM_STATE_SIGNALLED, SIM_STATE_STOPPED
>>   };
>>   
>> + /* For Command Line.  */
>> + char **ptr_CommandLine; /* Pointer to command Line Arguments. */
>
>Please call the variable:
>
>	ptr_command_line
>
>(gnu coding standards don't like edit case variables)
>
>>   typedef struct
>>   {
>>     enum h8300_sim_state state;
>> 
>> 
>> 
>> *** sim/h8300/compile.c.original	Wed Feb 19 15:28:09 2003
>> --- sim/h8300/compile.c.modified	Sat Feb 22 19:50:43 2003
>> *************** void sim_set_simcache_size PARAMS ((int)
>> *** 119,124 ****
>> --- 119,132 ----
>>   #define UEXTSHORT(x) ((x) & 0xffff)
>>   #define SEXTSHORT(x) ((short) (x))
>>   
>> + #define SET_CMDLINE_LOCATION \
>> +   if (h8300smode) \
>> +     addr_cmdline = 0xffff00L; \
>> +   else if (h8300hmode) \
>> +     addr_cmdline = 0x2ff00L; \
>> +   else \
>> +     addr_cmdline = 0xff00L;
>> + 
>
>Please write the above as a function cmdline_location() that 
>returns the 
>address.
>
>> +       ptr_CommandLine = argv;
>
>I'd change that to strdup (argv) (freeing the old value if necessary). 
>that way the code can't run foul of GDB freeing up the parameter.
>
>Otherwize, approved.
>
>Andrew
>


[-- Attachment #2: compile_c_commandline_patch.txt --]
[-- Type: text/plain, Size: 7644 bytes --]

Index: compile.c
===================================================================
RCS file: /cvs/src/src/sim/h8300/compile.c,v
retrieving revision 1.24
diff -c -3 -p -r1.24 compile.c
*** compile.c	14 Mar 2003 04:12:01 -0000	1.24
--- compile.c	14 Mar 2003 11:45:25 -0000
*************** lvalue (int x, int rn)
*** 176,181 ****
--- 176,192 ----
      }
  }
  
+ static int
+ cmdline_location()
+ {
+   if (h8300smode)
+     return 0xffff00L;
+   else if (h8300hmode)
+     return 0x2ff00L;
+   else
+     return 0xff00L;
+ }
+ 
  static unsigned int
  decode (int addr, unsigned char *data, decoded_inst *dst)
  {
*************** decode (int addr, unsigned char *data, d
*** 477,482 ****
--- 488,496 ----
  			case 0xcb:
  			  dst->opcode = O (O_SYS_FSTAT, SB);
  			  break;
+ 			case 0xcc:
+ 			  dst->opcode = O (O_SYS_CMDLINE, SB);
+ 			  break;
  			}
  		      /* End of Processing for system calls.  */
  		    }
*************** sim_resume (SIM_DESC sd, int step, int s
*** 1410,1415 ****
--- 1424,1586 ----
  	    goto condtrue;
  	  goto next;
  
+ 	/* Trap for Command Line setup.  */
+ 	case O (O_SYS_CMDLINE, SB):
+ 	  {
+ 	    int i = 0;		/* Loop counter.  */
+ 	    int j = 0;		/* Loop counter.  */
+ 	    int ind_arg_len = 0;	/* Length of each argument.  */
+ 	    int no_of_args = 0;	/* The no. or cmdline args.  */
+ 	    int current_location = 0;	/* Location of string.  */
+ 	    int old_sp = 0;	/* The Initial Stack Pointer.  */
+ 	    int no_of_slots = 0;	/* No. of slots required on the stack
+ 					   for storing cmdline args.  */
+ 	    int sp_move = 0;	/* No. of locations by which the stack needs
+ 				   to grow.  */
+ 	    int new_sp = 0;	/* The final stack pointer location passed
+ 				   back.  */
+ 	    int *argv_ptrs;	/* Pointers of argv strings to be stored.  */
+ 	    int argv_ptrs_location = 0;	/* Location of pointers to cmdline
+ 					   args on the stack.  */
+ 	    int char_ptr_size = 0;	/* Size of a character pointer on
+ 					   target machine.  */
+ 	    int addr_cmdline = 0;	/* Memory location where cmdline has
+ 					   to be stored.  */
+ 	    int size_cmdline = 0;	/* Size of cmdline.  */
+ 
+ 	    /* Set the address of 256 free locations where command line is
+ 	       stored.  */
+ 	    addr_cmdline = cmdline_location();
+ 	    cpu.regs[0] = addr_cmdline;
+ 
+ 	    /* Counting the no. of commandline arguments.  */
+ 	    for (i = 0; ptr_command_line[i] != NULL; i++)
+ 	      continue;
+ 
+ 	    /* No. of arguments in the command line.  */
+ 	    no_of_args = i;
+ 
+ 	    /* Current location is just a temporary variable,which we are
+ 	       setting to the point to the start of our commandline string.  */
+ 	    current_location = addr_cmdline;
+ 
+ 	    /* Allocating space for storing pointers of the command line
+ 	       arguments.  */
+ 	    argv_ptrs = (int *) malloc (sizeof (int) * no_of_args);
+ 
+ 	    /* Setting char_ptr_size to the sizeof (char *) on the different
+ 	       architectures.  */
+ 	    if (h8300hmode || h8300smode)
+ 	      {
+ 		char_ptr_size = 4;
+ 	      }
+ 	    else
+ 	      {
+ 		char_ptr_size = 2;
+ 	      }
+ 
+ 	    for (i = 0; i < no_of_args; i++)
+ 	      {
+ 		ind_arg_len = 0;
+ 
+ 		/* The size of the commandline argument.  */
+ 		ind_arg_len = (strlen (ptr_command_line[i]) + 1);
+ 
+ 		/* The total size of the command line string.  */
+ 		size_cmdline += ind_arg_len;
+ 
+ 		/* As we have only 256 bytes, we need to provide a graceful
+ 		   exit. Anyways, a program using command line arguments 
+ 		   where we cannot store all the command line arguments
+ 		   given may behave unpredictably.  */
+ 		if (size_cmdline >= 256)
+ 		  {
+ 		    cpu.regs[0] = 0;
+ 		    goto next;
+ 		  }
+ 		else
+ 		  {
+ 		    /* current_location points to the memory where the next
+ 		       commandline argument is stored.  */
+ 		    argv_ptrs[i] = current_location;
+ 		    for (j = 0; j < ind_arg_len; j++)
+ 		      {
+ 			SET_MEMORY_B ((current_location +
+ 				       (sizeof (char) * j)),
+ 				      *(ptr_command_line[i] + 
+ 				       sizeof (char) * j));
+ 		      }
+ 
+ 		    /* Setting current_location to the starting of next
+ 		       argument.  */
+ 		    current_location += ind_arg_len;
+ 		  }
+ 	      }
+ 
+ 	    /* This is the original position of the stack pointer.  */
+ 	    old_sp = cpu.regs[7];
+ 
+ 	    /* We need space from the stack to store the pointers to argvs.  */
+ 	    /* As we will infringe on the stack, we need to shift the stack
+ 	       pointer so that the data is not overwritten. We calculate how
+ 	       much space is required.  */
+ 	    sp_move = (no_of_args) * (char_ptr_size);
+ 
+ 	    /* The final position of stack pointer, we have thus taken some
+ 	       space from the stack.  */
+ 	    new_sp = old_sp - sp_move;
+ 
+ 	    /* Temporary variable holding value where the argv pointers need
+ 	       to be stored.  */
+ 	    argv_ptrs_location = new_sp;
+ 
+ 	    /* The argv pointers are stored at sequential locations. As per
+ 	       the H8300 ABI.  */
+ 	    for (i = 0; i < no_of_args; i++)
+ 	      {
+ 		/* Saving the argv pointer.  */
+ 		if (h8300hmode || h8300smode)
+ 		  {
+ 		    SET_MEMORY_L (argv_ptrs_location, argv_ptrs[i]);
+ 		  }
+ 		else
+ 		  {
+ 		    SET_MEMORY_W (argv_ptrs_location, argv_ptrs[i]);
+ 		  }
+ 	
+ 		/* The next location where the pointer to the next argv
+ 		   string has to be stored.  */    
+ 		argv_ptrs_location += char_ptr_size;
+ 	      }
+ 
+ 	    /* Required by POSIX, Setting 0x0 at the end of the list of argv
+ 	       pointers.  */
+ 	    if (h8300hmode || h8300smode)
+ 	      {
+ 		SET_MEMORY_L (old_sp, 0x0);
+ 	      }
+ 	    else
+ 	      {
+ 		SET_MEMORY_W (old_sp, 0x0);
+ 	      }
+ 
+ 	    /* Freeing allocated memory.  */
+ 	    free (argv_ptrs);
+ 	    for (i = 0; i <= no_of_args; i++)
+ 	      {
+ 		free (ptr_command_line[i]);
+ 	      }
+ 	    free (ptr_command_line);
+ 
+ 	    /* The no. of argv arguments are returned in Reg 0.  */
+ 	    cpu.regs[0] = no_of_args;
+ 	    /* The Pointer to argv in Register 1.  */
+ 	    cpu.regs[1] = new_sp;
+ 	    /* Setting the stack pointer to the new value.  */
+ 	    cpu.regs[7] = new_sp;
+ 	  }
+ 	  goto next;
+ 
  	  /* System call processing starts.  */
  	case O (O_SYS_OPEN, SB):
  	  {
*************** sim_load (SIM_DESC sd, char *prog, bfd *
*** 2531,2540 ****
--- 2702,2738 ----
  SIM_RC
  sim_create_inferior (SIM_DESC sd, struct bfd *abfd, char **argv, char **env)
  {
+   int i = 0;
+   int len_arg = 0;
+   int no_of_args = 0;
+   
    if (abfd != NULL)
      cpu.pc = bfd_get_start_address (abfd);
    else
      cpu.pc = 0;
+ 
+   /* Command Line support.  */
+   if (argv != NULL)
+     {
+       /* Counting the no. of commandline arguments.  */
+       for (no_of_args = 0; argv[no_of_args] != NULL; no_of_args++)
+         continue;
+ 
+       /* Allocating memory for the argv pointers.  */
+       ptr_command_line = (char **) malloc ((sizeof (char *))
+ 		         * (no_of_args + 1));
+ 
+       for (i = 0; i < no_of_args; i++)
+ 	{
+ 	  /* Calculating the length of argument for allocating memory.  */
+ 	  len_arg = strlen (argv[i] + 1);
+ 	  ptr_command_line[i] = (char *) malloc (sizeof (char) * len_arg);
+ 	  /* Copying the argument string.  */
+ 	  ptr_command_line[i] = (char *) strdup (argv[i]);
+ 	}
+       ptr_command_line[i] = NULL;
+     }
+   
    return SIM_RC_OK;
  }
  

[-- Attachment #3: inst_h_commandline_patch.txt --]
[-- Type: text/plain, Size: 582 bytes --]

Index: inst.h
===================================================================
RCS file: /cvs/src/src/sim/h8300/inst.h,v
retrieving revision 1.4
diff -c -3 -p -r1.4 inst.h
*** inst.h	26 Dec 2002 05:44:46 -0000	1.4
--- inst.h	14 Mar 2003 11:46:32 -0000
*************** enum h8300_sim_state {
*** 66,71 ****
--- 66,74 ----
    SIM_STATE_RUNNING, SIM_STATE_EXITED, SIM_STATE_SIGNALLED, SIM_STATE_STOPPED
  };
  
+ /* For Command Line.  */
+ char **ptr_command_line; /* Pointer to Command Line Arguments. */
+ 
  typedef struct
  {
    enum h8300_sim_state state;

[-- Attachment #4: Simulator_ChangeLog.txt --]
[-- Type: text/plain, Size: 521 bytes --]

2003-03-17  D.Venkatasubramanian  <dvenkat@noida.hcltech.com>

	* compile.c: Added #define SET_CMDLINE_LOCATION to 
	set the location of 8-bit (256 locations) where the
	Command Line arguments would be stored.
	(decode): Added a TRAP to 0xcc for Commandline 
	processing using pseudo opcode O_SYS_CMDLINE.
	(sim_resume): Added handling of O_SYS_CMDLINE Trap.
	(sim_create_inferior): Setting a pointer to 
	Commandline Args array.
	* inst.h: Added a new variable ptr_CommandLine for
	storing pointer to Commandline array.

^ permalink raw reply	[flat|nested] 7+ messages in thread
* RE: FW: [PATCH] Commandline Support for the H8300 Simulator.
@ 2003-03-17  9:36 D.Venkatasubramanian, Noida
  2003-03-17 14:28 ` Andrew Cagney
  0 siblings, 1 reply; 7+ messages in thread
From: D.Venkatasubramanian, Noida @ 2003-03-17  9:36 UTC (permalink / raw)
  To: D.Venkatasubramanian, Noida, Andrew Cagney, gdb-patches

Hi,

Corrected ChangeLog.

Thanks and Regards,

Venky

2003-03-17  D.Venkatasubramanian  <dvenkat@noida.hcltech.com>

	* compile.c: Added #define SET_CMDLINE_LOCATION to 
	set the location of 8-bit (256 locations) where the
	Command Line arguments would be stored.
	(decode): Added a TRAP to 0xcc for Commandline 
	processing using pseudo opcode O_SYS_CMDLINE.
	(sim_resume): Added handling of O_SYS_CMDLINE Trap.
	(sim_create_inferior): Setting a pointer to 
	Commandline Args array.
	* inst.h: Added a new variable ptr_command_line for
	storing pointer to Commandline array.

>-----Original Message-----
>From: D.Venkatasubramanian, Noida 
>Sent: Monday, March 17, 2003 3:07 PM
>To: 'Andrew Cagney'; gdb-patches@sources.redhat.com
>Subject: RE: FW: [PATCH] Commandline Support for the H8300 Simulator.
>
>
>Hi Andrew,
>
>I have done the changes you had suggested.
>I am submitting the GDB part of the changes.
>
>Is it OK?
>
>Thanks and Regards,
>
>Venky
>
>>-----Original Message-----
>>From: Andrew Cagney [mailto:ac131313@redhat.com]
>>Sent: Friday, March 07, 2003 10:53 PM
>>To: D.Venkatasubramanian, Noida; gdb-patches@sources.redhat.com
>>Subject: Re: FW: [PATCH] Commandline Support for the H8300 Simulator.
>>
>>
>>
>>> 2003-02-22  D.Venkatasubramanian  <dvenkat@noida.hcltech.com>
>>> 
>>> 	* compile.c: Added #define SET_CMDLINE_LOCATION to 
>>> 	set the location of 8-bit (256 locations) where the
>>> 	Command Line arguments would be stored.
>>> 	(decode): Added a TRAP to 0xcc for Commandline 
>>> 	processing using pseudo opcode O_SYS_CMDLINE.
>>> 	(sim_resume): Added handling of O_SYS_CMDLINE Trap.
>>> 	(sim_create_inferior): Setting a pointer to 
>>> 	Commandline Args array.
>>> 	* inst.h: Added a new variable ptr_CommandLine for
>>> 	storing pointer to Commandline array.
>>> 
>>> 
>>> 
>>> *** sim/h8300/inst.h.original	Wed Feb 19 15:28:24 2003
>>> --- sim/h8300/inst.h.modified	Sat Feb 22 19:50:51 2003
>>> *************** enum h8300_sim_state {
>>> *** 66,71 ****
>>> --- 66,74 ----
>>>     SIM_STATE_RUNNING, SIM_STATE_EXITED, 
>>SIM_STATE_SIGNALLED, SIM_STATE_STOPPED
>>>   };
>>>   
>>> + /* For Command Line.  */
>>> + char **ptr_CommandLine; /* Pointer to command Line Arguments. */
>>
>>Please call the variable:
>>
>>	ptr_command_line
>>
>>(gnu coding standards don't like edit case variables)
>>
>>>   typedef struct
>>>   {
>>>     enum h8300_sim_state state;
>>> 
>>> 
>>> 
>>> *** sim/h8300/compile.c.original	Wed Feb 19 15:28:09 2003
>>> --- sim/h8300/compile.c.modified	Sat Feb 22 19:50:43 2003
>>> *************** void sim_set_simcache_size PARAMS ((int)
>>> *** 119,124 ****
>>> --- 119,132 ----
>>>   #define UEXTSHORT(x) ((x) & 0xffff)
>>>   #define SEXTSHORT(x) ((short) (x))
>>>   
>>> + #define SET_CMDLINE_LOCATION \
>>> +   if (h8300smode) \
>>> +     addr_cmdline = 0xffff00L; \
>>> +   else if (h8300hmode) \
>>> +     addr_cmdline = 0x2ff00L; \
>>> +   else \
>>> +     addr_cmdline = 0xff00L;
>>> + 
>>
>>Please write the above as a function cmdline_location() that 
>>returns the 
>>address.
>>
>>> +       ptr_CommandLine = argv;
>>
>>I'd change that to strdup (argv) (freeing the old value if 
>necessary). 
>>that way the code can't run foul of GDB freeing up the parameter.
>>
>>Otherwize, approved.
>>
>>Andrew
>>
>


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

end of thread, other threads:[~2003-03-17 14:28 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2003-03-05 14:07 FW: [PATCH] Commandline Support for the H8300 Simulator D.Venkatasubramanian, Noida
2003-03-07 17:11 ` Andrew Cagney
2003-03-07 17:22 ` Andrew Cagney
2003-03-11  8:51 D.Venkatasubramanian, Noida
2003-03-17  9:34 D.Venkatasubramanian, Noida
2003-03-17  9:36 D.Venkatasubramanian, Noida
2003-03-17 14:28 ` Andrew Cagney

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox