MIPS_CPUComponent Class Reference

Back to the index.

Public Member Functions | Static Public Member Functions | Protected Member Functions | Protected Attributes | List of all members
MIPS_CPUComponent Class Reference

A Component representing a MIPS processor. More...

#include <MIPS_CPUComponent.h>

Inheritance diagram for MIPS_CPUComponent:
CPUDyntransComponent CPUComponent Component AddressDataBus UnitTestable ReferenceCountable

Public Member Functions

 MIPS_CPUComponent ()
 Constructs a MIPS_CPUComponent. More...
 
virtual void ResetState ()
 Resets the state variables of this component. More...
 
virtual bool PreRunCheckForComponent (GXemul *gxemul)
 Checks the state of this component, before starting execution. More...
 
virtual size_t DisassembleInstruction (uint64_t vaddr, size_t maxlen, unsigned char *instruction, vector< string > &result)
 Disassembles an instruction into readable strings. More...
 
template<int op, bool samepage, bool singlestep>
void instr_b (CPUDyntransComponent *cpubase, DyntransIC *ic)
 
template<bool link, bool singlestep>
void instr_j (CPUDyntransComponent *cpubase, DyntransIC *ic)
 
template<bool link, bool singlestep>
void instr_jr (CPUDyntransComponent *cpubase, DyntransIC *ic)
 
template<bool store, typename addressType , typename T , bool signedLoad>
void instr_loadstore (CPUDyntransComponent *cpubase, DyntransIC *ic)
 
- Public Member Functions inherited from CPUDyntransComponent
 CPUDyntransComponent (const string &className, const string &cpuKind)
 Constructs a CPUDyntransComponent. More...
 
virtual int Execute (GXemul *gxemul, int nrOfCycles)
 Execute one or more cycles. More...
 
- Public Member Functions inherited from CPUComponent
 CPUComponent (const string &className, const string &cpuKind)
 Constructs a CPUComponent. More...
 
SymbolRegistryGetSymbolRegistry ()
 Gets a reference to the CPU's symbol registry. More...
 
const SymbolRegistryGetSymbolRegistry () const
 
virtual double GetCurrentFrequency () const
 Returns the current frequency (in Hz) that the component runs at. More...
 
virtual CPUComponentAsCPUComponent ()
 Returns the component's CPUComponent interface. More...
 
virtual void GetMethodNames (vector< string > &names) const
 Retrieves a component's implemented method names. More...
 
virtual bool MethodMayBeReexecutedWithoutArgs (const string &methodName) const
 Returns whether a method name may be re-executed without args. More...
 
virtual void ExecuteMethod (GXemul *gxemul, const string &methodName, const vector< string > &arguments)
 Executes a method on the component. More...
 
virtual AddressDataBusAsAddressDataBus ()
 Returns the component's AddressDataBus interface, if any. More...
 
virtual void AddressSelect (uint64_t address)
 Place an address on the bus. More...
 
virtual bool ReadData (uint8_t &data, Endianness endianness)
 Reads 8-bit data from the currently selected address. More...
 
virtual bool ReadData (uint16_t &data, Endianness endianness)
 Reads 16-bit data from the currently selected address. More...
 
virtual bool ReadData (uint32_t &data, Endianness endianness)
 Reads 32-bit data from the currently selected address. More...
 
virtual bool ReadData (uint64_t &data, Endianness endianness)
 Reads 64-bit data from the currently selected address. More...
 
virtual bool WriteData (const uint8_t &data, Endianness endianness)
 Writes 8-bit data to the currently selected address. More...
 
virtual bool WriteData (const uint16_t &data, Endianness endianness)
 Writes 16-bit data to the currently selected address. More...
 
virtual bool WriteData (const uint32_t &data, Endianness endianness)
 Writes 32-bit data to the currently selected address. More...
 
virtual bool WriteData (const uint64_t &data, Endianness endianness)
 Writes 64-bit data to the currently selected address. More...
 
- Public Member Functions inherited from Component
virtual ~Component ()
 
string GetClassName () const
 Gets the class name of the component. More...
 
string GetVisibleClassName () const
 Gets the visible class name of the component. More...
 
refcount_ptr< ComponentClone () const
 Clones the component and all its children. More...
 
