Skip to content

Commit

Permalink
[debug] Add hypervisor support for PrivRw
Browse files Browse the repository at this point in the history
Change-Id: I635a8f86b407f104ea74f00f4aefa1ce8170cb2d
  • Loading branch information
lz-bro committed Nov 12, 2024
1 parent e637451 commit c2340c6
Showing 1 changed file with 12 additions and 4 deletions.
16 changes: 12 additions & 4 deletions debug/gdbserver.py
Original file line number Diff line number Diff line change
Expand Up @@ -1649,15 +1649,19 @@ def setup(self):
# pylint: disable=attribute-defined-outside-init
self.gdb.load()

misa = self.hart.misa
# It may be affected by reset halt
misa = self.gdb.p(f"$misa=0x{self.hart.misa:x}")
self.supported = set()
self.supported_vmodes = set()
if misa & (1<<20):
self.supported.add(0)
if misa & (1<<18):
self.supported.add(1)
if misa & (1<<7):
self.supported.add(2)
self.supported_vmodes = self.supported
self.supported.add(3)
for privilege in self.supported_vmodes:
self.supported.add(f"{(1 << 2) + privilege}")

self.disable_pmp()

Expand All @@ -1672,14 +1676,18 @@ def setup(self):
class PrivRw(PrivTest):
"""Test reading/writing priv."""
def test(self):
self.write_nop_program(4)
for privilege in range(4):
privilege_limit = max(self.supported) + 1
self.write_nop_program(privilege_limit)
for privilege in range(privilege_limit):
self.gdb.p(f"$priv={privilege}")
self.gdb.stepi()
actual = self.gdb.p("$priv")
assertIn(actual, self.supported)
if privilege in self.supported:
assertEqual(actual, privilege)
if len(self.supported_vmodes):
# Restore to machine mode
self.gdb.p("$priv=3")

class PrivChange(PrivTest):
"""Test that the core's privilege level actually changes when the debugger
Expand Down

0 comments on commit c2340c6

Please sign in to comment.