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: border2.nntp.dca1.giganews.com!border1.nntp.dca1.giganews.com!nntp.giganews.com!newspeer1.nac.net!feeder.erje.net!eu.feeder.erje.net!eternal-september.org!feeder.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail From: MatthiasR Newsgroups: comp.lang.ada Subject: Re: Forcing GNAT to use 32-bit load/store instructions on ARM? Date: Sun, 20 Jul 2014 13:35:56 +0200 Organization: - Message-ID: References: <0e0b9ac2-e793-4cc5-8d8d-d3441ca28a58@googlegroups.com> <1j7b0m3yptffy$.1cztnkty8elrv$.dlg@40tude.net> Mime-Version: 1.0 Content-Type: text/plain; charset="ISO-8859-1" Content-Transfer-Encoding: 7Bit Injection-Date: Sun, 20 Jul 2014 11:42:38 +0000 (UTC) Injection-Info: mx05.eternal-september.org; posting-host="1ac4ede7ccea417d69ccb6e34af8286b"; logging-data="29683"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/2hiFtPXWaFwWrYBpTCki1Xc0/Y+QI5h8=" User-Agent: KNode/4.7.2 Cancel-Lock: sha1:PtHs+weuGWRV3Qw3v6jFkxK42YY= Xref: number.nntp.dca.giganews.com comp.lang.ada:187726 Date: 2014-07-20T13:35:56+02:00 List-Id: Randy Brukardt wrote: > [...] > >> Unfortunately there seem to be no way to force a specific access width, >> so this feature is not really useable (without the mentioned workaround >> with the temporary variable) on architectures where the allowed access >> width is not uniform over the whole address range. > > No, you're looking at this the wrong way. If you write this in C, you read > the entire register and then do some sort of bit-mask, and then write the > thing back. You have to do that same thing in Ada, just using the record > type instead of the bit mask. Ada replaces the bit masking operations by > more readable record component accesses; it doesn't suddenly allow you to > write something that you couldn't possibly write in C [a direct write of > part of a register]. (Whether Ada *should* have allowed you do to that is > a totally different question and relatively irrelevant at the moment > because the language isn't likely to support anything new in the near > future.) > > Randy. Ironically, there *is* another possibility, just in C. In principle, 'Volatile Bitfields', mapped to the register via a pointer, can be used. Bitfields are avoided by most C programmers because their layout is generally not well defined. Means to control the layout (like representation clauses in Ada) do not exist. At least for the ARM platform, the situation is more convenient: There are rules for the layout of bitfields given in the AAPCS (ABI specification for ARM, 'Procedure Call Standard for the ARM Architecture'). So, if the compiler is AAPCS-compliant, the layout of the bitfield records is exactly defined. Additionaly, the AAPCS requires in chapter 7.1.7.5 (http://infocenter.arm.com/help/topic/com.arm.doc.ihi0042e/IHI0042E_aapcs.pdf) that all reads or writes from/to volatile bitfields must be done 'using the access width appropriate to the type of the container'. The 'container' is not the record/struct as a whole, it is a type specifier given with each of the bitfields (this concept of a 'container type' is somewhat strange, I needed some time to get the idea of this...) Example: struct s { volatile int a:8; volatile char b:2 }; 'int' and 'char' are the 'container types' of the bitfields 'a' and 'b'. A AAPCS-compliant compiler must read or write 's.a' using a 32-bit access (assuming 'int' is 32 bit wide). Accesses to 's.b' must be 8 bit wide. So, if a C compiler is AAPCS-compliant, volatile bitfields should have the desired behaviour. Whether a compiler is *really* AAPCS-compliant, is another question. A well-known open source C compiler had bugs in this area in several releases. Last year, attempts were made to repair it. I don't know the current status. Matthias