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=-1.9 required=5.0 tests=BAYES_00 autolearn=unavailable autolearn_force=no version=3.4.4 Path: eternal-september.org!reader01.eternal-september.org!reader02.eternal-september.org!news.eternal-september.org!news.eternal-september.org!news.eternal-september.org!feeder.eternal-september.org!news.swapon.de!fu-berlin.de!uni-berlin.de!individual.net!not-for-mail From: Niklas Holsti Newsgroups: comp.lang.ada Subject: Re: Best representation for spares Date: Sun, 16 Feb 2014 12:02:41 +0200 Organization: Tidorum Ltd Message-ID: References: <215f6df2-a7ec-42f4-ac82-656d5b12bf61@googlegroups.com> <8383f5d6-3f66-415b-ab3f-8801fa377a6b@googlegroups.com> <8200939f-9bbd-44dd-848c-00c663f37121@googlegroups.com> <1e41e2d6-7ff8-445d-9c14-14c49b244bcf@googlegroups.com> Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit X-Trace: individual.net IOsEC+m7flbawJSjyjPLsQydayubSaxSQRM5eLel5LKoL/r5M8 Cancel-Lock: sha1:TALmAj1Ny1kbNaRBSWm8at1rdkE= User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.8; rv:24.0) Gecko/20100101 Thunderbird/24.3.0 In-Reply-To: <1e41e2d6-7ff8-445d-9c14-14c49b244bcf@googlegroups.com> Xref: news.eternal-september.org comp.lang.ada:18605 Date: 2014-02-16T12:02:41+02:00 List-Id: On 14-02-15 23:35 , Rego, P. wrote: > On Saturday, February 15, 2014 6:25:27 PM UTC-2, Rego, P. wrote: >> type Zero_Bit is new Boolean; >> type Zero_Bits is array (Positive range <>) of Zero_Bit; >> for Zero_Bits'Component_Size use 1; >> type Auxiliary_Interrupt_Status_Type is >> record >> Mini_Uart_IRQ : Boolean; >> SPI_1_IRQ : Boolean; >> SPI_2_IRQ : Boolean; >> Spare : Zero_Bits (3 .. 31) := (3 .. 31 => 0); >> end record; > > The only thing when I use this approach, in > > Auxiliary_Peripherals_Register_Map : Auxiliary_Peripherals_Register_Map_Type; (You are using a different record type name here -- not Auxiliary_Interrupt_Status_Type -- I assume it is an unimportant mistake.) > for Auxiliary_Peripherals_Register_Map'Address use > System'To_Address (16#7E21_5000#); Here you are "overlaying" a record object on a specific storage location, presumably a memory-mapped I/O control register. This is OK, but it has consequences... > I get from compiler the warnings > >> default initialization of "Auxiliary_Peripherals_Register_Map" >> may modify overlaid storage >> use pragma Import for "Auxiliary_Peripherals_Register_Map" to >> suppress initialization (RM B.1(24)) The compiler is warning you that the initialization of the Spare component will take place during the elaboration of the declaration of Auxiliary_Peripherals_Register_Map, which is usually not what one wants to happen with memory-mapped I/O registers. Usually, such registers are initialized by explicit assignment statements later on, in the system initialization procedure. > But in this case I do not want to suppress initialization. Why not? If the Spare bits are documented as "reserved", there should not be any need to initialize just them, and your record type (the one that is declared in the quote) does not default-initialize any other components, which means that the default initialization gives them some garbage values. Or leaves them unchanged, if it can write only to the Spare bits (unlikely, and partial-word access to mmio registers is usually not desirable anyway -- look into using the Atomic aspect for such objects). > What to do to eliminate this warning? You can suppy an explicit initialization in the object declaration, even one using the default initial values for all components: Auxiliary_Peripherals_Register_Map: Auxiliary_Peripherals_Register_Map_Type := (others => <>); -- ^^^^^^^^^^^^^^^^^^ -- Explicit initialization using default initial values. for Auxiliary_Peripherals_Register_Map'Address use System'To_Address (16#7E21_5000#); However, this assigns *unknown* values to the components without default initial values, that is, the xxx_IRQ components. You probably want to initialize these components to False, to avoid spurious invocation of the interrupt handlers. I would not put any default initializations in record types that I intend to overlay onto mmio registers. > I took a look on ARM B.1(24), and it says > > "The declaration of an imported object shall not include > an explicit initialization expression. Default > initializations are not performed." > > So what should actually happen in this case if I use > Spare : Zero_Bits (3 .. 31) := (3 .. 31 => 0); That is a default initialization. As the RM says, if the object is imported, the default initialization is not done, just as if you had declared the component without it, as Spare : Zero_Bits (3 .. 31); Moreover, the RM section you quote makes it illegal to give an explicit initialization (as in my example above) for an imported object. Thus, to "initialize" an imported object, you must use an ordinary assignment statement. The declaration of an imported object cannot initialize it. -- Niklas Holsti Tidorum Ltd niklas holsti tidorum fi . @ .