comp.lang.ada
 help / color / mirror / Atom feed
* How do I disable elaboration code on this
@ 2011-04-09 13:58 Lucretia
  2011-04-09 16:57 ` Jeffrey Carter
  2011-04-10 16:34 ` Rolf
  0 siblings, 2 replies; 38+ messages in thread
From: Lucretia @ 2011-04-09 13:58 UTC (permalink / raw)


The following code will not compile no matter what I do. Basically, I
want to write the startup code for Cortex-M3 in Ada with no assembly.
So, the ISR code needs to be elaboration free as it's the first bit of
code that would run on reset.

Essentially, at address 0 the exception vectors are stored. These are
in flash ROM so elaboration code is out of the question anyway. Each
element of the array is a pointer to an interrupt service routine.
I've specified a 4 element vector to test this out:

I've compiled with:

~/opt/tamp/bin/arm-none-eabi-gnatmake --RTS=/home/laguest/src/mine/
tamp/rts/boards/xpresso1769 -c -g -gnatyy -gnaty-s -mcpu=cortex-m3 -
mthumb -gnatG test.adb

and used my own build of the compiler and my own zero footprint
runtime.

I get the following output:

-- Start of output
Source recreated from tree for ISR (body)
-----------------------------------------


package body isr is

   procedure isr__dummy is
   begin
      %push_constraint_error_label ()
      %push_program_error_label ()
      %push_storage_error_label ()
      null;
      %pop_constraint_error_label
      %pop_program_error_label
      %pop_storage_error_label
      return;
   end isr__dummy;
begin
   null;
end isr;

Source recreated from tree for ISR (spec)
-----------------------------------------

pragma restrictions (no_elaboration_code);
with system;
with system;
isr_E : boolean := false;

package isr is
   procedure isr__dummy;
   pragma convention (c, isr__dummy);
