annotate gcc/ada/libgnat/i-vxwork__x86.ads @ 131:84e7813d76e9

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