]>
Commit | Line | Data |
---|---|---|
fbf5a39b AC |
1 | ------------------------------------------------------------------------------ |
2 | -- -- | |
3 | -- GNAT COMPILER COMPONENTS -- | |
4 | -- -- | |
5 | -- S Y S T E M . T H R E A D S . I N I T I A L I Z A T I O N -- | |
6 | -- -- | |
7 | -- B o d y -- | |
8 | -- -- | |
65356e64 | 9 | -- Copyright (C) 1992-2003 Free Software Foundation, Inc. -- |
fbf5a39b AC |
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 2, 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. 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 GNAT; 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 | -- GNAT was originally developed by the GNAT team at New York University. -- | |
30 | -- Extensive contributions were provided by Ada Core Technologies Inc. -- | |
31 | -- -- | |
32 | ------------------------------------------------------------------------------ | |
33 | ||
34 | -- This is the VxWorks version of this package; to use this implementation, | |
35 | -- the task hook libraries should be included in the VxWorks kernel. | |
36 | ||
37 | with System.Secondary_Stack; | |
9596236a | 38 | with System.Storage_Elements; |
65356e64 | 39 | with System.Soft_Links; |
fbf5a39b | 40 | with Interfaces.C; |
fbf5a39b AC |
41 | |
42 | package body System.Threads.Initialization is | |
43 | ||
44 | use Interfaces.C; | |
45 | ||
46 | package SSS renames System.Secondary_Stack; | |
47 | ||
65356e64 AC |
48 | package SSL renames System.Soft_Links; |
49 | ||
fbf5a39b AC |
50 | procedure Initialize_Task_Hooks; |
51 | -- Register the appropriate hooks (Register and Reset_TSD) to the | |
52 | -- underlying OS, so that they will be called when a task is created | |
53 | -- or reset. | |
54 | ||
55 | Current_ATSD : aliased System.Address; | |
56 | pragma Import (C, Current_ATSD, "__gnat_current_atsd"); | |
57 | ||
58 | --------------------------- | |
59 | -- Initialize_Task_Hooks -- | |
60 | --------------------------- | |
61 | ||
62 | procedure Initialize_Task_Hooks is separate; | |
63 | -- Separate, as these hooks are different for AE653 and VxWorks 5.5. | |
64 | ||
65356e64 AC |
65 | -------------- |
66 | -- Init_RTS -- | |
67 | -------------- | |
68 | ||
69 | procedure Init_RTS is | |
70 | begin | |
71 | SSL.Get_Jmpbuf_Address := Get_Jmpbuf_Address'Access; | |
72 | SSL.Get_Sec_Stack_Addr := Get_Sec_Stack_Addr'Access; | |
73 | SSL.Get_Current_Excep := Get_Current_Excep'Access; | |
74 | SSL.Set_Jmpbuf_Address := Set_Jmpbuf_Address'Access; | |
75 | SSL.Set_Sec_Stack_Addr := Set_Sec_Stack_Addr'Access; | |
76 | end Init_RTS; | |
77 | ||
fbf5a39b AC |
78 | -------------- |
79 | -- Register -- | |
80 | -------------- | |
81 | ||
82 | function Register (T : OSI.Thread_Id) return OSI.STATUS is | |
fbf5a39b AC |
83 | Result : OSI.STATUS; |
84 | begin | |
85 | -- It cannot be assumed that the caller of this routine has a ATSD; | |
86 | -- so neither this procedure nor the procedures that it calls should | |
9596236a AC |
87 | -- raise or handle exceptions, or make use of a secondary stack. |
88 | ||
89 | -- This routine is only necessary because taskVarAdd cannot be | |
90 | -- executed once an AE653 partition has entered normal mode | |
91 | -- (depending on configRecord.c, allocation could be disabled). | |
92 | -- Otherwise, everything could have been done in Thread_Body_Enter. | |
fbf5a39b | 93 | |
65356e64 | 94 | if OSI.taskIdVerify (T) = OSI.ERROR then |
fbf5a39b AC |
95 | return OSI.ERROR; |
96 | end if; | |
97 | ||
98 | Result := OSI.taskVarAdd (T, Current_ATSD'Access); | |
9596236a AC |
99 | pragma Assert (Result /= OSI.ERROR); |
100 | ||
fbf5a39b AC |
101 | return Result; |
102 | end Register; | |
103 | ||
9596236a AC |
104 | subtype Default_Sec_Stack is |
105 | System.Storage_Elements.Storage_Array | |
106 | (1 .. SSS.Default_Secondary_Stack_Size); | |
fbf5a39b | 107 | |
9596236a | 108 | Main_Sec_Stack : aliased Default_Sec_Stack; |
fbf5a39b | 109 | |
9596236a | 110 | -- Secondary stack for environment task |
fbf5a39b | 111 | |
9596236a AC |
112 | Main_ATSD : aliased ATSD; |
113 | ||
114 | -- TSD for environment task | |
fbf5a39b AC |
115 | |
116 | begin | |
117 | Initialize_Task_Hooks; | |
65356e64 | 118 | Init_RTS; |
9596236a AC |
119 | |
120 | -- Register the environment task | |
121 | declare | |
122 | Result : Interfaces.C.int := Register (OSI.taskIdSelf); | |
123 | pragma Assert (Result /= OSI.ERROR); | |
124 | begin | |
125 | Thread_Body_Enter | |
126 | (Main_Sec_Stack'Address, | |
127 | Main_Sec_Stack'Size / System.Storage_Unit, | |
128 | Main_ATSD'Address); | |
129 | end; | |
fbf5a39b | 130 | end System.Threads.Initialization; |