summaryrefslogtreecommitdiffstats
path: root/gcc/ada/5gtpgetc.adb
blob: 8b02ad9f9fcf1032649ca8aabb5b4e07782c25c8 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
------------------------------------------------------------------------------
--                                                                          --
--                GNU ADA RUN-TIME LIBRARY (GNARL) COMPONENTS               --
--                                                                          --
--     S Y S T E M . T A S K _ P R I M I T I V E S . G E N _ T C B I N F    --
--                                                                          --
--                                 B o d y                                  --
--                                                                          --
--                                                                          --
--              Copyright (C) 1999-2000 Free Software Fundation             --
--                                                                          --
-- GNARL is free software; you can  redistribute it  and/or modify it under --
-- terms of the  GNU General Public License as published  by the Free Soft- --
-- ware  Foundation;  either version 2,  or (at your option) any later ver- --
-- sion. GNARL is distributed in the hope that it will be useful, but WITH- --
-- OUT ANY WARRANTY;  without even the  implied warranty of MERCHANTABILITY --
-- or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License --
-- for  more details.  You should have  received  a copy of the GNU General --
-- Public License  distributed with GNARL; see file COPYING.  If not, write --
-- to  the Free Software Foundation,  59 Temple Place - Suite 330,  Boston, --
-- MA 02111-1307, USA.                                                      --
--                                                                          --
-- As a special exception,  if other files  instantiate  generics from this --
-- unit, or you link  this unit with other files  to produce an executable, --
-- this  unit  does not  by itself cause  the resulting  executable  to  be --
-- covered  by the  GNU  General  Public  License.  This exception does not --
-- however invalidate  any other reasons why  the executable file  might be --
-- covered by the  GNU Public License.                                      --
--                                                                          --
-- GNARL was developed by the GNARL team at Florida State University.       --
-- Extensive contributions were provided by Ada Core Technologies Inc.      --
--                                                                          --
------------------------------------------------------------------------------

--  This is an SGI Irix version of this package

--  This procedure creates the file "a-tcbinf.c"
--  "A-tcbinf.c" is subsequently compiled and made part of the RTL
--  to be referenced by the SGI Workshop debugger. The main procedure:
--  "Gen_Tcbinf" imports this child procedure and runs as part of the
--  RTL build process. Because of the complex process used to build
--  the GNAT RTL for all the different systems and the frequent changes
--  made to the internal data structures, its impractical to create
--  "a-tcbinf.c" using a standalone process.
with System.Tasking;
with Ada.Text_IO;
with Unchecked_Conversion;

procedure System.Task_Primitives.Gen_Tcbinf is

   use System.Tasking;

   subtype Version_String is String (1 .. 4);

   Version : constant Version_String := "3.11";

   function To_Integer is new Unchecked_Conversion
     (Version_String, Integer);

   type Dummy_TCB_Ptr is access Ada_Task_Control_Block (Entry_Num => 0);
   Dummy_TCB : constant Dummy_TCB_Ptr := new Ada_Task_Control_Block (0);

   C_File : Ada.Text_IO.File_Type;

   procedure Pl (S : String);
   procedure Nl (C : Ada.Text_IO.Positive_Count := 1);
   function State_Name (S : Task_States) return String;

   procedure Pl (S : String) is
   begin
      Ada.Text_IO.Put_Line (C_File, S);
   end Pl;

   procedure Nl (C : Ada.Text_IO.Positive_Count := 1) is
   begin
      Ada.Text_IO.New_Line (C_File, C);
   end Nl;

   function State_Name (S : Task_States) return String is
   begin
      case S is
         when Unactivated =>
            return "Unactivated";
         when Runnable =>
            return "Runnable";
         when Terminated =>
            return "Terminated";
         when Activator_Sleep =>
            return "Child Activation Wait";
         when Acceptor_Sleep =>
            return "Accept/Select Wait";
         when Entry_Caller_Sleep =>
            return "Waiting on Entry Call";
         when Async_Select_Sleep =>
            return "Async_Select Wait";
         when Delay_Sleep =>
            return "Delay Sleep";
         when Master_Completion_Sleep =>
            return "Child Termination Wait";
         when Master_Phase_2_Sleep =>
            return "Wait Child in Term Alt";
         when Interrupt_Server_Idle_Sleep =>
            return "Int Server Idle Sleep";
         when Interrupt_Server_Blocked_Interrupt_Sleep =>
            return "Int Server Blk Int Sleep";
         when Timer_Server_Sleep =>
            return "Timer Server Sleep";
         when AST_Server_Sleep =>
            return "AST Server Sleep";
         when Asynchronous_Hold =>
            return "Asynchronous Hold";
         when Interrupt_Server_Blocked_On_Event_Flag =>
            return "Int Server Blk Evt Flag";
      end case;
   end State_Name;

   All_Tasks_Link_Offset   : constant Integer
     := Dummy_TCB.Common'Position + Dummy_TCB.Common.All_Tasks_Link'Position;
   Entry_Count_Offset      : constant Integer
     := Dummy_TCB.Entry_Num'Position;
   Entry_Point_Offset      : constant Integer
     := Dummy_TCB.Common'Position + Dummy_TCB.Common.Task_Entry_Point'Position;
   Parent_Offset           : constant Integer
     := Dummy_TCB.Common'Position + Dummy_TCB.Common.Parent'Position;
   Base_Priority_Offset    : constant Integer
     := Dummy_TCB.Common'Position + Dummy_TCB.Common.Base_Priority'Position;
   Current_Priority_Offset : constant Integer
     := Dummy_TCB.Common'Position + Dummy_TCB.Common.Current_Priority'Position;
   Stack_Size_Offset       : constant Integer
     := Dummy_TCB.Common'Position +
       Dummy_TCB.Common.Compiler_Data.Pri_Stack_Info.Size'Position;
   State_Offset            : constant Integer
     := Dummy_TCB.Common'Position + Dummy_TCB.Common.State'Position;
   Task_Image_Offset       : constant Integer
     := Dummy_TCB.Common'Position + Dummy_TCB.Common.Task_Image'Position;
   Thread_Offset           : constant Integer
     := Dummy_TCB.Common'Position + Dummy_TCB.Common.LL'Position +
        Dummy_TCB.Common.LL.Thread'Position;