const refcount_ptr< ComponentLightClone () const
 Makes a light clone of the component and all its children. More...
 
void DetectChanges (const refcount_ptr< Component > &oldClone, ostream &changeMessages) const
 Compare an older clone to the current tree, to find changes. More...
 
string GenerateTreeDump (const string &branchTemplate, bool htmlLinksForClassNames=false, string prefixForComponentUrls="") const
 Generates an ASCII tree dump of a component tree. More...
 
virtual string GenerateDetails () const
 Generate details about the component. More...
 
void Reset ()
 Resets the state of this component and all its children. More...
 
bool PreRunCheck (GXemul *gxemul)
 Checks the state of this component and all its children, before starting execution. More...
 
void FlushCachedState ()
 Resets the cached state of this component and all its children. More...
 
virtual RootComponentAsRootComponent ()
 Returns the component's RootComponent interface. More...
 
void SetParent (Component *parentComponent)
 Sets the parent component of this component. More...
 
ComponentGetParent ()
 Gets this component's parent component, if any. More...
 
const ComponentGetParent () const
 
string GeneratePath () const
 Generates a string representation of the path to the Component. More...
 
string GenerateShortestPossiblePath () const
 Generates a short string representation of the path to the Component. More...
 
const refcount_ptr< ComponentLookupPath (string path) const
 Looks up a path from this Component, and returns a pointer to the found Component, if any. More...
 
vector< string > FindPathByPartialMatch (const string &partialPath, bool shortestPossible=false) const
 Finds complete component paths, given a partial path. More...
 
void AddChild (refcount_ptr< Component > childComponent, size_t insertPosition=(size_t)-1)
 Adds a reference to a child component. More...
 
size_t RemoveChild (Component *childToRemove)
 Removes a reference to a child component. More...
 
ComponentsGetChildren ()
 Gets pointers to child components. More...
 
const ComponentsGetChildren () const
 Gets pointers to child components, as a const reference. More...
 
void GetVariableNames (vector< string > &names) const
 Retrieves a component's state variable names. More...
 
StateVariableGetVariable (const string &name)
 Gets a pointer to a state variable. More...
 
const StateVariableGetVariable (const string &name) const
 Gets a pointer to a state variable. More...
 
bool SetVariableValue (const string &name, const string &expression)
 Sets a variable to a new value. More...
 
void Serialize (ostream &ss, SerializationContext &context) const
 Serializes the Component into a string stream. More...
 
bool CheckConsistency () const
 Checks consistency by serializing and deserializing the component (including all its child components), and comparing the checksum of the original tree with the deserialized tree. More...
 
void AddChecksum (Checksum &checksum) const
 Adds this component's state, including children, to a checksum. More...
 
- Public Member Functions inherited from ReferenceCountable
 ReferenceCountable ()
 Default constructor, which initializes the reference count to zero. More...
 
 ~ReferenceCountable ()
 
- Public Member Functions inherited from AddressDataBus
 AddressDataBus ()
 Constructs an AddressDataBus instance. More...
 
virtual ~AddressDataBus ()
 

Static Public Member Functions

static refcount_ptr< ComponentCreate (const ComponentCreateArgs &args)
 Creates a MIPS_CPUComponent. More...
 
static string GetAttribute (const string &attributeName)
 
static void RunUnitTests (int &nSucceeded, int &nFailures)
 
- Static Public Member Functions inherited from CPUDyntransComponent
static void RunUnitTests (int &nSucceeded, int &nFailures)
 
- Static Public Member Functions inherited from CPUComponent
static void RunUnitTests (int &nSucceeded, int &nFailures)
 
- Static Public Member Functions inherited from Component
static string GetAttribute (const string &attributeName)
 Creates a Component. More...
 
static refcount_ptr< ComponentDeserialize (ostream &messages, const string &str, size_t &pos)
 Deserializes a string into a component tree. More...
 
- Static Public Member Functions inherited from UnitTestable
static void RunUnitTests (int &nSucceeded, int &nFailures)
 Runs unit test cases. More...
 

Protected Member Functions

virtual bool CheckVariableWrite (StateVariable &var, const string &oldValue)
 Checks whether a write to a variable is OK. More...
 
virtual bool VirtualToPhysical (uint64_t vaddr, uint64_t &paddr, bool &writable)
 Virtual to physical address translation (MMU). More...
 
