forked from AdaCore/bb-runtimes
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy paths-bbsuti__ppc.adb
155 lines (132 loc) · 5.73 KB
/
s-bbsuti__ppc.adb
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
------------------------------------------------------------------------------
-- --
-- GNAT RUN-TIME LIBRARY (GNARL) COMPONENTS --
-- --
-- S Y S T E M . B B . B O A R D _ S U P P O R T . T I M E --
-- --
-- B o d y --
-- --
-- Copyright (C) 1999-2002 Universidad Politecnica de Madrid --
-- Copyright (C) 2003-2005 The European Space Agency --
-- Copyright (C) 2003-2017, AdaCore --
-- --
-- GNAT 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 3, or (at your option) any later ver- --
-- sion. GNAT 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. --
-- --
-- As a special exception under Section 7 of GPL version 3, you are granted --
-- additional permissions described in the GCC Runtime Library Exception, --
-- version 3.1, as published by the Free Software Foundation. --
-- --
-- You should have received a copy of the GNU General Public License and --
-- a copy of the GCC Runtime Library Exception along with this program; --
-- see the files COPYING3 and COPYING.RUNTIME respectively. If not, see --
-- <http://www.gnu.org/licenses/>. --
-- --
-- GNAT was originally developed by the GNAT team at New York University. --
-- Extensive contributions were provided by Ada Core Technologies Inc. --
-- --
-- The port of GNARL to bare board targets was initially developed by the --
-- Real-Time Systems Group at the Technical University of Madrid. --
-- --
------------------------------------------------------------------------------
-- For PowerPc: use time base and decrementer registers from the core
with System.Machine_Code; use System.Machine_Code;
separate (System.BB.Board_Support)
package body Time is
-----------------------
-- Local Definitions --
-----------------------
type Unsigned_32 is mod 2 ** 32;
for Unsigned_32'Size use 32;
-- Values of this type represent number of times that the clock finishes
-- its countdown. This type should allow atomic reads and updates.
function Read_TBL return Unsigned_32;
pragma Inline (Read_TBL);
-- Read the Time Base Lower word
function Read_TBU return Unsigned_32;
pragma Inline (Read_TBU);
-- Read the Time Base Upper word
----------------
-- Read_Clock --
----------------
function Read_Clock return BB.Time.Time is
use type BB.Time.Time;
Lo : Unsigned_32;
Hi : Unsigned_32;
Hi1 : Unsigned_32;
begin
-- We can't atomically read the 64-bits counter. So check that the
-- 32 MSB don't change.
Hi := Read_TBU;
loop
Lo := Read_TBL;
Hi1 := Read_TBU;
exit when Hi = Hi1;
Hi := Hi1;
end loop;
return (BB.Time.Time (Hi) * 2 ** 32) + BB.Time.Time (Lo);
end Read_Clock;
---------------------------
-- Install_Alarm_Handler --
---------------------------
procedure Install_Alarm_Handler
(Handler : BB.Interrupts.Interrupt_Handler) is
begin
CPU_Specific.Install_Exception_Handler
(Handler.all'Address, CPU_Specific.Decrementer_Excp);
end Install_Alarm_Handler;
--------------
-- Read_TBL --
--------------
function Read_TBL return Unsigned_32 is
Res : Unsigned_32;
begin
Asm ("mftbl %0",
Outputs => Unsigned_32'Asm_Output ("=r", Res),
Volatile => True);
return Res;
end Read_TBL;
--------------
-- Read_TBU --
--------------
function Read_TBU return Unsigned_32 is
Res : Unsigned_32;
begin
Asm ("mftbu %0",
Outputs => Unsigned_32'Asm_Output ("=r", Res),
Volatile => True);
return Res;
end Read_TBU;
---------------
-- Set_Alarm --
---------------
procedure Set_Alarm (Ticks : BB.Time.Time)
is
use BB.Time;
Now : constant BB.Time.Time := Read_Clock;
Diff : constant Unsigned_64 :=
(if Ticks > Now then Unsigned_64 (Ticks - Now) else 1);
Val : Unsigned_32;
begin
if Diff >= 2 ** 31 then
Val := 16#7FFF_FFFF#;
-- The maximum value that can be set in the DEC register. MSB must
-- not be set to avoid a useless interrupt (PowerPC triggers an
-- interrupt when the MSB switches from 0 to 1).
else
Val := Unsigned_32 (Diff);
end if;
Asm ("mtdec %0",
Inputs => Unsigned_32'Asm_Input ("r", Val),
Volatile => True);
end Set_Alarm;
---------------------------
-- Clear_Alarm_Interrupt --
---------------------------
procedure Clear_Alarm_Interrupt
renames BB.Board_Support.Clear_Alarm_Interrupt;
end Time;