File : s-bbbosu-p55.adb


   1 ------------------------------------------------------------------------------
   2 --                                                                          --
   3 --                  GNAT RUN-TIME LIBRARY (GNARL) COMPONENTS                --
   4 --                                                                          --
   5 --                S Y S T E M . B B . B O A R D _ S U P P O R T             --
   6 --                                                                          --
   7 --                                  B o d y                                 --
   8 --                                                                          --
   9 --        Copyright (C) 1999-2002 Universidad Politecnica de Madrid         --
  10 --             Copyright (C) 2003-2005 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 -- GNAT was originally developed  by the GNAT team at  New York University. --
  30 -- Extensive contributions were provided by Ada Core Technologies Inc.      --
  31 --                                                                          --
  32 -- The port of GNARL to bare board targets was initially developed by the   --
  33 -- Real-Time Systems Group at the Technical University of Madrid.           --
  34 --                                                                          --
  35 ------------------------------------------------------------------------------
  36 
  37 --  Board support for mpc5566
  38 
  39 with Interfaces; use Interfaces;
  40 
  41 with System.BB.Board_Parameters;
  42 with System.Machine_Code;
  43 
  44 package body System.BB.Board_Support is
  45 
  46    ----------------------
  47    -- Initialize_Board --
  48    ----------------------
  49 
  50    procedure Initialize_Board is
  51       INTC_MCR : Unsigned_32;
  52       for INTC_MCR'Address use 16#FFF4_8000#;
  53       pragma Volatile (INTC_MCR);
  54       pragma Import (Ada, INTC_MCR);
  55 
  56    begin
  57       --  Initialize the INTC
  58 
  59       INTC_MCR := 0; -- VTES=0, HVEN=0
  60 
  61       --  Mask interrupts
  62 
  63       Set_Current_Priority (Interrupt_Priority'Last - 1);
  64    end Initialize_Board;
  65 
  66    ---------------------------
  67    -- Clear_Alarm_Interrupt --
  68    ---------------------------
  69 
  70    procedure Clear_Alarm_Interrupt is
  71       use System.Machine_Code;
  72 
  73    begin
  74       --  Clear TSR[DIS]
  75 
  76       Asm ("mtspr 336,%0",
  77            Inputs => Unsigned_32'Asm_Input ("r", 2 ** (63 - 36)),
  78            Volatile => True);
  79    end Clear_Alarm_Interrupt;
  80 
  81    ---------------------------
  82    -- Get_Interrupt_Request --
  83    ---------------------------
  84 
  85    function Get_Interrupt_Request
  86      (Vector : CPU_Specific.Vector_Id)
  87       return System.BB.Interrupts.Interrupt_ID is
  88       pragma Unreferenced (Vector);
  89 
  90       INTC_IACKR : Unsigned_32;
  91       for INTC_IACKR'Address use 16#FFF4_8010#;
  92       pragma Volatile (INTC_IACKR);
  93       pragma Import (Ada, INTC_IACKR);
  94       --  Interrupt acknowledge register
  95 
  96    begin
  97       return System.BB.Interrupts.Interrupt_ID ((INTC_IACKR and 16#7FC#) / 4);
  98    end Get_Interrupt_Request;
  99 
 100    -------------------------------
 101    -- Install_Interrupt_Handler --
 102    -------------------------------
 103 
 104    procedure Install_Interrupt_Handler
 105      (Handler   : Address;
 106       Interrupt : Interrupts.Interrupt_ID;
 107       Prio      : Interrupt_Priority)
 108    is
 109       pragma Unreferenced (Interrupt, Prio);
 110    begin
 111       CPU_Specific.Install_Exception_Handler
 112         (Handler, CPU_Specific.External_Interrupt_Excp);
 113    end Install_Interrupt_Handler;
 114 
 115    ---------------------------
 116    -- Priority_Of_Interrupt --
 117    ---------------------------
 118 
 119    function Priority_Of_Interrupt
 120      (Interrupt : System.BB.Interrupts.Interrupt_ID) return System.Any_Priority
 121    is
 122       type Intc_Psr_Type is
 123         array (System.BB.Interrupts.Interrupt_ID) of Unsigned_8;
 124       INTC_PSR : Intc_Psr_Type;
 125       for INTC_PSR'Address use 16#FFF4_8040#;
 126       pragma Volatile (INTC_PSR);
 127       pragma Import (Ada, INTC_PSR);
 128    begin
 129       return Interrupt_Priority'First +
 130                Natural (INTC_PSR (Interrupt) and 16#0F#);
 131    end Priority_Of_Interrupt;
 132 
 133    ----------------
 134    -- Power_Down --
 135    ----------------
 136 
 137    procedure Power_Down is
 138    begin
 139       null;
 140    end Power_Down;
 141 
 142    -----------------------------
 143    -- Clear_Interrupt_Request --
 144    -----------------------------
 145 
 146    procedure Clear_Interrupt_Request
 147      (Interrupt : System.BB.Interrupts.Interrupt_ID)
 148    is
 149       pragma Unreferenced (Interrupt);
 150 
 151       INTC_EOIR : Unsigned_32;
 152       for INTC_EOIR'Address use 16#FFF4_8018#;
 153       pragma Volatile (INTC_EOIR);
 154       pragma Import (Ada, INTC_EOIR);
 155       --  INTC end of interrupt register
 156    begin
 157       INTC_EOIR := 0;
 158    end Clear_Interrupt_Request;
 159 
 160    --------------------------
 161    -- Set_Current_Priority --
 162    --------------------------
 163 
 164    procedure Set_Current_Priority (Priority : Integer) is
 165       INTC_CPR : Unsigned_32;
 166       for INTC_CPR'Address use 16#FFF4_8008#;
 167       pragma Volatile (INTC_CPR);
 168       pragma Import (Ada, INTC_CPR);
 169       --  INTC current priority register
 170 
 171    begin
 172       --  Note that Priority cannot be the last one, as this procedure is
 173       --  unable to disable the decrementer interrupt.
 174 
 175       pragma Assert (Priority /= Interrupt_Priority'Last);
 176 
 177       if Priority in Interrupt_Priority then
 178          INTC_CPR := Unsigned_32 (Priority - Interrupt_Priority'First);
 179       else
 180          INTC_CPR := 0;
 181       end if;
 182    end Set_Current_Priority;
 183 
 184 end System.BB.Board_Support;