From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 118427 invoked by alias); 13 Feb 2018 16:40:12 -0000 Mailing-List: contact gcc-patches-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Archive: List-Post: List-Help: Sender: gcc-patches-owner@gcc.gnu.org Received: (qmail 116247 invoked by uid 89); 13 Feb 2018 16:40:12 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-2.8 required=5.0 tests=AWL,BAYES_00,RCVD_IN_DNSWL_NONE,SPF_HELO_PASS,SPF_PASS autolearn=ham version=3.3.2 spammy= X-HELO: EUR01-HE1-obe.outbound.protection.outlook.com Received: from mail-he1eur01on0058.outbound.protection.outlook.com (HELO EUR01-HE1-obe.outbound.protection.outlook.com) (104.47.0.58) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Tue, 13 Feb 2018 16:40:10 +0000 Received: from DB6PR0801MB2053.eurprd08.prod.outlook.com (10.168.86.22) by DB6PR0801MB1895.eurprd08.prod.outlook.com (10.168.85.17) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384_P256) id 15.20.485.10; Tue, 13 Feb 2018 16:40:06 +0000 Received: from DB6PR0801MB2053.eurprd08.prod.outlook.com ([fe80::ac2f:91c:c9da:ec56]) by DB6PR0801MB2053.eurprd08.prod.outlook.com ([fe80::ac2f:91c:c9da:ec56%17]) with mapi id 15.20.0485.015; Tue, 13 Feb 2018 16:40:06 +0000 From: Wilco Dijkstra To: "adhemerval.zanella@linaro.org" CC: GCC Patches , nd Subject: Re: [PATCH v6] aarch64: Add split-stack support Date: Tue, 13 Feb 2018 16:40:00 -0000 Message-ID: authentication-results: spf=none (sender IP is ) smtp.mailfrom=Wilco.Dijkstra@arm.com; x-ms-publictraffictype: Email x-microsoft-exchange-diagnostics: 1;DB6PR0801MB1895;7:PK6Ueaqs+33ojOA8UwrxD83TGm2da1eU4sFP31FtvyfVNMMMLsToMJVH7SMX9rm8DKAr6nJY1ktpu8JXbOkRAdPwr/ndFeFwfKQsXjsU6vt9BXaWN3iFN4Rfuf3KK2WDiuyrckJ7CBOUTRIJGyx1B+Z/u6ajnwyrbCeBUAWwBWm3raJr0K1BMU2p3b3d0hJGoUeYvDlJG8XMd6yUc0DdjVm6PFFHaqQiKRcAb3ScUNQrJHa8feBMnUfV3Yk17kCR x-ms-exchange-antispam-srfa-diagnostics: SSOS; x-ms-office365-filtering-ht: Tenant x-ms-office365-filtering-correlation-id: 1a1c8005-5408-424e-8acf-08d57300706d x-microsoft-antispam: UriScan:;BCL:0;PCL:0;RULEID:(7020095)(4652020)(48565401081)(5600026)(4604075)(3008032)(4534165)(4627221)(201703031133081)(201702281549075)(2017052603307)(7153060)(7193020);SRVR:DB6PR0801MB1895; x-ms-traffictypediagnostic: DB6PR0801MB1895: nodisclaimer: True x-microsoft-antispam-prvs: x-exchange-antispam-report-test: UriScan:; x-exchange-antispam-report-cfa-test: BCL:0;PCL:0;RULEID:(6040501)(2401047)(8121501046)(5005006)(93006095)(93001095)(10201501046)(3002001)(3231101)(944501161)(6055026)(6041288)(20161123562045)(20161123564045)(20161123558120)(20161123560045)(201703131423095)(201702281528075)(20161123555045)(201703061421075)(201703061406153)(6072148)(201708071742011);SRVR:DB6PR0801MB1895;BCL:0;PCL:0;RULEID:;SRVR:DB6PR0801MB1895; x-forefront-prvs: 0582641F53 x-forefront-antispam-report: SFV:NSPM;SFS:(10009020)(396003)(39380400002)(346002)(366004)(39860400002)(376002)(189003)(199004)(53936002)(105586002)(229853002)(72206003)(86362001)(7736002)(6246003)(68736007)(305945005)(9686003)(97736004)(316002)(3846002)(6116002)(55016002)(6436002)(54906003)(74316002)(5250100002)(478600001)(14454004)(2501003)(6916009)(5660300001)(5640700003)(81156014)(2900100001)(2906002)(8936002)(8676002)(81166006)(59450400001)(99286004)(6506007)(3280700002)(3660700001)(106356001)(25786009)(4326008)(102836004)(2351001)(186003)(66066001)(33656002)(7696005)(26005);DIR:OUT;SFP:1101;SCL:1;SRVR:DB6PR0801MB1895;H:DB6PR0801MB2053.eurprd08.prod.outlook.com;FPR:;SPF:None;PTR:InfoNoRecords;MX:1;A:1;LANG:en; received-spf: None (protection.outlook.com: arm.com does not designate permitted sender hosts) x-microsoft-antispam-message-info: OzDFmxDjs9hXxBvoHoFRzLr7n9yQHSN2zpdG2E0YYr9ioFkQ+hB5ci231BHwAE9fMhXkpv02jMpyQl8pMxPYjA== spamdiagnosticoutput: 1:99 spamdiagnosticmetadata: NSPM Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 X-OriginatorOrg: arm.com X-MS-Exchange-CrossTenant-Network-Message-Id: 1a1c8005-5408-424e-8acf-08d57300706d X-MS-Exchange-CrossTenant-originalarrivaltime: 13 Feb 2018 16:40:06.5745 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: f34e5979-57d9-4aaa-ad4d-b122a662184d X-MS-Exchange-Transport-CrossTenantHeadersStamped: DB6PR0801MB1895 X-SW-Source: 2018-02/txt/msg00747.txt.bz2 Hi Adhemerval, A few comments on the assembly code: +# This function is called with non-standard calling convention: on entry +# x10 is the requested stack pointer, x11 is previous stack pointer (if +# functions has stacked arguments which needs to be restored), and x12 is +# the caller link register on function entry (which will be restored by +# morestack when returning to caller). The split-stack prologue is in +# the form: +# +# function: +# mrs x9, tpidr_el0 +# ldur x9, [x9, #-8] +# mov x10, +# movk x10, #0x0, lsl #16 +# sub x10, sp, x10 +# mov x11, sp # if function has stacked arguments +# mov x12, x30 This should go... +# cmp x9, x10 +# bcc .LX +# main_fn_entry: +# [function body] +# LX: ...here: mov x12, x30 +# bl __morestack +# b main_fn_entry Note using a bl here rather than a branch means you'll kill the return stac= k. +# The N bit is also restored to indicate that the function is called +# (so the prologue addition can set up the argument pointer correctly). + +ENTRY(__morestack) +.LFB1: + .cfi_startproc + +#ifdef __PIC__ + .cfi_personality 0x9b,DW.ref.__gcc_personality_v0 + .cfi_lsda 0x1b,.LLSDA1 +#else + .cfi_personality 0x3,__gcc_personality_v0 + .cfi_lsda 0x3,.LLSDA1 +#endif + # Calculate requested stack size. + sub x10, sp, x10 + + # Save parameters + stp x29, x12, [sp, -MORESTACK_FRAMESIZE]! + .cfi_def_cfa_offset MORESTACK_FRAMESIZE + .cfi_offset 29, -MORESTACK_FRAMESIZE + .cfi_offset 30, -MORESTACK_FRAMESIZE+8 + add x29, sp, 0 + .cfi_def_cfa_register 29 + # Adjust the requested stack size for the frame pointer save. + stp x0, x1, [x29, 16] + stp x2, x3, [x29, 32] + add x10, x10, BACKOFF + stp x4, x5, [x29, 48] + stp x6, x7, [x29, 64] + stp x8, x30, [x29, 80] + str x10, [x29, 96] Probably best to use NEWSTACK_SAVE here for clarity. + # void __morestack_block_signals (void) + bl __morestack_block_signals + + # void *__generic_morestack (size_t *pframe_size, + # void *old_stack, + # size_t param_size) + # pframe_size: is the size of the required stack frame (the function + # amount of space remaining on the allocated stack). + # old_stack: points at the parameters the old stack + # param_size: size in bytes of parameters to copy to the new stack. + add x0, x29, NEWSTACK_SAVE + add x1, x29, MORESTACK_FRAMESIZE + mov x2, 0 + bl __generic_morestack + + # Start using new stack + mov sp, x0 + + # Set __private_ss stack guard for the new stack. + ldr x9, [x29, NEWSTACK_SAVE] + add x0, x0, BACKOFF + sub x0, x0, x9 +.LEHB0: + mrs x1, tpidr_el0 + str x0, [x1, SPLITSTACK_PTR_TP] Is the label for unwinding exactly at the right place? + # void __morestack_unblock_signals (void) + bl __morestack_unblock_signals + + # Set up for a call to the target function. + ldp x0, x1, [x29, 16] + ldp x2, x3, [x29, 32] + ldp x4, x5, [x29, 48] + ldp x6, x7, [x29, 64] + ldp x8, x12, [x29, 80] + add x11, x29, MORESTACK_FRAMESIZE + ldr x30, [x29, 8] + # Indicate __morestack was called. + cmp x12, 0 No idea what this is for but the ldr/cmp are completely redundant. + blr x12 + + stp x0, x1, [x29, 16] + stp x2, x3, [x29, 32] + stp x4, x5, [x29, 48] + stp x6, x7, [x29, 64] These 3 STPs are dead. + bl __morestack_block_signals + + # void *__generic_releasestack (size_t *pavailable) + add x0, x29, NEWSTACK_SAVE + bl __generic_releasestack + + # Reset __private_ss stack guard to value for old stack + ldr x9, [x29, NEWSTACK_SAVE] + add x0, x0, BACKOFF + sub x0, x0, x9 + + # Update TCB split stack field +.LEHE0: + mrs x1, tpidr_el0 + str x0, [x1, SPLITSTACK_PTR_TP] + + bl __morestack_unblock_signals + + # Use old stack again. + add sp, x29, MORESTACK_FRAMESIZE + + ldp x0, x1, [x29, 16] + ldp x2, x3, [x29, 32] + ldp x4, x5, [x29, 48] + ldp x6, x7, [x29, 64] These 3 LDPs are dead. + ldp x29, x30, [x29] + + .cfi_remember_state + .cfi_restore 30 + .cfi_restore 29 + .cfi_def_cfa 31, 0 + + ret