From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from wout2-smtp.messagingengine.com (wout2-smtp.messagingengine.com [64.147.123.25]) by mx.groups.io with SMTP id smtpd.web11.1901.1684431371554268813 for ; Thu, 18 May 2023 10:36:11 -0700 Authentication-Results: mx.groups.io; dkim=fail reason="signature has expired" header.i=@bsdio.com header.s=fm2 header.b=fskpFnih; spf=pass (domain: bsdio.com, ip: 64.147.123.25, mailfrom: rebecca@bsdio.com) Received: from compute5.internal (compute5.nyi.internal [10.202.2.45]) by mailout.west.internal (Postfix) with ESMTP id 9DCFD32000D7; Thu, 18 May 2023 13:36:10 -0400 (EDT) Received: from imap43 ([10.202.2.93]) by compute5.internal (MEProxy); Thu, 18 May 2023 13:36:10 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bsdio.com; h=cc :content-transfer-encoding:content-type:content-type:date:date :from:from:in-reply-to:in-reply-to:message-id:mime-version :references:reply-to:sender:subject:subject:to:to; s=fm2; t= 1684431370; x=1684517770; bh=+RRQKmP7+cSeL/VIgGOtkyG26H7JVRL971/ twqLNDiE=; b=fskpFnihd4Y/kMWKEMZX+hqDmih5g+KwlgR2R2EXiU66gLEEpkg 7d5OYcpzJhonLtKO7/RtDUt6raFA5Wmh4C39KKwAbFkBIZAxoubI5RFd2GEoFKiL EZYIo0Vx8hgoyDIQspQX6qag3KzqItBguJudOxZ9anD39OGg5vHeyGw+X8Iipo97 6wey9BQCznxpiE5lVgIOb6W74jHQnJmqJsQAyMNoriPGgijXwrherUt4v1kYU0bV G1rgNjdLb62CWYBNSs/hudW4xXXalb2VhMc3z6k8MTHM9wrzg+CjiUFJX8HNeQ5T UAmGsawdSoZ8BL6hByX1fmoyFEvjQxVqk5A== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:content-transfer-encoding:content-type :content-type:date:date:feedback-id:feedback-id:from:from :in-reply-to:in-reply-to:message-id:mime-version:references :reply-to:sender:subject:subject:to:to:x-me-proxy:x-me-proxy :x-me-sender:x-me-sender:x-sasl-enc; s=fm1; t=1684431370; x= 1684517770; bh=+RRQKmP7+cSeL/VIgGOtkyG26H7JVRL971/twqLNDiE=; b=j ri0KPTycGoWMdkrFS26DuqwVSKwIYGOV7cZIDnzRo9E7550bMIOECsG5uxiOWGCu UM5izZZE3sK5ZY4ZyUWK+pr4d4fenfuezHdmeexutIPP8NhCtcddT6vttFz77v/U 3JfmYq1wSPpJYotUCdJNiT39muBdh0kpuX0kqk8snCbTXE3FA0aJlTCGxA24b1sC H2JVZ1emiv4TnXO+EJrfHAsGqlY/NDgb6dHP0hjHFjwYtY+ruoAbFfGJg7gQ5kAR GXYNHQbZK4T7ChSWBvnNuFftqUPyEydfni9qdghT9g9/JKq47lKmgBdTVmD7WuPr uNjmeTPMeHIbkOoa2vlMw== X-ME-Sender: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvhedrfeeifedguddugecutefuodetggdotefrod ftvfcurfhrohhfihhlvgemucfhrghsthforghilhdpqfgfvfdpuffrtefokffrpgfnqfgh necuuegrihhlohhuthemuceftddtnecusecvtfgvtghiphhivghnthhsucdlqddutddtmd enucfjughrpefofgggkfgjfhffhffvufgtgfesthhqredtreerjeenucfhrhhomhepfdft vggsvggttggrucevrhgrnhdfuceorhgvsggvtggtrgessghsughiohdrtghomheqnecugg ftrfgrthhtvghrnhepffevheeivddvffffhfekleehffegledtteetheeiueeivdelteeh hfduvdehiefhnecuffhomhgrihhnpehgrhhouhhpshdrihhonecuvehluhhsthgvrhfuih iivgeptdenucfrrghrrghmpehmrghilhhfrhhomheprhgvsggvtggtrgessghsughiohdr tghomh X-ME-Proxy: Feedback-ID: i5b994698:Fastmail Received: by mailuser.nyi.internal (Postfix, from userid 501) id A22562D4008F; Thu, 18 May 2023 13:36:09 -0400 (EDT) X-Mailer: MessagingEngine.com Webmail Interface User-Agent: Cyrus-JMAP/3.9.0-alpha0-431-g1d6a3ebb56-fm-20230511.001-g1d6a3ebb Mime-Version: 1.0 Message-Id: In-Reply-To: References: Date: Thu, 18 May 2023 11:36:09 -0600 From: "Rebecca Cran" To: devel@edk2.groups.io, "Kinney, Michael D" , "Ray' 'Ni" Subject: Re: [edk2-devel] CpuDeadLoop() is optimized by compiler Content-Type: text/plain;charset=utf-8 Content-Transfer-Encoding: quoted-printable When I use CpuDeadLoop for debugging on Aarch64 I have symbols loaded so I = can just do =E2=80=98set Index=3D1=E2=80=99 and resume, but it sounds like = the issue is that people want to sometimes debug without symbols/source, an= d the generated assembly is making that difficult. Rebecca On Thu, May 18, 2023, at 9:36 AM, Michael D Kinney wrote: > Hi Ray, >=20 > So the code generated does deadloop, but is just not easy to resume=20 > from as we have been able to do in the past. >=20 > We use CpuDeadloop() for 2 purposes. One is a terminal condition with=20 > no reason to ever continue. >=20 > The 2nd is a debug aide for developers to halt the system at a specific= =20 > location and then continue from that point, usually with a debugger, to= =20 > step through code to an area to evaluate unexpected behavior. >=20 > We may have to do a NASM implementation of CpuDeadloop() to make sure=20 > it meets both use cases. >=20 > Mike >=20 > *From:* Ni, Ray =20 > *Sent:* Thursday, May 18, 2023 3:00 AM > *To:* devel@edk2.groups.io > *Cc:* Kinney, Michael D ; Rebecca Cran=20 > ; Ni, Ray > *Subject:* CpuDeadLoop() is optimized by compiler >=20 > Hi, > Starting from certain version of Visual Studio C compiler (I don=E2=80=99= t have=20 > the exact version. I am using VS2019), CpuDeadLoop is now optimized=20 > quite well by compiler. >=20 > The optimization is so =E2=80=9Cgood=E2=80=9D that it becomes harder for = developers to=20 > break out of the deadloop. >=20 > I copied the assembly instructions as below for your reference. > The compiler does not generate instructions that jump out of the loop=20 > when the Index is not zero. > So in order to break out of the loop, developers need to: > 1. Manually adjust rsp by increasing 40 > 2. Manually =E2=80=9Cret=E2=80=9D >=20 > I am not sure if anyone has interest to re-write this function so that=20 > compiler can be =E2=80=9Cfooled=E2=80=9D again. > Thanks, > Ray >=20 > =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D > ; Function compile flags: /Ogspy > ; File e:\work\edk2\MdePkg\Library\BaseLib\CpuDeadLoop.c > ; COMDAT CpuDeadLoop > _TEXT SEGMENT > Index$ =3D 48 > CpuDeadLoop PROC = =20 > ; COMDAT >=20 > ; 26 : { >=20 > $LN12: > 00000 48 83 ec 28 sub rsp, 40 = =20 > ; 00000028H >=20 > ; 27 : volatile UINTN Index; > ; 28 :=20 > ; 29 : for (Index =3D 0; Index =3D=3D 0;) { >=20 > 00004 48 c7 44 24 30 > 00 00 00 00 mov QWORD PTR Index$[rsp], 0 > $LN10@CpuDeadLoo: >=20 > ; 30 : CpuPause (); >=20 > 0000d 48 8b 44 24 30 mov rax, QWORD PTR Index$[rsp] > 00012 e8 00 00 00 00 call CpuPause > 00017 eb f4 jmp SHORT $LN10@CpuDeadLoo > CpuDeadLoop ENDP > _TEXT ENDS > END >=20 >=20 >=20