Index: bsps/sparc/leon2/start/bsp_specs
===================================================================
--- bsps/sparc/leon2/start/bsp_specs	(revision 99648958668d3a33ee57974479b36201fe303f34)
+++ bsps/sparc/leon2/start/bsp_specs	(revision 99648958668d3a33ee57974479b36201fe303f34)
@@ -0,0 +1,9 @@
+%rename endfile old_endfile
+%rename startfile old_startfile
+
+*startfile:
+%{!qrtems: %(old_startfile)} \
+%{!nostdlib: %{qrtems: crti.o%s crtbegin.o%s}}
+
+*endfile:
+%{!qrtems: %(old_endfile)} %{qrtems: crtend.o%s crtn.o%s}
Index: bsps/sparc/leon2/start/bspdelay.c
===================================================================
--- bsps/sparc/leon2/start/bspdelay.c	(revision 99648958668d3a33ee57974479b36201fe303f34)
+++ bsps/sparc/leon2/start/bspdelay.c	(revision 99648958668d3a33ee57974479b36201fe303f34)
@@ -0,0 +1,27 @@
+/**
+ * @file
+ * @ingroup sparc_leon2
+ * @brief LEON2 BSP Delay Method
+ */
+
+/*
+ *  COPYRIGHT (c) 1989-2011.
+ *  On-Line Applications Research Corporation (OAR).
+ *
+ *  The license and distribution terms for this file may be
+ *  found in the file LICENSE in this distribution or at
+ *  http://www.rtems.org/license/LICENSE.
+ */
+
+#include <bsp.h>
+
+void rtems_bsp_delay(int usecs)
+{
+  uint32_t then;
+
+  then  = LEON_REG.Timer_Counter_1;
+  then += usecs;
+
+  while (LEON_REG.Timer_Counter_1 >= then)
+    ;
+}
Index: bsps/sparc/leon2/start/bspidle.c
===================================================================
--- bsps/sparc/leon2/start/bspidle.c	(revision 99648958668d3a33ee57974479b36201fe303f34)
+++ bsps/sparc/leon2/start/bspidle.c	(revision 99648958668d3a33ee57974479b36201fe303f34)
@@ -0,0 +1,35 @@
+/**
+ * @file
+ * @ingroup sparc_leon2
+ * @brief LEON2 Idle Thread 
+ */
+
+/*
+ *  LEON2 Idle Thread with power-down function
+ *
+ *  COPYRIGHT (c) 1989-2009.
+ *  On-Line Applications Research Corporation (OAR).
+ *
+ *  The license and distribution terms for this file may be
+ *  found in the file LICENSE in this distribution or at
+ *  http://www.rtems.org/license/LICENSE.
+ *
+ *  Ported to LEON implementation of the SPARC by On-Line Applications
+ *  Research Corporation (OAR) under contract to the European Space
+ *  Agency (ESA).
+ *
+ *  LEON modifications of respective RTEMS file: COPYRIGHT (c) 1995.
+ *  European Space Agency.
+ */
+
+#include <bsp.h>
+
+void *bsp_idle_thread( uintptr_t ignored )
+{
+  while (1) {
+    /* make sure on load follows store to power-down reg */
+    LEON_REG.Power_Down = LEON_REG.Power_Down;
+  }
+  return NULL;
+}
+
Index: bsps/sparc/leon2/start/bspstart.c
===================================================================
--- bsps/sparc/leon2/start/bspstart.c	(revision 99648958668d3a33ee57974479b36201fe303f34)
+++ bsps/sparc/leon2/start/bspstart.c	(revision 99648958668d3a33ee57974479b36201fe303f34)
@@ -0,0 +1,127 @@
+/**
+ * @file
+ * @ingroup sparc_leon2
+ * @brief LEON2 Cache Snooping Support
+ */
+
+/*
+ *  LEON2 Cache Snooping Support
+ *
+ *  COPYRIGHT (c) 2011
+ *  Aeroflex Gaisler
+ *
+ *  COPYRIGHT (c) 1989-2009.
+ *  On-Line Applications Research Corporation (OAR).
+ *
+ *  The license and distribution terms for this file may be
+ *  found in the file LICENSE in this distribution or at
+ *  http://www.rtems.org/license/LICENSE.
+ *
+ *  Ported to ERC32 implementation of the SPARC by On-Line Applications
+ *  Research Corporation (OAR) under contract to the European Space
+ *  Agency (ESA).
+ *
+ *  ERC32 modifications of respective RTEMS file: COPYRIGHT (c) 1995.
+ *  European Space Agency.
+ */
+
+#include <bsp.h>
+#include <bsp/bootcard.h>
+#include <rtems/sysinit.h>
+
+/*
+ * Tells us if data cache snooping is available
+ */
+int CPU_SPARC_HAS_SNOOPING;
+
+/*
+ * set_snooping
+ *
+ * Read the data cache configuration register to determine if
+ * bus snooping is available. This is needed for some drivers so
+ * that they can select the most efficient copy routines.
+ */
+static inline int set_snooping(void)
+{
+  unsigned int tmp = *(unsigned int *)0x80000014; /* Cache control register */
+  return ((tmp>>23) & 1); /* Data cache snooping enabled */
+}
+
+void bsp_start( void )
+{
+  CPU_SPARC_HAS_SNOOPING = set_snooping();
+}
+
+/* If RTEMS_DRVMGR_STARTUP is defined extra code is added that
+ * registers the LEON2 AMBA bus driver as root driver into the
+ * driver manager.
+ *
+ * The structues here are declared weak so that the user can override
+ * the configuration and add custom cores in the RTEMS project.
+ */
+#ifdef RTEMS_DRVMGR_STARTUP
+#include <drvmgr/drvmgr.h>
+#include <drvmgr/leon2_amba_bus.h>
+
+/* All drivers included by BSP, this is overridden by the user by including
+ * the devmgr_confdefs.h. No specifc drivers needed by BSP since IRQ/TIMER/UART
+ * is not drvmgr drivers.
+ */
+drvmgr_drv_reg_func drvmgr_drivers[] __attribute__((weak)) =
+{
+  NULL /* End array with NULL */
+};
+
+/* Defines what cores are avilable on the bus in addition to the standard
+ * LEON2 peripherals.
+ */
+struct leon2_core leon2_amba_custom_cores[] __attribute__((weak)) =
+{
+  EMPTY_LEON2_CORE
+};
+
+/* Configure LEON2 Root bus driver */
+struct leon2_bus leon2_bus_config __attribute__((weak)) =
+{
+  &leon2_std_cores[0], /* The standard cores, defined by driver */
+  &leon2_amba_custom_cores[0],   /* custom cores, defined by us */
+  DRVMGR_TRANSLATE_ONE2ONE,
+  DRVMGR_TRANSLATE_ONE2ONE,
+};
+
+/* Driver resources on LEON2 AMBA bus. Used to set options for particular
+ * LEON2 cores, it is up to the driver to look at the configuration paramters
+ * once started.
+ */
+struct drvmgr_bus_res leon2_amba_res __attribute__((weak)) =
+{
+  .next = NULL,
+  .resource = {
+    DRVMGR_RES_EMPTY
+  },
+};
+#endif /* RTEMS_DRVMGR_STARTUP */
+
+/*
+ * Called just before drivers are initialized.  Is used to initialize shared
+ * interrupt handling.
+ */
+static void leon2_pre_driver_hook( void )
+{
+  bsp_spurious_initialize();
+
+  /* Initialize shared interrupt handling, must be done after IRQ
+   * controller has been found and initialized.
+   */
+  BSP_shared_interrupt_init();
+
+#ifdef RTEMS_DRVMGR_STARTUP
+  leon2_root_register(&leon2_bus_config, &leon2_amba_res);
+#endif
+}
+
+RTEMS_SYSINIT_ITEM(
+  leon2_pre_driver_hook,
+  RTEMS_SYSINIT_BSP_PRE_DRIVERS,
+  RTEMS_SYSINIT_ORDER_MIDDLE
+);
Index: bsps/sparc/leon2/start/linkcmds
===================================================================
--- bsps/sparc/leon2/start/linkcmds	(revision 99648958668d3a33ee57974479b36201fe303f34)
+++ bsps/sparc/leon2/start/linkcmds	(revision 99648958668d3a33ee57974479b36201fe303f34)
@@ -0,0 +1,29 @@
+/*  linkcmds
+ */
+
+/* Default values, can be overridden */
+
+_PROM_SIZE = DEFINED (_PROM_SIZE) ? _PROM_SIZE : 2M;
+_PROM_START = DEFINED (_PROM_START) ? _PROM_START : 0x00000000;
+
+_RAM_SIZE = DEFINED (_RAM_SIZE) ? _RAM_SIZE : 4M;
+_RAM_START = DEFINED (_RAM_START) ? _RAM_START : 0x40000000;
+
+/*
+ *  Base address of the on-CPU peripherals
+ */
+
+_LEON_REG = 0x80000000;
+LEON_REG = _LEON_REG;
+
+/* these are the maximum values */
+
+MEMORY
+{
+  rom     : ORIGIN = 0x00000000, LENGTH = 256M
+  ram     : ORIGIN = 0x40000000, LENGTH = 1024M
+}
+
+ENTRY(start)
+
+INCLUDE linkcmds.base
Index: bsps/sparc/leon2/start/linkcmds.at697f
===================================================================
--- bsps/sparc/leon2/start/linkcmds.at697f	(revision 99648958668d3a33ee57974479b36201fe303f34)
+++ bsps/sparc/leon2/start/linkcmds.at697f	(revision 99648958668d3a33ee57974479b36201fe303f34)
@@ -0,0 +1,1 @@
+INCLUDE linkcmds.leon2
Index: bsps/sparc/leon2/start/linkcmds.leon2
===================================================================
--- bsps/sparc/leon2/start/linkcmds.leon2	(revision 99648958668d3a33ee57974479b36201fe303f34)
+++ bsps/sparc/leon2/start/linkcmds.leon2	(revision 99648958668d3a33ee57974479b36201fe303f34)
@@ -0,0 +1,29 @@
+/*  linkcmds
+ */
+
+/* Default values, can be overridden */
+
+_PROM_SIZE = DEFINED (_PROM_SIZE) ? _PROM_SIZE : 2M;
+_PROM_START = DEFINED (_PROM_START) ? _PROM_START : 0x00000000;
+
+_RAM_SIZE = DEFINED (_RAM_SIZE) ? _RAM_SIZE : 4M;
+_RAM_START = DEFINED (_RAM_START) ? _RAM_START : 0x40000000;
+
+/*
+ *  Base address of the on-CPU peripherals
+ */
+
+_LEON_REG = 0x80000000;
+LEON_REG = _LEON_REG;
+
+/* these are the maximum values */
+
+MEMORY
+{
+  rom     : ORIGIN = 0x00000000, LENGTH = 256M
+  ram     : ORIGIN = 0x40000000, LENGTH = 1024M
+}
+
+ENTRY(start)
+
+INCLUDE linkcmds.base
Index: bsps/sparc/leon2/start/setvec.c
===================================================================
--- bsps/sparc/leon2/start/setvec.c	(revision 99648958668d3a33ee57974479b36201fe303f34)
+++ bsps/sparc/leon2/start/setvec.c	(revision 99648958668d3a33ee57974479b36201fe303f34)
@@ -0,0 +1,65 @@
+/**
+ * @file
+ * @ingroup sparc_leon2
+ * @brief Installs an interrupt vector on the SPARC simulator
+ */
+
+/*  set_vector
+ *
+ *  This routine installs an interrupt vector on the SPARC simulator.
+ *
+ *  INPUT PARAMETERS:
+ *    handler - interrupt handler entry point
+ *    vector  - vector number
+ *    type    - 0 indicates raw hardware connect
+ *              1 indicates RTEMS interrupt connect
+ *
+ *  OUTPUT PARAMETERS:  NONE
+ *
+ *  RETURNS:
+ *    address of previous interrupt handler
+ *
+ *  COPYRIGHT (c) 1989-1998.
+ *  On-Line Applications Research Corporation (OAR).
+ *
+ *  The license and distribution terms for this file may be
+ *  found in the file LICENSE in this distribution or at
+ *  http://www.rtems.org/license/LICENSE.
+ *
+ *  Ported to LEON implementation of the SPARC by On-Line Applications
+ *  Research Corporation (OAR) under contract to the European Space
+ *  Agency (ESA).
+ *
+ *  LEON modifications of respective RTEMS file: COPYRIGHT (c) 1995.
+ *  European Space Agency.
+ */
+
+#include <bsp.h>
+
+rtems_isr_entry set_vector(                   /* returns old vector */
+  rtems_isr_entry     handler,                /* isr routine        */
+  rtems_vector_number vector,                 /* vector number      */
+  int                 type                    /* RTEMS or RAW intr  */
+)
+{
+  rtems_isr_entry previous_isr;
+  uint32_t      real_trap;
+  uint32_t      source;
+
+  if ( type )
+    rtems_interrupt_catch( handler, vector, &previous_isr );
+  else
+    _CPU_ISR_install_raw_handler( vector, handler, (void *)&previous_isr );
+
+  real_trap = SPARC_REAL_TRAP_NUMBER( vector );
+
+  if ( LEON_INT_TRAP( real_trap ) ) {
+
+    source = LEON_TRAP_SOURCE( real_trap );
+
+    LEON_Clear_interrupt( source );
+    LEON_Unmask_interrupt( source );
+  }
+
+  return previous_isr;
+}
Index: bsps/sparc/leon2/start/spurious.c
===================================================================
--- bsps/sparc/leon2/start/spurious.c	(revision 99648958668d3a33ee57974479b36201fe303f34)
+++ bsps/sparc/leon2/start/spurious.c	(revision 99648958668d3a33ee57974479b36201fe303f34)
@@ -0,0 +1,184 @@
+/**
+ * @file
+ * @ingroup sparc_leon2
+ * @brief LEON Spurious Trap Handler
+ */
+
+/*
+ *  LEON Spurious Trap Handler
+ *
+ *  This is just enough of a trap handler to let us know what
+ *  the likely source of the trap was.
+ *
+ *  Developed as part of the port of RTEMS to the LEON implementation
+ *  of the SPARC by On-Line Applications Research Corporation (OAR)
+ *  under contract to the European Space Agency (ESA).
+ *
+ *  COPYRIGHT (c) 1995. European Space Agency.
+ *
+ *  This terms of the RTEMS license apply to this file.
+ */
+
+#include <bsp.h>
+#include <rtems/bspIo.h>
+#include <inttypes.h>
+
+void _CPU_Exception_frame_print( const CPU_Exception_frame *frame )
+{
+  uint32_t                   trap;
+  uint32_t                   real_trap;
+  const CPU_Interrupt_frame *isf;
+
+  trap = frame->trap;
+  real_trap = SPARC_REAL_TRAP_NUMBER(trap);
+  isf = frame->isf;
+
+  printk(
+    "Unexpected trap (%2" PRId32 ") at address 0x%08" PRIx32 "\n",
+    real_trap,
+    isf->tpc
+  );
+
+  switch (real_trap) {
+
+    /*
+     *  First the ones defined by the basic architecture
+     */
+
+    case 0x00:
+      printk( "reset\n" );
+      break;
+    case 0x01:
+      printk( "instruction access exception\n" );
+      break;
+    case 0x02:
+      printk( "illegal instruction\n" );
+      break;
+    case 0x03:
+      printk( "privileged instruction\n" );
+      break;
+    case 0x04:
+      printk( "fp disabled\n" );
+      break;
+    case 0x07:
+      printk( "memory address not aligned\n" );
+      break;
+    case 0x08:
+      printk( "fp exception\n" );
+      break;
+    case 0x09:
+      printk("data access exception at 0x%08x\n", LEON_REG.Failed_Address );
+      break;
+    case 0x0A:
+      printk( "tag overflow\n" );
+      break;
+
+    /*
+     *  Then the ones defined by the LEON in particular
+     */
+
+    case LEON_TRAP_TYPE( LEON_INTERRUPT_CORRECTABLE_MEMORY_ERROR ):
+      printk( "LEON_INTERRUPT_CORRECTABLE_MEMORY_ERROR\n" );
+      break;
+    case LEON_TRAP_TYPE( LEON_INTERRUPT_UART_2_RX_TX ):
+      printk( "LEON_INTERRUPT_UART_2_RX_TX\n" );
+      break;
+    case LEON_TRAP_TYPE( LEON_INTERRUPT_UART_1_RX_TX ):
+      printk( "LEON_INTERRUPT_UART_1_RX_TX\n" );
+      break;
+    case LEON_TRAP_TYPE( LEON_INTERRUPT_EXTERNAL_0 ):
+      printk( "LEON_INTERRUPT_EXTERNAL_0\n" );
+      break;
+    case LEON_TRAP_TYPE( LEON_INTERRUPT_EXTERNAL_1 ):
+      printk( "LEON_INTERRUPT_EXTERNAL_1\n" );
+      break;
+    case LEON_TRAP_TYPE( LEON_INTERRUPT_EXTERNAL_2 ):
+      printk( "LEON_INTERRUPT_EXTERNAL_2\n" );
+      break;
+    case LEON_TRAP_TYPE( LEON_INTERRUPT_EXTERNAL_3 ):
+      printk( "LEON_INTERRUPT_EXTERNAL_3\n" );
+      break;
+    case LEON_TRAP_TYPE( LEON_INTERRUPT_TIMER1 ):
+      printk( "LEON_INTERRUPT_TIMER1\n" );
+      break;
+    case LEON_TRAP_TYPE( LEON_INTERRUPT_TIMER2 ):
+      printk( "LEON_INTERRUPT_TIMER2\n" );
+      break;
+
+    default:
+      break;
+  }
+}
+
+static rtems_isr bsp_spurious_handler(
+   rtems_vector_number trap,
+   CPU_Interrupt_frame *isf
+)
+{
+  CPU_Exception_frame frame = {
+    .trap = trap,
+    .isf = isf
+  };
+
+#if !defined(SPARC_USE_LAZY_FP_SWITCH)
+  if ( SPARC_REAL_TRAP_NUMBER( trap ) == 4 ) {
+    _Internal_error( INTERNAL_ERROR_ILLEGAL_USE_OF_FLOATING_POINT_UNIT );
+  }
+#endif
+
+  rtems_fatal(
+    RTEMS_FATAL_SOURCE_EXCEPTION,
+    (rtems_fatal_code) &frame
+  );
+}
+
+/*
+ *  bsp_spurious_initialize
+ *
+ *  Install the spurious handler for most traps. Note that set_vector()
+ *  will unmask the corresponding asynchronous interrupt, so the initial
+ *  interrupt mask is restored after the handlers are installed.
+ */
+
+void bsp_spurious_initialize()
+{
+  uint32_t trap;
+  uint32_t level;
+  uint32_t mask;
+
+  level = sparc_disable_interrupts();
+  mask = LEON_REG.Interrupt_Mask;
+
+  for ( trap=0 ; trap<256 ; trap++ ) {
+
+    /*
+     *  Skip window overflow, underflow, and flush as well as software
+     *  trap 0,9,10 which we will use as a shutdown, IRQ disable, IRQ enable.
+     *  Also avoid trap 0x70 - 0x7f which cannot happen and where some of the
+     *  space is used to pass parameters to the program.
+     */
+
+    if (( trap == 5 || trap == 6 ) ||
+#if defined(SPARC_USE_LAZY_FP_SWITCH)
+        ( trap == 4 ) ||
+#endif
+        (( trap >= 0x11 ) && ( trap <= 0x1f )) ||
+        (( trap >= 0x70 ) && ( trap <= 0x83 )) ||
+        ( trap == 0x80 + SPARC_SWTRAP_IRQDIS ) ||
+#if defined(SPARC_USE_SYNCHRONOUS_FP_SWITCH)
+        ( trap == 0x80 + SPARC_SWTRAP_IRQDIS_FP ) ||
+#endif
+        ( trap == 0x80 + SPARC_SWTRAP_IRQEN ))
+      continue;
+
+    set_vector(
+        (rtems_isr_entry) bsp_spurious_handler,
+        SPARC_SYNCHRONOUS_TRAP( trap ),
+        1
+    );
+  }
+
+  LEON_REG.Interrupt_Mask = mask;
+  sparc_enable_interrupts(level);
+
+}
