File : s-bbbosu-prep.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 with Interfaces; use Interfaces;
  38 
  39 with System.BB.Parameters;
  40 with System.IOPorts; use System.IOPorts;
  41 
  42 package body System.BB.Board_Support is
  43    use System.BB.Interrupts;
  44 
  45    procedure Initialize_PICs;
  46    --  Initialize the PICs
  47 
  48    subtype Master_Interrupt_IDs is Interrupt_ID range 1 .. 8;
  49    pragma Unreferenced (Master_Interrupt_IDs);
  50    subtype Slave_Interrupt_IDs is Interrupt_ID range 9 .. 16;
  51    --  There are two PICs.  The second one is a slave of the first one
  52 
  53    Master_Pic_Port : constant Port_Id := 16#20#;
  54    Slave_Pic_Port  : constant Port_Id := 16#A0#;
  55    --  PICs port
  56 
  57    ----------------------
  58    -- Initialize_Board --
  59    ----------------------
  60 
  61    procedure Initialize_Board is
  62    begin
  63       Initialize_PICs;
  64    end Initialize_Board;
  65 
  66    ---------------------
  67    -- Initialize_PICs --
  68    ---------------------
  69 
  70    procedure Initialize_PICs is
  71    begin
  72       --  Master PIC
  73 
  74       --  ICW1: ICW4 needed, cascade mode, edge-triggered
  75 
  76       Outb (Master_Pic_Port + 0, 2#0001_0001#);
  77 
  78       --  ICW2: Vector 0-7
  79 
  80       Outb (Master_Pic_Port + 1, 16#00#);
  81 
  82       --  ICW3: (master): slave on int 2
  83 
  84       Outb (Master_Pic_Port + 1, 2#0000_0100#);
  85 
  86       --  ICW4: 8086 mode, normal EOI, buffered mode/master, not special mode
  87 
  88       Outb (Master_Pic_Port + 1, 2#0000_1100#);
  89 
  90       --  Slave PIC
  91 
  92       --  ICW1: ICW4 needed, cascade mode, edge-triggered
  93 
  94       Outb (Slave_Pic_Port + 0, 2#0001_0001#);
  95 
  96       --  ICW2: Vector 8-15
  97 
  98       Outb (Slave_Pic_Port + 1, 16#08#);
  99 
 100       --  ICW3: (slave): slave id 2
 101 
 102       Outb (Slave_Pic_Port + 1, 16#02#);
 103 
 104       --  ICW4: 8086 mode, normal EOI, buffered mode/slave, not special mode
 105 
 106       Outb (Slave_Pic_Port + 1, 2#0000_1000#);
 107 
 108       --  Unmask all interrupts except timer
 109 
 110       Outb (Master_Pic_Port + 1, 1);
 111       Outb (Slave_Pic_Port + 1, 0);
 112    end Initialize_PICs;
 113 
 114    ----------------------
 115    -- Ticks_Per_Second --
 116    ----------------------
 117 
 118    function Ticks_Per_Second return Natural is
 119    begin
 120       --  Frequency of the system clock for the decrementer timer
 121 
 122       return 100_000_000;
 123    end Ticks_Per_Second;
 124 
 125    ---------------------------
 126    -- Clear_Alarm_Interrupt --
 127    ---------------------------
 128 
 129    procedure Clear_Alarm_Interrupt is
 130    begin
 131       --  Nothing to do on standard powerpc
 132 
 133       null;
 134    end Clear_Alarm_Interrupt;
 135 
 136    ---------------------------
 137    -- Get_Interrupt_Request --
 138    ---------------------------
 139 
 140    function Get_Interrupt_Request
 141      (Vector : CPU_Specific.Vector_Id) return Interrupt_ID
 142    is
 143       pragma Unreferenced (Vector);
 144 
 145       Intack : Unsigned_8;
 146       for Intack'Address use 16#BFFFFFF0#;
 147       pragma Volatile (Intack);
 148       pragma Import (Ada, Intack);
 149       --  Prep specific address to send an IACK request on the bus and get
 150       --  the pending interrupt.
 151 
 152    begin
 153       return System.BB.Interrupts.Interrupt_ID (Intack);
 154    end Get_Interrupt_Request;
 155 
 156    -------------------------------
 157    -- Install_Interrupt_Handler --
 158    -------------------------------
 159 
 160    procedure Install_Interrupt_Handler
 161      (Handler   : Address;
 162       Interrupt : Interrupts.Interrupt_ID;
 163       Prio      : Interrupt_Priority)
 164    is
 165       pragma Unreferenced (Interrupt, Prio);
 166    begin
 167       CPU_Specific.Install_Exception_Handler
 168         (Handler, CPU_Specific.External_Interrupt_Excp);
 169    end Install_Interrupt_Handler;
 170 
 171    ---------------------------
 172    -- Priority_Of_Interrupt --
 173    ---------------------------
 174 
 175    function Priority_Of_Interrupt
 176      (Interrupt : System.BB.Interrupts.Interrupt_ID) return System.Any_Priority
 177    is
 178    begin
 179       --  Assert that it is a real interrupt
 180 
 181       pragma Assert (Interrupt /= System.BB.Interrupts.No_Interrupt);
 182 
 183       return Interrupt_Priority'First;
 184    end Priority_Of_Interrupt;
 185 
 186    -----------------------------
 187    -- Clear_Interrupt_Request --
 188    -----------------------------
 189 
 190    procedure Clear_Interrupt_Request
 191      (Interrupt : System.BB.Interrupts.Interrupt_ID)
 192    is
 193    begin
 194       if Interrupt in Slave_Interrupt_IDs then
 195          Outb (Slave_Pic_Port, 2#0010_0000#);
 196       end if;
 197 
 198       Outb (Master_Pic_Port, 2#0010_0000#);
 199    end Clear_Interrupt_Request;
 200 
 201    --------------------------
 202    -- Set_Current_Priority --
 203    --------------------------
 204 
 205    procedure Set_Current_Priority (Priority : Integer) is
 206    begin
 207       --  Note that Priority cannot be the last one, as this procedure is
 208       --  unable to disable the decrementer interrupt.
 209 
 210       pragma Assert (Priority /= Interrupt_Priority'Last);
 211 
 212       null;
 213    end Set_Current_Priority;
 214 
 215    ----------------
 216    -- Power_Down --
 217    ----------------
 218 
 219    procedure Power_Down is
 220    begin
 221       null;
 222    end Power_Down;
 223 
 224 end System.BB.Board_Support;