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]

[commit:sim/ppc] Remove hardwired reg size


Hello,

This patch addresses two problems in the PSIM <-> gdb inerface:

- hardwired buffer size
- better handling of unknown registers


committed, Andrew
2003-06-20  Andrew Cagney  <cagney@redhat.com>

	* sim_calls.c (sim_create_inferior): Assert that
	psim_write_register succeeded.
	(sim_fetch_register, sim_store_register): Make "regname" constant.
	Delete Altivec hack.  Return result from psim_read_register /
	psim_write_register.
	* psim.h (psim_read_register, psim_write_register): Change return
	type to int.  Update comments.
	* psim.c: Update copyright.
	(psim_stack): Assert that the psim_read_register worked.
	(psim_read_register, psim_read_register): Return the register's
	size.  Allocate the cooked buffer dynamically.
	* hw_register.c: Update copyright.
	(do_register_init): Check that psim_write_register succeeded.
	* hw_init.c: Update copyright.
	(create_ppc_elf_stack_frame, create_ppc_aix_stack_frame): Assert
	that the register transfer worked.

Index: hw_init.c
===================================================================
RCS file: /cvs/src/src/sim/ppc/hw_init.c,v
retrieving revision 1.2
diff -u -r1.2 hw_init.c
--- hw_init.c	10 May 2001 17:48:10 -0000	1.2
+++ hw_init.c	20 Jun 2003 13:24:54 -0000
@@ -1,6 +1,6 @@
 /*  This file is part of the program psim.
     
-    Copyright (C) 1994-1997, Andrew Cagney <cagney@highland.com.au>
+    Copyright 1994, 1997, 2003 Andrew Cagney
     
     This program is free software; you can redistribute it and/or modify
     it under the terms of the GNU General Public License as published by
@@ -591,16 +591,16 @@
 			start_argv, start_envp);
 
   /* set up the registers */
-  psim_write_register(device_system(me), -1,
-		      &top_of_stack, "sp", cooked_transfer);
-  psim_write_register(device_system(me), -1,
-		      &argc, "r3", cooked_transfer);
-  psim_write_register(device_system(me), -1,
-		      &start_argv, "r4", cooked_transfer);
-  psim_write_register(device_system(me), -1,
-		      &start_envp, "r5", cooked_transfer);
-  psim_write_register(device_system(me), -1,
-		      &start_aux, "r6", cooked_transfer);
+  ASSERT (psim_write_register(device_system(me), -1,
+			      &top_of_stack, "sp", cooked_transfer) > 0);
+  ASSERT (psim_write_register(device_system(me), -1,
+			      &argc, "r3", cooked_transfer) > 0);
+  ASSERT (psim_write_register(device_system(me), -1,
+			      &start_argv, "r4", cooked_transfer) > 0);
+  ASSERT (psim_write_register(device_system(me), -1,
+			      &start_envp, "r5", cooked_transfer) > 0);
+  ASSERT (psim_write_register(device_system(me), -1,
+			      &start_aux, "r6", cooked_transfer) > 0);
 }
 
 static void
@@ -619,16 +619,16 @@
   create_ppc_elf_stack_frame(me, bottom_of_stack, argv, envp);
   
   /* extract argument addresses from registers */
-  psim_read_register(device_system(me), 0,
-		     &top_of_stack, "r1", cooked_transfer);
-  psim_read_register(device_system(me), 0,
-		     &core_argc, "r3", cooked_transfer);
-  psim_read_register(device_system(me), 0,
-		     &core_argv, "r4", cooked_transfer);
-  psim_read_register(device_system(me), 0,
-		     &core_envp, "r5", cooked_transfer);
-  psim_read_register(device_system(me), 0,
-		     &core_aux, "r6", cooked_transfer);
+  ASSERT (psim_read_register(device_system(me), 0,
+			     &top_of_stack, "r1", cooked_transfer) > 0);
+  ASSERT (psim_read_register(device_system(me), 0,
+			     &core_argc, "r3", cooked_transfer) > 0);
+  ASSERT (psim_read_register(device_system(me), 0,
+			     &core_argv, "r4", cooked_transfer) > 0);
+  ASSERT (psim_read_register(device_system(me), 0,
+			     &core_envp, "r5", cooked_transfer) > 0);
+  ASSERT (psim_read_register(device_system(me), 0,
+			     &core_aux, "r6", cooked_transfer) > 0);
 
   /* extract arguments from registers */
   device_error(me, "Unfinished procedure create_ppc_aix_stack_frame\n");