virtual string VirtualAddressAsString (uint64_t vaddr)
 Format a virtual address as a displayable string. More...
 
virtual uint64_t PCtoInstructionAddress (uint64_t pc)
 Convert PC value to instuction address. More...
 
virtual int FunctionTraceArgumentCount ()
 
virtual int64_t FunctionTraceArgument (int n)
 
virtual bool FunctionTraceReturnImpl (int64_t &retval)
 
virtual int GetDyntransICshift () const
 
virtual void ShowRegisters (GXemul *gxemul, const vector< string > &arguments) const
 
- Protected Member Functions inherited from CPUDyntransComponent
void DyntransToBeTranslatedBegin (struct DyntransIC *)
 
bool DyntransReadInstruction (uint16_t &iword)
 
bool DyntransReadInstruction (uint32_t &iword)
 
void DyntransToBeTranslatedDone (struct DyntransIC *)
 
void DyntransResyncPC ()
 Calculate m_pc based on m_nextIC and m_firstIConPage. More...
 
void DyntransPCtoPointers ()
 Calculate m_nextIC and m_firstIConPage, based on m_pc. More...
 
 DECLARE_DYNTRANS_INSTR (nop)
 
 DECLARE_DYNTRANS_INSTR (abort)
 
 DECLARE_DYNTRANS_INSTR (endOfPage)
 
 DECLARE_DYNTRANS_INSTR (endOfPage2)
 
 DECLARE_DYNTRANS_INSTR (branch_samepage)
 
 DECLARE_DYNTRANS_INSTR (set_u64_imms32)
 
 DECLARE_DYNTRANS_INSTR (mov_u64_u64)
 
 DECLARE_DYNTRANS_INSTR (add_u32_u32_immu32)
 
 DECLARE_DYNTRANS_INSTR (add_u32_u32_u32)
 
 DECLARE_DYNTRANS_INSTR (add_u64_u64_imms32_truncS32)
 
 DECLARE_DYNTRANS_INSTR (add_u64_u64_u64_truncS32)
 
 DECLARE_DYNTRANS_INSTR (add_u64_u64_imms32)
 
 DECLARE_DYNTRANS_INSTR (sub_u32_u32_immu32)
 
 DECLARE_DYNTRANS_INSTR (sub_u32_u32_u32)
 
 DECLARE_DYNTRANS_INSTR (sub_u64_u64_u64_truncS32)
 
 DECLARE_DYNTRANS_INSTR (and_u32_u32_immu32)
 
 DECLARE_DYNTRANS_INSTR (and_u64_u64_immu32)
 
 DECLARE_DYNTRANS_INSTR (or_u32_u32_immu32)
 
 DECLARE_DYNTRANS_INSTR (or_u32_u32_u32)
 
 DECLARE_DYNTRANS_INSTR (or_u64_u64_immu32)
 
 DECLARE_DYNTRANS_INSTR (xor_u32_u32_immu32)
 
 DECLARE_DYNTRANS_INSTR (xor_u32_u32_u32)
 
 DECLARE_DYNTRANS_INSTR (xor_u64_u64_immu32)
 
 DECLARE_DYNTRANS_INSTR (xor_u64_u64_u64)
 
 DECLARE_DYNTRANS_INSTR (shift_left_u64_u64_imm5_truncS32)
 
 DECLARE_DYNTRANS_INSTR (shift_right_u64_u64asu32_imm5_truncS32)
 
- Protected Member Functions inherited from CPUComponent
virtual void FlushCachedStateForComponent ()
 Resets the cached state of this component. More...
 
uint64_t Unassemble (int nRows, bool indicatePC, uint64_t vaddr, ostream &output)
 
bool FunctionTraceCall ()
 
bool FunctionTraceReturn ()
 
- Protected Member Functions inherited from Component
 Component (const string &className, const string &visibleClassName)
 Base constructor for a Component. More...
 
template<class T >
bool AddVariable (const string &name, T *variablePointer)
 Adds a state variable of type T to the Component. More...
 
bool AddCustomVariable (const string &name, CustomStateVariableHandler *variableHandler)
 Adds a custom state variable to the Component. More...
 
