Commit | Line | Data |
---|---|---|
920dae64 AT |
1 | # ========== Copyright Header Begin ========================================== |
2 | # | |
3 | # OpenSPARC T2 Processor File: Pfe_Tlb.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 | class GetAttrError(Exception): | |
23 | def __init__(self,name): | |
24 | Exception.__init__(self) | |
25 | self.name = name | |
26 | def __str__(self): | |
27 | return "The TLB has no getable field member '"+self.name+"'" | |
28 | ||
29 | class DelAttrError(Exception): | |
30 | def __init__(self,name): | |
31 | Exception.__init__(self) | |
32 | self.name = name | |
33 | def __str__(self): | |
34 | return "TLB attributes such as "+name+" can not be deleted" | |
35 | ||
36 | class SetAttrError(Exception): | |
37 | def __init__(self,name): | |
38 | Exception.__init__(self) | |
39 | self.name = name | |
40 | def __str__(self): | |
41 | return "The TLB has no setable field member '"+self.name+"'" | |
42 | ||
43 | ||
44 | def __geterror_fun__(name,strand): | |
45 | raise GetAttrError(name) | |
46 | def __seterror_fun__(name,strand,value): | |
47 | raise SetAttrError(name) | |
48 | ||
49 | def __geterror__(name): | |
50 | return lambda strand: __geterror_fun__(name,strand) | |
51 | def __seterror__(name): | |
52 | return lambda strand,value: __seterror_fun__(name,strand,value) | |
53 | ||
54 | ||
55 | class Tte: | |
56 | PAGE_SIZE = ['8K','64K','512K','4M','32M','256M','2G','16G'] | |
57 | ||
58 | def __init__(self,tte_ref=None,**args): | |
59 | if tte_ref == None: | |
60 | self.valid = False | |
61 | self.real = False | |
62 | self.pid = 0 | |
63 | self.ctx = 0 | |
64 | self.size = 0 | |
65 | self.tag = 0 | |
66 | self.ie = False | |
67 | self.nfo = False | |
68 | self.x = False | |
69 | self.p = False | |
70 | self.w = False | |
71 | self.e = False | |
72 | self.cv = False | |
73 | self.cp = False | |
74 | self.lock = False | |
75 | self.addr = 0 | |
76 | # some N2 specific TTE fields | |
77 | self.sw0 = 0 | |
78 | self.sw1 = 0 | |
79 | self.soft = 0 | |
80 | # N1 specific TTE fields | |
81 | self.diag7_3 = 0 | |
82 | self.szh = 0 | |
83 | self.szl = 0 | |
84 | self.l = 0 | |
85 | elif isinstance(tte_ref,TlbTte) or isinstance(tte_ref,Tte): | |
86 | self.valid = tte_ref.valid | |
87 | self.real = tte_ref.real | |
88 | self.ctx = tte_ref.ctx | |
89 | self.pid = tte_ref.pid | |
90 | self.tag = tte_ref.tag | |
91 | self.size = tte_ref.size | |
92 | self.ie = tte_ref.ie | |
93 | self.nfo = tte_ref.nfo | |
94 | self.x = tte_ref.x | |
95 | self.p = tte_ref.p | |
96 | self.w = tte_ref.w | |
97 | self.e = tte_ref.e | |
98 | self.cv = tte_ref.cv | |
99 | self.cp = tte_ref.cp | |
100 | self.lock = tte_ref.lock | |
101 | self.addr = tte_ref.addr | |
102 | # N2 specific TTE fields | |
103 | self.soft_flds = tte_ref.soft_flds | |
104 | # N1 specific TTE fields | |
105 | self.diag7_3 = tte_ref.diag7_3 | |
106 | for arg in args: | |
107 | if self.__dict__.has_key(arg): | |
108 | setattr(self,arg,args[arg]) | |
109 | else: | |
110 | raise AttributeError(arg) | |
111 | ||
112 | def __str__(self): | |
113 | """ | |
114 | return a string of the most common looked at fields of the TTE | |
115 | """ | |
116 | if not self.valid: | |
117 | return '-------' | |
118 | elif self.real: | |
119 | s = 'r' | |
120 | ctx = '' | |
121 | else: | |
122 | s = 'v' | |
123 | ctx = ' 0x%04x' % self.ctx | |
124 | ||
125 | s += self.p and 'p' or '-' | |
126 | s += self.x and 'x' or '-' | |
127 | s += self.w and 'w' or '-' | |
128 | s += self.e and 'e' or '-' | |
129 | s += self.nfo and 'n' or '-' | |
130 | s += self.ie and 'i' or '-' | |
131 | ||
132 | tag = self.tag | |
133 | if tag < 0: | |
134 | tag = 0x10000000000000000 + tag | |
135 | addr = self.addr | |
136 | if addr < 0: | |
137 | addr = 0x10000000000000000 + addr | |
138 | ||
139 | size = self.PAGE_SIZE[self.size] | |
140 | s += '%4s 0x%016x 0x%016x 0x%02x' % (size,tag,addr,self.pid) | |
141 | s += ctx | |
142 | ||
143 | return s | |
144 | ||
145 | ||
146 | class TlbTte: | |
147 | PAGE_SIZE = ['8K','64K','512K','4M','32M','256M','2G','16G'] | |
148 | ||
149 | __getfun__ = { 'xlate': __geterror__('xlate'), 'match': __geterror__('match') } | |
150 | __setfun__ = {} | |
151 | ||
152 | for field in ['valid','real','pid','ctx','size','tag','ie','nfo', | |
153 | 'x','p','w','e','cv','cp','lock','addr''soft_flds', | |
154 | 'diag7_3','data','tag']: | |
155 | __getfun__[field] = __geterror__(field) | |
156 | __setfun__[field] = __seterror__(field) | |
157 | ||
158 | def __init__(self,tlb,index_fun,index_arg): | |
159 | self.__dict__['__tlb__'] = tlb | |
160 | self.__dict__['__fun__'] = index_fun | |
161 | self.__dict__['__arg__'] = index_arg | |
162 | ||
163 | def __getattr__(self,name): | |
164 | if TlbTte.__getfun__.has_key(name): | |
165 | return TlbTte.__getfun__[name](self.__fun__(self.__arg__)) | |
166 | else: | |
167 | raise AttributeError | |
168 | ||
169 | def __setattr__(self,name,value): | |
170 | if TlbTte.__setfun__.has_key(name): | |
171 | tte = self.__fun__(self.__arg__) | |
172 | TlbTte.__setfun__[name](tte,value) | |
173 | if 'flush' in dir(self.__tlb__): | |
174 | self.__tlb__.flush(tte) | |
175 | else: | |
176 | raise AttributeError | |
177 | ||
178 | def __repr__(self): | |
179 | return '<TlbTte instance>' | |
180 | ||
181 | def __str__(self): | |
182 | """ | |
183 | return a string of the most common looked at fields of the TTE | |
184 | """ | |
185 | if not self.valid: | |
186 | return '-------' | |
187 | elif self.real: | |
188 | s = 'r' | |
189 | ctx = '' | |
190 | else: | |
191 | s = 'v' | |
192 | ctx = ' 0x%04x' % self.ctx | |
193 | ||
194 | s += self.p and 'p' or '-' | |
195 | s += self.x and 'x' or '-' | |
196 | s += self.w and 'w' or '-' | |
197 | s += self.e and 'e' or '-' | |
198 | s += self.nfo and 'n' or '-' | |
199 | s += self.ie and 'i' or '-' | |
200 | ||
201 | tag = self.tag | |
202 | if tag < 0: | |
203 | tag = 0x10000000000000000 + tag | |
204 | addr = self.addr | |
205 | if addr < 0: | |
206 | addr = 0x10000000000000000 + addr | |
207 | ||
208 | size = self.PAGE_SIZE[self.size] | |
209 | s += '%4s 0x%016x 0x%016x 0x%02x' % (size,tag,addr,self.pid) | |
210 | s += ctx | |
211 | ||
212 | return s | |
213 | ||
214 | ||
215 | class TlbIter: | |
216 | def __init__(self,tlb): | |
217 | self.tlb = tlb | |
218 | self.idx = 0 | |
219 | ||
220 | def __iter__(self): | |
221 | return self | |
222 | ||
223 | def next(self): | |
224 | index = self.tlb.next_valid_index(self.idx) | |
225 | if index >= 0: | |
226 | self.idx = index + 1 | |
227 | return index | |
228 | raise StopIteration | |
229 | ||
230 | ||
231 | class Tlb: | |
232 | def __init__(self,tlb): | |
233 | self.__dict__['__tlb__'] = tlb | |
234 | self.__dict__['tte'] = {} | |
235 | for i in range(0,self.size()): | |
236 | self.tte[i] = TlbTte(tlb,self.index,i) | |
237 | ||
238 | def __len__(self): | |
239 | n = 0 | |
240 | i = self.next_valid_index(0) | |
241 | while i >= 0: | |
242 | n += 1 | |
243 | i = self.next_valid_index(i+1) | |
244 | return n | |
245 | ||
246 | def __iter__(self): | |
247 | return TlbIter(self.__tlb__) | |
248 | ||
249 | def __repr__(self): | |
250 | l = {} | |
251 | i = self.__tlb__.next_valid_index(0) | |
252 | while i >= 0: | |
253 | l[i] = self.tte[i] | |
254 | i = self.__tlb__.next_valid_index(i+1) | |
255 | return str(l) | |
256 | ||
257 | def __str__(self): | |
258 | s = '' | |
259 | i = self.__tlb__.next_valid_index(0) | |
260 | while i >= 0: | |
261 | s += '0x%03x: %s\n' % (i,str(self.tte[i])) | |
262 | i = self.__tlb__.next_valid_index(i+1) | |
263 | return s | |
264 | ||
265 | def __getitem__(self,index): | |
266 | return self.tte[index] | |
267 | ||
268 | def __setitem__(self,index,tte): | |
269 | if isinstance(tte,Tte): | |
270 | lhs = self.tte[index] | |
271 | lhs.valid = tte.valid | |
272 | lhs.real = tte.real | |
273 | lhs.ctx = tte.ctx | |
274 | lhs.pid = tte.pid | |
275 | lhs.tag = tte.tag | |
276 | lhs.size = tte.size | |
277 | lhs.ie = tte.ie | |
278 | lhs.nfo = tte.nfo | |
279 | lhs.x = tte.x | |
280 | lhs.p = tte.p | |
281 | lhs.w = tte.w | |
282 | lhs.e = tte.e | |
283 | lhs.cv = tte.cv | |
284 | lhs.cp = tte.cp | |
285 | lhs.lock = tte.lock | |
286 | lhs.addr = tte.addr | |
287 | else: | |
288 | raise TypeError | |
289 | ||
290 | # size() returns the fixed size of the TLB in number of TTEs. | |
291 | ||
292 | def size(self): | |
293 | pass | |
294 | ||
295 | # index() returns the TTE currently at index i of the TLB. | |
296 | ||
297 | def index(self,i): | |
298 | pass | |
299 | ||
300 | # insert() inserts the TTE in the TLB. | |
301 | ||
302 | def insert(self,tte): | |
303 | pass | |
304 | ||
305 | # next_valid_index() returns the next valid TTE in the TLB | |
306 | # starting from i. If none are found the -1 is returned. | |
307 | ||
308 | def next_valid_index(self,i): | |
309 | if 0 <= i: | |
310 | while i < index.size(): | |
311 | if self.tte[i].valid: | |
312 | return i | |
313 | i += 1 | |
314 | return -1 | |
315 | ||
316 | # return reference to the tte that got inserted | |
317 | # tag_bits21_13 (0 .. 0x1ff) are the lower 9 bits of the tag | |
318 | # real is 1 when the tsb needs to be a ra2 pa tte, 0 otherwise | |
319 | def insert4v(self,pid,tag,data,tag_bits21_13,real): | |
320 | pass | |
321 | ||
322 | def insert4u(self,pid,tag,data,va,real): | |
323 | pass | |
324 | ||
325 | ||
326 | ||
327 | ||
328 |