Commit | Line | Data |
---|---|---|
86530b38 AT |
1 | """ |
2 | class list all commands intended for blaze in a blaze-riesling | |
3 | environment | |
4 | """ | |
5 | import sys, types | |
6 | ||
7 | import sam | |
8 | ||
9 | class SamCmdMap: | |
10 | """ | |
11 | """ | |
12 | ||
13 | def __init__ (self, blaze=None): | |
14 | """ | |
15 | """ | |
16 | self.blaze = blaze | |
17 | self.cmdMap = [ | |
18 | 'conf', | |
19 | 'connect', | |
20 | 'console-send', | |
21 | 'device', | |
22 | 'diskdelay', | |
23 | 'dbg', | |
24 | 'dump', | |
25 | 'file', | |
26 | # 'help', | |
27 | 'ioa', | |
28 | 'ldm', | |
29 | 'load', | |
30 | 'mem', | |
31 | 'memdump', | |
32 | 'memseg', | |
33 | 'mips', | |
34 | 'mmi', | |
35 | 'mod', | |
36 | 'on', | |
37 | # 5/25/05: penable/pdisable will update CMP registers and step() will check | |
38 | # core_running_status before execution, so blaze has no need to handle penable/ | |
39 | # pdisable any more, it should consider all strands are enabled at all time, | |
40 | # and let riesling strand.step() decide whenther it should step or not. | |
41 | # 'pdisable', | |
42 | # 'penable', | |
43 | # 9/2/05: pmask is used to control which blaze cpus will be enabled, this is | |
44 | # to work around CMP to get user a better control of cpu execution. | |
45 | 'pmask', | |
46 | 'rdt', | |
47 | 'regs', | |
48 | 'rstrace', | |
49 | 'run', | |
50 | 'scsi_ctrl', | |
51 | 'scsi_disk', | |
52 | 'setreg', | |
53 | 'stepi', | |
54 | 'stepim', | |
55 | 'stept', | |
56 | 'stop', | |
57 | 'sync', | |
58 | 'time', | |
59 | 'tlbdump', | |
60 | 'uldm', | |
61 | 'write', | |
62 | 'ssi', # riesling command, turn it to nop in sam | |
63 | 'runfast', # riesling command, ditto | |
64 | 'vdebug', | |
65 | 'load_symbols', | |
66 | 'unload_symbols', | |
67 | 'sym', | |
68 | 'where', | |
69 | 'tlbs' | |
70 | ] | |
71 | ||
72 | ||
73 | def issueCmd (self, cmd, output, riesReposit): | |
74 | """ | |
75 | """ | |
76 | tokens = cmd.split() | |
77 | if tokens[0] in self.cmdMap: | |
78 | if tokens[0] == 'file': | |
79 | # process the file line-by-line | |
80 | return 'execfile("%s")' % (tokens[1]) | |
81 | else: | |
82 | if ((tokens[0] == 'ssi') or (tokens[0] == 'runfast')): | |
83 | sys.stderr.write('ERROR: command %s is not supported in SAM, use "stepi N" or "run N" instead\n' % (tokens[0])) | |
84 | return None | |
85 | elif (tokens[0] == 'run'): | |
86 | if (len(tokens) > 1): | |
87 | # 'run' is a non-blocking call, if we see 'run N', | |
88 | # convert that to 'stepi N' | |
89 | cmd = 'stepi ' + ' '.join(tokens[1:]) | |
90 | else: | |
91 | # 'run' alone becomes a non-blocking call, we should | |
92 | # get UI prompt back right the way | |
93 | cmd = tokens[0] | |
94 | elif (tokens[0] == 'pmask'): | |
95 | if len(tokens) == 1: | |
96 | # query current pmask | |
97 | sys.stderr.write('%#x\n' % riesReposit.pmask) | |
98 | return None | |
99 | else: | |
100 | if not sam.is_stopped(): | |
101 | sys.stderr.write('Simulator is running, issue "stop" before changing pmask\n') | |
102 | return None | |
103 | # set blaze penable accordingly | |
104 | newMask = long(tokens[1], 16) | |
105 | toDisable = riesReposit.pmask & (~newMask & 0xffffffffffffffffL) | |
106 | toEnable = (~riesReposit.pmask & 0xffffffffffffffffL) & newMask | |
107 | #sys.stderr.write('DBX: newMask=%#x toDisable=%#x toEnable=%#x\n' % (newMask, toDisable, toEnable)) | |
108 | # disable currently enabled, but to be disabled strands | |
109 | for i in range(riesReposit.blazeNumcpu): | |
110 | if ((toDisable >> i) &0x1) == 0x1: | |
111 | cmd = 'pdisable th%d' % i | |
112 | #sys.stderr.write('DBX: cmd=%s\n' % cmd) | |
113 | #self.blaze.command(cmd) | |
114 | sam.ui_exec(cmd); | |
115 | # disable currently disabled, but to be enabled strands | |
116 | for i in range(riesReposit.blazeNumcpu): | |
117 | if ((toEnable >> i) &0x1) == 0x1: | |
118 | cmd = 'penable th%d' % i | |
119 | #sys.stderr.write('DBX: cmd=%s\n' % cmd) | |
120 | #self.blaze.command(cmd) | |
121 | sam.ui_exec(cmd); | |
122 | # update to the new mask | |
123 | riesReposit.pmask = newMask | |
124 | return None | |
125 | ||
126 | if type(output) is types.ListType: | |
127 | #output = output.append(self.blaze.command(cmd)) | |
128 | sam.ui_exec(cmd); | |
129 | else: | |
130 | #self.blaze.command(cmd) | |
131 | sam.ui_exec(cmd); | |
132 | ||
133 | ||
134 | if cmd == 'run': | |
135 | riesReposit.running = 1 | |
136 | #print "start running...." | |
137 | #sys.ps1 = 'run>' | |
138 | #elif (cmd == 'stop') or (cmd.startswith('stepi ')): | |
139 | elif cmd == 'stop': | |
140 | # don't check 'stepi' here. If we first do 'run', then | |
141 | # enter either 'run N' or 'stepi N', blaze will issue | |
142 | # 'is running' and return without doing anything, at this | |
143 | # time blaze is still in the first 'run', so we cannot | |
144 | # set running to 0 for 'run N' or 'stepi N', as they may | |
145 | # not be executed at all. | |
146 | riesReposit.running = 0 | |
147 | #print "stop command was issued." | |
148 | #sys.ps1 = 'stop>' | |
149 | ||
150 | if len(tokens) > 2 and (tokens[0] == 'mod' and | |
151 | tokens[1] == 'load'): | |
152 | # mod load xxx yyy, register 'xxx' as a command prefix, as all | |
153 | # module 'yyy' related commands will use that prefix | |
154 | if not tokens[2] in self.cmdMap: | |
155 | self.cmdMap.append(tokens[2]) | |
156 | return None | |
157 | else: | |
158 | return cmd | |
159 | ||
160 | ||
161 | def showCmd (self): | |
162 | """ | |
163 | """ | |
164 | print self.cmdMap | |
165 | ||
166 | ||
167 | """self-testing | |
168 | """ | |
169 | if __name__ == "__main__": | |
170 | pass |