GXemulGetRunningGXemulInstance ()
 Returns a reference to the current GXemul instance. More...
 
UIGetUI ()
 Gets an UI reference for outputting debug messages during runtime. More...
 

Protected Attributes

virtual void(*)(CPUDyntransComponent
*, DyntransIC *) 
GetDyntransToBeTranslated ()
 
- Protected Attributes inherited from CPUDyntransComponent
virtual void(*)(CPUDyntransComponent
*cpu, DyntransIC *ic) 
GetDyntransToBeTranslated ()
 
struct DyntransICm_firstIConPage
 
struct DyntransICm_nextIC
 
int m_dyntransPageMask
 
int m_dyntransICentriesPerPage
 
int m_dyntransICshift
 
int m_executedCycles
 
int m_nrOfCyclesToExecute
 
DyntransTranslationCache m_translationCache
 
struct DyntransIC m_abortIC
 
- Protected Attributes inherited from CPUComponent
double m_frequency
 
bool m_paused
 
string m_cpuArchitecture
 
int m_pageSize
 
uint64_t m_pc
 
uint64_t m_lastDumpAddr
 
uint64_t m_lastUnassembleVaddr
 
bool m_hasUsedUnassemble
 
bool m_isBigEndian
 
bool m_showFunctionTraceCall
 
bool m_showFunctionTraceReturn
 
int32_t m_functionCallTraceDepth
 
int64_t m_nrOfTracedFunctionCalls
 
bool m_inDelaySlot
 
uint64_t m_delaySlotTarget
 
AddressDataBusm_addressDataBus
 
uint64_t m_addressSelect
 
bool m_exceptionOrAbortInDelaySlot
 

Detailed Description

A Component representing a MIPS processor.

Definition at line 147 of file MIPS_CPUComponent.h.

Constructor & Destructor Documentation

MIPS_CPUComponent::MIPS_CPUComponent ( )

Member Function Documentation

bool MIPS_CPUComponent::CheckVariableWrite ( StateVariable var,
const string &  oldValue 
)
protectedvirtual

Checks whether a write to a variable is OK.

This function is called after the variable has been written. By returning false, the component indicates that the value which was written is invalid, and the write will be undone.

An implementation should first check variables defined for the implementation class, and then call its base class' function.

The implementation in the base Component class handles the variables that are defined for all components, and returns true for anything else.

Parameters
varThe variable to check.
oldValueThe serialized previous value.
Returns
true if the write was ok, false otherwise.

Reimplemented from Component.

Definition at line 177 of file MIPS_CPUComponent.cc.

References Component::CheckVariableWrite(), Component::GetUI(), MIPS_GPR_ZERO, mips_cpu_type_def::name, and UI::ShowDebugMessage().

refcount_ptr< Component > MIPS_CPUComponent::Create ( const ComponentCreateArgs args)
static
size_t MIPS_CPUComponent::DisassembleInstruction ( uint64_t  vaddr,
size_t  maxLen,
unsigned char *  instruction,
vector< string > &  result 
)
virtual

Disassembles an instruction into readable strings.

Parameters
vaddrThe virtual address of the program counter.
maxLenThe number of bytes in the instruction buffer.
instructionA pointer to a buffer containing the instruction.
resultA vector where the implementation will add:
  1. machine code bytes in a standard notation
  2. instruction mnemonic
  3. instruction arguments
  4. instruction comments
All of the fields above are optional, but they have to be specified in the same order for a particular CPU implementation, so that the fields of the vector can be listed in a tabular format.
Returns
The number of bytes that the instruction occupied.

Implements CPUComponent.

Definition at line 428 of file MIPS_CPUComponent.cc.

