comp.lang.ada
 help / color / mirror / Atom feed
From: John_J_Cupak@raytheon.com (John Cupak)
Subject: Help with Copying Shared Memory to Local
Date: 23 May 2002 06:50:11 -0700
Date: 2002-05-23T13:50:11+00:00	[thread overview]
Message-ID: <c7990eda.0205230550.203d300a@posting.google.com> (raw)

A colleague asked me to help him solve an memory copy problem.

The source memory location is in a "shared" area, and the
destination memory location is "local" to the application.

The original code, written in Ada83, works by copying two bytes
at a time. Evidently, the hardware crashes if they try to access
a single byte.

Here's the Ada 95 version of the original Ada83 code:

-- Assumed visibility of Project_Types
procedure Copy_Double_Byte(Destination : in System.Address;
                           Source      : in System.Address;
                           Length      : in Natural) is
   
  Destination_Pointer : Project_Types.Double_Byte_Pointer;
  Source_Pointer      : Project_Types.Double_Byte_Pointer;
   
begin -- Copy_Double_Byte
   
  -- Ensure source address in correct range
  if Source >= System.Addresses.Logical_Address(Project_Types.Virtual_Base_Address)
and
  Source < System.Addresses.Logical_Address(Project_Types.Virtual_Base_Address
+ 16#200_000#) then
      
     -- Must reference memory on double byte boundry
     -- The number of bytes to copy is specified by the Length
parameter
     for Index in 0..(Length/2) - 1 loop
         
        -- Create source and destination pointers from base address
plus double byte offsets
        Destination_Pointer := Project_Types.To_Double_Byte_Pointer(
                                
System.Deprecated.Incr_Addr(Destination, Index * 2));
        Source_Pointer      := Project_Types.To_Double_Byte_Pointer(
                                 System.Deprecated.Incr_Addr(Source,  
   Index * 2));
         
        -- Copy contents
        Destination_Pointer.all := Source_Pointer.all;
         
     end loop;
      
  end if; -- Source check
   
end Copy_Double_Byte;

I found a 1997 reference in this newsgroup (comp.lang.ada) to a
similar problem entitled
"Q: How to do memory access with gnat" from Michael Erdman
(boavista@berlin.snafu.de)
with references to the Ada95 System.Address_To_Access_Conversions
child package and
the System.Storage_Elements child package.

So, before I go off and write up a new version of the "memory copy"
procedure using
these two child packages, has anyone ever implemented such a solution
that would be
willing to share?

Comments and recommendations always appreciated.

John Cupak



             reply	other threads:[~2002-05-23 13:50 UTC|newest]

Thread overview: 18+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2002-05-23 13:50 John Cupak [this message]
2002-05-23 20:32 ` Help with Copying Shared Memory to Local Jeffrey Carter
2002-05-23 21:18   ` John Cupak
2002-05-24  1:37     ` Randy Brukardt
2002-05-24  2:08       ` Jeffrey Carter
2002-05-24 17:05         ` John R. Strohm
2002-05-24 16:55           ` Stephen Leake
2002-05-24 20:43             ` John R. Strohm
2002-05-24 19:49               ` Pat Rogers
2002-05-24 23:23                 ` martin.m.dowie
2002-05-24 20:54               ` Stephen Leake
2002-05-24 19:41           ` Jeffrey Carter
2002-05-26  0:55           ` John Cupak
2002-05-28 17:52             ` John Cupak
2002-05-25 11:23   ` Robert Dewar
2002-05-26  4:48     ` Jeffrey Carter
  -- strict thread matches above, loose matches on Subject: below --
2002-05-24 14:22 Beard, Frank [Contractor]
2002-05-24 19:30 ` Jeffrey Carter
replies disabled

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