| 1 | # ========== Copyright Header Begin ========================================== |
| 2 | # |
| 3 | # OpenSPARC T2 Processor File: State.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 | |
| 37 | package Midas::State; |
| 38 | use strict; |
| 39 | |
| 40 | use File::Spec; |
| 41 | use Cwd; |
| 42 | |
| 43 | use Midas::MMU; |
| 44 | use Midas::Configure; |
| 45 | use Midas::Command; |
| 46 | use Midas::Paths; |
| 47 | use Midas::Globals; |
| 48 | use Midas::Error; |
| 49 | |
| 50 | require Exporter; |
| 51 | our @ISA = qw(Exporter); |
| 52 | our @EXPORT = qw(init_state); |
| 53 | our @EXPORT_OK = qw(); |
| 54 | |
| 55 | use fields qw( |
| 56 | start_dir |
| 57 | build_dir |
| 58 | dest_dir |
| 59 | |
| 60 | diag_root |
| 61 | |
| 62 | created_build_dir |
| 63 | skipping_build |
| 64 | |
| 65 | mmu |
| 66 | tsbs |
| 67 | tsblinks |
| 68 | |
| 69 | apps |
| 70 | ); |
| 71 | |
| 72 | ############################################################################## |
| 73 | |
| 74 | sub init_state { |
| 75 | my $diag_root = shift; |
| 76 | my $start_dir = shift; |
| 77 | my $dest_dir = shift; |
| 78 | |
| 79 | $diag_root = $ENV{DV_ROOT} unless defined $diag_root; |
| 80 | $start_dir = getcwd unless defined $start_dir; |
| 81 | $dest_dir = getcwd unless defined $start_dir; |
| 82 | |
| 83 | $diag_root = File::Spec->rel2abs($diag_root, getcwd); |
| 84 | $start_dir = File::Spec->rel2abs($start_dir, getcwd); |
| 85 | $dest_dir = File::Spec->rel2abs($dest_dir, getcwd); |
| 86 | |
| 87 | my $state = Midas::State->new(start_dir => $start_dir, |
| 88 | dest_dir => $dest_dir, |
| 89 | diag_root => $diag_root, |
| 90 | ); |
| 91 | |
| 92 | |
| 93 | $state->set_build_dir($state->get_build_dir()); |
| 94 | |
| 95 | $ENV{DIAG_ROOT} = $diag_root; |
| 96 | $ENV{START_DIR} = $start_dir; |
| 97 | $ENV{DEST_DIR} = $dest_dir; |
| 98 | |
| 99 | return $state; |
| 100 | } |
| 101 | |
| 102 | ############################################################################## |
| 103 | |
| 104 | sub new { |
| 105 | my $this = shift; |
| 106 | my %args = @_; |
| 107 | |
| 108 | unless (ref $this) { |
| 109 | $this = fields::new($this); |
| 110 | } |
| 111 | |
| 112 | $this->set_defaults(); |
| 113 | |
| 114 | foreach my $key (keys %args) { |
| 115 | $this->{$key} = $args{$key}; |
| 116 | } |
| 117 | return $this; |
| 118 | } |
| 119 | |
| 120 | ############################################################################## |
| 121 | |
| 122 | sub set_defaults { |
| 123 | my $this = shift; |
| 124 | |
| 125 | $this->{start_dir} = '.'; |
| 126 | $this->{build_dir} = undef; |
| 127 | $this->{dest_dir} = '.'; |
| 128 | $this->{diag_root} = $ENV{DV_ROOT}; |
| 129 | $this->{created_build_dir} = 0; |
| 130 | $this->{skipping_build} = 0; |
| 131 | $this->{mmu} = undef; |
| 132 | $this->{apps} = {}; |
| 133 | $this->{tsbs} = {}; |
| 134 | $this->{tsblinks} = {}; |
| 135 | } |
| 136 | |
| 137 | ############################################################################## |
| 138 | |
| 139 | sub get_build_dir { |
| 140 | my $this = shift; |
| 141 | my @args = @_; |
| 142 | |
| 143 | my $build = $this->{build_dir}; |
| 144 | if(not defined $build) { |
| 145 | $build = $CONFIG{build_dir}; |
| 146 | } |
| 147 | my $build_abs = File::Spec->rel2abs($build, $this->{start_dir}); |
| 148 | |
| 149 | if(grep /^\-abs$/, @args) { |
| 150 | return $build_abs; |
| 151 | } |
| 152 | |
| 153 | return compact_path($build_abs); |
| 154 | } |
| 155 | |
| 156 | ############################################################################## |
| 157 | |
| 158 | sub set_build_dir { |
| 159 | my $this = shift; |
| 160 | my $build_dir = shift; |
| 161 | |
| 162 | my $build = File::Spec->rel2abs($build_dir, $this->{start_dir}); |
| 163 | $this->{build_dir} = $build; |
| 164 | return $this->{build_dir}; |
| 165 | } |
| 166 | |
| 167 | ############################################################################## |
| 168 | |
| 169 | sub get_start_dir { |
| 170 | my $this = shift; |
| 171 | my @args = @_; |
| 172 | |
| 173 | my $start_dir = $this->{start_dir}; |
| 174 | |
| 175 | if(grep /^\-abs$/, @args) { |
| 176 | return $start_dir; |
| 177 | } |
| 178 | |
| 179 | return compact_path $start_dir; |
| 180 | } |
| 181 | |
| 182 | ############################################################################## |
| 183 | |
| 184 | sub get_dest_dir { |
| 185 | my $this = shift; |
| 186 | my @args = @_; |
| 187 | |
| 188 | my $dest_dir = $this->{dest_dir}; |
| 189 | |
| 190 | if(grep /^\-abs$/, @args) { |
| 191 | return $dest_dir; |
| 192 | } |
| 193 | |
| 194 | return compact_path $dest_dir; |
| 195 | } |
| 196 | |
| 197 | ############################################################################## |
| 198 | |
| 199 | sub set_dest_dir { |
| 200 | my $this = shift; |
| 201 | my $dest_dir = shift; |
| 202 | |
| 203 | $this->{dest_dir} = File::Spec->rel2abs($dest_dir); |
| 204 | } |
| 205 | |
| 206 | ############################################################################## |
| 207 | |
| 208 | sub get_created_build_dir { |
| 209 | my $this = shift; |
| 210 | |
| 211 | return $this->{created_build_dir}; |
| 212 | } |
| 213 | |
| 214 | ############################################################################## |
| 215 | |
| 216 | sub set_created_build_dir { |
| 217 | my $this = shift; |
| 218 | my $val = shift; |
| 219 | |
| 220 | $val = 1 unless defined $val; |
| 221 | $this->{created_build_dir} = $val; |
| 222 | return $this->{created_build_dir}; |
| 223 | } |
| 224 | |
| 225 | ############################################################################## |
| 226 | |
| 227 | sub get_diag_root { |
| 228 | my $this = shift; |
| 229 | |
| 230 | return $this->{diag_root}; |
| 231 | } |
| 232 | |
| 233 | ############################################################################## |
| 234 | |
| 235 | sub get_mmu { |
| 236 | my $this = shift; |
| 237 | my $type = shift; |
| 238 | |
| 239 | fatal "Tried to get mmu of specified type $type when an mmu already ". |
| 240 | "exists!\n", M_CODE if defined $type && defined $this->{mmu}; |
| 241 | |
| 242 | return $this->{mmu} if defined $this->{mmu}; |
| 243 | |
| 244 | my $mmu = create_mmu( defined $type ? $type : $CONFIG{mmu_type} ); |
| 245 | $this->{mmu} = $mmu; |
| 246 | return $this->{mmu}; |
| 247 | } |
| 248 | |
| 249 | ############################################################################## |
| 250 | |
| 251 | sub clear { |
| 252 | my $this = shift; |
| 253 | $this->set_defaults(); |
| 254 | } |
| 255 | |
| 256 | ############################################################################## |
| 257 | |
| 258 | sub skipping_build { |
| 259 | my $this = shift; |
| 260 | my $bool = shift; |
| 261 | $this->{skipping_build} = $bool if defined $bool; |
| 262 | return $this->{skipping_build}; |
| 263 | } |
| 264 | |
| 265 | ############################################################################## |
| 266 | |
| 267 | sub get_tsb { |
| 268 | my $this = shift; |
| 269 | my $name = shift; |
| 270 | |
| 271 | return $this->{tsbs}{$name} if exists $this->{tsbs}{$name}; |
| 272 | return; |
| 273 | } |
| 274 | |
| 275 | ############################################################################## |
| 276 | |
| 277 | sub get_tsblink { |
| 278 | my $this = shift; |
| 279 | my $name = shift; |
| 280 | |
| 281 | return $this->{tsblinks}{$name} if exists $this->{tsblinks}{$name}; |
| 282 | return; |
| 283 | } |
| 284 | |
| 285 | ############################################################################## |
| 286 | 1; |