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:47 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 its own unique fashion. In
|
15 |
|
|
addition, each processor type provides a control mechanism to
|
16 |
|
|
allow for the proper handling of an interrupt. The processor
|
17 |
|
|
dependent response to the interrupt modifies the current
|
18 |
|
|
execution state and results in a change in the execution stream.
|
19 |
|
|
Most processors require that an interrupt handler utilize some
|
20 |
|
|
special control mechanisms to return to the normal processing
|
21 |
|
|
stream. Although RTEMS hides many of the processor dependent
|
22 |
|
|
details of interrupt processing, it is important to understand
|
23 |
|
|
how the RTEMS interrupt manager is mapped onto the processor's
|
24 |
|
|
unique architecture. Discussed in this chapter are the SPARC's
|
25 |
|
|
interrupt response and control mechanisms as they pertain to
|
26 |
|
|
RTEMS.
|
27 |
|
|
|
28 |
|
|
RTEMS and associated documentation uses the terms
|
29 |
|
|
interrupt and vector. In the SPARC architecture, these terms
|
30 |
|
|
correspond to traps and trap type, respectively. The terms will
|
31 |
|
|
be used interchangeably in this manual.
|
32 |
|
|
|
33 |
|
|
@section Synchronous Versus Asynchronous Traps
|
34 |
|
|
|
35 |
|
|
The SPARC architecture includes two classes of traps:
|
36 |
|
|
synchronous and asynchronous. Asynchronous traps occur when an
|
37 |
|
|
external event interrupts the processor. These traps are not
|
38 |
|
|
associated with any instruction executed by the processor and
|
39 |
|
|
logically occur between instructions. The instruction currently
|
40 |
|
|
in the execute stage of the processor is allowed to complete
|
41 |
|
|
although subsequent instructions are annulled. The return
|
42 |
|
|
address reported by the processor for asynchronous traps is the
|
43 |
|
|
pair of instructions following the current instruction.
|
44 |
|
|
|
45 |
|
|
Synchronous traps are caused by the actions of an
|
46 |
|
|
instruction. The trap stimulus in this case either occurs
|
47 |
|
|
internally to the processor or is from an external signal that
|
48 |
|
|
was provoked by the instruction. These traps are taken
|
49 |
|
|
immediately and the instruction that caused the trap is aborted
|
50 |
|
|
before any state changes occur in the processor itself. The
|
51 |
|
|
return address reported by the processor for synchronous traps
|
52 |
|
|
is the instruction which caused the trap and the following
|
53 |
|
|
instruction.
|
54 |
|
|
|
55 |
|
|
@section Vectoring of Interrupt Handler
|
56 |
|
|
|
57 |
|
|
Upon receipt of an interrupt the SPARC automatically
|
58 |
|
|
performs the following actions:
|
59 |
|
|
|
60 |
|
|
@itemize @bullet
|
61 |
|
|
@item disables traps (sets the ET bit of the psr to 0),
|
62 |
|
|
|
63 |
|
|
@item the S bit of the psr is copied into the Previous
|
64 |
|
|
Supervisor Mode (PS) bit of the psr,
|
65 |
|
|
|
66 |
|
|
@item the cwp is decremented by one (modulo the number of
|
67 |
|
|
register windows) to activate a trap window,
|
68 |
|
|
|
69 |
|
|
@item the PC and nPC are loaded into local register 1 and 2
|
70 |
|
|
(l0 and l1),
|
71 |
|
|
|
72 |
|
|
@item the trap type (tt) field of the Trap Base Register (TBR)
|
73 |
|
|
is set to the appropriate value, and
|
74 |
|
|
|
75 |
|
|
@item if the trap is not a reset, then the PC is written with
|
76 |
|
|
the contents of the TBR and the nPC is written with TBR + 4. If
|
77 |
|
|
the trap is a reset, then the PC is set to zero and the nPC is
|
78 |
|
|
set to 4.
|
79 |
|
|
@end itemize
|
80 |
|
|
|
81 |
|
|
Trap processing on the SPARC has two features which
|
82 |
|
|
are noticeably different than interrupt processing on other
|
83 |
|
|
architectures. First, the value of psr register in effect
|
84 |
|
|
immediately before the trap occurred is not explicitly saved.
|
85 |
|
|
Instead only reversible alterations are made to it. Second, the
|
86 |
|
|
Processor Interrupt Level (pil) is not set to correspond to that
|
87 |
|
|
of the interrupt being processed. When a trap occurs, ALL
|
88 |
|
|
subsequent traps are disabled. In order to safely invoke a
|
89 |
|
|
subroutine during trap handling, traps must be enabled to allow
|
90 |
|
|
for the possibility of register window overflow and underflow
|
91 |
|
|
traps.
|
92 |
|
|
|
93 |
|
|
If the interrupt handler was installed as an RTEMS
|
94 |
|
|
interrupt handler, then upon receipt of the interrupt, the
|
95 |
|
|
processor passes control to the RTEMS interrupt handler which
|
96 |
|
|
performs the following actions:
|
97 |
|
|
|
98 |
|
|
@itemize @bullet
|
99 |
|
|
@item saves the state of the interrupted task on it's stack,
|
100 |
|
|
|
101 |
|
|
@item insures that a register window is available for
|
102 |
|
|
subsequent traps,
|
103 |
|
|
|
104 |
|
|
@item if this is the outermost (i.e. non-nested) interrupt,
|
105 |
|
|
then the RTEMS interrupt handler switches from the current stack
|
106 |
|
|
to the interrupt stack,
|
107 |
|
|
|
108 |
|
|
@item enables traps,
|
109 |
|
|
|
110 |
|
|
@item invokes the vectors to a user interrupt service routine (ISR).
|
111 |
|
|
@end itemize
|
112 |
|
|
|
113 |
|
|
Asynchronous interrupts are ignored while traps are
|
114 |
|
|
disabled. Synchronous traps which occur while traps are
|
115 |
|
|
disabled result in the CPU being forced into an error mode.
|
116 |
|
|
|
117 |
|
|
A nested interrupt is processed similarly with the
|
118 |
|
|
exception that the current stack need not be switched to the
|
119 |
|
|
interrupt stack.
|
120 |
|
|
|
121 |
|
|
@section Traps and Register Windows
|
122 |
|
|
|
123 |
|
|
One of the register windows must be reserved at all
|
124 |
|
|
times for trap processing. This is critical to the proper
|
125 |
|
|
operation of the trap mechanism in the SPARC architecture. It
|
126 |
|
|
is the responsibility of the trap handler to insure that there
|
127 |
|
|
is a register window available for a subsequent trap before
|
128 |
|
|
re-enabling traps. It is likely that any high level language
|
129 |
|
|
routines invoked by the trap handler (such as a user-provided
|
130 |
|
|
RTEMS interrupt handler) will allocate a new register window.
|
131 |
|
|
The save operation could result in a window overflow trap. This
|
132 |
|
|
trap cannot be correctly processed unless (1) traps are enabled
|
133 |
|
|
and (2) a register window is reserved for traps. Thus, the
|
134 |
|
|
RTEMS interrupt handler insures that a register window is
|
135 |
|
|
available for subsequent traps before enabling traps and
|
136 |
|
|
invoking the user's interrupt handler.
|
137 |
|
|
|
138 |
|
|
@section Interrupt Levels
|
139 |
|
|
|
140 |
|
|
Sixteen levels (0-15) of interrupt priorities are
|
141 |
|
|
supported by the SPARC architecture with level fifteen (15)
|
142 |
|
|
being the highest priority. Level zero (0) indicates that
|
143 |
|
|
interrupts are fully enabled. Interrupt requests for interrupts
|
144 |
|
|
with priorities less than or equal to the current interrupt mask
|
145 |
|
|
level are ignored.
|
146 |
|
|
|
147 |
|
|
Although RTEMS supports 256 interrupt levels, the
|
148 |
|
|
SPARC only supports sixteen. RTEMS interrupt levels 0 through
|
149 |
|
|
15 directly correspond to SPARC processor interrupt levels. All
|
150 |
|
|
other RTEMS interrupt levels are undefined and their behavior is
|
151 |
|
|
unpredictable.
|
152 |
|
|
|
153 |
|
|
@section Disabling of Interrupts by RTEMS
|
154 |
|
|
|
155 |
|
|
During the execution of directive calls, critical
|
156 |
|
|
sections of code may be executed. When these sections are
|
157 |
|
|
encountered, RTEMS disables interrupts to level seven (15)
|
158 |
|
|
before the execution of this section and restores them to the
|
159 |
|
|
previous level upon completion of the section. RTEMS has been
|
160 |
|
|
optimized to insure that interrupts are disabled for less than
|
161 |
|
|
RTEMS_MAXIMUM_DISABLE_PERIOD microseconds on a RTEMS_MAXIMUM_DISABLE_PERIOD_MHZ
|
162 |
|
|
Mhz ERC32 with zero wait states.
|
163 |
|
|
These numbers will vary based the number of wait states and
|
164 |
|
|
processor speed present on the target board.
|
165 |
|
|
[NOTE: The maximum period with interrupts disabled is hand calculated. This
|
166 |
|
|
calculation was last performed for Release
|
167 |
|
|
RTEMS_RELEASE_FOR_MAXIMUM_DISABLE_PERIOD.]
|
168 |
|
|
|
169 |
|
|
[NOTE: It is thought that the length of time at which
|
170 |
|
|
the processor interrupt level is elevated to fifteen by RTEMS is
|
171 |
|
|
not anywhere near as long as the length of time ALL traps are
|
172 |
|
|
disabled as part of the "flush all register windows" operation.]
|
173 |
|
|
|
174 |
|
|
Non-maskable interrupts (NMI) cannot be disabled, and
|
175 |
|
|
ISRs which execute at this level MUST NEVER issue RTEMS system
|
176 |
|
|
calls. If a directive is invoked, unpredictable results may
|
177 |
|
|
occur due to the inability of RTEMS to protect its critical
|
178 |
|
|
sections. However, ISRs that make no system calls may safely
|
179 |
|
|
execute as non-maskable interrupts.
|
180 |
|
|
|
181 |
|
|
@section Interrupt Stack
|
182 |
|
|
|
183 |
|
|
The SPARC architecture does not provide for a
|
184 |
|
|
dedicated interrupt stack. Thus by default, trap handlers would
|
185 |
|
|
execute on the stack of the RTEMS task which they interrupted.
|
186 |
|
|
This artificially inflates the stack requirements for each task
|
187 |
|
|
since EVERY task stack would have to include enough space to
|
188 |
|
|
account for the worst case interrupt stack requirements in
|
189 |
|
|
addition to it's own worst case usage. RTEMS addresses this
|
190 |
|
|
problem on the SPARC by providing a dedicated interrupt stack
|
191 |
|
|
managed by software.
|
192 |
|
|
|
193 |
|
|
During system initialization, RTEMS allocates the
|
194 |
|
|
interrupt stack from the Workspace Area. The amount of memory
|
195 |
|
|
allocated for the interrupt stack is determined by the
|
196 |
|
|
interrupt_stack_size field in the CPU Configuration Table. As
|
197 |
|
|
part of processing a non-nested interrupt, RTEMS will switch to
|
198 |
|
|
the interrupt stack before invoking the installed handler.
|
199 |
|
|
|