# ========== Copyright Header Begin ==========================================
# OpenSPARC T2 Processor File: AttrBlock.pm
# Copyright (C) 1995-2007 Sun Microsystems, Inc. All Rights Reserved
# 4150 Network Circle, Santa Clara, California 95054, U.S.A.
# * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; version 2 of the License.
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
# For the avoidance of doubt, and except that if any non-GPL license
# choice is available it will apply instead, Sun elects to use only
# the General Public License version 2 (GPLv2) at this time for any
# software where a choice of GPL license versions is made
# available with the language indicating that GPLv2 or any later version
# may be used, or where a choice of which version of the GPL is applied is
# Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
# CA 95054 USA or visit www.sun.com if you need additional information or
# ========== Copyright Header End ============================================
package Midas
::AttrBlock
;
our @Settable = qw(name section);
our %Settable = map { $_ => 1 } Midas
::AttrBlock
->settable();
##############################################################################
$this = fields
::new
($this);
foreach my $key (keys %args) {
$this->{$key} = $args{$key};
$this->{settable
} = \
%Settable;
##############################################################################
##############################################################################
$this->{endfile
} = $endfile;
$this->{endline
} = $endline;
##############################################################################
return ($this->{endfile
}, $this->{endline
});
##############################################################################
my $that = $class->new();
##############################################################################
my @fields = keys %$this;
my @shallow_refs = qw(Midas::Section);
# Note this does a shallow copy of elements in arrays and values in hashes.
# May need to fix that if this gets more complicated
foreach my $field (@fields) {
if(not ref $src->{$field}) {
$this->{$field} = $src->{$field};
my $reftype = ref $src->{$field};
if($reftype eq 'ARRAY') {
$this->{$field} = [ @
{$src->{$field}} ];
} elsif($reftype eq 'HASH') {
$this->{$field} = { %{$src->{$field}} };
} elsif(grep /^$reftype$/, @shallow_refs) {
$this->{$field} = $src->{$field};
$this->{$field} = $src->{$field}->clone();
##############################################################################
##############################################################################
return 1 if exists $this->{settable
}{$attr};
##############################################################################
$this->attr_fatal("Attribute \"$attr\" is not a settable attribute.",
M_ILLEGALPARAM
) unless $this->is_settable($attr);
# make "section" a synonym for "name"
if ($attr eq 'section') {
if ($this->{has_set
}{$attr}) {
$this->attr_fatal("Attribute \"$attr\" is set multiple times.",
$this->{has_set
}{$attr} = 1;
##############################################################################
my $fline = $this->get_fline();
if(not defined $this->{name
}) {
my $message = '' unless defined $message;
$message .= "Block has no \"name\" or \"section\" tag.\n";
push @messages, { message
=> $message, code
=> M_ATTRSYNTAX
}
##############################################################################
##############################################################################
$this->{secobj
} = $obj if defined $obj;
##############################################################################
my $fline = "File=$this->{srcfile}, Line=$this->{srcline}";
##############################################################################
my $secname = $this->{name
};
my $fline = $this->get_fline();
fatal
"SECTION '$secname': $message\n At $fline\n", $errcode;
##############################################################################
$this->{srcfile
} = $srcfile;
$this->{srcline
} = $srcline;
# Make sure that name => or section => gets set first. That way, if any
# later attributes cause an error, at least the error message will
my @attr_names = keys %args;
@attr_names = ('name', keys %args);
if(exists $args{section
}) {
my $section = $args{section
};
@attr_names = ('section', keys %args);
$args{section
} = $section;
foreach my $attr (@attr_names) {
if ($this->is_settable($attr)) {
$this->set_attr($attr, $args{$attr});
$this->attr_fatal("No such attribute '$attr'.",M_ILLEGALPARAM
);
##############################################################################
###############################################################################
###############################################################################
package Midas
::AttrBlock
::LinkAttrs
;
use TRELoad
'BitFieldTie';
use base
'Midas::AttrBlock';
fields
->import(Midas
::Segment
->all_va_names());
our @Settable = Midas
::Segment
->all_va_names();
our %Settable = map { $_ => 1 } Midas
::AttrBlock
::LinkAttrs
->settable();
#############################################################################
$this = fields
::new
($this);
foreach my $key (keys %args) {
$this->{$key} = $args{$key};
$this->{settable
} = \
%Settable;
#############################################################################
my @settable = $this->SUPER::settable
();
push @settable, @Settable;
#############################################################################
return 1 if defined $this->{ Midas
::Segment
->name2va_name($segment) };
#############################################################################
$this->attr_fatal("No segment argument to has_segment.\n", M_CODE
)
my $vaname = Midas
::Segment
->name2va_name($segment);
return unless defined $this->{$vaname};
my $va = string2bf
($this->{$vaname}, $VASIZE);
$this->attr_fatal("Cannot interpret $uc \"$this->{$vaname}\":\n$va",
#############################################################################
my $va_bf = $this->get_segment_va_bf($segment);
return unless ref $va_bf;
#############################################################################
return grep { $this->has_segment($_) } Midas
::Segment
->all_names();
#############################################################################
my @messages = $this->SUPER::sanity_check
();
my $name = $this->get_section_name();
my $fline = $this->get_fline();
foreach my $segment ($this->defined_segments()) {
my $vaname = Midas
::Segment
->name2va_name($segment);
my $va = string2bf
($this->{$vaname}, $VASIZE);
my $message = "Section '$name' specified ${segment}_va isn't a ".
push @messages, { message
=> $message, code
=> M_NOTNUM
};
$seg_vas{$segment} = $va;
my $dword_offset = $va->extract(2, 0);
if ($dword_offset != 0) {
my $message = "Section '$name' ${segment}_va 0x$va is not 8-byte ".
"aligned.\n at $fline\n";
push @messages, { message
=> $message, code
=> M_BADALIGN
};
foreach my $segment (keys %seg_vas) {
my $vastring = $seg_vas{$segment};
if(exists $rev{$vastring}) {
my $oldseg = $rev{$vastring};
my $message = "Section '$name', ${oldseg}_va and ${segment}_va are ".
"the same\n at $fline\n";
push @messages, { message
=> $message, code
=> M_SECSYNTAX
};
$rev{$vastring} = $segment;
#############################################################################
###############################################################################
###############################################################################
package Midas
::AttrBlock
::MapAttrs
;
use base
'Midas::AttrBlock';
our %Settable = map { $_ => 1} Midas
::AttrBlock
::MapAttrs
->settable();
#############################################################################
$this = fields
::new
($this);
foreach my $key (keys %args) {
$this->{$key} = $args{$key};
$this->{settable
} = \
%Settable;
#############################################################################
$this->{segment
} = Midas
::Segment
->new(SEG_UNDEF
)
unless defined $this->{segment
};
$this->SUPER::set_defaults
;
$this->{mmutype
} = 'generic' unless defined $this->{mmutype
};
#############################################################################
my @settable = $this->SUPER::settable
();
push @settable, @Settable;
##############################################################################
return 1 if exists $MapAttr_Settable{$attr};
#############################################################################
sub get_field_size_hash
{
#############################################################################
if(exists $STATE->{tsbs
}{$attr}) {
push @
{$this->{tsbnames
}}, $attr;
$STATE->{tsbs
}{$attr}->touch();
return $this->SUPER::set_attr
($attr, $value);
#############################################################################
return [ @
{$this->{tsbnames
}} ];
#############################################################################
return 1 if $this->{segment
}->name() eq $segment;
#############################################################################
return $this->{segment
}->name();
############################################################################
############################################################################
#############################################################################
return 1 if $this->is_segment($segment);
#############################################################################
if(defined $this->{va
}) {
return BitFieldTie
->new($VASIZE, $this->{va
});
#############################################################################
my $bf = $this->get_va_bf();
return unless defined $bf;
############################################################################
############################################################################
my $bf = $this->get_pa_bf();
return unless defined $bf;
############################################################################
return $this->get_pa_bf();
############################################################################
my $bf = $this->get_ra_bf();
return unless defined $bf;
#############################################################################
$this->{unique_name
} = $name if defined $name;
return $this->{unique_name
};
#############################################################################
sub write_to_goldfinger
{
my $in_image = ((not $this->skip_image) and
$this->write_to_segment($segment)) ?
1 : 0;
if (not defined $this->{compressimage
}) {
$this->{compressimage
} = 0;
$this->{compressimage
} &&= $CONFIG{compress_image
};
my $type = $this->get_type();
my $name = $this->{name
};
my $va = $this->get_va();
my $ra = $this->get_ra();
my $pa = $this->get_pa();
my $unique_name = $this->unique_name();
$fh->print(" BLOCK $unique_name\n");
$fh->print(" SECTION_NAME = \"$name\";\n");
$fh->print(" SEGMENT_NAME = \"$type\";\n");
$fh->print(" LINK_SECTION = \"$linkname\";\n");
$fh->print(" SRC_FILE = \"$this->{srcfile}\";\n");
$fh->print(" SRC_LINE = $this->{srcline};\n");
$fh->print(" COMPRESS = $this->{compressimage};\n");
$fh->print(" VA = $va;\n") if defined $va;
$fh->print(" RA = $ra;\n") if defined $ra;
$fh->print(" PA = $pa;\n") if defined $pa;
$fh->print(" IN_IMAGE = $in_image;\n");
$fh->print(" END_VA = $this->{end_va};\n")
if defined $this->{end_va
};
$fh->print(" START_LABEL = \"$this->{start_label}\";\n")
if defined $this->{start_label
};
$fh->print(" END_LABEL = \"$this->{end_label}\";\n")
if defined $this->{end_label
};
$this->write_goldfinger_mmu_params($fh);
$fh->print(" END BLOCK\n");
#############################################################################
sub write_goldfinger_mmu_params
{
#############################################################################
###############################################################################
###############################################################################