RFA: remove *_{fetch,store}_word

J.T. Conklin jtc@redback.com
Wed Jun 14 14:38:00 GMT 2000


I submit the enclosed patch for approval.  This set of patches change
the m88k BUG and i960 Nindy targets to perform memory transfers via
dcache_xfer_memory() instead of spliting the transfer into aligned
chunks and calling *_{fetch,store}_word to perform the transfer.  This
is a step in the direction of moving dcache above target memory
transfer functions.

Unfortunately, it was not possible to test the changes to these
targets.  I have high confidence in the m88k BUG target changes.  The
BUG target uses s-record up/downloads to read and write memory.  Since
these transfers have high overhead, reading and writing memory in one
chunk instead of word-sized transfer should be much faster.  I'm some-
what less confident about the Nindy change, since I was unable to find
a copy of the Nindy protocol specification or the Nindy source.  There
is nothing in the nindy-share/nindy.c code that suggests that
unaligned memory transfers are not allowed, but I would have liked to
be sure.  As I mentioned to Stan, if this is a problem, we can address
it in nindy's low level memory transfer code at that time.

        --jtc

2000-06-14  J.T. Conklin  <jtc@redback.com>

        * remote-nindy.c (nindy_fetch_word, nindy_store_word): Removed
        (nindy_xfer_inferior_memory): Use dcache_xfer_memory() instead of
        breaking transfer into chunks and using nindy_fetch_word() and
        nindy_store_word().

        * remote-bug.c (bug_xfer_memory): Use dcache_xfer_memory() instead
        of breaking transfer into chunks and using gr_fetch_word() and
        gr_store_word().

        * remote.c (remote_fetch_word, remote_store_word): Removed.

        * remote-utils.h (gr_fetch_word, gr_store_word): Removed.
        * remote-utils.c (gr_fetch_word, gr_store_word): Removed.

        * dcache.h (dcache_fetch, dcache_poke, dcache_poke_block): Removed.
        * dcache.c (dcache_fetch, dcache_poke): Removed.

Index: dcache.c
===================================================================
RCS file: /cvs/src/src/gdb/dcache.c,v
retrieving revision 1.3
diff -c -r1.3 dcache.c
*** dcache.c	2000/06/04 00:41:09	1.3
--- dcache.c	2000/06/14 21:16:29
***************
*** 378,399 ****
  }
  
  
- /* Using the data cache DCACHE return the contents of the word at
-    address ADDR in the remote machine.  */
- int
- dcache_fetch (dcache, addr)
-      DCACHE *dcache;
-      CORE_ADDR addr;
- {
-   int res;
- 
-   if (dcache_xfer_memory (dcache, addr, (char *) &res, sizeof res, 0) != sizeof res)
-     memory_error (EIO, addr);
- 
-   return res;
- }
- 
- 
  /* Write the byte at PTR into ADDR in the data cache.
     Return zero on write error.
   */
--- 378,383 ----
***************
*** 418,440 ****
    db->anydirty = 1;
    return 1;
  }
- 
- /* Write the word at ADDR both in the data cache and in the remote machine.  
-    Return zero on write error.
-  */
- 
- int
- dcache_poke (dcache, addr, data)
-      DCACHE *dcache;
-      CORE_ADDR addr;
-      int data;
- {
-   if (dcache_xfer_memory (dcache, addr, (char *) &data, sizeof data, 1) != sizeof data)
-     return 0;
- 
-   return dcache_writeback (dcache);
- }
- 
  
  /* Initialize the data cache.  */
  DCACHE *
--- 402,407 ----
Index: dcache.h
===================================================================
RCS file: /cvs/src/src/gdb/dcache.h,v
retrieving revision 1.3
diff -c -r1.3 dcache.h
*** dcache.h	2000/06/04 00:41:09	1.3
--- dcache.h	2000/06/14 21:16:30
***************
*** 27,52 ****
  
  typedef struct dcache_struct DCACHE;
  
