comp.lang.ada
 help / color / mirror / Atom feed
* function at specific address
@ 2004-02-25 21:59 Szymon Guz
  2004-02-26 13:59 ` Robert I. Eachus
                   ` (2 more replies)
  0 siblings, 3 replies; 5+ messages in thread
From: Szymon Guz @ 2004-02-25 21:59 UTC (permalink / raw)


Hi,
is there a possibility to make a function that after compiling will 
point to a specific address in the memory ? And I want to set the 
address in the code.



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

* Re: function at specific address
  2004-02-25 21:59 function at specific address Szymon Guz
@ 2004-02-26 13:59 ` Robert I. Eachus
  2004-02-26 14:23 ` Frank J. Lhota
       [not found] ` <m23c8ydm5v.fsf@jvdsys.demon.nl>
  2 siblings, 0 replies; 5+ messages in thread
From: Robert I. Eachus @ 2004-02-26 13:59 UTC (permalink / raw)


Szymon Guz wrote:

> Hi,
> is there a possibility to make a function that after compiling will 
> point to a specific address in the memory ? And I want to set the 
> address in the code.

Sure.  Oh, you really wanted to know how to do it?  I'd need more 
information about what you are really trying to do, but check RM 13.3. 
You can find it on-line at 
http://www.adaic.org/standards/95lrm/html/RM-13-3.html

Other types of address manipulations are all described in chapter 13 
somewhere.

-- 
                                           Robert I. Eachus

"The only thing necessary for the triumph of evil is for good men to do 
nothing." --Edmund Burke




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

* Re: function at specific address
  2004-02-25 21:59 function at specific address Szymon Guz
  2004-02-26 13:59 ` Robert I. Eachus
@ 2004-02-26 14:23 ` Frank J. Lhota
       [not found] ` <m23c8ydm5v.fsf@jvdsys.demon.nl>
  2 siblings, 0 replies; 5+ messages in thread
From: Frank J. Lhota @ 2004-02-26 14:23 UTC (permalink / raw)


If I understand you correctly, you want your function to be loaded at an
address determined at run time. This may be possible, but it is a highly
platform-specific issue. In order to get more hlep, you will need to specify
what environment this program will be running on.

Also, it might help if we took a step back and looked at the larger picture.
There may be a way to achieve your goals other than forcing a function to be
loaded at a given address. Please provide us with more details.





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

