comp.lang.ada
 help / color / mirror / Atom feed
* Re: Q: How to do memory access with gnat
  1997-07-20  0:00 Q: How to do memory access with gnat Michael Erdmann
  1997-07-20  0:00 ` Samuel Tardieu
@ 1997-07-20  0:00 ` Tucker Taft
  1997-07-20  0:00   ` Q: How to do memory access with gnat - OS.ADS (1/1) Michael Erdmann
                     ` (2 more replies)
  1997-07-22  0:00 ` Q: How to do memory access with gnat Michael Erdmann
  2 siblings, 3 replies; 8+ messages in thread
From: Tucker Taft @ 1997-07-20  0:00 UTC (permalink / raw)



Michael Erdmann (boavista@berlin.snafu.de) wrote:

: i like to do something like this in Ada95  (excuse the C-example):

: 	typedef struct  {  ..,other_data;   char data[1];  }  Msg_data; 
: 	Msg_Data	*shared;

: 	// get some memory from the system
: 	DosGetSharedMemory( ..., &shared... )

: 	// copy data into shared memory 
: 	for( i ,,,, )
: 	   shared->data[i] := some_data[i];

: In  Ada95  i am not able to copy data from an Ada object into a some external
: memory.
: Any idea ?

You can use an address clause to associate an Ada name with a given
address.  E.g.:
    Shared : Msg_Data;
    for Shared'Address use <arbitrary computation>;
  begin
    Shared.data(I) := ...

Alternatively, the most direct analogy to the C approach is to declare
an access type, and initialize a variable of the type using 
unchecked_conversion or the Address_To_Access_Conversion generic, or by
passing its 'Address to some external routine.

    type Msg_Data_Ptr is access all Msg_Data;
    Shared : Msg_Data_Ptr;

  begin
    DosGetSharedMemory(..., Shared'Address, ...);
    Shared.data(I) := ...

--
-Tucker Taft   stt@inmet.com   http://www.inmet.com/~stt/
Intermetrics, Inc.  Burlington, MA  USA




^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: Q: How to do memory access with gnat
  1997-07-20  0:00 Q: How to do memory access with gnat Michael Erdmann
@ 1997-07-20  0:00 ` Samuel Tardieu
  1997-07-20  0:00   ` Michael Erdmann
  1997-07-20  0:00 ` Tucker Taft
  1997-07-22  0:00 ` Q: How to do memory access with gnat Michael Erdmann
  2 siblings, 1 reply; 8+ messages in thread
From: Samuel Tardieu @ 1997-07-20  0:00 UTC (permalink / raw)
  To: Michael Erdmann


>>>>> "Michael" == Michael Erdmann <boavista@berlin.snafu.de> writes:

Michael> In Ada95 i am not able to copy data from an Ada object into a
Michael> some external memory.  Any idea ?

You should try using the predefined generic package
System.Address_To_Access_Conversions. Then given a variable of type
System.Address, you can obtain an access value on your shared data.

Pseudo example:

with Dos_Utils;
with System.Address_To_Access_Conversions;

procedure Test is

   type My_Data is record
      [...]
   end record;

   package A_To_A is new System.Address_To_Access_Conversions (My_Data);
   subtype My_Data_Access is A_To_A.Object_Pointer;
   
   Addr : System.Address;
   Data : My_Data_Access;

begin
   Addr := Dos_Utils.Get_Shared_Memory (Data'Size / 8);
   Data := A_To_A.To_Pointer (Addr);
   [...you can use Data, it is pointing on an object stored in shared mem...]
end Test;

  Sam
-- 
Samuel Tardieu -- sam@ada.eu.org




^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: Q: How to do memory access with gnat
  1997-07-20  0:00 ` Samuel Tardieu
