This is the mail archive of the gdb-patches@sources.redhat.com mailing list for the GDB project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[PATCH] Commandline Support for the H8300 Simulator.


Hi All,

I am submitting a patch for adding support for 
the processing of commandline arguments on the 
H8300 Simulator.

A brief description of each of the changes 
follows:

(File : h8300_h_patch.txt)
1) Added a pseudo opcode O_SYS_CMDLINE which 
will act as a trap identifier in h8300.h.

(File : crt0_S_patch.txt)
2) An extra instruction enclosed between a 
#ifdef __SIMULATOR_ARGV_SUPPORT__ / #endif 
directives, which simulates a trap instruction.
This instruction is a jsr to 0xcc, one of the 
locations in the magic vector used by H8300.

(File : configure_host_patch.txt)
3) Added a macro -DSIMULATOR_ARGV_SUPPORT. The 
configure.host file ensures that this macro 
is activated when our target is a simulator.

(File : inst_h_patch.txt)
4) Added a new char ** variable which will 
hold the address of the Commandline arguments 
which the common files of the simulator would 
provide.

(File : compile_c_patch.txt)
This requires a lengthy explanation
5) This macro sets a variable addr_cmdline to 
point to the location of the 8-bit high memory 
area as defined in the linker scripts. If the 
linker scripts change, then so would this 
require a change.

 #define SET_CMDLINE_LOCATION \
   if (h8300smode) \
     addr_cmdline = 0xffff00L; \
   else if (h8300hmode) \
     addr_cmdline = 0x2ff00L; \
   else \
     addr_cmdline = 0xff00L;

6) 0xcc is a magic vector location used to 
simulate a trap instruction on H8300.
Q : Why I chose 0xcc?
A : A patch for File I/O implementation is 
pending approval, and those require 0xc5 - 0xcb, 
hence the 0xcc, once that patch is approved, the 
Oxc4 would be rendered useless and we could then 
use it instead of 0xcc. (Whether or not we want to 
change to 0xc4 then is a matter of trivial opinion.)

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

7) Setting pointer to Commandline arguments 
provided by the common simulator support.
 
   /* Command Line support.  */
   if (argv != NULL)
     {
       ptr_CommandLine = argv;
     }
   
8) The code starting with this in sim_resume 
handles the actual simulation of the system call.

case O (O_SYS_CMDLINE, SB):

I have added a lot of comments to the code.

Briefly, this saves the commandline arguments to 
the 8-bit memory area, and sets up an array which 
contains the addresses in the 8-bit area, where
each argument starts. Once that is done, these 
have to be saved in simulator memory consecutively.
As I need memory which is non volatile, I steal 
some memory from the stack and move the stack 
pointer such that I have enough memory to store all
these addresses. As teh stack pointer holds the new
value at the end, this memory is rendered non-volatile.

At this point, I store the addresses in the array 
containing the address values for the commandline 
arguments to this memory.

Nick Clifton had pointed out that at the beginning, 
there should be another value, a pointer to the 
beginning of argv. But the H8300 compiler seems not 
to require this. I set the no. of arguments to 
Register 0, address of the first of the address on 
the non-volatile memory to Register 1, and set the 
new stack pointer to the top of this non-volatile 
memory. (Slightly controversial stuff, that extra
pointer to argv that Nick had specified, but adding
that seems to break the support, the last argument
gets left out.)

Tested on H8300-hms and H8300-elf and does not seem
to break anything. Also I am able to print the 
commandline arguments correctly.

I used a simple test case :
int main(int argc, char *argv[])
{
        int i;
        int j = 0;

        printf ("Argc = %d\n", argc);

        for (i = 0; i < argc; i++)
                printf ("%s\n", argv[i]);
        return 0;
}

Could someone review this patch and point out any issues. 
Thought, this would be very useful feature combined with
the File I/O feature for which I have already submitted
a patch.

I think I will end this long description here.

Thank You Nick Clifton and Kazu Hirata and all those that 
were helpful in the explanation of ABI and other issues.

Thanks and Regards,

Venky

PS : There are two files complete_patch.txt and 
complete_ChangeLog.txt which contain all the patches
and ChangeLogs in single files respectively.

Changelog Entries

In include/opcode (File : binutils_ChangeLog.txt)


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

	* h8300.h: Added a pseudo opcodes for Commandline
	processing.

In newlib/ (File : newlib_ChangeLog.txt)

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

	* libc/include/sys/h8300hms/crt0.S: Added an extra 
	instruction enclosed by SIMULATOR_ARGV_SUPPORT macro 
	for Commandline support when target is simulator.
	* configure.host: Added -DSIMULATOR_ARGV_SUPPORT for
	Commandline Support.

In sim/h8300/ (File : sim_ChangeLog.txt)

2003-02-22  D.Venkatasubramanian  <dvenkat at noida dot hcltech dot 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: sim_ChangeLog.txt
Description: Text document

Attachment: newlib_ChangeLog.txt
Description: Text document

Attachment: inst_h_patch.txt
Description: Text document

Attachment: h8300_h_patch.txt
Description: Text document

Attachment: crt0_S_patch.txt
Description: Text document

Attachment: configure_host_patch.txt
Description: Text document

Attachment: compile_c_patch.txt
Description: Text document

Attachment: binutils_ChangeLog.txt
Description: Text document

Attachment: complete_ChangeLog.txt
Description: Text document

Attachment: complete_patch.txt
Description: Text document


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]