Commit | Line | Data |
---|---|---|
920dae64 AT |
1 | # ========== Copyright Header Begin ========================================== |
2 | # | |
3 | # OpenSPARC T2 Processor File: Pfe_Memory.py | |
4 | # Copyright (c) 2006 Sun Microsystems, Inc. All Rights Reserved. | |
5 | # DO NOT ALTER OR REMOVE COPYRIGHT NOTICES. | |
6 | # | |
7 | # The above named program is free software; you can redistribute it and/or | |
8 | # modify it under the terms of the GNU General Public | |
9 | # License version 2 as published by the Free Software Foundation. | |
10 | # | |
11 | # The above named program is distributed in the hope that it will be | |
12 | # useful, but WITHOUT ANY WARRANTY; without even the implied warranty of | |
13 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
14 | # General Public License for more details. | |
15 | # | |
16 | # You should have received a copy of the GNU General Public | |
17 | # License along with this work; if not, write to the Free Software | |
18 | # Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA. | |
19 | # | |
20 | # ========== Copyright Header End ============================================ | |
21 | ||
22 | from Pfe_Conversion import * | |
23 | ||
24 | #---------------------------------------------------------------------------- | |
25 | # Memory is the wrapper that provides the hooks to all the ways to access | |
26 | # memory: 1,2,4,8 bytes, int or double, or little endian ... | |
27 | #---------------------------------------------------------------------------- | |
28 | ||
29 | class Memory: | |
30 | """ | |
31 | Memory memory | |
32 | """ | |
33 | def __init__(self): | |
34 | self.b = MemoryInterface(self,self.__ldb__, self.__stb__,1) | |
35 | self.h = MemoryInterface(self,self.__ldh__, self.__sth__,2) | |
36 | self.w = MemoryInterface(self,self.__ldw__, self.__stw__,4) | |
37 | self.x = MemoryInterface(self,self.__ldx__ , self.__stx__,8) | |
38 | self.f = MemoryInterface(self,self.__ldf__, self.__stf__,4) | |
39 | self.d = MemoryInterface(self,self.__ldd__, self.__std__,8) | |
40 | self.c = MemoryInterface(self,self.__ldc__, self.__stc__,1) | |
41 | self.cl = self.c # ha, simply for completeness | |
42 | self.bl = self.b # ha, simply for completeness | |
43 | self.hl = MemoryInterface(self,self.__ldhl__, self.__sthl__,2) | |
44 | self.wl = MemoryInterface(self,self.__ldwl__, self.__stwl__,4) | |
45 | self.xl = MemoryInterface(self,self.__ldxl__, self.__stxl__,8) | |
46 | self.fl = MemoryInterface(self,self.__ldfl__, self.__stfl__,4) | |
47 | self.dl = MemoryInterface(self,self.__lddl__, self.__stdl__,8) | |
48 | ||
49 | def load(self,filename,addr=None): pass | |
50 | def save(self,filename,addr,size): pass | |
51 | ||
52 | # __flush__() needs to be provided for processor implementations that | |
53 | # implement decode caches or i caches. The flush() is called on | |
54 | # every store. | |
55 | ||
56 | def __flush__(self,addr): pass | |
57 | ||
58 | # __ldb__(), __ldh__(), __ldw__(), and __ldx__() implement 1, 2, 4 and | |
59 | # 8 byte load operations. They need to be provided by the implementation. | |
60 | ||
61 | def __ldb__(self,addr): pass | |
62 | def __ldh__(self,addr): pass | |
63 | def __ldw__(self,addr): pass | |
64 | def __ldx__(self,addr): pass | |
65 | ||
66 | # __stb__(), __sth__(), __stw__(), and __stx__() implement 1, 2, 4 and | |
67 | # 8 byte store operations. They need to be provided by the implementation. | |
68 | ||
69 | def __stb__(self,addr,data): pass | |
70 | def __sth__(self,addr,data): pass | |
71 | def __stw__(self,addr,data): pass | |
72 | def __stx__(self,addr,data): pass | |
73 | ||
74 | def __ldc__( self,addr): return chr(self.__ldb__(addr)) | |
75 | def __ldf__( self,addr): return w2f(self.__ldw__(addr)) | |
76 | def __ldd__( self,addr): return x2d(long(self.__ldx__(addr))) | |
77 | def __ldhl__(self,addr): return h2h(self.__ldh__(addr)) | |
78 | def __ldwl__(self,addr): return w2w(self.__ldw__(addr)) | |
79 | def __ldxl__(self,addr): return x2x(long(self.__ldx__(addr))) | |
80 | def __ldfl__(self,addr): return w2f(self.__ldwl__(addr)) | |
81 | def __lddl__(self,addr): return x2d(self.__ldxl__(addr)) | |
82 | ||
83 | def __stc__( self,addr,data): self.__stb__(addr,ord(data)) | |
84 | def __stf__( self,addr,data): self.__stw__(addr,f2w(data)) | |
85 | def __std__( self,addr,data): self.__stx__(addr,d2x(data)) | |
86 | def __sthl__(self,addr,data): self.__sth__(addr,h2h(data)) | |
87 | def __stwl__(self,addr,data): self.__stw__(addr,w2w(data)) | |
88 | def __stxl__(self,addr,data): self.__stx__(addr,x2x(long(data))) | |
89 | def __stfl__(self,addr,data): self.__stwl__(addr,f2w(data)) | |
90 | def __stdl__(self,addr,data): self.__stxl__(addr,d2x(data)) | |
91 | ||
92 | ||
93 | #---------------------------------------------------------------------------- | |
94 | # MemoryInterface implements the actual index operator for | |
95 | # the various memory sizes, expliting pythons slicing operator | |
96 | #---------------------------------------------------------------------------- | |
97 | ||
98 | class MemoryInterface: | |
99 | def __init__(self,mem,load,store,size): | |
100 | self.__mem__ = mem | |
101 | self.__ld__ = load | |
102 | self.__st__ = store | |
103 | self.__size__ = size | |
104 | ||
105 | def slice_step(self,__slice__,step): | |
106 | if __slice__.step == None: | |
107 | return step | |
108 | else: | |
109 | return __slice__.step | |
110 | ||
111 | def __len__(self): | |
112 | return long(1 << 55) | |
113 | ||
114 | def __getitem__(self,address): | |
115 | if type(address) == slice: | |
116 | m = [] | |
117 | a = address.start | |
118 | s = self.slice_step(address,self.__size__) | |
119 | while a < address.stop: | |
120 | m.append(self.__ld__(a)) | |
121 | a += s | |
122 | return m | |
123 | else: | |
124 | return self.__ld__(address) | |
125 | ||
126 | def __setitem__(self,address,value): | |
127 | if type(address) == slice: | |
128 | a = address.start | |
129 | s = self.slice_step(address,self.__size__) | |
130 | i = 0 | |
131 | while a < address.stop and i < len(value): | |
132 | self.__st__(a,value[i]) | |
133 | self.__mem__.__flush__(address) | |
134 | a += s | |
135 | i += 1 | |
136 | else: | |
137 | self.__st__(address,value) | |
138 | self.__mem__.__flush__(address) | |
139 | ||
140 | ||
141 | ||
142 | ||
143 | ||
144 | ||
145 | ||
146 | ||
147 | ||
148 | ||
149 | ||
150 | ||
151 | ||
152 | ||
153 | ||
154 |