@ 1997-07-20  0:00   ` Michael Erdmann
  0 siblings, 0 replies; 8+ messages in thread
From: Michael Erdmann @ 1997-07-20  0:00 UTC (permalink / raw)



On 20 Jul 1997 15:10:11 +0200, Samuel Tardieu wrote:

:>>>>>> "Michael" == Michael Erdmann <boavista@berlin.snafu.de> writes:
:>
:>Michael> In Ada95 i am not able to copy data from an Ada object into a
:>Michael> some external memory.  Any idea ?
:>

:>You should try using the predefined generic package
:>System.Address_To_Access_Conversions. Then given a variable of type
:>System.Address, you can obtain an access value on your shared data.
The data structure to be stored in the shared stat looks like this,

type Message_Record( Record_Size : Integer ) is record
         Nbr_Of_Bytes     : Integer := Record_Size;
         data             :  Data_Buffer( 1,,Record_Size);
end record;

My Problem is to address the data array correctly. It seems because 
it is not managed under Ada memory management it is not possible
to do the following:

	To_Message(share),data(1,,Nbr_Of_Bytes) := data(1... )

I get allways a constraint error. In order to avoid this i thought about a 
procedure which is intended to set the shared memory  at a offset
relative to a certain base address. The result is this:

   procedure Store_At( base : Address ; offset : Integer ; value:BYTE ) is
      package BYTE_Access is new System.Address_To_Access_Conversions(
                                 Object => BYTE );
      use BYTE_Access;
   begin
      BYTE_Access.To_Pointer(base+offset).all := value;
   end Store_At;

But is does not work, because i am not able to add the offset to the base.

Michael








^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: Q: How to do memory access with gnat - os.ADB (0/1)
  1997-07-20  0:00 ` Tucker Taft
  1997-07-20  0:00   ` Q: How to do memory access with gnat - OS.ADS (1/1) Michael Erdmann
  1997-07-20  0:00   ` Q: How to do memory access with gnat - OS.ADS (0/1) Michael Erdmann
@ 1997-07-20  0:00   ` Michael Erdmann
  2 siblings, 0 replies; 8+ messages in thread
From: Michael Erdmann @ 1997-07-20  0:00 UTC (permalink / raw)



On Sun, 20 Jul 1997 13:07:26 GMT, Tucker Taft wrote:

:>Michael Erdmann (boavista@berlin.snafu.de) wrote:
::>
:>You can use an address clause to associate an Ada name with a given
:>address.  E.g.:
:>    Shared : Msg_Data;
:>    for Shared'Address use <arbitrary computation>;
:>  begin
:>    Shared.data(I) := ...
The important point is this assignment here. The example is from a simple
message 
passing system where the size of the data array message is not known. 
The message record is defined like this:

	 type Message_Record( Record_Size : Integer ) is record
        	    Nbr_Of_Bytes		: Integer := Record_Size;
         	   data			: DataBuffer(1..Record_Size);
      	end record;

The Problem is when i am doing it like this;

	RC := DosAllocateShared( .... shared_data )
	Msg := To_Message( shared_data );	-- convert to access to
Message_Record
	Msg.Nbr_Of_Bytes := ,,,,,;
	Msg.data(1,,Nbr_Of_Bytes) := data(1....)

a contraint error is generated in the last assignment.
:>
:>Alternatively, the most direct analogy to the C approach is to declare
:>an access type, and initialize a variable of the type using 
:>unchecked_conversion or the Address_To_Access_Conversion generic, 

I have done this. In order to by pass the problem with the array above i
thought about
a procedure which would allow to store data relative to a base address. The
problem 
is i am not able to add an integer offset to an address, because it is not
possible
to convert  from Integer to Stoarge_Offset from System.Storage_Elements.

>or by
:>passing its 'Address to some external routine.

I hope i dont need to do it!







^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: Q: How to do memory access with gnat - OS.ADS (0/1)
  1997-07-20  0:00 ` Tucker Taft
  1997-07-20  0:00   ` Q: How to do memory access with gnat - OS.ADS (1/1) Michael Erdmann
@ 1997-07-20  0:00   ` Michael Erdmann
  1997-07-20  0:00   ` Q: How to do memory access with gnat - os.ADB (0/1) Michael Erdmann
  2 siblings, 0 replies; 8+ messages in thread
From: Michael Erdmann @ 1997-07-20  0:00 UTC (permalink / raw)



On Sun, 20 Jul 1997 13:07:26 GMT, Tucker Taft wrote:

:>Michael Erdmann (boavista@berlin.snafu.de) wrote:
::>
:>You can use an address clause to associate an Ada name with a given
:>address.  E.g.:
:>    Shared : Msg_Data;
:>    for Shared'Address use <arbitrary computation>;
:>  begin
:>    Shared.data(I) := ...
The important point is this assignment here. The example is from a simple
message 
passing system where the size of the data array message is not known. 
The message record is defined like this:

	 type Message_Record( Record_Size : Integer ) is record
        	    Nbr_Of_Bytes		: Integer := Record_Size;
         	   data			: DataBuffer(1..Record_Size);
      	end record;

The Problem is when i am doing it like this;

	RC := DosAllocateShared( .... shared_data )
	Msg := To_Message( shared_data );	-- convert to access to
Message_Record
	Msg.Nbr_Of_Bytes := ,,,,,;
	Msg.data(1,,Nbr_Of_Bytes) := data(1....)

a contraint error is generated in the last assignment.
:>
:>Alternatively, the most direct analogy to the C approach is to declare
:>an access type, and initialize a variable of the type using 
:>unchecked_conversion or the Address_To_Access_Conversion generic, 

I have done this. In order to by pass the problem with the array above i
thought about
a procedure which would allow to store data relative to a base address. The
problem 
is i am not able to add an integer offset to an address, because it is not
possible
to convert  from Integer to Stoarge_Offset from System.Storage_Elements.

>or by
:>passing its 'Address to some external routine.

I hope i dont need to do it!







^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: Q: How to do memory access with gnat - OS.ADS (1/1)
  1997-07-20  0:00 ` Tucker Taft
