From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-40130.protonmail.ch (mail-40130.protonmail.ch [185.70.40.130]) by sourceware.org (Postfix) with ESMTPS id 191D53896839 for ; Wed, 17 Feb 2021 12:02:52 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org 191D53896839 Date: Wed, 17 Feb 2021 12:02:44 +0000 To: Richard Earnshaw From: iNvEr7 Cc: "newlib@sourceware.org" Reply-To: iNvEr7 Subject: Re: [PATCH] Semihosting ctr0 typo (adr/ldr)? Message-ID: In-Reply-To: <28425b94-60e9-b6b5-7f95-613937995044@foss.arm.com> References: <2SG25aQ-_EdUvM9w1kXfGjpV_I6OSbvGLA9jIuXTs51Rzc7ESf1s9rIDWF85eATSD7jtZle5D2asRAeEEwtJs5adLfOf_c-uOa3myGWT-Ys=@protonmail.com> <28425b94-60e9-b6b5-7f95-613937995044@foss.arm.com> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable X-Spam-Status: No, score=-12.5 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, FREEMAIL_ENVFROM_END_DIGIT, FREEMAIL_FROM, FREEMAIL_REPLYTO_END_DIGIT, GIT_PATCH_0, RCVD_IN_DNSWL_LOW, RCVD_IN_MSPIKE_H3, RCVD_IN_MSPIKE_WL, SPF_HELO_PASS, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.2 X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on server2.sourceware.org X-BeenThere: newlib@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Newlib mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 17 Feb 2021 12:02:56 -0000 On Wednesday, February 17, 2021 3:22 AM, Richard Earnshaw wrote: > On 17/02/2021 10:01, Corinna Vinschen wrote: > > > On Feb 16 22:56, iNvEr7 via Newlib wrote: > > > > > libgloss/arm/crt0.S | 2 +- > > > newlib/libc/sys/arm/crt0.S | 2 +- > > > 2 files changed, 2 insertions(+), 2 deletions(-) > > > diff --git a/libgloss/arm/crt0.S b/libgloss/arm/crt0.S > > > index 8490bde2f..b8bbcee18 100644 > > > --- a/libgloss/arm/crt0.S > > > +++ b/libgloss/arm/crt0.S > > > @@ -283,7 +283,7 @@ > > > #ifdef ARM_RDI_MONITOR > > > /* Issue Angel SWI to read stack info. */ > > > movs r0, #AngelSWI_Reason_HeapInfo > > > > > > - adr r1, .LC0 /* Point at ptr to 4 words to receive data. */ > > > > > > - ldr r1, .LC0 /* Point at ptr to 4 words to receive data. / > > > #ifdef THUMB_VXM > > > bkpt AngelSWI > > > #elif defined(thumb2) > > > diff --git a/newlib/libc/sys/arm/crt0.S b/newlib/libc/sys/arm/crt= 0.S > > > index 5e677a23c..3c5771229 100644 > > > --- a/newlib/libc/sys/arm/crt0.S > > > +++ b/newlib/libc/sys/arm/crt0.S > > > @@ -270,7 +270,7 @@ > > > #ifdef ARM_RDI_MONITOR > > > / Issue Angel SWI to read stack info. */movs r0, #AngelSWI_Reason= _HeapInfo > > > > > > > > > - adr r1, .LC0 /* Point at ptr to 4 words to receive data. */ > > > > > > - ldr r1, .LC0 /* Point at ptr to 4 words to receive data. */ > > > #ifdef THUMB_VXM > > > bkpt AngelSWI > > > #elif defined(thumb2) > > > -- > > > 2.29.2 > > > > > > > I'm a bit suprised that this problem hasn't been noticed for the > > last 10 years. I'm not familiar with the ARM stuff at all, so maybe > > somebody from ARM can chime in here? > > Thanks, > > Corinna > > No, I don't think that is right, but it took some digging to be sure. > > The specification for the HeapInfo syscall is here: > > https://developer.arm.com/documentation/100863/0300/Semihosting-operation= s/SYS-HEAPINFO--0x16-?lang=3Den > > and it says that the parameter is the /address of a pointer/ to the > 4-word block. In other words, it is not the address of the block itself. > > It's odd that it is defined this way, but I think the code is doing what > the specification says. Certainly the comments in the code seem to > reflect this. > > R. Thanks for clarifying this. It is indeed an odd definition. I encountered a= crash when running a newlib-linked bare-metal binary on QEMU with semihost= ing enabled. I narrowed down the crash to the heapinfo semihosting call in = the crt0. Now we know it's the QEMU implementation's problem, not newlib. I= t seems they are the one misinterpreted the ARM spec. I will open an issue = to QEMU instead.