private
   type isr__cb is not null access procedure;
   pragma convention (c, isr__cb);
   type isr__vectors is array (1 .. 4) of isr__cb;
   pragma convention (c, isr__vectors);
   isr__addr : constant system.system__address := system__address!(
     0);
   [type isr__TvectorsB is array (1 .. 4 range <>) of isr__cb]
   freeze isr__TvectorsB [
      procedure isr__TvectorsBIP (_init : in out isr__TvectorsB) is
         %push_constraint_error_label ()
         %push_program_error_label ()
         %push_storage_error_label ()
         subtype isr__TvectorsBIP__S4s is isr__TvectorsB (_init'first(
           1) .. _init'last(1));
      begin
         for J1 in _init'first(1) .. _init'last(1) loop
            [constraint_error "access check failed"]
            _init (J1) := null;
         end loop;
         %pop_constraint_error_label
         %pop_program_error_label
         %pop_storage_error_label
         return;
      end isr__TvectorsBIP;
   ]
   [subtype isr__T12s is isr__TvectorsB (1 .. 4)]
   reference isr__T12s
   reference isr__T12s
   isr__vector : constant isr__vectors := (isr__dummy'access,
     isr__dummy'access, isr__dummy'access, isr__dummy'access);
   pragma convention (c, isr__vector);
   for isr__vector'address use isr__addr;
end isr;

isr.ads:20:04: violation of restriction "NO_ELABORATION_CODE" at line
1
arm-none-eabi-gnatmake: "isr.adb" compilation error
-- End of output

I've also tried an array of addresses, this produces the same problem.
Can anyone point me in the right direction? Surely, this is possible
in Ada?

-------------------------- Code below
--------------------------------------
pragma Restrictions (No_Elaboration_Code);

with System;

package ISR is
   procedure Dummy;
   pragma Convention (C, Dummy);
private
   type Cb is not null access procedure;
   pragma Convention (C, Cb);

   type Vectors is array (1 .. 4) of Cb;
   pragma Convention (C, Vectors);

   Addr : constant System.Address := System'To_Address
(16#0000_0000#);

   Vector : constant Vectors :=
     (Dummy'Access,
      Dummy'Access,
      Dummy'Access,
      Dummy'Access);
   pragma Convention (C, Vector);
   for Vector'Address use Addr;
end ISR;
package body ISR is
   procedure Dummy is
   begin
      null;
   end Dummy;
end ISR;
pragma Restrictions (No_Floating_Point);

with ISR;

procedure Test is
begin
  null;
end Test;



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

* Re: How do I disable elaboration code on this
  2011-04-09 13:58 How do I disable elaboration code on this Lucretia
@ 2011-04-09 16:57 ` Jeffrey Carter
  2011-04-09 17:01   ` Simon Wright
  2011-04-10 17:20   ` Lucretia
  2011-04-10 16:34 ` Rolf
  1 sibling, 2 replies; 38+ messages in thread
From: Jeffrey Carter @ 2011-04-09 16:57 UTC (permalink / raw)


On 04/09/2011 06:58 AM, Lucretia wrote:
> The following code will not compile no matter what I do. Basically, I
> want to write the startup code for Cortex-M3 in Ada with no assembly.
> So, the ISR code needs to be elaboration free as it's the first bit of
> code that would run on reset.

>     Vector : constant Vectors :=
>       (Dummy'Access,
>        Dummy'Access,
>        Dummy'Access,
>        Dummy'Access);
>     pragma Convention (C, Vector);
>     for Vector'Address use Addr;

I think what you need here is

Vector : constant Vectors;
pragma Import (Ada, Vector);
for Vector'Address use Addr;

since you don't want Vector to be initialized.

Vector will not be initialized because you have pragma Import for it.

Note that you don't need procedure Dummy.

-- 
Jeff Carter
"I'm particularly glad that these lovely children were
here today to hear that speech. Not only was it authentic
frontier gibberish, it expressed a courage little seen
in this day and age."
Blazing Saddles
88



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

* Re: How do I disable elaboration code on this
  2011-04-09 16:57 ` Jeffrey Carter
@ 2011-04-09 17:01   ` Simon Wright
  2011-04-09 17:44     ` Ludovic Brenta
  2011-04-10 17:20   ` Lucretia
  1 sibling, 1 reply; 38+ messages in thread
From: Simon Wright @ 2011-04-09 17:01 UTC (permalink / raw)


Jeffrey Carter <spam.jrcarter.not@spam.not.acm.org> writes:

> On 04/09/2011 06:58 AM, Lucretia wrote:
>> The following code will not compile no matter what I do. Basically, I
>> want to write the startup code for Cortex-M3 in Ada with no assembly.
>> So, the ISR code needs to be elaboration free as it's the first bit of
>> code that would run on reset.
>
>>     Vector : constant Vectors :=
>>       (Dummy'Access,
>>        Dummy'Access,
>>        Dummy'Access,
>>        Dummy'Access);
>>     pragma Convention (C, Vector);
>>     for Vector'Address use Addr;
>
> I think what you need here is
>
> Vector : constant Vectors;
> pragma Import (Ada, Vector);
> for Vector'Address use Addr;
>
> since you don't want Vector to be initialized.
>
> Vector will not be initialized because you have pragma Import for it.
>
> Note that you don't need procedure Dummy.

But the real code will have actual ISR procedures. OP is merely sparing
us the unnecessary detail of the real ISRs.



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

* Re: How do I disable elaboration code on this
  2011-04-09 17:01   ` Simon Wright
@ 2011-04-09 17:44     ` Ludovic Brenta
  2011-04-09 19:19       ` Simon Wright
  0 siblings, 1 reply; 38+ messages in thread
From: Ludovic Brenta @ 2011-04-09 17:44 UTC (permalink / raw)


Simon Wright <simon@pushface.org> writes on comp.lang.ada:
> Jeffrey Carter <spam.jrcarter.not@spam.not.acm.org> writes:
>
>> On 04/09/2011 06:58 AM, Lucretia wrote:
>>> The following code will not compile no matter what I do. Basically, I
>>> want to write the startup code for Cortex-M3 in Ada with no assembly.
>>> So, the ISR code needs to be elaboration free as it's the first bit of
>>> code that would run on reset.
>>
>>>     Vector : constant Vectors :=
>>>       (Dummy'Access,
>>>        Dummy'Access,
>>>        Dummy'Access,
>>>        Dummy'Access);
>>>     pragma Convention (C, Vector);
>>>     for Vector'Address use Addr;
>>
>> I think what you need here is
>>
>> Vector : constant Vectors;
>> pragma Import (Ada, Vector);
>> for Vector'Address use Addr;
>>
>> since you don't want Vector to be initialized.
>>
>> Vector will not be initialized because you have pragma Import for it.
>>
>> Note that you don't need procedure Dummy.
>
> But the real code will have actual ISR procedures. OP is merely sparing
> us the unnecessary detail of the real ISRs.

But the vector being in Flash ROM, the Ada code needs not and indeed may
not initialize it, so I think Jeffrey's reply is correct.  The pragma
Import and the address clause will make the actual vectors (in ROM)
visible to the Ada program.

-- 
Ludovic Brenta.



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

* Re: How do I disable elaboration code on this
  2011-04-09 17:44     ` Ludovic Brenta
@ 2011-04-09 19:19       ` Simon Wright
  2011-04-09 19:32         ` Jeffrey Carter
  2011-04-09 19:35         ` Ludovic Brenta
  0 siblings, 2 replies; 38+ messages in thread
From: Simon Wright @ 2011-04-09 19:19 UTC (permalink / raw)


Ludovic Brenta <ludovic@ludovic-brenta.org> writes:

> Simon Wright <simon@pushface.org> writes on comp.lang.ada:
>> Jeffrey Carter <spam.jrcarter.not@spam.not.acm.org> writes:
>>
>>> On 04/09/2011 06:58 AM, Lucretia wrote:
>>>> The following code will not compile no matter what I do. Basically, I
>>>> want to write the startup code for Cortex-M3 in Ada with no assembly.
>>>> So, the ISR code needs to be elaboration free as it's the first bit of
>>>> code that would run on reset.
>>>
>>>>     Vector : constant Vectors :=
>>>>       (Dummy'Access,
>>>>        Dummy'Access,
>>>>        Dummy'Access,
>>>>        Dummy'Access);
>>>>     pragma Convention (C, Vector);
>>>>     for Vector'Address use Addr;
>>>
>>> I think what you need here is
>>>
>>> Vector : constant Vectors;
>>> pragma Import (Ada, Vector);
>>> for Vector'Address use Addr;
>>>
>>> since you don't want Vector to be initialized.
>>>
>>> Vector will not be initialized because you have pragma Import for it.
>>>
>>> Note that you don't need procedure Dummy.
>>
>> But the real code will have actual ISR procedures. OP is merely sparing
>> us the unnecessary detail of the real ISRs.
>
> But the vector being in Flash ROM, the Ada code needs not and indeed may
> not initialize it, so I think Jeffrey's reply is correct.  The pragma
> Import and the address clause will make the actual vectors (in ROM)
> visible to the Ada program.

That would be true if the vector was built in a separate C or ASM file,
but Luke wants to do the whole thing in Ada and then write it to
Flash. See above: "Basically, I want to write the startup code for
Cortex-M3 in Ada with no assembly."



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

* Re: How do I disable elaboration code on this
  2011-04-09 19:19       ` Simon Wright
@ 2011-04-09 19:32         ` Jeffrey Carter
  2011-04-10  9:06           ` Lucretia
  2011-04-09 19:35         ` Ludovic Brenta
  1 sibling, 1 reply; 38+ messages in thread
From: Jeffrey Carter @ 2011-04-09 19:32 UTC (permalink / raw)


On 04/09/2011 12:19 PM, Simon Wright wrote:
>
> That would be true if the vector was built in a separate C or ASM file,
> but Luke wants to do the whole thing in Ada and then write it to
> Flash. See above: "Basically, I want to write the startup code for
> Cortex-M3 in Ada with no assembly."

Maybe I misunderstood, but I think the code the OP presented is the Ada to 
access the ISRs in flash from Ada, not code to create them.

-- 
Jeff Carter
"I'm particularly glad that these lovely children were
here today to hear that speech. Not only was it authentic
frontier gibberish, it expressed a courage little seen
in this day and age."
Blazing Saddles
88



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

* Re: How do I disable elaboration code on this
  2011-04-09 19:19       ` Simon Wright
  2011-04-09 19:32         ` Jeffrey Carter
@ 2011-04-09 19:35         ` Ludovic Brenta
  2011-04-09 22:05           ` Simon Wright
  1 sibling, 1 reply; 38+ messages in thread
From: Ludovic Brenta @ 2011-04-09 19:35 UTC (permalink / raw)


Simon Wright <simon@pushface.org> writes on comp.lang.ada:
> Ludovic Brenta <ludovic@ludovic-brenta.org> writes:
>
>> Simon Wright <simon@pushface.org> writes on comp.lang.ada:
>>> Jeffrey Carter <spam.jrcarter.not@spam.not.acm.org> writes:
>>>
>>>> On 04/09/2011 06:58 AM, Lucretia wrote:
>>>>> The following code will not compile no matter what I do. Basically, I
>>>>> want to write the startup code for Cortex-M3 in Ada with no assembly.
>>>>> So, the ISR code needs to be elaboration free as it's the first bit of
>>>>> code that would run on reset.
>>>>
>>>>>     Vector : constant Vectors :=
>>>>>       (Dummy'Access,
>>>>>        Dummy'Access,
>>>>>        Dummy'Access,
>>>>>        Dummy'Access);
>>>>>     pragma Convention (C, Vector);
>>>>>     for Vector'Address use Addr;
>>>>
>>>> I think what you need here is
>>>>
>>>> Vector : constant Vectors;
>>>> pragma Import (Ada, Vector);
>>>> for Vector'Address use Addr;
>>>>
>>>> since you don't want Vector to be initialized.
>>>>
>>>> Vector will not be initialized because you have pragma Import for it.
>>>>
>>>> Note that you don't need procedure Dummy.
>>>
>>> But the real code will have actual ISR procedures. OP is merely sparing
>>> us the unnecessary detail of the real ISRs.
>>
>> But the vector being in Flash ROM, the Ada code needs not and indeed may
>> not initialize it, so I think Jeffrey's reply is correct.  The pragma
>> Import and the address clause will make the actual vectors (in ROM)
>> visible to the Ada program.
>
> That would be true if the vector was built in a separate C or ASM
> file, but Luke wants to do the whole thing in Ada and then write it to
> Flash. See above: "Basically, I want to write the startup code for
> Cortex-M3 in Ada with no assembly."

The vector can and must be built and burned to Flash separately, by an
Ada program of course :) This Ada program cannot write to Flash, it can
only read the vector previously stored there with no elaboration and no
initialization.  This is very similar to things I did at Barco avionics
a few years ago (I even wrote the driver for writing to the particular
Flash device in pure Ada).

-- 
Ludovic Brenta.



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

* Re: How do I disable elaboration code on this
  2011-04-09 19:35         ` Ludovic Brenta
@ 2011-04-09 22:05           ` Simon Wright
  2011-04-10  5:39             ` Simon Wright
  0 siblings, 1 reply; 38+ messages in thread
From: Simon Wright @ 2011-04-09 22:05 UTC (permalink / raw)


Ludovic Brenta <ludovic@ludovic-brenta.org> writes:

> Simon Wright <simon@pushface.org> writes on comp.lang.ada:
>> Ludovic Brenta <ludovic@ludovic-brenta.org> writes:
>>
>>> Simon Wright <simon@pushface.org> writes on comp.lang.ada:
>>>> Jeffrey Carter <spam.jrcarter.not@spam.not.acm.org> writes:
>>>>
>>>>> On 04/09/2011 06:58 AM, Lucretia wrote:
>>>>>> The following code will not compile no matter what I do. Basically, I
>>>>>> want to write the startup code for Cortex-M3 in Ada with no assembly.
>>>>>> So, the ISR code needs to be elaboration free as it's the first bit of
>>>>>> code that would run on reset.
>>>>>
>>>>>>     Vector : constant Vectors :=
>>>>>>       (Dummy'Access,
>>>>>>        Dummy'Access,
>>>>>>        Dummy'Access,
>>>>>>        Dummy'Access);
>>>>>>     pragma Convention (C, Vector);
>>>>>>     for Vector'Address use Addr;

>>> But the vector being in Flash ROM, the Ada code needs not and indeed may
>>> not initialize it, so I think Jeffrey's reply is correct.  The pragma
>>> Import and the address clause will make the actual vectors (in ROM)
>>> visible to the Ada program.
>>
>> That would be true if the vector was built in a separate C or ASM
>> file, but Luke wants to do the whole thing in Ada and then write it to
>> Flash. See above: "Basically, I want to write the startup code for
>> Cortex-M3 in Ada with no assembly."
>
> The vector can and must be built and burned to Flash separately, by an
> Ada program of course :) This Ada program cannot write to Flash, it can
> only read the vector previously stored there with no elaboration and no
> initialization.  This is very similar to things I did at Barco avionics
> a few years ago (I even wrote the driver for writing to the particular
> Flash device in pure Ada).

Well, you've done it and I haven't!

The process I deduced from Luke's question ends up with taking an
executable image (including the ISV, which is at 16#0000_0000# after
reset) and burning it to Flash using some utility or other (probably
part of the SDK).

So, can he find a way of generating this executable from just Ada?

It's the fact that Vector is at 16#0000_0000# that's causing the problem
(there is no elaboration code if the linker is allowed to put Vector
where it likes). So clearly GNAT doesn't know how to make ld do what's
wanted and has to do it the hard way.

Is the missing bit perhaps the use of what on VAX used to be called
program sections (PSECTs)?

GNU ld includes the option

   --section-start sectionname=org
      Locate a section in the output file at the absolute address given
      by org. You may use this option as many times as necessary to
      locate multiple sections in the command line. org must be a single
      hexadecimal integer; for compatibility with other linkers, you may
      omit the leading 0x usually associated with hexadecimal values.

so I suppose what's needed is a way to force Vector into a specific
named section.

What about pragma Linker_Section?
http://gcc.gnu.org/onlinedocs/gcc-4.5.0/gnat_rm/Pragma-Linker_005fSection.html

I can't go much further here (what's legal as the name of a section
depends on the assembler/linker conventions), but this

   pragma Linker_Section (Vector, "initial_isv,0");

resulted in this

        .globl _isr__vector
        .section initial_isv
        .align 5
_isr__vector:
        .quad   _isr__dummy
        .quad   _isr__dummy
        .quad   _isr__dummy
        .quad   _isr__dummy
        .const

(This is a 64-bit compiler, hence the .quad's. No idea about .align 5.)



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

* Re: How do I disable elaboration code on this
  2011-04-09 22:05           ` Simon Wright
@ 2011-04-10  5:39             ` Simon Wright
  0 siblings, 0 replies; 38+ messages in thread
From: Simon Wright @ 2011-04-10  5:39 UTC (permalink / raw)


Simon Wright <simon@pushface.org> writes:

>    pragma Linker_Section (Vector, "initial_isv,0");
>
> resulted in this
>
>         .globl _isr__vector
>         .section initial_isv
>         .align 5
> _isr__vector:
>         .quad   _isr__dummy
>         .quad   _isr__dummy
>         .quad   _isr__dummy
>         .quad   _isr__dummy
>         .const

What happened there was I said 'gnatmake -S isr.adb'. I should have said
'gnatmake -S -c -u -f isr.adb', which actually forces the recompile,
resulting in

        .section initial_isv,0

as you might have expected.

Probably not reasonable to ask anyone to spend effort teaching gnatmake
that the target with -S is the .s file, not the .o/.ali!



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

* Re: How do I disable elaboration code on this
  2011-04-09 19:32         ` Jeffrey Carter
@ 2011-04-10  9:06           ` Lucretia
  2011-04-10  9:31             ` Simon Wright
  0 siblings, 1 reply; 38+ messages in thread
From: Lucretia @ 2011-04-10  9:06 UTC (permalink / raw)


> > That would be true if the vector was built in a separate C or ASM file,
> > but Luke wants to do the whole thing in Ada and then write it to
> > Flash. See above: "Basically, I want to write the startup code for
> > Cortex-M3 in Ada with no assembly."
>
> Maybe I misunderstood, but I think the code the OP presented is the Ada to
> access the ISRs in flash from Ada, not code to create them.

What Simon said. What I want is to generate the table.

The dummy isr is require for now.

I use a custom linker script to generate the elf.

Do I need to force the access types to C convention?

Thanks,
Luke



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

* Re: How do I disable elaboration code on this
  2011-04-10  9:06           ` Lucretia
@ 2011-04-10  9:31             ` Simon Wright
  0 siblings, 0 replies; 38+ messages in thread
From: Simon Wright @ 2011-04-10  9:31 UTC (permalink / raw)


Lucretia <Lucretia9000@yahoo.co.uk> writes:

> Do I need to force the access types to C convention?

Don't know, but don't see how it can harm either way. I'd play safe and
use convention C.



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

* Re: How do I disable elaboration code on this
  2011-04-09 13:58 How do I disable elaboration code on this Lucretia
  2011-04-09 16:57 ` Jeffrey Carter
@ 2011-04-10 16:34 ` Rolf
  1 sibling, 0 replies; 38+ messages in thread
From: Rolf @ 2011-04-10 16:34 UTC (permalink / raw)


On 9 Apr., 15:58, Lucretia <Lucretia9...@yahoo.co.uk> wrote:
> The following code will not compile no matter what I do. Basically, I
> want to write the startup code for Cortex-M3 in Ada with no assembly.
> So, the ISR code needs to be elaboration free as it's the first bit of
> code that would run on reset.

If I understand you correctly you need to set up the vector table
statically so that no dynamic code is needed to attach the actual ISR
code to the vector jump table.  That is similar to the AVR interrupt
architecture.

> Essentially, at address 0 the exception vectors are stored. These are
> in flash ROM so elaboration code is out of the question anyway. Each
> element of the array is a pointer to an interrupt service routine.
> I've specified a 4 element vector to test this out:
>

...

>
> I get the following output:
>
> -- Start of output

...

>    [type isr__TvectorsB is array (1 .. 4 range <>) of isr__cb]
>    freeze isr__TvectorsB [
>       procedure isr__TvectorsBIP (_init : in out isr__TvectorsB) is
>          %push_constraint_error_label ()
>          %push_program_error_label ()
>          %push_storage_error_label ()
>          subtype isr__TvectorsBIP__S4s is isr__TvectorsB (_init'first(
>            1) .. _init'last(1));
>       begin
>          for J1 in _init'first(1) .. _init'last(1) loop
>             [constraint_error "access check failed"]
>             _init (J1) := null;
>          end loop;

This part is the only dynamic elaboration code that I see. It
initializes the elements of the vector with null pointers.

>    isr__vector : constant isr__vectors := (isr__dummy'access,
>      isr__dummy'access, isr__dummy'access, isr__dummy'access);

Here the vecor gets set up with four copies of Dummy's address as you
express it in your code.

I think it is a missed optimization of the compiler as the vector
first is initialized with zeroes and then imidiately following it is
set up with the correct values.

If you want to get rid of dynamic code you must somehow convince the
compiler that initializing with zeroes is not necessary. I'd try to
use separate constants, like:

Vector1 : constant CB := Dummy'Access;
Vector2 : constant CB := Dummy'Access;
...

You probably have to add address clauses and pragma Convention C
statements.


>
> I've also tried an array of addresses, this produces the same problem.
> Can anyone point me in the right direction? Surely, this is possible
> in Ada?

The problem is that you use an array. It does not depend on the types
stored in the array.  Having an array GNAT generates a loop for the
init code.

HTH
   Rolf



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

* Re: How do I disable elaboration code on this
  2011-04-09 16:57 ` Jeffrey Carter
  2011-04-09 17:01   ` Simon Wright
@ 2011-04-10 17:20   ` Lucretia
  2011-04-10 20:12     ` Jeffrey Carter
  2011-04-10 20:47     ` Georg Bauhaus
  1 sibling, 2 replies; 38+ messages in thread
From: Lucretia @ 2011-04-10 17:20 UTC (permalink / raw)


> I think what you need here is
>
> Vector : constant Vectors;
> pragma Import (Ada, Vector);
> for Vector'Address use Addr;
>
> since you don't want Vector to be initialized.
>
> Vector will not be initialized because you have pragma Import for it.

Nope, this didn't work. Checked the RM. Seems that if I use pragma
Import (Ada, Vector) then the compiler assumes that this is an
external (possibly in ASM) that is already initialised and therefore
cannot be initialized to my ISR subprograms.

Luke.



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

* Re: How do I disable elaboration code on this
  2011-04-10 17:20   ` Lucretia
@ 2011-04-10 20:12     ` Jeffrey Carter
  2011-04-10 20:47     ` Georg Bauhaus
  1 sibling, 0 replies; 38+ messages in thread
From: Jeffrey Carter @ 2011-04-10 20:12 UTC (permalink / raw)


On 04/10/2011 10:20 AM, Lucretia wrote:
>
> Nope, this didn't work. Checked the RM. Seems that if I use pragma
> Import (Ada, Vector) then the compiler assumes that this is an
> external (possibly in ASM) that is already initialised and therefore
> cannot be initialized to my ISR subprograms.

I gather that you are trying to set up the vector to be written to flash, not 
use a vector already in flash. In that case I don't see how you could expect the 
code that writes the vector to flash to not have elaboration code for the new 
vector you are creating through declarations in a declarative region.

My suggestion was for code that uses the vector in flash.

You could import the vector as a variable to suppress the initialization to all 
null, then assign to it in the executable part of your program, but that's 
simply moving the initialization from elaboration code to explicit code.

-- 
Jeff Carter
"It's all right, Taggart. Just a man and a horse being hung out there."
Blazing Saddles
34



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

* Re: How do I disable elaboration code on this
  2011-04-10 17:20   ` Lucretia
  2011-04-10 20:12     ` Jeffrey Carter
@ 2011-04-10 20:47     ` Georg Bauhaus
  2011-04-10 21:19       ` Lucretia
  1 sibling, 1 reply; 38+ messages in thread
From: Georg Bauhaus @ 2011-04-10 20:47 UTC (permalink / raw)


On 4/10/11 7:20 PM, Lucretia wrote:
>> I think what you need here is
>>
>> Vector : constant Vectors;
>> pragma Import (Ada, Vector);
>> for Vector'Address use Addr;
>>
>> since you don't want Vector to be initialized.
>>
>> Vector will not be initialized because you have pragma Import for it.
>
> Nope, this didn't work. Checked the RM. Seems that if I use pragma
> Import (Ada, Vector) then the compiler assumes that this is an
> external (possibly in ASM) that is already initialised and therefore
> cannot be initialized to my ISR subprograms.

Don't know whether the following just silences the compiler
or whether it solves the elaboration code issue. (The issue
seems to appear with variables that have an address clause
specified.  There code below seems to result in two _init
procedures, one for CbW and one for Vectors; the assembly listing
shows a number of moves related to Vectors).

The idea was to replace Cb with a limited record CbW
that has a Cb component. The component is default initialized
to point to Dummy.

pragma Restrictions (No_Elaboration_Code);

with System;

package ISR is
    procedure Dummy;
    pragma Convention (C, Dummy);

private
    type Cb is not null access procedure;
    pragma Convention (C, Cb);

    type CbW is limited record
       C : Cb := Dummy'Access;
    end record;
    type Vectors is array (1 .. 4) of CbW;
    pragma Convention (C, Vectors);

    Addr : constant System.Address := System'To_Address
         (16#0000_0000#);

    Vector : Vectors;
    pragma Import (Ada, Vector);
    for Vector'Address use Addr;
end ISR;
package body ISR is
    procedure Dummy is
    begin
       null;
    end Dummy;
end ISR;




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

* Re: How do I disable elaboration code on this
  2011-04-10 20:47     ` Georg Bauhaus
@ 2011-04-10 21:19       ` Lucretia
  2011-04-11  5:08         ` Lucretia
  0 siblings, 1 reply; 38+ messages in thread
From: Lucretia @ 2011-04-10 21:19 UTC (permalink / raw)


On Apr 10, 9:47 pm, Georg Bauhaus <rm-host.bauh...@maps.futureapps.de>
wrote:
> pragma Restrictions (No_Elaboration_Code);
>
> with System;
>
> package ISR is
>     procedure Dummy;
>     pragma Convention (C, Dummy);
>
> private
>     type Cb is not null access procedure;
>     pragma Convention (C, Cb);
>
>     type CbW is limited record
>        C : Cb := Dummy'Access;
>     end record;
>     type Vectors is array (1 .. 4) of CbW;
>     pragma Convention (C, Vectors);
>
>     Addr : constant System.Address := System'To_Address
>          (16#0000_0000#);
>
>     Vector : Vectors;
>     pragma Import (Ada, Vector);
>     for Vector'Address use Addr;
> end ISR;

But can you initialise the array with different routines? I'm betting
not. In a real implementation, there will be a number of ISR's but
some may point to the dummy one.

Luke.



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

* Re: How do I disable elaboration code on this
  2011-04-10 21:19       ` Lucretia
@ 2011-04-11  5:08         ` Lucretia
  2011-04-11  6:28           ` Simon Wright
  0 siblings, 1 reply; 38+ messages in thread
From: Lucretia @ 2011-04-11  5:08 UTC (permalink / raw)


Just to clarify, this vector is to be:

1) set up by the user
2) gathered by the linker script and written out at the start of the
elf
3) placed at address 0 in the elf
4) made ROMable

From your responses, it seems that you don't quite understand my aim
here, point 4 is the most important here, ROMable means, the compiler
must not under any circumstance create any elaboration code to
initialise the array and given that the array is 1) constant and 2)
has known contents, the compiler should be capable of this. Maybe GNAT
can't do it? Maybe Ada can't do it and actually is wrong for OS
development? Which I doubt otherwise, I may as well go create my own
strongly typed language for OS/embedded work?

Luke.



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

* Re: How do I disable elaboration code on this
  2011-04-11  5:08         ` Lucretia
@ 2011-04-11  6:28           ` Simon Wright
  2011-04-11  8:54             ` Lucretia
  0 siblings, 1 reply; 38+ messages in thread
From: Simon Wright @ 2011-04-11  6:28 UTC (permalink / raw)


Lucretia <Lucretia9000@yahoo.co.uk> writes:

> Just to clarify, this vector is to be:
>
> 1) set up by the user
> 2) gathered by the linker script and written out at the start of the
> elf
> 3) placed at address 0 in the elf
> 4) made ROMable
>
> From your responses, it seems that you don't quite understand my aim
> here, point 4 is the most important here, ROMable means, the compiler
> must not under any circumstance create any elaboration code to
> initialise the array and given that the array is 1) constant and 2)
> has known contents, the compiler should be capable of this. Maybe GNAT
> can't do it? Maybe Ada can't do it and actually is wrong for OS
> development? Which I doubt otherwise, I may as well go create my own
> strongly typed language for OS/embedded work?

