# ========== Copyright Header Begin ==========================================
# OpenSPARC T2 Processor File: Command.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 ============================================
use TRELoad
'BitFieldTie';
our @EXPORT = qw(run_command chat fatal banner string2bf hexstring2bf
#our %opt = ( verbose => 1 );
##############################################################################
return $$Verbose if ref $Verbose;
##############################################################################
##############################################################################
my $obj = Midas
::Error
->throw($msg, $code);
##############################################################################
$level = 1 unless defined $level;
return unless verbose
>= $level;
my @lines = split /\n/, "$msgs";
my $string = "$Prg: " . (join "\n$Prg: $_", @lines);
##############################################################################
chat
"###########################################################\n", 2;
foreach my $line (@lines) {
print "$Prg: ## $line\n" if verbose
> 0;
chat
"###########################################################\n", 2;
##############################################################################
foreach my $key (keys %args) {
fatal
"Midas::Command does not recongnize configuration option ".
return ( verbose
=> $Verbose,
##############################################################################
my @options = qw( verbose=i fatal! errcode=i pass_errcode! );
Getopt
::Long
::Configure
('no_pass_through');
GetOptions
(\
%cmd_opt, @options) or
fatal
"Cannot parse flags to run_command: @flags\n";
if(verbose
>= $cmd_opt{verbose
}) {
print "$Prg: $command\n";
$status = system($command) unless opt_n
;
if($cmd_opt{fatal
} and $status) {
my $core = $status & 128;
my $core_msg = $core ?
"Dumped core." : "";
fatal
"Command \"$command\" died via signal $sig. $core_msg\n",
if($cmd_opt{pass_errcode
} and exists $ERRCODES{$exit}) {
fatal
"Command \"$command\" failed. $core_msg\n", $exit;
fatal
"Command \"$command\" failed with status $exit. $core_msg\n",
##############################################################################
fatal
"Cannot run string2bf without a width argument!\n", M_CODE
if($string =~ /^\s*0[xX]/ or ref($string) or $CONFIG{default_radix
} eq 'hex')
(my $mystring = $string) =~ s/^\s*0[xX]//;
my $max_digits = int($width / 4);
$max_digits++ if (($max_digits) * 4 != $width);
if(length $mystring > $max_digits) {
my $difference = (length $mystring) - $max_digits;
my $leader = substr($mystring, 0, $difference);
return "Hex overflow: \"$string\" won't fit in $width bits!\n"
unless $leader eq ('0' x
$difference);
my $max_bf = BitFieldTie
->new(65, "1");
$max_bf->left_shift($width);
$test_bf = BitFieldTie
->new_dec(65, $string);
if($test_bf->ucompare($max_bf) >= 0) {
return "Dec Overflow: \"$string\" won't fit in $width bits!\n";
$bf = BitFieldTie
->new($width, $string);
$bf = BitFieldTie
->new_dec($width, $string);
##############################################################################
$string = "0x$string" unless $string =~ /^\s*0[xX]/;
return string2bf
($string, $width);
##############################################################################