OSDN Git Service

2005-03-08 Ed Schonberg <schonberg@adacore.com>
[pf3gnuchains/gcc-fork.git] / gcc / ada / i-vxwork-x86.ads
1 ------------------------------------------------------------------------------
2 --                                                                          --
3 --                 GNU ADA 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-2004 Ada Core Technologies, Inc.          --
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,  59 Temple Place - Suite 330,  Boston, --
20 -- MA 02111-1307, 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 with System.VxWorks;
51
52 package Interfaces.VxWorks is
53    pragma Preelaborate (VxWorks);
54
55    ------------------------------------------------------------------------
56    --  Here is a complete example that shows how to handle the Interrupt 0x33
57    --  with a direct-vectored interrupt handler in Ada using this package:
58
59    --  with Interfaces.VxWorks; use Interfaces.VxWorks;
60    --  with System;
61    --
62    --  package P is
63    --
64    --     Count : Integer;
65    --     pragma Atomic (Count);
66    --
67    --     procedure Handler (Parameter : System.Address);
68    --
69    --  end P;
70    --
71    --  package body P is
72    --
73    --     procedure Handler (Parameter : System.Address) is
74    --     begin
75    --        Count := Count + 1;
76    --        logMsg ("received an interrupt" & ASCII.LF & ASCII.Nul);
77    --     end Handler;
78    --  end P;
79    --
80    --  with Interfaces.VxWorks; use Interfaces.VxWorks;
81    --  with Ada.Text_IO; use Ada.Text_IO;
82    --  with Ada.Interrupts;
83    --  with Machine_Code; use Machine_Code;
84    --
85    --  with P; use P;
86    --  procedure Useint is
87    --     --  Be sure to use a reasonable interrupt number for the target
88    --     --  board!
89    --     --  This one is an unreserved interrupt for the Pentium 3 BSP
90    --     Interrupt : constant := 16#33#;
91    --
92    --     task T;
93    --
94    --     S : STATUS;
95    --
96    --     task body T is
97    --     begin
98    --        loop
99    --           Put_Line ("Generating an interrupt...");
100    --           delay 1.0;
101    --
102    --           --  Generate interrupt, using interrupt number
103    --           Asm ("int %0",
104    --                Inputs =>
105    --                  Ada.Interrupts.Interrupt_ID'Asm_Input
106    --                    ("i", Interrupt));
107    --        end loop;
108    --     end T;
109    --
110    --  begin
111    --     S := intConnect (INUM_TO_IVEC (Interrupt), Handler'Access);
112    --
113    --     loop
114    --        delay 2.0;
115    --        Put_Line ("value of count:" & P.Count'Img);
116    --     end loop;
117    --  end Useint;
118    -------------------------------------
119
120    subtype int is Integer;
121
122    type STATUS is new int;
123    --  Equivalent of the C type STATUS
124
125    OK    : constant STATUS := 0;
126    ERROR : constant STATUS := -1;
127
128    type VOIDFUNCPTR is access procedure (parameter : System.Address);
129    type Interrupt_Vector is new System.Address;
130    type Exception_Vector is new System.Address;
131
132    function intConnect
133      (vector    : Interrupt_Vector;
134       handler   : VOIDFUNCPTR;
135       parameter : System.Address := System.Null_Address) return STATUS;
136    --  Binding to the C routine intConnect. Use this to set up an
137    --  user handler. The routine generates a wrapper around the user
138    --  handler to save and restore context
139
140    function intVecGet
141      (Vector : Interrupt_Vector) return VOIDFUNCPTR;
142    --  Binding to the C routine intVecGet. Use this to get the
143    --  existing handler for later restoral
144
145    procedure intVecSet
146      (Vector  : Interrupt_Vector;
147       Handler : VOIDFUNCPTR);
148    --  Binding to the C routine intVecSet. Use this to restore a
149    --  handler obtained using intVecGet
150
151    procedure intVecGet2
152      (vector       : Interrupt_Vector;
153       pFunction    : out VOIDFUNCPTR;
154       pIdtGate     : access int;
155       pIdtSelector : access int);
156    --  Binding to the C routine intVecGet2. Use this to get the
157    --  existing handler for later restoral
158
159    procedure intVecSet2
160      (vector       : Interrupt_Vector;
161       pFunction    : VOIDFUNCPTR;
162       pIdtGate     : access int;
163       pIdtSelector : access int);
164    --  Binding to the C routine intVecSet2. Use this to restore a
165    --  handler obtained using intVecGet2
166
167    function INUM_TO_IVEC (intNum : int) return Interrupt_Vector;
168    --  Equivalent to the C macro INUM_TO_IVEC used to convert an interrupt
169    --  number to an interrupt vector
170
171    procedure logMsg
172      (fmt : String; arg1, arg2, arg3, arg4, arg5, arg6 : int := 0);
173    --  Binding to the C routine logMsg. Note that it is the caller's
174    --  responsibility to ensure that fmt is a null-terminated string
175    --  (e.g logMsg ("Interrupt" & ASCII.NUL))
176
177    type FP_CONTEXT is private;
178    --  Floating point context save and restore. Handlers using floating
179    --  point must be bracketed with these calls. The pFpContext parameter
180    --  should be an object of type FP_CONTEXT that is
181    --  declared local to the handler.
182    --  See the VxWorks Intel Architecture Supplement regarding
183    --  these routines.
184
185    procedure fppRestore (pFpContext : in out FP_CONTEXT);
186    --  Restore floating point context - old style
187
188    procedure fppSave (pFpContext : in out FP_CONTEXT);
189    --  Save floating point context - old style
190
191    procedure fppXrestore (pFpContext : in out FP_CONTEXT);
192    --  Restore floating point context - new style
193
194    procedure fppXsave (pFpContext : in out FP_CONTEXT);
195    --  Save floating point context - new style
196
197 private
198
199    type FP_CONTEXT is new System.VxWorks.FP_CONTEXT;
200    --  Target-dependent floating point context type
201
202    pragma Import (C, intConnect, "intConnect");
203    pragma Import (C, intVecGet, "intVecGet");
204    pragma Import (C, intVecSet, "intVecSet");
205    pragma Import (C, intVecGet2, "intVecGet2");
206    pragma Import (C, intVecSet2, "intVecSet2");
207    pragma Import (C, INUM_TO_IVEC, "__gnat_inum_to_ivec");
208    pragma Import (C, logMsg, "logMsg");
209    pragma Import (C, fppRestore, "fppRestore");
210    pragma Import (C, fppSave, "fppSave");
211    pragma Import (C, fppXrestore, "fppXrestore");
212    pragma Import (C, fppXsave, "fppXsave");
213 end Interfaces.VxWorks;