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.3 required=5.0 tests=BAYES_00,INVALID_MSGID autolearn=no autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,c78177ec2e61f4ac X-Google-Attributes: gid103376,public From: Geert Bosch Subject: Re: ada and robots Date: 1997/06/23 Message-ID: <5olje1$oov$1@gonzo.sun3.iaf.nl>#1/1 X-Deja-AN: 252778792 References: <97061611223212@psavax.pwfl.com> Organization: La Calandre Infortunee Newsgroups: comp.lang.ada Date: 1997-06-23T00:00:00+00:00 List-Id: Robert Dewar wrote: ``This hardware accepted ONLY word (4-byte) memory requests, and simply malfunctioned in a completely unpredictable manner if byte memory requests were received. [...] The fix turned out to be simple, by changing the code to type Bits is array (0..31) of Boolean; GNAT could be persuaded to generate the word sequence. But there code was always relying in an undocumented way on the particular choice of the compiler, and for that matter, still is. '' IMO it is an obvious bug to do memory I/O to such a device using an unconstrained array type without any representation clauses or whatever. From such a device you should only read data with 'Size=32 and pragma Atomic applied: type Bits is array (0 .. 31) of Boolean; pragma Pack (Bits); pragma Atomic (Bits); for Bits'Size use 32; Certainly I would not expect any compiler to read elements from Bits using byte reads in this case. For larger bit arrays than 32 bits I would choose to map the entire device memory using a constrained array of Bits, like: type Word_Index is range 0 .. 2**32 - 1; type Words is array (Word_Index range <>) of Bits; subtype Video_Words is array (0 .. 16#3FFF#); Of course this can only guarantee 32-bits memory-mapped I/O on a machine with a 32-bit I/O bus. A much harder problem is to ensure only byte-reads. I agree with Robert that in cases like this the only good solution is to use machine code insertions, since there is no way in Ada to forbid a compiler to read several array elements at a time. It would seem natural for the compiler to use memory reads of exactly Component_Size if supported by the hardware and pragma Atomic_Components is specified for the type, but counting on it is dangerous. Regards, Geert