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 adaintr.t,v 1.4 2002/01/17 21:47:44 joel Exp
|
7 |
|
|
@c
|
8 |
|
|
|
9 |
|
|
@chapter Ada95 Interrupt Support
|
10 |
|
|
|
11 |
|
|
@section Introduction
|
12 |
|
|
|
13 |
|
|
This chapter describes what is required to enable Ada interrupt
|
14 |
|
|
and error exception handling when using GNAT over RTEMS.
|
15 |
|
|
|
16 |
|
|
The GNAT Ada95 interrupt support RTEMS was developed by
|
17 |
|
|
Jiri Gaisler who also wrote this
|
18 |
|
|
chapter.
|
19 |
|
|
|
20 |
|
|
@section Mapping Interrupts to POSIX Signals
|
21 |
|
|
|
22 |
|
|
In Ada95, interrupts can be attached with the interrupt_attach pragma.
|
23 |
|
|
For most systems, the gnat run-time will use POSIX signal to implement
|
24 |
|
|
the interrupt handling, mapping one signal per interrupt. For interrupts
|
25 |
|
|
to be propagated to the attached Ada handler, the corresponding signal
|
26 |
|
|
must be raised when the interrupt occurs.
|
27 |
|
|
|
28 |
|
|
The same mechanism is used to generate Ada error exceptions.
|
29 |
|
|
Three error exceptions are defined: program, constraint and storage
|
30 |
|
|
error. These are generated by raising the predefined signals: SIGILL,
|
31 |
|
|
SIGFPE and SIGSEGV. These signals should be raised when a spurious
|
32 |
|
|
or erroneous trap occurs.
|
33 |
|
|
|
34 |
|
|
To enable gnat interrupt and error exception support for a particular
|
35 |
|
|
bsp, the following has to be done:
|
36 |
|
|
|
37 |
|
|
@enumerate
|
38 |
|
|
|
39 |
|
|
@item Write an interrupt/trap handler that will raise the corresponding
|
40 |
|
|
signal depending on the interrupt/trap number.
|
41 |
|
|
|
42 |
|
|
@item Install the interrupt handler for all interrupts/traps that will be
|
43 |
|
|
handled by gnat (including spurious).
|
44 |
|
|
|
45 |
|
|
@item At startup, gnat calls @code{__gnat_install_handler()}. The bsp
|
46 |
|
|
must provide this function which installs the interrupt/trap handlers.
|
47 |
|
|
|
48 |
|
|
@end enumerate
|
49 |
|
|
|
50 |
|
|
Which cpu-interrupt will generate which signal is implementation
|
51 |
|
|
defined. There are 32 POSIX signals (1 - 32), and all except the
|
52 |
|
|
three error signals (SIGILL, SIGFPE and SIGSEGV) can be used. I
|
53 |
|
|
would suggest to use the upper 16 (17 - 32) which do not
|
54 |
|
|
have an assigned POSIX name.
|
55 |
|
|
|
56 |
|
|
Note that the pragma interrupt_attach will only bind a signal
|
57 |
|
|
to a particular Ada handler - it will not unmask the
|
58 |
|
|
interrupt or do any other things to enable it. This have to be
|
59 |
|
|
done separately, typically by writing various device register.
|
60 |
|
|
|
61 |
|
|
@section Example Ada95 Interrupt Program
|
62 |
|
|
|
63 |
|
|
An example program (@code{irq_test}) is included in the
|
64 |
|
|
Ada examples package to show how interrupts can be handled
|
65 |
|
|
in Ada95. Note that generation of the test interrupt
|
66 |
|
|
(@code{irqforce.c}) is bsp specific and must be edited.
|
67 |
|
|
|
68 |
|
|
NOTE: The @code{irq_test} example was written for the SPARC/ERC32
|
69 |
|
|
BSP.
|
70 |
|
|
|
71 |
|
|
@section Version Requirements
|
72 |
|
|
|
73 |
|
|
With RTEMS 4.0, a patch was required to psignal.c in RTEMS
|
74 |
|
|
sources (to correct a bug associated to the default action of
|
75 |
|
|
signals 15-32). The SPARC/ERC32 RTEMS BSP includes the
|
76 |
|
|
@code{gnatsupp} subdirectory that can be used as an example
|
77 |
|
|
for other BSPs.
|
78 |
|
|
|
79 |
|
|
With GNAT 3.11p, a patch is required for @code{a-init.c} to invoke
|
80 |
|
|
the BSP specific routine that installs the exception handlers.
|
81 |
|
|
|