coding-style improved.

git-svn-id: https://www4.informatik.uni-erlangen.de/i4svn/danceos/trunk/devel/fail@1364 8c4709b5-6ec9-48aa-a5cd-a96041d1645a
This commit is contained in:
adrian
2012-06-20 08:42:58 +00:00
parent 583f60c430
commit 127a25707f
2 changed files with 718 additions and 734 deletions

File diff suppressed because it is too large Load Diff

View File

@ -31,239 +31,238 @@ class MemoryManager;
* activates the specific experiment There are further methods to read/write * activates the specific experiment There are further methods to read/write
* registers and memory, and control the SUT (save/restore/reset). * registers and memory, and control the SUT (save/restore/reset).
*/ */
class SimulatorController class SimulatorController {
{ protected:
protected: EventList m_EvList; //!< storage where events are being buffered
EventList m_EvList; //!< storage where events are being buffered CoroutineManager m_Flows; //!< managed experiment flows
CoroutineManager m_Flows; //!< managed experiment flows RegisterManager *m_Regs; //!< access to cpu register
RegisterManager *m_Regs; //!< access to cpu register MemoryManager *m_Mem; //!< access to memory pool
MemoryManager *m_Mem; //!< access to memory pool //! list of suppressed interrupts
//! list of suppressed interrupts std::vector<unsigned> m_SuppressedInterrupts;
std::vector<unsigned> m_SuppressedInterrupts; friend class EventList; //!< "outsources" the event management
friend class EventList; //!< "outsources" the event management public:
public: SimulatorController()
SimulatorController() : m_Regs(NULL), m_Mem(NULL) { }
: m_Regs(NULL), m_Mem(NULL) { } SimulatorController(RegisterManager* regs, MemoryManager* mem)
SimulatorController(RegisterManager* regs, MemoryManager* mem) : m_Regs(regs), m_Mem(mem) { }
: m_Regs(regs), m_Mem(mem) { } virtual ~SimulatorController() { }
virtual ~SimulatorController() { } /**
/** * @brief Initialization function each implementation needs to call on
* @brief Initialization function each implementation needs to call on * startup
* startup *
* * This function needs to be invoked once the simulator starts, and
* This function needs to be invoked once the simulator starts, and * allows the SimulatorController to instantiate all needed experiment
* allows the SimulatorController to instantiate all needed experiment * components.
* components. */
*/ void startup();
void startup(); /**
/** * Experiments need to hook here.
* Experiments need to hook here. */
*/ void initExperiments();
void initExperiments(); /* ********************************************************************
/* ******************************************************************** * Standard Event Handler API
* Standard Event Handler API * ********************************************************************/
* ********************************************************************/ /**
/** * Breakpoint event handler. This routine needs to be called in the
* Breakpoint event handler. This routine needs to be called in the * simulator specific backend each time a breakpoint event occurs.
* simulator specific backend each time a breakpoint event occurs. * @param instrPtr the instruction pointer of the breakpoint event
* @param instrPtr the instruction pointer of the breakpoint event * @param address_space the address space it should occur in
* @param address_space the address space it should occur in */
*/ void onBreakpointEvent(address_t instrPtr, address_t address_space);
void onBreakpointEvent(address_t instrPtr, address_t address_space); /**
/** * Memory access event handler (read/write).
* Memory access event handler (read/write). * @param addr the accessed memory address
* @param addr the accessed memory address * @param len the length of the accessed memory
* @param len the length of the accessed memory * @param is_write \c true if memory is written, \c false if read
* @param is_write \c true if memory is written, \c false if read * @param instrPtr the address of the instruction causing the memory
* @param instrPtr the address of the instruction causing the memory * access
* access *
* * FIXME: should instrPtr be part of this interface?
* FIXME: should instrPtr be part of this interface? */
*/ void onMemoryAccessEvent(address_t addr, size_t len,
void onMemoryAccessEvent(address_t addr, size_t len, bool is_write, address_t instrPtr);
bool is_write, address_t instrPtr); /**
/** * Interrupt event handler.
* Interrupt event handler. * @param interruptNum the interrupt-type id
* @param interruptNum the interrupt-type id * @param nmi nmi-value from guest-system
* @param nmi nmi-value from guest-system */
*/ void onInterruptEvent(unsigned interruptNum, bool nmi);
void onInterruptEvent(unsigned interruptNum, bool nmi); /**
/** * Trap event handler.
* Trap event handler. * @param trapNum the trap-type id
* @param trapNum the trap-type id */
*/ void onTrapEvent(unsigned trapNum);
void onTrapEvent(unsigned trapNum); /**
/** * Guest system communication handler.
* Guest system communication handler. * @param data the "message" from the guest system
* @param data the "message" from the guest system * @param port the port of the event
* @param port the port of the event */
*/ void onGuestSystemEvent(char data, unsigned port);
void onGuestSystemEvent(char data, unsigned port); /**
/** * (Conditional) Jump-instruction handler.
* (Conditional) Jump-instruction handler. * @param flagTriggered \c true if the jump was triggered due to a
* @param flagTriggered \c true if the jump was triggered due to a * specific FLAG (zero/carry/sign/overflow/parity flag)
* specific FLAG (zero/carry/sign/overflow/parity flag) * @param opcode the opcode of the conrecete jump instruction
* @param opcode the opcode of the conrecete jump instruction */
*/ void onJumpEvent(bool flagTriggered, unsigned opcode);
void onJumpEvent(bool flagTriggered, unsigned opcode); /**
/** * This method is called when an experiment flow adds a new event by
* This method is called when an experiment flow adds a new event by * calling \c simulator.addEvent(pev) or \c simulator.addEventAndWait(pev).
* calling \c simulator.addEvent(pev) or \c simulator.addEventAndWait(pev). * More specifically, the event will be added to the event-list first
* More specifically, the event will be added to the event-list first * (buffer-list, to be precise) and then this event handler is called.
* (buffer-list, to be precise) and then this event handler is called. * @param pev the event which has been added
* @param pev the event which has been added * @return You should return \c true to continue and \c false to prevent
* @return You should return \c true to continue and \c false to prevent * the addition of the event \a pev, yielding an error in the
* the addition of the event \a pev, yielding an error in the * experiment flow (i.e. -1 is returned).
* experiment flow (i.e. -1 is returned). */
*/ virtual bool onEventAddition(BaseEvent* pev) { return true; }
virtual bool onEventAddition(BaseEvent* pev) { return true; } /**
/** * This method is called when an experiment flow removes an event from
* This method is called when an experiment flow removes an event from * the event-management by calling \c removeEvent(prev), \c clearEvents()
* the event-management by calling \c removeEvent(prev), \c clearEvents() * or by deleting a complete flow (\c removeFlow). More specifically, this
* or by deleting a complete flow (\c removeFlow). More specifically, this * event handler will be called *before* the event is actually deleted.
* event handler will be called *before* the event is actually deleted. * @param pev the event to be deleted when returning from the event handler
* @param pev the event to be deleted when returning from the event handler */
*/ virtual void onEventDeletion(BaseEvent* pev) { }
virtual void onEventDeletion(BaseEvent* pev) { } /**
/** * This method is called when an previously added event is about to be
* This method is called when an previously added event is about to be * triggered by the simulator-backend. More specifically, this event handler
* triggered by the simulator-backend. More specifically, this event handler * will be called *before* the event is actually triggered, i.e. before the
* will be called *before* the event is actually triggered, i.e. before the * corresponding coroutine is toggled.
* corresponding coroutine is toggled. * @param pev the event to be triggered when returning from the event handler
* @param pev the event to be triggered when returning from the event handler */
*/ virtual void onEventTrigger(BaseEvent* pev) { }
virtual void onEventTrigger(BaseEvent* pev) { } /* ********************************************************************
/* ******************************************************************** * Simulator Controller & Access API:
* Simulator Controller & Access API: * ********************************************************************/
* ********************************************************************/ /**
/** * Save simulator state.
* Save simulator state. * @param path Location to store state information
* @param path Location to store state information */
*/ virtual void save(const std::string& path) = 0;
virtual void save(const std::string& path) = 0; /**
/** * Restore simulator state. Implicitly discards all previously
* Restore simulator state. Implicitly discards all previously * registered events.
* registered events. * @param path Location to previously saved state information
* @param path Location to previously saved state information */
*/ virtual void restore(const std::string& path) = 0;
virtual void restore(const std::string& path) = 0; /**
/** * Reboot simulator.
* Reboot simulator. */
*/ virtual void reboot() = 0;
virtual void reboot() = 0; /**
/** * Terminate simulator
* Terminate simulator * @param exCode Individual exit code
* @param exCode Individual exit code */
*/ void terminate(int exCode = EXIT_SUCCESS) __attribute__ ((noreturn));
void terminate(int exCode = EXIT_SUCCESS) __attribute__ ((noreturn)); /**
/** * Check whether the interrupt should be suppressed.
* Check whether the interrupt should be suppressed. * @param interruptNum the interrupt-type id
* @param interruptNum the interrupt-type id * @return \c true if the interrupt is suppressed, \c false oterwise
* @return \c true if the interrupt is suppressed, \c false oterwise */
*/ bool isSuppressedInterrupt(unsigned interruptNum);
bool isSuppressedInterrupt(unsigned interruptNum); /**
/** * Add a Interrupt to the list of suppressed.
* Add a Interrupt to the list of suppressed. * @param interruptNum the interrupt-type id
* @param interruptNum the interrupt-type id * @return \c true if sucessfully added, \c false otherwise (already
* @return \c true if sucessfully added, \c false otherwise (already * existing)
* existing) */
*/ bool addSuppressedInterrupt(unsigned interruptNum);
bool addSuppressedInterrupt(unsigned interruptNum); /**
/** * Remove a Interrupt from the list of suppressed.
* Remove a Interrupt from the list of suppressed. * @param interruptNum the interrupt-type id
* @param interruptNum the interrupt-type id * @return \c true if sucessfully removed, \c false otherwise (not
* @return \c true if sucessfully removed, \c false otherwise (not * found)
* found) */
*/ bool removeSuppressedInterrupt(unsigned interruptNum);
bool removeSuppressedInterrupt(unsigned interruptNum); /**
/** * Returns the (constant) initialized register manager.
* Returns the (constant) initialized register manager. * @return a reference to the register manager
* @return a reference to the register manager */
*/ RegisterManager& getRegisterManager() { return (*m_Regs); }
RegisterManager& getRegisterManager() { return (*m_Regs); } const RegisterManager& getRegisterManager() const { return (*m_Regs); }
const RegisterManager& getRegisterManager() const { return (*m_Regs); } /**
/** * Sets the register manager.
* Sets the register manager. * @param pReg the new register manager (or a concrete derived class of
* @param pReg the new register manager (or a concrete derived class of * RegisterManager)
* RegisterManager) */
*/ void setRegisterManager(RegisterManager* pReg) { m_Regs = pReg; }
void setRegisterManager(RegisterManager* pReg) { m_Regs = pReg; } /**
/** * Returns the (constant) initialized memory manager.
* Returns the (constant) initialized memory manager. * @return a reference to the memory manager
* @return a reference to the memory manager */
*/ MemoryManager& getMemoryManager() { return (*m_Mem); }
MemoryManager& getMemoryManager() { return (*m_Mem); } const MemoryManager& getMemoryManager() const { return (*m_Mem); }
const MemoryManager& getMemoryManager() const { return (*m_Mem); } /**
/** * Sets the memory manager.
* Sets the memory manager. * @param pMem a new concrete memory manager
* @param pMem a new concrete memory manager */
*/ void setMemoryManager(MemoryManager* pMem) { m_Mem = pMem; }
void setMemoryManager(MemoryManager* pMem) { m_Mem = pMem; } /* ********************************************************************
/* ******************************************************************** * Experiment-Flow & Event Management API:
* Experiment-Flow & Event Management API: * ********************************************************************/
* ********************************************************************/ /**
/** * Adds the specified experiment or plugin and creates a coroutine to
* Adds the specified experiment or plugin and creates a coroutine to * run it in.
* run it in. * @param flow the experiment flow object to be added
* @param flow the experiment flow object to be added */
*/ void addFlow(ExperimentFlow* flow);
void addFlow(ExperimentFlow* flow); /**
/** * Removes the specified experiment or plugin and destroys its coroutine
* Removes the specified experiment or plugin and destroys its coroutine * and all associated events.
* and all associated events. * @param flow the experiment flow object to be removed
* @param flow the experiment flow object to be removed */
*/ void removeFlow(ExperimentFlow* flow);
void removeFlow(ExperimentFlow* flow); /**
/** * Add event ev to the event management. This causes the event to be
* Add event ev to the event management. This causes the event to be * active.
* active. * @param ev the event pointer to be added for the current flow
* @param ev the event pointer to be added for the current flow * @return the id of the event used to identify the object on occurrence;
* @return the id of the event used to identify the object on occurrence; * -1 is returned on errors
* -1 is returned on errors */
*/ EventId addEvent(BaseEvent* ev);
EventId addEvent(BaseEvent* ev); /**
/** * Removes the event with the specified id.
* Removes the event with the specified id. * @param ev the pointer of the event-object to be removed; if \a ev is
* @param ev the pointer of the event-object to be removed; if \a ev is * equal to \c NULL all events (for all experiments) will be
* equal to \c NULL all events (for all experiments) will be * removed
* removed */
*/ void removeEvent(BaseEvent* ev) { m_EvList.remove(ev); }
void removeEvent(BaseEvent* ev) { m_EvList.remove(ev); } /**
/** * Removes all previously added events for all experiments. To
* Removes all previously added events for all experiments. To * restrict this to a specific experiment flow, pass a pointer to it.
* restrict this to a specific experiment flow, pass a pointer to it. */
*/ void clearEvents(ExperimentFlow *flow = 0) { m_EvList.remove(flow); }
void clearEvents(ExperimentFlow *flow = 0) { m_EvList.remove(flow); } /**
/** * Waits on any events which have been added to the event management. If
* Waits on any events which have been added to the event management. If * one of those events occour, waitAny() will return the id of that event.
* one of those events occour, waitAny() will return the id of that event. * @return the previously occurred event
* @return the previously occurred event *
* * FIXME: Maybe this should return immediately if there are not events?
* FIXME: Maybe this should return immediately if there are not events? * (additional parameter flag?)
* (additional parameter flag?) */
*/ BaseEvent* waitAny();
BaseEvent* waitAny(); /**
/** * Add event \a ev to the global buffer and wait for it (combines
* Add event \a ev to the global buffer and wait for it (combines * \c addEvent() and \c waitAny()).
* \c addEvent() and \c waitAny()). * @param ev the event pointer to be added
* @param ev the event pointer to be added * @return the pointer of the occurred event (it is not guaranteed that
* @return the pointer of the occurred event (it is not guaranteed that * this pointer will be equal to ev)
* this pointer will be equal to ev) *
* * FIXME: Rename to make clear this returns when *any* event occurs
* FIXME: Rename to make clear this returns when *any* event occurs */
*/ BaseEvent* addEventAndWait(BaseEvent* ev);
BaseEvent* addEventAndWait(BaseEvent* ev); /**
/** * Checks whether any experiment flow has events in the event-list.
* Checks whether any experiment flow has events in the event-list. * @return \c true if there are still events, or \c false otherwise
* @return \c true if there are still events, or \c false otherwise */
*/ bool hasEvents() const { return getEventCount() > 0; }
bool hasEvents() const { return getEventCount() > 0; } /**
/** * Determines the number of (stored) events in the event-list which have
* Determines the number of (stored) events in the event-list which have * not been triggered so far.
* not been triggered so far. * @return the actual number of events
* @return the actual number of events */
*/ unsigned getEventCount() const { return m_EvList.getEventCount(); }
unsigned getEventCount() const { return m_EvList.getEventCount(); }
}; };
} // end-of-namespace: fail } // end-of-namespace: fail