- /* Using the data cache DCACHE return the contents of the word at
-    address ADDR in the remote machine.  */
- int dcache_fetch (DCACHE * dcache, CORE_ADDR addr);
- 
  /* Flush DCACHE. */
  void dcache_flush (DCACHE * dcache);
  
  /* Initialize DCACHE. */
  DCACHE *dcache_init (memxferfunc reading, memxferfunc writing);
  
- /* Write the word at ADDR both in the data cache and in the remote machine.  */
- int dcache_poke (DCACHE * dcache, CORE_ADDR addr, int data);
- 
  /* Simple to call from <remote>_xfer_memory */
  
  int dcache_xfer_memory (DCACHE * cache, CORE_ADDR mem, char *my, int len,
  			int should_write);
- 
- /* Write the bytes at ADDR into the data cache and the remote machine. */
- int dcache_poke_block (DCACHE * cache, CORE_ADDR mem, char *my, int len);
  
  /* Turn dcache state on or off */
  void set_dcache_state (int);
--- 27,42 ----
Index: remote-bug.c
===================================================================
RCS file: /cvs/src/src/gdb/remote-bug.c,v
retrieving revision 1.3
diff -c -r1.3 remote-bug.c
*** remote-bug.c	2000/05/28 01:12:29	1.3
--- remote-bug.c	2000/06/14 21:16:45
***************
*** 575,649 ****
       int write;
       struct target_ops *target;	/* ignored */
  {
!   register int i;
  
!   /* Round starting address down to longword boundary.  */
!   register CORE_ADDR addr;
! 
!   /* Round ending address up; get number of longwords that makes.  */
!   register int count;
! 
!   /* Allocate buffer of that many longwords.  */
!   register int *buffer;
! 
!   addr = memaddr & -sizeof (int);
!   count = (((memaddr + len) - addr) + sizeof (int) - 1) / sizeof (int);
! 
!   buffer = (int *) alloca (count * sizeof (int));
! 
!   if (write)
!     {
!       /* Fill start and end extra bytes of buffer with existing memory data.  */
! 
!       if (addr != memaddr || len < (int) sizeof (int))
! 	{
! 	  /* Need part of initial word -- fetch it.  */
! 	  buffer[0] = gr_fetch_word (addr);
! 	}
! 
!       if (count > 1)		/* FIXME, avoid if even boundary */
! 	{
! 	  buffer[count - 1]
! 	    = gr_fetch_word (addr + (count - 1) * sizeof (int));
! 	}
! 
!       /* Copy data to be written over corresponding part of buffer */
! 
!       memcpy ((char *) buffer + (memaddr & (sizeof (int) - 1)), myaddr, len);
! 
!       /* Write the entire buffer.  */
! 
!       for (i = 0; i < count; i++, addr += sizeof (int))
! 	{
! 	  errno = 0;
! 	  gr_store_word (addr, buffer[i]);
! 	  if (errno)
! 	    {
! 
! 	      return 0;
! 	    }
! 
! 	}
!     }
!   else
!     {
!       /* Read all the longwords */
!       for (i = 0; i < count; i++, addr += sizeof (int))
! 	{
! 	  errno = 0;
! 	  buffer[i] = gr_fetch_word (addr);
! 	  if (errno)
! 	    {
! 	      return 0;
! 	    }
! 	  QUIT;
! 	}
! 
!       /* Copy appropriate bytes out of the buffer.  */
!       memcpy (myaddr, (char *) buffer + (memaddr & (sizeof (int) - 1)), len);
!     }
! 
!   return len;
  }
  
  static void
--- 575,584 ----
       int write;
       struct target_ops *target;	/* ignored */
  {
!   if (len <= 0)
!     return 0;
  
!   return dcache_xfer_memory (gr_get_dcache (), memaddr, myaddr, len, write);
  }
  
  static void
