From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received-SPF: Pass (sender SPF authorized) identity=mailfrom; client-ip=2607:f8b0:4864:20::141; helo=mail-it1-x141.google.com; envelope-from=ard.biesheuvel@linaro.org; receiver=edk2-devel@lists.01.org Received: from mail-it1-x141.google.com (mail-it1-x141.google.com [IPv6:2607:f8b0:4864:20::141]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by ml01.01.org (Postfix) with ESMTPS id DE4992118F37F for ; Wed, 12 Dec 2018 06:49:19 -0800 (PST) Received: by mail-it1-x141.google.com with SMTP id a6so10138300itl.4 for ; Wed, 12 Dec 2018 06:49:19 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=mLDAElgfg2o90Z8WJf38on9Pl9uJuoJWNhqUt3jxw+c=; b=SjZJMN/h2U5nWKyiFnc+xHrD914GtwzFqm27dDTnn7VKoxFDrvpAow4zojSfNPlRej BVqt2m+ATwC3VDoqzCWv7KQqlLDAqOBVDAP7bh3IBXj+EouTIzJmxQd0qzIQJgtPL1P4 kH3maU/yZbYUvpd3LadzVio7flwgQK3BMtOKI= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=mLDAElgfg2o90Z8WJf38on9Pl9uJuoJWNhqUt3jxw+c=; b=DLgIf051os/GzOpufKlOjALz5jBpYURbezr1kGsckgNzrfyAHEfxiDBcKlxJcom7MH Un6tpAvZLwZip5QQ38B1nqoXVMaFqcmoFINm0aHcxLwMdHbYCtaFaz6Th3OhYBZxAP3a j6MwUKC1fbor7UUPHCbrCX3ba8VNJOZPGiuVKIr7Ch3nQZX+A8wmGkQWEuk2ONnvGVt5 4NeV3j/S1SCel75ywubi7BlTsXt3ZqHC65vj/AWf2qClcQHleOW+D0KYbpJYSnR/E8AO HF5sJuxl68VO/qm2yiSipftcEq05DfqBsdCTpLFxfSCZXmaujzWMpDJzvfpD04xPz7pO Zkqg== X-Gm-Message-State: AA+aEWY6HaKBByEBxFhm4WFO9KQHNPDzP3atf3m+yI33yHh9V4ioCiJh OdJlqPOd4UCB/r4VpXsGCTehta2GV9xZYUUUwlZJlf53 X-Google-Smtp-Source: AFSGD/XGpkyioNt7rFtxzZmUUOj8N0eHx1UgjjXNznFsFVIK3Bzb8Ag9BYLJtJG/pGjg9eYerqdbU/gvN6L9L8o5TUg= X-Received: by 2002:a24:710:: with SMTP id f16mr5471794itf.121.1544626158954; Wed, 12 Dec 2018 06:49:18 -0800 (PST) MIME-Version: 1.0 References: <20181212091211.13258-1-ard.biesheuvel@linaro.org> <20181212113009.vmsv37swaui3z4os@bivouac.eciton.net> <20181212123137.bzwi46gsszljlsvw@bivouac.eciton.net> <20181212144113.dxrno2cpclyszjrq@bivouac.eciton.net> In-Reply-To: <20181212144113.dxrno2cpclyszjrq@bivouac.eciton.net> From: Ard Biesheuvel Date: Wed, 12 Dec 2018 15:49:07 +0100 Message-ID: To: Leif Lindholm Cc: "edk2-devel@lists.01.org" Subject: Re: [PATCH] EmbeddedPkg/GdbDebugAgent ARM: use modern dialect for ldm/stm instructions X-BeenThere: edk2-devel@lists.01.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: EDK II Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 12 Dec 2018 14:49:20 -0000 Content-Type: text/plain; charset="UTF-8" On Wed, 12 Dec 2018 at 15:41, Leif Lindholm wrote: > > On Wed, Dec 12, 2018 at 01:45:17PM +0100, Ard Biesheuvel wrote: > > > > > > @@ -198,9 +199,9 @@ ASM_PFX(AsmCommonExceptionEntry): > > > > > > and R3, R1, #0x1f @ Check CPSR to see if User or System Mode > > > > > > cmp R3, #0x1f @ if ((CPSR == 0x10) || (CPSR == 0x1df)) > > > > > > cmpne R3, #0x10 @ > > > > > > - stmeqed R2, {lr}^ @ save unbanked lr > > > > > > + stmdaeq R2, {lr}^ @ save unbanked lr > > > > > > Then again, looking closer at these instructions, they're not really > > > doing stack operations. Just (ab)using the instruction to get at the > > > banked User mode LR from a different mode. So > > > a) The symmetry thing doesn't really apply, so the ED is actively > > > misleading here. > > > b) This could trivially be changed to use FD anyway, just setting R2's > > > offset from PC to #0x34 :) > > > > > > > Actually, since there is no writeback, what is the point of the > > decrement-after? Can't we just drop it? > > Possibly picked specifically to _not_ be mistaken for a stack > operation. In this scenario The DA just means don't add 4 to R2 before > using it as address. > Indeed. But in the load counterpart below, it means increment-before, so it will restore lr from the wrong address. > > The more I look at this code the more broken it seems. I'll just remove it. > > As previously stated, I'm happy with this. > > / > Leif > > > > > > > @ else > > > > > > - stmneed R2, {lr} @ save SVC lr > > > > > > + stmdane R2, {lr} @ save SVC lr > > > > > > > > > > > > > > > > > > ldr R5, [SP, #0x58] @ PC is the LR pushed by srsfd > > > > > > @@ -245,9 +246,9 @@ GdbExceptionHandler ( > > > > > > and R1, R1, #0x1f @ Check to see if User or System Mode > > > > > > cmp R1, #0x1f @ if ((CPSR == 0x10) || (CPSR == 0x1f)) > > > > > > cmpne R1, #0x10 @ > > > > > > - ldmeqed R2, {lr}^ @ restore unbanked lr > > > > > > + ldmibeq R2, {lr}^ @ restore unbanked lr > > > > > > @ else > > > > > > - ldmneed R3, {lr} @ restore SVC lr, via ldmfd SP!, {LR} > > > > > > + ldmibne R3, {lr} @ restore SVC lr, via ldmfd SP!, {LR} > > > > > > > > > > > > ldmfd SP!,{R0-R12} @ Restore general purpose registers > > > > > > @ Exception handler can not change SP > > > > > > -- > > > > > > 2.19.2 > > > > > > > > > > > > c) But given a), I would take this one if the comment was updated to > > > be explicit about how esoteric this operation really is. > > > I.e.: "(ab)use STM^ to save banked User mode LR from SVC/HYP mode" > > > and "(ab)use LDM^ to restore banked User mode LR from SVC/HYP mode" > > > > > > I would also be happy to nuke it (including the commented out > > > inclusion for BeagleBoardPkg). > > > > > > / > > > Leif