From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id ABAAE3858C74; Wed, 17 Aug 2022 02:32:49 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org ABAAE3858C74 From: "pinskia at gcc dot gnu.org" To: gcc-bugs@gcc.gnu.org Subject: [Bug target/106635] AARCH64 STUR instruction causes bus error Date: Wed, 17 Aug 2022 02:32:49 +0000 X-Bugzilla-Reason: CC X-Bugzilla-Type: changed X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: gcc X-Bugzilla-Component: target X-Bugzilla-Version: 11.2.1 X-Bugzilla-Keywords: wrong-code X-Bugzilla-Severity: normal X-Bugzilla-Who: pinskia at gcc dot gnu.org X-Bugzilla-Status: RESOLVED X-Bugzilla-Resolution: INVALID X-Bugzilla-Priority: P3 X-Bugzilla-Assigned-To: unassigned at gcc dot gnu.org X-Bugzilla-Target-Milestone: --- X-Bugzilla-Flags: X-Bugzilla-Changed-Fields: Message-ID: In-Reply-To: References: Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Bugzilla-URL: http://gcc.gnu.org/bugzilla/ Auto-Submitted: auto-generated MIME-Version: 1.0 X-BeenThere: gcc-bugs@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-bugs mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 17 Aug 2022 02:32:49 -0000 https://gcc.gnu.org/bugzilla/show_bug.cgi?id=3D106635 --- Comment #7 from Andrew Pinski --- (In reply to Xiaoguang from comment #6) > (In reply to Richard Earnshaw from comment #5) > > Your original code contains (after stripping out the volatile): > > u32 temp_32 =3D (u32)status_data_base_addr; > > *dst++ =3D temp_32; > > data_length++; > >=20=20 > > if(sizeof(addr_t) =3D=3D 8) { > > *dst++ =3D (u32)(((u64)status_data_base_addr)>>32); > > data_length++; > > } > >=20 > > Which of course on a 64-bit machine simplifies to=20 > >=20 > > u32 temp_32 =3D (u32)status_data_base_addr; > > *dst++ =3D temp_32; > > data_length++; > >=20=20 > > *dst++ =3D (u32)(((u64)status_data_base_addr)>>32); > > data_length++; > >=20 > > And which the compiler then further simplifies to=20 > >=20 > > *([unaligned]u64*)dst =3D status_data_base_addr; > > data_length +=3D 2; > > dst +=3D 2; > >=20 > > If the location that dst points to is in normal, cachable, memory, then= this > > will be fine. But if you're writing to non-cachable memory, then you m= ight > > get a trap. > Thanks Very much for the explaination, Can you tell me why unaligned acce= ss > only works in normal cachable memory? where does this constraint come fr= om?=20 The architect (armv8) explains this. Basically the hardware does not know w= hat to do when there is a unaligned access as it has to two reads and two write= s to get the data correct. It in the arm armv8 document. >=20 > >=20 > > the correct fix is to mark dst as volatile in this case. > >=20 > > void CWLCollectReadRegData(volatile u32* dst,u16 reg_start, u32 > > reg_length,u32* > > total_length, addr_t status_data_base_addr)=