/* $Id: msr.hh,v 1.9 2008-04-28 20:29:15 sybreon Exp $
|
/* $Id: msr.hh,v 1.9 2008-04-28 20:29:15 sybreon Exp $
|
**
|
**
|
** AEMB2 HI-PERFORMANCE CPU
|
** AEMB2 HI-PERFORMANCE CPU
|
** Copyright (C) 2004-2007 Shawn Tan Ser Ngiap
|
** Copyright (C) 2004-2007 Shawn Tan Ser Ngiap
|
**
|
**
|
** This file is part of AEMB.
|
** This file is part of AEMB.
|
**
|
**
|
** AEMB is free software: you can redistribute it and/or modify it
|
** AEMB is free software: you can redistribute it and/or modify it
|
** under the terms of the GNU General Public License as published by
|
** under the terms of the GNU General Public License as published by
|
** the Free Software Foundation, either version 3 of the License, or
|
** the Free Software Foundation, either version 3 of the License, or
|
** (at your option) any later version.
|
** (at your option) any later version.
|
**
|
**
|
** AEMB is distributed in the hope that it will be useful, but WITHOUT
|
** AEMB is distributed in the hope that it will be useful, but WITHOUT
|
** ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
** ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
** or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public
|
** or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public
|
** License for more details.
|
** License for more details.
|
**
|
**
|
** You should have received a copy of the GNU General Public License
|
** You should have received a copy of the GNU General Public License
|
** along with AEMB. If not, see .
|
** along with AEMB. If not, see .
|
*/
|
*/
|
|
|
/**
|
/**
|
Basic MSR functions
|
Basic MSR functions
|
@file msr.hh
|
@file msr.hh
|
|
|
These functions provide read/write access to the Machine Status
|
These functions provide read/write access to the Machine Status
|
Register. It also contains the bit definitions of the register.
|
Register. It also contains the bit definitions of the register.
|
*/
|
*/
|
|
|
#ifndef _AEMB_MSR_HH
|
#ifndef _AEMB_MSR_HH
|
#define _AEMB_MSR_HH
|
#define _AEMB_MSR_HH
|
|
|
// STANDARD BITS
|
// STANDARD BITS
|
#define AEMB_MSR_BE (1 << 0) ///< Buslock Enable
|
#define AEMB_MSR_BE (1 << 0) ///< Buslock Enable
|
#define AEMB_MSR_IE (1 << 1) ///< Interrupt Enable
|
#define AEMB_MSR_IE (1 << 1) ///< Interrupt Enable
|
#define AEMB_MSR_C (1 << 2) ///< Arithmetic Carry
|
#define AEMB_MSR_C (1 << 2) ///< Arithmetic Carry
|
#define AEMB_MSR_BIP (1 << 3) ///< Break in Progress
|
#define AEMB_MSR_BIP (1 << 3) ///< Break in Progress
|
#define AEMB_MSR_EE (1 << 8) ///< Exception Enable
|
#define AEMB_MSR_EE (1 << 8) ///< Exception Enable
|
#define AEMB_MSR_EIP (1 << 9) ///< Exception in Progress
|
#define AEMB_MSR_EIP (1 << 9) ///< Exception in Progress
|
|
|
#define AEMB_MSR_ITE (1 << 5) ///< Instruction Cache Enable
|
#define AEMB_MSR_ITE (1 << 5) ///< Instruction Cache Enable
|
#define AEMB_MSR_DZ (1 << 6) ///< Division by Zero
|
#define AEMB_MSR_DZ (1 << 6) ///< Division by Zero
|
#define AEMB_MSR_DTE (1 << 7) ///< Data Cache Enable
|
#define AEMB_MSR_DTE (1 << 7) ///< Data Cache Enable
|
|
|
// CUSTOM BITS
|
// CUSTOM BITS
|
#define AEMB_MSR_MTX (1 << 4) ///< Hardware Mutex
|
#define AEMB_MSR_MTX (1 << 4) ///< Hardware Mutex
|
#define AEMB_MSR_PHA (1 << 29) ///< Hardware Thread Phase
|
#define AEMB_MSR_PHA (1 << 29) ///< Hardware Thread Phase
|
#define AEMB_MSR_HTX (1 << 30) ///< Hardware Threads Extension
|
#define AEMB_MSR_HTX (1 << 30) ///< Hardware Threads Extension
|
#define AEMB_MSR_CC (1 << 31) ///< Carry Copy
|
#define AEMB_MSR_CC (1 << 31) ///< Carry Copy
|
|
|
#ifdef __cplusplus
|
#ifdef __cplusplus
|
extern "C" {
|
extern "C" {
|
#endif
|
#endif
|
|
|
/**
|
/**
|
Read the value of the MSR register
|
Read the value of the MSR register
|
@return register contents
|
@return register contents
|
*/
|
*/
|
|
|
inline int aembGetMSR()
|
static inline int aembGetMSR()
|
{
|
{
|
int rmsr;
|
int rmsr;
|
asm volatile ("mfs %0, rmsr":"=r"(rmsr));
|
asm volatile ("mfs %0, rmsr":"=r"(rmsr));
|
return rmsr;
|
return rmsr;
|
}
|
}
|
|
|
/**
|
/**
|
Write a value to the MSR register
|
Write a value to the MSR register
|
@param rmsr value to write
|
@param rmsr value to write
|
*/
|
*/
|
|
|
inline void aembPutMSR(int rmsr)
|
static inline void aembPutMSR(int rmsr)
|
{
|
{
|
asm volatile ("mts rmsr, %0"::"r"(rmsr));
|
asm volatile ("mts rmsr, %0"::"r"(rmsr));
|
}
|
}
|
|
|
/**
|
/**
|
Read and clear the MSR
|
Read and clear the MSR
|
@param rmsk clear mask
|
@param rmsk clear mask
|
@return msr value
|
@return msr value
|
*/
|
*/
|
|
|
inline int aembClrMSR(const short rmsk)
|
static inline int aembClrMSR(const short rmsk)
|
{
|
{
|
int tmp;
|
int tmp;
|
//asm volatile ("msrclr %0, %1":"=r"(tmp):"K"(rmsk):"memory");
|
//asm volatile ("msrclr %0, %1":"=r"(tmp):"K"(rmsk):"memory");
|
return tmp;
|
return tmp;
|
}
|
}
|
|
|
/**
|
/**
|
Read and set the MSR
|
Read and set the MSR
|
@param rmsk set mask
|
@param rmsk set mask
|
@return msr value
|
@return msr value
|
*/
|
*/
|
|
|
inline int aembSetMSR(const short rmsk)
|
static inline int aembSetMSR(const short rmsk)
|
{
|
{
|
int tmp;
|
int tmp;
|
//asm volatile ("msrset %0, %1":"=r"(tmp):"K"(rmsk):"memory");
|
//asm volatile ("msrset %0, %1":"=r"(tmp):"K"(rmsk):"memory");
|
return tmp;
|
return tmp;
|
}
|
}
|
|
|
/** Enable global interrupts */
|
/** Enable global interrupts */
|
inline int aembEnableInterrupts()
|
static inline int aembEnableInterrupts()
|
{
|
{
|
int msr;
|
int msr;
|
asm volatile ("msrset %0, %1":"=r"(msr):"K"(AEMB_MSR_IE));
|
asm volatile ("msrset %0, %1":"=r"(msr):"K"(AEMB_MSR_IE));
|
return msr;
|
return msr;
|
}
|
}
|
|
|
/** Disable global interrupts */
|
/** Disable global interrupts */
|
inline int aembDisableInterrupts()
|
static inline int aembDisableInterrupts()
|
{
|
{
|
int msr;
|
int msr;
|
asm volatile ("msrclr %0, %1":"=r"(msr):"K"(AEMB_MSR_IE));
|
asm volatile ("msrclr %0, %1":"=r"(msr):"K"(AEMB_MSR_IE));
|
return msr;
|
return msr;
|
}
|
}
|
|
|
/** Enable global exception */
|
/** Enable global exception */
|
inline int aembEnableException()
|
static inline int aembEnableException()
|
{
|
{
|
int msr;
|
int msr;
|
asm volatile ("msrset %0, %1":"=r"(msr):"K"(AEMB_MSR_EE));
|
asm volatile ("msrset %0, %1":"=r"(msr):"K"(AEMB_MSR_EE));
|
return msr;
|
return msr;
|
}
|
}
|
|
|
/** Disable global exception */
|
/** Disable global exception */
|
inline int aembDisableException()
|
static inline int aembDisableException()
|
{
|
{
|
int msr;
|
int msr;
|
asm volatile ("msrclr %0, %1":"=r"(msr):"K"(AEMB_MSR_EE));
|
asm volatile ("msrclr %0, %1":"=r"(msr):"K"(AEMB_MSR_EE));
|
return msr;
|
return msr;
|
}
|
}
|
|
|
/** Enable data caches */
|
/** Enable data caches */
|
inline int aembEnableDataTag()
|
static inline int aembEnableDataTag()
|
{
|
{
|
int msr;
|
int msr;
|
asm volatile ("msrset %0, %1":"=r"(msr):"K"(AEMB_MSR_DTE));
|
asm volatile ("msrset %0, %1":"=r"(msr):"K"(AEMB_MSR_DTE));
|
return msr;
|
return msr;
|
}
|
}
|
|
|
/** Disable data caches */
|
/** Disable data caches */
|
inline int aembDisableDataTag()
|
static inline int aembDisableDataTag()
|
{
|
{
|
int msr;
|
int msr;
|
asm volatile ("msrclr %0, %1":"=r"(msr):"K"(AEMB_MSR_DTE));
|
asm volatile ("msrclr %0, %1":"=r"(msr):"K"(AEMB_MSR_DTE));
|
return msr;
|
return msr;
|
}
|
}
|
|
|
/** Enable inst caches */
|
/** Enable inst caches */
|
inline int aembEnableInstTag()
|
static inline int aembEnableInstTag()
|
{
|
{
|
int msr;
|
int msr;
|
asm volatile ("msrset %0, %1":"=r"(msr):"K"(AEMB_MSR_ITE));
|
asm volatile ("msrset %0, %1":"=r"(msr):"K"(AEMB_MSR_ITE));
|
return msr;
|
return msr;
|
}
|
}
|
|
|
/** Disable inst caches */
|
/** Disable inst caches */
|
inline int aembDisableInstTag()
|
static inline int aembDisableInstTag()
|
{
|
{
|
int msr;
|
int msr;
|
asm volatile ("msrclr %0, %1":"=r"(msr):"K"(AEMB_MSR_ITE));
|
asm volatile ("msrclr %0, %1":"=r"(msr):"K"(AEMB_MSR_ITE));
|
return msr;
|
return msr;
|
}
|
}
|
|
|
#ifdef __cplusplus
|
#ifdef __cplusplus
|
}
|
}
|
#endif
|
#endif
|
|
|
#endif
|
#endif
|
|
|