[ RCOS.java Home | RCOS Home | David's Home ]

Interrupt CRC

Name:

Interrupt

Comment:

The following class defines the data structures for the simulation of hardware interrupts. We record whether interrupts are enabled or disabled, and any hardware interrupts that are scheduled to occur in the future.

Collaborators:

Responsibilities:

class Interrupt {
  public:
    Interrupt();                        // initialize the interrupt simulation
    ~Interrupt();                       // de-allocate data structures

    IntStatus SetLevel(IntStatus level);// Disable or enable interrupts
                                        // and return previous setting.

    void Enable();                      // Enable interrupts.
    IntStatus getLevel() {return level;}// Return whether interrupts
                                        // are enabled or disabled

    void Idle();                        // The ready queue is empty, roll
                                        // simulated time forward until the
                                        // next interrupt

    void Halt();                        // quit and print out stats

    void YieldOnReturn();               // cause a context switch on return
                                        // from an interrupt handler

    MachineStatus getStatus() { return status; } // idle, kernel, user
    void setStatus(MachineStatus st) { status = st; }

    void DumpState();                   // Print interrupt state


    // NOTE: the following are internal to the hardware simulation code.
    // DO NOT call these directly.  I should make them "private",
    // but they need to be public since they are called by the
    // hardware device simulators.

    void Schedule(VoidFunctionPtr handler,// Schedule an interrupt to occur
        int arg, int when, IntType type);// at time ``when''.  This is called
                                        // by the hardware device simulators.

    void OneTick();                     // Advance simulated time

  private:
    IntStatus level;            // are interrupts enabled or disabled?
    List *pending;              // the list of interrupts scheduled
                                // to occur in the future
    bool inHandler;             // TRUE if we are running an interrupt handler
    bool yieldOnReturn;         // TRUE if we are to context switch
                                // on return from the interrupt handler
    MachineStatus status;       // idle, kernel mode, user mode

    // these functions are internal to the interrupt simulation code

    bool CheckIfDue(bool advanceClock); // Check if an interrupt is supposed   
                                        // to occur now

    void ChangeLevel(IntStatus old,     // SetLevel, without advancing the
        IntStatus now);                 // simulated time
};