tac0S
Template Affectional Command Operating System
interrupt.h
Go to the documentation of this file.
1 
35 #ifndef INTERRUPT_H
36 #define INTERRUPT_H
37 
38 #include "copyright.h"
39 #include "list.h"
40 
42 enum IntStatus { IntOff, IntOn };
43 
47 enum MachineStatus {IdleMode, SystemMode, UserMode};
48 
52 enum IntType { TimerInt, DiskInt, ConsoleWriteInt, ConsoleReadInt,
53  NetworkSendInt, NetworkRecvInt};
54 
58 
60  public:
61  PendingInterrupt(VoidFunctionPtr func, int param,
62  long long time, IntType kind);
63  // initialize an interrupt that will
64  // occur in the future
65 
66  VoidFunctionPtr handler; // The function (in the hardware device
67  // emulator) to call when the interrupt occurs
68  int arg; // The argument to the function.
69  long long when; // When the interrupt is supposed to fire
70  IntType type; // for debugging
71 };
72 
73 // The following class defines the data structures for the simulation
74 // of hardware interrupts. We record whether interrupts are enabled
75 // or disabled, and any hardware interrupts that are scheduled to occur
76 // in the future.
77 
78 class Interrupt {
79  public:
80  Interrupt(); // initialize the interrupt simulation
81  ~Interrupt(); // de-allocate data structures
82 
83  IntStatus SetLevel(IntStatus level);// Disable or enable interrupts
84  // and return previous setting.
85 
86  void Enable(); // Enable interrupts.
87  IntStatus getLevel() {return level;}// Return whether interrupts
88  // are enabled or disabled
89 
90  void Idle(); // The ready queue is empty, roll
91  // simulated time forward until the
92  // next interrupt
93 
94  void Halt(); // quit and print out stats
95 
96  void YieldOnReturn(); // cause a context switch on return
97  // from an interrupt handler
98 
99  MachineStatus getStatus() { return status; } // idle, kernel, user
100  void setStatus(MachineStatus st) { status = st; }
101 
102  void DumpState(); // Print interrupt state
103 
104 
105  // NOTE: the following are internal to the hardware simulation code.
106  // DO NOT call these directly. I should make them "private",
107  // but they need to be public since they are called by the
108  // hardware device simulators.
109 
110  void Schedule(VoidFunctionPtr handler,// Schedule an interrupt to occur
111  int arg, long long when, IntType type);// at time ``when''. This is called
112  // by the hardware device simulators.
113 
114  void OneTick(); // Advance simulated time
115 
116  private:
117  IntStatus level; // are interrupts enabled or disabled?
118  List *pending; // the list of interrupts scheduled
119  // to occur in the future
120  bool inHandler; // TRUE if we are running an interrupt handler
121  bool yieldOnReturn; // TRUE if we are to context switch
122  // on return from the interrupt handler
123  MachineStatus status; // idle, kernel mode, user mode
124 
125  // these functions are internal to the interrupt simulation code
126 
127  bool CheckIfDue(bool advanceClock); // Check if an interrupt is supposed
128  // to occur now
129 
130  void ChangeLevel(IntStatus old, // SetLevel, without advancing the
131  IntStatus now); // simulated time
132 };
133 
134 #endif // INTERRRUPT_H
Definition: interrupt.h:78
The following class defines an interrupt that is scheduled to occur in the future. The internal data structures are left public to make it simpler to manipulate.
Definition: interrupt.h:59
Definition: list.h:46
IntType
IntType records which hardware device generated an interrupt. In Nachos, we support a hardware timer ...
Definition: interrupt.h:52
Routines to manage a singly-linked list of "things". Defining TRUE and FALSE is usually a Bad Idea...
IntStatus
Interrupts can be disabled (IntOff) or enabled (IntOn)
Definition: interrupt.h:42
MachineStatus
Nachos can be running kernel code (SystemMode), user code (UserMode), or there can be no runnable thr...
Definition: interrupt.h:47
PendingInterrupt(VoidFunctionPtr func, int param, long long time, IntType kind)
PendingInterrupt::PendingInterrupt Initialize a hardware device interrupt that is to be scheduled to ...
Definition: interrupt.cc:45