Index: c/src/lib/libbsp/sparc/leon/startup/.cvsignore
===================================================================
--- c/src/lib/libbsp/sparc/leon/startup/.cvsignore	(revision b21b0ab3e77d91fc32e4324d3dfaf57ce24096ab)
+++ c/src/lib/libbsp/sparc/leon/startup/.cvsignore	(revision b21b0ab3e77d91fc32e4324d3dfaf57ce24096ab)
@@ -0,0 +1,2 @@
+Makefile
+Makefile.in
Index: c/src/lib/libbsp/sparc/leon/startup/Makefile.am
===================================================================
--- c/src/lib/libbsp/sparc/leon/startup/Makefile.am	(revision b21b0ab3e77d91fc32e4324d3dfaf57ce24096ab)
+++ c/src/lib/libbsp/sparc/leon/startup/Makefile.am	(revision b21b0ab3e77d91fc32e4324d3dfaf57ce24096ab)
@@ -0,0 +1,45 @@
+##
+## $Id$
+##
+
+AUTOMAKE_OPTIONS = foreign 1.4
+
+VPATH = @srcdir@:@srcdir@/../../shared:@srcdir@/../../../shared
+
+PGM = $(ARCH)/startup.rel
+
+C_FILES = bspclean.c bsplibc.c bsppost.c bspstart.c main.c bootcard.c sbrk.c \
+    setvec.c spurious.c
+C_O_FILES = $(C_FILES:%.c=$(ARCH)/%.o)
+
+S_FILES = boardinit.S
+S_O_FILES = $(S_FILES:%.S=$(ARCH)/%.o)
+
+OBJS = $(C_O_FILES) $(S_O_FILES)
+
+include $(RTEMS_ROOT)/make/custom/@RTEMS_BSP@.cfg
+include $(top_srcdir)/../../../../../../automake/compile.am
+include $(top_srcdir)/../../../../../../automake/lib.am
+
+#
+# (OPTIONAL) Add local stuff here using +=
+#
+
+# USE_INIT_FINI tells main.c what C++ help we need.
+AM_CPPFLAGS += -DUSE_INIT_FINI
+
+$(PGM): $(OBJS)
+	$(make-rel)
+
+$(PROJECT_RELEASE)/lib/linkcmds: linkcmds
+	$(INSTALL_DATA) $< $@
+
+TMPINSTALL_FILES += $(PROJECT_RELEASE)/lib/linkcmds
+
+all-local: $(ARCH) $(OBJS) $(PGM) $(TMPINSTALL_FILES)
+
+.PRECIOUS: $(PGM)
+
+EXTRA_DIST = linkcmds setvec.c spurious.c boardinit.S
+
+include $(top_srcdir)/../../../../../../automake/local.am
Index: c/src/lib/libbsp/sparc/leon/startup/boardinit.S
===================================================================
--- c/src/lib/libbsp/sparc/leon/startup/boardinit.S	(revision b21b0ab3e77d91fc32e4324d3dfaf57ce24096ab)
+++ c/src/lib/libbsp/sparc/leon/startup/boardinit.S	(revision b21b0ab3e77d91fc32e4324d3dfaf57ce24096ab)
@@ -0,0 +1,64 @@
+/*
+ *  boardinit.s
+ *
+ *  Start code for the LEON.
+ *
+ *  $Id$
+ */
+
+#include <asm.h>
+#include <leon.h>
+
+	.global __bsp_board_init
+
+__bsp_board_init:
+
+/* Check if LEON is initialised. If not, this means that we are
+   running on the simulator. Initiate some of the parameters
+   that are done by the boot-prom otherwise.
+*/
+
+        set     SYM(LEON_REG), %l0  	! %l0 = base address of peripherals
+	ld	[%l0+LEON_REG_CACHECTRL_OFFSET], %l1 ! Check if LEON has been initialised
+	andcc	%l1, 3, %g0		
+	bne	2f
+	nop
+
+
+	flush
+	set	0x1000f, %l1
+	st      %l1, [%l0 + LEON_REG_CACHECTRL_OFFSET]     ! enable caches
+	ld      [%l0 + LEON_REG_SIM_ROM_SIZE_OFFSET], %g1  ! load simulator rom size
+	clr	%l2
+	srl	%g1, 13, %g1		! calculate appropriate rom size
+1:
+	srl	%g1, 1, %g1
+	tst	%g1
+	bne,a	1b
+	inc	%l2
+	sll	%l2, 14, %l2
+	st	%l2, [%l0 + LEON_REG_MEMCFG1_OFFSET] ! set prom size in memcfg1
+
+	set	0, %l2
+	ld      [%l0 + LEON_REG_SIM_RAM_SIZE_OFFSET], %g2 ! load simulator ram size
+	srl	%g2, 13, %g1		! calculate appropriate ram size
+1:
+	srl	%g1, 1, %g1
+	tst	%g1
+	bne,a	1b
+	inc	%l2
+	sll	%l2, 9, %l2
+	st	%l2, [%l0 + LEON_REG_MEMCFG2_OFFSET] ! set ram size in memcfg2
+
+	set	SYM(RAM_START), %l1  ! Cannot use RAM_END due to bug in linker
+	set	SYM(RAM_SIZE), %l2
+	add	%l1, %l2, %sp
+	set	49, %l2
+	st	%l2, [%l0 + LEON_REG_SCALER_LOAD_OFFSET] ! scaler reload register
+	st	%l2, [%l0 + LEON_REG_SCALERCNT_OFFSET] ! scaler counter register
+
+2:
+	retl
+	nop
+
+/* end of file */
Index: c/src/lib/libbsp/sparc/leon/startup/linkcmds
===================================================================
--- c/src/lib/libbsp/sparc/leon/startup/linkcmds	(revision b21b0ab3e77d91fc32e4324d3dfaf57ce24096ab)
+++ c/src/lib/libbsp/sparc/leon/startup/linkcmds	(revision b21b0ab3e77d91fc32e4324d3dfaf57ce24096ab)
@@ -0,0 +1,173 @@
+/*  linkcmds
+ *
+ *  $Id$
+ */
+
+OUTPUT_ARCH(sparc)
+__DYNAMIC  =  0;
+
+/*
+ * The memory map looks like this:
+ * +--------------------+ <- low memory
+ * | .text              |
+ * |        etext       |
+ * |        ctor list   | the ctor and dtor lists are for
+ * |        dtor list   | C++ support
+ * |        _endtext    |
+ * +--------------------+
+ * | .data              | initialized data goes here
+ * |        _sdata      |
+ * |        _edata      |
+ * +--------------------+
+ * | .bss               |
+ * |        __bss_start | start of bss, cleared by crt0
+ * |        _end        | start of heap, used by sbrk()
+ * +--------------------+
+ * |    heap space      |
+ * |        _ENDHEAP    |
+ * |    stack space     | 
+ * |        __stack     | top of stack
+ * +--------------------+ <- high memory
+ */
+
+
+/*
+ * User modifiable values:
+ *
+ * _CLOCK_SPEED               in Mhz (used to program the counter/timers)
+ *
+ * _PROM_SIZE                 size of PROM (permissible values are 128K, 256K,
+ *                               512K, 1M, 2M, 4M, 8M and 16M)
+ * _RAM_SIZE                  size of RAM (permissible values are 256K, 512K,
+ *                               1M, 2M, 4M, 8M, 16M, and 32M)
+ *
+ */
+
+/* Default values, can be overridden */
+
+_PROM_SIZE = 2M;
+_RAM_SIZE = 4M;
+
+_RAM_START = 0x40000000;
+_RAM_END = _RAM_START + _RAM_SIZE;
+
+_PROM_START = 0x00000000;
+_PROM_END = _PROM_START + _PROM_SIZE;
+
+/*
+ *  Alternate names without leading _.
+ */
+
+PROM_START = _PROM_START;
+PROM_SIZE = _PROM_SIZE;
+PROM_END = _PROM_END;
+
+RAM_START = _RAM_START;
+RAM_SIZE = _RAM_SIZE;
+RAM_END = _RAM_END;
+
+/*
+ *  Base address of the on-CPU peripherals
+ */
+
+_LEON_REG = 0x80000000;
+LEON_REG = 0x80000000;
+
+/* these are the maximum values */
+
+MEMORY
+{
+  rom     : ORIGIN = 0x00000000, LENGTH = 256M
+  ram     : ORIGIN = 0x40000000, LENGTH = 1024M
+}
+
+/*
+ * stick everything in ram (of course)
+ */
+SECTIONS
+{
+  .text :
+  {
+    CREATE_OBJECT_SYMBOLS
+    text_start = .;
+    _text_start = .;
+    *(.text)
+    . = ALIGN (16);
+
+    *(.eh_frame)
+    . = ALIGN (16);
+
+    *(.gnu.linkonce.t*)
+
+    /*
+     * C++ constructors
+     */
+    __CTOR_LIST__ = .;
+    LONG((__CTOR_END__ - __CTOR_LIST__) / 4 - 2)
+    *(.ctors)
+    LONG(0)
+    __CTOR_END__ = .;
+    __DTOR_LIST__ = .;
+    LONG((__DTOR_END__ - __DTOR_LIST__) / 4 - 2)
+    *(.dtors)
+    LONG(0)
+    __DTOR_END__ = .;
+
+    _rodata_start = . ;
+    *(.rodata)
+    *(.gnu.linkonce.r*)
+    _erodata = ALIGN( 0x10 ) ;
+
+    etext = ALIGN(0x10);
+    _etext = .;
+    *(.init)
+    *(.fini)
+    *(.lit)
+    *(.shdata)
+    . = ALIGN (16);
+    _endtext = .;
+  } > ram
+  .dynamic	  : { *(.dynamic) 	} >ram
+  .got		  : { *(.got) 		} >ram
+  .plt   	  : { *(.plt) 		} >ram
+  .hash		  : { *(.hash)		} >ram
+  .dynrel	  : { *(.dynrel)	} >ram
+  .dynsym	  : { *(.dynsym)	} >ram
+  .dynstr	  : { *(.dynstr)	} >ram
+  .hash		  : { *(.hash)		} >ram
+  .data :
+  {
+    data_start = .;
+    _data_start = .;
+    _sdata = . ;
+    *(.data)
+    *(.gnu.linkonce.d*)
+    *(.gcc_except_table)
+    . = ALIGN(0x10);
+    edata = .;
+    _edata = .;
+  } > ram
+  .shbss :
+  {
+    *(.shbss)
+  } > ram
+  .bss :
+  {
+    __bss_start = ALIGN(0x8);
+    _bss_start = .;
+    bss_start = .;
+    *(.bss)
+    *(COMMON)
+    end = .;
+    _end = ALIGN(0x8);
+    __end = ALIGN(0x8);
+  } > ram
+  .stab . (NOLOAD) :
+  {
+    [ .stab ]
+  }
+  .stabstr . (NOLOAD) :
+  {
+    [ .stabstr ]
+  }
+}
Index: c/src/lib/libbsp/sparc/leon/startup/setvec.c
===================================================================
--- c/src/lib/libbsp/sparc/leon/startup/setvec.c	(revision b21b0ab3e77d91fc32e4324d3dfaf57ce24096ab)
+++ c/src/lib/libbsp/sparc/leon/startup/setvec.c	(revision b21b0ab3e77d91fc32e4324d3dfaf57ce24096ab)
@@ -0,0 +1,72 @@
+/*  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).
+ *  Copyright assigned to U.S. Government, 1994.
+ *
+ *  The license and distribution terms for this file may be
+ *  found in the file LICENSE in this distribution or at
+ *  http://www.OARcorp.com/rtems/license.html.
+ *
+ *  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.
+ *
+ *  $Id$
+ */
+
+#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;
+  unsigned32      real_trap;
+  unsigned32      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;
+}
+
+/* LEON specific power-down function */
+
+void _CPU_Thread_Idle_body( void )
+{
+  while (1) {
+    LEON_REG.Power_Down = 0;   /* value is irrelevant */
+  }
+}
+
Index: c/src/lib/libbsp/sparc/leon/startup/spurious.c
===================================================================
--- c/src/lib/libbsp/sparc/leon/startup/spurious.c	(revision b21b0ab3e77d91fc32e4324d3dfaf57ce24096ab)
+++ c/src/lib/libbsp/sparc/leon/startup/spurious.c	(revision b21b0ab3e77d91fc32e4324d3dfaf57ce24096ab)
@@ -0,0 +1,173 @@
+/*
+ *  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.
+ *
+ *  $Id$
+ */
+
+#include <bsp.h>
+
+#include <string.h>
+
+static const char digits[16] = "0123456789abcdef";
+
+/* Simple integer-to-string conversion */
+
+void itos(unsigned32 u, char *s)
+{
+  int i;
+
+  for (i=0; i<8; i++) {
+    s[i] =  digits[(u >> (28 - (i*4))) & 0x0f];
+  }
+}
+
+/*
+ *  bsp_spurious_handler
+ *
+ *  Print a message on the debug console and then die
+ */
+
+rtems_isr bsp_spurious_handler(
+   rtems_vector_number trap,
+   CPU_Interrupt_frame *isf
+)
+{
+  char line[ 80 ];
+  rtems_unsigned32 real_trap;
+
+  real_trap = SPARC_REAL_TRAP_NUMBER(trap);
+
+  strcpy(line, "Unexpected trap (0x  ) at address 0x        ");
+  line[ 19 ] = digits[ real_trap >> 4 ];
+  line[ 20 ] = digits[ real_trap & 0xf ];
+  itos(isf->tpc, &line[36]);
+  DEBUG_puts( line );
+
+  switch (real_trap) {
+
+    /*
+     *  First the ones defined by the basic architecture
+     */
+
+    case 0x00: 
+      DEBUG_puts( "reset" );
+      break;
+    case 0x01: 
+      DEBUG_puts( "instruction access exception" );
+      break;
+    case 0x02: 
+      DEBUG_puts( "illegal instruction" );
+      break;
+    case 0x03: 
+      DEBUG_puts( "privileged instruction" );
+      break;
+    case 0x04: 
+      DEBUG_puts( "fp disabled" );
+      break;
+    case 0x07: 
+      DEBUG_puts( "memory address not aligned" );
+      break;
+    case 0x08: 
+      DEBUG_puts( "fp exception" );
+      break;
+    case 0x09: 
+      strcpy(line, "data access exception at 0x        " );
+      itos(LEON_REG.Failed_Address, &line[27]);
+      DEBUG_puts( line );
+      break;
+    case 0x0A: 
+      DEBUG_puts( "tag overflow" );
+      break;
+
+    /*
+     *  Then the ones defined by the LEON in particular
+     */
+
+    case LEON_TRAP_TYPE( LEON_INTERRUPT_CORRECTABLE_MEMORY_ERROR ):
+      DEBUG_puts( "LEON_INTERRUPT_CORRECTABLE_MEMORY_ERROR" );
+      break;
+    case LEON_TRAP_TYPE( LEON_INTERRUPT_UART_2_RX_TX ):
+      DEBUG_puts( "LEON_INTERRUPT_UART_2_RX_TX" );
+      break;
+    case LEON_TRAP_TYPE( LEON_INTERRUPT_UART_1_RX_TX ):
+      DEBUG_puts( "LEON_INTERRUPT_UART_1_RX_TX" );
+      break;
+    case LEON_TRAP_TYPE( LEON_INTERRUPT_EXTERNAL_0 ):
+      DEBUG_puts( "LEON_INTERRUPT_EXTERNAL_0" );
+      break;
+    case LEON_TRAP_TYPE( LEON_INTERRUPT_EXTERNAL_1 ):
+      DEBUG_puts( "LEON_INTERRUPT_EXTERNAL_1" );
+      break;
+    case LEON_TRAP_TYPE( LEON_INTERRUPT_EXTERNAL_2 ):
+      DEBUG_puts( "LEON_INTERRUPT_EXTERNAL_2" );
+      break;
+    case LEON_TRAP_TYPE( LEON_INTERRUPT_EXTERNAL_3 ):
+      DEBUG_puts( "LEON_INTERRUPT_EXTERNAL_3" );
+      break;
+    case LEON_TRAP_TYPE( LEON_INTERRUPT_TIMER1 ):
+      DEBUG_puts( "LEON_INTERRUPT_TIMER1" );
+      break;
+    case LEON_TRAP_TYPE( LEON_INTERRUPT_TIMER2 ):
+      DEBUG_puts( "LEON_INTERRUPT_TIMER2" );
+      break;
+
+    default:
+      break;
+  }
+
+  /*
+   *  What else can we do but stop ...
+   */
+
+  asm volatile( "mov 1, %g1; ta 0x0" );
+}
+
+/*
+ *  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()
+{
+  rtems_unsigned32 trap;
+  unsigned32 level;
+  unsigned32 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 which we will use as a shutdown. Also avoid trap 0x70 - 0x7f
+     *  which cannot happen and where some of the space is used to pass
+     *  paramaters to the program.
+     */
+
+    if (( trap == 5 || trap == 6 ) ||
+    	(( trap >= 0x11 ) && ( trap <= 0x1f )) || 
+    	(( trap >= 0x70 ) && ( trap <= 0x83 )))
+      continue;
+
+    set_vector( bsp_spurious_handler, SPARC_SYNCHRONOUS_TRAP( trap ), 1 );
+  }
+
+  LEON_REG.Interrupt_Mask = mask;
+  sparc_enable_interrupts(level);
+
+}