Please re-read this which I posted earlier (apologies if my news
interface is failing. I did try mailing it.)

Provided that the Cortex-M3 SDK ld has the ability to specify where a
section should go, this will meet all your criteria except possibly (2)
(which doesn't seem really necessary?)

The SDK must have the ability to specify where sections should go,
otherwise how is this exception vector set up from C or ASM?

------------------------------------------------------------------------

It's the fact that Vector is at 16#0000_0000# that's causing the problem
(there is no elaboration code if the linker is allowed to put Vector
where it likes). So clearly GNAT doesn't know how to make ld do what's
wanted and has to do it the hard way.

Is the missing bit perhaps the use of what on VAX used to be called
program sections (PSECTs)?

GNU ld includes the option

   --section-start sectionname=org
      Locate a section in the output file at the absolute address given
      by org. You may use this option as many times as necessary to
      locate multiple sections in the command line. org must be a single
      hexadecimal integer; for compatibility with other linkers, you may
      omit the leading 0x usually associated with hexadecimal values.

so I suppose what's needed is a way to force Vector into a specific
named section.

What about pragma Linker_Section?
http://gcc.gnu.org/onlinedocs/gcc-4.5.0/gnat_rm/Pragma-Linker_005fSection.html

I can't go much further here (what's legal as the name of a section
depends on the assembler/linker conventions), but this

   pragma Linker_Section (Vector, "initial_isv,0");

