OSDN Git Service

2003-12-05 Thomas Quinot <quinot@act-europe.fr>
[pf3gnuchains/gcc-fork.git] / gcc / ada / 5zthrini.adb
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 --                                                                          --
9 --            Copyright (C) 1992-2003 Free Software Foundation, Inc.        --
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;
38 with System.Storage_Elements;
39 with System.Soft_Links;
40 with Interfaces.C;
41
42 package body System.Threads.Initialization is
43
44    use Interfaces.C;
45
46    package SSS renames System.Secondary_Stack;
47
48    package SSL renames System.Soft_Links;
49
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
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
78    --------------
79    -- Register --
80    --------------
81
82    function Register (T : OSI.Thread_Id) return OSI.STATUS is
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
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.
93
94       if OSI.taskIdVerify (T) = OSI.ERROR then
95          return OSI.ERROR;
96       end if;
97
98       Result := OSI.taskVarAdd (T, Current_ATSD'Access);
99       pragma Assert (Result /= OSI.ERROR);
100
101       return Result;
102    end Register;
103
104    subtype Default_Sec_Stack is
105      System.Storage_Elements.Storage_Array
106        (1 .. SSS.Default_Secondary_Stack_Size);
107
108    Main_Sec_Stack : aliased Default_Sec_Stack;
109
110    --  Secondary stack for environment task
111
112    Main_ATSD : aliased ATSD;
113
114    --  TSD for environment task
115
116 begin
117    Initialize_Task_Hooks;
118
119    --  Register the environment task
120    declare
121       Result : Interfaces.C.int := Register (OSI.taskIdSelf);
122       pragma Assert (Result /= OSI.ERROR);
123    begin
124       Thread_Body_Enter
125         (Main_Sec_Stack'Address,
126          Main_Sec_Stack'Size / System.Storage_Unit,
127          Main_ATSD'Address);
128    end;
129 end System.Threads.Initialization;