-
Notifications
You must be signed in to change notification settings - Fork 14.3k
[lldb][debugserver] Read/write SME registers on arm64 #119171
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
jasonmolenda
merged 11 commits into
llvm:main
from
jasonmolenda:add-sme-register-support-to-debugserver
Dec 19, 2024
Merged
Changes from all commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
2e3738e
[lldb][debugserver] Read/write SME registers on arm64
jasonmolenda 87bdde7
reformats refomatted
jasonmolenda 1c94310
reformat until refomatting bot is appeased
jasonmolenda 157a1b7
Update test case:
jasonmolenda 1fac08c
typeo fix
jasonmolenda 2e964a4
clear up old/new values a bit more
jasonmolenda 697340e
Carefully testing SME and non-SME hardware showed some testsuite issues
jasonmolenda 8daf124
Small fix to the zeroing of the SME regs before attempting reads
jasonmolenda 110860f
fix whitespace nit
jasonmolenda 6ad5249
Simplify a conditional in the API test.
jasonmolenda 76d88c2
Merge branch 'main' into add-sme-register-support-to-debugserver
jasonmolenda File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
C_SOURCES := main.c | ||
|
||
CFLAGS_EXTRAS := -mcpu=apple-m4 | ||
|
||
include Makefile.rules |
217 changes: 217 additions & 0 deletions
217
lldb/test/API/macosx/sme-registers/TestSMERegistersDarwin.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,217 @@ | ||
import lldb | ||
from lldbsuite.test.lldbtest import * | ||
from lldbsuite.test.decorators import * | ||
import lldbsuite.test.lldbutil as lldbutil | ||
import os | ||
|
||
|
||
class TestSMERegistersDarwin(TestBase): | ||
NO_DEBUG_INFO_TESTCASE = True | ||
mydir = TestBase.compute_mydir(__file__) | ||
|
||
@skipIfRemote | ||
@skipUnlessDarwin | ||
@skipUnlessFeature("hw.optional.arm.FEAT_SME") | ||
@skipUnlessFeature("hw.optional.arm.FEAT_SME2") | ||
# thread_set_state/thread_get_state only avail in macOS 15.4+ | ||
@skipIf(macos_version=["<", "15.4"]) | ||
def test(self): | ||
"""Test that we can read the contents of the SME/SVE registers on Darwin""" | ||
self.build() | ||
(target, process, thread, bkpt) = lldbutil.run_to_source_breakpoint( | ||
self, "break before sme", lldb.SBFileSpec("main.c") | ||
) | ||
frame = thread.GetFrameAtIndex(0) | ||
self.assertTrue(frame.IsValid()) | ||
|
||
self.assertTrue( | ||
target.BreakpointCreateBySourceRegex( | ||
"break while sme", lldb.SBFileSpec("main.c") | ||
).IsValid() | ||
) | ||
self.assertTrue( | ||
target.BreakpointCreateBySourceRegex( | ||
"break after sme", lldb.SBFileSpec("main.c") | ||
).IsValid() | ||
) | ||
|
||
if self.TraceOn(): | ||
self.runCmd("reg read -a") | ||
|
||
self.assertTrue(frame.register["svl"].GetError().Fail()) | ||
self.assertTrue(frame.register["z0"].GetError().Fail()) | ||
self.assertTrue(frame.register["p0"].GetError().Fail()) | ||
self.assertTrue(frame.register["za"].GetError().Fail()) | ||
self.assertTrue(frame.register["zt0"].GetError().Fail()) | ||
|
||
process.Continue() | ||
frame = thread.GetFrameAtIndex(0) | ||
self.assertEqual(thread.GetStopReason(), lldb.eStopReasonBreakpoint) | ||
|
||
# Now in SME enabled mode | ||
self.assertTrue(frame.register["svl"].GetError().Success()) | ||
self.assertTrue(frame.register["z0"].GetError().Success()) | ||
self.assertTrue(frame.register["p0"].GetError().Success()) | ||
self.assertTrue(frame.register["za"].GetError().Success()) | ||
self.assertTrue(frame.register["zt0"].GetError().Success()) | ||
|
||
# SSVE and SME modes should be enabled (reflecting PSTATE.SM and PSTATE.ZA) | ||
svcr = frame.register["svcr"] | ||
self.assertEqual(svcr.GetValueAsUnsigned(), 3) | ||
|
||
svl_reg = frame.register["svl"] | ||
svl = svl_reg.GetValueAsUnsigned() | ||
|
||
z0 = frame.register["z0"] | ||
self.assertEqual(z0.GetNumChildren(), svl) | ||
self.assertEqual(z0.GetChildAtIndex(0).GetValueAsUnsigned(), 0x1) | ||
self.assertEqual(z0.GetChildAtIndex(svl - 1).GetValueAsUnsigned(), 0x1) | ||
|
||
z31 = frame.register["z31"] | ||
self.assertEqual(z31.GetNumChildren(), svl) | ||
self.assertEqual(z31.GetChildAtIndex(0).GetValueAsUnsigned(), 32) | ||
self.assertEqual(z31.GetChildAtIndex(svl - 1).GetValueAsUnsigned(), 32) | ||
|
||
p0 = frame.register["p0"] | ||
self.assertEqual(p0.GetNumChildren(), svl / 8) | ||
self.assertEqual(p0.GetChildAtIndex(0).GetValueAsUnsigned(), 0xFF) | ||
self.assertEqual( | ||
p0.GetChildAtIndex(p0.GetNumChildren() - 1).GetValueAsUnsigned(), 0xFF | ||
) | ||
|
||
p15 = frame.register["p15"] | ||
self.assertEqual(p15.GetNumChildren(), svl / 8) | ||
self.assertEqual(p15.GetChildAtIndex(0).GetValueAsUnsigned(), 0xFF) | ||
self.assertEqual( | ||
p15.GetChildAtIndex(p15.GetNumChildren() - 1).GetValueAsUnsigned(), 0xFF | ||
) | ||
|
||
za = frame.register["za"] | ||
self.assertEqual(za.GetNumChildren(), (svl * svl)) | ||
za_0 = za.GetChildAtIndex(0) | ||
self.assertEqual(za_0.GetValueAsUnsigned(), 4) | ||
za_final = za.GetChildAtIndex(za.GetNumChildren() - 1) | ||
self.assertEqual(za_final.GetValueAsUnsigned(), 67) | ||
|
||
zt0 = frame.register["zt0"] | ||
self.assertEqual(zt0.GetNumChildren(), 64) | ||
zt0_0 = zt0.GetChildAtIndex(0) | ||
self.assertEqual(zt0_0.GetValueAsUnsigned(), 0) | ||
zt0_final = zt0.GetChildAtIndex(63) | ||
self.assertEqual(zt0_final.GetValueAsUnsigned(), 63) | ||
|
||
# Modify all of the registers, instruction step, confirm that the | ||
# registers have the new values. Without the instruction step, it's | ||
# possible debugserver or lldb could lie about the write succeeding. | ||
|
||
z0_old_values = [] | ||
DavidSpickett marked this conversation as resolved.
Show resolved
Hide resolved
|
||
z0_new_values = [] | ||
z0_new_str = '"{' | ||
for i in range(svl): | ||
z0_old_values.append(z0.GetChildAtIndex(i).GetValueAsUnsigned()) | ||
z0_new_values.append(z0_old_values[i] + 5) | ||
z0_new_str = z0_new_str + ("0x%02x " % z0_new_values[i]) | ||
z0_new_str = z0_new_str + '}"' | ||
self.runCmd("reg write z0 %s" % z0_new_str) | ||
|
||
z31_old_values = [] | ||
z31_new_values = [] | ||
z31_new_str = '"{' | ||
for i in range(svl): | ||
z31_old_values.append(z31.GetChildAtIndex(i).GetValueAsUnsigned()) | ||
z31_new_values.append(z31_old_values[i] + 3) | ||
z31_new_str = z31_new_str + ("0x%02x " % z31_new_values[i]) | ||
z31_new_str = z31_new_str + '}"' | ||
self.runCmd("reg write z31 %s" % z31_new_str) | ||
|
||
p0_old_values = [] | ||
p0_new_values = [] | ||
p0_new_str = '"{' | ||
for i in range(int(svl / 8)): | ||
p0_old_values.append(p0.GetChildAtIndex(i).GetValueAsUnsigned()) | ||
p0_new_values.append(p0_old_values[i] - 5) | ||
p0_new_str = p0_new_str + ("0x%02x " % p0_new_values[i]) | ||
p0_new_str = p0_new_str + '}"' | ||
self.runCmd("reg write p0 %s" % p0_new_str) | ||
|
||
p15_old_values = [] | ||
p15_new_values = [] | ||
p15_new_str = '"{' | ||
for i in range(int(svl / 8)): | ||
p15_old_values.append(p15.GetChildAtIndex(i).GetValueAsUnsigned()) | ||
p15_new_values.append(p15_old_values[i] - 8) | ||
p15_new_str = p15_new_str + ("0x%02x " % p15_new_values[i]) | ||
p15_new_str = p15_new_str + '}"' | ||
self.runCmd("reg write p15 %s" % p15_new_str) | ||
|
||
za_old_values = [] | ||
za_new_values = [] | ||
za_new_str = '"{' | ||
for i in range(svl * svl): | ||
za_old_values.append(za.GetChildAtIndex(i).GetValueAsUnsigned()) | ||
za_new_values.append(za_old_values[i] + 7) | ||
za_new_str = za_new_str + ("0x%02x " % za_new_values[i]) | ||
za_new_str = za_new_str + '}"' | ||
self.runCmd("reg write za %s" % za_new_str) | ||
|
||
zt0_old_values = [] | ||
zt0_new_values = [] | ||
zt0_new_str = '"{' | ||
for i in range(64): | ||
zt0_old_values.append(zt0.GetChildAtIndex(i).GetValueAsUnsigned()) | ||
zt0_new_values.append(zt0_old_values[i] + 2) | ||
zt0_new_str = zt0_new_str + ("0x%02x " % zt0_new_values[i]) | ||
zt0_new_str = zt0_new_str + '}"' | ||
self.runCmd("reg write zt0 %s" % zt0_new_str) | ||
|
||
thread.StepInstruction(False) | ||
frame = thread.GetFrameAtIndex(0) | ||
|
||
if self.TraceOn(): | ||
self.runCmd("reg read -a") | ||
|
||
z0 = frame.register["z0"] | ||
for i in range(z0.GetNumChildren()): | ||
DavidSpickett marked this conversation as resolved.
Show resolved
Hide resolved
|
||
self.assertEqual( | ||
z0_new_values[i], z0.GetChildAtIndex(i).GetValueAsUnsigned() | ||
) | ||
|
||
z31 = frame.register["z31"] | ||
for i in range(z31.GetNumChildren()): | ||
self.assertEqual( | ||
z31_new_values[i], z31.GetChildAtIndex(i).GetValueAsUnsigned() | ||
) | ||
|
||
p0 = frame.register["p0"] | ||
for i in range(p0.GetNumChildren()): | ||
self.assertEqual( | ||
p0_new_values[i], p0.GetChildAtIndex(i).GetValueAsUnsigned() | ||
) | ||
|
||
p15 = frame.register["p15"] | ||
for i in range(p15.GetNumChildren()): | ||
self.assertEqual( | ||
p15_new_values[i], p15.GetChildAtIndex(i).GetValueAsUnsigned() | ||
) | ||
|
||
za = frame.register["za"] | ||
for i in range(za.GetNumChildren()): | ||
self.assertEqual( | ||
za_new_values[i], za.GetChildAtIndex(i).GetValueAsUnsigned() | ||
) | ||
|
||
zt0 = frame.register["zt0"] | ||
for i in range(zt0.GetNumChildren()): | ||
self.assertEqual( | ||
zt0_new_values[i], zt0.GetChildAtIndex(i).GetValueAsUnsigned() | ||
) | ||
DavidSpickett marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
process.Continue() | ||
frame = thread.GetFrameAtIndex(0) | ||
self.assertEqual(thread.GetStopReason(), lldb.eStopReasonBreakpoint) | ||
|
||
self.assertTrue(frame.register["svl"].GetError().Fail()) | ||
self.assertTrue(frame.register["z0"].GetError().Fail()) | ||
self.assertTrue(frame.register["p0"].GetError().Fail()) | ||
self.assertTrue(frame.register["za"].GetError().Fail()) | ||
self.assertTrue(frame.register["zt0"].GetError().Fail()) |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nit: lots of magic values here but in all fairness that's consistent with the surrounding code. The comment covers the 8 byte granule so I'm not too concerned, though some constants might make this easier to read.