Commit | Line | Data |
---|---|---|
86530b38 AT |
1 | # -*- perl -*- |
2 | ||
3 | package Midas::MMU; | |
4 | use strict; | |
5 | ||
6 | use Midas::Command; | |
7 | use Midas::Configure; | |
8 | use Midas::Error; | |
9 | use Midas::Globals; | |
10 | use Midas::Segment; | |
11 | ||
12 | use Midas::AttrBlock; | |
13 | use Midas::MMU::TTEFormat; | |
14 | ||
15 | # Needs to be a require so it happens AFTER 'use fields'. | |
16 | # This is because of a circularity in the inclusions | |
17 | require Midas::MMU::Ultra2; | |
18 | require Midas::MMU::Niagara; | |
19 | require Midas::MMU::Niagara2; | |
20 | require Midas::MMU::Rock; | |
21 | ||
22 | require Midas::TSB; | |
23 | ||
24 | require Exporter; | |
25 | ||
26 | our @ISA = qw(Exporter); | |
27 | our @EXPORT = qw(create_mmu); | |
28 | ||
29 | use fields qw(type vasize pasize mapattr_type tsb_type tsblink_type); | |
30 | ||
31 | ||
32 | ############################################################################## | |
33 | ||
34 | sub create_mmu { | |
35 | my $type = shift; | |
36 | my %args = @_; | |
37 | ||
38 | $type = lc $type; | |
39 | my $mmu; | |
40 | if($type eq 'niagara') { | |
41 | $mmu = Midas::MMU::Niagara->new(%args); | |
42 | } elsif($type eq 'niagara2') { | |
43 | $mmu = Midas::MMU::Niagara2->new(%args); | |
44 | } elsif($type eq 'rock') { | |
45 | $mmu = Midas::MMU::Rock->new(%args); | |
46 | } elsif($type eq 'ultra2' or $type eq 'ultrasparc2') { | |
47 | $mmu = Midas::MMU::Ultra2->new(%args); | |
48 | } else { | |
49 | fatal "No such mmu type \"$type\"\n", M_BADCONFIG; | |
50 | } | |
51 | ||
52 | ||
53 | $VASIZE = $mmu->{vasize}; | |
54 | $RASIZE = exists $mmu->{rasize} ? $mmu->{rasize} : $mmu->{pasize}; | |
55 | $PASIZE = $mmu->{pasize}; | |
56 | ||
57 | $mmu->init_mmu(); | |
58 | ||
59 | ||
60 | return $mmu; | |
61 | } | |
62 | ||
63 | ############################################################################## | |
64 | ||
65 | sub new { | |
66 | my $this = shift; | |
67 | my %args = @_; | |
68 | ||
69 | unless (ref $this) { | |
70 | $this = fields::new($this); | |
71 | } | |
72 | ||
73 | ||
74 | foreach my $key (keys %args) { | |
75 | $this->{$key} = $args{$key}; | |
76 | } | |
77 | ||
78 | $this->{mapattr_type} = 'Midas::MMU::SunSectionAttrs'; | |
79 | $this->{tsb_type} = 'Midas::TSB'; | |
80 | $this->{tsblink_type} = 'Midas::TSBLink'; | |
81 | ||
82 | return $this; | |
83 | } | |
84 | ||
85 | ############################################################################## | |
86 | ||
87 | sub init_mmu { | |
88 | my $this = shift; | |
89 | ||
90 | %MapAttr_Settable = map { $_ => 1 } $this->{mapattr_type}->settable(); | |
91 | my $fieldhash = get_union_tte_field_hash( $this->{type} ); | |
92 | foreach my $key (keys %$fieldhash) { | |
93 | $MapAttr_Settable{$key} = 1; | |
94 | } | |
95 | ||
96 | my $fhash_ref = $this->{mapattr_type}->get_field_size_hash(); | |
97 | foreach my $key (keys %$fieldhash) { | |
98 | $fhash_ref->{$key} = $fieldhash->{$key}; | |
99 | } | |
100 | foreach my $field (keys %$fhash_ref) { | |
101 | my $width = $fhash_ref->{$field}; | |
102 | my $range_bf = BitFieldTie->new(64, 1); | |
103 | $range_bf->left_shift($width); | |
104 | $MapAttr_FieldMax{$field} = $range_bf; | |
105 | $MapAttr_FieldWidth{$field} = $width; | |
106 | } | |
107 | } | |
108 | ||
109 | ############################################################################## | |
110 | ||
111 | sub set_defaults { | |
112 | my $this = shift; | |
113 | ||
114 | $this->{vasize} = 64 unless defined $this->{vasize}; | |
115 | $this->{pasize} = 64 unless defined $this->{pasize}; | |
116 | $this->{type} = 'generic' unless defined $this->{type}; | |
117 | ||
118 | } | |
119 | ||
120 | ############################################################################## | |
121 | ||
122 | sub create_attrs_object { | |
123 | my $this = shift; | |
124 | my $type = shift; | |
125 | ||
126 | return Midas::AttrBlock::LinkAttrs->new() | |
127 | if((lc $type) eq 'link'); | |
128 | ||
129 | return $this->{mapattr_type}->new(segment => Midas::Segment->new($type), | |
130 | mmutype => $this->{type}, | |
131 | ) | |
132 | if Midas::Segment->is_segment_name($type); | |
133 | ||
134 | fatal "Can't create_attrs_object of type $type with abstract superclass ". | |
135 | "Midas::MMU\n", M_CODE; | |
136 | } | |
137 | ||
138 | ############################################################################## | |
139 | ||
140 | sub create_tsb_object { | |
141 | my $this = shift; | |
142 | my @args = @_; | |
143 | ||
144 | return $this->{tsb_type}->new(@args); | |
145 | } | |
146 | ||
147 | ############################################################################## | |
148 | ||
149 | sub create_tsb_object_from_line { | |
150 | my $this = shift; | |
151 | my $startline = shift; | |
152 | my $fh = shift; | |
153 | my $srcfile = shift; | |
154 | my $srcline = shift; | |
155 | ||
156 | $this->{tsb_type}->new_from_line($startline, $fh, $srcfile, $srcline, $this); | |
157 | } | |
158 | ||
159 | ############################################################################## | |
160 | ||
161 | sub create_tsb_link_object { | |
162 | my $this = shift; | |
163 | my @args = @_; | |
164 | ||
165 | return $this->{tsblink_type}->new(@args); | |
166 | } | |
167 | ||
168 | ############################################################################## | |
169 | ||
170 | sub create_tsb_link_object_from_line { | |
171 | my $this = shift; | |
172 | my $startline = shift; | |
173 | my $fh = shift; | |
174 | my $srcfile = shift; | |
175 | my $srcline = shift; | |
176 | ||
177 | $this->{tsblink_type}->new_from_line($startline, $fh, $srcfile, $srcline, | |
178 | $this); | |
179 | } | |
180 | ||
181 | ############################################################################## | |
182 | ||
183 | sub mmu_cpp_args { | |
184 | my $this = shift; | |
185 | return; | |
186 | } | |
187 | ||
188 | ############################################################################## | |
189 | ||
190 | sub parse_section_attrs { | |
191 | my $this = shift; | |
192 | my $startline = shift; | |
193 | my $fh = shift; | |
194 | my $srcline = shift; | |
195 | my $srcfile = shift; | |
196 | ||
197 | local ($_); | |
198 | $_ = $startline; | |
199 | ||
200 | my $attrs; | |
201 | ||
202 | my $segstring = join '|', map { "($_)" } Midas::Segment->all_names(); | |
203 | ||
204 | ||
205 | if(/^\s*attr_($segstring|(link))\s*\{/) { | |
206 | my $attr_type = $1; | |
207 | ||
208 | $attrs = $this->create_attrs_object($attr_type); | |
209 | $attrs->set_defaults(); | |
210 | ||
211 | $attrs->{type} = $1; | |
212 | $attrs->{srcfile} = $srcfile; | |
213 | $attrs->{srcline} = $srcline; | |
214 | ||
215 | while(<$fh>) { | |
216 | $srcline++; | |
217 | last if /^\s*\}\s*$/; | |
218 | my @attrs = split /,/, $_; | |
219 | foreach my $attr (@attrs) { | |
220 | $attr =~ s/\s+//g; | |
221 | ||
222 | if($attr =~ /(\S+)=(\S+)/) { | |
223 | if($attrs->is_settable($1)) { | |
224 | $attrs->set_attr($1, $2); | |
225 | } else { | |
226 | $attrs->attr_fatal("No such attribute '$1'", M_ILLEGALPARAM); | |
227 | } | |
228 | } elsif($attr =~ /(\S+)/) { | |
229 | if($attrs->is_settable($1)) { | |
230 | $attrs->set_attr($1, 1); | |
231 | } else { | |
232 | $attrs->attr_fatal("No such attribute '$1'", M_ILLEGALPARAM); | |
233 | } | |
234 | } | |
235 | } | |
236 | } | |
237 | } else { | |
238 | fatal "Error parsing section attributes: file=$srcfile line=$srcline:\n$_", | |
239 | M_ATTRSYNTAX; | |
240 | } | |
241 | ||
242 | $attrs->set_end_file_line($srcfile, $srcline); | |
243 | ||
244 | return $attrs; | |
245 | } | |
246 | ||
247 | ############################################################################## | |
248 | 1; |