* ========== Copyright Header Begin ==========================================
* OpenSPARC T2 Processor File: SS_CsrAccess.h
* 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 ============================================
/************************************************************************
** Copyright (C) 2006, Sun Microsystems, Inc.
** Sun considers its source code as an unpublished, proprietary
** trade secret and it is available only under strict license provisions.
** This copyright notice is placed here only to protect Sun in the event
** the source is deemed a published work. Disassembly, decompilation,
** or other means of reducing the object code to human readable form
** is prohibited by the license agreement under which this code is
** provided to the user or company in possession of this copy.
*************************************************************************/
#include "MemoryTransaction.h"
SS_CsrAccess(SS_Csr
& csr
) :
virtual ~SS_CsrAccess() {}
const SS_CsrAccess
<T
> & operator=( const SS_CsrAccess
<T
> &rhs
)
fprintf(stderr
, "ERROR: SS_CsrAccess<T> & operator=(): Unimplemented function\n");
/* Access a CSR at index 0 */
bool access(T
&csr
, bool isRead
) {
return access(0, csr
, isRead
);
/* Access a CSR at ndx for read or write.
* The CSR is indexed relative to its base address, using its
* memory stride. This information is set by the CSR's class and
bool access(uint64_t ndx
, T
&csr
, bool isRead
) {
SS_Strand
* strand
= NULL
; //TODO need a valid strand-id
uint64_t pa
= T::BaseAddress
+ ndx
* T::Stride
;
fprintf(stderr
, "ERROR: SS_CsrAccess::access(): Out of bounds index %d\n", ndx
);
int access
= MemoryTransaction::INTERNAL
;
int state
= csr_
.read64(pa
, &data
, (access
|MemoryTransaction::READ
), 0/*(strand->strand_id()*/);
// if the Csr hasn't been set, use the reset value
csr_
.write64(pa
, data
, (access
|MemoryTransaction::WRITE
), 0/*strand->strand_id()*/);
/* Return the CSR's raw 64-bit at index, ndx. */
uint64_t getNative(uint64_t ndx
) {
/* Ptr-to-member-function types used to access CSR's bitfields. */
typedef uint64_t (T::*GetFn
)(void) const;
typedef void (T::*SetFn
)(uint64_t);
/* Return the CSR's bitfield associated with getFn() at index 0. */
uint64_t get(GetFn getFn
) {
/* Return the CSR's bitfield associated with getFn() at 'ndx'. */
uint64_t get(uint64_t ndx
, GetFn getFn
) {
return ((csr
).*(getFn
))();
/* Set the CSR at index 0 to 'value'. Return the CSR's new result. */
T
setNative(uint64_t ndx
, uint64_t value
) {
/* Set the CSR's bitfield associated with setFn at index 0 to ones.
* Return the CSR's new result.
return set(0, setFn
, ~0ULL);
/* Set the CSR's bitfield associated with setFn at index 0 to 'value'.
* Return the CSR's new result.
T
set(SetFn setFn
, uint64_t value
) {
return set(0, setFn
, value
);
/* Set the CSR's bitfield associated with setFn at 'ndx' to ones.
* Return the CSR's new result.
T
set(uint64_t ndx
, SetFn setFn
) {
/* Set the CSR's bitfield associated with setFn at 'ndx' to 'value'.
* Return the CSR's new result.
T
set(uint64_t ndx
, SetFn setFn
, uint64_t value
) {
#endif /* SS_CSR_ACCESS_H */