(instead of "for Vector'Address") resulted in this

        .globl _isr__vector
        .section initial_isv
        .align 5
_isr__vector:
        .quad   _isr__dummy
        .quad   _isr__dummy
        .quad   _isr__dummy
        .quad   _isr__dummy
        .const

(This is a 64-bit compiler, hence the .quad's. No idea about .align 5.)



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

* Re: How do I disable elaboration code on this
  2011-04-11  6:28           ` Simon Wright
@ 2011-04-11  8:54             ` Lucretia
  2011-04-11 10:10               ` Simon Wright
                                 ` (2 more replies)
  0 siblings, 3 replies; 38+ messages in thread
From: Lucretia @ 2011-04-11  8:54 UTC (permalink / raw)


The problem has nothing to do with the linker, I'm using binutils and
gnat that I'e built myself. The problem is that GNAT is generating
elaboration code where it is not allowed, i.e. code that 1)
initialises  the array to 0 and 2) code that the copies function
addresses into the array.

If this cannot work then I'm surprised and I'll be forced to use
separate constants as noted by Rolf. It just seems like overkill
having to specify each element separately when an array is the right
structure ffor the job.

And in other languages like C it doesn't do the same thing. You can
specify a static constant array and it'll initialise it with the right
data.

Luke



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

* Re: How do I disable elaboration code on this
  2011-04-11  8:54             ` Lucretia
@ 2011-04-11 10:10               ` Simon Wright
  2011-04-11 11:59                 ` Simon Clubley
  2011-04-11 11:19               ` Georg Bauhaus
  2011-04-14 19:19               ` Florian Weimer
  2 siblings, 1 reply; 38+ messages in thread
From: Simon Wright @ 2011-04-11 10:10 UTC (permalink / raw)


Lucretia <Lucretia9000@yahoo.co.uk> writes:

> The problem has nothing to do with the linker, I'm using binutils and
> gnat that I'e built myself. The problem is that GNAT is generating
> elaboration code where it is not allowed, i.e. code that 1)
> initialises  the array to 0 and 2) code that the copies function
> addresses into the array.
>
> If this cannot work then I'm surprised and I'll be forced to use
> separate constants as noted by Rolf. It just seems like overkill
> having to specify each element separately when an array is the right
> structure ffor the job.
>
> And in other languages like C it doesn't do the same thing. You can
> specify a static constant array and it'll initialise it with the right
> data.

And can you also specify the load address?

I happen to have a cross-compiler for VxWorks here (handy now, but I
ought to delete it) so I tried the following.

First, add markers so I can see what's what (note, the syntax for a
linker section name is different for VxWorks):

   Start : constant Integer := 16#1234_5678#;
   pragma Linker_Section (Start, "initial_isv#0");
   Vector : constant Vectors :=
     (Dummy'Access,
      Dummy'Access,
      Dummy'Access,
      Dummy'Access);
   pragma Convention (C, Vector);
   pragma Linker_Section (Vector, "initial_isv#0");
   --  for Vector'Address use Addr;
   Finish : constant Integer := 16#1234_4321#;
   pragma Linker_Section (Finish, "initial_isv#0");

Build:

$ powerpc-wrs-vxworks-gnatmake test.adb \
   -f 
   -largs -Wl,--section-start -Wl,initial_isv=0x0

which generates an ELF file:

$ powerpc-wrs-vxworks-objdump -h -r test


test:     file format elf32-powerpc-vxworks

Sections:
Idx Name          Size      VMA       LMA       File off  Algn
  0 initial_isv   00000018  00000000  00000000  00000034  2**2
                  CONTENTS, RELOC, READONLY
[....]
RELOCATION RECORDS FOR [initial_isv]:
OFFSET   TYPE              VALUE 
00000004 R_PPC_ADDR32      isr__dummy
00000008 R_PPC_ADDR32      isr__dummy
0000000c R_PPC_ADDR32      isr__dummy
00000010 R_PPC_ADDR32      isr__dummy
[...]
Disassembly of section initial_isv:

00000000 <isr__start>:
   0:   12 34 56 78     .long 0x12345678

00000004 <isr__vector>:
        ...

00000014 <isr__finish>:
  14:   12 34 43 21     vmhraddshs v17,v20,v8,v12


I don't know whether this achieves what you are after, but it looks
pretty hopeful.

You've built binutils for your target (you said "my own
binutils" or something like that - if they really are yours rather than
GNU, (a) hats off, (b) I'm barking up the wrong tree and will shut up)
so I would expect --section_start to work the same.



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

* Re: How do I disable elaboration code on this
  2011-04-11  8:54             ` Lucretia
  2011-04-11 10:10               ` Simon Wright
@ 2011-04-11 11:19               ` Georg Bauhaus
  2011-04-11 13:50                 ` Simon Wright
  2011-04-14 19:19               ` Florian Weimer
  2 siblings, 1 reply; 38+ messages in thread
