From: Niklas Holsti <niklas.holsti@tidorum.invalid>
Subject: Re: Record initialisation question
Date: Thu, 14 Jan 2021 16:27:09 +0200 [thread overview]
Message-ID: <i6b2ltFcg4hU1@mid.individual.net> (raw)
In-Reply-To: <60004212$0$13563$426a34cc@news.free.fr>
On 2021-01-14 15:07, DrPi wrote:
>
>> The problem is that "static" in Ada means "known at compile time",
>> while addresses, although static in execution, are generally not known
>> until link time. A case where assembly language is more powerful :-(
>>
> Or C :(
> I use the manufacturer C code generated by their tool as reference. In
> C, initializing a structure element with an address is not a problem.
The C compiler emits a relocatable reference to the addressed object,
and the linker replaces it with the absolute address. An Ada compiler
should be able to do the same thing when the address of a statically
allocated object is used to initialize another statically allocated
object, assuming that the initialization expression is simple enough to
require no run-time computation. Perhaps part of the reason why that
does not happen is that System.Address is a private type, and might not
be an integer type.
Do you (or someone) know if the C language standard guarantees that such
initializations will be done by the linker, and not by the C start-up
code that is analogous to Ada elaboration code?
Can you ask your Ada compiler vendor for suggestions? Assuming you have
support from them.
>>> I have to find a workaround.
>>
>> If addresses are the only problem, and you are in control of the flash
>> memory lay-out, you might be able to define static Ada constant
>> expressions that compute ("predict") the addresses of every boot data
>> structure record. But those expressions would need to use the sizes of
>> the records, I think, and unfortunately the 'Size of a record type is
>> not a static expression (IIRC), and that may hold also for the
>> GNAT-specific 'Max_Size_In_Storage_Units.
>
> I can redefine the records with UInt32 instead of System.Address. The
> problem is : What is the expression to convert from Address to UInt32
> without using a function ?
You could try Unchecked_Conversion or System.Storage_Units.To_Integer.
But my suggestion did not involve such conversions: I assumed that you
would be able to compute, using static universal-integer expressions,
the addresses for all your flash objects, and use those directly in the
record aggregates. This assumes that you are able to define the lay-out
of all the stuff in the flash. You might then also specify the 'Address
of each flash object, using those same universal-integer expressions.
Something like this (not tested with a compiler):
Flash_Start : constant := 16#500#;
Obj_A_Addr : constant := Flash_Start;
Obj_B_Addr : constant := Obj_A_Addr + 16#234#;
-- Here 16#234# is supposed to be the size of Obj_A, so that
-- Obj_B follows Obj_A in flash.
Obj_A : constant Dcd_T := (
Next => Obj_B_Addr,
...);
for Obj_A'Address
use System.Storage_Elements.To_Address (Obj_A_Addr);
next prev parent reply other threads:[~2021-01-14 14:27 UTC|newest]
Thread overview: 32+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-01-09 9:30 Record initialisation question DrPi
2021-01-09 10:46 ` Dmitry A. Kazakov
2021-01-10 16:41 ` DrPi
2021-01-11 21:48 ` Shark8
2021-01-12 11:38 ` Simon Wright
2021-01-12 15:01 ` Shark8
2021-01-14 21:32 ` Simon Wright
2021-01-14 23:12 ` Shark8
2021-01-14 12:58 ` DrPi
2021-01-17 17:03 ` DrPi
2021-01-17 23:55 ` Shark8
2021-01-18 20:02 ` DrPi
2021-01-19 5:50 ` Randy Brukardt
2021-01-09 15:44 ` Niklas Holsti
2021-01-10 16:53 ` DrPi
2021-01-10 19:30 ` Niklas Holsti
2021-01-10 21:27 ` DrPi
2021-01-10 22:14 ` Niklas Holsti
2021-01-11 17:46 ` DrPi
2021-01-11 20:58 ` Niklas Holsti
2021-01-14 13:07 ` DrPi
2021-01-14 13:36 ` AdaMagica
2021-01-14 14:07 ` Jeffrey R. Carter
2021-01-14 14:09 ` Jeffrey R. Carter
2021-01-14 14:27 ` Niklas Holsti [this message]
2021-01-14 16:53 ` Shark8
2021-01-15 7:50 ` DrPi
2021-01-15 18:15 ` Shark8
2021-01-16 10:28 ` DrPi
2021-01-14 16:59 ` Paul Rubin
2021-01-15 7:49 ` DrPi
2021-01-17 17:08 ` DrPi
replies disabled
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox