1 |
281 |
jeremybenn |
------------------------------------------------------------------------------
|
2 |
|
|
-- --
|
3 |
|
|
-- GNAT RUN-TIME LIBRARY (GNARL) COMPONENTS --
|
4 |
|
|
-- --
|
5 |
|
|
-- I N T E R F A C E S . V X W O R K S --
|
6 |
|
|
-- --
|
7 |
|
|
-- S p e c --
|
8 |
|
|
-- --
|
9 |
|
|
-- Copyright (C) 1999-2008, AdaCore --
|
10 |
|
|
-- --
|
11 |
|
|
-- GNARL is free software; you can redistribute it and/or modify it under --
|
12 |
|
|
-- terms of the GNU General Public License as published by the Free Soft- --
|
13 |
|
|
-- ware Foundation; either version 2, or (at your option) any later ver- --
|
14 |
|
|
-- sion. GNARL is distributed in the hope that it will be useful, but WITH- --
|
15 |
|
|
-- OUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY --
|
16 |
|
|
-- or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License --
|
17 |
|
|
-- for more details. You should have received a copy of the GNU General --
|
18 |
|
|
-- Public License distributed with GNARL; see file COPYING. If not, write --
|
19 |
|
|
-- to the Free Software Foundation, 51 Franklin Street, Fifth Floor, --
|
20 |
|
|
-- Boston, MA 02110-1301, USA. --
|
21 |
|
|
-- --
|
22 |
|
|
-- As a special exception, if other files instantiate generics from this --
|
23 |
|
|
-- unit, or you link this unit with other files to produce an executable, --
|
24 |
|
|
-- this unit does not by itself cause the resulting executable to be --
|
25 |
|
|
-- covered by the GNU General Public License. This exception does not --
|
26 |
|
|
-- however invalidate any other reasons why the executable file might be --
|
27 |
|
|
-- covered by the GNU Public License. --
|
28 |
|
|
-- --
|
29 |
|
|
-- GNARL was developed by the GNARL team at Florida State University. --
|
30 |
|
|
-- Extensive contributions were provided by Ada Core Technologies, Inc. --
|
31 |
|
|
-- --
|
32 |
|
|
------------------------------------------------------------------------------
|
33 |
|
|
|
34 |
|
|
-- This is the x86 VxWorks version of this package
|
35 |
|
|
|
36 |
|
|
-- This package provides a limited binding to the VxWorks API
|
37 |
|
|
-- In particular, it interfaces with the VxWorks hardware interrupt
|
38 |
|
|
-- facilities, allowing the use of low-latency direct-vectored
|
39 |
|
|
-- interrupt handlers. Note that such handlers have a variety of
|
40 |
|
|
-- restrictions regarding system calls and language constructs. In particular,
|
41 |
|
|
-- the use of exception handlers and functions returning variable-length
|
42 |
|
|
-- objects cannot be used. Less restrictive, but higher-latency handlers can
|
43 |
|
|
-- be written using Ada protected procedures, Ada 83 style interrupt entries,
|
44 |
|
|
-- or by signalling an Ada task from within an interrupt handler using a
|
45 |
|
|
-- binary semaphore as described in the VxWorks Programmer's Manual.
|
46 |
|
|
--
|
47 |
|
|
-- For complete documentation of the operations in this package, please
|
48 |
|
|
-- consult the VxWorks Programmer's Manual and VxWorks Reference Manual.
|
49 |
|
|
|
50 |
|
|
pragma Warnings (Off, "*foreign convention*");
|
51 |
|
|
pragma Warnings (Off, "*add Convention pragma*");
|
52 |
|
|
|
53 |
|
|
with System.VxWorks;
|
54 |
|
|
|
55 |
|
|
package Interfaces.VxWorks is
|
56 |
|
|
pragma Preelaborate;
|
57 |
|
|
|
58 |
|
|
------------------------------------------------------------------------
|
59 |
|
|
-- Here is a complete example that shows how to handle the Interrupt 0x33
|
60 |
|
|
-- with a direct-vectored interrupt handler in Ada using this package:
|
61 |
|
|
|
62 |
|
|
-- with Interfaces.VxWorks; use Interfaces.VxWorks;
|
63 |
|
|
-- with System;
|
64 |
|
|
--
|
65 |
|
|
-- package P is
|
66 |
|
|
--
|
67 |
|
|
-- Count : Integer;
|
68 |
|
|
-- pragma Atomic (Count);
|
69 |
|
|
--
|
70 |
|
|
-- procedure Handler (Parameter : System.Address);
|
71 |
|
|
--
|
72 |
|
|
-- end P;
|
73 |
|
|
--
|
74 |
|
|
-- package body P is
|
75 |
|
|
--
|
76 |
|
|
-- procedure Handler (Parameter : System.Address) is
|
77 |
|
|
-- begin
|
78 |
|
|
-- Count := Count + 1;
|
79 |
|
|
-- logMsg ("received an interrupt" & ASCII.LF & ASCII.NUL);
|
80 |
|
|
-- end Handler;
|
81 |
|
|
-- end P;
|
82 |
|
|
--
|
83 |
|
|
-- with Interfaces.VxWorks; use Interfaces.VxWorks;
|
84 |
|
|
-- with Ada.Text_IO; use Ada.Text_IO;
|
85 |
|
|
-- with Ada.Interrupts;
|
86 |
|
|
-- with Machine_Code; use Machine_Code;
|
87 |
|
|
--
|
88 |
|
|
-- with P; use P;
|
89 |
|
|
-- procedure Useint is
|
90 |
|
|
-- -- Be sure to use a reasonable interrupt number for the target
|
91 |
|
|
-- -- board!
|
92 |
|
|
-- -- This one is an unreserved interrupt for the Pentium 3 BSP
|
93 |
|
|
-- Interrupt : constant := 16#33#;
|
94 |
|
|
--
|
95 |
|
|
-- task T;
|
96 |
|
|
--
|
97 |
|
|
-- S : STATUS;
|
98 |
|
|
--
|
99 |
|
|
-- task body T is
|
100 |
|
|
-- begin
|
101 |
|
|
-- loop
|
102 |
|
|
-- Put_Line ("Generating an interrupt...");
|
103 |
|
|
-- delay 1.0;
|
104 |
|
|
--
|
105 |
|
|
-- -- Generate interrupt, using interrupt number
|
106 |
|
|
-- Asm ("int %0",
|
107 |
|
|
-- Inputs =>
|
108 |
|
|
-- Ada.Interrupts.Interrupt_ID'Asm_Input
|
109 |
|
|
-- ("i", Interrupt));
|
110 |
|
|
-- end loop;
|
111 |
|
|
-- end T;
|
112 |
|
|
--
|
113 |
|
|
-- begin
|
114 |
|
|
-- S := intConnect (INUM_TO_IVEC (Interrupt), Handler'Access);
|
115 |
|
|
--
|
116 |
|
|
-- loop
|
117 |
|
|
-- delay 2.0;
|
118 |
|
|
-- Put_Line ("value of count:" & P.Count'Img);
|
119 |
|
|
-- end loop;
|
120 |
|
|
-- end Useint;
|
121 |
|
|
-------------------------------------
|
122 |
|
|
|
123 |
|
|
subtype int is Integer;
|
124 |
|
|
|
125 |
|
|
type STATUS is new int;
|
126 |
|
|
-- Equivalent of the C type STATUS
|
127 |
|
|
|
128 |
|
|
OK : constant STATUS := 0;
|
129 |
|
|
ERROR : constant STATUS := -1;
|
130 |
|
|
|
131 |
|
|
type VOIDFUNCPTR is access procedure (parameter : System.Address);
|
132 |
|
|
type Interrupt_Vector is new System.Address;
|
133 |
|
|
type Exception_Vector is new System.Address;
|
134 |
|
|
|
135 |
|
|
function intConnect
|
136 |
|
|
(vector : Interrupt_Vector;
|
137 |
|
|
handler : VOIDFUNCPTR;
|
138 |
|
|
parameter : System.Address := System.Null_Address) return STATUS;
|
139 |
|
|
-- Binding to the C routine intConnect. Use this to set up an
|
140 |
|
|
-- user handler. The routine generates a wrapper around the user
|
141 |
|
|
-- handler to save and restore context
|
142 |
|
|
|
143 |
|
|
function intContext return int;
|
144 |
|
|
-- Binding to the C routine intContext. This function returns 1 only
|
145 |
|
|
-- if the current execution state is in interrupt context.
|
146 |
|
|
|
147 |
|
|
function intVecGet
|
148 |
|
|
(Vector : Interrupt_Vector) return VOIDFUNCPTR;
|
149 |
|
|
-- Binding to the C routine intVecGet. Use this to get the
|
150 |
|
|
-- existing handler for later restoral
|
151 |
|
|
|
152 |
|
|
procedure intVecSet
|
153 |
|
|
(Vector : Interrupt_Vector;
|
154 |
|
|
Handler : VOIDFUNCPTR);
|
155 |
|
|
-- Binding to the C routine intVecSet. Use this to restore a
|
156 |
|
|
-- handler obtained using intVecGet
|
157 |
|
|
|
158 |
|
|
procedure intVecGet2
|
159 |
|
|
(vector : Interrupt_Vector;
|
160 |
|
|
pFunction : out VOIDFUNCPTR;
|
161 |
|
|
pIdtGate : not null access int;
|
162 |
|
|
pIdtSelector : not null access int);
|
163 |
|
|
-- Binding to the C routine intVecGet2. Use this to get the
|
164 |
|
|
-- existing handler for later restoral
|
165 |
|
|
|
166 |
|
|
procedure intVecSet2
|
167 |
|
|
(vector : Interrupt_Vector;
|
168 |
|
|
pFunction : VOIDFUNCPTR;
|
169 |
|
|
pIdtGate : not null access int;
|
170 |
|
|
pIdtSelector : not null access int);
|
171 |
|
|
-- Binding to the C routine intVecSet2. Use this to restore a
|
172 |
|
|
-- handler obtained using intVecGet2
|
173 |
|
|
|
174 |
|
|
function INUM_TO_IVEC (intNum : int) return Interrupt_Vector;
|
175 |
|
|
-- Equivalent to the C macro INUM_TO_IVEC used to convert an interrupt
|
176 |
|
|
-- number to an interrupt vector
|
177 |
|
|
|
178 |
|
|
procedure logMsg
|
179 |
|
|
(fmt : String; arg1, arg2, arg3, arg4, arg5, arg6 : int := 0);
|
180 |
|
|
-- Binding to the C routine logMsg. Note that it is the caller's
|
181 |
|
|
-- responsibility to ensure that fmt is a null-terminated string
|
182 |
|
|
-- (e.g logMsg ("Interrupt" & ASCII.NUL))
|
183 |
|
|
|
184 |
|
|
type FP_CONTEXT is private;
|
185 |
|
|
-- Floating point context save and restore. Handlers using floating
|
186 |
|
|
-- point must be bracketed with these calls. The pFpContext parameter
|
187 |
|
|
-- should be an object of type FP_CONTEXT that is
|
188 |
|
|
-- declared local to the handler.
|
189 |
|
|
-- See the VxWorks Intel Architecture Supplement regarding
|
190 |
|
|
-- these routines.
|
191 |
|
|
|
192 |
|
|
procedure fppRestore (pFpContext : in out FP_CONTEXT);
|
193 |
|
|
-- Restore floating point context - old style
|
194 |
|
|
|
195 |
|
|
procedure fppSave (pFpContext : in out FP_CONTEXT);
|
196 |
|
|
-- Save floating point context - old style
|
197 |
|
|
|
198 |
|
|
procedure fppXrestore (pFpContext : in out FP_CONTEXT);
|
199 |
|
|
-- Restore floating point context - new style
|
200 |
|
|
|
201 |
|
|
procedure fppXsave (pFpContext : in out FP_CONTEXT);
|
202 |
|
|
-- Save floating point context - new style
|
203 |
|
|
|
204 |
|
|
private
|
205 |
|
|
|
206 |
|
|
type FP_CONTEXT is new System.VxWorks.FP_CONTEXT;
|
207 |
|
|
-- Target-dependent floating point context type
|
208 |
|
|
|
209 |
|
|
pragma Import (C, intConnect, "intConnect");
|
210 |
|
|
pragma Import (C, intContext, "intContext");
|
211 |
|
|
pragma Import (C, intVecGet, "intVecGet");
|
212 |
|
|
pragma Import (C, intVecSet, "intVecSet");
|
213 |
|
|
pragma Import (C, intVecGet2, "intVecGet2");
|
214 |
|
|
pragma Import (C, intVecSet2, "intVecSet2");
|
215 |
|
|
pragma Import (C, INUM_TO_IVEC, "__gnat_inum_to_ivec");
|
216 |
|
|
pragma Import (C, logMsg, "logMsg");
|
217 |
|
|
pragma Import (C, fppRestore, "fppRestore");
|
218 |
|
|
pragma Import (C, fppSave, "fppSave");
|
219 |
|
|
pragma Import (C, fppXrestore, "fppXrestore");
|
220 |
|
|
pragma Import (C, fppXsave, "fppXsave");
|
221 |
|
|
end Interfaces.VxWorks;
|