Commit | Line | Data |
---|---|---|
86530b38 AT |
1 | |
2 | from Pfe_Conversion import * | |
3 | ||
4 | #---------------------------------------------------------------------------- | |
5 | # Io is the wrapper that provides the hooks to all the ways to access | |
6 | # io: 1,2,4,8 bytes, int or double, or little endian ... | |
7 | #---------------------------------------------------------------------------- | |
8 | ||
9 | class Io: | |
10 | """ | |
11 | Io io | |
12 | """ | |
13 | def __init__(self): | |
14 | self.b = IoInterface(self,self.__ldb__, self.__stb__,1) | |
15 | self.h = IoInterface(self,self.__ldh__, self.__sth__,2) | |
16 | self.w = IoInterface(self,self.__ldw__, self.__stw__,4) | |
17 | self.x = IoInterface(self,self.__ldx__ , self.__stx__,8) | |
18 | self.f = IoInterface(self,self.__ldf__, self.__stf__,4) | |
19 | self.d = IoInterface(self,self.__ldd__, self.__std__,8) | |
20 | self.c = IoInterface(self,self.__ldc__, self.__stc__,1) | |
21 | self.cl = self.c # ha, simply for completeness | |
22 | self.bl = self.b # ha, simply for completeness | |
23 | self.hl = IoInterface(self,self.__ldhl__, self.__sthl__,2) | |
24 | self.wl = IoInterface(self,self.__ldwl__, self.__stwl__,4) | |
25 | self.xl = IoInterface(self,self.__ldxl__, self.__stxl__,8) | |
26 | self.fl = IoInterface(self,self.__ldfl__, self.__stfl__,4) | |
27 | self.dl = IoInterface(self,self.__lddl__, self.__stdl__,8) | |
28 | ||
29 | ||
30 | # __ldb__(), __ldh__(), __ldw__(), and __ldx__() implement 1, 2, 4 and | |
31 | # 8 byte load operations. They need to be provided by the implementation. | |
32 | ||
33 | def __ldb__(self,sid,addr): pass | |
34 | def __ldh__(self,sid,addr): pass | |
35 | def __ldw__(self,sid,addr): pass | |
36 | def __ldx__(self,sid,addr): pass | |
37 | ||
38 | # __stb__(), __sth__(), __stw__(), and __stx__() implement 1, 2, 4 and | |
39 | # 8 byte store operations. They need to be provided by the implementation. | |
40 | ||
41 | def __stb__(self,sid,addr,data): pass | |
42 | def __sth__(self,sid,addr,data): pass | |
43 | def __stw__(self,sid,addr,data): pass | |
44 | def __stx__(self,sid,addr,data): pass | |
45 | ||
46 | def __ldc__( self,sid,addr): return chr(self.__ldb__(sid,addr)) | |
47 | def __ldf__( self,sid,addr): return w2f(self.__ldw__(sid,addr)) | |
48 | def __ldd__( self,sid,addr): return x2d(long(self.__ldx__(sid,addr))) | |
49 | def __ldhl__(self,sid,addr): return h2h(self.__ldh__(sid,addr)) | |
50 | def __ldwl__(self,sid,addr): return w2w(self.__ldw__(sid,addr)) | |
51 | def __ldxl__(self,sid,addr): return x2x(long(self.__ldx__(sid,addr))) | |
52 | def __ldfl__(self,sid,addr): return w2f(self.__ldwl__(sid,addr)) | |
53 | def __lddl__(self,sid,addr): return x2d(self.__ldxl__(sid,addr)) | |
54 | ||
55 | def __stc__( self,sid,addr,data): self.__stb__(sid,addr,ord(data)) | |
56 | def __stf__( self,sid,addr,data): self.__stw__(sid,addr,f2w(data)) | |
57 | def __std__( self,sid,addr,data): self.__stx__(sid,addr,d2x(data)) | |
58 | def __sthl__(self,sid,addr,data): self.__sth__(sid,addr,h2h(data)) | |
59 | def __stwl__(self,sid,addr,data): self.__stw__(sid,addr,w2w(data)) | |
60 | def __stxl__(self,sid,addr,data): self.__stx__(sid,addr,x2x(long(data))) | |
61 | def __stfl__(self,sid,addr,data): self.__stwl__(sid,addr,f2w(data)) | |
62 | def __stdl__(self,sid,addr,data): self.__stxl__(sid,addr,d2x(data)) | |
63 | ||
64 | ||
65 | #---------------------------------------------------------------------------- | |
66 | # IoInterface implements the actual index operator for | |
67 | # the various io sizes, expliting pythons slicing operator | |
68 | #---------------------------------------------------------------------------- | |
69 | ||
70 | class IoInterface: | |
71 | def __init__(self,io,load,store,size): | |
72 | self.__io__ = io | |
73 | self.__ld__ = load | |
74 | self.__st__ = store | |
75 | self.__size__ = size | |
76 | ||
77 | def slice_step(self,__slice__,step): | |
78 | if __slice__.step == None: | |
79 | return step | |
80 | else: | |
81 | return __slice__.step | |
82 | ||
83 | def __len__(self): | |
84 | return long(1 << 55) | |
85 | ||
86 | def __getitem__(self,address): | |
87 | if type(address) == slice: | |
88 | m = [] | |
89 | a = address.start | |
90 | s = self.slice_step(address,self.__size__) | |
91 | while a < address.stop: | |
92 | m.append(self.__ld__(0,a)) | |
93 | a += s | |
94 | return m | |
95 | else: | |
96 | return self.__ld__(0,address) | |
97 | ||
98 | def __setitem__(self,address,value): | |
99 | if type(address) == slice: | |
100 | a = address.start | |
101 | s = self.slice_step(address,self.__size__) | |
102 | i = 0 | |
103 | while a < address.stop and i < len(value): | |
104 | self.__st__(0,a,value[i]) | |
105 | a += s | |
106 | i += 1 | |
107 | else: | |
108 | self.__st__(0,address,value) | |
109 | ||
110 | ||
111 | ||
112 | ||
113 | ||
114 | ||
115 | ||
116 | ||
117 | ||
118 | ||
119 | ||
120 | ||
121 | ||
122 | ||
123 | ||
124 |