annotate gcc/ada/libgnarl/s-osinte__vxworks.adb @ 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 -- S Y S T E M . O S _ I N T E R F A C E --
kono
parents:
diff changeset
6 -- --
kono
parents:
diff changeset
7 -- B o d y --
kono
parents:
diff changeset
8 -- --
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
9 -- Copyright (C) 1997-2018, Free Software Foundation, Inc. --
111
kono
parents:
diff changeset
10 -- --
kono
parents:
diff changeset
11 -- GNARL 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 VxWorks version
kono
parents:
diff changeset
33
kono
parents:
diff changeset
34 -- This package encapsulates all direct interfaces to OS services that are
kono
parents:
diff changeset
35 -- needed by children of System.
kono
parents:
diff changeset
36
kono
parents:
diff changeset
37 pragma Polling (Off);
kono
parents:
diff changeset
38 -- Turn off polling, we do not want ATC polling to take place during tasking
kono
parents:
diff changeset
39 -- operations. It causes infinite loops and other problems.
kono
parents:
diff changeset
40
kono
parents:
diff changeset
41 package body System.OS_Interface is
kono
parents:
diff changeset
42
kono
parents:
diff changeset
43 use type Interfaces.C.int;
kono
parents:
diff changeset
44
kono
parents:
diff changeset
45 Low_Priority : constant := 255;
kono
parents:
diff changeset
46 -- VxWorks native (default) lowest scheduling priority
kono
parents:
diff changeset
47
kono
parents:
diff changeset
48 -----------------
kono
parents:
diff changeset
49 -- To_Duration --
kono
parents:
diff changeset
50 -----------------
kono
parents:
diff changeset
51
kono
parents:
diff changeset
52 function To_Duration (TS : timespec) return Duration is
kono
parents:
diff changeset
53 begin
kono
parents:
diff changeset
54 return Duration (TS.ts_sec) + Duration (TS.ts_nsec) / 10#1#E9;
kono
parents:
diff changeset
55 end To_Duration;
kono
parents:
diff changeset
56
kono
parents:
diff changeset
57 -----------------
kono
parents:
diff changeset
58 -- To_Timespec --
kono
parents:
diff changeset
59 -----------------
kono
parents:
diff changeset
60
kono
parents:
diff changeset
61 function To_Timespec (D : Duration) return timespec is
kono
parents:
diff changeset
62 S : time_t;
kono
parents:
diff changeset
63 F : Duration;
kono
parents:
diff changeset
64
kono
parents:
diff changeset
65 begin
kono
parents:
diff changeset
66 S := time_t (Long_Long_Integer (D));
kono
parents:
diff changeset
67 F := D - Duration (S);
kono
parents:
diff changeset
68
kono
parents:
diff changeset
69 -- If F is negative due to a round-up, adjust for positive F value
kono
parents:
diff changeset
70
kono
parents:
diff changeset
71 if F < 0.0 then
kono
parents:
diff changeset
72 S := S - 1;
kono
parents:
diff changeset
73 F := F + 1.0;
kono
parents:
diff changeset
74 end if;
kono
parents:
diff changeset
75
kono
parents:
diff changeset
76 return timespec'(ts_sec => S,
kono
parents:
diff changeset
77 ts_nsec => long (Long_Long_Integer (F * 10#1#E9)));
kono
parents:
diff changeset
78 end To_Timespec;
kono
parents:
diff changeset
79
kono
parents:
diff changeset
80 -------------------------
kono
parents:
diff changeset
81 -- To_VxWorks_Priority --
kono
parents:
diff changeset
82 -------------------------
kono
parents:
diff changeset
83
kono
parents:
diff changeset
84 function To_VxWorks_Priority (Priority : int) return int is
kono
parents:
diff changeset
85 begin
kono
parents:
diff changeset
86 return Low_Priority - Priority;
kono
parents:
diff changeset
87 end To_VxWorks_Priority;
kono
parents:
diff changeset
88
kono
parents:
diff changeset
89 --------------------
kono
parents:
diff changeset
90 -- To_Clock_Ticks --
kono
parents:
diff changeset
91 --------------------
kono
parents:
diff changeset
92
kono
parents:
diff changeset
93 -- ??? - For now, we'll always get the system clock rate since it is
kono
parents:
diff changeset
94 -- allowed to be changed during run-time in VxWorks. A better method would
kono
parents:
diff changeset
95 -- be to provide an operation to set it that so we can always know its
kono
parents:
diff changeset
96 -- value.
kono
parents:
diff changeset
97
kono
parents:
diff changeset
98 -- Another thing we should probably allow for is a resultant tick count
kono
parents:
diff changeset
99 -- greater than int'Last. This should probably be a procedure with two
kono
parents:
diff changeset
100 -- output parameters, one in the range 0 .. int'Last, and another
kono
parents:
diff changeset
101 -- representing the overflow count.
kono
parents:
diff changeset
102
kono
parents:
diff changeset
103 function To_Clock_Ticks (D : Duration) return int is
kono
parents:
diff changeset
104 Ticks : Long_Long_Integer;
kono
parents:
diff changeset
105 Rate_Duration : Duration;
kono
parents:
diff changeset
106 Ticks_Duration : Duration;
kono
parents:
diff changeset
107
kono
parents:
diff changeset
108 begin
kono
parents:
diff changeset
109 if D < 0.0 then
kono
parents:
diff changeset
110 return ERROR;
kono
parents:
diff changeset
111 end if;
kono
parents:
diff changeset
112
kono
parents:
diff changeset
113 -- Ensure that the duration can be converted to ticks
kono
parents:
diff changeset
114 -- at the current clock tick rate without overflowing.
kono
parents:
diff changeset
115
kono
parents:
diff changeset
116 Rate_Duration := Duration (sysClkRateGet);
kono
parents:
diff changeset
117
kono
parents:
diff changeset
118 if D > (Duration'Last / Rate_Duration) then
kono
parents:
diff changeset
119 Ticks := Long_Long_Integer (int'Last);
kono
parents:
diff changeset
120 else
kono
parents:
diff changeset
121 Ticks_Duration := D * Rate_Duration;
kono
parents:
diff changeset
122 Ticks := Long_Long_Integer (Ticks_Duration);
kono
parents:
diff changeset
123
kono
parents:
diff changeset
124 if Ticks_Duration > Duration (Ticks) then
kono
parents:
diff changeset
125 Ticks := Ticks + 1;
kono
parents:
diff changeset
126 end if;
kono
parents:
diff changeset
127
kono
parents:
diff changeset
128 if Ticks > Long_Long_Integer (int'Last) then
kono
parents:
diff changeset
129 Ticks := Long_Long_Integer (int'Last);
kono
parents:
diff changeset
130 end if;
kono
parents:
diff changeset
131 end if;
kono
parents:
diff changeset
132
kono
parents:
diff changeset
133 return int (Ticks);
kono
parents:
diff changeset
134 end To_Clock_Ticks;
kono
parents:
diff changeset
135
kono
parents:
diff changeset
136 -----------------------------
kono
parents:
diff changeset
137 -- Binary_Semaphore_Create --
kono
parents:
diff changeset
138 -----------------------------
kono
parents:
diff changeset
139
kono
parents:
diff changeset
140 function Binary_Semaphore_Create return Binary_Semaphore_Id is
kono
parents:
diff changeset
141 begin
kono
parents:
diff changeset
142 return Binary_Semaphore_Id (semBCreate (SEM_Q_FIFO, SEM_EMPTY));
kono
parents:
diff changeset
143 end Binary_Semaphore_Create;
kono
parents:
diff changeset
144
kono
parents:
diff changeset
145 -----------------------------
kono
parents:
diff changeset
146 -- Binary_Semaphore_Delete --
kono
parents:
diff changeset
147 -----------------------------
kono
parents:
diff changeset
148
kono
parents:
diff changeset
149 function Binary_Semaphore_Delete (ID : Binary_Semaphore_Id) return int is
kono
parents:
diff changeset
150 begin
kono
parents:
diff changeset
151 return semDelete (SEM_ID (ID));
kono
parents:
diff changeset
152 end Binary_Semaphore_Delete;
kono
parents:
diff changeset
153
kono
parents:
diff changeset
154 -----------------------------
kono
parents:
diff changeset
155 -- Binary_Semaphore_Obtain --
kono
parents:
diff changeset
156 -----------------------------
kono
parents:
diff changeset
157
kono
parents:
diff changeset
158 function Binary_Semaphore_Obtain (ID : Binary_Semaphore_Id) return int is
kono
parents:
diff changeset
159 begin
kono
parents:
diff changeset
160 return semTake (SEM_ID (ID), WAIT_FOREVER);
kono
parents:
diff changeset
161 end Binary_Semaphore_Obtain;
kono
parents:
diff changeset
162
kono
parents:
diff changeset
163 ------------------------------
kono
parents:
diff changeset
164 -- Binary_Semaphore_Release --
kono
parents:
diff changeset
165 ------------------------------
kono
parents:
diff changeset
166
kono
parents:
diff changeset
167 function Binary_Semaphore_Release (ID : Binary_Semaphore_Id) return int is
kono
parents:
diff changeset
168 begin
kono
parents:
diff changeset
169 return semGive (SEM_ID (ID));
kono
parents:
diff changeset
170 end Binary_Semaphore_Release;
kono
parents:
diff changeset
171
kono
parents:
diff changeset
172 ----------------------------
kono
parents:
diff changeset
173 -- Binary_Semaphore_Flush --
kono
parents:
diff changeset
174 ----------------------------
kono
parents:
diff changeset
175
kono
parents:
diff changeset
176 function Binary_Semaphore_Flush (ID : Binary_Semaphore_Id) return int is
kono
parents:
diff changeset
177 begin
kono
parents:
diff changeset
178 return semFlush (SEM_ID (ID));
kono
parents:
diff changeset
179 end Binary_Semaphore_Flush;
kono
parents:
diff changeset
180
kono
parents:
diff changeset
181 ----------
kono
parents:
diff changeset
182 -- kill --
kono
parents:
diff changeset
183 ----------
kono
parents:
diff changeset
184
kono
parents:
diff changeset
185 function kill (pid : t_id; sig : Signal) return int is
kono
parents:
diff changeset
186 begin
kono
parents:
diff changeset
187 return System.VxWorks.Ext.kill (pid, int (sig));
kono
parents:
diff changeset
188 end kill;
kono
parents:
diff changeset
189
kono
parents:
diff changeset
190 -----------------------
kono
parents:
diff changeset
191 -- Interrupt_Connect --
kono
parents:
diff changeset
192 -----------------------
kono
parents:
diff changeset
193
kono
parents:
diff changeset
194 function Interrupt_Connect
kono
parents:
diff changeset
195 (Vector : Interrupt_Vector;
kono
parents:
diff changeset
196 Handler : Interrupt_Handler;
kono
parents:
diff changeset
197 Parameter : System.Address := System.Null_Address) return int is
kono
parents:
diff changeset
198 begin
kono
parents:
diff changeset
199 return
kono
parents:
diff changeset
200 System.VxWorks.Ext.Interrupt_Connect
kono
parents:
diff changeset
201 (System.VxWorks.Ext.Interrupt_Vector (Vector),
kono
parents:
diff changeset
202 System.VxWorks.Ext.Interrupt_Handler (Handler),
kono
parents:
diff changeset
203 Parameter);
kono
parents:
diff changeset
204 end Interrupt_Connect;
kono
parents:
diff changeset
205
kono
parents:
diff changeset
206 -----------------------
kono
parents:
diff changeset
207 -- Interrupt_Context --
kono
parents:
diff changeset
208 -----------------------
kono
parents:
diff changeset
209
kono
parents:
diff changeset
210 function Interrupt_Context return int is
kono
parents:
diff changeset
211 begin
kono
parents:
diff changeset
212 return System.VxWorks.Ext.Interrupt_Context;
kono
parents:
diff changeset
213 end Interrupt_Context;
kono
parents:
diff changeset
214
kono
parents:
diff changeset
215 --------------------------------
kono
parents:
diff changeset
216 -- Interrupt_Number_To_Vector --
kono
parents:
diff changeset
217 --------------------------------
kono
parents:
diff changeset
218
kono
parents:
diff changeset
219 function Interrupt_Number_To_Vector
kono
parents:
diff changeset
220 (intNum : int) return Interrupt_Vector
kono
parents:
diff changeset
221 is
kono
parents:
diff changeset
222 begin
kono
parents:
diff changeset
223 return Interrupt_Vector
kono
parents:
diff changeset
224 (System.VxWorks.Ext.Interrupt_Number_To_Vector (intNum));
kono
parents:
diff changeset
225 end Interrupt_Number_To_Vector;
kono
parents:
diff changeset
226
kono
parents:
diff changeset
227 -----------------
kono
parents:
diff changeset
228 -- Current_CPU --
kono
parents:
diff changeset
229 -----------------
kono
parents:
diff changeset
230
kono
parents:
diff changeset
231 function Current_CPU return Multiprocessors.CPU is
kono
parents:
diff changeset
232 begin
kono
parents:
diff changeset
233 -- ??? Should use vxworks multiprocessor interface
kono
parents:
diff changeset
234
kono
parents:
diff changeset
235 return Multiprocessors.CPU'First;
kono
parents:
diff changeset
236 end Current_CPU;
kono
parents:
diff changeset
237
kono
parents:
diff changeset
238 end System.OS_Interface;