[testsuite]
[official-gcc.git] / gcc / ada / libgnat / i-vxwork.ads
blob28b039427d08e4b1cb62441a7a1942ec218cae3c
1 ------------------------------------------------------------------------------
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-2018, 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 ------------------------------------------------------------------------------
32 -- This package provides a limited binding to the VxWorks API
34 -- In particular, it interfaces with the VxWorks hardware interrupt
35 -- facilities, allowing the use of low-latency direct-vectored interrupt
36 -- handlers. Note that such handlers have a variety of restrictions regarding
37 -- system calls and language constructs. In particular, the use of exception
38 -- handlers and functions returning variable-length objects cannot be used.
39 -- Less restrictive, but higher-latency handlers can be written using Ada
40 -- protected procedures, Ada 83 style interrupt entries, or by signalling
41 -- an Ada task from within an interrupt handler using a binary semaphore
42 -- as described in the VxWorks Programmer's Manual.
44 -- For complete documentation of the operations in this package, please
45 -- consult the VxWorks Programmer's Manual and VxWorks Reference Manual.
47 pragma Warnings (Off, "*foreign convention*");
48 pragma Warnings (Off, "*add Convention pragma*");
49 -- These are temporary pragmas to suppress warnings about mismatching
50 -- conventions, which will be a problem when we get rid of trampolines ???
52 with System.VxWorks;
54 package Interfaces.VxWorks is
55 pragma Preelaborate;
57 ------------------------------------------------------------------------
58 -- Here is a complete example that shows how to handle the Interrupt 0x14
59 -- with a direct-vectored interrupt handler in Ada using this package:
61 -- with Interfaces.VxWorks; use Interfaces.VxWorks;
62 -- with System;
64 -- package P is
66 -- Count : Integer;
67 -- pragma Atomic (Count);
69 -- Level : constant := 1;
70 -- -- Interrupt level used by this example
72 -- procedure Handler (parameter : System.Address);
74 -- end P;
76 -- package body P is
78 -- procedure Handler (parameter : System.Address) is
79 -- S : STATUS;
80 -- begin
81 -- Count := Count + 1;
82 -- logMsg ("received an interrupt" & ASCII.LF & ASCII.NUL);
84 -- -- Acknowledge VME interrupt
86 -- S := sysBusIntAck (intLevel => Level);
87 -- end Handler;
88 -- end P;
90 -- with Interfaces.VxWorks; use Interfaces.VxWorks;
91 -- with Ada.Text_IO; use Ada.Text_IO;
93 -- with P; use P;
94 -- procedure Useint is
96 -- -- Be sure to use a reasonable interrupt number for board.
97 -- -- This one is the unused VME graphics interrupt on the PPC MV2604
99 -- Interrupt : constant := 16#14#;
101 -- task T;
103 -- S : STATUS;
105 -- task body T is
106 -- begin
107 -- loop
108 -- Put_Line ("Generating an interrupt...");
109 -- delay 1.0;
111 -- -- Generate VME interrupt, using interrupt number
113 -- S := sysBusIntGen (1, Interrupt);
114 -- end loop;
115 -- end T;
117 -- begin
118 -- S := sysIntEnable (intLevel => Level);
119 -- S := intConnect (INUM_TO_IVEC (Interrupt), handler'Access);
121 -- loop
122 -- delay 2.0;
123 -- Put_Line ("value of count:" & P.Count'Img);
124 -- end loop;
125 -- end Useint;
126 -------------------------------------
128 subtype int is Integer;
130 type STATUS is new int;
131 -- Equivalent of the C type STATUS
133 OK : constant STATUS := 0;
134 ERROR : constant STATUS := -1;
136 type VOIDFUNCPTR is access procedure (parameter : System.Address);
137 type Interrupt_Vector is new System.Address;
138 type Exception_Vector is new System.Address;
140 function intConnect
141 (vector : Interrupt_Vector;
142 handler : VOIDFUNCPTR;
143 parameter : System.Address := System.Null_Address) return STATUS;
144 -- Binding to the C routine intConnect. Use this to set up an user handler.
145 -- The routine generates a wrapper around the user handler to save and
146 -- restore context
148 function intContext return int;
149 -- Binding to the C routine intContext. This function returns 1 only if the
150 -- current execution state is in interrupt context.
152 function intVecGet
153 (Vector : Interrupt_Vector) return VOIDFUNCPTR;
154 -- Binding to the C routine intVecGet. Use this to get the existing handler
155 -- for later restoral
157 procedure intVecSet
158 (Vector : Interrupt_Vector;
159 Handler : VOIDFUNCPTR);
160 -- Binding to the C routine intVecSet. Use this to restore a handler
161 -- obtained using intVecGet
163 function INUM_TO_IVEC (intNum : int) return Interrupt_Vector;
164 -- Equivalent to the C macro INUM_TO_IVEC used to convert an interrupt
165 -- number to an interrupt vector
167 function sysIntEnable (intLevel : int) return STATUS;
168 -- Binding to the C routine sysIntEnable
170 function sysIntDisable (intLevel : int) return STATUS;
171 -- Binding to the C routine sysIntDisable
173 function sysBusIntAck (intLevel : int) return STATUS;
174 -- Binding to the C routine sysBusIntAck
176 function sysBusIntGen (intLevel : int; Intnum : int) return STATUS;
177 -- Binding to the C routine sysBusIntGen. Note that the T2 documentation
178 -- implies that a vector address is the proper argument - it's not. The
179 -- interrupt number in the range 0 .. 255 (for 68K and PPC) is the correct
180 -- argument.
182 procedure logMsg
183 (fmt : String; arg1, arg2, arg3, arg4, arg5, arg6 : int := 0);
184 -- Binding to the C routine logMsg. Note that it is the caller's
185 -- responsibility to ensure that fmt is a null-terminated string
186 -- (e.g logMsg ("Interrupt" & ASCII.NUL))
188 type FP_CONTEXT is private;
189 -- Floating point context save and restore. Handlers using floating point
190 -- must be bracketed with these calls. The pFpContext parameter should be
191 -- an object of type FP_CONTEXT that is declared local to the handler.
193 procedure fppRestore (pFpContext : in out FP_CONTEXT);
194 -- Restore floating point context
196 procedure fppSave (pFpContext : in out FP_CONTEXT);
197 -- Save floating point context
199 private
201 type FP_CONTEXT is new System.VxWorks.FP_CONTEXT;
202 -- Target-dependent floating point context type
204 pragma Import (C, intConnect, "intConnect");
205 pragma Import (C, intContext, "intContext");
206 pragma Import (C, intVecGet, "intVecGet");
207 pragma Import (C, intVecSet, "intVecSet");
208 pragma Import (C, INUM_TO_IVEC, "__gnat_inum_to_ivec");
209 pragma Import (C, sysIntEnable, "sysIntEnable");
210 pragma Import (C, sysIntDisable, "sysIntDisable");
211 pragma Import (C, sysBusIntAck, "sysBusIntAck");
212 pragma Import (C, sysBusIntGen, "sysBusIntGen");
213 pragma Import (C, logMsg, "logMsg");
214 pragma Import (C, fppRestore, "fppRestore");
215 pragma Import (C, fppSave, "fppSave");
216 end Interfaces.VxWorks;