From: Georg Bauhaus @ 2011-04-11 11:19 UTC (permalink / raw)


On 11.04.11 10:54, Lucretia wrote:
> The problem has nothing to do with the linker, I'm using binutils and
> gnat that I'e built myself. The problem is that GNAT is generating
> elaboration code where it is not allowed, i.e. code that 1)
> initialises  the array to 0 and 2) code that the copies function
> addresses into the array.

When, just for the fun of it, I added pragma Preelaborate,
I learned that Dummy'Address is non-static.

Assuming this could be helped by specifying the final
location of procedure Dummy in ROM, how would you do
this in C (as you said that's possible, I'm curious).



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

* Re: How do I disable elaboration code on this
  2011-04-11 10:10               ` Simon Wright
@ 2011-04-11 11:59                 ` Simon Clubley
  2011-04-11 18:30                   ` Simon Wright
  2011-04-11 23:08                   ` Lucretia
  0 siblings, 2 replies; 38+ messages in thread
From: Simon Clubley @ 2011-04-11 11:59 UTC (permalink / raw)


On 2011-04-11, Simon Wright <simon@pushface.org> wrote:
> Lucretia <Lucretia9000@yahoo.co.uk> writes:
>
>> The problem has nothing to do with the linker, I'm using binutils and
>> gnat that I'e built myself. The problem is that GNAT is generating
>> elaboration code where it is not allowed, i.e. code that 1)
>> initialises  the array to 0 and 2) code that the copies function
>> addresses into the array.
>>
>> If this cannot work then I'm surprised and I'll be forced to use
>> separate constants as noted by Rolf. It just seems like overkill
>> having to specify each element separately when an array is the right
>> structure ffor the job.
>>
>> And in other languages like C it doesn't do the same thing. You can
>> specify a static constant array and it'll initialise it with the right
>> data.
>
> And can you also specify the load address?
>

