Main Page   Class Hierarchy   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-1996 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 #include "callback.h"
00041 
00043 enum IntStatus { IntOff, IntOn };
00044 
00048 enum MachineStatus {IdleMode, SystemMode, UserMode};
00049 
00053 enum IntType { TimerInt, DiskInt, ConsoleWriteInt, ConsoleReadInt, 
00054                         ElevatorInt, NetworkSendInt, NetworkRecvInt};
00055 
00059 
00060 class PendingInterrupt {
00061   public:
00062     PendingInterrupt(CallBackObj *callOnInt, int time, IntType kind);
00065 
00066     CallBackObj *callOnInterrupt;
00067 
00068     
00069     int when;                   
00070     IntType type;               
00071 };
00072 
00077 
00078 class Interrupt {
00079   public:
00080     Interrupt();                
00081     ~Interrupt();               
00082     
00083     IntStatus SetLevel(IntStatus level);
00086 
00087     void Enable() { (void) SetLevel(IntOn); }
00089     IntStatus getLevel() {return level;}
00092     
00093     void Idle();                
00094 
00095 
00096 
00097     void Halt();                
00098     
00099     void YieldOnReturn();       
00100 
00101 
00102     MachineStatus getStatus() { return status; } 
00103     void setStatus(MachineStatus st) { status = st; }
00105 
00106     bool AnyFutureInterrupts() { return !pending->IsEmpty(); }
00108 
00109     void DumpState();           
00110     
00111 
00112     // NOTE: the following are internal to the hardware simulation code.
00113     // DO NOT call these directly.  I should make them "private",
00114     // but they need to be public since they are called by the
00115     // hardware device simulators.
00116 
00117     void Schedule(CallBackObj *callTo, int when, IntType type);
00121     
00122     void OneTick();             //"< Advance simulated time
00123 
00124   private:
00125     IntStatus level;            
00126     SortedList<PendingInterrupt *> *pending;            
00129     bool inHandler;             
00130     bool yieldOnReturn;         
00131 
00132     MachineStatus status;       
00133 
00134     // these functions are internal to the interrupt simulation code
00135 
00136     bool CheckIfDue(bool advanceClock); 
00139 
00140     void ChangeLevel(IntStatus old,     
00141                         IntStatus now); 
00144 };
00145 
00146 #endif 

Generated at Wed Jul 4 11:32:21 2001 for Nachos by doxygen1.2.8.1 written by Dimitri van Heesch, © 1997-2001