@ 1997-07-20  0:00   ` Michael Erdmann
  1997-07-20  0:00   ` Q: How to do memory access with gnat - OS.ADS (0/1) Michael Erdmann
  1997-07-20  0:00   ` Q: How to do memory access with gnat - os.ADB (0/1) Michael Erdmann
  2 siblings, 0 replies; 8+ messages in thread
From: Michael Erdmann @ 1997-07-20  0:00 UTC (permalink / raw)



d2l0aCBPUzI7ICAgICAgICAgICAgICAgdXNlIE9TMjsNCndpdGggU3lzdGVtOyAgICAgICAgICAg
IHVzZSBTeXN0ZW07DQoNCnBhY2thZ2UgT1MgaXMNCg0KICAgdHlwZSBEYXRhX1JlY29yZCBpcyBh
cnJheSggUG9zaXRpdmUgcmFuZ2UgPD4gKSBvZiBCWVRFOw0KDQogICB0eXBlIE1lc3NhZ2VfUmVj
b3JkKCBSZWNvcmRfU2l6ZSA6IEludGVnZXIgKSBpcyByZWNvcmQNCiAgICAgICAgIE5icl9PZl9C
eXRlcyAgICAgOiBJbnRlZ2VyIDo9IFJlY29yZF9TaXplOw0KICAgICAgICAgZGF0YSAgICAgICAg
ICAgICA6IEJZVEU7DQogICAgICBlbmQgcmVjb3JkOw0KDQogICB0eXBlIE1lc3NhZ2UgaXMgYWNj
ZXNzIGFsbCBNZXNzYWdlX1JlY29yZDsNCg0KDQogICB0eXBlIERhdGFfQnVmZmVyIGlzIGFjY2Vz
cyBhbGwgRGF0YV9SZWNvcmQ7DQoNCiAgIHByb2NlZHVyZSBNYWluX0RyaXZlciggUV9OYW1lIDog
U3RyaW5nICk7DQogICBwcm9jZWR1cmUgU2VuZCggUV9OYW1lIDogU3RyaW5nOyBkYXRhIDogRGF0
YV9CdWZmZXIgKTsNCg0KZW5kIE9TOw0K






^ permalink raw reply	[flat|nested] 8+ messages in thread

* Q: How to do memory access with gnat
@ 1997-07-20  0:00 Michael Erdmann
  1997-07-20  0:00 ` Samuel Tardieu
                   ` (2 more replies)
  0 siblings, 3 replies; 8+ messages in thread
From: Michael Erdmann @ 1997-07-20  0:00 UTC (permalink / raw)



Hi

i like to do something like this in Ada95  (excuse the C-example):

	typedef struct  {  ..,other_data;   char data[1];  }  Msg_data; 
	Msg_Data	*shared;

	// get some memory from the system
	DosGetSharedMemory( ..., &shared... )

	// copy data into shared memory 
	for( i ,,,, )
	   shared->data[i] := some_data[i];

In  Ada95  i am not able to copy data from an Ada object into a some external
memory.
Any idea ?
 






^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: Q: How to do memory access with gnat
  1997-07-20  0:00 Q: How to do memory access with gnat Michael Erdmann
  1997-07-20  0:00 ` Samuel Tardieu
  1997-07-20  0:00 ` Tucker Taft
@ 1997-07-22  0:00 ` Michael Erdmann
  2 siblings, 0 replies; 8+ messages in thread