* Re: function at specific address
       [not found] ` <m23c8ydm5v.fsf@jvdsys.demon.nl>
@ 2004-03-04  5:18   ` pburnand0-news
  2004-03-04  9:03     ` Preben Randhol
  0 siblings, 1 reply; 5+ messages in thread
From: pburnand0-news @ 2004-03-04  5:18 UTC (permalink / raw)


Jerry van Dijk wrote:

> 
> Szymon Guz <guzo@stud.ics.p.lodz.pl> writes:
> 
>> is there a possibility to make a function that after compiling will point
>> to a specific address in the memory ? And I want to set the address in
>> the code.
> 
> 
> Do you think your OS is going to allow that ?
> 

That's a good question to ask if the OS allows this...
I think this would anyway be for a specific machine with a minimal or even 
no OS at all (ie just a bootstrap for an embedded system)...


There is perhaps a first simple solution :
A so called at_clause:


proc_address : constant Address := 16#789abcde#;
procedure  foo( i: integer; j: integer; k: integer );
for foo'Address use proc_address;


procedure  foo( i: integer; j: integer; k: integer ) is
begin
  Text_IO.Put_Line( "Hello, world !" );
  Text_IO.Put( "i = " );
  Text_IO.Put( i );
  Text_IO.Newline;
  Text_IO.Put( "j = " );
  Text_IO.Put( j );
  Text_IO.Newline;
  Text_IO.Put( "k = " );
  Text_IO.Put( k );
  Text_IO.Newline;
end;






Note: the following solution has not been tested.  This is only an idea.  
You'll surely need to adapt it to your specific system...


I think it's directly possible to put a function at a precise address, but 
there should be a way of doing indirectly.

Using the SYSTEM package, you can directly poke into the computer's memory.

One solution is to make put assembler code at the address you want.  This 
assembler should them jump to your ADA procedure or function.

For a Motorola processor, you would have something like:
This code does only two thing.  Call your procedure and then return to the 
caller.
  JSR your_proc    // jump sub-routine
  RTS              // return

Once assembled this generated perhaps 8 bytes of binary code.

Then you would need to store the binary code somewhere at the adress you 
want.  You can use the SYSTEM package for this.

Then you've the procedure to call


procedure  foo( i: integer; j: integer; k: integer ) is
begin
  TEXT_IO.PUT_LINE( "Hello, world !" );
  TEXT_IO.PUT( "i = " );
  TEXT_IO.PUT( i );
  TEXT_IO.NEWLINE;
  TEXT_IO.PUT( "j = " );
  TEXT_IO.PUT( j );
  TEXT_IO.NEWLINE;
  TEXT_IO.PUT( "k = " );
  TEXT_IO.PUT( k );
  TEXT_IO.NEWLINE;
end;


Now you would need to define the constants to poke into the memory.  
(Obviously, you must be sure that this memory is not used for something 
else !)


  type byte is mod 256;

  JSR_code1 : constant byte := 16#xx#   // xx depends of CPU...
  JSR_code2 : constant byte := 16#xx#
  RTS_code1 : constant byte := 16#xx#
  RTS_code2 : constant byte := 16#xx#


  PROC_ADR : constant := 16#DEADBEEF#  // the absolute where your proc must 
reside

  Writing into the memory...  Use the SYSTEM package.

  SYSTEM. ... ( JSR_code1, PROC_ADR + 0 );
  SYSTEM. ... ( JSR_code2, PROC_ADR + 1 );
  SYSTEM. ... ( foo'Address, PROC_ADR + 2 );
  SYSTEM. ... ( RTS_code1, PROC_ADR + 4 );
  SYSTEM. ... ( RTS_code2, PROC_ADR + 5 );


Now the problem remaining is that a the JSR call adds the return address on 
the stack.  Depending of how your ADA compiler passes the parameter, you 
may need to ignore the first parameter.  The ignored parameter should have 
the same size as the address.  (I've assumed 32 bits so far).


So your procedure becomes:

procedure  foo( DUMMY_PARAM: integer; i: integer; j: integer; k: integer ) 
is
begin
...
end;

or perhaps:

procedure  foo( i: integer; j: integer; k: integer; DUMMY_PARAM: integer ) 
is
begin
...
end;

Depending in which order the parameters are put on the stack.


You should perhaps test with a procedure without parameter first...





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

* Re: function at specific address
  2004-03-04  5:18   ` pburnand0-news
@ 2004-03-04  9:03     ` Preben Randhol
  0 siblings, 0 replies; 5+ messages in thread
From: Preben Randhol @ 2004-03-04  9:03 UTC (permalink / raw)


On 2004-03-04, pburnand0-news@yahoo.com <pburnand0-news@yahoo.com> wrote:
> There is perhaps a first simple solution :
> A so called at_clause:
>
>
> proc_address : constant Address := 16#789abcde#;
> procedure  foo( i: integer; j: integer; k: integer );
> for foo'Address use proc_address;
>
>
> procedure  foo( i: integer; j: integer; k: integer ) is
> begin
>   Text_IO.Put_Line( "Hello, world !" );
>   Text_IO.Put( "i = " );
>   Text_IO.Put( i );
>   Text_IO.Newline;
>   Text_IO.Put( "j = " );
>   Text_IO.Put( j );
>   Text_IO.Newline;
>   Text_IO.Put( "k = " );
>   Text_IO.Put( k );
>   Text_IO.Newline;
> end;
>

Are you sure this works? The code has numerous bugs.

-- 
Rox-Filer; *the* file manager => http://rox.sf.net/



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

end of thread, other threads:[~2004-03-04  9:03 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2004-02-25 21:59 function at specific address Szymon Guz
2004-02-26 13:59 ` Robert I. Eachus
2004-02-26 14:23 ` Frank J. Lhota
     [not found] ` <m23c8ydm5v.fsf@jvdsys.demon.nl>
2004-03-04  5:18   ` pburnand0-news
2004-03-04  9:03     ` Preben Randhol

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