On Cortex M3 devices using C, this array is placed in it's own section
and is placed at address 0 by the linker script.

The issue here is that when the Cortex M3 comes out of reset it reads,
and loads, the stack pointer from the first longword in that array
and then jumps to the address specified by the second longword.

To Luke: are you targetting only the Cortex M3 or traditional ARM7
devices as well ?

If you are targetting the latter as well, you may wish to think about
just using a wrapper as you would need to have assembly wrappers anyway
for the ARM7 device. (For anyone here unfamiliar with ARM7 devices, when
traditional ARM7 devices come out of reset, you cannot even run C code
until you have setup a SP in the startup code).

Simon.

-- 
Simon Clubley, clubley@remove_me.eisner.decus.org-Earth.UFP
Microsoft: Bringing you 1980s technology to a 21st century world



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

* Re: How do I disable elaboration code on this
  2011-04-11 11:19               ` Georg Bauhaus
@ 2011-04-11 13:50                 ` Simon Wright
  0 siblings, 0 replies; 38+ messages in thread
From: Simon Wright @ 2011-04-11 13:50 UTC (permalink / raw)


Georg Bauhaus <rm.dash-bauhaus@futureapps.de> writes:

> When, just for the fun of it, I added pragma Preelaborate,
> I learned that Dummy'Address is non-static.

pragma Preelaborate is accepted without complaint by GCC 4.5.0.



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

* Re: How do I disable elaboration code on this
  2011-04-11 11:59                 ` Simon Clubley
@ 2011-04-11 18:30                   ` Simon Wright
  2011-04-11 19:12                     ` Simon Wright
  2011-04-11 23:08                   ` Lucretia
  1 sibling, 1 reply; 38+ messages in thread
From: Simon Wright @ 2011-04-11 18:30 UTC (permalink / raw)


Simon Clubley <clubley@remove_me.eisner.decus.org-Earth.UFP> writes:

> The issue here is that when the Cortex M3 comes out of reset it reads,
> and loads, the stack pointer from the first longword in that array and
> then jumps to the address specified by the second longword.

I see (in the definitive guide)

Reset Sequence

After the processor exits reset, it will read two words from memory:

* Address 0x00000000: Starting value of R13 (the stack pointer)

* Address 0x00000004: Reset vector (the starting address of program
  execution; LSB should be set to 1 to indicate Thumb state)

The part about the LSB being set to 1 may cause difficulty! I suppose
one could say "Foo'Address + 1" (which means the vector would have to be
an array of System.Address, not so good but I think unavoidable??)



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

* Re: How do I disable elaboration code on this
  2011-04-11 18:30                   ` Simon Wright
@ 2011-04-11 19:12                     ` Simon Wright
  2011-04-11 19:50                       ` Simon Wright
                                         ` (3 more replies)
  0 siblings, 4 replies; 38+ messages in thread
From: Simon Wright @ 2011-04-11 19:12 UTC (permalink / raw)


Simon Wright <simon@pushface.org> writes:

> The part about the LSB being set to 1 may cause difficulty! I suppose
> one could say "Foo'Address + 1" (which means the vector would have to be
> an array of System.Address, not so good but I think unavoidable??)

And then we're back to the 'no elaboration code' problem.

Does the LSB really have to be set to 1? The Cortex-M3 only implements
Thumb instructions, doesn't it?



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

* Re: How do I disable elaboration code on this
  2011-04-11 19:12                     ` Simon Wright
@ 2011-04-11 19:50                       ` Simon Wright
  2011-04-11 21:40                       ` Lucretia
                                         ` (2 subsequent siblings)
  3 siblings, 0 replies; 38+ messages in thread
From: Simon Wright @ 2011-04-11 19:50 UTC (permalink / raw)


Simon Wright <simon@pushface.org> writes:

> Does the LSB really have to be set to 1? The Cortex-M3 only implements
> Thumb instructions, doesn't it?

This question
http://stackoverflow.com/questions/2682428/gnu-ld-removes-section
seems to indicate that the LSB need not be set to 1.



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

* Re: How do I disable elaboration code on this
  2011-04-11 19:12                     ` Simon Wright
  2011-04-11 19:50                       ` Simon Wright
@ 2011-04-11 21:40                       ` Lucretia
  2011-04-11 23:12                         ` Lucretia
  2011-04-13 16:53                       ` Simon Wright
  2011-04-15  8:38                       ` Simon Wright
  3 siblings, 1 reply; 38+ messages in thread
From: Lucretia @ 2011-04-11 21:40 UTC (permalink / raw)


On Apr 11, 8:12 pm, Simon Wright <si...@pushface.org> wrote:
> Simon Wright <si...@pushface.org> writes:
> > The part about the LSB being set to 1 may cause difficulty! I suppose
> > one could say "Foo'Address + 1" (which means the vector would have to be
> > an array of System.Address, not so good but I think unavoidable??)
>
> And then we're back to the 'no elaboration code' problem.
>
> Does the LSB really have to be set to 1? The Cortex-M3 only implements
> Thumb instructions, doesn't it?

