Initial commit of OpenSPARC T2 design and verification files.
[OpenSPARC-T2-DV] / tools / perlmod / Midas / 3.32 / lib / site_perl / 5.8.0 / Midas / MMU.pm
CommitLineData
86530b38
AT
1# ========== Copyright Header Begin ==========================================
2#
3# OpenSPARC T2 Processor File: MMU.pm
4# Copyright (C) 1995-2007 Sun Microsystems, Inc. All Rights Reserved
5# 4150 Network Circle, Santa Clara, California 95054, U.S.A.
6#
7# * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
8#
9# This program is free software; you can redistribute it and/or modify
10# it under the terms of the GNU General Public License as published by
11# the Free Software Foundation; version 2 of the License.
12#
13# This program is distributed in the hope that it will be useful,
14# but WITHOUT ANY WARRANTY; without even the implied warranty of
15# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16# GNU General Public License for more details.
17#
18# You should have received a copy of the GNU General Public License
19# along with this program; if not, write to the Free Software
20# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
21#
22# For the avoidance of doubt, and except that if any non-GPL license
23# choice is available it will apply instead, Sun elects to use only
24# the General Public License version 2 (GPLv2) at this time for any
25# software where a choice of GPL license versions is made
26# available with the language indicating that GPLv2 or any later version
27# may be used, or where a choice of which version of the GPL is applied is
28# otherwise unspecified.
29#
30# Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
31# CA 95054 USA or visit www.sun.com if you need additional information or
32# have any questions.
33#
34# ========== Copyright Header End ============================================
35# -*- perl -*-
36
37package Midas::MMU;
38use strict;
39
40use Midas::Command;
41use Midas::Configure;
42use Midas::Error;
43use Midas::Globals;
44use Midas::Segment;
45
46use Midas::AttrBlock;
47use Midas::MMU::TTEFormat;
48
49# Needs to be a require so it happens AFTER 'use fields'.
50# This is because of a circularity in the inclusions
51require Midas::MMU::Ultra2;
52require Midas::MMU::Niagara;
53require Midas::MMU::Niagara2;
54
55
56require Midas::TSB;
57
58require Exporter;
59
60our @ISA = qw(Exporter);
61our @EXPORT = qw(create_mmu);
62
63use fields qw(type vasize pasize mapattr_type tsb_type tsblink_type);
64
65
66##############################################################################
67
68sub create_mmu {
69 my $type = shift;
70 my %args = @_;
71
72 $type = lc $type;
73 my $mmu;
74 if($type eq 'niagara') {
75 $mmu = Midas::MMU::Niagara->new(%args);
76 } elsif($type eq 'niagara2') {
77 $mmu = Midas::MMU::Niagara2->new(%args);
78 } elsif($type eq 'ultra2' or $type eq 'ultrasparc2') {
79 $mmu = Midas::MMU::Ultra2->new(%args);
80 } else {
81 fatal "No such mmu type \"$type\"\n", M_BADCONFIG;
82 }
83
84
85 $VASIZE = $mmu->{vasize};
86 $RASIZE = exists $mmu->{rasize} ? $mmu->{rasize} : $mmu->{pasize};
87 $PASIZE = $mmu->{pasize};
88
89 $mmu->init_mmu();
90
91
92 return $mmu;
93}
94
95##############################################################################
96
97sub new {
98 my $this = shift;
99 my %args = @_;
100
101 unless (ref $this) {
102 $this = fields::new($this);
103 }
104
105
106 foreach my $key (keys %args) {
107 $this->{$key} = $args{$key};
108 }
109
110 $this->{mapattr_type} = 'Midas::MMU::SunSectionAttrs';
111 $this->{tsb_type} = 'Midas::TSB';
112 $this->{tsblink_type} = 'Midas::TSBLink';
113
114 return $this;
115}
116
117##############################################################################
118
119sub init_mmu {
120 my $this = shift;
121
122 %MapAttr_Settable = map { $_ => 1 } $this->{mapattr_type}->settable();
123 my $fieldhash = get_union_tte_field_hash( $this->{type} );
124 foreach my $key (keys %$fieldhash) {
125 $MapAttr_Settable{$key} = 1;
126 }
127
128 my $fhash_ref = $this->{mapattr_type}->get_field_size_hash();
129 foreach my $key (keys %$fieldhash) {
130 $fhash_ref->{$key} = $fieldhash->{$key};
131 }
132 foreach my $field (keys %$fhash_ref) {
133 my $width = $fhash_ref->{$field};
134 my $range_bf = BitFieldTie->new(64, 1);
135 $range_bf->left_shift($width);
136 $MapAttr_FieldMax{$field} = $range_bf;
137 $MapAttr_FieldWidth{$field} = $width;
138 }
139}
140
141##############################################################################
142
143sub set_defaults {
144 my $this = shift;
145
146 $this->{vasize} = 64 unless defined $this->{vasize};
147 $this->{pasize} = 64 unless defined $this->{pasize};
148 $this->{type} = 'generic' unless defined $this->{type};
149
150}
151
152##############################################################################
153
154sub create_attrs_object {
155 my $this = shift;
156 my $type = shift;
157
158 return Midas::AttrBlock::LinkAttrs->new()
159 if((lc $type) eq 'link');
160
161 return $this->{mapattr_type}->new(segment => Midas::Segment->new($type),
162 mmutype => $this->{type},
163 )
164 if Midas::Segment->is_segment_name($type);
165
166 fatal "Can't create_attrs_object of type $type with abstract superclass ".
167 "Midas::MMU\n", M_CODE;
168}
169
170##############################################################################
171
172sub create_tsb_object {
173 my $this = shift;
174 my @args = @_;
175
176 return $this->{tsb_type}->new(@args);
177}
178
179##############################################################################
180
181sub create_tsb_object_from_line {
182 my $this = shift;
183 my $startline = shift;
184 my $fh = shift;
185 my $srcfile = shift;
186 my $srcline = shift;
187
188 $this->{tsb_type}->new_from_line($startline, $fh, $srcfile, $srcline, $this);
189}
190
191##############################################################################
192
193sub create_tsb_link_object {
194 my $this = shift;
195 my @args = @_;
196
197 return $this->{tsblink_type}->new(@args);
198}
199
200##############################################################################
201
202sub create_tsb_link_object_from_line {
203 my $this = shift;
204 my $startline = shift;
205 my $fh = shift;
206 my $srcfile = shift;
207 my $srcline = shift;
208
209 $this->{tsblink_type}->new_from_line($startline, $fh, $srcfile, $srcline,
210 $this);
211}
212
213##############################################################################
214
215sub mmu_cpp_args {
216 my $this = shift;
217 return;
218}
219
220##############################################################################
221
222sub parse_section_attrs {
223 my $this = shift;
224 my $startline = shift;
225 my $fh = shift;
226 my $srcline = shift;
227 my $srcfile = shift;
228
229 local ($_);
230 $_ = $startline;
231
232 my $attrs;
233
234 my $segstring = join '|', map { "($_)" } Midas::Segment->all_names();
235
236
237 if(/^\s*attr_($segstring|(link))\s*\{/) {
238 my $attr_type = $1;
239
240 $attrs = $this->create_attrs_object($attr_type);
241 $attrs->set_defaults();
242
243 $attrs->{type} = $1;
244 $attrs->{srcfile} = $srcfile;
245 $attrs->{srcline} = $srcline;
246
247 while(<$fh>) {
248 $srcline++;
249 last if /^\s*\}\s*$/;
250 my @attrs = split /,/, $_;
251 foreach my $attr (@attrs) {
252 $attr =~ s/\s+//g;
253
254 if($attr =~ /(\S+)=(\S+)/) {
255 if($attrs->is_settable($1)) {
256 $attrs->set_attr($1, $2);
257 } else {
258 $attrs->attr_fatal("No such attribute '$1'", M_ILLEGALPARAM);
259 }
260 } elsif($attr =~ /(\S+)/) {
261 if($attrs->is_settable($1)) {
262 $attrs->set_attr($1, 1);
263 } else {
264 $attrs->attr_fatal("No such attribute '$1'", M_ILLEGALPARAM);
265 }
266 }
267 }
268 }
269 } else {
270 fatal "Error parsing section attributes: file=$srcfile line=$srcline:\n$_",
271 M_ATTRSYNTAX;
272 }
273
274 $attrs->set_end_file_line($srcfile, $srcline);
275
276 return $attrs;
277}
278
279##############################################################################
2801;