From: Michael Erdmann @ 1997-07-22  0:00 UTC (permalink / raw)



On Sun, 20 Jul 97 14:37:05, Michael Erdmann wrote:

:>Hi
:>
:>i like to do something like this in Ada95  (excuse the C-example):
:>
:>	typedef struct  {  ..,other_data;   char data[1];  }  Msg_data; 
:>	Msg_Data	*shared;
:>
:>	// get some memory from the system
:>	DosGetSharedMemory( ..., &shared... )
:>
:>	// copy data into shared memory 
:>	for( i ,,,, )
:>	   shared->data[i] := some_data[i];
:>
:>In  Ada95  i am not able to copy data from an Ada object into a some external
:>memory.
:>Any idea ?
:> 
:>
:>
If some body is interested how i managed to solve the Problem here is my
solution but i dont know if it works for all processor types:

with System;                    use System;
with System.Storage_Elements;   use System.Storage_Elements;
with System.Address_To_Access_Conversions;
with Unchecked_Conversion;


   function TO_Storage_Offset is new 
        Unchecked_Conversion(Source => Integer, Target=>Storage_Offset);

   package BYTE_Access is new System.Address_To_Access_Conversions( BYTE );

   procedure Store_Byte( base : Address ; offset : Integer ; value:BYTE ) is
   begin
      BYTE_Access.To_Pointer(base+TO_Storage_Offset(offset) ).all := value;
   end Store_Byte;

   function Get_Byte( base: Address; offset : Integer ) return BYTE is
   begin
      return BYTE_Access.To_Pointer(base+TO_Storage_Offset(offset)).all;
   end Get_Byte;








^ permalink raw reply	[flat|nested] 8+ messages in thread

end of thread, other threads:[~1997-07-22  0:00 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
1997-07-20  0:00 Q: How to do memory access with gnat Michael Erdmann
1997-07-20  0:00 ` Samuel Tardieu
1997-07-20  0:00   ` Michael Erdmann
1997-07-20  0:00 ` Tucker Taft
1997-07-20  0:00   ` Q: How to do memory access with gnat - OS.ADS (1/1) Michael Erdmann
1997-07-20  0:00   ` Q: How to do memory access with gnat - OS.ADS (0/1) Michael Erdmann
1997-07-20  0:00   ` Q: How to do memory access with gnat - os.ADB (0/1) Michael Erdmann
1997-07-22  0:00 ` Q: How to do memory access with gnat Michael Erdmann

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