That's bit 0, not byte 0, just in case anyone's confused. And yes,
Address is private therefore will cause elaboration problems. I
originally had an array of these, forgot about the +1 part, but then I
was trying to just get it to work!

I will upload a sample project to GitHub if I get the time that should
help us.

Luke.



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

* Re: How do I disable elaboration code on this
  2011-04-11 11:59                 ` Simon Clubley
  2011-04-11 18:30                   ` Simon Wright
@ 2011-04-11 23:08                   ` Lucretia
  2011-04-12 11:50                     ` Simon Clubley
  1 sibling, 1 reply; 38+ messages in thread
From: Lucretia @ 2011-04-11 23:08 UTC (permalink / raw)


On Apr 11, 12:59 pm, Simon Clubley <clubley@remove_me.eisner.decus.org-
Earth.UFP> wrote:

> On Cortex M3 devices using C, this array is placed in it's own section
> and is placed at address 0 by the linker script.

Yup, easy in C. just a static const array of pointers to functions in
a separate file, the linker is then used to slap it into place.

> The issue here is that when the Cortex M3 comes out of reset it reads,
> and loads, the stack pointer from the first longword in that array
> and then jumps to the address specified by the second longword.
>
> To Luke: are you targetting only the Cortex M3 or traditional ARM7
> devices as well ?

Not yet. It's just that the M3 doesn't actually need ASM for C/C++
projects, I wanted to see if I could do the same from Ada.

At the moment, I have a Cortex-M3 board so that shall be my target, I
intend to write an equivalent of CMSIS for use as the BSP for these
chips.

As for ARM7 or other ARM's, there's no real reason why you couldn't
provide something similar. No need for a wrapper, as depending on the
platform, you'd provide a different BSP and a different startup and
for bigger ARM's, that'd be ASM. This ASM could be conditionally
assembled if need be for different ARM's.

Thanks,
Luke.



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

* Re: How do I disable elaboration code on this
  2011-04-11 21:40                       ` Lucretia
@ 2011-04-11 23:12                         ` Lucretia
  2011-04-11 23:16                           ` Lucretia
  2011-04-11 23:31                           ` Lucretia
  0 siblings, 2 replies; 38+ messages in thread
From: Lucretia @ 2011-04-11 23:12 UTC (permalink / raw)


On Apr 11, 10:40 pm, Lucretia <Lucretia9...@yahoo.co.uk> wrote:

> I will upload a sample project to GitHub if I get the time that should
> help us.

Here's the repo:

https://github.com/Lucretia/XpressAda

This uses the compiler built from my TAMP project.

Luke.



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

* Re: How do I disable elaboration code on this
  2011-04-11 23:12                         ` Lucretia
@ 2011-04-11 23:16                           ` Lucretia
  2011-04-11 23:31                           ` Lucretia
  1 sibling, 0 replies; 38+ messages in thread
From: Lucretia @ 2011-04-11 23:16 UTC (permalink / raw)


I forgot to mention that it builds, but I don't know ARM ASM well
enough to know if it's generating the right code yet :D

It is, at least, not generating all of the elaboration code for the
vectors.

Luke.



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

* Re: How do I disable elaboration code on this
  2011-04-11 23:12                         ` Lucretia
  2011-04-11 23:16                           ` Lucretia
@ 2011-04-11 23:31                           ` Lucretia
  2011-04-12  5:22                             ` Simon Wright
  2011-04-12 17:07                             ` Simon Clubley
  1 sibling, 2 replies; 38+ messages in thread
From: Lucretia @ 2011-04-11 23:31 UTC (permalink / raw)


On Apr 12, 12:12 am, Lucretia <Lucretia9...@yahoo.co.uk> wrote:

> Here's the repo:
>
> https://github.com/Lucretia/XpressAda

Renamed it, sorry:

https://github.com/Lucretia/xpressada



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

* Re: How do I disable elaboration code on this
  2011-04-11 23:31                           ` Lucretia
@ 2011-04-12  5:22                             ` Simon Wright
  2011-04-12 17:07                             ` Simon Clubley
  1 sibling, 0 replies; 38+ messages in thread
From: Simon Wright @ 2011-04-12  5:22 UTC (permalink / raw)


Lucretia <Lucretia9000@yahoo.co.uk> writes:

> On Apr 12, 12:12 am, Lucretia <Lucretia9...@yahoo.co.uk> wrote:

> https://github.com/Lucretia/xpressada

There's already a section .isr in link.ld (commented out), might be the
thing to use? At least you know it'll be first!



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

* Re: How do I disable elaboration code on this
  2011-04-11 23:08                   ` Lucretia
@ 2011-04-12 11:50                     ` Simon Clubley
  2011-04-12 16:48                       ` Lucretia
  0 siblings, 1 reply; 38+ messages in thread
From: Simon Clubley @ 2011-04-12 11:50 UTC (permalink / raw)


On 2011-04-11, Lucretia <Lucretia9000@yahoo.co.uk> wrote:
> On Apr 11, 12:59�pm, Simon Clubley <clubley@remove_me.eisner.decus.org-
> Earth.UFP> wrote:
>
>> The issue here is that when the Cortex M3 comes out of reset it reads,
>> and loads, the stack pointer from the first longword in that array
>> and then jumps to the address specified by the second longword.
>>
>> To Luke: are you targetting only the Cortex M3 or traditional ARM7
>> devices as well ?
>
> Not yet. It's just that the M3 doesn't actually need ASM for C/C++
> projects, I wanted to see if I could do the same from Ada.
>
> At the moment, I have a Cortex-M3 board so that shall be my target, I
> intend to write an equivalent of CMSIS for use as the BSP for these
> chips.
>
> As for ARM7 or other ARM's, there's no real reason why you couldn't
> provide something similar. No need for a wrapper, as depending on the
> platform, you'd provide a different BSP and a different startup and
> for bigger ARM's, that'd be ASM. This ASM could be conditionally
> assembled if need be for different ARM's.
>

Misleading choice of words on my part. By wrapper, I meant calling the
the Ada program from a assembly based startup routine; ie: wrapping the
Ada code within a outer layer of startup assembly code.

I've had another idea about how you may be able to implement this and
that is by defining the vector table in the linker script itself.

This is just a theory; I have no experience of the Cortex M3 and I don't
do in linker scripts what I am to suggest (I take the traditional approach
of defining a vector section in my ARM7 assembly startup code) so I don't
know if something I have not considered will stop you from doing this.

If you read the Output Section Data part of the GNU ld manual at:

http://sourceware.org/binutils/docs/ld/Output-Section-Data.html#Output-Section-Data

you will see that you can actually insert linker script defined values
(as opposed to just symbols) into the output image itself.

If you use a series of "LONG(addr)" statements in the vectors section of
your linker script, where addr is the name of the Ada vector routine in
question for that vector, (or the symbol containing the SP starting value
for the first LONG(addr)), you may be able to construct the vector table
in the linker script itself.

BTW, if this appears to work, I suggest you use your cross-compiled objdump
to verify that the generated table appears to be as you would expect it to
be.

Simon.

