atomic_0.5.0_14c344cc/src/armv6m/atomic-critical_section.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
with System.Machine_Code; use System.Machine_Code;

package body Atomic.Critical_Section is

   -----------
   -- Enter --
   -----------

   procedure Enter (State : out Interrupt_State) is
      NL : constant String := ASCII.CR & ASCII.LF;
   begin
      System.Machine_Code.Asm
        (Template =>
           "dsb" & NL &             -- Ensure completion of memory accesses
           "mrs %0, PRIMASK" & NL & -- Save PRIMASK State
           "cpsid i",               -- Clear PRIMASK
         Outputs  => Interrupt_State'Asm_Output ("=r", State),
         Inputs   => No_Input_Operands,
         Clobber  => "",
         Volatile => True);
   end Enter;

   -----------
   -- Leave --
   -----------

   procedure Leave (State : Interrupt_State) is
      NL : constant String := ASCII.CR & ASCII.LF;
   begin
      System.Machine_Code.Asm
        (Template =>
           "dsb" & NL &       -- Ensure completion of memory accesses
           "msr PRIMASK, %0", -- restore PRIMASK
         Outputs  => No_Output_Operands,
         Inputs   => Interrupt_State'Asm_Input ("r", State),
         Clobber  => "",
         Volatile => True);
   end Leave;

end Atomic.Critical_Section;