From patchwork Fri Aug 2 12:33:43 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alexander Fedotov X-Patchwork-Id: 170428 Delivered-To: patch@linaro.org Received: by 2002:a92:512:0:0:0:0:0 with SMTP id q18csp759096ile; Fri, 2 Aug 2019 05:34:11 -0700 (PDT) X-Google-Smtp-Source: APXvYqy7VRjvkFoqtkDH1w4Om+1mjxTnjKUx73olF7EN+E4oO/ypUVU5WAsrObVxaDIoj0YUpc4X X-Received: by 2002:aa7:8619:: with SMTP id p25mr38680587pfn.220.1564749251273; Fri, 02 Aug 2019 05:34:11 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1564749251; cv=none; d=google.com; s=arc-20160816; b=rTJw9ZTIYwnpXgs16ZLuiOaWTp291lNXrJIDkJ50jBNu/ApwwicdRsLdULZuLorTxJ l72ZnpFW+2r24tgrpPZ1KsV6vNphKEiUmISVVtR73FjcwMJB3fUbctAtmntGN6L2udpB BAXyihmKEfH2KdRDi2rYB93pGxgswElgFO/YuXPVWTRd3sBBXrPbWaTulhyVHm4QkkCt ROT1gCqaAGZkDDwVKazZglBfC4D/sldwyxYnP21+LXcwukRt8E3dIpnuRb7SsQTy77OE ZN/yko399LabQC54jQPYDeo6CF/juybFdw4MTJiNExoMf6jjdaxKXTDyl2FQmS6xgNq/ uNSQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature:delivered-to:sender:list-help:list-post:list-archive :list-subscribe:list-unsubscribe:list-id:precedence:mailing-list :dkim-signature:domainkey-signature; bh=J5McYiSVh7yUmrtkMQCLDM3VqOtYloJvbIVucGp7ut8=; b=zGEaoYIK4PALQBqyum7I6IXEXLNupkjSQJ7+Y0qjRj9BSXwaj/zqh+IPqOTS93Mqg+ S3mYm5fkjPIzL5iY7gWIHng9uuUl5tYIpguWxzG226PHGj2UEJU3Ii32u0sc2LSkAd00 SkryVXAwvbODJ/5/Lv7I0/2Is1hGlBa//hFOfFXI/fRq5ylVGLDOpd4TO6ncJKagtbeH w3Z2e93FQF2HSTHPH3Wl5TjTQHxD3yc90/WGDLfp4TOE9XzCjY+afxXg1IOhSe6sMCTH qucINCn2ec1T0RBRhlnYc0x1FxSRib17MxRRtW/Lf+6LXw7OY8igo3L6t80UPkaBzh8z iyrw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@sourceware.org header.s=default header.b=Wcb21DkI; dkim=pass header.i=@gmail.com header.s=20161025 header.b=jwZLo83I; spf=pass (google.com: domain of newlib-return-17119-patch=linaro.org@sourceware.org designates 209.132.180.131 as permitted sender) smtp.mailfrom="newlib-return-17119-patch=linaro.org@sourceware.org"; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from sourceware.org (server1.sourceware.org. [209.132.180.131]) by mx.google.com with ESMTPS id z9si30133537pgk.46.2019.08.02.05.34.11 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 02 Aug 2019 05:34:11 -0700 (PDT) Received-SPF: pass (google.com: domain of newlib-return-17119-patch=linaro.org@sourceware.org designates 209.132.180.131 as permitted sender) client-ip=209.132.180.131; Authentication-Results: mx.google.com; dkim=pass header.i=@sourceware.org header.s=default header.b=Wcb21DkI; dkim=pass header.i=@gmail.com header.s=20161025 header.b=jwZLo83I; spf=pass (google.com: domain of newlib-return-17119-patch=linaro.org@sourceware.org designates 209.132.180.131 as permitted sender) smtp.mailfrom="newlib-return-17119-patch=linaro.org@sourceware.org"; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com DomainKey-Signature: a=rsa-sha1; c=nofws; d=sourceware.org; h=list-id :list-unsubscribe:list-subscribe:list-archive:list-post :list-help:sender:from:to:cc:subject:date:message-id:in-reply-to :references; q=dns; s=default; b=S2syXObBYYJyYiMhJAh7UbRvopinxoL UipE73YC75s0XMCPDszlaPPAZR7SlmdfMbO0VU5bniWJo9f3fCPiUyfLDW+kLWAT Z5+DCcR+rzLTJEiS1LAnAk3menqUNBYeB//y6YnZjxxD3JIgPyPZ+9+mfDwM7H/J cewgltsNY3E8= DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=sourceware.org; h=list-id :list-unsubscribe:list-subscribe:list-archive:list-post :list-help:sender:from:to:cc:subject:date:message-id:in-reply-to :references; s=default; bh=yPNjLivlbfIyjBaOtUOmu8lMU6U=; b=Wcb21 DkI+dFHDcwBPJojK3QLz1T299IiyU7LhkZw5VDO/Z+E/Zex3sbeeJPj2kTIFfcn2 ieupcIfR0NEZnaqCM6c+b513bEDKKWliY6n3QDsYzJk9gEhUCIgVFYU4aFvKdBJF pcZPQWbK0R4yj1K5R7AnPeihXn7bMVUs8vo4sQ= Received: (qmail 47520 invoked by alias); 2 Aug 2019 12:33:56 -0000 Mailing-List: contact newlib-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: newlib-owner@sourceware.org Delivered-To: mailing list newlib@sourceware.org Received: (qmail 47437 invoked by uid 89); 2 Aug 2019 12:33:55 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-26.0 required=5.0 tests=AWL, BAYES_00, FREEMAIL_FROM, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, RCVD_IN_DNSWL_NONE, SPF_PASS autolearn=ham version=3.3.1 spammy=modification X-HELO: mail-lj1-f172.google.com Received: from mail-lj1-f172.google.com (HELO mail-lj1-f172.google.com) (209.85.208.172) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Fri, 02 Aug 2019 12:33:54 +0000 Received: by mail-lj1-f172.google.com with SMTP id m23so72600774lje.12 for ; Fri, 02 Aug 2019 05:33:53 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=J5McYiSVh7yUmrtkMQCLDM3VqOtYloJvbIVucGp7ut8=; b=jwZLo83Ic+m5tUNNsB9jqJcIL6KsBwDgKcScJGCqkifoci0kQUgyMuqL9NvBluJQrK jWiw28rp2tRZda8eFRVl+pQ+GHsSGmSqSnp6l5i09aVJbDaCvUXgfBKOj5Nz/qnoAIGO l0Q121i+KWH3kETf0OcvLu2aQMEk6r+YzZ9jIXmW0k+rCbdzFelul0nIwwUx+DXDv4AU cIybmP8JrP8hhAufKtwdMgVTDZ969bBXExvTfwRkvcbR/TiK+htU3RBvGpDnalcHNjfo 047BrubtaKSOeGF8s6anaLakhqn+X1nSEuItzLM154swpJ8a3i3K3FoHAPQBXHTP7DP9 2Bdw== Return-Path: Received: from af-ubuntu18-hyperv.cmtknet.ru (relay.cmtk.ru. [195.5.145.226]) by smtp.gmail.com with ESMTPSA id u9sm12914135lfk.64.2019.08.02.05.33.51 (version=TLS1_3 cipher=AEAD-AES256-GCM-SHA384 bits=256/256); Fri, 02 Aug 2019 05:33:51 -0700 (PDT) From: Alexander Fedotov To: newlib@sourceware.org Cc: Alexander Fedotov Subject: [PATCH v2 1/4] Align libgloss/arm and libc/sys/arm sources: Fix GetCmdLine semihosting directives Date: Fri, 2 Aug 2019 07:33:43 -0500 Message-Id: <20190802123346.5377-2-alfedotov@gmail.com> In-Reply-To: <20190802123346.5377-1-alfedotov@gmail.com> References: <20190802123346.5377-1-alfedotov@gmail.com> Applied changes from the commit 9b11672: When simulating arm code, the target program startup code (crt0) uses semihosting invocations to get the command line from the simulator. The simulator returns the command line and its size into the area passed in parameter. (ARM 32-bit specifications : http://infocenter.arm.com/help/topic/com.arm.doc.dui0058d/DUI0058.pdf chapter "5.4.19 SYS_GET_CMDLINE"). The memory area pointed by the semihosting register argument is located in .text section (usually not writtable (RX)). If we run this code on a simulator that respects this rights properties (qemu user-mode for instance), the command line will not be written to the .text program memory, in particular the length of the string. The program runs with an empty command line. This problem hasn't been seen earlier probably because qemu user-mode is not so much used, but this can happen with another simulator that refuse to write in a read-only segment. With this modification, the command line can be correctly passed to the target program. Changes: - newlib/libc/sys/arm/crt0.S : Arguments passed to the AngelSWI_Reason_GetCmdLine semihosting invocation are placed into .data section instead of .text --- newlib/libc/sys/arm/crt0.S | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) -- 2.17.1 diff --git a/newlib/libc/sys/arm/crt0.S b/newlib/libc/sys/arm/crt0.S index 9c262428d..40bbc3d69 100644 --- a/newlib/libc/sys/arm/crt0.S +++ b/newlib/libc/sys/arm/crt0.S @@ -393,13 +393,14 @@ __change_mode: movs r1, r0 #else movs r0, #AngelSWI_Reason_GetCmdLine - adr r1, .LC30 /* Space for command line. */ + ldr r1, .LC30 /* Space for command line. */ #ifdef THUMB_VXM bkpt AngelSWI #else AngelSWIAsm AngelSWI #endif ldr r1, .LC30 + ldr r1, [r1] #endif /* Parse string at r1. */ movs r0, #0 /* Count of arguments so far. */ @@ -586,8 +587,7 @@ change_back: #endif #ifdef ARM_RDI_MONITOR .LC30: - .word CommandLine - .word 255 + .word AngelSWIArgs .LC31: .word __end__ @@ -600,6 +600,9 @@ HeapLimit: .word 0 __stack_base__: .word 0 StackLimit: .word 0 CommandLine: .space 256,0 /* Maximum length of 255 chars handled. */ +AngelSWIArgs: + .word CommandLine + .word 255 #endif #ifdef __pe__