OpenCores
URL https://opencores.org/ocsvn/s80186/s80186/trunk

Subversion Repositories s80186

[/] [s80186/] [trunk/] [scripts/] [debug] - Blame information for rev 2

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 2 jamieiles
#!/usr/bin/env python
2
 
3
# Copyright Jamie Iles, 2017
4
#
5
# This file is part of s80x86.
6
#
7
# s80x86 is free software: you can redistribute it and/or modify
8
# it under the terms of the GNU General Public License as published by
9
# the Free Software Foundation, either version 3 of the License, or
10
# (at your option) any later version.
11
#
12
# s80x86 is distributed in the hope that it will be useful,
13
# but WITHOUT ANY WARRANTY; without even the implied warranty of
14
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15
# GNU General Public License for more details.
16
#
17
# You should have received a copy of the GNU General Public License
18
# along with s80x86.  If not, see .
19
 
20
import cmd
21
from shlex import split
22
import distorm3
23
 
24
from py8086sim.Cpu import JTAGCPU, GPR, Flag
25
 
26
regdict = {
27
    'AX': GPR.AX,
28
    'CX': GPR.CX,
29
    'DX': GPR.DX,
30
    'BX': GPR.BX,
31
    'SP': GPR.SP,
32
    'BP': GPR.BP,
33
    'SI': GPR.SI,
34
    'DI': GPR.DI,
35
    'ES': GPR.ES,
36
    'CS': GPR.CS,
37
    'SS': GPR.SS,
38
    'DS': GPR.DS,
39
    'IP': GPR.IP
40
}
41
 
42
 
43
class Debugger(cmd.Cmd):
44
    def __init__(self):
45
        cmd.Cmd.__init__(self)
46
        self.c = JTAGCPU("debugger")
47
        self._update_prompt()
48
 
49
    def _update_prompt(self):
50
        self.prompt = 'debug {0:04x}:{1:04x}> '.format(
51
            self.c.read_reg(GPR.CS), self.c.read_reg(GPR.IP))
52
 
53
    def do_reset(self, line):
54
        '''Reset the CPU'''
55
        self.c.reset()
56
        self._update_prompt()
57
        return False
58
 
59
    def do_disassemble(self, line):
60
        '''Disassemble the instruction at CS:IP'''
61
        cs = self.c.read_reg(GPR.CS)
62
        ip = self.c.read_reg(GPR.IP)
63
 
64
        buf = [chr(self.c.read_mem8(cs, ip + i)) for i in xrange(15)]
65
        instruction = distorm3.Decode(ip, ''.join(buf), distorm3.Decode16Bits)[0]
66
        _, size, instruction, _ = instruction
67
        hexbytes = ['{0:02x}'.format(ord(b)) for b in buf[:size]]
68
        print('{0:s}\t{1:s}'.format(' '.join(hexbytes), instruction.lower()))
69
 
70
        return False
71
 
72
    def do_regs(self, line):
73
        '''Display the CPU registers'''
74
        regnames = ['AX', 'CX', 'DX', 'BX', 'SP', 'BP', 'SI', 'DI', 'ES',
75
                    'CS', 'SS', 'DS', 'IP']
76
        for name in regnames:
77
            print('{name}: {val:04x}'.format(name=name,
78
                                             val=self.c.read_reg(GPR.names[name])))
79
        flagnames = ['CF', 'PF', 'AF', 'ZF', 'SF', 'TF', 'IF', 'DF', 'OF']
80
        flags = self.c.read_flags()
81
        set_flags = filter(lambda x: flags & Flag.names[x], flagnames)
82
        print('FLAGS: {0:04x} {1:s}'.format(self.c.read_flags(),
83
                                            ' '.join(set_flags)))
84
        return False
85
 
86
    def do_step(self, line):
87
        '''Single step the CPU'''
88
        self.c.step()
89
        self._update_prompt()
90
        return False
91
 
92
    def do_write_reg(self, line):
93
        '''Write a GPR
94
 
95
        REG := VAL'''
96
        tokens = split(line)
97
        assert len(tokens) == 2
98
        self.c.write_reg(regdict[tokens[0]], int(tokens[1], 16))
99
        self._update_prompt()
100
        return False
101
 
102
    def do_in16(self, line):
103
        '''Read a 16-bit IO port'''
104
        tokens = split(line)
105
        assert len(tokens) == 1
106
        print('{0:04x}'.format(self.c.read_io16(int(tokens[0], 16))))
107
        self._update_prompt()
108
        return False
109
 
110
    def do_out16(self, line):
111
        '''Write a 16-bit IO port'''
112
        tokens = split(line)
113
        assert len(tokens) == 2
114
        self.c.write_io16(int(tokens[0], 16), int(tokens[1], 16))
115
        self._update_prompt()
116
        return False
117
 
118
    def do_in8(self, line):
119
        '''Read a 8-bit IO port'''
120
        tokens = split(line)
121
        assert len(tokens) == 1
122
        print('{0:04x}'.format(self.c.read_io8(int(tokens[0], 16))))
123
        self._update_prompt()
124
        return False
125
 
126
    def do_out8(self, line):
127
        '''Write a 8-bit IO port'''
128
        tokens = split(line)
129
        assert len(tokens) == 2
130
        self.c.write_io8(int(tokens[0], 16), int(tokens[1], 16))
131
        self._update_prompt()
132
        return False
133
 
134
    def do_w16(self, line):
135
        '''Write a 16-bit value to memory'''
136
        tokens = split(line)
137
        assert len(tokens) == 2
138
        seg, offset = tokens[0].split(':')
139
        self.c.write_mem16(int(seg, 16), int(offset, 16), int(tokens[1], 16))
140
        self._update_prompt()
141
        return False
142
 
143
    def do_r16(self, line):
144
        '''Read a 16-bit value from memory'''
145
        tokens = split(line)
146
        assert len(tokens) == 1
147
        seg, offset = tokens[0].split(':')
148
        v = self.c.read_mem16(int(seg, 16), int(offset, 16))
149
        print('{0:04x}'.format(v))
150
        self._update_prompt()
151
        return False
152
 
153
    def do_EOF(self, line):
154
        print('')
155
        return True
156
 
157
Debugger().cmdloop()

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.