From patchwork Wed Oct 11 11:57:43 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alexander Fedotov X-Patchwork-Id: 115545 Delivered-To: patch@linaro.org Received: by 10.140.22.163 with SMTP id 32csp663599qgn; Wed, 11 Oct 2017 04:58:00 -0700 (PDT) X-Received: by 10.84.248.10 with SMTP id p10mr8962109pll.447.1507723080448; Wed, 11 Oct 2017 04:58:00 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1507723080; cv=none; d=google.com; s=arc-20160816; b=BRa7MOh3qeRZ0S10Liq1dLeEUZNBAUx92kafO2pwJAukjZC5uT9UgU2wS+1Y7QXeF3 N4s7KDwobuwhllHm3VIH5m4alADxA5s2fMyvdlWYUGWLSv2SixM/uQPvmGVfqL0pHA38 wU9NoJUUIRVKNrNcU8qg7oSbhbcOICUOLEYU6rgOqT9BIER5gPQH6mwXJe9xX0eYLWAM yCuK94QzIjMUOm5EGz2AtLoV6Do4hPdT7yCCNvl44WumnFzFRac3sm0a2WoUJUdRSxcL YGDPXVC/N58zuhEIg8WheqZcGT8AJRfpxhmNTtC+cx4peoa0TLw0vUfGpA0Z0ywSOuzA mm9g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=to:subject:message-id:date:from:mime-version:delivered-to:sender :list-help:list-post:list-archive:list-subscribe:list-unsubscribe :list-id:precedence:mailing-list:dkim-signature:domainkey-signature :arc-authentication-results; bh=d5LZoavtENPkwLIfsh75bqvK3YicR+Qla6yQhUgDMPk=; b=NVyPxaXxXpIVvhPSzGEeZCupIQu48NhLrg/cAfR9FC2fw2Adol+LWjAmjEvVH8VNhM QlNqU3J6ANMsb7f4OA9QcE3TUtPjjgR4+oph8d//+ZoZPyYHIfBY5V+V8I754augNyxx lec7wWsc98xLR7JPyIMAzK8TmOIy12caJjZKYxttMLqqKgWCS6I4F3NssJWvXGnTYWZO CnDDPxn5Aoqxh79y6QzJgBOEaXWlIZYCSCy2es7bw2qirJu9z3Q6AmFzY6O7ESCV/7LZ saeZpU0pP9gVWGLXT8H37x9vMUvI+BoJUDnVagLT9eBvin4qKL6J8Y0Biuu1CuwbMwpK Gvrg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@sourceware.org header.s=default header.b=Fxlsdb7H; spf=pass (google.com: domain of newlib-return-15262-patch=linaro.org@sourceware.org designates 209.132.180.131 as permitted sender) smtp.mailfrom=newlib-return-15262-patch=linaro.org@sourceware.org; dmarc=fail (p=NONE sp=NONE 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 b69si6963278pfe.523.2017.10.11.04.58.00 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 11 Oct 2017 04:58:00 -0700 (PDT) Received-SPF: pass (google.com: domain of newlib-return-15262-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=Fxlsdb7H; spf=pass (google.com: domain of newlib-return-15262-patch=linaro.org@sourceware.org designates 209.132.180.131 as permitted sender) smtp.mailfrom=newlib-return-15262-patch=linaro.org@sourceware.org; dmarc=fail (p=NONE sp=NONE 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:mime-version:from:date:message-id:subject:to :content-type; q=dns; s=default; b=spst8UXzo8KwteSZTiYVpHMYvY1/h g2uuOjEoOjejopEkIlPttLPwiD+adF96GUTjmnWJzWYJxi9UdSGAzgPwCcEoS+sc 119Vdc/LWQcgTLMuDvhbcJkfkCFAHQrBuNT+gNgCJgGeBfXxbA6lNa//YePs27HX 6xeoGpcnfM9zBY= 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:mime-version:from:date:message-id:subject:to :content-type; s=default; bh=00Yy4CWlNZUA3SH0tMBeF2HH7mk=; b=Fxl sdb7Hn7kPDcH/818YKWrqAocDdaZ16rnsKQHrEMdWBI+RWXVTmpFWX7pBHnEypBX rHgQeSqRD/DLaSc+cRT4ciOUqeiqO0wagHL9CqRKNecAoHSh5JPgIGV0UTPEPZAB c9ZWxpUFOChp+biuLc3ifphC16ZX5WMZDME01l0g= Received: (qmail 27159 invoked by alias); 11 Oct 2017 11:57:48 -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 27059 invoked by uid 89); 11 Oct 2017 11:57:47 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-25.3 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.2 spammy=angel, Honour, honour, Angel X-HELO: mail-pg0-f54.google.com Received: from mail-pg0-f54.google.com (HELO mail-pg0-f54.google.com) (74.125.83.54) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Wed, 11 Oct 2017 11:57:46 +0000 Received: by mail-pg0-f54.google.com with SMTP id y7so862487pgb.7 for ; Wed, 11 Oct 2017 04:57:46 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:from:date:message-id:subject:to; bh=IT81Dh7hLmq29EuabosiZz4j+s+4jbDeZ2vBkeUqy40=; b=QkZ9LUaAySFdncAnrQ6zK4hMh7Hw0acnqcnhKa/czxpVHtZxR2aB3NlXMRWKKSdF+F Gg2hUZd6DdZ3UJeldj7ODgd0TtaGM3BEw/KEFoUMbKZumpTwxtucyaYiM9NCUu4ziSte opvNahd7vWI87WXDORmdnlAKt88NW2ggUHiiFqU87eHiV0lua6+8eDRRA4kfFyAcqrZr pcMsQOtIrvn8x5FIIdQz70Q8vftwPZ2PRgZtngbDlXGnWfKNlHS5aQkV2Kc5uJKzG6G5 RnaW0yn1YscPiQbe9WhaFKZQBGoMbCEt5cYKyIoUJG9VzIerUnW4AzSnJ6amdXA7JyWw kPrA== X-Gm-Message-State: AMCzsaVRynppDFLBhJwSPK7lD7L/D7RkGra8c20UW+zbVaQxi+4SQZLN NCwOpgXLTq61U7cUfX7+NCUu5lKil8kfNtq9WStdug== X-Google-Smtp-Source: AOwi7QCGYDwWsEuAgWkaFccRfJ/JVFQf0C2G4uqqEpaMZrmRT1hnxfPka/w57w2WpKG6+g99WODUaTt0ZdkWLJUawMA= X-Received: by 10.98.181.3 with SMTP id y3mr6353637pfe.264.1507723064555; Wed, 11 Oct 2017 04:57:44 -0700 (PDT) MIME-Version: 1.0 Received: by 10.100.163.141 with HTTP; Wed, 11 Oct 2017 04:57:43 -0700 (PDT) From: Alexander Fedotov Date: Wed, 11 Oct 2017 14:57:43 +0300 Message-ID: Subject: [PATCH] Semihosting fix for AArch64 when heapinfo is not provided by debugger To: newlib@sourceware.org Use the same approach as in ARM port for case when Debugger not providing necessary info for semihosting. Alex >From 4f2ac350345f1126fa491dc0a335a9e1da92817e Mon Sep 17 00:00:00 2001 From: Alexander Fedotov Date: Wed, 11 Oct 2017 14:52:20 +0300 Subject: [PATCH] Fixed semihosting for AArch64 when heapinfo parameters are not provided by debugger --- libgloss/aarch64/crt0.S | 78 ++++++++++++++++++++++++++++++--------------- libgloss/aarch64/syscalls.c | 7 +++- 2 files changed, 59 insertions(+), 26 deletions(-) diff --git a/libgloss/aarch64/crt0.S b/libgloss/aarch64/crt0.S index f670e03..f831be1 100644 --- a/libgloss/aarch64/crt0.S +++ b/libgloss/aarch64/crt0.S @@ -102,33 +102,44 @@ ldr x0, .LC0 /* point at returned values */ ldr x1, [x0, #8] /* get heap_limit */ + /* Set __heap_limit. */ +#ifdef __ILP32__ + /* Sanity check on the __heap_limit. */ + tst x1, #0xffffffff00000000 + bne .Linsanepar +#endif + cmp x1, xzr + beq .LC4 + adrp x2, __heap_limit + add x2, x2, #:lo12:__heap_limit + str x1, [x2] +.LC4: + + ldr x1, [x0] /* get heap_base */ #ifdef __ILP32__ /* Sanity check on the heap base. */ - ldr x0, [x0] /* get heap_base */ - tst x0, #0xffffffff00000000 - beq 1f - /* Exit with 1 if the heap base is not within the 32-bit address - space. */ - mov x0, ADP_Stopped_ApplicationExit & 0xff - movk x0, ADP_Stopped_ApplicationExit >> 16, lsl #16 - adrp x1, HeapBase /* Reuse to construct the parameter block. */ - add x1, x1, #:lo12:HeapBase - str x0, [x1] - mov x0, 1 - str x0, [x1, #8] - mov w0, #AngelSVC_Reason_ReportException - AngelSVCAsm AngelSVC -1: - /* For the sake of safety, set the stack base to the top end of - the 32-bit address space if the returned value from the - Angel API call is larger than or equal to 4 GiB. */ tst x1, #0xffffffff00000000 - csinv w1, w1, wzr, eq + bne .Linsanepar #endif -#else - /* Set up the stack pointer to a fixed value. */ - ldr x1, .Lstack + cmp x1, xzr + bne .LC5 + /* If the heap base value [x0, #0] is 0 then the heap base is actually + at the end of program data (i.e. __end__) */ + ldr x1, .LC3 + str x1, [x0, #0] +.LC5: + ldr x1, [x0, #16] /* get stack_base */ + +#ifdef __ILP32__ + /* Sanity check on the stack_base. */ + tst x1, #0xffffffff00000000 + bne .Linsanepar +#endif + cmp x1, xzr + bne .LC6 #endif + ldr x1, .Lstack /* Set up the stack pointer to a fixed value */ +.LC6: /* Ensure quad-word stack alignment. */ and x0, x1, #~15 @@ -234,6 +245,22 @@ b FUNCTION (exit) /* Cannot return. */ +#if defined (ARM_RDI_MONITOR) && defined (__ILP32__) +.Linsanepar: + /* Exit with 1 if the parameter is not within the 32-bit address + space. */ + mov x1, ADP_Stopped_ApplicationExit & 0xff + movk x1, ADP_Stopped_ApplicationExit >> 16, lsl #16 + adrp x0, HeapBase /* Reuse to construct the parameter block. */ + add x0, x0, #:lo12:HeapBase + str x1, [x0] + mov x1, 1 + str x1, [x0, #8] + mov w1, #AngelSVC_Reason_ReportException + AngelSVCAsm AngelSVC + b . +#endif + /* Function initializing exception vector table, flatmap, etc. Declared as weak symbol so that user can override this definition by linking in their own version of the function. */ @@ -245,12 +272,13 @@ FUNCTION (_cpu_init_hook): #ifdef ARM_RDI_MONITOR .LC0: GEN_DWORD HeapBase -#else +.LC3: + GEN_DWORD __end__ +#endif .Lstack: GEN_DWORD __stack - .weak __stack -#endif + .LC1: GEN_DWORD __bss_start__ .LC2: diff --git a/libgloss/aarch64/syscalls.c b/libgloss/aarch64/syscalls.c index af206a1..4de4e0d 100644 --- a/libgloss/aarch64/syscalls.c +++ b/libgloss/aarch64/syscalls.c @@ -625,6 +625,9 @@ _getpid (int n __attribute__ ((unused))) return 1; } +/* Heap limit returned from SYS_HEAPINFO Angel semihost call. */ +ulong __heap_limit __attribute__ ((aligned (8))) = 0xcafedead; + caddr_t _sbrk (int incr) { @@ -637,7 +640,9 @@ _sbrk (int 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 > __heap_limit))) { /* Some of the libstdc++-v3 tests rely upon detecting out of memory errors, so do not abort here. */ -- 2.7.4