-- 
Simon Clubley, clubley@remove_me.eisner.decus.org-Earth.UFP
Microsoft: Bringing you 1980s technology to a 21st century world



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

* Re: How do I disable elaboration code on this
  2011-04-12 11:50                     ` Simon Clubley
@ 2011-04-12 16:48                       ` Lucretia
  0 siblings, 0 replies; 38+ messages in thread
From: Lucretia @ 2011-04-12 16:48 UTC (permalink / raw)


> you will see that you can actually insert linker script defined values
> (as opposed to just symbols) into the output image itself.
>
> If you use a series of "LONG(addr)" statements in the vectors section of
> your linker script, where addr is the name of the Ada vector routine in
> question for that vector, (or the symbol containing the SP starting value
> for the first LONG(addr)), you may be able to construct the vector table

I have something similar this already on my blink app.

Luke



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

* Re: How do I disable elaboration code on this
  2011-04-11 23:31                           ` Lucretia
  2011-04-12  5:22                             ` Simon Wright
@ 2011-04-12 17:07                             ` Simon Clubley
  1 sibling, 0 replies; 38+ messages in thread
From: Simon Clubley @ 2011-04-12 17:07 UTC (permalink / raw)


On 2011-04-11, Lucretia <Lucretia9000@yahoo.co.uk> wrote:
>
> Renamed it, sorry:
>
> https://github.com/Lucretia/xpressada

I've just had a quick look at the code.

While I understand your focus on setting up the Ada vector routines in the
vector table, I wonder if it would be wise to also look at the requirement
to store the value (at 16#00000000#) to be used for the initial stack
pointer in case that shows up any additional issues with elaboration (or
anything else).

One obvious model would be to have a record with a initial 32 bit address
variable followed by a array of Cb as you have now.

The interesting question however, is how are you going to populate that
stack pointer variable ? Are you planning to use a hardcoded constant
within the Ada code or are you planning to define a symbol within the
linker script and import that into the Ada code ?

If it's the latter, I wonder if the compiler will generate any additional
unexpected elaboration code or if the generated code will just reference
the linker symbol directly ?

Simon.

-- 
Simon Clubley, clubley@remove_me.eisner.decus.org-Earth.UFP
Microsoft: Bringing you 1980s technology to a 21st century world



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

* Re: How do I disable elaboration code on this
  2011-04-11 19:12                     ` Simon Wright
  2011-04-11 19:50                       ` Simon Wright
  2011-04-11 21:40                       ` Lucretia
@ 2011-04-13 16:53                       ` Simon Wright
  2011-04-15  8:38                       ` Simon Wright
  3 siblings, 0 replies; 38+ messages in thread
From: Simon Wright @ 2011-04-13 16:53 UTC (permalink / raw)


Simon Wright <simon@pushface.org> writes:

> Does the LSB really have to be set to 1? The Cortex-M3 only implements
> Thumb instructions, doesn't it?

Both Thumbulator and QEMU (-cpu cortex-m3) are happy with or without the
least significant bit being set to 1.

(That was a _very_ entertaining excursion through a new assembler and
 some new-to-me features of objcopy).

Of course, not the same as a real Cortex-M3 board!



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

* Re: How do I disable elaboration code on this
  2011-04-11  8:54             ` Lucretia
  2011-04-11 10:10               ` Simon Wright
  2011-04-11 11:19               ` Georg Bauhaus
@ 2011-04-14 19:19               ` Florian Weimer
  2 siblings, 0 replies; 38+ messages in thread
From: Florian Weimer @ 2011-04-14 19:19 UTC (permalink / raw)


* Lucretia:

> The problem has nothing to do with the linker, I'm using binutils and
> gnat that I'e built myself. The problem is that GNAT is generating
> elaboration code where it is not allowed, i.e. code that 1)
> initialises  the array to 0 and 2) code that the copies function
> addresses into the array.

I believe that this is simply a missed optimization opportunity in
GNAT.  There have been some changes to increase the number of cases
where initialization can be preelaborated, but this particular area
has not been covered so far.

As for workarounds, using an .S file which allocates the object at the
right address and initializes it seems to be the best way to deal with
this issue at present.  Or you could use a C file and a section
attribute.  C treats pointers to function designators as constant
expressions, but there does not seem to be a C extension which allows
one to specify the address of an object.



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

* Re: How do I disable elaboration code on this
  2011-04-11 19:12                     ` Simon Wright
                                         ` (2 preceding siblings ...)
  2011-04-13 16:53                       ` Simon Wright
@ 2011-04-15  8:38                       ` Simon Wright
  3 siblings, 0 replies; 38+ messages in thread
From: Simon Wright @ 2011-04-15  8:38 UTC (permalink / raw)


Simon Wright <simon@pushface.org> writes:

> Simon Wright <simon@pushface.org> writes:
>
>> The part about the LSB being set to 1 may cause difficulty! I suppose
>> one could say "Foo'Address + 1" (which means the vector would have to be
>> an array of System.Address, not so good but I think unavoidable??)
>
> And then we're back to the 'no elaboration code' problem.
>
> Does the LSB really have to be set to 1? The Cortex-M3 only implements
> Thumb instructions, doesn't it?

It turns out that (at GCC 4.6.0, binutils 2.21) GCC -mthumb marks
functions (subprograms) with the assembler directive .thumb_func; GAS
then sets the least significant bit in references to the subprogram. So,
no human interaction required.



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

end of thread, other threads:[~2011-04-15  8:38 UTC | newest]

Thread overview: 38+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2011-04-09 13:58 How do I disable elaboration code on this Lucretia
2011-04-09 16:57 ` Jeffrey Carter
2011-04-09 17:01   ` Simon Wright
2011-04-09 17:44     ` Ludovic Brenta
2011-04-09 19:19       ` Simon Wright
2011-04-09 19:32         ` Jeffrey Carter
2011-04-10  9:06           ` Lucretia
2011-04-10  9:31             ` Simon Wright
2011-04-09 19:35         ` Ludovic Brenta
2011-04-09 22:05           ` Simon Wright
2011-04-10  5:39             ` Simon Wright
2011-04-10 17:20   ` Lucretia
2011-04-10 20:12     ` Jeffrey Carter
2011-04-10 20:47     ` Georg Bauhaus
2011-04-10 21:19       ` Lucretia
2011-04-11  5:08         ` Lucretia
2011-04-11  6:28           ` Simon Wright
2011-04-11  8:54             ` Lucretia
2011-04-11 10:10               ` Simon Wright
2011-04-11 11:59                 ` Simon Clubley
2011-04-11 18:30                   ` Simon Wright
2011-04-11 19:12                     ` Simon Wright
2011-04-11 19:50                       ` Simon Wright
2011-04-11 21:40                       ` Lucretia
2011-04-11 23:12                         ` Lucretia
2011-04-11 23:16                           ` Lucretia
2011-04-11 23:31                           ` Lucretia
2011-04-12  5:22                             ` Simon Wright
2011-04-12 17:07                             ` Simon Clubley
2011-04-13 16:53                       ` Simon Wright
2011-04-15  8:38                       ` Simon Wright
2011-04-11 23:08                   ` Lucretia
2011-04-12 11:50                     ` Simon Clubley
2011-04-12 16:48                       ` Lucretia
2011-04-11 11:19               ` Georg Bauhaus
2011-04-11 13:50                 ` Simon Wright
2011-04-14 19:19               ` Florian Weimer
2011-04-10 16:34 ` Rolf

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