Index: remote-nindy.c
===================================================================
RCS file: /cvs/src/src/gdb/remote-nindy.c,v
retrieving revision 1.3
diff -c -r1.3 remote-nindy.c
*** remote-nindy.c	2000/05/28 01:12:29	1.3
--- remote-nindy.c	2000/06/14 21:16:52
***************
*** 487,521 ****
    immediate_quit--;
  }
  
- /* Read a word from remote address ADDR and return it.
-  * This goes through the data cache.
-  */
- int
- nindy_fetch_word (addr)
-      CORE_ADDR addr;
- {
-   return dcache_fetch (nindy_dcache, addr);
- }
- 
- /* Write a word WORD into remote address ADDR.
-    This goes through the data cache.  */
- 
- void
- nindy_store_word (addr, word)
-      CORE_ADDR addr;
-      int word;
- {
-   dcache_poke (nindy_dcache, addr, word);
- }
- 
  /* Copy LEN bytes to or from inferior's memory starting at MEMADDR
     to debugger memory starting at MYADDR.   Copy to inferior if
!    WRITE is nonzero.  Returns the length copied.
  
-    This is stolen almost directly from infptrace.c's child_xfer_memory,
-    which also deals with a word-oriented memory interface.  Sometime,
-    FIXME, rewrite this to not use the word-oriented routines.  */
- 
  int
  nindy_xfer_inferior_memory (memaddr, myaddr, len, should_write, target)
       CORE_ADDR memaddr;
--- 487,496 ----
    immediate_quit--;
  }
  
  /* Copy LEN bytes to or from inferior's memory starting at MEMADDR
     to debugger memory starting at MYADDR.   Copy to inferior if
!    SHOULD_WRITE is nonzero.  Returns the length copied. */
  
  int
  nindy_xfer_inferior_memory (memaddr, myaddr, len, should_write, target)
       CORE_ADDR memaddr;
***************
*** 524,584 ****
       int should_write;
       struct target_ops *target;	/* ignored */
  {
!   register int i;
!   /* Round starting address down to longword boundary.  */
!   register CORE_ADDR addr = memaddr & -sizeof (int);
!   /* Round ending address up; get number of longwords that makes.  */
!   register int count
!   = (((memaddr + len) - addr) + sizeof (int) - 1) / sizeof (int);
!   /* Allocate buffer of that many longwords.  */
!   register int *buffer = (int *) alloca (count * sizeof (int));
! 
!   if (should_write)
!     {
!       /* Fill start and end extra bytes of buffer with existing memory data.  */
! 
!       if (addr != memaddr || len < (int) sizeof (int))
! 	{
! 	  /* Need part of initial word -- fetch it.  */
! 	  buffer[0] = nindy_fetch_word (addr);
! 	}
! 
!       if (count > 1)		/* FIXME, avoid if even boundary */
! 	{
! 	  buffer[count - 1]
! 	    = nindy_fetch_word (addr + (count - 1) * sizeof (int));
! 	}
! 
!       /* Copy data to be written over corresponding part of buffer */
! 
!       memcpy ((char *) buffer + (memaddr & (sizeof (int) - 1)), myaddr, len);
! 
!       /* Write the entire buffer.  */
! 
!       for (i = 0; i < count; i++, addr += sizeof (int))
! 	{
! 	  errno = 0;
! 	  nindy_store_word (addr, buffer[i]);
! 	  if (errno)
! 	    return 0;
! 	}
!     }
!   else
!     {
!       /* Read all the longwords */
!       for (i = 0; i < count; i++, addr += sizeof (int))
! 	{
! 	  errno = 0;
! 	  buffer[i] = nindy_fetch_word (addr);
! 	  if (errno)
! 	    return 0;
! 	  QUIT;
! 	}
! 
!       /* Copy appropriate bytes out of the buffer.  */
!       memcpy (myaddr, (char *) buffer + (memaddr & (sizeof (int) - 1)), len);
!     }
!   return len;
  }
  
  static void
