File : s-bbcppr.ads
1 ------------------------------------------------------------------------------
2 -- --
3 -- GNAT RUN-TIME LIBRARY (GNARL) COMPONENTS --
4 -- --
5 -- S Y S T E M . B B . C P U _ P R I M I T I V E S --
6 -- --
7 -- S p e c --
8 -- --
9 -- Copyright (C) 1999-2002 Universidad Politecnica de Madrid --
10 -- Copyright (C) 2003-2004 The European Space Agency --
11 -- Copyright (C) 2003-2016, AdaCore --
12 -- --
13 -- GNAT is free software; you can redistribute it and/or modify it under --
14 -- terms of the GNU General Public License as published by the Free Soft- --
15 -- ware Foundation; either version 3, or (at your option) any later ver- --
16 -- sion. GNAT is distributed in the hope that it will be useful, but WITH- --
17 -- OUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY --
18 -- or FITNESS FOR A PARTICULAR PURPOSE. --
19 -- --
20 -- --
21 -- --
22 -- --
23 -- --
24 -- You should have received a copy of the GNU General Public License and --
25 -- a copy of the GCC Runtime Library Exception along with this program; --
26 -- see the files COPYING3 and COPYING.RUNTIME respectively. If not, see --
27 -- <http://www.gnu.org/licenses/>. --
28 -- --
29 ------------------------------------------------------------------------------
30
31 -- This package contains the primitives which are dependent on the
32 -- underlying processor.
33
34 pragma Restrictions (No_Elaboration_Code);
35
36 with System;
37 with System.BB.Parameters;
38
39 package System.BB.CPU_Primitives is
40 pragma Preelaborate;
41
42 type Word is mod 2**System.Word_Size;
43
44 ------------------------
45 -- Context management --
46 ------------------------
47
48 -- The context buffer is an abstract type that holds all values indexed by
49 -- Context_Id that make up a thread's state which are not otherwise stored
50 -- in main memory. This typically includes all user-visible registers, and
51 -- possibly some other status as well.
52
53 -- In case different contexts have different amounts of state (for example,
54 -- due to absence of a floating-point unit in a particular configuration,
55 -- or just the FPU not being used), it is expected that these details
56 -- are handled in the implementation, which should ignore updates of
57 -- unsupported state and return a default value for queries of such state.
58
59 type Context_Buffer is private;
60
61 type Context_Id is range 0 .. Parameters.Context_Buffer_Capacity - 1;
62 -- Type used for accessing to the different elements in the context buffer
63
64 procedure Context_Switch;
65 pragma Inline (Context_Switch);
66 -- Perform the context switch between the running_thread and the
67 -- first_thread. The value of running_thread will be updated.
68
69 function Get_Context
70 (Context : Context_Buffer;
71 Index : Context_Id) return Word;
72 pragma Inline (Get_Context);
73 -- Returns item of the specified context.
74
75 procedure Set_Context
76 (Context : in out Context_Buffer;
77 Index : Context_Id;
78 Value : Word);
79 pragma Inline (Set_Context);
80 -- Updates the given context.
81
82 procedure Initialize_Context
83 (Buffer : not null access Context_Buffer;
84 Program_Counter : System.Address;
85 Argument : System.Address;
86 Stack_Pointer : System.Address);
87 pragma Inline (Initialize_Context);
88 -- Initialize_Context inserts inside the context buffer the default
89 -- values for each register. The values for the stack pointer, the
90 -- program counter, and argument to be passed are provided as arguments.
91
92 ---------------------------------
93 -- Interrupt and trap handling --
94 ---------------------------------
95
96 type Vector_Id is range 0 .. Parameters.Trap_Vectors - 1;
97
98 procedure Install_Error_Handlers;
99 pragma Inline (Install_Error_Handlers);
100 -- Called at system initialization time to install a CPU specific
101 -- trap handler, GNAT_Error_Handler, that converts synchronous traps
102 -- to appropriate exceptions.
103
104 procedure Install_Trap_Handler
105 (Service_Routine : System.Address;
106 Vector : Vector_Id;
107 Synchronous : Boolean := False);
108 -- Install a new handler in the trap table, both for synchronous and
109 -- asynchronous traps. Interrupts must be disabled before the trap
110 -- handler is called.
111
112 procedure Disable_Interrupts;
113 pragma Inline (Disable_Interrupts);
114 -- All external interrupts (asynchronous traps) are disabled. Note
115 -- that this will take care of the CPU specific part of enabling and
116 -- disabling the interrupts. For systems were this is not sufficient, the
117 -- Board_Support.Set_Current_Priority routine must also be implemented in
118 -- order to do the board-specific enable/disable operations.
119
120 procedure Enable_Interrupts (Level : Integer);
121 pragma Inline (Enable_Interrupts);
122 -- Interrupts are enabled if they are above the value given by Level
123
124 procedure Initialize_CPU;
125 pragma Inline (Initialize_CPU);
126 -- Set the CPU up to use the proper stack for interrupts, initialize and
127 -- enable system trap handlers.
128
129 private
130 Context_Buffer_Size : constant :=
131 Parameters.Context_Buffer_Capacity * System.Word_Size;
132 -- Size calculated taken into account that the components are 32-bit, and
133 -- that we want then aligned on 64-bit boundaries.
134
135 type Context_Buffer is array (Context_Id) of System.Address;
136 for Context_Buffer'Size use Context_Buffer_Size;
137 for Context_Buffer'Alignment use 8;
138 -- This array contains all the registers that the thread needs to save
139 -- within its thread descriptor. Using double word boundaries allows us
140 -- to use double word loads and stores safely in the context switch.
141
142 end System.BB.CPU_Primitives;