From patchwork Tue May 2 12:46:59 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Laurent Alfonsi X-Patchwork-Id: 98441 Delivered-To: patch@linaro.org Received: by 10.140.109.52 with SMTP id k49csp1855634qgf; Tue, 2 May 2017 05:47:21 -0700 (PDT) X-Received: by 10.99.113.15 with SMTP id m15mr29887368pgc.120.1493729240991; Tue, 02 May 2017 05:47:20 -0700 (PDT) Return-Path: Received: from sourceware.org (server1.sourceware.org. [209.132.180.131]) by mx.google.com with ESMTPS id s26si18041734pge.221.2017.05.02.05.47.20 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 02 May 2017 05:47:20 -0700 (PDT) Received-SPF: pass (google.com: domain of newlib-return-14561-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; spf=pass (google.com: domain of newlib-return-14561-patch=linaro.org@sourceware.org designates 209.132.180.131 as permitted sender) smtp.mailfrom=newlib-return-14561-patch=linaro.org@sourceware.org DomainKey-Signature: a=rsa-sha1; c=nofws; d=sourceware.org; h=list-id :list-unsubscribe:list-subscribe:list-archive:list-post :list-help:sender:message-id:date:from:mime-version:to:subject :content-type; q=dns; s=default; b=m0w0lkGYKeaDITcpozvkPFb9jF2C9 vwrf5BsFPJla8r3A08xnT7jhu+agyyU7GAixounv+SM889qzBJQ3E6tsOwZkqZl7 GnyoU2zWb/Y/LIoXOeZkCXVAwrKfk1oTlzmycaRMczd97+rtskpcMllGOxBoc1Hr fy/AQzMUoDDg1k= 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:message-id:date:from:mime-version:to:subject :content-type; s=default; bh=wbkSGZMY8xVMMoED/PUTE21OvY8=; b=dZa oubFtpOvvuoXip+ySXHU1QnI+hknHiqAA380csGaa7xN2GouG/neIX9ulaQ+S9j/ xXrQJxsiMGiOJfliEMLbq8W2E57PZEy9NwesX/Pm7f+qjWmIHwS+KYGRIzJ6yT/4 a0Mf89Y8EH3oEvbPuLK618mU+Hj70/wriLxlLEUU= Received: (qmail 42199 invoked by alias); 2 May 2017 12:47:07 -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 42175 invoked by uid 89); 2 May 2017 12:47:06 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-27.6 required=5.0 tests=BAYES_00, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, RCVD_IN_DNSWL_LOW, SPF_PASS autolearn=ham version=3.3.2 spammy=H*UA:14.0, angel, Angel, Hx-languages-length:3675 X-HELO: mx07-00178001.pphosted.com Received: from mx07-00178001.pphosted.com (HELO mx07-00178001.pphosted.com) (62.209.51.94) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Tue, 02 May 2017 12:47:04 +0000 Received: from pps.filterd (m0046668.ppops.net [127.0.0.1]) by mx07-00178001.pphosted.com (8.16.0.11/8.16.0.11) with SMTP id v42Cl2Sg030239 for ; Tue, 2 May 2017 14:47:03 +0200 Received: from beta.dmz-eu.st.com (beta.dmz-eu.st.com [164.129.1.35]) by mx07-.pphosted.com with ESMTP id 2a4g9x1v2m-1 (version=TLSv1 cipher=ECDHE-RSA-AES256-SHA bits=256 verify=NOT) for ; Tue, 02 May 2017 14:47:03 +0200 Received: from zeta.dmz-eu.st.com (zeta.dmz-eu.st.com [164.129.230.9]) by beta.dmz-eu.st.com (STMicroelectronics) with ESMTP id AFC0A38 for ; Tue, 2 May 2017 12:47:00 +0000 (GMT) Received: from Webmail-eu.st.com (sfhdag5node3.st.com [10.75.127.15]) by zeta.dmz-eu.st.com (STMicroelectronics) with ESMTP id 619B41644 for ; Tue, 2 May 2017 12:47:00 +0000 (GMT) Received: from [164.129.122.187] (10.75.127.50) by SFHDAG5NODE3.st.com (10.75.127.15) with Microsoft SMTP Server (TLS) id 15.0.1178.4; Tue, 2 May 2017 14:47:00 +0200 Message-ID: <59087FC3.3050605@st.com> Date: Tue, 2 May 2017 14:46:59 +0200 From: Laurent Alfonsi User-Agent: Mozilla/5.0 (X11; Linux i686 on x86_64; rv:14.0) Gecko/20120713 Thunderbird/14.0 MIME-Version: 1.0 To: Subject: [PATCH] ARM / AArch64: Fix GetCmdLine semihosting directives X-ClientProxiedBy: SFHDAG5NODE2.st.com (10.75.127.14) To SFHDAG5NODE3.st.com (10.75.127.15) X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10432:, , definitions=2017-05-02_08:, , signatures=0 X-IsSubscribed: yes All, There's currently a problem in ARM & AArch64 crt0 on the GetCommandLine semihosting invocation. I am proposing this patch to fix the issue. Tested with versions : gcc 5.4, binutils 2.26, qemu-arm / qemu-aarch64 2.5.0. Would it be ok to commit ? Regards, Laurent Alfonsi >From 12968a3744777fe4daac6a03cb76303e952664cc Mon Sep 17 00:00:00 2001 From: Laurent ALFONSI Date: Tue, 18 Apr 2017 17:50:16 +0200 Subject: [PATCH] ARM/AArch64: Fix GetCmdLine semihosting directives 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: - libgloss/arm/crt0.S : Arguments passed to the AngelSWI_Reason_GetCmdLine semihosting invocation are placed into .data section instead of .text - libgloss/aarch64/crt0.S : Idem for aarch64 AngelSVC_Reason_GetCmdLine semihosting. --- libgloss/aarch64/crt0.S | 11 +++++++---- libgloss/arm/crt0.S | 9 ++++++--- 2 files changed, 13 insertions(+), 7 deletions(-) diff --git a/libgloss/aarch64/crt0.S b/libgloss/aarch64/crt0.S index fdfc174..42673fb 100644 --- a/libgloss/aarch64/crt0.S +++ b/libgloss/aarch64/crt0.S @@ -166,11 +166,12 @@ /* Fetch and parse the command line. */ #ifdef ARM_RDI_MONITOR - adr x1, .Lcmdline /* Command line descriptor. */ + ldr x1, .Lcmdline /* Command line descriptor. */ mov w0, #AngelSVC_Reason_GetCmdLine AngelSVCAsm AngelSVC #endif ldr x8, .Lcmdline + ldr x8, [x8] mov x0, #0 /* argc */ mov x1, sp /* argv */ @@ -267,9 +268,8 @@ FUNCTION (_cpu_init_reset): .Lenvp: GEN_DWORD env .Lcmdline: - GEN_DWORD CommandLine - .dword 511 - + GEN_DWORD AngelSVCArgs + /* Workspace for Angel calls. */ .data .align 3 @@ -287,3 +287,6 @@ StackBase: GEN_DWORD __stack StackLimit: .dword 0 env: .dword 0 /* Dummy environment array */ CommandLine: .space 512,0 /* Maximum length of 511 chars handled. */ +AngelSVCArgs: + GEN_DWORD CommandLine + .dword 511 diff --git a/libgloss/arm/crt0.S b/libgloss/arm/crt0.S index 78bc467..709b71c 100644 --- a/libgloss/arm/crt0.S +++ b/libgloss/arm/crt0.S @@ -294,9 +294,10 @@ __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 */ AngelSWIAsm AngelSWI ldr r1, .LC30 + ldr r1, [r1] #endif /* Parse string at r1 */ movs r0, #0 /* count of arguments so far */ @@ -503,8 +504,7 @@ change_back: #endif #ifdef ARM_RDI_MONITOR .LC30: - .word CommandLine - .word 511 + .word AngelSWIArgs .LC31: .word __end__ @@ -517,6 +517,9 @@ HeapLimit: .word 0 __stack_base__: .word 0 StackLimit: .word 0 CommandLine: .space 512,0 /* Maximum length of 511 chars handled. */ +AngelSWIArgs: + .word CommandLine + .word 511 #endif #ifdef __pe__ -- 1.9.1