From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on polar.synack.me X-Spam-Level: X-Spam-Status: No, score=-0.3 required=5.0 tests=BAYES_00,FREEMAIL_FROM, REPLYTO_WITHOUT_TO_CC autolearn=no autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,7d678bbfa50f2552 X-Google-Attributes: gid103376,public X-Google-ArrivalTime: 2004-03-03 20:32:42 PST Message-ID: <4046b131_1@127.0.0.1> From: pburnand0-news@yahoo.com Subject: Re: function at specific address Newsgroups: comp.lang.ada Reply-To: pburnand0-news@yahoo.com Date: Thu, 04 Mar 2004 06:18:40 +0100 References: User-Agent: KNode/0.7.1 MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7Bit X-Authenticated-User: $$laz_wrsc X-Comments: This message was posted through Newsfeed.com X-Comments2: IMPORTANT: Newsfeeds.com does not condone, nor support, spam or any illegal or copyrighted postings. X-Comments3: IMPORTANT: Under NO circumstances will postings containing illegal or copyrighted material through this service be tolerated!! X-Report: Please report illegal or inappropriate use to You may also use our online abuse reporting from: http://www.newsfeed.com/abuseform.htm X-Abuse-Info: Please be sure to forward a copy of ALL headers, INCLUDING the body (DO NOT SEND ATTACHMENTS) Organization: Newsfeed.com http://www.newsfeed.com 100,000+ UNCENSORED Newsgroups. Path: archiver1.google.com!news2.google.com!news.maxwell.syr.edu!news-out2.nntp.be!local!corp-news!not-for-mail Xref: archiver1.google.com comp.lang.ada:6045 Date: 2004-03-04T06:18:40+01:00 List-Id: Jerry van Dijk wrote: > > Szymon Guz 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...