Commit | Line | Data |
---|---|---|
86530b38 AT |
1 | |
2 | class GetAttrError(Exception): | |
3 | def __init__(self,name): | |
4 | Exception.__init__(self) | |
5 | self.name = name | |
6 | def __str__(self): | |
7 | return "The strand has no getable state member '"+self.name+"'" | |
8 | ||
9 | class DelAttrError(Exception): | |
10 | def __init__(self,name): | |
11 | Exception.__init__(self) | |
12 | self.name = name | |
13 | def __str__(self): | |
14 | return "Strand attributes such as "+self.name+" can not be deleted" | |
15 | ||
16 | class SetAttrError(Exception): | |
17 | def __init__(self,name): | |
18 | Exception.__init__(self) | |
19 | self.name = name | |
20 | def __str__(self): | |
21 | return "The strand has no setable state member '"+name+"'" | |
22 | ||
23 | class TrapLevelZeroError(Exception): | |
24 | def __init__(self): | |
25 | Exception.__init__(self) | |
26 | def __str__(self): | |
27 | return "Trap state can not be accessed when tl=0" | |
28 | ||
29 | ||
30 | def __geterror_fun__(name,strand): | |
31 | raise GetAttrError(name) | |
32 | def __seterror_fun__(name,strand,value): | |
33 | raise SetAttrError(name) | |
34 | ||
35 | def __geterror__(name): | |
36 | return lambda strand: __geterror_fun__(name,strand) | |
37 | def __seterror__(name): | |
38 | return lambda strand,value: __seterror_fun__(name,strand,value) | |
39 | ||
40 | ||
41 | def __gettl_check__(strand): | |
42 | tl = Strand.__getfun__['tl'](strand) | |
43 | if tl == 0: | |
44 | raise TrapLevelZeroError() | |
45 | return tl | |
46 | ||
47 | def __gettt__(strand): return TrapStack.__getfun__['tt'](strand,__gettl_check__(strand)) | |
48 | def __settt__(strand,value): TrapStack.__setfun__['tt'](strand,__gettl_check__(strand),value) | |
49 | def __gettpc__(strand): return TrapStack.__getfun__['tpc'](strand,__gettl_check__(strand)) | |
50 | def __settpc__(strand,value): TrapStack.__setfun__['tpc'](strand,__gettl_check__(strand),value) | |
51 | def __gettnpc__(strand): return TrapStack.__getfun__['tnpc'](strand,__gettl_check__(strand)) | |
52 | def __settnpc__(strand,value): TrapStack.__setfun__['tnpc'](strand,__gettl_check__(strand),value) | |
53 | def __gettstate__(strand): return TrapStack.__getfun__['tstate'](strand,__gettl_check__(strand)) | |
54 | def __settstate__(strand,value): TrapStack.__setfun__['tstate'](strand,__gettl_check__(strand),value) | |
55 | def __gethtstate__(strand): return TrapStack.__getfun__['htstate'](strand,__gettl_check__(strand)) | |
56 | def __sethtstate__(strand,value): TrapStack.__setfun__['htstate'](strand,__gettl_check__(strand),value) | |
57 | ||
58 | ||
59 | class Strand: | |
60 | __getfun__= { | |
61 | 'tt': __gettt__, | |
62 | 'tpc': __gettpc__, | |
63 | 'tnpc': __gettnpc__, | |
64 | 'tstate': __gettstate__, | |
65 | 'htstate': __gethtstate__ | |
66 | } | |
67 | __setfun__ = { | |
68 | 'tt': __settt__, | |
69 | 'tpc': __settpc__, | |
70 | 'tnpc': __settnpc__, | |
71 | 'tstate': __settstate__, | |
72 | 'htstate': __sethtstate__ | |
73 | } | |
74 | ||
75 | for i in ['pc', 'npc', 'cwp', 'cansave', 'canrestore', 'otherwin', 'cleanwin', 'wstate', | |
76 | 'y', 'asi', 'ccr', 'fsr', 'gsr', 'fprs', 'pil', 'softint', | |
77 | 'tl', 'gl', 'pstate', 'hpstate', 'tba', 'htba', 'hver', 'hintp', | |
78 | 'tick', 'stick', 'tick_cmpr', 'stick_cmpr', 'hstick_cmpr', 'rstv_addr' | |
79 | 'max_tl', 'max_gl', 'max_ptl', 'max_pgl','max_wp','strand_id']: | |
80 | __getfun__[i] = __geterror__(i) | |
81 | __setfun__[i] = __seterror__(i) | |
82 | ||
83 | __irf__ = ['g%d' % i for i in range(0,8)]\ | |
84 | + ['o%d' % i for i in range(0,8)]\ | |
85 | + ['l%d' % i for i in range(0,8)]\ | |
86 | + ['i%d' % i for i in range(0,8)] | |
87 | __frf__ = ['f%d' % i for i in range(0,64)] | |
88 | __drf__ = ['d%d' % i for i in range(0,64,2)] | |
89 | __qrf__ = ['q%d' % i for i in range(0,64,4)] | |
90 | __asr__ = ['asr%d' % i for i in range(0,32)] | |
91 | __pr__ = ['pr%d' % i for i in range(0,32)] | |
92 | __hpr__ = ['hpr%d' % i for i in range(0,32)] | |
93 | __sim__ = ['sim%d' % i for i in range(0,32)] | |
94 | ||
95 | for i in __irf__: | |
96 | __getfun__[i] = __geterror__(i) | |
97 | __setfun__[i] = __seterror__(i) | |
98 | for i in __frf__: | |
99 | __getfun__[i] = __geterror__(i) | |
100 | __setfun__[i] = __seterror__(i) | |
101 | for i in __drf__: | |
102 | __getfun__[i] = __geterror__(i) | |
103 | __setfun__[i] = __seterror__(i) | |
104 | for i in __qrf__: | |
105 | __getfun__[i] = __geterror__(i) | |
106 | __setfun__[i] = __seterror__(i) | |
107 | for i in __asr__: | |
108 | __getfun__[i] = __geterror__(i) | |
109 | __setfun__[i] = __seterror__(i) | |
110 | for i in __pr__: | |
111 | __getfun__[i] = __geterror__(i) | |
112 | __setfun__[i] = __seterror__(i) | |
113 | for i in __hpr__: | |
114 | __getfun__[i] = __geterror__(i) | |
115 | __setfun__[i] = __seterror__(i) | |
116 | for i in __sim__: | |
117 | __getfun__[i] = __geterror__(i) | |
118 | __setfun__[i] = __seterror__(i) | |
119 | ||
120 | del i | |
121 | ||
122 | def __init__(self,strand,ref): | |
123 | self.__dict__['__strand__'] = strand | |
124 | self.__dict__['ref'] = ref | |
125 | self.__dict__['inst_tlb'] = {} | |
126 | self.__dict__['data_tlb'] = {} | |
127 | self.__dict__['brk'] = {} | |
128 | self.__dict__['t'] = TrapStack(strand) | |
129 | self.__dict__['g'] = GlobalStack(strand) | |
130 | self.__dict__['w'] = WindowStack(strand) | |
131 | self.__dict__['__listing__'] = 0 | |
132 | self.__dict__['__verify__'] = False | |
133 | self.__dict__['__ras__'] = False | |
134 | ||
135 | def __getattr__(self,name): | |
136 | if Strand.__getfun__.has_key(name): | |
137 | return Strand.__getfun__[name](self.__strand__) | |
138 | raise GetAttrError(name) | |
139 | ||
140 | def __setattr__(self,name,data): | |
141 | if Strand.__setfun__.has_key(name): | |
142 | return Strand.__setfun__[name](self.__strand__,data) | |
143 | #self.__dict__[name] = data | |
144 | if self.__dict__.has_key(name): | |
145 | self.__dict__[name] = data | |
146 | return | |
147 | #else: | |
148 | # print 'Cant set. No strand attribute %s\n' % (name,) | |
149 | ||
150 | try: | |
151 | getattr(self,name) | |
152 | except GetAttrError: | |
153 | return 'Cant set. No strand attribute %s\n' % (name,) | |
154 | else: | |
155 | self.__dict__[name] = data | |
156 | ||
157 | ||
158 | def __delattr__(self,name): | |
159 | if name == 'brk': | |
160 | for i in self.brk: | |
161 | del self.brk[i] | |
162 | elif name == 'inst_tlb': | |
163 | for i in self.inst_tbl: | |
164 | del self.inst_tlb[i] | |
165 | elif name == 'data_tlb': | |
166 | for i in self.data_tbl: | |
167 | del self.data_tlb[i] | |
168 | elif name == '__strand__' or name == 't': | |
169 | DelAttrError(name) | |
170 | else: | |
171 | del self.__dict__[name] | |
172 | ||
173 | def __repr__(self): | |
174 | return "<Strand instance>" | |
175 | ||
176 | def __str__(self): | |
177 | return "<Strand instance>" | |
178 | ||
179 | #------------------------------------------------------------------------ | |
180 | # mode switching related interface | |
181 | #------------------------------------------------------------------------ | |
182 | ||
183 | def lstmode(self,lstval = None): | |
184 | """ | |
185 | lstmode() switches the strand to listing mode based on the value of lstval | |
186 | a value of 0 disables the list mode. | |
187 | a value of 1 enables the list mode where the executed instruction along | |
188 | with the sideeffects are displayed. | |
189 | a value of 2 enables the list mode where only the executed instruction | |
190 | is displayed. | |
191 | w/o an argument the current listing mode is returned | |
192 | """ | |
193 | if lstval == None: | |
194 | return self.__listing__ | |
195 | elif type(lstval) != int: | |
196 | raise TypeError | |
197 | ||
198 | self.__listing__ = lstval | |
199 | ||
200 | if lstval != 0: | |
201 | self.step = self.__lststep__ | |
202 | if lstval == 1: | |
203 | if self.__dict__.has_key('__lstnames__'): | |
204 | if self.tl == 0: | |
205 | for r in self.__lstnames__: | |
206 | if r in ['tt','tpc','tnpc','tstate','htstate']: | |
207 | self.__lststate__[r] = None | |
208 | else: | |
209 | self.__lststate__[r] = getattr(self,r) | |
210 | else: | |
211 | for r in self.__lststate__: | |
212 | self.__lststate__[r] = getattr(self,r) | |
213 | else: | |
214 | self.step = self.__runstep__ | |
215 | ||
216 | ||
217 | def vrfmode(self,on): | |
218 | """ | |
219 | vrfmode() switches the strand to verification mode when on=True, e.g turn of optimisations for | |
220 | run mode. This means that every load/store and instruction fetch goes through the | |
221 | mmu. | |
222 | """ | |
223 | if on == None: | |
224 | return self.__verify__ | |
225 | elif type(on) != bool: | |
226 | raise TypeError | |
227 | ||
228 | self.__verify__ = on | |
229 | ||
230 | ||
231 | def rasmode(self,on): | |
232 | """ | |
233 | rasmode() switches the strand into ras mode when on=True, expects vrfmode to be on | |
234 | """ | |
235 | if on == None: | |
236 | return self.__ras__ | |
237 | elif type(on) != bool: | |
238 | raise TypeError | |
239 | ||
240 | self.__ras__ = on | |
241 | ||
242 | #------------------------------------------------------------------------ | |
243 | # translate addresses | |
244 | #------------------------------------------------------------------------ | |
245 | ||
246 | def va2pa(self,va,ctx=None,pid=None): | |
247 | pass | |
248 | ||
249 | def ra2pa(self,ra,pid=None): | |
250 | pass | |
251 | ||
252 | #------------------------------------------------------------------------ | |
253 | # CMP related interface | |
254 | #------------------------------------------------------------------------ | |
255 | ||
256 | def available(self,on=None): | |
257 | pass | |
258 | ||
259 | def enable(self,on=None): | |
260 | pass | |
261 | ||
262 | def running(self,on=None): | |
263 | pass | |
264 | ||
265 | def stepping(self,on=None): | |
266 | pass | |
267 | ||
268 | #------------------------------------------------------------------------ | |
269 | # step related interface | |
270 | #------------------------------------------------------------------------ | |
271 | ||
272 | def step(self,n=None): | |
273 | """ | |
274 | step() steps the simulator n instructions forward | |
275 | The method is switched between __runstep__ and __lststep__ by lstmode() | |
276 | """ | |
277 | pass | |
278 | ||
279 | def __runstep__(self,n=None): | |
280 | """ | |
281 | runstep() steps the simulator n instruction without echoing inpstr to output | |
282 | """ | |
283 | pass | |
284 | ||
285 | def __lststep__(self,n=None): | |
286 | """ | |
287 | lststep() steps the simulator n instruction and echo instr to output | |
288 | """ | |
289 | pass | |
290 | ||
291 | ||
292 | ||
293 | class TrapStackEntry: | |
294 | def __init__(self,strand,tl): | |
295 | self.__dict__['strand'] = strand | |
296 | self.__dict__['tl'] = tl | |
297 | ||
298 | def __getattr__(self,name): | |
299 | return TrapStack.__getfun__[name](self.strand,self.tl) | |
300 | ||
301 | def __setattr__(self,name,value): | |
302 | return TrapStack.__setfun__[name](self.strand,self.tl,value) | |
303 | ||
304 | ||
305 | class TrapStack: | |
306 | MAXTL = 15 | |
307 | ||
308 | __getfun__ = {} | |
309 | __setfun__ = {} | |
310 | ||
311 | for field in ['tt','tpc','tnpc','tstate','htstate']: | |
312 | __getfun__[field] = __geterror__(field) | |
313 | __setfun__[field] = __seterror__(field) | |
314 | del field | |
315 | ||
316 | def __init__(self,strand): | |
317 | self.trap_stack = {} | |
318 | for tl in range(1,TrapStack.MAXTL): | |
319 | self.trap_stack[tl] = TrapStackEntry(strand,tl) | |
320 | ||
321 | def __getitem__(self,index): | |
322 | if index == 0: | |
323 | raise TrapLevelZeroError() | |
324 | return self.trap_stack[index] | |
325 | ||
326 | ||
327 | class GlobalStackEntry: | |
328 | def __init__(self,strand,gl): | |
329 | self.__dict__['strand'] = strand | |
330 | self.__dict__['gl'] = gl | |
331 | ||
332 | def __getattr__(self,name): | |
333 | return GlobalStack.__getfun__[name](self.strand,self.gl) | |
334 | ||
335 | def __setattr__(self,name,value): | |
336 | return GlobalStack.__setfun__[name](self.strand,self.gl,value) | |
337 | ||
338 | def __getitem__(self,index): | |
339 | return GlobalStack.__getfun__[index](self.strand,self.gl) | |
340 | ||
341 | def setitem__(self,index,value): | |
342 | return GlobalStack.__setfun__[index](self.strand,self.gl,value) | |
343 | ||
344 | class GlobalStack: | |
345 | MAXGL=15 | |
346 | ||
347 | __getfun__ = {} | |
348 | __setfun__ = {} | |
349 | ||
350 | for r in ['g%d' % i for i in range(0,8)]: | |
351 | __getfun__[r] = __geterror__(r) | |
352 | __setfun__[r] = __seterror__(r) | |
353 | ||
354 | def __init__(self,strand): | |
355 | self.global_stack = {} | |
356 | for gl in range(0,GlobalStack.MAXGL + 1): | |
357 | self.global_stack[gl] = GlobalStackEntry(strand,gl) | |
358 | ||
359 | def __getitem__(self,index): | |
360 | return self.global_stack[index] | |
361 | ||
362 | class WindowRegEntry: | |
363 | def __init__(self,strand,win): | |
364 | self.__dict__['strand'] = strand | |
365 | self.__dict__['win'] = win | |
366 | ||
367 | def __getattr__(self,name): | |
368 | return WindowStack.__getfun__[name](self.strand,self.win) | |
369 | ||
370 | def __setattr__(self,name,value): | |
371 | return WindowStack.__setfun__[name](self.strand,self.win,value) | |
372 | ||
373 | def __getitem__(self,index): | |
374 | return WindowStack.__getfun__[index](self.strand,self.win) | |
375 | ||
376 | def __setitem__(self,index,value): | |
377 | return WindowStack.__setfun__[index](self.strand,self.win,value) | |
378 | ||
379 | ||
380 | class WindowStack: | |
381 | MAXWP = 32 | |
382 | ||
383 | __getfun__ = {} | |
384 | __setfun__ = {} | |
385 | ||
386 | for r in Strand.__irf__[8:]: | |
387 | __getfun__[r] = __geterror__(r) | |
388 | __setfun__[r] = __seterror__(r) | |
389 | ||
390 | def __init__(self,strand): | |
391 | self.window_stack = {} | |
392 | for win in range(0,WindowStack.MAXWP): | |
393 | self.window_stack[win] = WindowRegEntry(strand,win) | |
394 | ||
395 | def __getitem__(self,index): | |
396 | return self.window_stack[index] | |
397 | ||
398 | ||
399 | ||
400 | ||
401 | ||
402 | ||
403 | ||
404 | ||
405 | ||
406 | ||
407 | ||
408 | ||
409 | ||
410 |