From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 13954 invoked by alias); 17 Mar 2003 09:34:15 -0000 Mailing-List: contact gdb-patches-help@sources.redhat.com; run by ezmlm Precedence: bulk List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sources.redhat.com Received: (qmail 13827 invoked from network); 17 Mar 2003 09:34:12 -0000 Received: from unknown (HELO ngate.noida.hcltech.com) (202.54.110.230) by sources.redhat.com with SMTP; 17 Mar 2003 09:34:12 -0000 Received: from exch-01.noida.hcltech.com (exch-01 [204.160.254.29]) by ngate.noida.hcltech.com (8.9.3/8.9.3) with ESMTP id PAA06028; Mon, 17 Mar 2003 15:08:35 +0530 Received: by exch-01.noida.hcltech.com with Internet Mail Service (5.5.2656.59) id ; Mon, 17 Mar 2003 14:57:13 +0530 Message-ID: From: "D.Venkatasubramanian, Noida" To: Andrew Cagney , gdb-patches@sources.redhat.com Subject: RE: FW: [PATCH] Commandline Support for the H8300 Simulator. Date: Mon, 17 Mar 2003 09:34:00 -0000 MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="----_=_NextPart_000_01C2EC67.3AD32D20" X-SW-Source: 2003-03/txt/msg00357.txt.bz2 This message is in MIME format. Since your mail reader does not understand this format, some or all of this message may not be legible. ------_=_NextPart_000_01C2EC67.3AD32D20 Content-Type: text/plain; charset="iso-8859-1" Content-length: 2375 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 >> >> * 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 > ------_=_NextPart_000_01C2EC67.3AD32D20 Content-Type: text/plain; name="compile_c_commandline_patch.txt" Content-Transfer-Encoding: quoted-printable Content-Disposition: attachment; filename="compile_c_commandline_patch.txt" Content-length: 7745 Index: compile.c =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D 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 ---- } } =20=20 + static int + cmdline_location() + { + if (h8300smode) + return 0xffff00L; + else if (h8300hmode) + return 0x2ff00L; + else + return 0xff00L; + } +=20 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 =3D O (O_SYS_FSTAT, SB); break; + case 0xcc: + dst->opcode =3D 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; =20=20 + /* Trap for Command Line setup. */ + case O (O_SYS_CMDLINE, SB): + { + int i =3D 0; /* Loop counter. */ + int j =3D 0; /* Loop counter. */ + int ind_arg_len =3D 0; /* Length of each argument. */ + int no_of_args =3D 0; /* The no. or cmdline args. */ + int current_location =3D 0; /* Location of string. */ + int old_sp =3D 0; /* The Initial Stack Pointer. */ + int no_of_slots =3D 0; /* No. of slots required on the stack + for storing cmdline args. */ + int sp_move =3D 0; /* No. of locations by which the stack needs + to grow. */ + int new_sp =3D 0; /* The final stack pointer location passed + back. */ + int *argv_ptrs; /* Pointers of argv strings to be stored. */ + int argv_ptrs_location =3D 0; /* Location of pointers to cmdline + args on the stack. */ + int char_ptr_size =3D 0; /* Size of a character pointer on + target machine. */ + int addr_cmdline =3D 0; /* Memory location where cmdline has + to be stored. */ + int size_cmdline =3D 0; /* Size of cmdline. */ +=20 + /* Set the address of 256 free locations where command line is + stored. */ + addr_cmdline =3D cmdline_location(); + cpu.regs[0] =3D addr_cmdline; +=20 + /* Counting the no. of commandline arguments. */ + for (i =3D 0; ptr_command_line[i] !=3D NULL; i++) + continue; +=20 + /* No. of arguments in the command line. */ + no_of_args =3D i; +=20 + /* Current location is just a temporary variable,which we are + setting to the point to the start of our commandline string. */ + current_location =3D addr_cmdline; +=20 + /* Allocating space for storing pointers of the command line + arguments. */ + argv_ptrs =3D (int *) malloc (sizeof (int) * no_of_args); +=20 + /* Setting char_ptr_size to the sizeof (char *) on the different + architectures. */ + if (h8300hmode || h8300smode) + { + char_ptr_size =3D 4; + } + else + { + char_ptr_size =3D 2; + } +=20 + for (i =3D 0; i < no_of_args; i++) + { + ind_arg_len =3D 0; +=20 + /* The size of the commandline argument. */ + ind_arg_len =3D (strlen (ptr_command_line[i]) + 1); +=20 + /* The total size of the command line string. */ + size_cmdline +=3D ind_arg_len; +=20 + /* As we have only 256 bytes, we need to provide a graceful + exit. Anyways, a program using command line arguments=20 + where we cannot store all the command line arguments + given may behave unpredictably. */ + if (size_cmdline >=3D 256) + { + cpu.regs[0] =3D 0; + goto next; + } + else + { + /* current_location points to the memory where the next + commandline argument is stored. */ + argv_ptrs[i] =3D current_location; + for (j =3D 0; j < ind_arg_len; j++) + { + SET_MEMORY_B ((current_location + + (sizeof (char) * j)), + *(ptr_command_line[i] +=20 + sizeof (char) * j)); + } +=20 + /* Setting current_location to the starting of next + argument. */ + current_location +=3D ind_arg_len; + } + } +=20 + /* This is the original position of the stack pointer. */ + old_sp =3D cpu.regs[7]; +=20 + /* 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 =3D (no_of_args) * (char_ptr_size); +=20 + /* The final position of stack pointer, we have thus taken some + space from the stack. */ + new_sp =3D old_sp - sp_move; +=20 + /* Temporary variable holding value where the argv pointers need + to be stored. */ + argv_ptrs_location =3D new_sp; +=20 + /* The argv pointers are stored at sequential locations. As per + the H8300 ABI. */ + for (i =3D 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]); + } +=20=09 + /* The next location where the pointer to the next argv + string has to be stored. */=20=20=20=20 + argv_ptrs_location +=3D char_ptr_size; + } +=20 + /* 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); + } +=20 + /* Freeing allocated memory. */ + free (argv_ptrs); + for (i =3D 0; i <=3D no_of_args; i++) + { + free (ptr_command_line[i]); + } + free (ptr_command_line); +=20 + /* The no. of argv arguments are returned in Reg 0. */ + cpu.regs[0] =3D no_of_args; + /* The Pointer to argv in Register 1. */ + cpu.regs[1] =3D new_sp; + /* Setting the stack pointer to the new value. */ + cpu.regs[7] =3D new_sp; + } + goto next; +=20 /* 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 **e= nv) { + int i =3D 0; + int len_arg =3D 0; + int no_of_args =3D 0; +=20=20=20 if (abfd !=3D NULL) cpu.pc =3D bfd_get_start_address (abfd); else cpu.pc =3D 0; +=20 + /* Command Line support. */ + if (argv !=3D NULL) + { + /* Counting the no. of commandline arguments. */ + for (no_of_args =3D 0; argv[no_of_args] !=3D NULL; no_of_args++) + continue; +=20 + /* Allocating memory for the argv pointers. */ + ptr_command_line =3D (char **) malloc ((sizeof (char *)) + * (no_of_args + 1)); +=20 + for (i =3D 0; i < no_of_args; i++) + { + /* Calculating the length of argument for allocating memory. */ + len_arg =3D strlen (argv[i] + 1); + ptr_command_line[i] =3D (char *) malloc (sizeof (char) * len_arg); + /* Copying the argument string. */ + ptr_command_line[i] =3D (char *) strdup (argv[i]); + } + ptr_command_line[i] =3D NULL; + } +=20=20=20 return SIM_RC_OK; } =20=20 ------_=_NextPart_000_01C2EC67.3AD32D20 Content-Type: text/plain; name="inst_h_commandline_patch.txt" Content-Transfer-Encoding: quoted-printable Content-Disposition: attachment; filename="inst_h_commandline_patch.txt" Content-length: 709 Index: inst.h =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D 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_STO= PPED }; =20=20 + /* For Command Line. */ + char **ptr_command_line; /* Pointer to Command Line Arguments. */ +=20 typedef struct { enum h8300_sim_state state; ------_=_NextPart_000_01C2EC67.3AD32D20 Content-Type: text/plain; name="Simulator_ChangeLog.txt" Content-Disposition: attachment; filename="Simulator_ChangeLog.txt" Content-length: 521 2003-03-17 D.Venkatasubramanian * 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. ------_=_NextPart_000_01C2EC67.3AD32D20--