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