Main Page   Compound List   File List   Compound Members   File Members  

interrupt.h

Go to the documentation of this file.
00001 // interrupt.h 
00002 //      Data structures to emulate low-level interrupt hardware.
00003 //
00004 //      The hardware provides a routine (SetLevel) to enable or disable
00005 //      interrupts.
00006 //
00007 //      In order to emulate the hardware, we need to keep track of all
00008 //      interrupts the hardware devices would cause, and when they
00009 //      are supposed to occur.  
00010 //
00011 //      This module also keeps track of simulated time.  Time advances
00012 //      only when the following occur: 
00013 //              interrupts are re-enabled
00014 //              a user instruction is executed
00015 //              there is nothing in the ready queue
00016 //
00017 //      As a result, unlike real hardware, interrupts (and thus time-slice 
00018 //      context switches) cannot occur anywhere in the code where interrupts
00019 //      are enabled, but rather only at those places in the code where 
00020 //      simulated time advances (so that it becomes time to invoke an
00021 //      interrupt in the hardware simulation).
00022 //
00023 //      NOTE: this means that incorrectly synchronized code may work
00024 //      fine on this hardware simulation (even with randomized time slices),
00025 //      but it wouldn't work on real hardware.  (Just because we can't
00026 //      always detect when your program would fail in real life, does not 
00027 //      mean it's ok to write incorrectly synchronized code!)
00028 //
00029 //  DO NOT CHANGE -- part of the machine emulation
00030 //
00031 // Copyright (c) 1992-1993 The Regents of the University of California.
00032 // All rights reserved.  See copyright.h for copyright notice and limitation 
00033 // of liability and disclaimer of warranty provisions.
00034 
00035 #ifndef INTERRUPT_H
00036 #define INTERRUPT_H
00037 
00038 #include "copyright.h"
00039 #include "list.h"
00040 
00041 // Interrupts can be disabled (IntOff) or enabled (IntOn)
00042 enum IntStatus { IntOff, IntOn };
00043 
00044 // Nachos can be running kernel code (SystemMode), user code (UserMode),
00045 // or there can be no runnable thread, because the ready list 
00046 // is empty (IdleMode).
00047 enum MachineStatus {IdleMode, SystemMode, UserMode};
00048 
00049 // IntType records which hardware device generated an interrupt.
00050 // In Nachos, we support a hardware timer device, a disk, a console
00051 // display and keyboard, and a network.
00052 enum IntType { TimerInt, DiskInt, ConsoleWriteInt, ConsoleReadInt, 
00053                                 NetworkSendInt, NetworkRecvInt};
00054 
00055 // The following class defines an interrupt that is scheduled
00056 // to occur in the future.  The internal data structures are
00057 // left public to make it simpler to manipulate.
00058 
00059 class PendingInterrupt {
00060   public:
00061     PendingInterrupt(VoidFunctionPtr func, int param, int time, IntType kind);
00062                                 // initialize an interrupt that will
00063                                 // occur in the future
00064 
00065     VoidFunctionPtr handler;    // The function (in the hardware device
00066                                 // emulator) to call when the interrupt occurs
00067     int arg;                    // The argument to the function.
00068     int when;                   // When the interrupt is supposed to fire
00069     IntType type;               // for debugging
00070 };
00071 
00072 // The following class defines the data structures for the simulation
00073 // of hardware interrupts.  We record whether interrupts are enabled
00074 // or disabled, and any hardware interrupts that are scheduled to occur
00075 // in the future.
00076 
00077 class Interrupt {
00078   public:
00079     Interrupt();                        // initialize the interrupt simulation
00080     ~Interrupt();                       // de-allocate data structures
00081     
00082     IntStatus SetLevel(IntStatus level);// Disable or enable interrupts 
00083                                         // and return previous setting.
00084 
00085     void Enable();                      // Enable interrupts.
00086     IntStatus getLevel() {return level;}// Return whether interrupts
00087                                         // are enabled or disabled
00088     
00089     void Idle();                        // The ready queue is empty, roll 
00090                                         // simulated time forward until the 
00091                                         // next interrupt
00092 
00093     void Halt();                        // quit and print out stats
00094     
00095     void YieldOnReturn();               // cause a context switch on return 
00096                                         // from an interrupt handler
00097 
00098     MachineStatus getStatus() { return status; } // idle, kernel, user
00099     void setStatus(MachineStatus st) { status = st; }
00100 
00101     void DumpState();                   // Print interrupt state
00102     
00103 
00104     // NOTE: the following are internal to the hardware simulation code.
00105     // DO NOT call these directly.  I should make them "private",
00106     // but they need to be public since they are called by the
00107     // hardware device simulators.
00108 
00109     void Schedule(VoidFunctionPtr handler,// Schedule an interrupt to occur
00110         int arg, int when, IntType type);// at time ``when''.  This is called
00111                                         // by the hardware device simulators.
00112     
00113     void OneTick();                     // Advance simulated time
00114 
00115   private:
00116     IntStatus level;            // are interrupts enabled or disabled?
00117     List *pending;              // the list of interrupts scheduled
00118                                 // to occur in the future
00119     bool inHandler;             // TRUE if we are running an interrupt handler
00120     bool yieldOnReturn;         // TRUE if we are to context switch
00121                                 // on return from the interrupt handler
00122     MachineStatus status;       // idle, kernel mode, user mode
00123 
00124     // these functions are internal to the interrupt simulation code
00125 
00126     bool CheckIfDue(bool advanceClock); // Check if an interrupt is supposed
00127                                         // to occur now
00128 
00129     void ChangeLevel(IntStatus old,     // SetLevel, without advancing the
00130         IntStatus now);                 // simulated time
00131 };
00132 
00133 #endif // INTERRRUPT_H

Generated on Mon Feb 10 09:54:45 2003 for nachos by doxygen1.2.14 written by Dimitri van Heesch, © 1997-2002
The University of Southern California does not screen or control the content on this website and thus does not guarantee the accuracy, integrity, or quality of such content. All content on this website is provided by and is the sole responsibility of the person from which such content originated, and such content does not necessarily reflect the opinions of the University administration or the Board of Trustees