References BE32_TO_HOST, CPUComponent::GetSymbolRegistry(), HI6_ADDI, HI6_ADDIU, HI6_ANDI, HI6_BEQ, HI6_BEQL, HI6_BGTZ, HI6_BGTZL, HI6_BLEZ, HI6_BLEZL, HI6_BNE, HI6_BNEL, HI6_DADDI, HI6_DADDIU, HI6_J, HI6_JAL, HI6_LB, HI6_LBU, HI6_LD, HI6_LDC1, HI6_LDC2, HI6_LDL, HI6_LDR, HI6_LH, HI6_LHU, HI6_LL, HI6_LLD, HI6_LQ_MDMX, HI6_LUI, HI6_LW, HI6_LWC1, HI6_LWC2, HI6_LWC3, HI6_LWL, HI6_LWR, HI6_LWU, HI6_ORI, HI6_REGIMM, HI6_SB, HI6_SC, HI6_SCD, HI6_SD, HI6_SDC1, HI6_SDC2, HI6_SDL, HI6_SDR, HI6_SH, HI6_SLTI, HI6_SLTIU, HI6_SPECIAL, HI6_SQ_SPECIAL3, HI6_SW, HI6_SWC1, HI6_SWC2, HI6_SWC3, HI6_SWL, HI6_SWR, HI6_XORI, mips_cpu_type_def::isa_level, LE32_TO_HOST, SymbolRegistry::LookupAddress(), CPUComponent::m_inDelaySlot, CPUComponent::m_isBigEndian, CPUComponent::m_pc, MIPS_GPR_ZERO, MIPS_R5900, PCtoInstructionAddress(), REGIMM_BGEZ, REGIMM_BGEZAL, REGIMM_BGEZALL, REGIMM_BGEZL, REGIMM_BLTZ, REGIMM_BLTZAL, REGIMM_BLTZALL, REGIMM_BLTZL, REGIMM_SYNCI, mips_cpu_type_def::rev, SPECIAL_ADD, SPECIAL_ADDU, SPECIAL_AND, SPECIAL_BREAK, SPECIAL_DADD, SPECIAL_DADDU, SPECIAL_DDIV, SPECIAL_DDIVU, SPECIAL_DIV, SPECIAL_DIVU, SPECIAL_DMULT, SPECIAL_DMULTU, SPECIAL_DSLL, SPECIAL_DSLL32, SPECIAL_DSLLV, SPECIAL_DSRA, SPECIAL_DSRA32, SPECIAL_DSRAV, SPECIAL_DSRL, SPECIAL_DSRL32, SPECIAL_DSRLV, SPECIAL_DSUB, SPECIAL_DSUBU, SPECIAL_JALR, SPECIAL_JR, SPECIAL_MFHI, SPECIAL_MFLO, SPECIAL_MFSA, SPECIAL_MOVN, SPECIAL_MOVZ, SPECIAL_MTHI, SPECIAL_MTLO, SPECIAL_MTSA, SPECIAL_MULT, SPECIAL_MULTU, SPECIAL_NOR, SPECIAL_OR, SPECIAL_SLL, SPECIAL_SLLV, SPECIAL_SLT, SPECIAL_SLTU, SPECIAL_SRA, SPECIAL_SRAV, SPECIAL_SRL, SPECIAL_SRLV, SPECIAL_SUB, SPECIAL_SUBU, SPECIAL_SYNC, SPECIAL_SYSCALL, SPECIAL_TEQ, SPECIAL_TGE, SPECIAL_TGEU, SPECIAL_TLT, SPECIAL_TLTU, SPECIAL_TNE, and SPECIAL_XOR.

int64_t MIPS_CPUComponent::FunctionTraceArgument ( int  n)
protectedvirtual

Reimplemented from CPUComponent.

Definition at line 302 of file MIPS_CPUComponent.cc.

References MIPS_GPR_A0.

int MIPS_CPUComponent::FunctionTraceArgumentCount ( )
protectedvirtual

Reimplemented from CPUComponent.

Definition at line 290 of file MIPS_CPUComponent.cc.

bool MIPS_CPUComponent::FunctionTraceReturnImpl ( int64_t &  retval)
protectedvirtual

Reimplemented from CPUComponent.

Definition at line 309 of file MIPS_CPUComponent.cc.

References MIPS_GPR_V0.

string MIPS_CPUComponent::GetAttribute ( const string &  attributeName)
static

Definition at line 919 of file MIPS_CPUComponent.cc.

References Component::GetAttribute().

int MIPS_CPUComponent::GetDyntransICshift ( ) const
protectedvirtual

Implements CPUDyntransComponent.

Definition at line 320 of file MIPS_CPUComponent.cc.

References CPUComponent::m_pc.