Index: hw_register.c
===================================================================
RCS file: /cvs/src/src/sim/ppc/hw_register.c,v
retrieving revision 1.1.1.1
diff -u -r1.1.1.1 hw_register.c
--- hw_register.c	16 Apr 1999 01:35:09 -0000	1.1.1.1
+++ hw_register.c	20 Jun 2003 13:24:54 -0000
@@ -1,6 +1,6 @@
 /*  This file is part of the program psim.
     
-    Copyright (C) 1994-1996, Andrew Cagney <cagney@highland.com.au>
+    Copyright 1994, 1995, 1996, 2003 Andrew Cagney
     
     This program is free software; you can redistribute it and/or modify
     it under the terms of the GNU General Public License as published by
@@ -98,10 +98,11 @@
       DTRACE(register, ("%d.%s=0x%lx\n", processor, name,
 			(unsigned long)value));
     }    
-    psim_write_register(system, processor, /* all processors */
-			&value,
-			name,
-			cooked_transfer);
+    if (psim_write_register(system, processor, /* all processors */
+			    &value,
+			    name,
+			    cooked_transfer) <= 0)
+      error("Invalid register name %s\n", name);
   }
 }
 		 
Index: psim.c
===================================================================
RCS file: /cvs/src/src/sim/ppc/psim.c,v
retrieving revision 1.2
diff -u -r1.2 psim.c
--- psim.c	17 Jun 2002 19:58:39 -0000	1.2
+++ psim.c	20 Jun 2003 13:24:54 -0000
@@ -1,6 +1,6 @@
 /*  This file is part of the program psim.
 
-    Copyright (C) 1994-1997, Andrew Cagney <cagney@highland.com.au>
+    Copyright 1994, 1995, 1996, 1997, 2003 Andrew Cagney
 
     This program is free software; you can redistribute it and/or modify
     it under the terms of the GNU General Public License as published by
@@ -729,7 +729,8 @@
 					  "/openprom/init/stack");
   if (stack_device != (device*)0) {
     unsigned_word stack_pointer;
-    psim_read_register(system, 0, &stack_pointer, "sp", cooked_transfer);
+    ASSERT (psim_read_register(system, 0, &stack_pointer, "sp",
+			       cooked_transfer) > 0);
     device_ioctl(stack_device,
 		 NULL, /*cpu*/
 		 0, /*cia*/
@@ -766,7 +767,7 @@
 /* storage manipulation functions */
 
 INLINE_PSIM\
-(void)
+(int)
 psim_read_register(psim *system,
 		   int which_cpu,
 		   void *buf,
@@ -774,7 +775,7 @@
 		   transfer_mode mode)
 {
   register_descriptions description;
-  char cooked_buf[sizeof(unsigned_8)];
+  char *cooked_buf;
   cpu *processor;
 
   /* find our processor */
@@ -792,7 +793,8 @@
   /* find the register description */
   description = register_description(reg);
   if (description.type == reg_invalid)
-    error("psim_read_register() invalid register name `%s'\n", reg);
+    return 0;
+  cooked_buf = alloca (description.size);
 
   /* get the cooked value */
   switch (description.type) {
@@ -877,12 +879,13 @@
     memcpy(buf/*dest*/, cooked_buf/*src*/, description.size);
   }
 
+  return description.size;
 }
 
 
 
 INLINE_PSIM\