--- 499,508 ----
       int should_write;
       struct target_ops *target;	/* ignored */
  {
!   if (len <= 0)
!     return 0;
!   return dcache_xfer_memory (nindy_dcache, memaddr, myaddr, 
! 			     len, should_write);
  }
  
  static void
Index: remote-utils.c
===================================================================
RCS file: /cvs/src/src/gdb/remote-utils.c,v
retrieving revision 1.2
diff -c -r1.2 remote-utils.c
*** remote-utils.c	2000/05/28 01:12:29	1.2
--- remote-utils.c	2000/06/14 21:16:58
***************
*** 618,644 ****
    /* Do nothing, since we assume we can store individual regs */
  }
  
- /* Read a word from remote address ADDR and return it.
-  * This goes through the data cache.
-  */
- int
- gr_fetch_word (addr)
-      CORE_ADDR addr;
- {
-   return dcache_fetch (gr_get_dcache (), addr);
- }
- 
- /* Write a word WORD into remote address ADDR.
-    This goes through the data cache.  */
- 
- void
- gr_store_word (addr, word)
-      CORE_ADDR addr;
-      int word;
- {
-   dcache_poke (gr_get_dcache (), addr, word);
- }
- 
  void
  _initialize_sr_support ()
  {
--- 618,623 ----
Index: remote-utils.h
===================================================================
RCS file: /cvs/src/src/gdb/remote-utils.h,v
retrieving revision 1.3
diff -c -r1.3 remote-utils.h
*** remote-utils.h	2000/06/04 00:41:09	1.3
--- remote-utils.h	2000/06/14 21:16:58
***************
*** 117,123 ****
  
  #define gr_expect_prompt()	sr_expect(gr_get_prompt())
  
- int gr_fetch_word (CORE_ADDR addr);
  int gr_multi_scan (char *list[], int passthrough);
  int sr_get_hex_digit (int ignore_space);
  int sr_pollchar (void);
--- 117,122 ----
***************
*** 132,138 ****
  void gr_kill (void);
  void gr_mourn (void);
  void gr_prepare_to_store (void);
- void gr_store_word (CORE_ADDR addr, int word);
  void sr_expect (char *string);
  void sr_get_hex_byte (char *byt);
  void sr_scan_args (char *proto, char *args);
--- 131,136 ----
Index: remote.c
===================================================================
RCS file: /cvs/src/src/gdb/remote.c,v
retrieving revision 1.14
diff -c -r1.14 remote.c
*** remote.c	2000/06/12 01:33:49	1.14
--- remote.c	2000/06/14 21:18:12
***************
*** 3209,3248 ****
  
    remote_send (buf, PBUFSIZ);
  }
- 
- /* Use of the data cache *used* to be disabled because it loses for looking
-    at and changing hardware I/O ports and the like.  Accepting `volatile'
-    would perhaps be one way to fix it.  Another idea would be to use the
-    executable file for the text segment (for all SEC_CODE sections?
-    For all SEC_READONLY sections?).  This has problems if you want to
-    actually see what the memory contains (e.g. self-modifying code,
-    clobbered memory, user downloaded the wrong thing).  
- 
-    Because it speeds so much up, it's now enabled, if you're playing
-    with registers you turn it of (set remotecache 0).  */
- 
- /* Read a word from remote address ADDR and return it.
-    This goes through the data cache.  */
- 
- #if 0				/* unused? */
- static int
- remote_fetch_word (addr)
-      CORE_ADDR addr;
- {
-   return dcache_fetch (remote_dcache, addr);
- }
- 
- /* Write a word WORD into remote address ADDR.
-    This goes through the data cache.  */
- 
- static void
- remote_store_word (addr, word)
-      CORE_ADDR addr;
-      int word;
- {
-   dcache_poke (remote_dcache, addr, word);
- }
- #endif /* 0 (unused?) */
  
  
  
--- 3209,3214 ----


-- 
J.T. Conklin
RedBack Networks


More information about the Gdb-patches mailing list