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