Initial commit of OpenSPARC T2 design and verification files.
[OpenSPARC-T2-DV] / tools / src / nas,5.n2.os.2 / pfe / Pfe_Memory.py
CommitLineData
86530b38
AT
1
2from Pfe_Conversion import *
3
4#----------------------------------------------------------------------------
5# Memory is the wrapper that provides the hooks to all the ways to access
6# memory: 1,2,4,8 bytes, int or double, or little endian ...
7#----------------------------------------------------------------------------
8
9class Memory:
10 """
11 Memory memory
12 """
13 def __init__(self):
14 self.b = MemoryInterface(self,self.__ldb__, self.__stb__,1)
15 self.h = MemoryInterface(self,self.__ldh__, self.__sth__,2)
16 self.w = MemoryInterface(self,self.__ldw__, self.__stw__,4)
17 self.x = MemoryInterface(self,self.__ldx__ , self.__stx__,8)
18 self.f = MemoryInterface(self,self.__ldf__, self.__stf__,4)
19 self.d = MemoryInterface(self,self.__ldd__, self.__std__,8)
20 self.c = MemoryInterface(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 = MemoryInterface(self,self.__ldhl__, self.__sthl__,2)
24 self.wl = MemoryInterface(self,self.__ldwl__, self.__stwl__,4)
25 self.xl = MemoryInterface(self,self.__ldxl__, self.__stxl__,8)
26 self.fl = MemoryInterface(self,self.__ldfl__, self.__stfl__,4)
27 self.dl = MemoryInterface(self,self.__lddl__, self.__stdl__,8)
28
29 def load(self,filename,addr=None): pass
30 def save(self,filename,addr,size): pass
31
32 # __flush__() needs to be provided for processor implementations that
33 # implement decode caches or i caches. The flush() is called on
34 # every store.
35
36 def __flush__(self,addr): pass
37
38 # __ldb__(), __ldh__(), __ldw__(), and __ldx__() implement 1, 2, 4 and
39 # 8 byte load operations. They need to be provided by the implementation.
40
41 def __ldb__(self,addr): pass
42 def __ldh__(self,addr): pass
43 def __ldw__(self,addr): pass
44 def __ldx__(self,addr): pass
45
46 # __stb__(), __sth__(), __stw__(), and __stx__() implement 1, 2, 4 and
47 # 8 byte store operations. They need to be provided by the implementation.
48
49 def __stb__(self,addr,data): pass
50 def __sth__(self,addr,data): pass
51 def __stw__(self,addr,data): pass
52 def __stx__(self,addr,data): pass
53
54 def __ldc__( self,addr): return chr(self.__ldb__(addr))
55 def __ldf__( self,addr): return w2f(self.__ldw__(addr))
56 def __ldd__( self,addr): return x2d(long(self.__ldx__(addr)))
57 def __ldhl__(self,addr): return h2h(self.__ldh__(addr))
58 def __ldwl__(self,addr): return w2w(self.__ldw__(addr))
59 def __ldxl__(self,addr): return x2x(long(self.__ldx__(addr)))
60 def __ldfl__(self,addr): return w2f(self.__ldwl__(addr))
61 def __lddl__(self,addr): return x2d(self.__ldxl__(addr))
62
63 def __stc__( self,addr,data): self.__stb__(addr,ord(data))
64 def __stf__( self,addr,data): self.__stw__(addr,f2w(data))
65 def __std__( self,addr,data): self.__stx__(addr,d2x(data))
66 def __sthl__(self,addr,data): self.__sth__(addr,h2h(data))
67 def __stwl__(self,addr,data): self.__stw__(addr,w2w(data))
68 def __stxl__(self,addr,data): self.__stx__(addr,x2x(long(data)))
69 def __stfl__(self,addr,data): self.__stwl__(addr,f2w(data))
70 def __stdl__(self,addr,data): self.__stxl__(addr,d2x(data))
71
72
73#----------------------------------------------------------------------------
74# MemoryInterface implements the actual index operator for
75# the various memory sizes, expliting pythons slicing operator
76#----------------------------------------------------------------------------
77
78class MemoryInterface:
79 def __init__(self,mem,load,store,size):
80 self.__mem__ = mem
81 self.__ld__ = load
82 self.__st__ = store
83 self.__size__ = size
84
85 def slice_step(self,__slice__,step):
86 if __slice__.step == None:
87 return step
88 else:
89 return __slice__.step
90
91 def __len__(self):
92 return long(1 << 55)
93
94 def __getitem__(self,address):
95 if type(address) == slice:
96 m = []
97 a = address.start
98 s = self.slice_step(address,self.__size__)
99 while a < address.stop:
100 m.append(self.__ld__(a))
101 a += s
102 return m
103 else:
104 return self.__ld__(address)
105
106 def __setitem__(self,address,value):
107 if type(address) == slice:
108 a = address.start
109 s = self.slice_step(address,self.__size__)
110 i = 0
111 while a < address.stop and i < len(value):
112 self.__st__(a,value[i])
113 self.__mem__.__flush__(address)
114 a += s
115 i += 1
116 else:
117 self.__st__(address,value)
118 self.__mem__.__flush__(address)
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134