// ========== Copyright Header Begin ==========================================
// OpenSPARC T2 Processor File: RegisterArray.cc
// Copyright (c) 2006 Sun Microsystems, Inc. All Rights Reserved.
// DO NOT ALTER OR REMOVE COPYRIGHT NOTICES.
// The above named program is free software; you can redistribute it and/or
// modify it under the terms of the GNU General Public
// License version 2 as published by the Free Software Foundation.
// The above named 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 work; if not, write to the Free Software
// Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA.
// ========== Copyright Header End ============================================
#include "RegisterArray.h"
RegisterArray::RegisterArray (string n
, Block
*b
, Addr a
, uint c
,
assert(w
== 1 || w
== 2 || w
== 4 || w
== 8);
assert(s
> 0 && (s
% w
) == 0);
fullName
= b
->getFullName() + "." + n
;
endAddr
= a
+ (c
- 1) * s
;
regType
= NULL
; // no RegisterType yet
regState
= new RegisterState
[count
]; // undefined value
regInfo
= new RegisterInfo
[count
]; // unassigned and dirty
mySignature
= NULL
; // allocated lazily
b
->addRegisterArray(this);
RegisterArray::~RegisterArray ()
for (uint i
=0; i
<count
; i
++)
void RegisterArray::printThis (ostream
&os
)
os
<< getFullName() << " (0x" << hex
<< startAddr
<< " to 0x" << endAddr
<< ", count " << dec
<< count
<< ", step 0x" << hex
<< step
<< ", width " << dec
<< regType
->widthBytes
<< " bytes)\n" << dec
;
for (uint index
=0; index
<count
; index
++) {
Register
*reg
= &(*this)[index
];
void RegisterArray::resetThis ()
regType
->check(getFullName());
if (regType
->resetValue
== 0)
memset(regState
, 0, sizeof(RegisterState
) * count
);
for (uint index
=0; index
<count
; index
++)
regState
[index
].value
= regType
->resetValue
;
if (regType
->resetAssigned
== 0)
memset(regInfo
, 0, sizeof(RegisterInfo
) * count
);
for (uint index
=0; index
<count
; index
++) {
regInfo
[index
].assigned
= (regType
->resetAssigned
!= 0);
regInfo
[index
].clean
= false;
void RegisterArray::signThis (ofstream
&ofs
)
regType
->check(getFullName());
if (mySignature
== NULL
) {
mySignature
= new Signature
*[count
];
for (uint i
=0; i
<count
; i
++) {
Signature::signScopeBegin(ofs
, getFullName());
for (uint index
=0; index
<count
; index
++) {
string s
= "[" + o
.str() + "]";
string n
= getBaseName() + s
;
string f
= getFullName() + s
;
mySignature
[index
] = new Signature
;
mySignature
[index
]->add(new SignData(f
, "", ®State
[index
].value
));
mySignature
[index
]->sign(ofs
, n
, "Register");
Signature::signScopeClose(ofs
, getFullName());
void RegisterArray::traceThis (ofstream
&ofs
)
for (uint index
=0; index
<count
; index
++) {
if (mySignature
&& mySignature
[index
] && !regInfo
[index
].clean
) {
mySignature
[index
]->printThis(ofs
);
regInfo
[index
].clean
= true;
bool RegisterArray::lookup (Addr a
, uint
*i
)
(a
- startAddr
) % step
== 0) {
uint64 index
= (a
- startAddr
) / step
;
Register
&RegisterArray::operator[] (uint index
)
bindRegisterToIndex(&valueR
, index
);
return valueR
; // return Register value by reference
void RegisterArray::reinitRegister (Register
*r
)
assert(r
->regType
!= NULL
);
regType
= r
->regType
; // set array regType to instance regType
delete r
->regInfo
; // clear out register pointers
r
->derived
= true; // do not delete dynamic state in ~Register
void RegisterArray::bindRegisterToIndex (Register
*r
, uint index
)
Signature
*signature
= NULL
;
signature
= mySignature
[index
];
r
->init(block
, startAddr
+ step
* index
, true, index
,
regType
, ®State
[index
], ®Info
[index
], signature
);