1 | @ifinfo |
---|
2 | @node Interrupt Processing, Interrupt Processing Introduction, Memory Model Flat Memory Model, Top |
---|
3 | @end ifinfo |
---|
4 | @chapter Interrupt Processing |
---|
5 | @ifinfo |
---|
6 | @menu |
---|
7 | * Interrupt Processing Introduction:: |
---|
8 | * Interrupt Processing Vectoring of Interrupt Handler:: |
---|
9 | * Interrupt Processing Interrupt Stack Frame:: |
---|
10 | * Interrupt Processing Interrupt Levels:: |
---|
11 | * Interrupt Processing Disabling of Interrupts by RTEMS:: |
---|
12 | * Interrupt Processing Interrupt Stack:: |
---|
13 | @end menu |
---|
14 | @end ifinfo |
---|
15 | |
---|
16 | @ifinfo |
---|
17 | @node Interrupt Processing Introduction, Interrupt Processing Vectoring of Interrupt Handler, Interrupt Processing, Interrupt Processing |
---|
18 | @end ifinfo |
---|
19 | @section Introduction |
---|
20 | |
---|
21 | Different types of processors respond to the |
---|
22 | occurrence of an interrupt in their own unique fashion. In |
---|
23 | addition, each processor type provides a control mechanism to |
---|
24 | allow the proper handling of an interrupt. The processor |
---|
25 | dependent response to the interrupt modifies the execution state |
---|
26 | and results in the modification of the execution stream. This |
---|
27 | modification usually requires that an interrupt handler utilize |
---|
28 | the provided control mechanisms to return to the normal |
---|
29 | processing stream. Although RTEMS hides many of the processor |
---|
30 | dependent details of interrupt processing, it is important to |
---|
31 | understand how the RTEMS interrupt manager is mapped onto the |
---|
32 | processor's unique architecture. Discussed in this chapter are |
---|
33 | the the processor's response and control mechanisms as they |
---|
34 | pertain to RTEMS. |
---|
35 | |
---|
36 | @ifinfo |
---|
37 | @node Interrupt Processing Vectoring of Interrupt Handler, Interrupt Processing Interrupt Stack Frame, Interrupt Processing Introduction, Interrupt Processing |
---|
38 | @end ifinfo |
---|
39 | @section Vectoring of Interrupt Handler |
---|
40 | |
---|
41 | Although the i386 supports multiple privilege levels, |
---|
42 | RTEMS and all user software executes at privilege level 0. This |
---|
43 | decision was made by the RTEMS designers to enhance |
---|
44 | compatibility with processors which do not provide sophisticated |
---|
45 | protection facilities like those of the i386. This decision |
---|
46 | greatly simplifies the discussion of i386 processing, as one |
---|
47 | need only consider interrupts without privilege transitions. |
---|
48 | |
---|
49 | Upon receipt of an interrupt the i386 automatically |
---|
50 | performs the following actions: |
---|
51 | |
---|
52 | @itemize @bullet |
---|
53 | @item pushes the EFLAGS register |
---|
54 | |
---|
55 | @item pushes the far address of the interrupted instruction |
---|
56 | |
---|
57 | @item vectors to the interrupt service routine (ISR). |
---|
58 | @end itemize |
---|
59 | |
---|
60 | A nested interrupt is processed similarly by the |
---|
61 | i386. |
---|
62 | |
---|
63 | @ifinfo |
---|
64 | @node Interrupt Processing Interrupt Stack Frame, Interrupt Processing Interrupt Levels, Interrupt Processing Vectoring of Interrupt Handler, Interrupt Processing |
---|
65 | @end ifinfo |
---|
66 | @section Interrupt Stack Frame |
---|
67 | |
---|
68 | The structure of the Interrupt Stack Frame for the |
---|
69 | i386 which is placed on the interrupt stack by the processor in |
---|
70 | response to an interrupt is as follows: |
---|
71 | |
---|
72 | @ifset use-ascii |
---|
73 | @example |
---|
74 | @group |
---|
75 | +----------------------+ |
---|
76 | | Old EFLAGS Register | ESP+8 |
---|
77 | +----------+-----------+ |
---|
78 | | UNUSED | Old CS | ESP+4 |
---|
79 | +----------+-----------+ |
---|
80 | | Old EIP | ESP |
---|
81 | +----------------------+ |
---|
82 | @end group |
---|
83 | @end example |
---|
84 | @end ifset |
---|
85 | |
---|
86 | @ifset use-tex |
---|
87 | @sp 1 |
---|
88 | @tex |
---|
89 | \centerline{\vbox{\offinterlineskip\halign{ |
---|
90 | \strut\vrule#& |
---|
91 | \hbox to 1.00in{\enskip\hfil#\hfil}& |
---|
92 | \vrule#& |
---|
93 | \hbox to 1.00in{\enskip\hfil#\hfil}& |
---|
94 | \vrule#& |
---|
95 | \hbox to 0.75in{\enskip\hfil#\hfil} |
---|
96 | \cr |
---|
97 | \multispan{4}\hrulefill\cr |
---|
98 | & \multispan{3} Old EFLAGS Register\quad&&ESP+8\cr |
---|
99 | \multispan{4}\hrulefill\cr |
---|
100 | &UNUSED &&Old CS &&ESP+4\cr |
---|
101 | \multispan{4}\hrulefill\cr |
---|
102 | & \multispan{3} Old EIP && ESP\cr |
---|
103 | \multispan{4}\hrulefill\cr |
---|
104 | }}\hfil} |
---|
105 | @end tex |
---|
106 | @end ifset |
---|
107 | |
---|
108 | @ifset use-html |
---|
109 | @html |
---|
110 | <CENTER> |
---|
111 | <TABLE COLS=3 WIDTH="40%" BORDER=2> |
---|
112 | <TR><TD ALIGN=center COLSPAN=2><STRONG>Old EFLAGS Register</STRONG></TD> |
---|
113 | <TD ALIGN=center>0x0</TD></TR> |
---|
114 | <TR><TD ALIGN=center><STRONG>UNUSED</STRONG></TD> |
---|
115 | <TD ALIGN=center><STRONG>Old CS</STRONG></TD> |
---|
116 | <TD ALIGN=center>0x2</TD></TR> |
---|
117 | <TR><TD ALIGN=center COLSPAN=2><STRONG>Old EIP</STRONG></TD> |
---|
118 | <TD ALIGN=center>0x4</TD></TR> |
---|
119 | </TABLE> |
---|
120 | </CENTER> |
---|
121 | @end html |
---|
122 | @end ifset |
---|
123 | |
---|
124 | @ifinfo |
---|
125 | @node Interrupt Processing Interrupt Levels, Interrupt Processing Disabling of Interrupts by RTEMS, Interrupt Processing Interrupt Stack Frame, Interrupt Processing |
---|
126 | @end ifinfo |
---|
127 | @section Interrupt Levels |
---|
128 | |
---|
129 | Although RTEMS supports 256 interrupt levels, the |
---|
130 | i386 only supports two -- enabled and disabled. Interrupts are |
---|
131 | enabled when the interrupt-enable flag (IF) in the extended |
---|
132 | flags (EFLAGS) is set. Conversely, interrupt processing is |
---|
133 | inhibited when the IF is cleared. During a non-maskable |
---|
134 | interrupt, all other interrupts, including other non-maskable |
---|
135 | ones, are inhibited. |
---|
136 | |
---|
137 | RTEMS interrupt levels 0 and 1 such that level zero |
---|
138 | (0) indicates that interrupts are fully enabled and level one |
---|
139 | that interrupts are disabled. All other RTEMS interrupt levels |
---|
140 | are undefined and their behavior is unpredictable. |
---|
141 | |
---|
142 | @ifinfo |
---|
143 | @node Interrupt Processing Disabling of Interrupts by RTEMS, Interrupt Processing Interrupt Stack, Interrupt Processing Interrupt Levels, Interrupt Processing |
---|
144 | @end ifinfo |
---|
145 | @section Disabling of Interrupts by RTEMS |
---|
146 | |
---|
147 | During the execution of directive calls, critical |
---|
148 | sections of code may be executed. When these sections are |
---|
149 | encountered, RTEMS disables interrupts before the execution of |
---|
150 | this section and restores them to the previous level upon |
---|
151 | completion of the section. RTEMS has been optimized to insure |
---|
152 | that interrupts are disabled for less than RTEMS_MAXIMUM_DISABLE_PERIOD |
---|
153 | microseconds on a RTEMS_MAXIMUM_DISABLE_PERIOD_MHZ Mhz i386 with zero |
---|
154 | wait states. These numbers will vary based the number of wait states |
---|
155 | and processor speed present on the target board. [NOTE: The maximum |
---|
156 | period with interrupts disabled within RTEMS was last calculated for |
---|
157 | Release RTEMS_RELEASE_FOR_MAXIMUM_DISABLE_PERIOD.] |
---|
158 | |
---|
159 | Non-maskable interrupts (NMI) cannot be disabled, and |
---|
160 | ISRs which execute at this level MUST NEVER issue RTEMS system |
---|
161 | calls. If a directive is invoked, unpredictable results may |
---|
162 | occur due to the inability of RTEMS to protect its critical |
---|
163 | sections. However, ISRs that make no system calls may safely |
---|
164 | execute as non-maskable interrupts. |
---|
165 | |
---|
166 | @ifinfo |
---|
167 | @node Interrupt Processing Interrupt Stack, Default Fatal Error Processing, Interrupt Processing Disabling of Interrupts by RTEMS, Interrupt Processing |
---|
168 | @end ifinfo |
---|
169 | @section Interrupt Stack |
---|
170 | |
---|
171 | The i386 family does not support a dedicated hardware |
---|
172 | interrupt stack. On this processor, RTEMS allocates and manages |
---|
173 | a dedicated interrupt stack. As part of vectoring a non-nested |
---|
174 | interrupt service routine, RTEMS switches from the stack of the |
---|
175 | interrupted task to a dedicated interrupt stack. When a |
---|
176 | non-nested interrupt returns, RTEMS switches back to the stack |
---|
177 | of the interrupted stack. The current stack pointer is not |
---|
178 | altered by RTEMS on nested interrupt. |
---|
179 | |
---|
180 | Without a dedicated interrupt stack, every task in |
---|
181 | the system MUST have enough stack space to accommodate the worst |
---|
182 | case stack usage of that particular task and the interrupt |
---|
183 | service routines COMBINED. By supporting a dedicated interrupt |
---|
184 | stack, RTEMS significantly lowers the stack requirements for |
---|
185 | each task. |
---|
186 | |
---|
187 | RTEMS allocates the dedicated interrupt stack from |
---|
188 | the Workspace Area. The amount of memory allocated for the |
---|
189 | interrupt stack is determined by the interrupt_stack_size field |
---|
190 | in the CPU Configuration Table. |
---|
191 | |
---|