template<int op, bool samepage, bool singlestep>
void MIPS_CPUComponent::instr_b ( CPUDyntransComponent cpubase,
DyntransIC ic 
)
template<bool link, bool singlestep>
void MIPS_CPUComponent::instr_j ( CPUDyntransComponent cpubase,
DyntransIC ic 
)
template<bool link, bool singlestep>
void MIPS_CPUComponent::instr_jr ( CPUDyntransComponent cpubase,
DyntransIC ic 
)
template<bool store, typename addressType , typename T , bool signedLoad>
void MIPS_CPUComponent::instr_loadstore ( CPUDyntransComponent cpubase,
DyntransIC ic 
)
uint64_t MIPS_CPUComponent::PCtoInstructionAddress ( uint64_t  pc)
protectedvirtual

Convert PC value to instuction address.

Usually, this does not need to be overridden. However, some architectures use e.g. the lowest bit of the PC register to indicate a different encoding mode (MIPS16), but the instruction is still aligned as if the lowest bit was 0.

Reimplemented from CPUComponent.

Definition at line 361 of file MIPS_CPUComponent.cc.

Referenced by DisassembleInstruction().

bool MIPS_CPUComponent::PreRunCheckForComponent ( GXemul gxemul)
virtual

Checks the state of this component, before starting execution.

Note 1: This function is not recursive, so children should not be traversed.

Note 2: After a component's state variables have been checked, the base class' PreRunCheckForComponent(GXemul*) function should also be called.

The implementation of this function may choose to print warning messages but still return true, or it can print error messages and return false.

Typical examples of pre-run-check failures are:

Returns
true if the component is ready to run, false otherwise.

Reimplemented from CPUComponent.

Definition at line 138 of file MIPS_CPUComponent.cc.

References GXemul::GetUI(), CPUComponent::m_pc, MIPS_GPR_ZERO, N_MIPS_GPRS, CPUComponent::PreRunCheckForComponent(), and UI::ShowDebugMessage().

void MIPS_CPUComponent::ResetState ( )
virtual

Resets the state variables of this component.

Note 1: This function is not recursive, so children should not be traversed.

Note 2: After a component's state variables have been reset, the base class' ResetState() function should also be called.

The implementation of this function ususally takes the form of a number of assignment of values to member variables, and then the call to the base class' ResetState() function.

Reimplemented from CPUComponent.

Definition at line 113 of file MIPS_CPUComponent.cc.

References CPUComponent::m_pageSize, CPUComponent::m_pc, MIPS_GPR_SP, MIPS_INITIAL_PC, MIPS_INITIAL_STACK_POINTER, N_MIPS_GPRS, and CPUComponent::ResetState().

Referenced by MIPS_CPUComponent().

static void MIPS_CPUComponent::RunUnitTests ( int &  nSucceeded,
int &  nFailures 
)
static
void MIPS_CPUComponent::ShowRegisters ( GXemul gxemul,
const vector< string > &  arguments 
) const
protectedvirtual
virtual string MIPS_CPUComponent::VirtualAddressAsString ( uint64_t  vaddr)
inlineprotectedvirtual

Format a virtual address as a displayable string.

This function may be overridden in each CPU implementation. The default implementation just uses the stringstream << operator.

Parameters
vaddrThe virtual address to translate.
Returns
A string rendering of the virtual address, e.g. "0x00100f00"

Reimplemented from CPUComponent.

Definition at line 181 of file MIPS_CPUComponent.h.

bool MIPS_CPUComponent::VirtualToPhysical ( uint64_t  vaddr,
uint64_t &  paddr,
bool &  writable 
)
protectedvirtual

Virtual to physical address translation (MMU).

This function should be overridden in each CPU implementation.

Parameters
vaddrThe virtual address to translate.
paddrThe return value; physical address.
writableThis is set to true or false by the function, depending on if the memory at the virtual address was writable or not.
Returns
True if the translation succeeded, false if there was a translation error.

Implements CPUComponent.

Definition at line 337 of file MIPS_CPUComponent.cc.

Member Data Documentation

virtual void(*)(CPUDyntransComponent*, DyntransIC*) MIPS_CPUComponent::GetDyntransToBeTranslated()
protected

Definition at line 199 of file MIPS_CPUComponent.h.


The documentation for this class was generated from the following files:

Generated on Sun Aug 17 2014 10:51:04 for GXemul by doxygen 1.8.3.1