X-Git-Url: https://git.libre-soc.org/?a=blobdiff_plain;f=debug%2Fgdbserver.py;h=09938d3f1b049b4e44674be4aa901285c6fdff41;hb=4590b79bc7241f3fa2424f96b4c6666a864fb6a9;hp=924f42ae69e0fb23fc5d181f92a9719570b1a082;hpb=bf90ee0cf31a7cd0b2c535592f9970a300a8f1a5;p=riscv-tests.git diff --git a/debug/gdbserver.py b/debug/gdbserver.py index 924f42a..09938d3 100755 --- a/debug/gdbserver.py +++ b/debug/gdbserver.py @@ -12,7 +12,7 @@ import targets import testlib from testlib import assertEqual, assertNotEqual, assertIn, assertNotIn from testlib import assertGreater, assertRegexpMatches, assertLess -from testlib import GdbTest, GdbSingleHartTest, TestFailed +from testlib import GdbTest, GdbSingleHartTest, TestFailed, assertTrue MSTATUS_UIE = 0x00000001 MSTATUS_SIE = 0x00000002 @@ -65,15 +65,19 @@ def readable_binary_string(s): return "".join("%02x" % ord(c) for c in s) class SimpleRegisterTest(GdbTest): - def check_reg(self, name): + def check_reg(self, name, alias): a = random.randrange(1< main_address + 0x100) + +class PrivTest(GdbTest): + compile_args = ("programs/priv.S", ) + def setup(self): + # pylint: disable=attribute-defined-outside-init + self.gdb.load() + + misa = self.hart.misa + self.supported = 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.add(3) + +class PrivRw(PrivTest): + def test(self): + """Test reading/writing priv.""" + # Disable physical memory protection by allowing U mode access to all + # memory. + self.gdb.p("$pmpcfg0=0xf") # TOR, R, W, X + self.gdb.p("$pmpaddr0=0x%x" % ((self.hart.ram + self.hart.ram_size) >> 2)) + + # Leave the PC at _start, where the first 4 instructions should be + # legal in any mode. + for privilege in range(4): + self.gdb.p("$priv=%d" % privilege) + self.gdb.stepi() + actual = self.gdb.p("$priv") + assertIn(actual, self.supported) + if privilege in self.supported: + assertEqual(actual, privilege) + +class PrivChange(PrivTest): + def test(self): + """Test that the core's privilege level actually changes.""" + + if 0 not in self.supported: + return 'not_applicable' + + self.gdb.b("main") + self.gdb.c() + + # Machine mode + self.gdb.p("$priv=3") + main_address = self.gdb.p("$pc") + self.gdb.stepi() + assertEqual("%x" % self.gdb.p("$pc"), "%x" % (main_address+4)) + + # User mode + self.gdb.p("$priv=0") + self.gdb.stepi() + # Should have taken an exception, so be nowhere near main. + pc = self.gdb.p("$pc") + assertTrue(pc < main_address or pc > main_address + 0x100) parsed = None def main(): @@ -855,9 +869,7 @@ def main(): global parsed # pylint: disable=global-statement parsed = parser.parse_args() target = targets.target(parsed) - - if parsed.xlen: - target.xlen = parsed.xlen + testlib.print_log_names = parsed.print_log_names module = sys.modules[__name__]