begin

   Ada.Text_IO.Create (C_File, Ada.Text_IO.Out_File, "a-tcbinf.c");

   Pl ("");
   Pl ("#include <sys/types.h>");
   Pl ("");
   Pl ("#define TCB_INFO_VERSION 2");
   Pl ("#define TCB_LIBRARY_VERSION "
     & Integer'Image (To_Integer (Version)));
   Pl ("");
   Pl ("typedef struct {");
   Pl ("");
   Pl ("   __uint32_t   info_version;");
   Pl ("   __uint32_t   library_version;");
   Pl ("");
   Pl ("   __uint32_t   All_Tasks_Link_Offset;");
   Pl ("   __uint32_t   Entry_Count_Offset;");
   Pl ("   __uint32_t   Entry_Point_Offset;");
   Pl ("   __uint32_t   Parent_Offset;");
   Pl ("   __uint32_t   Base_Priority_Offset;");
   Pl ("   __uint32_t   Current_Priority_Offset;");
   Pl ("   __uint32_t   Stack_Size_Offset;");
   Pl ("   __uint32_t   State_Offset;");
   Pl ("   __uint32_t   Task_Image_Offset;");
   Pl ("   __uint32_t   Thread_Offset;");
   Pl ("");
   Pl ("   char         **state_names;");
   Pl ("   __uint32_t   state_names_max;");
   Pl ("");
   Pl ("} task_control_block_info_t;");
   Pl ("");
   Pl ("static char *accepting_state_names = NULL;");

   Pl ("");
   Pl ("static char *task_state_names[] = {");

   for State in Task_States loop
      Pl ("   """ & State_Name (State) & """,");
   end loop;
   Pl ("   """"};");

   Pl ("");
   Pl ("");
   Pl ("task_control_block_info_t __task_control_block_info = {");
   Pl ("");
   Pl ("   TCB_INFO_VERSION,");
   Pl ("   TCB_LIBRARY_VERSION,");
   Pl ("");
   Pl ("   " & All_Tasks_Link_Offset'Img & ",");
   Pl ("   " & Entry_Count_Offset'Img & ",");
   Pl ("   " & Entry_Point_Offset'Img & ",");
   Pl ("   " & Parent_Offset'Img & ",");
   Pl ("   " & Base_Priority_Offset'Img & ",");
   Pl ("   " & Current_Priority_Offset'Img & ",");
   Pl ("   " & Stack_Size_Offset'Img & ",");
   Pl ("   " & State_Offset'Img & ",");
   Pl ("   " & Task_Image_Offset'Img & ",");
   Pl ("   " & Thread_Offset'Img & ",");
   Pl ("");
   Pl ("   task_state_names,");
   Pl ("   sizeof (task_state_names),");
   Pl ("");
   Pl ("");
   Pl ("};");

   Ada.Text_IO.Close (C_File);

end System.Task_Primitives.Gen_Tcbinf;
OpenPOWER on IntegriCloud