summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChristian Mauderer <Christian.Mauderer@embedded-brains.de>2014-05-07 11:32:59 +0200
committerSebastian Huber <sebastian.huber@embedded-brains.de>2017-08-10 09:05:47 +0200
commit775cbc02dec004f03c6cce21f64980820a704b63 (patch)
treea87d303d5aed4b87ff9b8c2b7879847ba46ebf71
parent19b365fdadf3d93973d56dd96b4cbc732392ee41 (diff)
bsp/xm_leon3: New BSP
It is necessary that the environment variable XTRATUM_PATH is set to the XtratuM installation path, e.g. XTRATUM_PATH="/opt/xtratum/xm" By default the example_xm_cf.xml will be used for building the tests. It can be overwritten with setting the XTRATUM_CONFIG environment variable to another XML file, e.g. XTRATUM_CONFIG="/some/path/to/rtems_xm_cf.xml"
-rw-r--r--c/src/lib/libbsp/shared/include/fatal.h5
-rw-r--r--c/src/lib/libbsp/sparc/acinclude.m42
-rw-r--r--c/src/lib/libbsp/sparc/shared/cpu.c5
-rw-r--r--c/src/lib/libbsp/sparc/shared/irq_asm.S74
-rw-r--r--c/src/lib/libbsp/sparc/shared/start/start.S65
-rw-r--r--c/src/lib/libbsp/sparc/shared/startup/linkcmds.base19
-rw-r--r--c/src/lib/libbsp/sparc/shared/uart/apbuart_termios.c15
-rw-r--r--c/src/lib/libbsp/sparc/xm-leon3/Makefile.am108
-rw-r--r--c/src/lib/libbsp/sparc/xm-leon3/README123
-rw-r--r--c/src/lib/libbsp/sparc/xm-leon3/bsp_specs17
-rw-r--r--c/src/lib/libbsp/sparc/xm-leon3/clock/clock-gpt.c124
-rw-r--r--c/src/lib/libbsp/sparc/xm-leon3/clock/clock-xtratum-exec.c23
-rw-r--r--c/src/lib/libbsp/sparc/xm-leon3/clock/clock-xtratum-hw.c21
-rw-r--r--c/src/lib/libbsp/sparc/xm-leon3/clock/clock-xtratum.h94
-rw-r--r--c/src/lib/libbsp/sparc/xm-leon3/configure.ac29
-rw-r--r--c/src/lib/libbsp/sparc/xm-leon3/console/console-apbuart.c83
-rw-r--r--c/src/lib/libbsp/sparc/xm-leon3/include/bsp.h207
-rw-r--r--c/src/lib/libbsp/sparc/xm-leon3/include/cache_.h113
-rw-r--r--c/src/lib/libbsp/sparc/xm-leon3/include/irq.h2
-rw-r--r--c/src/lib/libbsp/sparc/xm-leon3/include/tm27.h30
-rw-r--r--c/src/lib/libbsp/sparc/xm-leon3/include/xtratum.h117
-rw-r--r--c/src/lib/libbsp/sparc/xm-leon3/irq/irq.c98
-rw-r--r--c/src/lib/libbsp/sparc/xm-leon3/make/custom/xm_leon3.cfg55
-rw-r--r--c/src/lib/libbsp/sparc/xm-leon3/preinstall.am115
-rw-r--r--c/src/lib/libbsp/sparc/xm-leon3/startup/bspreset.c58
-rw-r--r--c/src/lib/libbsp/sparc/xm-leon3/startup/bspsmp.c105
-rw-r--r--c/src/lib/libbsp/sparc/xm-leon3/startup/bspstart.c55
-rw-r--r--c/src/lib/libbsp/sparc/xm-leon3/startup/example_xm_cf.xml69
-rw-r--r--c/src/lib/libbsp/sparc/xm-leon3/startup/isr-en-dis.S50
-rw-r--r--c/src/lib/libbsp/sparc/xm-leon3/startup/linkcmds34
-rw-r--r--c/src/lib/libbsp/sparc/xm-leon3/startup/psr.c26
-rw-r--r--c/src/lib/libbsp/sparc/xm-leon3/startup/setvec.c61
-rw-r--r--c/src/lib/libbsp/sparc/xm-leon3/startup/spurious.c35
-rw-r--r--c/src/lib/libbsp/sparc/xm-leon3/startup/tbr.c30
-rw-r--r--c/src/lib/libbsp/sparc/xm-leon3/xm/xmhdr.c36
35 files changed, 2098 insertions, 5 deletions
diff --git a/c/src/lib/libbsp/shared/include/fatal.h b/c/src/lib/libbsp/shared/include/fatal.h
index 3a63fb4b8b..d9ef290ec2 100644
--- a/c/src/lib/libbsp/shared/include/fatal.h
+++ b/c/src/lib/libbsp/shared/include/fatal.h
@@ -44,6 +44,11 @@ typedef enum {
/* XtratuM fatal codes */
XM_BSP_FATAL_CONSOLE_DEVICE_INSTALL_XM = BSP_FATAL_CODE_BLOCK(7949),
+ XM_BSP_FATAL_CLOCK_IRQ_INSTALL,
+ XM_BSP_FATAL_CPU_SMP_INITIALIZE,
+ XM_BSP_FATAL_SET_TBR_NOT_IMPLEMENTED,
+ XM_BSP_FATAL_GPT_CLOCK_IRQ_INSTALL,
+ XM_BSP_FATAL_CONSOLE_DEVICE_INSTALL_APBUART,
/* ARM fatal codes */
BSP_ARM_A9MPCORE_FATAL_CLOCK_IRQ_INSTALL = BSP_FATAL_CODE_BLOCK(1),
diff --git a/c/src/lib/libbsp/sparc/acinclude.m4 b/c/src/lib/libbsp/sparc/acinclude.m4
index 4d40305601..b15b647e35 100644
--- a/c/src/lib/libbsp/sparc/acinclude.m4
+++ b/c/src/lib/libbsp/sparc/acinclude.m4
@@ -8,6 +8,8 @@ AC_DEFUN([RTEMS_CHECK_BSPDIR],
AC_CONFIG_SUBDIRS([leon2]);;
leon3 )
AC_CONFIG_SUBDIRS([leon3]);;
+ xm-leon3 )
+ AC_CONFIG_SUBDIRS([xm-leon3]);;
*)
AC_MSG_ERROR([Invalid BSP]);;
esac
diff --git a/c/src/lib/libbsp/sparc/shared/cpu.c b/c/src/lib/libbsp/sparc/shared/cpu.c
index 12d347547b..18566466f8 100644
--- a/c/src/lib/libbsp/sparc/shared/cpu.c
+++ b/c/src/lib/libbsp/sparc/shared/cpu.c
@@ -14,6 +14,7 @@
*/
#include <rtems/score/cpu.h>
+#include <bspopts.h>
/*
* This initializes the set of opcodes placed in each trap
@@ -29,7 +30,11 @@
*/
const CPU_Trap_table_entry _CPU_Trap_slot_template = {
+#if defined(RTEMS_PARAVIRT_XTRATUM)
+ 0x01000000, /* nop */
+#else /* RTEMS_PARAVIRT_XTRATUM */
0xa1480000, /* mov %psr, %l0 */
+#endif /* RTEMS_PARAVIRT_XTRATUM */
0x29000000, /* sethi %hi(_handler), %l4 */
0x81c52000, /* jmp %l4 + %lo(_handler) */
0xa6102000 /* mov _vector, %l3 */
diff --git a/c/src/lib/libbsp/sparc/shared/irq_asm.S b/c/src/lib/libbsp/sparc/shared/irq_asm.S
index 7d0312b7e4..0858e2d127 100644
--- a/c/src/lib/libbsp/sparc/shared/irq_asm.S
+++ b/c/src/lib/libbsp/sparc/shared/irq_asm.S
@@ -24,6 +24,9 @@
#include <rtems/asm.h>
#include <rtems/score/percpu.h>
#include <bspopts.h>
+#ifdef RTEMS_PARAVIRT_XTRATUM
+#include <xm.h>
+#endif /* RTEMS_PARAVIRT_XTRATUM */
#if defined(SPARC_USE_SYNCHRONOUS_FP_SWITCH)
#define FP_FRAME_OFFSET_FO_F1 (SPARC_MINIMUM_STACK_FRAME_SIZE + 0)
@@ -89,7 +92,15 @@ SYM(_CPU_Context_switch):
ld [%g6 + PER_CPU_ISR_DISPATCH_DISABLE], %o4
! save it a bit later so we do not waste a couple of cycles
+#ifdef RTEMS_PARAVIRT_XTRATUM
+ mov %o0, %l6
+ mov sparc_get_psr_nr, %o0
+ __XM_AHC
+ mov %o0, %o2
+ mov %l6, %o0
+#else /* RTEMS_PARAVIRT_XTRATUM */
rd %psr, %o2
+#endif /* RTEMS_PARAVIRT_XTRATUM */
st %o2, [%o0 + PSR_OFFSET] ! save status register
! Now actually save ISR stack nesting prevention flag
@@ -141,6 +152,21 @@ SYM(_CPU_Context_restore_heir):
and %o2, SPARC_PSR_CWP_MASK, %g3 ! g3 = CWP
andn %o2, SPARC_PSR_ET_MASK, %g1 ! g1 = psr with traps disabled
+#ifdef RTEMS_PARAVIRT_XTRATUM
+ mov %o0, %g2
+
+ mov %o1, %g5
+ mov sparc_flush_regwin_nr, %o0
+ __XM_AHC
+
+ or %g1, SPARC_PSR_ET_MASK, %g1
+ mov sparc_set_psr_nr, %o0
+ mov %g1, %o1
+ __XM_AHC
+
+ mov %g2, %o0
+ mov %g5, %o1
+#else /* RTEMS_PARAVIRT_XTRATUM */
mov %g1, %psr ! **** DISABLE TRAPS ****
mov %wim, %g2 ! g2 = wim
mov 1, %g4
@@ -196,6 +222,7 @@ done_flushing:
mov 1, %g4
sll %g4, %g2, %g4 ! g4 = new WIM
mov %g4, %wim
+#endif /* RTEMS_PARAVIRT_XTRATUM */
#if defined(RTEMS_SMP)
/*
@@ -304,7 +331,14 @@ done_flushing:
PUBLIC(_CPU_Context_restore)
SYM(_CPU_Context_restore):
save %sp, -SPARC_MINIMUM_STACK_FRAME_SIZE, %sp
+#ifdef RTEMS_PARAVIRT_XTRATUM
+ mov sparc_get_psr_nr, %o0
+ __XM_AHC
+ mov %o0, %o2
+#else /* RTEMS_PARAVIRT_XTRATUM */
rd %psr, %o2
+#endif /* RTEMS_PARAVIRT_XTRATUM */
+
#if defined(RTEMS_SMP)
! On SPARC the restore path needs also a valid executing context on SMP
! to update the is executing indicator.
@@ -356,6 +390,7 @@ win_ovflow:
mov %g4, %l4 ! save the globals this block uses
mov %g5, %l5
+#ifndef RTEMS_PARAVIRT_XTRATUM
/*
* When at a "window overflow" trap, (wim == (1 << cwp)).
* If we get here like that, then process a window overflow.
@@ -419,6 +454,7 @@ win_ovflow:
restore
nop
+#endif /* RTEMS_PARAVIRT_XTRATUM */
dont_do_the_window:
/*
@@ -567,7 +603,14 @@ pil_fixed:
andn %g5, %l5, %g5
#endif
+#ifdef RTEMS_PARAVIRT_XTRATUM
+ mov sparc_set_psr_nr, %o0
+ mov %g5, %o1
+ or %o1, SPARC_PSR_ET_MASK, %o1
+ __XM_AHC
+#else /* RTEMS_PARAVIRT_XTRATUM */
wr %g5, SPARC_PSR_ET_MASK, %psr ! **** ENABLE TRAPS ****
+#endif /* RTEMS_PARAVIRT_XTRATUM */
/*
* Vector to user's handler.
@@ -773,7 +816,14 @@ isr_dispatch:
.Lthread_dispatch_done:
#endif
+#ifdef RTEMS_PARAVIRT_XTRATUM
+ mov %o0, %g1
+ set sparc_set_pil_nr, %o0
+ __XM_AHC
+ mov %g1, %o0
+#else /* RTEMS_PARAVIRT_XTRATUM */
ta SPARC_SWTRAP_IRQDIS ! **** DISABLE INTERRUPTS ****
+#endif /* RTEMS_PARAVIRT_XTRATUM */
/*
* While we had ISR dispatching disabled in this thread,
@@ -807,12 +857,23 @@ simple_return:
ldd [%fp + ISF_PSR_OFFSET], %l0 ! restore psr, PC
ld [%fp + ISF_NPC_OFFSET], %l2 ! restore nPC
+#ifdef RTEMS_PARAVIRT_XTRATUM
+ mov sparc_get_psr_nr, %o0
+ __XM_AHC
+ mov %o0, %l3
+#else /* RTEMS_PARAVIRT_XTRATUM */
rd %psr, %l3
+#endif /* RTEMS_PARAVIRT_XTRATUM */
and %l3, SPARC_PSR_CWP_MASK, %l3 ! want "current" CWP
andn %l0, SPARC_PSR_CWP_MASK, %l0 ! want rest from task
or %l3, %l0, %l0 ! install it later...
andn %l0, SPARC_PSR_ET_MASK, %l0
+#ifdef RTEMS_PARAVIRT_XTRATUM
+ mov sparc_ctrl_winflow_nr, %o0
+ __XM_AHC
+#endif /* RTEMS_PARAVIRT_XTRATUM */
+
/*
* Restore tasks global and out registers
*/
@@ -829,6 +890,7 @@ simple_return:
ldd [%fp + ISF_I4_OFFSET], %i4 ! restore i4, i5
ldd [%fp + ISF_I6_FP_OFFSET], %i6 ! restore i6/fp, i7
+#ifndef RTEMS_PARAVIRT_XTRATUM
/*
* Registers:
*
@@ -891,14 +953,26 @@ simple_return:
ldd [%g1 + CPU_STACK_FRAME_I6_FP_OFFSET], %i6
! reload of sp clobbers ISF
save ! Back to ISR dispatch window
+#endif /* RTEMS_PARAVIRT_XTRATUM */
good_task_window:
+#ifdef RTEMS_PARAVIRT_XTRATUM
+ mov %l0, %o1
+ mov sparc_set_psr_nr, %o0
+ __XM_AHC
+#else /* RTEMS_PARAVIRT_XTRATUM */
mov %l0, %psr ! **** DISABLE TRAPS ****
nop; nop; nop
+#endif /* RTEMS_PARAVIRT_XTRATUM */
! and restore condition codes.
ld [%g1 + ISF_G1_OFFSET], %g1 ! restore g1
+#ifdef RTEMS_PARAVIRT_XTRATUM
+ mov sparc_iret_nr, %o0
+ __XM_AHC
+#else /* RTEMS_PARAVIRT_XTRATUM */
jmp %l1 ! transfer control and
rett %l2 ! go back to tasks window
+#endif /* RTEMS_PARAVIRT_XTRATUM */
/* end of file */
diff --git a/c/src/lib/libbsp/sparc/shared/start/start.S b/c/src/lib/libbsp/sparc/shared/start/start.S
index 64498c6110..494fae5e68 100644
--- a/c/src/lib/libbsp/sparc/shared/start/start.S
+++ b/c/src/lib/libbsp/sparc/shared/start/start.S
@@ -19,8 +19,13 @@
#include <rtems/score/percpu.h>
#include <bspopts.h>
-#if defined(RTEMS_SMP) && defined(BSP_LEON3_SMP)
- #define START_LEON3_ENABLE_SMP
+#ifdef RTEMS_PARAVIRT_XTRATUM
+#include <xm.h>
+#endif
+
+#if defined(RTEMS_SMP) && \
+ (defined(BSP_LEON3_SMP) || defined(RTEMS_PARAVIRT_XTRATUM))
+ #define START_ON_SECONDARY_PROCESSOR
#endif
/*
@@ -114,8 +119,13 @@ SYM(trap_table):
#else
BAD_TRAP; ! 04 fp disabled
#endif
+#ifdef RTEMS_PARAVIRT_XTRATUM
+ BAD_TRAP; ! 05 window overflow
+ BAD_TRAP; ! 06 window underflow
+#else /* RTEMS_PARAVIRT_XTRATUM */
WOTRAP(5, SYM(window_overflow_trap_handler)); ! 05 window overflow
WUTRAP(6, SYM(window_underflow_trap_handler));! 06 window underflow
+#endif /* RTEMS_PARAVIRT_XTRATUM */
BAD_TRAP; ! 07 memory address not aligned
BAD_TRAP; ! 08 fp exception
BAD_TRAP; ! 09 data access exception
@@ -207,9 +217,17 @@ SYM(CLOCK_SPEED):
* installed before.
*/
+#ifdef RTEMS_PARAVIRT_XTRATUM
+ SOFT_TRAP;
+#else /* RTEMS_PARAVIRT_XTRATUM */
TRAP( 0x80, SYM(syscall) ); ! 80 halt syscall SW trap
- SOFT_TRAP; SOFT_TRAP; ! 81 - 82
+#endif /* RTEMS_PARAVIRT_XTRATUM */
+ SOFT_TRAP; SOFT_TRAP; ! 81 - 82
+#ifdef RTEMS_PARAVIRT_XTRATUM
+ SOFT_TRAP;
+#else /* RTEMS_PARAVIRT_XTRATUM */
TRAP( 0x83, SYM(window_flush_trap_handler) ); ! 83 flush windows SW trap
+#endif /* RTEMS_PARAVIRT_XTRATUM */
SOFT_TRAP; SOFT_TRAP; SOFT_TRAP; SOFT_TRAP; ! 84 - 87
SOFT_TRAP; ! 88
@@ -272,6 +290,25 @@ SYM(hard_reset):
/* Common initialisation */
+#ifdef RTEMS_PARAVIRT_XTRATUM
+ /* Set up a valid stack */
+ set SYM(_RAM_START), %l1
+ set SYM(_RAM_SIZE), %l2
+ add %l1, %l2, %sp
+ mov %g1, %g7
+
+ /* Initialize TBR */
+ set sparc_write_tbr_nr, %o0
+ set trap_table, %o1
+ __XM_HC
+
+ /* Enable traps */
+ mov sparc_get_psr_nr, %o0
+ __XM_AHC
+ or %o0, SPARC_PSR_ET_MASK, %o1
+ mov sparc_set_psr_nr, %o0
+ __XM_AHC
+#else /* RTEMS_PARAVIRT_XTRATUM */
set SYM(trap_table), %g1 ! Initialize TBR
mov %g1, %tbr
@@ -288,13 +325,19 @@ SYM(hard_reset):
nop
nop
nop
+#endif /* RTEMS_PARAVIRT_XTRATUM */
sethi %hi(_Per_CPU_Information), %g6 ! get per-CPU control
add %g6, %lo(_Per_CPU_Information), %g6
-#if defined(START_LEON3_ENABLE_SMP)
+#if defined(START_ON_SECONDARY_PROCESSOR)
+#if defined(RTEMS_PARAVIRT_XTRATUM)
+ set get_vcpuid_nr, %o0 ! get virtual CPU identifier
+ __XM_HC
+#else
rd %asr17, %o0 ! get CPU identifier
srl %o0, LEON3_ASR17_PROCESSOR_INDEX_SHIFT, %o0
+#endif
sll %o0, PER_CPU_CONTROL_SIZE_LOG2, %l0
add %g6, %l0, %g6
@@ -311,6 +354,13 @@ SYM(hard_reset):
andn %sp, 0x0f, %sp ! align stack on 16-byte boundary
mov %sp, %fp ! set frame pointer
+#ifdef RTEMS_PARAVIRT_XTRATUM
+ mov %g7, %o0
+ call init_libxm ! initialize libxm
+ sub %sp, 0x60, %sp
+ add %sp, 0x60, %sp
+#endif /* RTEMS_PARAVIRT_XTRATUM */
+
call SYM(bsp_start_on_secondary_processor) ! does not return
sub %sp, SPARC_MINIMUM_STACK_FRAME_SIZE, %sp
.Lbootcpu:
@@ -367,6 +417,13 @@ zerobss:
bleu,a zerobss
nop
+#ifdef RTEMS_PARAVIRT_XTRATUM
+ mov %g7, %o0
+ call init_libxm ! initialize libxm
+ sub %sp, 0x60, %sp
+ add %sp, 0x60, %sp
+#endif /* RTEMS_PARAVIRT_XTRATUM */
+
mov %g0, %o0 ! command line
call SYM(boot_card) ! does not return
sub %sp, 0x60, %sp ! room for boot_card to save args
diff --git a/c/src/lib/libbsp/sparc/shared/startup/linkcmds.base b/c/src/lib/libbsp/sparc/shared/startup/linkcmds.base
index 4e391427ab..71044cc95b 100644
--- a/c/src/lib/libbsp/sparc/shared/startup/linkcmds.base
+++ b/c/src/lib/libbsp/sparc/shared/startup/linkcmds.base
@@ -106,6 +106,15 @@ SECTIONS
*(.shdata)
. = ALIGN (16);
} > ram
+
+ /*
+ * Special section for XtratuM hypervisor. It must have exactly this name and
+ * content.
+ */
+ .xmImageHdr : {
+ KEEP (*(.xmImageHdr))
+ } > ram
+
.tdata : {
_TLS_Data_begin = .;
*(.tdata .tdata.* .gnu.linkonce.td.*)
@@ -181,6 +190,16 @@ SECTIONS
{
*(.shbss)
} > ram
+
+ /*
+ * Special section for read-write data which will be not zero initialized by
+ * the BSS loop.
+ */
+ .rwextra :
+ {
+ *(.bsp_rwextra)
+ } > ram
+
.bss :
{
__bss_start = ALIGN(0x8);
diff --git a/c/src/lib/libbsp/sparc/shared/uart/apbuart_termios.c b/c/src/lib/libbsp/sparc/shared/uart/apbuart_termios.c
index 28ece27d9d..822bd1b0ef 100644
--- a/c/src/lib/libbsp/sparc/shared/uart/apbuart_termios.c
+++ b/c/src/lib/libbsp/sparc/shared/uart/apbuart_termios.c
@@ -22,6 +22,14 @@ static void apbuart_isr(void *arg)
unsigned int status;
char data;
+#ifdef RTEMS_PARAVIRT_XTRATUM
+ ISR_Level level;
+ _ISR_Disable_without_giant(level);
+ (void) level;
+
+ bsp_unmask_interrupt(uart->irq);
+#endif /* RTEMS_PARAVIRT_XTRATUM */
+
/* Get all received characters */
while ((status=uart->regs->status) & APBUART_STATUS_DR) {
/* Data has arrived, get new data */
@@ -161,13 +169,18 @@ static bool apbuart_set_attributes(
}
static void apbuart_set_best_baud(
- const struct apbuart_context *uart,
+ struct apbuart_context *uart,
struct termios *term
)
{
+#ifdef RTEMS_PARAVIRT_XTRATUM
+ rtems_termios_set_best_baud(term, (uint32_t) console_apbuart_initial_baud);
+ apbuart_set_attributes(&uart->base, term);
+#else /* RTEMS_PARAVIRT_XTRATUM */
uint32_t baud = (uart->freq_hz * 10) / ((uart->regs->scaler * 10 + 5) * 8);
rtems_termios_set_best_baud(term, baud);
+#endif /* RTEMS_PARAVIRT_XTRATUM */
}
static bool apbuart_first_open_polled(
diff --git a/c/src/lib/libbsp/sparc/xm-leon3/Makefile.am b/c/src/lib/libbsp/sparc/xm-leon3/Makefile.am
new file mode 100644
index 0000000000..01d07f2289
--- /dev/null
+++ b/c/src/lib/libbsp/sparc/xm-leon3/Makefile.am
@@ -0,0 +1,108 @@
+ACLOCAL_AMFLAGS = -I ../../../../aclocal
+
+include $(top_srcdir)/../../../../automake/compile.am
+
+include_bspdir = $(includedir)/bsp
+
+dist_project_lib_DATA = bsp_specs
+
+include_HEADERS = include/bsp.h
+include_HEADERS += include/tm27.h
+include_HEADERS += ../../sparc/shared/include/debug_defs.h
+
+include_bsp_HEADERS =
+
+nodist_include_HEADERS = include/bspopts.h
+nodist_include_bsp_HEADERS = ../../shared/include/bootcard.h
+DISTCLEANFILES = include/bspopts.h
+
+noinst_PROGRAMS =
+
+include_HEADERS += include/xtratum.h
+include_HEADERS += ../../shared/include/coverhd.h
+
+noinst_LIBRARIES = libbspstart.a
+CPPFLAGS += -I$(XTRATUM_PATH)/include -D"__XM_INCFLD(_fld)=<xm_inc/_fld>"
+libbspstart_a_SOURCES = ../../sparc/shared/start/start.S
+project_lib_DATA = start.$(OBJEXT)
+
+dist_project_lib_DATA += ../shared/startup/linkcmds.base
+dist_project_lib_DATA += startup/linkcmds
+
+dist_project_lib_DATA += startup/example_xm_cf.xml
+
+noinst_LIBRARIES += libbsp.a
+libbsp_a_SOURCES =
+libbsp_a_LIBADD =
+libbsp_a_CPPFLAGS =
+
+libbsp_a_CPPFLAGS += -I$(XTRATUM_PATH)/include -D"__XM_INCFLD(_fld)=<xm_inc/_fld>"
+
+# XtratuM header
+libbsp_a_SOURCES += xm/xmhdr.c
+
+# startup
+libbsp_a_SOURCES += ../../shared/bspclean.c
+libbsp_a_SOURCES += ../../shared/bootcard.c
+libbsp_a_SOURCES += startup/bspstart.c
+libbsp_a_SOURCES += ../../sparc/shared/startup/bspgetworkarea.c
+libbsp_a_SOURCES += ../../shared/sbrk.c
+libbsp_a_SOURCES += startup/isr-en-dis.S
+libbsp_a_SOURCES += ../../shared/bsppredriverhook.c
+libbsp_a_SOURCES += startup/psr.c
+libbsp_a_SOURCES += startup/tbr.c
+libbsp_a_SOURCES += startup/setvec.c
+libbsp_a_SOURCES += startup/spurious.c
+libbsp_a_SOURCES += ../../shared/timerstub.c
+libbsp_a_SOURCES += startup/bspreset.c
+
+if HAS_SMP
+libbsp_a_SOURCES += startup/bspsmp.c
+endif
+
+# ISR Handler
+libbsp_a_SOURCES += ../../sparc/shared/cpu.c
+libbsp_a_SOURCES += ../../sparc/shared/irq_asm.S
+
+# AMBA bus
+include_HEADERS += ../../sparc/shared/include/ambapp.h
+include_HEADERS += ../../sparc/shared/include/ambapp_ids.h
+include_HEADERS += ../../sparc/shared/include/grlib.h
+
+# Console
+include_bsp_HEADERS += ../../sparc/shared/include/apbuart.h
+include_bsp_HEADERS += ../../sparc/shared/include/apbuart_termios.h
+libbsp_a_SOURCES += ../../sparc/shared/uart/apbuart_termios.c
+libbsp_a_SOURCES += ../../shared/console-termios.c
+libbsp_a_SOURCES += ../../shared/xm/console-xm.c
+libbsp_a_SOURCES += ../../shared/xm/printk-support-xm.c
+libbsp_a_SOURCES += console/console-apbuart.c
+
+# Clock
+libbsp_a_SOURCES += clock/clock-xtratum-hw.c
+libbsp_a_SOURCES += clock/clock-xtratum-exec.c
+libbsp_a_SOURCES += clock/clock-gpt.c
+
+# IRQ
+include_bsp_HEADERS += ../../shared/include/irq-generic.h
+include_bsp_HEADERS += ../../shared/include/irq-info.h
+include_bsp_HEADERS += include/irq.h
+
+libbsp_a_SOURCES += ../../shared/src/irq-default-handler.c
+libbsp_a_SOURCES += ../../shared/src/irq-generic.c
+libbsp_a_SOURCES += ../../shared/src/irq-info.c
+libbsp_a_SOURCES += ../../shared/src/irq-legacy.c
+libbsp_a_SOURCES += ../../shared/src/irq-server.c
+libbsp_a_SOURCES += ../../shared/src/irq-shell.c
+libbsp_a_SOURCES += irq/irq.c
+
+# Cache
+libbsp_a_SOURCES += ../../../libcpu/shared/src/cache_manager.c
+libbsp_a_SOURCES += include/cache_.h
+libbsp_a_CPPFLAGS += -I$(srcdir)/../../shared/include
+
+libbsp_a_LIBADD += ../../../libcpu/@RTEMS_CPU@/access.rel \
+ ../../../libcpu/@RTEMS_CPU@/syscall.rel
+
+include $(srcdir)/preinstall.am
+include $(top_srcdir)/../../../../automake/local.am
diff --git a/c/src/lib/libbsp/sparc/xm-leon3/README b/c/src/lib/libbsp/sparc/xm-leon3/README
new file mode 100644
index 0000000000..582aceaf16
--- /dev/null
+++ b/c/src/lib/libbsp/sparc/xm-leon3/README
@@ -0,0 +1,123 @@
+Overview
+--------
+
+BSP for use with XtratuM 4 hypervisor.
+
+It is necessary that the environment variable XTRATUM_PATH is set to the
+XtratuM installation path, e.g.
+
+XTRATUM_PATH="/opt/xtratum/xm"
+
+By default the example_xm_cf.xml will be used for building the tests. It can
+be overwritten with setting the XTRATUM_CONFIG environment variable to another
+XML file, e.g.
+
+XTRATUM_CONFIG="/some/path/to/rtems_xm_cf.xml"
+
+Usage of different clock driver
+-------------------------------
+This BSP provides three clock drivers.
+
+1. The standard clock driver uses the XtratuM hardware clock (XM_HW_CLOCK).
+
+ Configuration:
+
+ #define CONFIGURE_APPLICATION_NEEDS_CLOCK_DRIVER
+
+2. The execution clock driver uses the XtratuM execution clock (XM_EXEC_CLOCK).
+
+ Configuration:
+
+ #define CONFIGURE_APPLICATION_EXTRA_DRIVERS \
+ { .initialization_entry = clock_xtratum_exec_initialize }
+ #define CONFIGURE_APPLICATION_DOES_NOT_NEED_CLOCK_DRIVER
+
+3. The GPTIMER clock driver uses a GPTIMER module defined via clock_gpt_regs.
+
+ Configuration:
+
+ #define CONFIGURE_APPLICATION_EXTRA_DRIVERS \
+ { .initialization_entry = clock_gpt_initialize }
+ #define CONFIGURE_APPLICATION_DOES_NOT_NEED_CLOCK_DRIVER
+
+ This GPTIMER module is also used for the CPU counter support if not
+ defined to CLOCK_GPT_NOT_PRESENT. The clock_gpt_regs must be defined via
+ the linker. It is assumed that XtratuM initialized the prescaler so that
+ the counter frequency is 1MHz.
+
+ The default memory location and IRQ is defined with linker symbols. You
+ can overwrite them with application specific values to use another memory
+ location and IRQ.
+
+Usage of different console driver
+---------------------------------
+
+This BSP provides two console drivers.
+
+1. The standard console driver uses the XtratuM hypervisor console.
+
+ Configuration:
+
+ #define CONFIGURE_APPLICATION_NEEDS_CONSOLE_DRIVER
+
+2. The APBUART console uses the APBUART defined via console_apbuart_regs.
+
+ Configuration:
+
+ #define CONFIGURE_APPLICATION_PREREQUISITE_DRIVERS \
+ CONSOLE_APBUART_DRIVER_TABLE_ENTRY
+
+ Do NOT define CONFIGURE_APPLICATION_NEEDS_CONSOLE_DRIVER in your
+ configuration.
+
+ Please note that this driver uses the IRQ defined by XtratuM as
+ XM_VT_HW_UART2_TRAP_NR. If you want to use another UART you have to map
+ the IRQ to this line in your XtratuM configuration.
+
+ Note the XtratuM hypervisor console is used for printk output until this
+ console is initialized.
+
+ The default memory location and IRQ is defined with linker symbols. You
+ can overwrite them with application specific values to use another memory
+ location and IRQ.
+
+List of open points
+-------------------
+
+- Implement or remove _SPARC_Set_TBR(). This function is not currently used by
+ anyone.
+
+- Find a better solution for setting the CPPFLAGS for libbspstart_a_SOURCES in
+ Makefile.am
+
+- Fix C++ support: The C++ exceptions (i.e. in testsuite/samples/cdtest) don't
+ work correctly. The reason is a broken window flush trap procedure (ta 0x3).
+
+Problems with XtratuM API
+-------------------------
+
+- The functions XM_sparc_set_pil and XM_sparc_clear_pil can only write all 0 or
+ all 1 to the PIL. Therefore a read modify write operation with two hypercalls
+ is necessary in the sparc_disable_interrupts and sparc_enable_interrupts
+ functions.
+
+- XM_write_console misses the const attribute for the character array that
+ should be written. Therefore there are warnings when passing the constant
+ string in xtratum_hyper_console_write_support_polled.
+
+- The XtratuM documentation does not clearly specify state and / or value of
+ registers at some points. Therefore this has to be guessed with help of
+ XtratuM sources. That is true for the following points:
+
+ - register usage and values when entering traps
+ - register values on the partition entry point
+ - which registers are preserved over XtratuM hypercalls
+
+- The thread context switch uses too many hypercalls.
+
+- The interrupt handling uses too many hypercalls.
+
+- The lazy hypercall implementation on XtratuM 4.2 is potentially broken on
+ SMP.
+
+- The init_libxm() implementation on XtratuM 4.2 is potentially broken on SMP.
diff --git a/c/src/lib/libbsp/sparc/xm-leon3/bsp_specs b/c/src/lib/libbsp/sparc/xm-leon3/bsp_specs
new file mode 100644
index 0000000000..93d6e75111
--- /dev/null
+++ b/c/src/lib/libbsp/sparc/xm-leon3/bsp_specs
@@ -0,0 +1,17 @@
+%rename endfile old_endfile
+%rename startfile old_startfile
+%rename link old_link
+%rename lib old_lib
+
+*endfile:
+crtend.o%s crtn.o%s
+
+*startfile:
+%{!qrtems: %(old_startfile)} \
+%{!nostdlib: %{qrtems: start.o%s crti.o%s crtbegin.o%s}}
+
+*link:
+%{!qrtems: %(old_link)} %{qrtems: -dc -dp -N}
+
+*lib:
+%(old_lib) -lxm
diff --git a/c/src/lib/libbsp/sparc/xm-leon3/clock/clock-gpt.c b/c/src/lib/libbsp/sparc/xm-leon3/clock/clock-gpt.c
new file mode 100644
index 0000000000..5bffa51ed3
--- /dev/null
+++ b/c/src/lib/libbsp/sparc/xm-leon3/clock/clock-gpt.c
@@ -0,0 +1,124 @@
+/*
+ * Copyright (c) 2014 embedded brains GmbH. All rights reserved.
+ *
+ * embedded brains GmbH
+ * Dornierstr. 4
+ * 82178 Puchheim
+ * Germany
+ * <info@embedded-brains.de>
+ *
+ * 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>
+#include <bsp/fatal.h>
+
+#include <xm.h>
+
+/*
+ * First timer generates one interrupt per underflow. Setup that it underflows
+ * once per tick.
+ */
+#define CLOCK_GPT_IDX_AUTO_RELOAD 0
+
+/*
+ * Second timer is decremented on each underflow of first timer. So it counts
+ * the ticks.
+ */
+#define CLOCK_GPT_IDX_TICK_CTR (CLOCK_GPT_IDX_AUTO_RELOAD + 1)
+
+#define TRAP_NUMBER \
+ XTRATUM_TRAP_FROM_XM_HW_IRQ((rtems_vector_number)clock_gpt_vt_hw_irq_nr)
+
+static volatile uint32_t lasttime;
+
+static void gpt_clock_handler(void *notused)
+{
+ rtems_interrupt_level level;
+
+ (void) notused;
+
+ clock_gpt_regs.timer[CLOCK_GPT_IDX_AUTO_RELOAD].ctrl
+ |= GPTIMER_TIMER_CTRL_IP;
+
+ /* This prevents infinite nesting of this interrupt */
+ rtems_interrupt_local_disable(level);
+ (void) level;
+
+ bsp_unmask_interrupt(TRAP_NUMBER);
+
+ while (lasttime > clock_gpt_regs.timer[CLOCK_GPT_IDX_TICK_CTR].value) {
+ --lasttime;
+ rtems_clock_tick();
+ }
+}
+
+static uint32_t nanoseconds_since_last_tick(void)
+{
+ uint32_t fast_timer_value;
+ uint32_t lasttime_value_0;
+ uint32_t slow_timer_value_0;
+ uint32_t slow_timer_value_1;
+
+ uint32_t usecs;
+ uint32_t usecs_per_tick = rtems_configuration_get_microseconds_per_tick();
+
+ do {
+ slow_timer_value_0 = clock_gpt_regs.timer[CLOCK_GPT_IDX_TICK_CTR].value;
+ lasttime_value_0 = lasttime;
+ fast_timer_value = clock_gpt_regs.timer[CLOCK_GPT_IDX_AUTO_RELOAD].value;
+ slow_timer_value_1 = clock_gpt_regs.timer[CLOCK_GPT_IDX_TICK_CTR].value;
+ } while (slow_timer_value_0 != slow_timer_value_1);
+
+ usecs = (lasttime_value_0 - slow_timer_value_0) * usecs_per_tick
+ + usecs_per_tick - fast_timer_value;
+
+ return usecs * 1000;
+}
+
+static void clock_handler_install(void)
+{
+ rtems_status_code sc;
+
+ sc = rtems_interrupt_handler_install(
+ TRAP_NUMBER,
+ "Clock",
+ RTEMS_INTERRUPT_UNIQUE,
+ gpt_clock_handler,
+ NULL
+ );
+ if (sc != RTEMS_SUCCESSFUL) {
+ bsp_fatal(XM_BSP_FATAL_GPT_CLOCK_IRQ_INSTALL);
+ }
+}
+
+rtems_device_driver clock_gpt_initialize(
+ rtems_device_major_number major,
+ rtems_device_minor_number minor,
+ void *pargp
+)
+{
+ uint64_t freq_hz = (uint32_t) clock_gpt_freq_hz;
+
+ clock_gpt_regs.timer[CLOCK_GPT_IDX_AUTO_RELOAD].ctrl = GPTIMER_TIMER_CTRL_IP;
+ clock_gpt_regs.timer[CLOCK_GPT_IDX_TICK_CTR].ctrl = GPTIMER_TIMER_CTRL_IP;
+
+ clock_handler_install();
+ rtems_clock_set_nanoseconds_extension(nanoseconds_since_last_tick);
+
+ clock_gpt_regs.timer[CLOCK_GPT_IDX_TICK_CTR].reload = 0xFFFFFFFF;
+ lasttime = clock_gpt_regs.timer[CLOCK_GPT_IDX_TICK_CTR].reload;
+ clock_gpt_regs.timer[CLOCK_GPT_IDX_TICK_CTR].ctrl = GPTIMER_TIMER_CTRL_EN
+ | GPTIMER_TIMER_CTRL_LD | GPTIMER_TIMER_CTRL_IP | GPTIMER_TIMER_CTRL_CH;
+
+ clock_gpt_regs.timer[CLOCK_GPT_IDX_AUTO_RELOAD].reload =
+ (uint32_t) ((freq_hz * rtems_configuration_get_microseconds_per_tick())
+ / UINT64_C(1000000)) - 1;
+ clock_gpt_regs.timer[CLOCK_GPT_IDX_AUTO_RELOAD].ctrl = GPTIMER_TIMER_CTRL_EN
+ | GPTIMER_TIMER_CTRL_RS | GPTIMER_TIMER_CTRL_LD | GPTIMER_TIMER_CTRL_IE
+ | GPTIMER_TIMER_CTRL_IP;
+
+ return RTEMS_SUCCESSFUL;
+}
diff --git a/c/src/lib/libbsp/sparc/xm-leon3/clock/clock-xtratum-exec.c b/c/src/lib/libbsp/sparc/xm-leon3/clock/clock-xtratum-exec.c
new file mode 100644
index 0000000000..c0d36ec1e6
--- /dev/null
+++ b/c/src/lib/libbsp/sparc/xm-leon3/clock/clock-xtratum-exec.c
@@ -0,0 +1,23 @@
+/*
+ * Copyright (c) 2014 embedded brains GmbH. All rights reserved.
+ *
+ * embedded brains GmbH
+ * Dornierstr. 4
+ * 82178 Puchheim
+ * Germany
+ * <info@embedded-brains.de>
+ *
+ * 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>
+
+#define XTRATUM_CLOCK XM_EXEC_CLOCK
+#define CLOCK_EXT_TRAP_NUMBER \
+ XTRATUM_TRAP_FROM_XM_EXT_IRQ( XM_VT_EXT_EXEC_TIMER )
+
+#define XTRATUM_CLOCK_INITIALIZE clock_xtratum_exec_initialize
+
+#include "clock-xtratum.h"
diff --git a/c/src/lib/libbsp/sparc/xm-leon3/clock/clock-xtratum-hw.c b/c/src/lib/libbsp/sparc/xm-leon3/clock/clock-xtratum-hw.c
new file mode 100644
index 0000000000..48a7efa062
--- /dev/null
+++ b/c/src/lib/libbsp/sparc/xm-leon3/clock/clock-xtratum-hw.c
@@ -0,0 +1,21 @@
+/*
+ * Copyright (c) 2014 embedded brains GmbH. All rights reserved.
+ *
+ * embedded brains GmbH
+ * Dornierstr. 4
+ * 82178 Puchheim
+ * Germany
+ * <info@embedded-brains.de>
+ *
+ * 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.
+ */
+
+#define XTRATUM_CLOCK XM_HW_CLOCK
+#define CLOCK_EXT_TRAP_NUMBER \
+ XTRATUM_TRAP_FROM_XM_EXT_IRQ( XM_VT_EXT_HW_TIMER )
+
+#define XTRATUM_CLOCK_INITIALIZE Clock_initialize
+
+#include "clock-xtratum.h"
diff --git a/c/src/lib/libbsp/sparc/xm-leon3/clock/clock-xtratum.h b/c/src/lib/libbsp/sparc/xm-leon3/clock/clock-xtratum.h
new file mode 100644
index 0000000000..587ae06e08
--- /dev/null
+++ b/c/src/lib/libbsp/sparc/xm-leon3/clock/clock-xtratum.h
@@ -0,0 +1,94 @@
+/*
+ * Copyright (c) 2014 embedded brains GmbH. All rights reserved.
+ *
+ * embedded brains GmbH
+ * Dornierstr. 4
+ * 82178 Puchheim
+ * Germany
+ * <info@embedded-brains.de>
+ *
+ * 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>
+#include <bsp/fatal.h>
+#include <bsp/irq.h>
+#include <xm.h>
+
+static uint32_t lasttime;
+
+static uint32_t xtratum_get_time(void)
+{
+ xmTime_t clocktime;
+
+ XM_get_time(XTRATUM_CLOCK, &clocktime);
+
+ return (uint32_t) clocktime;
+}
+static uint32_t xtratum_clock_nanoseconds_since_last_tick(void)
+{
+ uint32_t now = xtratum_get_time();
+
+ return (now - lasttime) * 1000;
+}
+
+static void xtratum_clock_handler(void *arg)
+{
+ uint32_t us_per_tick = rtems_configuration_get_microseconds_per_tick();
+ uint32_t now = xtratum_get_time();
+
+ (void) arg;
+
+ /* FIXME: What prevents infinite interrupt nesting here? */
+
+ while (lasttime + us_per_tick <= now) {
+ lasttime += us_per_tick;
+ rtems_clock_tick();
+ }
+}
+
+static void xtratum_clock_handler_install(void)
+{
+ rtems_status_code sc;
+
+ sc = rtems_interrupt_handler_install(
+ CLOCK_EXT_TRAP_NUMBER,
+ "Clock",
+ RTEMS_INTERRUPT_UNIQUE,
+ xtratum_clock_handler,
+ NULL
+ );
+ if (sc != RTEMS_SUCCESSFUL) {
+ bsp_fatal(XM_BSP_FATAL_CLOCK_IRQ_INSTALL);
+ }
+}
+
+rtems_device_driver XTRATUM_CLOCK_INITIALIZE(
+ rtems_device_major_number major,
+ rtems_device_minor_number minor,
+ void *arg
+)
+{
+ uint32_t us_per_tick = rtems_configuration_get_microseconds_per_tick();
+ xmTime_t clocktime;
+
+ (void) major;
+ (void) minor;
+ (void) arg;
+
+ XM_get_time(XTRATUM_CLOCK, &clocktime);
+
+ lasttime = (uint32_t) clocktime;
+
+ xtratum_clock_handler_install();
+
+ rtems_clock_set_nanoseconds_extension(
+ xtratum_clock_nanoseconds_since_last_tick
+ );
+
+ XM_set_timer(XTRATUM_CLOCK, clocktime + us_per_tick, us_per_tick);
+
+ return RTEMS_SUCCESSFUL;
+}
diff --git a/c/src/lib/libbsp/sparc/xm-leon3/configure.ac b/c/src/lib/libbsp/sparc/xm-leon3/configure.ac
new file mode 100644
index 0000000000..39ecfde837
--- /dev/null
+++ b/c/src/lib/libbsp/sparc/xm-leon3/configure.ac
@@ -0,0 +1,29 @@
+## Process this file with autoconf to produce a configure script.
+
+AC_PREREQ([2.69])
+AC_INIT([rtems-c-src-lib-libbsp-sparc-xtratum],[_RTEMS_VERSION],[http://www.rtems.org/bugzilla])
+AC_CONFIG_SRCDIR([bsp_specs])
+RTEMS_TOP(../../../../../..)
+
+RTEMS_CANONICAL_TARGET_CPU
+AM_INIT_AUTOMAKE([no-define nostdinc foreign 1.12.2])
+RTEMS_BSP_CONFIGURE
+
+RTEMS_PROG_CC_FOR_TARGET
+RTEMS_CANONICALIZE_TOOLS
+RTEMS_PROG_CCAS
+
+RTEMS_CHECK_NETWORKING
+RTEMS_CHECK_SMP
+
+AM_CONDITIONAL(HAS_NETWORKING,test "$HAS_NETWORKING" = "yes")
+AM_CONDITIONAL(HAS_SMP,[test "$rtems_cv_HAS_SMP" = "yes"])
+
+RTEMS_BSPOPTS_SET([XTRATUM_SIZE_PAGE_TABLE],[*],[256])
+RTEMS_BSPOPTS_HELP([XTRATUM_SIZE_PAGE_TABLE],[Size of the XtratuM page table in pages.])
+
+RTEMS_BSP_CLEANUP_OPTIONS(0, 1)
+
+# Explicitly list all Makefiles here
+AC_CONFIG_FILES([Makefile])
+AC_OUTPUT
diff --git a/c/src/lib/libbsp/sparc/xm-leon3/console/console-apbuart.c b/c/src/lib/libbsp/sparc/xm-leon3/console/console-apbuart.c
new file mode 100644
index 0000000000..42ff68f02d
--- /dev/null
+++ b/c/src/lib/libbsp/sparc/xm-leon3/console/console-apbuart.c
@@ -0,0 +1,83 @@
+/*
+ * Copyright (c) 2014 embedded brains GmbH. All rights reserved.
+ *
+ * embedded brains GmbH
+ * Dornierstr. 4
+ * 82178 Puchheim
+ * Germany
+ * <info@embedded-brains.de>
+ *
+ * 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>
+#include <bsp/fatal.h>
+#include <apbuart.h>
+#include <apbuart_termios.h>
+#include <rtems/bspIo.h>
+
+static struct apbuart_context apbuart;
+
+static struct apbuart_regs *dbg_uart = &console_apbuart_regs;
+
+static void apbuart_out_char(char c)
+{
+ apbuart_outbyte_polled(dbg_uart, c, 1, 1);
+}
+
+static int apbuart_in_char(void)
+{
+ return apbuart_inbyte_nonblocking(dbg_uart);
+}
+
+static void preinit_debug_apbuart(void)
+{
+ dbg_uart->ctrl |= APBUART_CTRL_RE | APBUART_CTRL_TE;
+ dbg_uart->status = 0;
+}
+
+rtems_device_driver console_apbuart_initialize(
+ rtems_device_major_number major,
+ rtems_device_minor_number minor,
+ void *arg
+)
+{
+ const rtems_termios_device_handler *handler;
+ rtems_status_code status;
+
+ if (console_apbuart_use_interrupts == CONSOLE_APBUART_USE_INTERRUPTS) {
+ handler = &apbuart_handler_interrupt;
+ } else {
+ handler = &apbuart_handler_polled;
+ }
+
+ rtems_termios_device_context_initialize(&apbuart.base, "APBUART");
+
+ apbuart.regs = &console_apbuart_regs;
+ apbuart.freq_hz = (unsigned int) console_apbuart_freq_hz;
+ apbuart.irq = XTRATUM_TRAP_FROM_XM_HW_IRQ(
+ (rtems_vector_number) console_apbuart_vt_hw_irq_nr
+ );
+
+ preinit_debug_apbuart();
+
+ rtems_termios_initialize();
+
+ status = rtems_termios_device_install(
+ CONSOLE_DEVICE_NAME,
+ handler,
+ NULL,
+ &apbuart.base
+ );
+ if (status != RTEMS_SUCCESSFUL) {
+ bsp_fatal(XM_BSP_FATAL_CONSOLE_DEVICE_INSTALL_APBUART);
+ }
+
+ /* Use this UART for printk */
+ BSP_output_char = apbuart_out_char;
+ BSP_poll_char = apbuart_in_char;
+
+ return RTEMS_SUCCESSFUL;
+}
diff --git a/c/src/lib/libbsp/sparc/xm-leon3/include/bsp.h b/c/src/lib/libbsp/sparc/xm-leon3/include/bsp.h
new file mode 100644
index 0000000000..f719f473b6
--- /dev/null
+++ b/c/src/lib/libbsp/sparc/xm-leon3/include/bsp.h
@@ -0,0 +1,207 @@
+/*
+ * Copyright (c) 2014 embedded brains GmbH. All rights reserved.
+ *
+ * embedded brains GmbH
+ * Dornierstr. 4
+ * 82178 Puchheim
+ * Germany
+ * <info@embedded-brains.de>
+ *
+ * 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.
+ */
+
+#ifndef LIBBSP_SPARC_XTRATUM_BSP_H
+#define LIBBSP_SPARC_XTRATUM_BSP_H
+
+#include <bspopts.h>
+
+#ifndef ASM
+
+#include <rtems.h>
+#include <xtratum.h>
+#include <grlib.h>
+#include <rtems/console.h>
+#include <rtems/clockdrv.h>
+#include <rtems/irq-extension.h>
+
+#include <bsp/default-initial-extension.h>
+
+#define BSP_FEATURE_IRQ_EXTENSION
+
+#ifdef __cplusplus
+extern "C" {
+#endif /* __cplusplus */
+
+/*
+ * This BSP provides three clock drivers.
+ *
+ * 1. The standard clock driver uses the XtratuM hardware clock (XM_HW_CLOCK).
+ *
+ * Configuration:
+ *
+ * #define CONFIGURE_APPLICATION_NEEDS_CLOCK_DRIVER
+ *
+ * 2. The execution clock driver uses the XtratuM execution clock (XM_EXEC_CLOCK).
+ *
+ * Configuration:
+ *
+ * #define CONFIGURE_APPLICATION_EXTRA_DRIVERS \
+ * { .initialization_entry = clock_xtratum_exec_initialize }
+ * #define CONFIGURE_APPLICATION_DOES_NOT_NEED_CLOCK_DRIVER
+ *
+ * 3. The GPTIMER clock driver uses a GPTIMER module defined via clock_gpt_regs.
+ *
+ * Configuration:
+ *
+ * #define CONFIGURE_APPLICATION_EXTRA_DRIVERS \
+ * { .initialization_entry = clock_gpt_initialize }
+ * #define CONFIGURE_APPLICATION_DOES_NOT_NEED_CLOCK_DRIVER
+ *
+ * This GPTIMER module is also used for the CPU counter support if not
+ * defined to CLOCK_GPT_NOT_PRESENT. The clock_gpt_regs must be defined via
+ * the linker. It is assumed that XtratuM initialized the prescaler so that
+ * the counter frequency is 1MHz.
+ *
+ * The default memory location and IRQ is defined with linker symbols. You
+ * can overwrite them with application specific values to use another memory
+ * location and IRQ.
+ */
+
+rtems_device_driver clock_xtratum_exec_initialize(
+ rtems_device_major_number major,
+ rtems_device_minor_number minor,
+ void *arg
+);
+
+/*
+ * The first timer generates one interrupt per underflow it is set up so that
+ * it underflows once per tick.
+ */
+#define CLOCK_GPT_IDX_AUTO_RELOAD 0
+
+/*
+ * The second timer decrements on each underflow of first timer. So it counts
+ * the ticks.
+ */
+#define CLOCK_GPT_IDX_TICK_CTR (CLOCK_GPT_IDX_AUTO_RELOAD + 1)
+
+/*
+ * The third timer is a free running counter used for the CPU counter support.
+ */
+#define CLOCK_GPT_IDX_CPU_CTR (CLOCK_GPT_IDX_TICK_CTR + 1)
+
+#define CLOCK_GPT_NOT_PRESENT ((volatile struct gptimer_regs *) 0xdeadbee0)
+
+/*
+ * Symbol defined via linker command file.
+ *
+ * Define this symbol to CLOCK_GPT_NOT_PRESENT if you want to use the GPTIMER.
+ */
+extern volatile struct gptimer_regs clock_gpt_regs;
+
+/*
+ * Symbol defined via linker command file.
+ */
+extern char clock_gpt_vt_hw_irq_nr[];
+
+/*
+ * Symbol defined via linker command file.
+ */
+extern char clock_gpt_freq_hz[];
+
+rtems_device_driver clock_gpt_initialize(
+ rtems_device_major_number major,
+ rtems_device_minor_number minor,
+ void *arg
+);
+
+/*
+ * This BSP provides two console drivers.
+ *
+ * 1. The standard console driver uses the XtratuM hypervisor console.
+ *
+ * Configuration:
+ *
+ * #define CONFIGURE_APPLICATION_NEEDS_CONSOLE_DRIVER
+ *
+ * 2. The APBUART console uses the APBUART defined via console_apbuart_regs.
+ *
+ * Configuration:
+ *
+ * #define CONFIGURE_APPLICATION_PREREQUISITE_DRIVERS \
+ * CONSOLE_APBUART_DRIVER_TABLE_ENTRY
+ *
+ * Do NOT define CONFIGURE_APPLICATION_NEEDS_CONSOLE_DRIVER in your
+ * configuration.
+ *
+ * Please note that this driver uses the IRQ defined by XtratuM as
+ * XM_VT_HW_UART2_TRAP_NR. If you want to use another UART you have to map
+ * the IRQ to this line in your XtratuM configuration.
+ *
+ * Note the XtratuM hypervisor console is used for printk output until this
+ * console is initialized.
+ *
+ * The default memory location and IRQ is defined with linker symbols. You
+ * can overwrite them with application specific values to use another memory
+ * location and IRQ.
+ */
+
+/*
+ * Symbol defined via linker command file.
+ */
+extern struct apbuart_regs console_apbuart_regs;
+
+/*
+ * Symbol defined via linker command file.
+ */
+extern char console_apbuart_vt_hw_irq_nr[];
+
+/*
+ * Symbol defined via linker command file.
+ */
+extern char console_apbuart_initial_baud[];
+
+/*
+ * Symbol defined via linker command file.
+ */
+extern char console_apbuart_freq_hz[];
+
+#define CONSOLE_APBUART_USE_INTERRUPTS ((char *) 0xdeadbee0)
+
+/*
+ * Symbol defined via linker command file.
+ *
+ * Define this symbol to CONSOLE_APBUART_USE_INTERRUPTS if you want to use
+ * interrupts for the APBUART console driver.
+ */
+extern char console_apbuart_use_interrupts[];
+
+rtems_device_driver console_apbuart_initialize(
+ rtems_device_major_number major,
+ rtems_device_minor_number minor,
+ void *arg
+);
+
+#define CONSOLE_APBUART_DRIVER_TABLE_ENTRY \
+ { console_apbuart_initialize, console_open, console_close, \
+ console_read, console_write, console_control }
+
+extern int end;
+
+rtems_isr_entry set_vector(
+ rtems_isr_entry handler,
+ rtems_vector_number vector,
+ int type
+);
+
+void bsp_spurious_initialize(void);
+
+#ifdef __cplusplus
+}
+#endif /* __cplusplus */
+
+#endif /* ASM */
+
+#endif /* LIBBSP_SPARC_XTRATUM_BSP_H */
diff --git a/c/src/lib/libbsp/sparc/xm-leon3/include/cache_.h b/c/src/lib/libbsp/sparc/xm-leon3/include/cache_.h
new file mode 100644
index 0000000000..94025d6437
--- /dev/null
+++ b/c/src/lib/libbsp/sparc/xm-leon3/include/cache_.h
@@ -0,0 +1,113 @@
+/*
+ * Copyright (c) 2014 embedded brains GmbH. All rights reserved.
+ *
+ * embedded brains GmbH
+ * Dornierstr. 4
+ * 82178 Puchheim
+ * Germany
+ * <rtems@embedded-brains.de>
+ *
+ * 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.
+ */
+
+#ifndef XTRATUM_CACHE_H
+#define XTRATUM_CACHE_H
+
+#include <xtratum.h>
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+#define CPU_CACHE_SUPPORT_PROVIDES_RANGE_FUNCTIONS
+
+#define CPU_INSTRUCTION_CACHE_ALIGNMENT 64
+
+#define CPU_DATA_CACHE_ALIGNMENT 64
+
+static inline void _CPU_cache_flush_data_range(
+ const void *d_addr,
+ size_t n_bytes
+)
+{
+ /* TODO */
+}
+
+static inline void _CPU_cache_invalidate_data_range(
+ const void *d_addr,
+ size_t n_bytes
+)
+{
+ /* TODO */
+}
+
+static inline void _CPU_cache_freeze_data(void)
+{
+ /* TODO */
+}
+
+static inline void _CPU_cache_unfreeze_data(void)
+{
+ /* TODO */
+}
+
+static inline void _CPU_cache_invalidate_entire_instruction(void)
+{
+ __asm__ volatile ("flush");
+}
+
+static inline void _CPU_cache_invalidate_instruction_range(
+ const void *i_addr,
+ size_t n_bytes
+)
+{
+ _CPU_cache_invalidate_entire_instruction();
+}
+
+static inline void _CPU_cache_freeze_instruction(void)
+{
+ /* TODO */
+}
+
+static inline void _CPU_cache_unfreeze_instruction(void)
+{
+ /* TODO */
+}
+
+static inline void _CPU_cache_flush_entire_data(void)
+{
+ /* TODO */
+}
+
+static inline void _CPU_cache_invalidate_entire_data(void)
+{
+ /* TODO */
+}
+
+static inline void _CPU_cache_enable_data(void)
+{
+ /* TODO */
+}
+
+static inline void _CPU_cache_disable_data(void)
+{
+ /* TODO */
+}
+
+static inline void _CPU_cache_enable_instruction(void)
+{
+ /* TODO */
+}
+
+static inline void _CPU_cache_disable_instruction(void)
+{
+ /* TODO */
+}
+
+#ifdef __cplusplus
+}
+#endif /* __cplusplus */
+
+#endif /* XTRATUM_CACHE_H */
diff --git a/c/src/lib/libbsp/sparc/xm-leon3/include/irq.h b/c/src/lib/libbsp/sparc/xm-leon3/include/irq.h
new file mode 100644
index 0000000000..afa99c050b
--- /dev/null
+++ b/c/src/lib/libbsp/sparc/xm-leon3/include/irq.h
@@ -0,0 +1,2 @@
+#define BSP_INTERRUPT_VECTOR_MIN 0
+#define BSP_INTERRUPT_VECTOR_MAX (CPU_INTERRUPT_NUMBER_OF_VECTORS - 1)
diff --git a/c/src/lib/libbsp/sparc/xm-leon3/include/tm27.h b/c/src/lib/libbsp/sparc/xm-leon3/include/tm27.h
new file mode 100644
index 0000000000..85c49637a8
--- /dev/null
+++ b/c/src/lib/libbsp/sparc/xm-leon3/include/tm27.h
@@ -0,0 +1,30 @@
+/*
+ * tm27.h
+ *
+ * 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.
+ */
+
+#ifndef _RTEMS_TMTEST27
+#error "This is an RTEMS internal file you must not include directly."
+#endif
+
+#ifndef __tm27_h
+#define __tm27_h
+
+#define TEST_VECTOR SPARC_SYNCHRONOUS_TRAP( 0x90 )
+
+#define MUST_WAIT_FOR_INTERRUPT 1
+
+#define Install_tm27_vector( handler ) \
+ set_vector( (handler), TEST_VECTOR, 1 );
+
+#define Cause_tm27_intr() \
+ __asm__ volatile( "ta 0x10; nop " );
+
+#define Clear_tm27_intr() /* empty */
+
+#define Lower_tm27_intr() /* empty */
+
+#endif /* __tm27_h */
diff --git a/c/src/lib/libbsp/sparc/xm-leon3/include/xtratum.h b/c/src/lib/libbsp/sparc/xm-leon3/include/xtratum.h
new file mode 100644
index 0000000000..df1267c925
--- /dev/null
+++ b/c/src/lib/libbsp/sparc/xm-leon3/include/xtratum.h
@@ -0,0 +1,117 @@
+/*
+ * Copyright (c) 2014 embedded brains GmbH. All rights reserved.
+ *
+ * embedded brains GmbH
+ * Dornierstr. 4
+ * 82178 Puchheim
+ * Germany
+ * <info@embedded-brains.de>
+ *
+ * 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.
+ */
+
+#ifndef _INCLUDE_XTRATUM_H
+#define _INCLUDE_XTRATUM_H
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+#ifndef ASM
+
+/* XtratuM defines traps for the hardware interrupts as well as some XtratuM
+ * Extended interrupts.
+ * TRAP[0x11..0x1F] <=> Hardware interrupts
+ * TRAP[0x20..0x2F] <=> Reserved for future architectures
+ * TRAP[0xE0..0xFF] <=> XtratuM Extended interrupts
+ */
+
+#define XTRATUM_IRQ_HW_LOW_FIRST 0x01
+#define XTRATUM_IRQ_HW_LOW_LAST 0x0F
+#define XTRATUM_TRAP_HW_LOW_OFFSET 0x10
+#define XTRATUM_TRAP_HW_LOW_FIRST \
+ (XTRATUM_TRAP_HW_LOW_OFFSET + XTRATUM_IRQ_HW_LOW_FIRST)
+#define XTRATUM_TRAP_HW_LOW_LAST \
+ (XTRATUM_TRAP_HW_LOW_OFFSET + XTRATUM_IRQ_HW_LOW_LAST)
+
+#define XTRATUM_IRQ_HW_HIGH_FIRST 0x10
+#define XTRATUM_IRQ_HW_HIGH_LAST 0x1F
+#define XTRATUM_TRAP_HW_HIGH_OFFSET 0x20
+#define XTRATUM_TRAP_HW_HIGH_FIRST \
+ (XTRATUM_TRAP_HW_HIGH_OFFSET + XTRATUM_IRQ_HW_HIGH_FIRST)
+#define XTRATUM_TRAP_HW_HIGH_LAST \
+ (XTRATUM_TRAP_HW_HIGH_OFFSET + XTRATUM_IRQ_HW_HIGH_LAST)
+
+#define XTRATUM_TRAP_EXT_OFFSET 0xE0
+#define XTRATUM_TRAP_EXT_FIRST (XTRATUM_TRAP_EXT_OFFSET)
+#define XTRATUM_TRAP_EXT_LAST (XTRATUM_TRAP_EXT_OFFSET + 0x1F)
+
+/* Converter macros for the irq-numbers defined by XtratuM */
+static inline rtems_vector_number XTRATUM_TRAP_FROM_XM_HW_IRQ(
+ uint32_t xm_vt_hw
+)
+{
+ rtems_vector_number vector = 0;
+ if(xm_vt_hw <= XTRATUM_IRQ_HW_LOW_LAST) {
+ vector = xm_vt_hw + XTRATUM_TRAP_HW_LOW_OFFSET;
+ } else {
+ vector = xm_vt_hw + XTRATUM_TRAP_HW_HIGH_OFFSET;
+ }
+ return vector;
+}
+
+#define XTRATUM_TRAP_FROM_XM_EXT_IRQ( xm_vt_ext ) \
+ ((xm_vt_ext) + XTRATUM_TRAP_EXT_OFFSET )
+
+/* Check for the trap number type */
+#define XTRATUM_TRAP_IS_HW_LOW( trap ) \
+ ((trap) >= XTRATUM_TRAP_HW_LOW_FIRST && (trap) <= XTRATUM_TRAP_HW_LOW_LAST)
+
+#define XTRATUM_TRAP_IS_HW_HIGH( trap ) \
+ ((trap) >= XTRATUM_TRAP_HW_HIGH_FIRST && (trap) <= XTRATUM_TRAP_HW_HIGH_LAST)
+
+#define XTRATUM_TRAP_IS_HW( trap ) \
+ (XTRATUM_TRAP_IS_HW_LOW(trap) || XTRATUM_TRAP_IS_HW_HIGH(trap))
+
+#define XTRATUM_TRAP_IS_EXT( trap ) \
+ ((trap) >= XTRATUM_TRAP_EXT_FIRST && (trap) <= XTRATUM_TRAP_EXT_LAST)
+
+#define XTRATUM_TRAP_IS_INTERRUPT( trap ) \
+ (XTRATUM_TRAP_IS_HW( trap ) || XTRATUM_TRAP_IS_EXT( trap ))
+
+/* get masks from trap number */
+static inline uint32_t xtratum_hw_mask( rtems_vector_number vector )
+{
+ uint32_t hw_mask = 0;
+ if ( XTRATUM_TRAP_IS_HW_LOW( vector ) ) {
+ hw_mask = 1 << (vector - XTRATUM_TRAP_HW_LOW_OFFSET);
+ } else if ( XTRATUM_TRAP_IS_HW_HIGH( vector ) ) {
+ hw_mask = 1 << (vector - XTRATUM_TRAP_HW_HIGH_OFFSET);
+ }
+ return hw_mask;
+}
+
+static inline uint32_t xtratum_ext_mask( rtems_vector_number vector )
+{
+ uint32_t ext_mask = 0;
+ if ( XTRATUM_TRAP_IS_EXT( vector ) ) {
+ ext_mask = 1 << (vector - XTRATUM_TRAP_EXT_OFFSET);
+ }
+ return ext_mask;
+}
+
+#endif /* ASM */
+
+void bsp_clear_interrupt( rtems_vector_number vector );
+void bsp_unmask_interrupt( rtems_vector_number vector );
+void bsp_mask_interrupt( rtems_vector_number vector );
+void xtratum_interrupt_init(void);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* _INCLUDE_XTRATUM_H */
+
diff --git a/c/src/lib/libbsp/sparc/xm-leon3/irq/irq.c b/c/src/lib/libbsp/sparc/xm-leon3/irq/irq.c
new file mode 100644
index 0000000000..3f3cb098a8
--- /dev/null
+++ b/c/src/lib/libbsp/sparc/xm-leon3/irq/irq.c
@@ -0,0 +1,98 @@
+/*
+ * Copyright (c) 2014 embedded brains GmbH. All rights reserved.
+ *
+ * embedded brains GmbH
+ * Dornierstr. 4
+ * 82178 Puchheim
+ * Germany
+ * <info@embedded-brains.de>
+ *
+ * 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 <rtems.h>
+#include <bsp.h>
+#include <bsp/irq-generic.h>
+#include <xm.h>
+
+static void bsp_isr_handler(rtems_vector_number vector)
+{
+ bsp_interrupt_handler_dispatch(vector);
+}
+
+void xtratum_interrupt_init(void)
+{
+ rtems_vector_number vector;
+ rtems_isr_entry previous_isr;
+
+ for (
+ vector = XTRATUM_TRAP_HW_LOW_FIRST;
+ vector <= XTRATUM_TRAP_HW_LOW_LAST;
+ vector++
+ ) {
+ rtems_interrupt_catch(bsp_isr_handler, vector, &previous_isr);
+ }
+
+ for (
+ vector = XTRATUM_TRAP_HW_HIGH_FIRST;
+ vector <= XTRATUM_TRAP_HW_HIGH_LAST;
+ vector++
+ ) {
+ rtems_interrupt_catch(bsp_isr_handler, vector, &previous_isr);
+ }
+
+ for (
+ vector = XTRATUM_TRAP_EXT_FIRST;
+ vector <= XTRATUM_TRAP_EXT_LAST;
+ vector++
+ ) {
+ rtems_interrupt_catch(bsp_isr_handler, vector, &previous_isr);
+ }
+
+ bsp_interrupt_initialize();
+}
+
+rtems_status_code bsp_interrupt_facility_initialize(void)
+{
+ return RTEMS_SUCCESSFUL;
+}
+
+rtems_status_code bsp_interrupt_vector_enable(rtems_vector_number vector)
+{
+ bsp_unmask_interrupt(vector);
+
+ return RTEMS_SUCCESSFUL;
+}
+
+rtems_status_code bsp_interrupt_vector_disable(rtems_vector_number vector)
+{
+ bsp_mask_interrupt(vector);
+
+ return RTEMS_SUCCESSFUL;
+}
+
+void bsp_clear_interrupt( rtems_vector_number vector )
+{
+ uint32_t hw_mask = xtratum_hw_mask( vector );
+ uint32_t ext_mask = xtratum_ext_mask( vector );
+
+ XM_clear_irqpend( hw_mask, ext_mask );
+}
+
+void bsp_unmask_interrupt( rtems_vector_number vector )
+{
+ uint32_t hw_mask = xtratum_hw_mask( vector );
+ uint32_t ext_mask = xtratum_ext_mask( vector );
+
+ XM_clear_irqmask( hw_mask, ext_mask );
+}
+
+void bsp_mask_interrupt( rtems_vector_number vector )
+{
+ uint32_t hw_mask = xtratum_hw_mask( vector );
+ uint32_t ext_mask = xtratum_ext_mask( vector );
+
+ XM_set_irqmask( hw_mask, ext_mask );
+}
+
diff --git a/c/src/lib/libbsp/sparc/xm-leon3/make/custom/xm_leon3.cfg b/c/src/lib/libbsp/sparc/xm-leon3/make/custom/xm_leon3.cfg
new file mode 100644
index 0000000000..26832b560f
--- /dev/null
+++ b/c/src/lib/libbsp/sparc/xm-leon3/make/custom/xm_leon3.cfg
@@ -0,0 +1,55 @@
+#
+# Config file for the XtratuM Hypervisor on LEON3.
+#
+
+include $(RTEMS_ROOT)/make/custom/default.cfg
+
+RTEMS_CPU=sparc
+RTEMS_CPU_MODEL=leon3
+
+# This contains the compiler options necessary to select the CPU model
+# and (hopefully) optimize for it.
+CPU_CFLAGS = -mcpu=leon3 -muser-mode -msoft-float
+
+# optimize flag: typically -O2
+CFLAGS_OPTIMIZE_V = -O2 -g
+CFLAGS_OPTIMIZE_V += -ffunction-sections -fdata-sections
+
+LDFLAGS = -Wl,--gc-sections
+LDFLAGS += -L"$(XTRATUM_PATH)/lib"
+LDFLAGS += -u xmImageHdr
+
+# Variables for building XtratuM executable
+XMRSWBUILD = $(XTRATUM_PATH)/bin/rswbuild
+XMPACK = $(XTRATUM_PATH)/bin/xmpack
+XMEFORMAT = $(XTRATUM_PATH)/bin/xmeformat
+XMCPARSER = $(XTRATUM_PATH)/bin/xmcparser
+XMCORE = $(XTRATUM_PATH)/lib/xm_core.xef
+
+ifeq ($(XTRATUM_CONFIG),)
+ XTRATUM_CONFIG = $(PROJECT_LIB)/example_xm_cf.xml
+endif
+
+XM_BASENAME = $(basename $@)
+XM_INPUT = $(XM_BASENAME).exe
+XM_XEF = $(XM_BASENAME).xef
+XM_BIN_XMC = $(XM_BASENAME).xm_cf.bin.xmc
+XM_XEF_XMC = $(XM_BASENAME).xm_cf.bin.xmc
+XM_CONTAINER_BIN = $(XM_BASENAME).bin
+XM_EXECUTABLE = $(XM_BASENAME).ralf
+XMPACK_ARGS = -h $(XMCORE):$(XM_XEF_XMC) -p 0:$(XM_XEF)
+
+define bsp-post-link
+ $(default-bsp-post-link)
+
+ $(XMEFORMAT) build $(XM_INPUT) -o $(XM_XEF)
+
+ $(XMCPARSER) -o $(XM_BIN_XMC) $(XTRATUM_CONFIG)
+
+ $(XMEFORMAT) build -m $(XM_BIN_XMC) -c -o $(XM_XEF_XMC)
+
+ $(XMPACK) check $(XM_XEF_XMC) $(XMPACK_ARGS)
+ $(XMPACK) build $(XMPACK_ARGS) $(XM_CONTAINER_BIN)
+
+ $(XMRSWBUILD) $(XM_CONTAINER_BIN) $(XM_EXECUTABLE)
+endef
diff --git a/c/src/lib/libbsp/sparc/xm-leon3/preinstall.am b/c/src/lib/libbsp/sparc/xm-leon3/preinstall.am
new file mode 100644
index 0000000000..7c68ce8b7d
--- /dev/null
+++ b/c/src/lib/libbsp/sparc/xm-leon3/preinstall.am
@@ -0,0 +1,115 @@
+## Automatically generated by ampolish3 - Do not edit
+
+if AMPOLISH3
+$(srcdir)/preinstall.am: Makefile.am
+ $(AMPOLISH3) $(srcdir)/Makefile.am > $(srcdir)/preinstall.am
+endif
+
+PREINSTALL_DIRS =
+DISTCLEANFILES += $(PREINSTALL_DIRS)
+
+all-am: $(PREINSTALL_FILES)
+
+PREINSTALL_FILES =
+CLEANFILES = $(PREINSTALL_FILES)
+
+all-local: $(TMPINSTALL_FILES)
+
+TMPINSTALL_FILES =
+CLEANFILES += $(TMPINSTALL_FILES)
+
+$(PROJECT_LIB)/$(dirstamp):
+ @$(MKDIR_P) $(PROJECT_LIB)
+ @: > $(PROJECT_LIB)/$(dirstamp)
+PREINSTALL_DIRS += $(PROJECT_LIB)/$(dirstamp)
+
+$(PROJECT_INCLUDE)/$(dirstamp):
+ @$(MKDIR_P) $(PROJECT_INCLUDE)
+ @: > $(PROJECT_INCLUDE)/$(dirstamp)
+PREINSTALL_DIRS += $(PROJECT_INCLUDE)/$(dirstamp)
+
+$(PROJECT_INCLUDE)/bsp/$(dirstamp):
+ @$(MKDIR_P) $(PROJECT_INCLUDE)/bsp
+ @: > $(PROJECT_INCLUDE)/bsp/$(dirstamp)
+PREINSTALL_DIRS += $(PROJECT_INCLUDE)/bsp/$(dirstamp)
+
+$(PROJECT_LIB)/bsp_specs: bsp_specs $(PROJECT_LIB)/$(dirstamp)
+ $(INSTALL_DATA) $< $(PROJECT_LIB)/bsp_specs
+PREINSTALL_FILES += $(PROJECT_LIB)/bsp_specs
+
+$(PROJECT_INCLUDE)/bsp.h: include/bsp.h $(PROJECT_INCLUDE)/$(dirstamp)
+ $(INSTALL_DATA) $< $(PROJECT_INCLUDE)/bsp.h
+PREINSTALL_FILES += $(PROJECT_INCLUDE)/bsp.h
+
+$(PROJECT_INCLUDE)/tm27.h: include/tm27.h $(PROJECT_INCLUDE)/$(dirstamp)
+ $(INSTALL_DATA) $< $(PROJECT_INCLUDE)/tm27.h
+PREINSTALL_FILES += $(PROJECT_INCLUDE)/tm27.h
+
+$(PROJECT_INCLUDE)/debug_defs.h: ../../sparc/shared/include/debug_defs.h $(PROJECT_INCLUDE)/$(dirstamp)
+ $(INSTALL_DATA) $< $(PROJECT_INCLUDE)/debug_defs.h
+PREINSTALL_FILES += $(PROJECT_INCLUDE)/debug_defs.h
+
+$(PROJECT_INCLUDE)/bspopts.h: include/bspopts.h $(PROJECT_INCLUDE)/$(dirstamp)
+ $(INSTALL_DATA) $< $(PROJECT_INCLUDE)/bspopts.h
+PREINSTALL_FILES += $(PROJECT_INCLUDE)/bspopts.h
+
+$(PROJECT_INCLUDE)/bsp/bootcard.h: ../../shared/include/bootcard.h $(PROJECT_INCLUDE)/bsp/$(dirstamp)
+ $(INSTALL_DATA) $< $(PROJECT_INCLUDE)/bsp/bootcard.h
+PREINSTALL_FILES += $(PROJECT_INCLUDE)/bsp/bootcard.h
+
+$(PROJECT_INCLUDE)/xtratum.h: include/xtratum.h $(PROJECT_INCLUDE)/$(dirstamp)
+ $(INSTALL_DATA) $< $(PROJECT_INCLUDE)/xtratum.h
+PREINSTALL_FILES += $(PROJECT_INCLUDE)/xtratum.h
+
+$(PROJECT_INCLUDE)/coverhd.h: ../../shared/include/coverhd.h $(PROJECT_INCLUDE)/$(dirstamp)
+ $(INSTALL_DATA) $< $(PROJECT_INCLUDE)/coverhd.h
+PREINSTALL_FILES += $(PROJECT_INCLUDE)/coverhd.h
+
+$(PROJECT_LIB)/start.$(OBJEXT): start.$(OBJEXT) $(PROJECT_LIB)/$(dirstamp)
+ $(INSTALL_DATA) $< $(PROJECT_LIB)/start.$(OBJEXT)
+TMPINSTALL_FILES += $(PROJECT_LIB)/start.$(OBJEXT)
+
+$(PROJECT_LIB)/linkcmds.base: ../shared/startup/linkcmds.base $(PROJECT_LIB)/$(dirstamp)
+ $(INSTALL_DATA) $< $(PROJECT_LIB)/linkcmds.base
+PREINSTALL_FILES += $(PROJECT_LIB)/linkcmds.base
+
+$(PROJECT_LIB)/linkcmds: startup/linkcmds $(PROJECT_LIB)/$(dirstamp)
+ $(INSTALL_DATA) $< $(PROJECT_LIB)/linkcmds
+PREINSTALL_FILES += $(PROJECT_LIB)/linkcmds
+
+$(PROJECT_LIB)/example_xm_cf.xml: startup/example_xm_cf.xml $(PROJECT_LIB)/$(dirstamp)
+ $(INSTALL_DATA) $< $(PROJECT_LIB)/example_xm_cf.xml
+PREINSTALL_FILES += $(PROJECT_LIB)/example_xm_cf.xml
+
+$(PROJECT_INCLUDE)/ambapp.h: ../../sparc/shared/include/ambapp.h $(PROJECT_INCLUDE)/$(dirstamp)
+ $(INSTALL_DATA) $< $(PROJECT_INCLUDE)/ambapp.h
+PREINSTALL_FILES += $(PROJECT_INCLUDE)/ambapp.h
+
+$(PROJECT_INCLUDE)/ambapp_ids.h: ../../sparc/shared/include/ambapp_ids.h $(PROJECT_INCLUDE)/$(dirstamp)
+ $(INSTALL_DATA) $< $(PROJECT_INCLUDE)/ambapp_ids.h
+PREINSTALL_FILES += $(PROJECT_INCLUDE)/ambapp_ids.h
+
+$(PROJECT_INCLUDE)/grlib.h: ../../sparc/shared/include/grlib.h $(PROJECT_INCLUDE)/$(dirstamp)
+ $(INSTALL_DATA) $< $(PROJECT_INCLUDE)/grlib.h
+PREINSTALL_FILES += $(PROJECT_INCLUDE)/grlib.h
+
+$(PROJECT_INCLUDE)/bsp/apbuart.h: ../../sparc/shared/include/apbuart.h $(PROJECT_INCLUDE)/bsp/$(dirstamp)
+ $(INSTALL_DATA) $< $(PROJECT_INCLUDE)/bsp/apbuart.h
+PREINSTALL_FILES += $(PROJECT_INCLUDE)/bsp/apbuart.h
+
+$(PROJECT_INCLUDE)/bsp/apbuart_termios.h: ../../sparc/shared/include/apbuart_termios.h $(PROJECT_INCLUDE)/bsp/$(dirstamp)
+ $(INSTALL_DATA) $< $(PROJECT_INCLUDE)/bsp/apbuart_termios.h
+PREINSTALL_FILES += $(PROJECT_INCLUDE)/bsp/apbuart_termios.h
+
+$(PROJECT_INCLUDE)/bsp/irq-generic.h: ../../shared/include/irq-generic.h $(PROJECT_INCLUDE)/bsp/$(dirstamp)
+ $(INSTALL_DATA) $< $(PROJECT_INCLUDE)/bsp/irq-generic.h
+PREINSTALL_FILES += $(PROJECT_INCLUDE)/bsp/irq-generic.h
+
+$(PROJECT_INCLUDE)/bsp/irq-info.h: ../../shared/include/irq-info.h $(PROJECT_INCLUDE)/bsp/$(dirstamp)
+ $(INSTALL_DATA) $< $(PROJECT_INCLUDE)/bsp/irq-info.h
+PREINSTALL_FILES += $(PROJECT_INCLUDE)/bsp/irq-info.h
+
+$(PROJECT_INCLUDE)/bsp/irq.h: include/irq.h $(PROJECT_INCLUDE)/bsp/$(dirstamp)
+ $(INSTALL_DATA) $< $(PROJECT_INCLUDE)/bsp/irq.h
+PREINSTALL_FILES += $(PROJECT_INCLUDE)/bsp/irq.h
+
diff --git a/c/src/lib/libbsp/sparc/xm-leon3/startup/bspreset.c b/c/src/lib/libbsp/sparc/xm-leon3/startup/bspreset.c
new file mode 100644
index 0000000000..2d5d62bf8b
--- /dev/null
+++ b/c/src/lib/libbsp/sparc/xm-leon3/startup/bspreset.c
@@ -0,0 +1,58 @@
+/*
+ * Copyright (c) 2014 embedded brains GmbH. All rights reserved.
+ *
+ * embedded brains GmbH
+ * Dornierstr. 4
+ * 82178 Puchheim
+ * Germany
+ * <info@embedded-brains.de>
+ *
+ * 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 <xm.h>
+#include <bsp/bootcard.h>
+
+void bsp_reset(void)
+{
+ uint32_t self_cpu = rtems_get_current_processor();
+
+ if (self_cpu == 0) {
+ /* Value should give us roughly something in the range of a few
+ * milliseconds. */
+ volatile uint32_t max_wait = 1234567;
+ uint32_t cpu_count = rtems_get_processor_count();
+ uint32_t cpus_halted = 0;
+
+ /* Wait some time for secondary processors to halt */
+ do {
+ xmVirtualCpuStatus_t status;
+ cpus_halted = 0;
+ uint32_t i;
+
+ for (i=1; i<cpu_count; ++i) {
+ XM_get_vcpu_status(i, &status);
+ if (status.state == XM_STATUS_HALTED) {
+ ++cpus_halted;
+ }
+ }
+ --max_wait;
+ } while (cpus_halted < cpu_count - 1 && max_wait > 0);
+
+ XM_halt_partition(XM_PARTITION_SELF);
+ } else {
+ XM_halt_vcpu(self_cpu);
+ }
+
+ while (1);
+}
+
+void _CPU_Fatal_halt(uint32_t source, uint32_t error)
+{
+ (void) source;
+ (void) error;
+
+ bsp_reset();
+}
diff --git a/c/src/lib/libbsp/sparc/xm-leon3/startup/bspsmp.c b/c/src/lib/libbsp/sparc/xm-leon3/startup/bspsmp.c
new file mode 100644
index 0000000000..f604144ffb
--- /dev/null
+++ b/c/src/lib/libbsp/sparc/xm-leon3/startup/bspsmp.c
@@ -0,0 +1,105 @@
+/*
+ * Copyright (c) 2014 embedded brains GmbH. All rights reserved.
+ *
+ * embedded brains GmbH
+ * Dornierstr. 4
+ * 82178 Puchheim
+ * Germany
+ * <info@embedded-brains.de>
+ *
+ * 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 <assert.h>
+#include <bsp.h>
+#include <bsp/bootcard.h>
+#include <xm.h>
+#include <rtems/score/smpimpl.h>
+#include <fatal.h>
+
+#define IPVI_NR( idx ) (XM_VT_EXT_IPVI0 + idx)
+#define IPVI_TRAP_NR( idx ) XTRATUM_TRAP_FROM_XM_EXT_IRQ( IPVI_NR( idx ) )
+
+void start(void);
+extern struct xmImageHdr xmImageHdr;
+
+uint32_t _CPU_SMP_Get_current_processor(void)
+{
+ return XM_get_vcpuid();
+}
+
+static rtems_isr bsp_inter_processor_interrupt(
+ rtems_vector_number vector
+)
+{
+ _SMP_Inter_processor_interrupt_handler();
+}
+
+void bsp_start_on_secondary_processor(void)
+{
+ rtems_vector_number vector = IPVI_TRAP_NR(_CPU_SMP_Get_current_processor());
+ bsp_unmask_interrupt(vector);
+
+ _SMP_Start_multitasking_on_secondary_processor();
+}
+
+static void install_vector_without_unmask(
+ rtems_isr_entry new_isr_handler,
+ rtems_vector_number vector
+) {
+ rtems_isr_entry previous_isr;
+
+ rtems_interrupt_catch(
+ new_isr_handler,
+ vector,
+ &previous_isr
+ );
+
+ bsp_clear_interrupt( vector );
+
+ rtems_cache_invalidate_entire_instruction();
+}
+
+uint32_t _CPU_SMP_Initialize(void)
+{
+ uint32_t cpu_index_self = XM_get_vcpuid();
+ rtems_vector_number vector = IPVI_TRAP_NR(cpu_index_self);
+
+ if (cpu_index_self != 0) {
+ bsp_fatal(XM_BSP_FATAL_CPU_SMP_INITIALIZE);
+ }
+
+ if (rtems_configuration_get_maximum_processors() > 1) {
+ install_vector_without_unmask(bsp_inter_processor_interrupt, vector);
+ bsp_unmask_interrupt(vector);
+ }
+
+ return XM_get_number_vcpus();
+}
+
+bool _CPU_SMP_Start_processor(uint32_t cpu_index)
+{
+ int32_t rv;
+ rtems_vector_number vector = IPVI_TRAP_NR(cpu_index);
+
+ install_vector_without_unmask(bsp_inter_processor_interrupt, vector);
+
+ rv = XM_reset_vcpu(cpu_index, xmImageHdr.pageTable, (xm_s32_t) start, 0);
+ assert(rv == XM_OK);
+
+ return true;
+}
+
+void _CPU_SMP_Finalize_initialization(uint32_t cpu_count)
+{
+ (void) cpu_count;
+
+ /* Nothing to do */
+}
+
+void _CPU_SMP_Send_interrupt(uint32_t target_processor_index)
+{
+ XM_raise_ipvi(IPVI_NR(target_processor_index));
+}
diff --git a/c/src/lib/libbsp/sparc/xm-leon3/startup/bspstart.c b/c/src/lib/libbsp/sparc/xm-leon3/startup/bspstart.c
new file mode 100644
index 0000000000..8fb454924e
--- /dev/null
+++ b/c/src/lib/libbsp/sparc/xm-leon3/startup/bspstart.c
@@ -0,0 +1,55 @@
+/*
+ * Copyright (c) 2014 embedded brains GmbH. All rights reserved.
+ *
+ * embedded brains GmbH
+ * Dornierstr. 4
+ * 82178 Puchheim
+ * Germany
+ * <info@embedded-brains.de>
+ *
+ * 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>
+#include <bsp/irq.h>
+#include <bsp/bootcard.h>
+
+#include <rtems/counter.h>
+#include <rtems/score/sparcimpl.h>
+
+static CPU_Counter_ticks free_counter_difference(
+ CPU_Counter_ticks second,
+ CPU_Counter_ticks first
+)
+{
+ return first - second;
+}
+
+static void cpu_counter_init(void)
+{
+ volatile struct gptimer_regs *gpt = &clock_gpt_regs;
+
+ if (&clock_gpt_regs != CLOCK_GPT_NOT_PRESENT) {
+ size_t timer_index = CLOCK_GPT_IDX_CPU_CTR;
+
+ gpt->timer[timer_index].reload = 0xffffffff;
+ gpt->timer[timer_index].ctrl = GPTIMER_TIMER_CTRL_EN
+ | GPTIMER_TIMER_CTRL_RS | GPTIMER_TIMER_CTRL_LD;
+
+ _SPARC_Counter_initialize(
+ _SPARC_Counter_read_address,
+ free_counter_difference,
+ (volatile const uint32_t *) &gpt->timer[timer_index].value
+ );
+
+ rtems_counter_initialize_converter(1000000);
+ }
+}
+
+void bsp_start(void)
+{
+ cpu_counter_init();
+ xtratum_interrupt_init();
+}
diff --git a/c/src/lib/libbsp/sparc/xm-leon3/startup/example_xm_cf.xml b/c/src/lib/libbsp/sparc/xm-leon3/startup/example_xm_cf.xml
new file mode 100644
index 0000000000..1747dbf2d2
--- /dev/null
+++ b/c/src/lib/libbsp/sparc/xm-leon3/startup/example_xm_cf.xml
@@ -0,0 +1,69 @@
+<?xml version="1.0"?>
+<SystemDescription xmlns="http://www.xtratum.org/xm-3.x" version="1.0.0" name="hello_world">
+ <HwDescription>
+ <MemoryLayout>
+ <Region type="sdram" start="0x0" size="256MB"/>
+ <!-- UART1 -->
+ <Region type="sdram" start="0xFF901000" size="4096B"/>
+ <!-- GPTIMER4 -->
+ <Region type="sdram" start="0xFF90C000" size="4096B"/>
+ </MemoryLayout>
+ <ProcessorTable>
+ <Processor id="0" frequency="150Mhz">
+ <CyclicPlanTable>
+ <Plan id="0" majorFrame="1000ms">
+ <Slot id="0" start="0ms" duration="900ms" partitionId="0" vCpuId="0"/>
+ </Plan>
+ </CyclicPlanTable>
+ </Processor>
+ <Processor id="1" frequency="150Mhz">
+ <CyclicPlanTable>
+ <Plan id="0" majorFrame="1000ms">
+ <Slot id="0" start="0ms" duration="900ms" partitionId="0" vCpuId="1"/>
+ </Plan>
+ </CyclicPlanTable>
+ </Processor>
+ <Processor id="2" frequency="150Mhz">
+ <CyclicPlanTable>
+ <Plan id="0" majorFrame="1000ms">
+ <Slot id="0" start="0ms" duration="900ms" partitionId="0" vCpuId="2"/>
+ </Plan>
+ </CyclicPlanTable>
+ </Processor>
+ <Processor id="3" frequency="150Mhz">
+ <CyclicPlanTable>
+ <Plan id="0" majorFrame="1000ms">
+ <Slot id="0" start="0ms" duration="900ms" partitionId="0" vCpuId="3"/>
+ </Plan>
+ </CyclicPlanTable>
+ </Processor>
+ </ProcessorTable>
+ <Devices>
+ <Uart id="0" baudRate="115200" name="Uart"/>
+ </Devices>
+ </HwDescription>
+ <XMHypervisor console="Uart">
+ <PhysicalMemoryArea size="16MB"/>
+ <IoMmu>
+ <AhbMst id="0" partitionId="0" busRouting="memory" vendorId="0x1" deviceId="0x11" />
+ </IoMmu>
+ </XMHypervisor>
+ <PartitionTable>
+ <Partition id="0" name="Partition1" flags="system" console="Uart" noVCpus="4">
+ <PhysicalMemoryAreas>
+ <Area start="0x02000000" size="16MB"/>
+ <Area start="0xFF901000" size="4096B" mappedAt="0x40901000" flags="uncacheable iommu"/>
+ <Area start="0xFF90C000" size="4096B" mappedAt="0x4090C000" flags="uncacheable iommu"/>
+ </PhysicalMemoryAreas>
+ <HwResources>
+ <Interrupts lines="9 30"/>
+ </HwResources>
+ </Partition>
+ </PartitionTable>
+ <Channels>
+ <Ipvi id="0" sourceId="0" destinationId="0"/>
+ <Ipvi id="1" sourceId="0" destinationId="0"/>
+ <Ipvi id="2" sourceId="0" destinationId="0"/>
+ <Ipvi id="3" sourceId="0" destinationId="0"/>
+ </Channels>
+</SystemDescription>
diff --git a/c/src/lib/libbsp/sparc/xm-leon3/startup/isr-en-dis.S b/c/src/lib/libbsp/sparc/xm-leon3/startup/isr-en-dis.S
new file mode 100644
index 0000000000..c427df7ce7
--- /dev/null
+++ b/c/src/lib/libbsp/sparc/xm-leon3/startup/isr-en-dis.S
@@ -0,0 +1,50 @@
+/*
+ * irq_en_dis.S
+ *
+ * Disabling or enabling the IRQ.
+ *
+ * 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.
+ *
+ * COPYRIGHT (c) 1995. European Space Agency.
+ * COPYRIGHT (c) 2011 UPV (Universidad Politécnica de Valencia)
+ *
+ * This terms of the RTEMS license apply to this file.
+ */
+
+#include <rtems/asm.h>
+#include <xm.h>
+
+ .seg "text"
+
+ PUBLIC(sparc_disable_interrupts)
+
+SYM(sparc_disable_interrupts):
+
+ set sparc_get_psr_nr, %o0
+ __XM_AHC
+ ! psr is now in %o0
+ mov %o0, %g1
+ set sparc_set_pil_nr, %o0
+ __XM_AHC
+ retl
+ mov %g1, %o0
+
+ PUBLIC(sparc_enable_interrupts)
+
+SYM(sparc_enable_interrupts):
+
+ mov %o0, %g1
+ set sparc_get_psr_nr, %o0
+ __XM_AHC
+ ! psr is now in %o0, old one in %g1
+ and %g1, SPARC_PSR_PIL_MASK, %g1
+ andn %o0, SPARC_PSR_PIL_MASK, %o0
+ or %o0, %g1, %o1
+ set sparc_set_psr_nr, %o0
+ __XM_AHC
+ retl
+ nop
+
+/* end of file */
diff --git a/c/src/lib/libbsp/sparc/xm-leon3/startup/linkcmds b/c/src/lib/libbsp/sparc/xm-leon3/startup/linkcmds
new file mode 100644
index 0000000000..019f6f6b6d
--- /dev/null
+++ b/c/src/lib/libbsp/sparc/xm-leon3/startup/linkcmds
@@ -0,0 +1,34 @@
+/* linkcmds
+ */
+
+/* Default values, can be overridden */
+
+_PROM_SIZE = DEFINED (_PROM_SIZE) ? _PROM_SIZE : 0;
+_PROM_START = DEFINED (_PROM_START) ? _PROM_START : 0x00000000;
+
+_RAM_SIZE = DEFINED (_RAM_SIZE) ? _RAM_SIZE : 16M;
+_RAM_START = DEFINED (_RAM_START) ? _RAM_START : 0x02000000;
+
+/* Define it to 0xdeadbee0 to prevent usage of this GPTIMER */
+clock_gpt_regs = DEFINED (clock_gpt_regs) ? clock_gpt_regs : 0x4090c000;
+
+clock_gpt_vt_hw_irq_nr = DEFINED (clock_gpt_vt_hw_irq_nr) ? clock_gpt_vt_hw_irq_nr : 9;
+clock_gpt_freq_hz = DEFINED (clock_gpt_freq_hz) ? clock_gpt_freq_hz : 1000000;
+
+console_apbuart_regs = DEFINED (console_apbuart_regs) ? console_apbuart_regs : 0x40901000;
+console_apbuart_vt_hw_irq_nr = DEFINED (console_apbuart_vt_hw_irq_nr) ? console_apbuart_vt_hw_irq_nr : 30;
+console_apbuart_initial_baud = DEFINED (console_apbuart_initial_baud) ? console_apbuart_initial_baud : 115200;
+console_apbuart_freq_hz = DEFINED (console_apbuart_freq_hz) ? console_apbuart_freq_hz : 150000000;
+
+/* Define it to 0xdeadbee0 to use interrupts (default = polled mode) */
+console_apbuart_use_interrupts = DEFINED (console_apbuart_use_interrupts) ? console_apbuart_use_interrupts : 0;
+
+/* these are the maximum values */
+
+MEMORY
+{
+ rom : ORIGIN = 0x00000000, LENGTH = 0
+ ram : ORIGIN = 0x02000000, LENGTH = 16M
+}
+
+INCLUDE linkcmds.base
diff --git a/c/src/lib/libbsp/sparc/xm-leon3/startup/psr.c b/c/src/lib/libbsp/sparc/xm-leon3/startup/psr.c
new file mode 100644
index 0000000000..21a84e76af
--- /dev/null
+++ b/c/src/lib/libbsp/sparc/xm-leon3/startup/psr.c
@@ -0,0 +1,26 @@
+/*
+ * Copyright (c) 2014 embedded brains GmbH. All rights reserved.
+ *
+ * embedded brains GmbH
+ * Dornierstr. 4
+ * 82178 Puchheim
+ * Germany
+ * <info@embedded-brains.de>
+ *
+ * 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 <rtems/score/sparc.h>
+#include <xm.h>
+
+uint32_t _SPARC_Get_PSR( void )
+{
+ return XM_sparc_get_psr();
+}
+
+void _SPARC_Set_PSR( uint32_t new_psr )
+{
+ XM_sparc_set_psr( new_psr );
+}
diff --git a/c/src/lib/libbsp/sparc/xm-leon3/startup/setvec.c b/c/src/lib/libbsp/sparc/xm-leon3/startup/setvec.c
new file mode 100644
index 0000000000..c370bc9078
--- /dev/null
+++ b/c/src/lib/libbsp/sparc/xm-leon3/startup/setvec.c
@@ -0,0 +1,61 @@
+/**
+ * @file
+ * @ingroup sparc_xtratum
+ * @brief Install an interrupt vector on SPARC
+ */
+
+/* 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>
+#include <xm.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;
+
+ 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 ( XTRATUM_TRAP_IS_INTERRUPT( real_trap ) ) {
+ bsp_clear_interrupt( real_trap );
+ bsp_unmask_interrupt( real_trap );
+ }
+
+ return previous_isr;
+}
diff --git a/c/src/lib/libbsp/sparc/xm-leon3/startup/spurious.c b/c/src/lib/libbsp/sparc/xm-leon3/startup/spurious.c
new file mode 100644
index 0000000000..336b9f93e8
--- /dev/null
+++ b/c/src/lib/libbsp/sparc/xm-leon3/startup/spurious.c
@@ -0,0 +1,35 @@
+/*
+ * 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.
+ *
+ * Modified for LEON3 BSP.
+ * COPYRIGHT (c) 2004.
+ * Gaisler Research.
+ *
+ * This terms of the RTEMS license apply to this file.
+ */
+
+#include <bsp.h>
+#include <rtems/bspIo.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 (0x%02x) at address 0x%08x\n", real_trap, isf->tpc);
+}
+
diff --git a/c/src/lib/libbsp/sparc/xm-leon3/startup/tbr.c b/c/src/lib/libbsp/sparc/xm-leon3/startup/tbr.c
new file mode 100644
index 0000000000..ad35272662
--- /dev/null
+++ b/c/src/lib/libbsp/sparc/xm-leon3/startup/tbr.c
@@ -0,0 +1,30 @@
+/*
+ * Copyright (c) 2014 embedded brains GmbH. All rights reserved.
+ *
+ * embedded brains GmbH
+ * Dornierstr. 4
+ * 82178 Puchheim
+ * Germany
+ * <info@embedded-brains.de>
+ *
+ * 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 <rtems/score/sparc.h>
+#include <xm.h>
+#include <fatal.h>
+
+uint32_t _SPARC_Get_TBR( void )
+{
+ partitionControlTable_t * pct = XM_get_PCT();
+ xmAddress_t tbr = pct->arch.tbr;
+ return tbr;
+}
+
+void _SPARC_Set_TBR( uint32_t new_tbr )
+{
+ /* TODO: implement */
+ bsp_fatal( XM_BSP_FATAL_SET_TBR_NOT_IMPLEMENTED );
+}
diff --git a/c/src/lib/libbsp/sparc/xm-leon3/xm/xmhdr.c b/c/src/lib/libbsp/sparc/xm-leon3/xm/xmhdr.c
new file mode 100644
index 0000000000..d20da6b290
--- /dev/null
+++ b/c/src/lib/libbsp/sparc/xm-leon3/xm/xmhdr.c
@@ -0,0 +1,36 @@
+/*
+ * xmhdr.c
+ *
+ * Partition header definition
+ *
+ * Created for RTEMS/XM3 by Javier Coronel (jacopa@ai2.upv.es)
+ * $Id: xmhdr.c, 2011/06/08
+ *
+ * Porting of RTEMS to XM3.
+ * It has been performed under IMA-SP project.
+ * COPYRIGHT (c) 2011
+ * UPV (Universidad Politécnica de Valencia)
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ */
+
+#include <xm.h>
+#include <xm_inc/arch/paging.h>
+#include <bsp.h>
+
+static xm_u8_t _pageTable[PAGE_SIZE*XTRATUM_SIZE_PAGE_TABLE] __attribute__((aligned(PAGE_SIZE))) __attribute__ ((section(".bsp_rwextra")));
+
+struct xmImageHdr xmImageHdr __XMIHDR = {
+ .sSignature=XMEF_PARTITION_MAGIC,
+ .compilationXmAbiVersion=XM_SET_VERSION(XM_ABI_VERSION, XM_ABI_SUBVERSION, XM_ABI_REVISION),
+ .compilationXmApiVersion=XM_SET_VERSION(XM_API_VERSION, XM_API_SUBVERSION, XM_API_REVISION),
+ .pageTable=(xmAddress_t)_pageTable,
+ .pageTableSize=XTRATUM_SIZE_PAGE_TABLE*PAGE_SIZE,
+ .noCustomFiles=0,
+ .eSignature=XMEF_PARTITION_MAGIC,
+};
+
+