-(void)
+(int)
 psim_write_register(psim *system,
 		    int which_cpu,
 		    const void *buf,
@@ -891,7 +894,7 @@
 {
   cpu *processor;
   register_descriptions description;
-  char cooked_buf[sizeof(unsigned_8)];
+  char *cooked_buf;
 
   /* find our processor */
   if (which_cpu == MAX_NR_PROCESSORS) {
@@ -901,21 +904,23 @@
     else
       which_cpu = system->last_cpu;
   }
+
+  /* find the description of the register */
+  description = register_description(reg);
+  if (description.type == reg_invalid)
+    return 0;
+  cooked_buf = alloca (description.size);
+
   if (which_cpu == -1) {
     int i;
     for (i = 0; i < system->nr_cpus; i++)
       psim_write_register(system, i, buf, reg, mode);
-    return;
+    return description.size;
   }
   ASSERT(which_cpu >= 0 && which_cpu < system->nr_cpus);
 
   processor = system->processors[which_cpu];
 
-  /* find the description of the register */
-  description = register_description(reg);
-  if (description.type == reg_invalid)
-    error("psim_write_register() invalid register name %s\n", reg);
-
   /* If the data is comming in raw (target order), need to cook it
      into host order before putting it into PSIM's internal structures */
   if (mode == raw_transfer) {
@@ -981,6 +986,7 @@
 
   }
 
+  return description.size;
 }
 
 
Index: psim.h
===================================================================
RCS file: /cvs/src/src/sim/ppc/psim.h,v
retrieving revision 1.1.1.1
diff -u -r1.1.1.1 psim.h
--- psim.h	16 Apr 1999 01:35:11 -0000	1.1.1.1
+++ psim.h	20 Jun 2003 13:24:54 -0000
@@ -138,21 +138,24 @@
  
 
 
-/* manipulate the state (registers or memory) of a processor within
+/* Manipulate the state (registers or memory) of a processor within
    the system.  In the case of memory, the read/write is performed
    using the specified processors address translation tables.
 
    Where applicable, WHICH_CPU == -1 indicates all processors and
-   WHICH_CPU == <nr_cpus> indicates the `current' processor. */
+   WHICH_CPU == <nr_cpus> indicates the `current' processor.
 
-extern void psim_read_register
+   The register functions return the size of the register, or 0 if the
+   register's name is not recognized.  */
+
+extern int psim_read_register
 (psim *system,
  int which_cpu,
  void *host_ordered_buf,
  const char reg[],
  transfer_mode mode);
 
-extern void psim_write_register
+extern int psim_write_register
 (psim *system,
  int which_cpu,
  const void *buf,
Index: sim_calls.c
===================================================================
RCS file: /cvs/src/src/sim/ppc/sim_calls.c,v
retrieving revision 1.6
diff -u -r1.6 sim_calls.c
--- sim_calls.c	27 Feb 2003 23:26:34 -0000	1.6
+++ sim_calls.c	20 Jun 2003 13:24:58 -0000
@@ -1,6 +1,6 @@
 /*  This file is part of the program psim.
 
-    Copyright (C) 1994-1996,1998, Andrew Cagney <cagney@highland.com.au>
+    Copyright 1994, 1995, 1996, 1998, 2003 Andrew Cagney
 
     This program is free software; you can redistribute it and/or modify
     it under the terms of the GNU General Public License as published by
@@ -180,7 +180,7 @@
 int
 sim_fetch_register (SIM_DESC sd, int regno, unsigned char *buf, int length)
 {
-  char *regname;
+  const char *regname;
 
   if (simulator == NULL) {
     return 0;
@@ -194,43 +194,33 @@
      But there are loops that just walk through the entire list of
      names and try to get everything.  */
   regname = gdbarch_register_name (current_gdbarch, regno);
-  /* FIXME: ezannoni 2002/04/15 Remove the 'vr' and 'vscr' check
-     once AltiVec support is committed.  */
-  if (! regname || regname[0] == '\0'
-      || (regname[0] == 'v' && regname[1] == 'r')
-      || (strcmp (regname, "vscr") == 0))
+  if (! regname || regname[0] == '\0')
     return -1;
 
   TRACE(trace_gdb, ("sim_fetch_register(regno=%d(%s), buf=0x%lx)\n",
 		    regno, regname, (long)buf));
-  psim_read_register(simulator, MAX_NR_PROCESSORS,
-		     buf, regname, raw_transfer);
-  return -1;
+  return psim_read_register(simulator, MAX_NR_PROCESSORS,
+			    buf, regname, raw_transfer);
 }
 
 
 int
 sim_store_register (SIM_DESC sd, int regno, unsigned char *buf, int length)
 {
-  char *regname;
+  const char *regname;
 
   if (simulator == NULL)
     return 0;
 
   /* See comments in sim_fetch_register, above.  */
   regname = gdbarch_register_name (current_gdbarch, regno);
-  /* FIXME: ezannoni 2002/04/15 Remove the 'vr' and 'vscr' check
-     once AltiVec support is committed.  */
-  if (! regname || regname[0] == '\0'
-      || (regname[0] == 'v' && regname[1] == 'r')
-      || (strcmp (regname, "vscr") == 0))
+  if (! regname || regname[0] == '\0')
     return -1;
 
   TRACE(trace_gdb, ("sim_store_register(regno=%d(%s), buf=0x%lx)\n",
 		    regno, regname, (long)buf));
-  psim_write_register(simulator, MAX_NR_PROCESSORS,
-		      buf, regname, raw_transfer);
-  return -1;
+  return psim_write_register(simulator, MAX_NR_PROCESSORS,
+			     buf, regname, raw_transfer);
 }
 
 
@@ -263,8 +253,8 @@
   psim_init(simulator);
   psim_stack(simulator, argv, envp);
 
-  psim_write_register(simulator, -1 /* all start at same PC */,
-		      &entry_point, "pc", cooked_transfer);
+  ASSERT (psim_write_register(simulator, -1 /* all start at same PC */,
+			      &entry_point, "pc", cooked_transfer) > 0);
   return SIM_RC_OK;
 }
 

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