1 <!-- Copyright (C) 2003 Red Hat, Inc. -->
2 <!-- This material may be distributed only subject to the terms -->
3 <!-- and conditions set forth in the Open Publication License, v1.0 -->
4 <!-- or later (the latest version is presently available at -->
5 <!-- http://www.opencontent.org/openpub/). -->
6 <!-- Distribution of the work or derivative of the work in any -->
7 <!-- standard (paper) book form is prohibited unless prior -->
8 <!-- permission is obtained from the copyright holder. -->
12 >Exception Handling</TITLE
13 ><meta name="MSSmartTagsPreventParsing" content="TRUE">
16 CONTENT="Modular DocBook HTML Stylesheet Version 1.76b+
19 TITLE="eCos Reference Manual"
20 HREF="ecos-ref.html"><LINK
22 TITLE="The eCos Hardware Abstraction Layer (HAL)"
23 HREF="the-ecos-hardware-abstraction-layer.html"><LINK
26 HREF="hal-smp-support.html"><LINK
28 TITLE="Vectors and VSRs"
29 HREF="hal-vectors-and-vsrs.html"></HEAD
40 SUMMARY="Header navigation table"
49 >eCos Reference Manual</TH
57 HREF="hal-smp-support.html"
71 HREF="hal-vectors-and-vsrs.html"
84 NAME="HAL-EXCEPTION-HANDLING">Chapter 10. Exception Handling</H1
94 HREF="hal-exception-handling.html#HAL-STARTUP"
99 HREF="hal-vectors-and-vsrs.html"
104 HREF="hal-default-synchronous-exception-handling.html"
105 >Default Synchronous Exception Handling</A
109 HREF="hal-default-interrupt-handling.html"
110 >Default Interrupt Handling</A
115 >Most of the HAL consists of simple macros or functions that are
116 called via the interfaces described in the previous section. These
117 just perform whatever operation is required by accessing the hardware
118 and then return. The exception to this is the handling of exceptions:
119 either synchronous hardware traps or asynchronous device
120 interrupts. Here control is passed first to the HAL, which then passed
121 it on to eCos or the application. After eCos has finished with it,
122 control is then passed back to the HAL for it to tidy up the CPU state
123 and resume processing from the point at which the exception occurred.</P
125 >The HAL exceptions handling code is usually found in the file
129 > in the architecture HAL. Since the
130 reset entry point is usually implemented as one of these it also deals
131 with system startup.</P
133 >The exact implementation of this code is under the control of the HAL
134 implementer. So long as it interacts correctly with the interfaces
135 defined previously it may take any form. However, all current
136 implementation follow the same pattern, and there should be a very
137 good reason to break with this. The rest of this section describes
140 >Exception handling normally deals with the following broad areas of
147 >Startup and initialization.</P
151 >Hardware exception delivery.</P
155 >Default handling of synchronous exceptions.</P
159 >Default handling of asynchronous interrupts.</P
167 NAME="HAL-STARTUP">HAL Startup</H1
169 >Execution normally begins at the reset vector with
170 the machine in a minimal startup state. From here the HAL needs to get
171 the machine running, set up the execution environment for the
172 application, and finally invoke its entry point.</P
174 >The following is a list of the jobs that need to be done in
175 approximately the order in which they should be accomplished. Many
176 of these will not be needed in some configurations.</P
182 > Initialize the hardware. This may involve initializing several
183 subsystems in both the architecture, variant and platform
191 > Initialize various CPU status registers. Most importantly, the CPU
192 interrupt mask should be set to disable interrupts.
197 > Initialize the MMU, if it is used. On many platforms it is
198 only possible to control the cacheability of address ranges
199 via the MMU. Also, it may be necessary to remap RAM and device
200 registers to locations other than their defaults. However, for
201 simplicity, the mapping should be kept as close to one-to-one
202 physical-to-virtual as possible.
207 > Set up the memory controller to access RAM, ROM and I/O devices
208 correctly. Until this is done it may not be possible to access
209 RAM. If this is a ROMRAM startup then the program code can
210 now be copied to its RAM address and control transferred to it.
215 > Set up any bus bridges and support chips. Often access to
216 device registers needs to go through various bus bridges and
217 other intermediary devices. In many systems these are combined
218 with the memory controller, so it makes sense to set these up
219 together. This is particularly important if early diagnostic
220 output needs to go through one of these devices.
225 > Set up diagnostic mechanisms. If the platform includes an LED or
226 LCD output device, it often makes sense to output progress
227 indications on this during startup. This helps with diagnosing
228 hardware and software errors.
233 > Initialize floating point and other extensions such as SIMD
234 and multimedia engines. It is usually necessary to enable
235 these and maybe initialize control and exception registers for
241 > Initialize interrupt controller. At the very least, it should
242 be configured to mask all interrupts. It may also be necessary
243 to set up the mapping from the interrupt controller's vector
244 number space to the CPU's exception number space. Similar
245 mappings may need to be set up between primary and secondary
246 interrupt controllers.
251 > Disable and initialize the caches. The caches should not
252 normally be enabled at this point, but it may be necessary to
253 clear or initialize them so that they can be enabled
254 later. Some architectures require that the caches be
255 explicitly reinitialized after a power-on reset.
260 > Initialize the timer, clock etc. While the timer used for RTC
261 interrupts will be initialized later, it may be necessary to
262 set up the clocks that drive it here.
267 > The exact order in which these initializations is done is
268 architecture or variant specific. It is also often not necessary
269 to do anything at all for some of these options. These fragments
270 of code should concentrate on getting the target up and running so
271 that C function calls can be made and code can be run. More
272 complex initializations that cannot be done in assembly code may
273 be postponed until calls to
276 >hal_variant_init()</TT
280 >hal_platform_init()</TT
284 > Not all of these initializations need to be done for all startup
285 types. In particular, RAM startups can reasonably assume that the
286 ROM monitor or loader has already done most of this work.
291 > Set up the stack pointer, this allows subsequent initialization
292 code to make proper procedure calls. Usually the interrupt stack
293 is used for this purpose since it is available, large enough, and
294 will be reused for other purposes later.
299 > Initialize any global pointer register needed for access to
300 globally defined variables. This allows subsequent initialization
301 code to access global variables.
306 > If the system is starting from ROM, copy the ROM template of the
310 > section out to its correct position in
312 HREF="hal-linker-scripts.html"
313 >the Section called <I
329 > Create a suitable C call stack frame. This may involve making
330 stack space for call frames, and arguments, and initializing the
331 back pointers to halt a GDB backtrace operation.
338 >hal_variant_init()</TT
342 >hal_platform_init()</TT
343 >. These will perform any
344 additional initialization needed by the variant and platform. This
345 typically includes further initialization of the interrupt
346 controller, PCI bus bridges, basic IO devices and enabling the
354 >cyg_hal_invoke_constructors()</TT
368 > returns, drop into an infinite
380 SUMMARY="Footer navigation table"
391 HREF="hal-smp-support.html"
409 HREF="hal-vectors-and-vsrs.html"
425 HREF="the-ecos-hardware-abstraction-layer.html"
433 >Vectors and VSRs</TD