00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
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
00113
00114
00115
00116
00117 void Schedule(CallBackObj *callTo, int when, IntType type);
00121
00122 void OneTick();
00123
00124 private:
00125 IntStatus level;
00126 SortedList<PendingInterrupt *> *pending;
00129 bool inHandler;
00130 bool yieldOnReturn;
00131
00132 MachineStatus status;
00133
00134
00135
00136 bool CheckIfDue(bool advanceClock);
00139
00140 void ChangeLevel(IntStatus old,
00141 IntStatus now);
00144 };
00145
00146 #endif