Mercurial > hg > ede
comparison dbg/dbg.py @ 28:6d32e54e5c16
emulator overhauled really, new a better memory structure
also cleaned up the file system some what.
author | james <jb302@eecs.qmul.ac.uk> |
---|---|
date | Fri, 11 Apr 2014 14:38:09 +0100 |
parents | |
children | 83e80c2c489c |
comparison
equal
deleted
inserted
replaced
27:a542cd390efd | 28:6d32e54e5c16 |
---|---|
1 #!/usr/bin/env python | |
2 # dbg.py - debug client | |
3 import struct | |
4 import os, sys | |
5 from subprocess import Popen, PIPE, STDOUT | |
6 | |
7 emu = Popen(['./a.out'], stdout=PIPE, stdin=PIPE, stderr=PIPE) | |
8 | |
9 def snd(m): | |
10 emu.stdin.write(struct.pack('>B', m)) | |
11 | |
12 def rcv(): | |
13 with open('out', 'r') as f: | |
14 c = f.read() | |
15 return c | |
16 | |
17 def step(): | |
18 snd(0x00) | |
19 | |
20 def run(): | |
21 snd(0x01) | |
22 | |
23 def set_reg(reg, data): | |
24 snd(0x02) | |
25 snd(reg) # reg | |
26 snd(data) # data | |
27 | |
28 def get_reg(reg): | |
29 snd(0x03) | |
30 snd(reg) # reg | |
31 #return rcv() | |
32 | |
33 def set_flag(flag, on): | |
34 snd(0x04) | |
35 if on == 0: | |
36 snd(flag) | |
37 snd(0) | |
38 else: | |
39 snd(flag) | |
40 snd(1) | |
41 | |
42 def get_flag(flag): | |
43 snd(0x05) | |
44 snd(flag) | |
45 #return rcv() | |
46 | |
47 def set_block(addrh, addrl, lenh, lenl, data): | |
48 snd(0x06) | |
49 snd(addrh) # address high byte | |
50 snd(addrl) # address low byte | |
51 snd(lenh) | |
52 snd(lenl) | |
53 for b in data: | |
54 snd(b) # data | |
55 | |
56 def get_block(addrh, addrl, lenh, lenl): | |
57 block = [] | |
58 snd(0x07) | |
59 snd(addrh) # address high byte | |
60 snd(addrl) # address low byte | |
61 snd(lenh) | |
62 snd(lenl) | |
63 #lc = 0 | |
64 #while lc != l: | |
65 # lc = os.path.getsize('out'); | |
66 #return rcv() | |
67 | |
68 registers = { | |
69 'r0':0, | |
70 'r1':1, | |
71 'r2':2, | |
72 'r3':3, | |
73 'dph':4, | |
74 'dpl':5, | |
75 'sph':6, | |
76 'spl':7, | |
77 'a':8, | |
78 'flags':9 | |
79 } | |
80 | |
81 cmds = { | |
82 'step':step, | |
83 'run':run, | |
84 'sr':set_reg, | |
85 'gr':get_reg, | |
86 'sf':set_flag, | |
87 'gf':get_flag, | |
88 'sb':set_block, | |
89 'gb':get_block | |
90 } |