Initial commit of OpenSPARC T2 architecture model.
[OpenSPARC-T2-SAM] / sam-t2 / sam / cpus / vonk / bl / api / pfe / src / Pfe_SymbolTbl.py
CommitLineData
920dae64
AT
1# ========== Copyright Header Begin ==========================================
2#
3# OpenSPARC T2 Processor File: Pfe_SymbolTbl.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
22class Pfe_SymbolTbl:
23 def __init__ (self):
24 self.id_pa = {}
25 self.id_ra = {}
26 self.id_va = {}
27 self.pa_id = []
28 self.ra_id = []
29 self.va_id = []
30
31
32 def load(self,filename):
33 file = open(filename)
34
35 for line in file:
36 id,va,ra,pa = line.split()
37
38 if not (ra in 'Xx'):
39 ra = eval('0x'+ra)
40 self.id_ra[id] = ra
41 self.ra_id.append((ra,id))
42
43 va = eval('0x'+va)
44 self.id_va[id] = va
45 self.va_id.append((va,id))
46
47 pa = eval('0x'+pa)
48 self.id_pa[id] = pa
49 self.pa_id.append((pa,id))
50
51 file.close()
52
53 self.pa_id.sort()
54 self.ra_id.sort()
55 self.va_id.sort()
56
57
58 def id2pa(self,id):
59 if self.id_pa.has_key(id):
60 return self.id_pa[id]
61 else:
62 return None
63
64 def id2ra(self,id):
65 if self.id_ra.has_key(id):
66 return self.id_ra[id]
67 else:
68 return None
69
70 def id2va(self,id):
71 if self.id_va.has_key(id):
72 return self.id_va[id]
73 else:
74 return None
75
76
77 def pa2id(self,pa):
78 ea_id = self.__find__(self.pa_id,pa)
79 if ea_id:
80 return ea_id[1]
81 return None
82
83 def ra2id(self,ra):
84 ea_id = self.__find__(self.ra_id,ra)
85 if ea_id:
86 return ea_id[1]
87 return None
88
89 def va2id(self,va):
90 ea_id = self.__find__(self.va_id,va)
91 if ea_id:
92 return ea_id[1]
93 return None
94
95
96 def pa2id_ofs(self,pa):
97 ea_id = self.__find__(self.pa_id,pa)
98 if ea_id:
99 ea,id = ea_id
100 return (id,pa - ea)
101 return None
102
103 def ra2id_ofs(self,ra):
104 ea_id = self.__find__(self.ra_id,ra)
105 if ea_id:
106 ea,id = ea_id
107 return (id,ra - ea)
108 return None
109
110 def va2id_ofs(self,va):
111 ea_id = self.__find__(self.va_id,va)
112 if ea_id:
113 ea,id = ea_id
114 return (id,va - ea)
115 return None
116
117 def __find__(self,list,ea):
118 l = 0
119 u = len(list)
120 m = u >> 1
121 while l != m:
122 if ea < list[m][0]:
123 u = m
124 else:
125 l = m
126 m = l + ((u - l) >> 1)
127 return list[m]
128
129
130