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__ From patchwork Fri Aug 2 12:33:44 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alexander Fedotov X-Patchwork-Id: 170429 Delivered-To: patch@linaro.org Received: by 2002:a92:512:0:0:0:0:0 with SMTP id q18csp759245ile; Fri, 2 Aug 2019 05:34:19 -0700 (PDT) X-Google-Smtp-Source: APXvYqzZtYgvhBZk6RAYWNjwaQwMHF9iSY6wGETA3udJwk4VPE/KDRKyG5z5u8+v/jABMljWSirn X-Received: by 2002:a63:10a:: with SMTP id 10mr40403233pgb.281.1564749258932; Fri, 02 Aug 2019 05:34:18 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1564749258; cv=none; d=google.com; s=arc-20160816; b=ExJlb+RnOLVgcf/5UGK0RDx6PDMxrlYv6/pEpZhduG7LYnxLFSGcyvGzzpCKUdkhHB HbKMPmboHAxV85+wwYxtdZScG3hfbyAqfOilbkW2oNzAiy4Z/c3/n1omg8GrTFcbppmr LwY22gFiwtY629mr1dq/p9+G1fyuzYbrfzgzmfoWKmebN/r9Tqn21q/ojG2Ic8uRcWjb NDXIw5Gr7Bs320FY5x0gEuegSDzzcm7qH9rd+g/RQBqbAysg5OVAB1w7EAysbSfbp6i2 msD/4CsKSphKHnzVk7G9OVQRPDssbPO3g7ez0adJ4UFR7HrhG/huMwqmufHXLRgXzxry FnEg== 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=IL9CudBbhiDKUhDyvXAavj2G4Ul/zmv2Xv3miSuT/d0=; b=cc9pMb2J1y1lRrOPXNgmlQZwWrywTwX70/FjrENEtcsDOYuyA1oHVODkTpqXLDktXd UNXei72mB7ajfcjNgxH5VasuezOEogeJZxo7D4zefIWn/ZCln5KCfjjCvtOl5YGQiXu/ vKYQfMGhWpHOKn0Ca6/dpciZe5I81cDHihiLq+5Iwt7OPxowMwZwBt6RihgRFw9osA3j LS7vhvQWGaLAwWti2N+j0qrwQ4YSwtdwdeF7Zl2caAWERgjW7q65O7aJcGydJ2LHZKAI iMpsaC9DSB5p6gC8vZ7KR0/wt4DH9LIIvltcG8cKyTw9hRX6R1JEkmMhJJWI657/18S+ yZeA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@sourceware.org header.s=default header.b=CZ92zIr1; dkim=pass header.i=@gmail.com header.s=20161025 header.b=tEFcvuxL; spf=pass (google.com: domain of newlib-return-17120-patch=linaro.org@sourceware.org designates 209.132.180.131 as permitted sender) smtp.mailfrom="newlib-return-17120-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 188si39937095pgd.404.2019.08.02.05.34.18 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 02 Aug 2019 05:34:18 -0700 (PDT) Received-SPF: pass (google.com: domain of newlib-return-17120-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=CZ92zIr1; dkim=pass header.i=@gmail.com header.s=20161025 header.b=tEFcvuxL; spf=pass (google.com: domain of newlib-return-17120-patch=linaro.org@sourceware.org designates 209.132.180.131 as permitted sender) smtp.mailfrom="newlib-return-17120-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=y00lFCg6OQpUNiUSkdjMgnvqdSCdDa1 VN81r3ZhFVhuwb8Pk56dhlizTHr5hfreawH5KLKP5cMIjkymQzqFCCrnvyEkRZu9 Wak3rDqsSD2egrGipv9sS7HXdSstD+e3l9YzoUPZ3TkmyBGMJ5a573SmM8CmDKJr DRQCxGH64LZI= 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=SoVp94H44DLdZS2452WOYNjEkpU=; b=CZ92z Ir1/ZzfERsz8qs/nLE4aHmpPHBsGOuWE9k2ZO7PP7i+QxlAo9TXcRBXRck7NKUVL jev7yl2bQE34PAm820M49sOZcI+3jBMEfx7vvmgto481ngyDDkLaIfxwr+QsISJE 9KnIeYDkPbpHNXy950fFEgk07E7WFTKwB2Gh6k= Received: (qmail 47622 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 47525 invoked by uid 89); 2 Aug 2019 12:33:56 -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= X-HELO: mail-lj1-f193.google.com Received: from mail-lj1-f193.google.com (HELO mail-lj1-f193.google.com) (209.85.208.193) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Fri, 02 Aug 2019 12:33:54 +0000 Received: by mail-lj1-f193.google.com with SMTP id v24so72823319ljg.13 for ; Fri, 02 Aug 2019 05:33:54 -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=IL9CudBbhiDKUhDyvXAavj2G4Ul/zmv2Xv3miSuT/d0=; b=tEFcvuxLryTAVCFl+wtVZx682oNKKp+7LsaCS0byJA9fobUY0GykWjbz5TT9VZ3pgc +FAgcBVdPMHt/wRoLi5fJCxi65OHQX3eAFI29fJlhGvMwdEQX1ofKLqAL//e2Wfsmsc+ sFZMjpHvTpvhH2+g0a2sAFF1tVmx3dT3FnWkpCiywU2Eoda6QeuOPTluZ0l0A6KgPG+7 7oHcBufjkmq3O5Q2SMpkSJvmGaiKZ1p4ni74i+BO14WbSSesJu+tlgaLSlPVCE275gEi FcwcIpSZryHxxQ/m4L4Na+nyCKr2BToui1Wwd0sPtvFJvM65zmActsF4AQQTLjgeceUB AUpw== 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 2/4] Align libgloss/arm and libc/sys/arm sources: HeapInfo and __heap_limit Date: Fri, 2 Aug 2019 07:33:44 -0500 Message-Id: <20190802123346.5377-3-alfedotov@gmail.com> In-Reply-To: <20190802123346.5377-1-alfedotov@gmail.com> References: <20190802123346.5377-1-alfedotov@gmail.com> Applied changes from commit 8d98f95: * arm/crt0.S: Initialise __heap_limit when ARM_RDI_MONITOR is defined. * arm/syscalls.c: define __heap_limit global symbol. * arm/syscalls.c (_sbrk): Honour __heap_limit. Applied changes from commit 8d98f95: Fixed semihosting for ARM when heapinfo not provided by debugger --- libgloss/arm/syscalls.c | 12 ++++++------ newlib/libc/sys/arm/crt0.S | 7 +++++++ newlib/libc/sys/arm/syscalls.c | 9 +++++++-- 3 files changed, 20 insertions(+), 8 deletions(-) -- 2.17.1 diff --git a/libgloss/arm/syscalls.c b/libgloss/arm/syscalls.c index dacd1a9d3..3605e0fd0 100644 --- a/libgloss/arm/syscalls.c +++ b/libgloss/arm/syscalls.c @@ -707,15 +707,15 @@ uint __heap_limit = 0xcafedead; void * __attribute__((weak)) _sbrk (ptrdiff_t incr) { - extern char end asm ("end"); /* Defined by the linker. */ + extern char end asm ("end"); /* Defined by the linker. */ static char * heap_end; - char * prev_heap_end; + char * prev_heap_end; if (heap_end == NULL) heap_end = & end; - + prev_heap_end = heap_end; - + if ((heap_end + incr > stack_ptr) /* Honour heap limit if it's valid. */ || (__heap_limit != 0xcafedead && heap_end + incr > (char *)__heap_limit)) @@ -726,14 +726,14 @@ _sbrk (ptrdiff_t incr) extern void abort (void); _write (1, "_sbrk: Heap and stack collision\n", 32); - + abort (); #else errno = ENOMEM; return (void *) -1; #endif } - + heap_end += incr; return (void *) prev_heap_end; diff --git a/newlib/libc/sys/arm/crt0.S b/newlib/libc/sys/arm/crt0.S index 40bbc3d69..a55aa365b 100644 --- a/newlib/libc/sys/arm/crt0.S +++ b/newlib/libc/sys/arm/crt0.S @@ -282,6 +282,13 @@ #endif ldr r0, .LC0 /* Point at values read. */ + /* Set __heap_limit. */ + ldr r1, [r0, #4] + cmp r1, #0 + beq .LC33 + ldr r2, =__heap_limit + str r1, [r2] +.LC33: ldr r1, [r0, #0] cmp r1, #0 bne .LC32 diff --git a/newlib/libc/sys/arm/syscalls.c b/newlib/libc/sys/arm/syscalls.c index b52107491..a2997b44c 100644 --- a/newlib/libc/sys/arm/syscalls.c +++ b/newlib/libc/sys/arm/syscalls.c @@ -487,10 +487,13 @@ _getpid (void) return (pid_t)1; } +/* Heap limit returned from SYS_HEAPINFO Angel semihost call. */ +uint __heap_limit = 0xcafedead; + void * __attribute__((weak)) _sbrk (ptrdiff_t incr) { - extern char end asm ("end"); /* Defined by the linker. */ + extern char end asm ("end"); /* Defined by the linker. */ static char * heap_end; char * prev_heap_end; @@ -499,7 +502,9 @@ _sbrk (ptrdiff_t incr) prev_heap_end = heap_end; - if (heap_end + incr > stack_ptr) + if ((heap_end + incr > stack_ptr) + /* Honour heap limit if it's valid. */ + || (__heap_limit != 0xcafedead && heap_end + incr > (char *)__heap_limit)) { /* Some of the libstdc++-v3 tests rely upon detecting out of memory errors, so do not abort here. */ From patchwork Fri Aug 2 12:33:45 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alexander Fedotov X-Patchwork-Id: 170430 Delivered-To: patch@linaro.org Received: by 2002:a92:512:0:0:0:0:0 with SMTP id q18csp759386ile; Fri, 2 Aug 2019 05:34:27 -0700 (PDT) X-Google-Smtp-Source: APXvYqwmABOW0I860UZKi1mBS7YqQRqS97amFTReWOxkHtP5roWCSeeEOlEOBaTSpUBeJeGzmAsi X-Received: by 2002:a62:5c3:: with SMTP id 186mr13491141pff.144.1564749267294; Fri, 02 Aug 2019 05:34:27 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1564749267; cv=none; d=google.com; s=arc-20160816; b=sNi0gX2l1Jgvk0CpCaSM+badHpzsaQWLxKz9Q9R1jmeOwH6mjFEu4sPM7EPuxYgIRD CYYXO5al+bs3lWwJ+NTNBVP2cIf698qZ3McXaBizCEwacBqozFgxRav2CsoGOpitD6/o pqp34nK75wGtsON3h4XBDDrMiVoqV5ykn+3WmnVIPCYKvKoShkXpVBzv5gnnz67jF0RP dfdS/+Hr+4YRFgblr7eQYVvl/fpTRzAtPPPK1NswDqv0PbBZndjWk4zP3H3bH8Bu8iqw 2L7nzCMsh548E7i9IyTjzQRbN8bJF/L/wWHi2V+Fd/gHHSxyh/7iH2SW0W9KlLWyRAEJ /+JQ== 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=oCXqKrUi8p032xqF8G8VEUPuwLXQl1/PcpqwrD0t5hc=; b=hUe5oqTlkCzgmK+wcZ5kOYkV6ixxLVysxVXJjuyBGhJ3mikD6SK0SgNE3KnB7VMr4b FAxu8WXd4ZkFS7fUVecvT5SGaHXnXNe0xofeT15/5Q9o1VeocXu+SOCdzj0Z+pixZtaN dkHV371I8+ioZBXWfaUFSmv5buo4ja4S9+rXoi/R77Fp8VgPcQTL2e5vN3YKU5z+e0T8 YvkWiiBXf+MbVZG9cosYHsoCCDR6w35vqEJUHp1xZt20FyJ3dtpLAsrlSQmLBBmHWeuR yHWkzeQ5EmmrscI8gWRLyWo0bcr5JP+OTOlKAqXKMbc6/dQKVVAgvLURteR5jZ/lAKlt z1Eg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@sourceware.org header.s=default header.b=L3sA9AoW; dkim=pass header.i=@gmail.com header.s=20161025 header.b=pSq6CyvY; spf=pass (google.com: domain of newlib-return-17121-patch=linaro.org@sourceware.org designates 209.132.180.131 as permitted sender) smtp.mailfrom="newlib-return-17121-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 t2si41406553pgq.488.2019.08.02.05.34.27 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 02 Aug 2019 05:34:27 -0700 (PDT) Received-SPF: pass (google.com: domain of newlib-return-17121-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=L3sA9AoW; dkim=pass header.i=@gmail.com header.s=20161025 header.b=pSq6CyvY; spf=pass (google.com: domain of newlib-return-17121-patch=linaro.org@sourceware.org designates 209.132.180.131 as permitted sender) smtp.mailfrom="newlib-return-17121-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=fkZnEWyaYDvX8sK8uweuaOIWt43snGA nVi24DIXGClDPVnWns51x+vajHh7YiwU5yDmNwrMzb3/ZooTmq2+1Bxb9aETS+jK wsZATudEHOSmZuOTinws2D2jhc/7U614+ucICX1NYbJVtgqs5a/LMhDuqo1vweQy PzHFJ86O5+lg= 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=xR73x7EDsHxbRpGUj9ro/tz5W2w=; b=L3sA9 AoWgvNI/rwknz7orXfzaavIplZpU9wK4jpKW5VaM8XTLgxC4/s+W/3mMkwR3E74z VDLxohRIQ36ODwT34jPe/7b7rRomOJQv8/zRSL7/i5x3SHFJf4nV6oG8Ll3rpMQQ A9miX/6SpyfOcimRrxBwJiUTuUjS/DkmJOf1UU= Received: (qmail 47734 invoked by alias); 2 Aug 2019 12:33:57 -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 47632 invoked by uid 89); 2 Aug 2019 12:33:56 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-26.1 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= X-HELO: mail-lj1-f181.google.com Received: from mail-lj1-f181.google.com (HELO mail-lj1-f181.google.com) (209.85.208.181) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Fri, 02 Aug 2019 12:33:55 +0000 Received: by mail-lj1-f181.google.com with SMTP id v24so72823353ljg.13 for ; Fri, 02 Aug 2019 05:33:55 -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=oCXqKrUi8p032xqF8G8VEUPuwLXQl1/PcpqwrD0t5hc=; b=pSq6CyvYhVPj/TpW52OE0D8K5Uw3cL5RrYjkQxMj2u+W/nMQuuDrQN78u2mzJxDm/M 7qxdPxGIsT36h/xHqFuWqYNVMhQb11/eeAMOJQXBl3FuLjWj3o/wlXlvNzuA+lObmUuD nH6EXd3ApseSpnwbErWRGU4l9tXkReqFhqg4d4us+/cplryvTrxqq8IFT+QaQ+3/8689 0YjMQUUAkh39cfT7UsAXg1/WapdBempKtZbIDcqkIIjZgKyUTX2nPqcX/+xi8DiX8pE3 IJ2FKMtCyljUp+Ujag1Ct58Wz8dY9LJXF1Uw76DdLMGzuFYUnbB5p5W7LZCFxNMGF0KW ksrQ== 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.52 (version=TLS1_3 cipher=AEAD-AES256-GCM-SHA384 bits=256/256); Fri, 02 Aug 2019 05:33:52 -0700 (PDT) From: Alexander Fedotov To: newlib@sourceware.org Cc: Alexander Fedotov Subject: [PATCH v2 3/4] Align libgloss/arm and libc/sys/arm sources: Lite exit support Date: Fri, 2 Aug 2019 07:33:45 -0500 Message-Id: <20190802123346.5377-4-alfedotov@gmail.com> In-Reply-To: <20190802123346.5377-1-alfedotov@gmail.com> References: <20190802123346.5377-1-alfedotov@gmail.com> Applied changes from commit 2404223: * arm/crt0.S (_mainCRTStartup): Weak reference to atexit and _fini when lite exit is enabled. --- newlib/libc/sys/arm/crt0.S | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) -- 2.17.1 diff --git a/newlib/libc/sys/arm/crt0.S b/newlib/libc/sys/arm/crt0.S index a55aa365b..5e677a23c 100644 --- a/newlib/libc/sys/arm/crt0.S +++ b/newlib/libc/sys/arm/crt0.S @@ -518,8 +518,17 @@ __change_mode: for _fini to be called at program exit. */ movs r4, r0 movs r5, r1 +#ifdef _LITE_EXIT + /* Make reference to atexit weak to avoid unconditionally pulling in + support code. Refer to comments in __atexit.c for more details. */ + .weak FUNCTION(atexit) + ldr r0, .Latexit + cmp r0, #0 + beq .Lweak_atexit +#endif ldr r0, .Lfini bl FUNCTION (atexit) +.Lweak_atexit: bl FUNCTION (_init) movs r0, r4 movs r1, r5 @@ -589,6 +598,13 @@ change_back: .LC2: .word __bss_end__ #ifdef __USES_INITFINI__ +#ifdef _LITE_EXIT +.Latexit: + .word FUNCTION(atexit) + + /* Weak reference _fini in case of lite exit. */ + .weak FUNCTION(_fini) +#endif .Lfini: .word FUNCTION(_fini) #endif From patchwork Fri Aug 2 12:33:46 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alexander Fedotov X-Patchwork-Id: 170431 Delivered-To: patch@linaro.org Received: by 2002:a92:512:0:0:0:0:0 with SMTP id q18csp759548ile; Fri, 2 Aug 2019 05:34:36 -0700 (PDT) X-Google-Smtp-Source: APXvYqzeBRIrSP6+jhJv9bk/NxFcFZCjjotmGaphno0Ba9VbpfYHMjTEolqZPkQ42lJH5tzsIaVn X-Received: by 2002:a17:902:e202:: with SMTP id ce2mr126148038plb.272.1564749276107; Fri, 02 Aug 2019 05:34:36 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1564749276; cv=none; d=google.com; s=arc-20160816; b=EYg5YWdxJvR2KsIF0hk3BD0V8B+MUBRFvLTRyZWE8fCC1qKOdbE+6wlJGG79wddMBj reO6VmgPDmNH5FxdwUzxusa02KjT07MeCkcra3eN7+SVTkM4P97UUBR+zdDFi//oGoEr fsnUN3VQQxfY6777BdVIfeMNlLVHD+h1E58f8x0WKq1MuAeEVqlonB3YRS8bdk6HFy+7 l9sbIzbAphsuVHZjAQ33BWY1e3C0GCyzyDQiRcb33Q07kt+6m/5J6/V9oKmdnvhzoRZE ockm+U9oIigbLJO2MK9cpsjASJGiItvSjFg0Wr8MGFmJdgqHmXuMm/G6hGl6UM+nAFHM oJdg== 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=KChtZjR/Jw8v/TPA/q/VO+Cg+hKYXgj3QPOpR1yd0v0=; b=w4BZre1Szy+3b534NzDfDfGZORsPCf2Ga/XXYTAB1jPoImvpjs3jq7O9a0Yxo3LGle 7y80nvAllwXIhpBDoZzzlr3rdmOY36cure9bbEGM0PTIuwl7F+YvIT8+oIrrVONofgmI w82ImCdW1j5zkcvyc+UGTEEI+oq6FROl4M3mbUH9lvk0Zmpai2zjK1UZcqpokTTMC1Mo sEariqU/jyxpybisziKfD3j/fUBUnaa7sYf6qbSZ0EEwz5uX4gZdOSSlrvpYh/UcYDAd q7kPKmFDpLq9QMJ2G5rzPZ4agt1zddJXN0wepVBmXSKV796RaKcoFs5LZt4Eoi6jKtO0 w51Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@sourceware.org header.s=default header.b=vqXhlAfz; dkim=pass header.i=@gmail.com header.s=20161025 header.b=R4gd9aI9; spf=pass (google.com: domain of newlib-return-17122-patch=linaro.org@sourceware.org designates 209.132.180.131 as permitted sender) smtp.mailfrom="newlib-return-17122-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 z4si33464625plo.297.2019.08.02.05.34.35 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 02 Aug 2019 05:34:36 -0700 (PDT) Received-SPF: pass (google.com: domain of newlib-return-17122-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=vqXhlAfz; dkim=pass header.i=@gmail.com header.s=20161025 header.b=R4gd9aI9; spf=pass (google.com: domain of newlib-return-17122-patch=linaro.org@sourceware.org designates 209.132.180.131 as permitted sender) smtp.mailfrom="newlib-return-17122-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=doUqbVtzTQPAhFaMk1MuBsPGvvs30KP TXIFHhgInAI4i7ddKmpbSPAmxNan2gX3IfKupsfayDbNb2hf6iisRD6aZ31Aui8x b2S0iXSzO3VADBXKDFm3BA5i44/mZix26nYyJ9mgQC01WAHKeJuNbOsmjff7752s 88UsU/U4BEEQ= 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=MtdXKo9rTPB1qynk0kJaDQyoO9k=; b=vqXhl AfzC0EBw3sVA1WjSHe1Rmkr4sKDVlkqSpQkpGskBEFypo3S11+2cxP9LqczFVZwW rNfnBnKJaCt+m2I8FpInSCIzkTdqeeNTsrA4JsCeDTEuSTunFvg0Y0TCGMZ8M+ks gGFa/G81ATnq1Vjo+PWyzJzQJhzqFQscp1gS48= Received: (qmail 48268 invoked by alias); 2 Aug 2019 12:34:00 -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 48174 invoked by uid 89); 2 Aug 2019 12:34:00 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-26.1 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= X-HELO: mail-lf1-f65.google.com Received: from mail-lf1-f65.google.com (HELO mail-lf1-f65.google.com) (209.85.167.65) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Fri, 02 Aug 2019 12:33:57 +0000 Received: by mail-lf1-f65.google.com with SMTP id r15so35832350lfm.11 for ; Fri, 02 Aug 2019 05:33:56 -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=KChtZjR/Jw8v/TPA/q/VO+Cg+hKYXgj3QPOpR1yd0v0=; b=R4gd9aI9oK1WS+hb2diH7XLpFpNSzJM4fQgsXvKsxODzRFwnRH5JoX0B3qyB92pnrF 83QA0pOZRZ+sGMOG8z0vCFcBmQrOotPmLiykXvk3YTtucodDh0X/BF/urLiNujQqBLIz Rx53oTzsrp9C1Lk6a0SSiXHKYvuYAl1X7NsUBTw7Pi9fzZI2ZMbujE2ebgKMiQ+5NJJj DcoXR7FIxJe07OhsasEtsABIRgl7nmZaauozfA6gX3aKXZSTelvpD/bzp903A0va1igr ghg9SiF9c5RUs1XbZfnxYu3+dhhl3nF9Mb0qWa8coGU+KFbGF7+66y9YI4ZEOcJFI5Oc M7/A== 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.53 (version=TLS1_3 cipher=AEAD-AES256-GCM-SHA384 bits=256/256); Fri, 02 Aug 2019 05:33:53 -0700 (PDT) From: Alexander Fedotov To: newlib@sourceware.org Cc: Alexander Fedotov Subject: [PATCH v2 4/4] Align libgloss/arm and libc/sys/arm sources: miscellaneous fixes Date: Fri, 2 Aug 2019 07:33:46 -0500 Message-Id: <20190802123346.5377-5-alfedotov@gmail.com> In-Reply-To: <20190802123346.5377-1-alfedotov@gmail.com> References: <20190802123346.5377-1-alfedotov@gmail.com> 1. Trim trailing spaces 2. Align comments, function declarations and definitions --- libgloss/arm/crt0.S | 2 +- libgloss/arm/syscalls.c | 106 ++++++++++++++------------------- newlib/libc/sys/arm/arm.h | 2 +- newlib/libc/sys/arm/syscalls.c | 50 +++++++++++----- 4 files changed, 82 insertions(+), 78 deletions(-) -- 2.17.1 diff --git a/libgloss/arm/crt0.S b/libgloss/arm/crt0.S index 3e740c654..8490bde2f 100644 --- a/libgloss/arm/crt0.S +++ b/libgloss/arm/crt0.S @@ -440,7 +440,7 @@ __change_mode: beq .LC10 /* See whether we are scanning a string. */ - cmp r3, #'"' + cmp r3, #'\"' #ifdef __thumb__ beq .LC20 cmp r3, #'\'' diff --git a/libgloss/arm/syscalls.c b/libgloss/arm/syscalls.c index 3605e0fd0..fc394f94b 100644 --- a/libgloss/arm/syscalls.c +++ b/libgloss/arm/syscalls.c @@ -18,30 +18,30 @@ #include "swi.h" /* Forward prototypes. */ -int _system (const char *); -int _rename (const char *, const char *); -int _isatty (int); +int _system (const char *); +int _rename (const char *, const char *); +int _isatty (int); clock_t _times (struct tms *); -int _gettimeofday (struct timeval *, void *); -int _unlink (const char *); -int _link (const char *, const char *); -int _stat (const char *, struct stat *); -int _fstat (int, struct stat *); +int _gettimeofday (struct timeval *, void *); +int _unlink (const char *); +int _link (const char *, const char *); +int _stat (const char *, struct stat *); +int _fstat (int, struct stat *); int _swistat (int fd, struct stat * st); -void * _sbrk (ptrdiff_t); -pid_t _getpid (void); -int _close (int); -clock_t _clock (void); -int _swiclose (int); -int _open (const char *, int, ...); -int _swiopen (const char *, int); -int _write (int, const void *, size_t); -int _swiwrite (int, const void *, size_t); -_off_t _lseek (int, _off_t, int); -_off_t _swilseek (int, _off_t, int); -int _read (int, void *, size_t); -int _swiread (int, void *, size_t); -void initialise_monitor_handles (void); +void * _sbrk (ptrdiff_t); +pid_t _getpid (void); +int _close (int); +clock_t _clock (void); +int _swiclose (int); +int _open (const char *, int, ...); +int _swiopen (const char *, int); +int _write (int, const void *, size_t); +int _swiwrite (int, const void *, size_t); +_off_t _lseek (int, _off_t, int); +_off_t _swilseek (int, _off_t, int); +int _read (int, void *, size_t); +int _swiread (int, void *, size_t); +void initialise_monitor_handles (void); static int checkerror (int); static int error (int); @@ -143,7 +143,7 @@ initialise_monitor_handles (void) int i; /* Open the standard file descriptors by opening the special - * teletype device, ":tt", read-only to obtain a descritpor for + * teletype device, ":tt", read-only to obtain a descriptor for * standard input and write-only to obtain a descriptor for standard * output. Finally, open ":tt" in append mode to obtain a descriptor * for standard error. Since this is a write mode, most kernels will @@ -154,7 +154,7 @@ initialise_monitor_handles (void) #ifdef ARM_RDI_MONITOR int volatile block[3]; - + block[0] = (int) ":tt"; block[2] = 3; /* length of filename */ block[1] = 0; /* mode "r" */ @@ -351,17 +351,15 @@ checkerror (int result) len, is the length in bytes to read. Returns the number of bytes *not* written. */ int -_swiread (int fh, - void * ptr, - size_t len) +_swiread (int fh, void * ptr, size_t len) { #ifdef ARM_RDI_MONITOR int block[3]; - + block[0] = fh; block[1] = (int) ptr; block[2] = (int) len; - + return checkerror (do_AngelSWI (AngelSWI_Reason_Read, block)); #else register int r0 asm("r0"); @@ -381,9 +379,7 @@ _swiread (int fh, Translates the return of _swiread into bytes read. */ int __attribute__((weak)) -_read (int fd, - void * ptr, - size_t len) +_read (int fd, void * ptr, size_t len) { int res; struct fdent *pfd; @@ -409,9 +405,7 @@ _read (int fd, /* fd, is a user file descriptor. */ off_t -_swilseek (int fd, - off_t ptr, - int dir) +_swilseek (int fd, off_t ptr, int dir) { off_t res; struct fdent *pfd; @@ -447,7 +441,7 @@ _swilseek (int fd, } dir = SEEK_SET; } - + #ifdef ARM_RDI_MONITOR int block[2]; if (dir == SEEK_END) @@ -458,7 +452,7 @@ _swilseek (int fd, return -1; ptr += res; } - + /* This code only does absolute seeks. */ block[0] = pfd->handle; block[1] = (int) ptr; @@ -494,9 +488,7 @@ _swilseek (int fd, } off_t -_lseek (int fd, - off_t ptr, - int dir) +_lseek (int fd, off_t ptr, int dir) { return _swilseek (fd, ptr, dir); } @@ -504,18 +496,15 @@ _lseek (int fd, /* fh, is a valid internal file handle. Returns the number of bytes *not* written. */ int -_swiwrite ( - int fh, - const void * ptr, - size_t len) +_swiwrite (int fh, const void * ptr, size_t len) { #ifdef ARM_RDI_MONITOR int block[3]; - + block[0] = fh; block[1] = (int) ptr; block[2] = (int) len; - + return checkerror (do_AngelSWI (AngelSWI_Reason_Write, block)); #else register int r0 asm("r0"); @@ -533,9 +522,7 @@ _swiwrite ( /* fd, is a user file descriptor. */ int __attribute__((weak)) -_write (int fd, - const void * ptr, - size_t len) +_write (int fd, const void * ptr, size_t len) { int res; struct fdent *pfd; @@ -593,7 +580,7 @@ _swiopen (const char * path, int flags) } } - /* The flags are Unix-style, so we need to convert them. */ + /* The flags are Unix-style, so we need to convert them. */ #ifdef O_BINARY if (flags & O_BINARY) aflags |= 1; @@ -611,25 +598,24 @@ _swiopen (const char * path, int flags) if (flags & O_APPEND) { - /* Can't ask for w AND a; means just 'a'. */ - aflags &= ~4; + aflags &= ~4; /* Can't ask for w AND a; means just 'a'. */ aflags |= 8; } - + #ifdef ARM_RDI_MONITOR block[0] = (int) path; block[2] = strlen (path); block[1] = aflags; - + fh = do_AngelSWI (AngelSWI_Reason_Open, block); - + #else asm ("mov r0,%2; mov r1, %3; swi %a1; mov %0, r0" : "=r"(fh) : "i" (SWI_Open),"r"(path),"r"(aflags) : "r0","r1"); #endif - + /* Return a user file descriptor or an error. */ if (fh >= 0) { @@ -784,13 +770,13 @@ _stat (const char *fname, struct stat *st) { int fd, res; memset (st, 0, sizeof (* st)); - /* The best we can do is try to open the file readonly. - If it exists, then we can guess a few things about it. */ + /* The best we can do is try to open the file readonly. If it exists, + then we can guess a few things about it. */ if ((fd = _open (fname, O_RDONLY)) == -1) return -1; st->st_mode |= S_IFREG | S_IREAD; res = _swistat (fd, st); - /* Not interested in the error. */ + /* Not interested in the error. */ _close (fd); return res; } @@ -880,7 +866,7 @@ _times (struct tms * tp) tp->tms_cutime = 0; /* user time, children */ tp->tms_cstime = 0; /* system time, children */ } - + return timeval; }; diff --git a/newlib/libc/sys/arm/arm.h b/newlib/libc/sys/arm/arm.h index dbed81750..10e5b0509 100644 --- a/newlib/libc/sys/arm/arm.h +++ b/newlib/libc/sys/arm/arm.h @@ -85,6 +85,6 @@ #define CPSR_F_MASK 0x40 /* FIQ bit. */ #define CPSR_I_MASK 0x80 /* IRQ bit. */ -#define CPSR_M_MASK 0x0F /* Mode mask except M[4] */ +#define CPSR_M_MASK 0x0F /* Mode mask except M[4]. */ #endif /* _LIBGLOSS_ARM_H */ diff --git a/newlib/libc/sys/arm/syscalls.c b/newlib/libc/sys/arm/syscalls.c index a2997b44c..1f7222980 100644 --- a/newlib/libc/sys/arm/syscalls.c +++ b/newlib/libc/sys/arm/syscalls.c @@ -114,6 +114,16 @@ void initialise_monitor_handles (void) { int i; + + /* Open the standard file descriptors by opening the special + * teletype device, ":tt", read-only to obtain a descriptor for + * standard input and write-only to obtain a descriptor for standard + * output. Finally, open ":tt" in append mode to obtain a descriptor + * for standard error. Since this is a write mode, most kernels will + * probably return the same value as for standard output, but the + * kernel can differentiate the two using the mode flag and return a + * different descriptor for standard error. + */ #ifdef ARM_RDI_MONITOR int volatile block[3]; @@ -163,11 +173,12 @@ get_errno (void) return do_AngelSWI (AngelSWI_Reason_Errno, NULL); #else register int r0 asm("r0"); - asm ("swi %a1" : "=r"(r0): "i" (SWI_GetErrno)); + asm ("swi %a1" : "=r"(r0) : "i" (SWI_GetErrno)); return r0; #endif } +/* Set errno and return result. */ static int error (int result) { @@ -183,7 +194,10 @@ wrap (int result) return result; } -/* Returns # chars not! written. */ +/* file, is a valid user file handle. + ptr, is a null terminated string. + len, is the length in bytes to read. + Returns the number of bytes *not* written. */ int _swiread (int file, void * ptr, size_t len) { @@ -207,6 +221,9 @@ _swiread (int file, void * ptr, size_t len) #endif } +/* file, is a valid user file handle. + Translates the return of _swiread into + bytes read. */ int __attribute__((weak)) _read (int file, void * ptr, size_t len) { @@ -223,15 +240,13 @@ _read (int file, void * ptr, size_t len) return len - x; } +/* file, is a user file descriptor. */ off_t _swilseek (int file, off_t ptr, int dir) { _off_t res; int fh = remap_handle (file); int slot = findslot (fh); -#ifdef ARM_RDI_MONITOR - int block[2]; -#endif if (dir == SEEK_CUR) { @@ -249,6 +264,7 @@ _swilseek (int file, off_t ptr, int dir) } #ifdef ARM_RDI_MONITOR + int block[2]; if (dir == SEEK_END) { block[0] = fh; @@ -294,7 +310,8 @@ _lseek (int file, off_t ptr, int dir) return wrap (_swilseek (file, ptr, dir)); } -/* Returns #chars not! written. */ +/* file, is a valid internal file handle. + Returns the number of bytes *not* written. */ int _swiwrite (int file, const void * ptr, size_t len) { @@ -319,6 +336,7 @@ _swiwrite (int file, const void * ptr, size_t len) #endif } +/* file, is a user file descriptor. */ int __attribute__((weak)) _write (int file, const void * ptr, size_t len) { @@ -366,7 +384,7 @@ _swiopen (const char * path, int flags) if (flags & O_APPEND) { - aflags &= ~4; /* Can't ask for w AND a; means just 'a'. */ + aflags &= ~4; /* Can't ask for w AND a; means just 'a'. */ aflags |= 8; } @@ -527,7 +545,7 @@ _sbrk (ptrdiff_t incr) extern void memset (struct stat *, int, unsigned int); -int +int __attribute__((weak)) _fstat (int file, struct stat * st) { memset (st, 0, sizeof (* st)); @@ -537,7 +555,8 @@ _fstat (int file, struct stat * st) file = file; } -int _stat (const char *fname, struct stat *st) +int __attribute__((weak)) +_stat (const char *fname, struct stat *st) { int file; @@ -553,20 +572,19 @@ int _stat (const char *fname, struct stat *st) return 0; } -int -_link (const char *__path1 __attribute__ ((unused)), - const char *__path2 __attribute__ ((unused))) +int __attribute__((weak)) +_link (const char *__path1 __attribute__ ((unused)), const char *__path2 __attribute__ ((unused))) { errno = ENOSYS; return -1; } int -_unlink (const char *path __attribute__ ((unused))) +_unlink (const char *path) { #ifdef ARM_RDI_MONITOR int block[2]; - block[0] = (int) path; + block[0] = (int)path; block[1] = strlen(path); return wrap (do_AngelSWI (AngelSWI_Reason_Remove, block)) ? -1 : 0; #else @@ -659,13 +677,13 @@ _system (const char *s) meaning to its return value. Try to do something reasonable.... */ if (!s) return 1; /* maybe there is a shell available? we can hope. :-P */ - block[0] = (int) s; + block[0] = (int)s; block[1] = strlen (s); e = wrap (do_AngelSWI (AngelSWI_Reason_System, block)); if ((e >= 0) && (e < 256)) { /* We have to convert e, an exit status to the encoded status of - the command. To avoid hard coding the exit status, we simply + the command. To avoid hard coding the exit status, we simply loop until we find the right position. */ int exit_code;