Exemple #1
0
    def check_reg(self, name, alias):
        if self.hart.extensionSupported('F'):
            mstatus_fs = 0x00006000
            self.gdb.p("$mstatus=$mstatus|0x%x" % mstatus_fs)
            self.gdb.stepi()
            a = random.random()
            b = random.random()
            self.gdb.p_fpr("$%s=%f" % (name, a))
            assertLess(abs((self.gdb.p_fpr("$%s" % alias)) - a), .001)
            self.gdb.stepi()
            assertLess(abs((self.gdb.p_fpr("$%s" % name)) - a), .001)
            assertLess(abs((self.gdb.p_fpr("$%s" % alias)) - a), .001)
            self.gdb.p_fpr("$%s=%f" % (alias, b))
            assertLess(abs((self.gdb.p_fpr("$%s" % name)) - b), .001)
            self.gdb.stepi()
            assertLess(abs((self.gdb.p_fpr("$%s" % name)) - b), .001)
            assertLess(abs((self.gdb.p_fpr("$%s" % alias)) - b), .001)

            size = self.gdb.p("sizeof($%s)" % name)
            if self.hart.extensionSupported('D'):
                assertEqual(size, 8)
            else:
                assertEqual(size, 4)
        else:
            output = self.gdb.p_raw("$" + name)
            assertRegex(output, r"void|Could not fetch register.*")
            output = self.gdb.p_raw("$" + alias)
            assertRegex(output, r"void|Could not fetch register.*")
Exemple #2
0
    def test(self):
        # Get to a point in the code where some registers have actually been
        # used.
        self.gdb.b("rot13")
        self.gdb.c()
        self.gdb.c()
        # Try both forms to test gdb.
        for cmd in ("info all-registers", "info registers all"):
            output = self.gdb.command(cmd, ops=20)
            for reg in ('zero', 'ra', 'sp', 'gp', 'tp'):
                assertIn(reg, output)
            for line in output.splitlines():
                assertRegex(line, r"^\S")

        #TODO
        # mcpuid is one of the few registers that should have the high bit set
        # (for rv64).
        # Leave this commented out until gdb and spike agree on the encoding of
        # mcpuid (which is going to be renamed to misa in any case).
        #assertRegex(output, ".*mcpuid *0x80")

        #TODO:
        # The instret register should always be changing.
        #last_instret = None
        #for _ in range(5):
        #    instret = self.gdb.p("$instret")
        #    assertNotEqual(instret, last_instret)
        #    last_instret = instret
        #    self.gdb.stepi()

        self.exit()
Exemple #3
0
 def test(self):
     self.gdb.b("read_loop")
     self.gdb.command("hbreak just_before_read_loop")
     output = self.gdb.command("jump just_before_read_loop")
     assertRegex(output, r"Breakpoint \d, just_before_read_loop ")
     output = self.gdb.c()
     assertRegex(output, r"Breakpoint \d, read_loop ")
Exemple #4
0
    def setup(self):
        self.disable_pmp()

        self.gdb.load()
        self.gdb.b("main")
        output = self.gdb.c()
        assertRegex(output, r"\bmain\b")
Exemple #5
0
 def test_translation(self):
     self.gdb.b("error")
     self.gdb.b("handle_trap")
     self.gdb.b("main:active")
     output = self.gdb.c()
     assertRegex(output, r"\bmain\b")
     assertEqual(0xdeadbeef, self.gdb.p("physical[0]"))
     assertEqual(0x55667788, self.gdb.p("physical[1]"))
     assertEqual(0xdeadbeef, self.gdb.p("virtual[0]"))
     assertEqual(0x55667788, self.gdb.p("virtual[1]"))
Exemple #6
0
 def setup(self):
     # TODO: If we use a random hart, then we get into trouble because
     # gdb_read_memory_packet() ignores which hart is currently selected, so
     # we end up reading satp from hart 0 when the address translation might
     # be set up on hart 1 only.
     self.gdb.select_hart(self.target.harts[0])
     self.gdb.load()
     self.gdb.b("main")
     output = self.gdb.c()
     assertRegex(output, r"\bmain\b")
Exemple #7
0
    def test(self):
        if self.hart.instruction_hardware_breakpoint_count < 2:
            raise TestNotApplicable

        self.gdb.command("delete")
        self.gdb.hbreak("main")
        self.gdb.hbreak("rot13")
        # We should hit 3 breakpoints.
        for expected in ("main", "rot13", "rot13"):
            output = self.gdb.c()
            self.gdb.p("$pc")
            assertRegex(output, r"[bB]reakpoint")
            assertIn("%s " % expected, output)
        self.gdb.command("delete")
        self.gdb.b("_exit")
        self.exit()
Exemple #8
0
 def test(self):
     if self.hart.extensionSupported('V'):
         vlenb = self.gdb.p("$vlenb")
         # Can't write quadwords, because gdb won't parse a 128-bit hex
         # value.
         written = {}
         for name, byte_count in (('b', 1), ('s', 2), ('w', 4), ('l', 8)):
             written[name] = {}
             for i in range(vlenb // byte_count):
                 written[name][i] = random.randrange(256 ** byte_count)
                 self.gdb.p("$v13.%s[%d]=0x%x" % (name, i, written[name][i]))
             self.gdb.stepi()
             self.gdb.p("$v13")
             for i in range(vlenb // byte_count):
                 assertEqual(self.gdb.p("$v13.%s[%d]" % (name, i)),
                         written[name][i])
     else:
         output = self.gdb.p_raw("$v13")
         assertRegex(output, r"void|Could not fetch register.*")
Exemple #9
0
    def test(self):
        if self.hart.instruction_hardware_breakpoint_count < 1:
            raise TestNotApplicable

        if not self.hart.honors_tdata1_hmode:
            # Run to main before setting the breakpoint, because startup code
            # will otherwise clear the trigger that we set.
            self.gdb.b("main")
            self.gdb.c()

        self.gdb.command("delete")
        self.gdb.hbreak("rot13")
        # The breakpoint should be hit exactly 2 times.
        for _ in range(2):
            output = self.gdb.c()
            self.gdb.p("$pc")
            assertRegex(output, r"[bB]reakpoint")
            assertIn("rot13 ", output)
        self.gdb.b("_exit")
        self.exit()