Index: /branches/reconfiguration/modules/vci_cc_vcache_wrapper/caba/test/common.mk
===================================================================
--- /branches/reconfiguration/modules/vci_cc_vcache_wrapper/caba/test/common.mk	(revision 850)
+++ /branches/reconfiguration/modules/vci_cc_vcache_wrapper/caba/test/common.mk	(revision 850)
@@ -0,0 +1,67 @@
+LD         := mipsel-unknown-elf-ld
+CC         := mipsel-unknown-elf-gcc
+AS         := mipsel-unknown-elf-as
+DU         := mipsel-unknown-elf-objdump
+AR         := mipsel-unknown-elf-ar
+RM         := rm -rf
+ECHO       := @echo
+MKDIR      := mkdir
+HEXDUMP    := hexdump
+DOXYGEN    := doxygen
+SED        := sed
+
+CFLAGS     := -Wall                        \
+              -mno-gpopt                   \
+              -ffreestanding               \
+              -fomit-frame-pointer         \
+              -march=mips32                \
+              -Os                          \
+              -ggdb                        \
+#             -msoft-float                 \
+#             -Werror                      \
+#             -Wno-unused-but-set-variable \
+#             -std=gnu99                   \
+#             -mlong-calls                 \
+
+BUILD_DIR  := build
+
+UTILS_PATH := ../../../../../softs
+
+INCLUDE    := -I$(UTILS_PATH)/drivers/     \
+              -I$(UTILS_PATH)/libs/        \
+              -I$(UTILS_PATH)/mach/		   \
+			  -I.
+
+VPATH      := $(UTILS_PATH)/drivers/       \
+              $(UTILS_PATH)/libs/          \
+              $(UTILS_PATH)/mach/
+
+# ============================================================================
+# Debug compilation flags
+# ============================================================================
+
+DEBUG_DEFS ?=
+
+DEBUG ?= 0
+ifeq ($(DEBUG),0)
+    DEBUG_DEFS += -DNDEBUG # deactivate assertions
+endif
+
+# ============================================================================
+# Compilation flags
+# ============================================================================
+
+DEFS := $(DEBUG_DEFS)
+
+# =============================================================================
+# Implicit makefile rules
+# =============================================================================
+
+$(BUILD_DIR)/%.o: %.c
+	$(CC) $(DEFS) $(CFLAGS) $(INCLUDE) -c -o $@ $<
+	$(DU) -D $@ > $@.txt
+
+$(BUILD_DIR)/%.o: %.S
+	$(CC) $(DEFS) $(CFLAGS) $(INCLUDE) -c -o $@ $<
+	$(DU) -D $@ > $@.txt
+
Index: /branches/reconfiguration/modules/vci_cc_vcache_wrapper/caba/test/simple_wdt_test/Makefile
===================================================================
--- /branches/reconfiguration/modules/vci_cc_vcache_wrapper/caba/test/simple_wdt_test/Makefile	(revision 850)
+++ /branches/reconfiguration/modules/vci_cc_vcache_wrapper/caba/test/simple_wdt_test/Makefile	(revision 850)
@@ -0,0 +1,86 @@
+# =============================================================================
+# \file      Makefile
+# \author    Cesar Fuguet
+# \date      July 9, 2014
+# =============================================================================
+include ../common.mk
+
+# =============================================================================
+# Include files paths
+# =============================================================================
+
+CONFDIR ?= output
+CONF    := $(addprefix $(CONFDIR)/config/, hard_config.h)
+
+INCLUDE += -I$(CONFDIR)/config
+
+# =============================================================================
+# Utils library
+# =============================================================================
+
+LIB_SRCS   := stdio.c            \
+              string.c           \
+              tty.c              \
+              simhelper.c
+
+LIB_OBJS   := $(addprefix $(BUILD_DIR)/,\
+                  $(subst .c,.o, $(notdir $(LIB_SRCS))))
+
+LIB_TARGET := $(BUILD_DIR)/libutils.a
+
+# =============================================================================
+# Documentation generation
+# =============================================================================
+
+DOCCONF := doxygen.config
+DOCDIR  := doc
+
+# =============================================================================
+# Object files
+# =============================================================================
+
+S_SRCS := reset.S
+C_SRCS := main.c
+
+OBJS   := $(addprefix $(BUILD_DIR)/,\
+              $(subst .c,.o, $(notdir $(C_SRCS))) \
+              $(subst .S,.o, $(notdir $(S_SRCS))))
+
+TARGET := $(BUILD_DIR)/soft.elf
+
+# =============================================================================
+# Makefile rules
+# =============================================================================
+
+all: $(TARGET)
+
+# Specific dependencies
+# NOTE: normal prerequisites | order-only prerequisites
+# SEE: http://www.gnu.org/software/make/manual/make.html#Prerequisite-Types
+
+$(LIB_OBJS): $(CONF) | $(BUILD_DIR)
+$(OBJS): $(CONF) | $(BUILD_DIR)
+
+doc: $(DOCCONF)
+	doxygen $<
+
+$(LIB_TARGET): $(LIB_OBJS)
+	$(AR) rcs $@ $(LIB_OBJS)
+
+$(TARGET): $(OBJS) ../soft.ld $(LIB_TARGET)
+	$(LD) -o $@ -T ../soft.ld $(OBJS) -L$(BUILD_DIR) -lutils
+	$(DU) -D $@ > $@.txt
+
+$(BUILD_DIR):
+	$(MKDIR) $@
+
+clean:
+	$(RM) $(BUILD_DIR)
+
+clean-doc:
+	$(RM) $(DOCDIR)
+
+clean-log:
+	$(RM) $(CONFDIR)
+
+distclean: clean clean-doc clean-log
Index: /branches/reconfiguration/modules/vci_cc_vcache_wrapper/caba/test/simple_wdt_test/main.c
===================================================================
--- /branches/reconfiguration/modules/vci_cc_vcache_wrapper/caba/test/simple_wdt_test/main.c	(revision 850)
+++ /branches/reconfiguration/modules/vci_cc_vcache_wrapper/caba/test/simple_wdt_test/main.c	(revision 850)
@@ -0,0 +1,40 @@
+#include "stdio.h"
+#include "cpu.h"
+#include "hard_config.h"
+#include "io.h"
+#include "simhelper.h"
+#include "cpu_registers.h"
+
+void exception_handler()
+{
+    printf("exception_handler(): pid %d\n", cpu_procid());
+
+    int error = 0;
+    if (cpu_get_cr_exccode() != CR_DBE) {
+        printf("error: exccode should be DBE");
+        error = 1;
+    }
+    if (cpu_get_mmu_detr() != MMU_READ_DATA_TIMEOUT) {
+        printf("error: mmu data exception type should be WDT timeout");
+        error = 1;
+    }
+    if (error == 0) {
+        printf("success");
+    }
+    simh_stop_simulation();
+}
+
+void main(void)
+{
+    cpu_set_wdt_max(500);
+
+    /*
+     * Cause a WDT timeout exception
+     * Trying to read a memory location of another (non-existent) cluster
+     */
+    ioread32(0xFF00000000ULL);
+}
+
+/* 
+ * vim: tabstop=4 : softtabstop=4 : shiftwidth=4 : expandtab
+ */
Index: /branches/reconfiguration/modules/vci_cc_vcache_wrapper/caba/test/simple_wdt_test/reset.S
===================================================================
--- /branches/reconfiguration/modules/vci_cc_vcache_wrapper/caba/test/simple_wdt_test/reset.S	(revision 850)
+++ /branches/reconfiguration/modules/vci_cc_vcache_wrapper/caba/test/simple_wdt_test/reset.S	(revision 850)
@@ -0,0 +1,95 @@
+/**
+ * File   : reset.S
+ * Author : Cesar FUGUET <cesar.fuguet-tortolero@lip6.fr>
+ * Date   : 16 October 2014
+ */
+
+#include "hard_config.h"
+#include "cpu_registers.h"
+
+    .section .reset,"ax",@progbits
+
+    .extern seg_stack_base
+    .extern seg_kcode_base
+    .extern main
+
+    .globl  reset
+    .ent    reset
+    .align  2
+
+#define P_MASK ((1<<P_WIDTH)-1)
+#define Y_MASK ((1<<Y_WIDTH)-1)
+
+reset:
+    .set noreorder
+
+    /* 
+     * SR register initialization
+     * - Disable interrupts
+     * - Keep the Bootstrap Exception Vector (BEV) bit set
+     */
+    li     k0,  0x00400000
+    mtc0   k0,  CP0_STATUS
+
+    /* 
+     * All processors compute:
+     *   cid = (x * Y_SIZE) + y
+     *   pid = (cid * NB_PROCS_MAX) + lpid
+     */
+    mfc0   k0,  CP0_PROCID
+    andi   k0,  k0,  0xFFF             /* k0 <= proc_xyl                 */
+    andi   t1,  k0,  P_MASK            /* t1 <= lpid                     */
+    srl    t2,  k0,  P_WIDTH           /* t2 <= cluster_xy               */
+    srl    t3,  t2,  Y_WIDTH           /* t3 <= x coordinate             */
+    andi   t4,  t2,  Y_MASK            /* t4 <= y coordinate             */
+
+    li     t6,  Y_SIZE                 /* t6 <= Y_SIZE                   */
+    multu  t3,  t6
+    mflo   t5
+    addu   k0,  t5,  t4                /* k0 <= cid                      */
+
+    li     t7,  NB_PROCS_MAX
+    multu  t5,  t7
+    mflo   t0
+    addu   k1,  t0,  t1                /* k1 <= pid                      */
+
+    /* each proc initializes stack pointer (16K per processor) */
+    addi   t0,  k1,  1                 /* t0 <= (pid + 1)                */
+    sll    t0,  t0,  14                /* t0 <= (pid + 1) * 16K          */
+    la     sp,  _stack
+    addu   sp,  sp,  t0                /* sp <= _stack[pid]              */
+
+    /* jumps to main in kernel mode */
+    jal    main
+    nop
+
+    j      exit
+    nop
+
+    .set reorder
+    .end reset
+
+
+
+.org 0x380
+
+reset_exception_handler:
+    mtc2   $0,  MMU_DATA_PADDR_EXT 
+    j exception_handler
+
+
+
+    .section .data
+
+/*
+ * Stack segment definition
+ * It contains the stacks of all processors, thus, if each one is using a
+ * 16 Kbytes stack and the segment is 512 Kbytes length then the max number
+ * of processors supported is 32
+ */
+_stack:
+    .space (1<<19)                     /* 512 Kbytes                     */
+
+/*
+ * vim: tabstop=4 : softtabstop=4 : shiftwidth=4 : expandtab
+ */
Index: /branches/reconfiguration/modules/vci_cc_vcache_wrapper/caba/test/simple_wdt_test/run.sh
===================================================================
--- /branches/reconfiguration/modules/vci_cc_vcache_wrapper/caba/test/simple_wdt_test/run.sh	(revision 850)
+++ /branches/reconfiguration/modules/vci_cc_vcache_wrapper/caba/test/simple_wdt_test/run.sh	(revision 850)
@@ -0,0 +1,17 @@
+PLATFORM="../../../../../platforms/tsar_generic_iob/"
+OUTDIR=output
+
+make
+./$PLATFORM/scripts/onerun.py -o $OUTDIR -p $PLATFORM -x1 -y1 -n1 -c
+
+export SOCLIB_FB=HEADLESS
+export SOCLIB_TTY=FILES
+./$PLATFORM/simul.x -SOFT build/soft.elf -DISK /dev/null 2> /dev/null >> $OUTDIR/log
+soclib-cleanup-terms &>/dev/null
+mv term0 $OUTDIR/term
+grep -q "success" $OUTDIR/term
+if [ $? == 0 ]; then
+	echo "Success"
+else
+	echo "Failure"
+fi
Index: /branches/reconfiguration/modules/vci_cc_vcache_wrapper/caba/test/soft.ld
===================================================================
--- /branches/reconfiguration/modules/vci_cc_vcache_wrapper/caba/test/soft.ld	(revision 850)
+++ /branches/reconfiguration/modules/vci_cc_vcache_wrapper/caba/test/soft.ld	(revision 850)
@@ -0,0 +1,38 @@
+/**********************************************************
+  File   : ldscript
+  Author : Cesar Fuguet
+  Date   : June 2011
+**********************************************************/
+
+/* Definition of the base address for code segment */
+
+seg_code_base = 0xBFC00000;
+seg_data_base = 0x00001000;
+
+/* Grouping sections into segments */
+
+ENTRY(reset)
+
+SECTIONS
+{
+    . = seg_code_base;
+    .text :
+    {
+        *(.reset)
+        *(.text)
+        *(.text.*)
+        *(.rodata)
+        *(.rodata.*)
+    }
+
+    . = seg_data_base;
+    .bss ALIGN(0x4) (NOLOAD) :
+    {
+        *(.data)
+        *(.bss)
+    }
+}
+
+/*
+ * vim: tabstop=4 : softtabstop=4 : shiftwidth=4 : expandtab
+ */
Index: /branches/reconfiguration/softs/drivers/simhelper.c
===================================================================
--- /branches/reconfiguration/softs/drivers/simhelper.c	(revision 850)
+++ /branches/reconfiguration/softs/drivers/simhelper.c	(revision 850)
@@ -0,0 +1,21 @@
+/**
+ * \file   simhelper.c
+ * \date   26 August, 2014
+ * \author Cesar Fuguet <cesar.fuguet-tortolero@lip6.fr>
+ *
+ * \brief  simhelper driver
+ */
+#include <simhelper.h>
+#include <io.h>
+#include <hard_config.h>
+
+#define SIMHREG(x) (SEG_SIM_BASE + ((x)<<3))
+
+void simh_stop_simulation()
+{
+    iowrite32(SIMHREG(SIMH_EXCEPTION), 0);
+}
+
+/*
+ * vim: tabstop=4 : softtabstop=4 : shiftwidth=4 : expandtab
+ */
Index: /branches/reconfiguration/softs/drivers/simhelper.h
===================================================================
--- /branches/reconfiguration/softs/drivers/simhelper.h	(revision 850)
+++ /branches/reconfiguration/softs/drivers/simhelper.h	(revision 850)
@@ -0,0 +1,36 @@
+/**
+ * \file   simhelper.h
+ * \date   26 August, 2014
+ * \author Cesar Fuguet <cesar.fuguet-tortolero@lip6.fr>
+ *
+ * \brief  simhelper driver
+ */
+#ifndef SIMHELPER_H
+#define SIMHELPER_H
+
+/**
+ * \note the size of each register depends on the VCI cell size implemented by
+ * the simhelper (i.e. when this component is connected to the external IO
+ * network, this parameter is 8 bytes = 2x32 bits words).
+ */
+enum SoclibSimhelperRegisters {
+    SIMH_STOP = 0,      /**< Write only */
+    SIMH_EXIT = 1,      /**< Write only */
+    SIMH_EXCEPTION = 2, /**< Write only */
+    SIMH_PAUSE = 3,     /**< Write only */
+    SIMH_CYCLES = 4,    /**< Read  only */
+    SIMH_SIGINT = 5,    /**< Write only */
+
+    SIMH_CELLSIZE = 2,  /**< Number of 32 bits words by register */
+};
+
+/**
+ * \brief stop simulation by throwing a RunTimeError
+ */
+void simh_stop_simulation();
+
+#endif
+
+/*
+ * vim: tabstop=4 : softtabstop=4 : shiftwidth=4 : expandtab
+ */
Index: /branches/reconfiguration/softs/drivers/tty.c
===================================================================
--- /branches/reconfiguration/softs/drivers/tty.c	(revision 850)
+++ /branches/reconfiguration/softs/drivers/tty.c	(revision 850)
@@ -0,0 +1,23 @@
+#include <tty.h>
+#include <io.h>
+#include <hard_config.h>
+
+#define TTYREG(x) (SEG_TTY_BASE + ((x)<<2))
+
+int tty_getc(char *c)
+{
+    if (ioread32(TTYREG(TTY_STATUS)) == 0) {
+        return 1;
+    }
+    *c = ioread32(TTYREG(TTY_READ));
+    return 0;
+}
+
+void tty_putc(const char c)
+{
+    iowrite32(TTYREG(TTY_WRITE), (uint32_t)c);
+}
+
+/*
+ * vim: tabstop=4 : softtabstop=4 : shiftwidth=4 : expandtab
+ */
Index: /branches/reconfiguration/softs/drivers/tty.h
===================================================================
--- /branches/reconfiguration/softs/drivers/tty.h	(revision 850)
+++ /branches/reconfiguration/softs/drivers/tty.h	(revision 850)
@@ -0,0 +1,19 @@
+#ifndef TTY_H
+#define TTY_H
+
+enum SoclibTtyRegisters {
+    TTY_WRITE = 0,
+    TTY_STATUS = 1,
+    TTY_READ = 2,
+    TTY_CONFIG = 3,
+    TTY_SPAN = 4,
+};
+
+int tty_getc(char *c);
+void tty_putc(const char c);
+
+#endif
+
+/*
+ * vim: tabstop=4 : softtabstop=4 : shiftwidth=4 : expandtab
+ */
Index: /branches/reconfiguration/softs/libs/assert.h
===================================================================
--- /branches/reconfiguration/softs/libs/assert.h	(revision 850)
+++ /branches/reconfiguration/softs/libs/assert.h	(revision 850)
@@ -0,0 +1,35 @@
+/**
+ * \file    assert.h
+ * \author  Cesar FUGUET
+ * \date    July 30, 2014
+ * \brief   assert macro definition
+ */
+#ifndef ASSERT_H
+#define ASSERT_H
+
+#include <stdio.h>
+
+/**
+ * \param cond A boolean condition
+ *
+ * \brief assert condition
+ * \note  the assert macro may be removed at compile time with the
+ *        -DNDEBUG option
+ */
+#ifndef NDEBUG
+#define assert(expression) {\
+        if (!(expression)) {                                          \
+            printf("assertion \"%s\" failed: file \"%s\", line %d\n", \
+                #expression, __FILE__, __LINE__);                     \
+            exit();                                                   \
+        }                                                             \
+    }
+#else
+#define assert(expression)
+#endif
+
+#endif
+
+/*
+ * vim: tabstop=4 : softtabstop=4 : shiftwidth=4 : expandtab
+ */
Index: /branches/reconfiguration/softs/libs/io.h
===================================================================
--- /branches/reconfiguration/softs/libs/io.h	(revision 850)
+++ /branches/reconfiguration/softs/libs/io.h	(revision 850)
@@ -0,0 +1,57 @@
+/**
+ * \file    io.h
+ * \date    5 September 2012
+ * \author  Cesar Fuguet
+ *
+ * Utility functions to write or read memory mapped hardware registers
+ */
+#ifndef IO_H
+#define IO_H
+
+#include <cpu.h>
+
+/**
+ * \brief Read an 32 bits memory mapped hardware register
+ * 
+ * \note interrupts should be disabled while executing this function
+ */
+static inline unsigned int ioread32(uint64_t paddr)
+{
+    uint32_t value;
+    uint32_t msb = paddr >> CLUSTER_OFFSET_BITS;
+    uint32_t lsb = paddr & ((1ULL << CLUSTER_OFFSET_BITS)-1);
+
+    asm volatile("mtc2   %2,     $24   \n"  /* DATA_PADDR_EXT <= msb */
+                 "lw     %0,     0(%1) \n"  /* value <= *paddr       */
+                 "mtc2   $0,     $24   \n"  /* DATA_PADDR_EXT <= 0   */
+                 : "=r"(value)
+                 : "r"(lsb), "r"(msb)
+                 : "memory");
+
+    return value;
+}
+
+/**
+ * \brief Write an 32 bits memory mapped hardware register
+ *
+ * \note interrupts should be disabled while executing this function
+ */
+static inline void iowrite32(uint64_t paddr, uint32_t value)
+{
+    uint32_t msb = paddr >> CLUSTER_OFFSET_BITS;
+    uint32_t lsb = paddr & ((1ULL << CLUSTER_OFFSET_BITS)-1);
+
+    asm volatile("mtc2   %2,     $24   \n"  /* DATA_PADDR_EXT <= msb */
+                 "sw     %0,     0(%1) \n"  /* value <= *paddr       */
+                 "mtc2   $0,     $24   \n"  /* DATA_PADDR_EXT <= 0   */
+                 "sync                 \n"
+                 : /* no outputs */
+                 : "r"(value), "r"(lsb), "r"(msb)
+                 : "memory");
+}
+
+#endif
+
+/*
+ * vim: tabstop=4 : softtabstop=4 : shiftwidth=4 : expandtab
+ */
Index: /branches/reconfiguration/softs/libs/stdio.c
===================================================================
--- /branches/reconfiguration/softs/libs/stdio.c	(revision 850)
+++ /branches/reconfiguration/softs/libs/stdio.c	(revision 850)
@@ -0,0 +1,167 @@
+/**
+ * \file    stdio.c
+ * \date    July 8, 2014
+ * \author  Cesar Fuguet
+ *
+ * \brief   input/output functions
+ */
+#include <stdio.h>
+#include <stdint.h>
+#include <tty.h>
+#include <cpu.h>
+
+static const char HexaTab[] = "0123456789ABCDEF";
+
+void puts(const char *buffer)
+{
+    sputs(buffer, 256);
+}
+
+int getc(char *c)
+{
+    return tty_getc(c);
+}
+
+void putc(const char c)
+{
+    if (c == '\n') {
+        tty_putc('\r');
+    }
+    tty_putc(c);
+}
+
+void sputs(const char *buffer, unsigned int length)
+{
+    unsigned int n;
+    for (n = 0; n < length; n++) {
+        if (buffer[n] == 0) {
+            break;
+        }
+        putc(buffer[n]);
+    }
+}
+
+void putx(unsigned int val)
+{
+    char buf[9];
+    unsigned int c;
+
+    buf[8] = 0;
+    for (c = 0; c < 8; c++) {
+        buf[7 - c] = HexaTab[val & 0xF];
+        val >>= 4;
+    }
+    puts(buf);
+}
+
+void putd(unsigned int val)
+{
+    char buf[11];
+    unsigned int i;
+    unsigned int first = 0;
+
+    buf[10] = 0;
+    for (i = 0; i < 10; i++) {
+        if ((val == 0) && (i != 0)) {
+            break;
+        }
+        buf[9 - i] = HexaTab[val % 10];
+        first = 9 - i;
+        val /= 10;
+    }
+    puts(&buf[first]);
+}
+
+void printf(const char *format, ...)
+{
+    va_list ap;
+    va_start(ap, format);
+
+    while (1) {
+        while (*format) {
+            unsigned int i;
+            for (i = 0; format[i] && (format[i] != '%'); i++) ;
+            if (i) {
+                sputs(format, i);
+                format += i;
+            }
+            if (*format == '%') {
+                format++;
+                goto printf_arguments;
+            }
+        }
+        va_end(ap);
+        return;
+
+      printf_arguments:
+        switch (*format++) {
+        case 'c':              /* char conversion */
+            {
+                char arg = (char)va_arg(ap, int);
+                putc(arg);
+                break;
+            }
+
+        case 'd':              /* 32 bits decimal signed  */
+            {
+                int arg = va_arg(ap, int);
+                if (arg < 0) {
+                    putc('-');
+                    arg = -arg;
+                }
+                putd(arg);
+                break;
+            }
+
+        case 'u':              /* 32 bits decimal unsigned  */
+            {
+                unsigned int arg = va_arg(ap, unsigned int);
+                putd(arg);
+                break;
+            }
+
+        case 'x':              /* 32 bits hexadecimal unsigned */
+            {
+                unsigned int arg = va_arg(ap, unsigned int);
+                puts("0x");
+                putx(arg);
+                break;
+            }
+
+        case 'l':              /* 64 bits hexadecimal unsigned */
+            {
+                uint64_t val = va_arg(ap, uint64_t);
+                puts("0x");
+                putx(val >> 32);
+                putx(val & ((1ULL << 32) - 1));
+                break;
+            }
+
+        case 's':              /* string */
+            {
+                char *arg = va_arg(ap, char *);
+                puts(arg);
+                break;
+            }
+
+        default:
+            goto return_error;
+        }                       /* end switch (format) */
+    }                           /* end while(1) */
+
+  return_error:
+    puts("\n\n[ERROR] in printf()\n");
+    exit();
+}                               /* end printf */
+
+/**
+ * exit function
+ */
+void exit()
+{
+    cpu_wait();
+}
+
+/*
+ * vim: tabstop=4 : softtabstop=4 : shiftwidth=4 : expandtab
+ */
Index: /branches/reconfiguration/softs/libs/stdio.h
===================================================================
--- /branches/reconfiguration/softs/libs/stdio.h	(revision 850)
+++ /branches/reconfiguration/softs/libs/stdio.h	(revision 850)
@@ -0,0 +1,40 @@
+/**
+ * \file    stdio.h
+ * \date    July 8, 2014
+ * \author  Cesar Fuguet
+ *
+ * \brief   input/output functions
+ */
+#ifndef _STDIO_H
+#define _STDIO_H
+#include <stdarg.h>
+
+int getc(char *c);
+void puts(const char *buffer);
+void putc(const char c);
+void sputs(const char *buffer, unsigned int length);
+void putx(unsigned int val);
+void putd(unsigned int val);
+
+/**
+ * Display a format on TTY0.
+ * To provide an atomic display, this function takes the lock protecting
+ * exclusive access to TTY0, entering a critical section until the lock
+ * is released.
+ * Only a limited number of formats are supported:
+ *   - %d : 32 bits signed   decimal
+ *   - %u : 32 bits unsigned decimal
+ *   - %x : 32 bits unsigned hexa
+ *   - %l : 64 bits unsigned hexa
+ *   - %c : char
+ *   - %s : string
+ */
+void printf(const char *format, ...);
+
+void exit();
+
+#endif                          /* _STDIO_H */
+
+/*
+ * vim: tabstop=4 : softtabstop=4 : shiftwidth=4 : expandtab
+ */
Index: /branches/reconfiguration/softs/libs/string.c
===================================================================
--- /branches/reconfiguration/softs/libs/string.c	(revision 850)
+++ /branches/reconfiguration/softs/libs/string.c	(revision 850)
@@ -0,0 +1,54 @@
+/**
+ * \file    string.c
+ * \date    July 8, 2014
+ * \author  Cesar Fuguet
+ *
+ * \brief   string utility functions
+ */
+#include <string.h>
+
+void *memset(void *_dst, int c, size_t len)
+{
+    const char val = (char)c;
+
+    /*
+     * Write 12 bytes when destination buffer is aligned to 4 bytes and length
+     * is greater or equal to 12
+     */
+    int *dst = _dst;
+    if (!((int)dst & 0x3)) {
+        const int word = (val << 24) | (val << 16) | (val << 8) | val;
+        while (len > 11) {
+            dst[0] = word;
+            dst[1] = word;
+            dst[2] = word;
+            len -= 12;
+            dst += 3;
+        }
+    }
+
+    /*
+     * Write 1 byte when destination buffer is not aligned to 4 bytes or length
+     * is smaller than 4
+     */
+    char *cdst = (char *)dst;
+    while (len--) {
+        *cdst++ = val;
+    }
+
+    return _dst;
+}
+
+void *memcpy(void *_dst, const void *_src, size_t n)
+{
+    uint8_t *cdst = (uint8_t *)_dst;
+    uint8_t *csrc = (uint8_t *)_src;
+    while (n--) {
+        *cdst++ = *csrc++;
+    }
+    return _dst;
+};
+
+/*
+ * vim: tabstop=4 : softtabstop=4 : shiftwidth=4 : expandtab
+ */
Index: /branches/reconfiguration/softs/libs/string.h
===================================================================
--- /branches/reconfiguration/softs/libs/string.h	(revision 850)
+++ /branches/reconfiguration/softs/libs/string.h	(revision 850)
@@ -0,0 +1,28 @@
+/**
+ * \file    string.h
+ * \date    July 8, 2014
+ * \author  Cesar Fuguet
+ *
+ * \brief   string utility functions
+ */
+#ifndef STRING_H
+#define STRING_H
+
+#include <stdint.h>
+#include <stddef.h>
+
+/**
+ * Set memory region
+ */
+void *memset(void *_dst, int c, size_t len);
+
+/**
+ * Copy memory region
+ */
+void *memcpy(void *_dst, const void *_src, size_t n);
+
+#endif
+
+/*
+ * vim: tabstop=4 : softtabstop=4 : shiftwidth=4 : expandtab
+ */
Index: /branches/reconfiguration/softs/mach/cpu.h
===================================================================
--- /branches/reconfiguration/softs/mach/cpu.h	(revision 850)
+++ /branches/reconfiguration/softs/mach/cpu.h	(revision 850)
@@ -0,0 +1,138 @@
+/**
+ * \file   cpu.h
+ * \date   March 10, 2014
+ * \author Cesar Fuguet
+ * \brief  MIPS32 processor core function definitions
+ */
+#ifndef _CPU_H
+#define _CPU_H
+
+#include <stdint.h>
+#include <hard_config.h>
+
+#define CLUSTER(x,y)        (((x) << Y_WIDTH) | (y))
+#define CLUSTER_ID_BITS     (X_WIDTH + Y_WIDTH)
+#define CLUSTER_OFFSET_BITS (40-CLUSTER_ID_BITS)
+
+/*
+ * Inline functions definition
+ */
+static inline unsigned int cpu_procid()
+{
+    register uint32_t ret asm("v0");
+    asm volatile ("mfc0     %[ret],     $15,1" : [ret] "=r"(ret));
+    return (ret & 0x3FF);
+}
+
+static inline unsigned int cpu_cluster()
+{
+    return (cpu_procid() / NB_PROCS_MAX);
+}
+
+static inline unsigned int cpu_x()
+{
+    return (cpu_cluster() >> Y_WIDTH);
+}
+
+static inline unsigned int cpu_y()
+{
+    return (cpu_cluster() & ((1 << X_WIDTH) - 1));
+}
+
+static inline unsigned int cpu_l()
+{
+    return (cpu_procid() % NB_PROCS_MAX);
+}
+
+static inline unsigned int cpu_time()
+{
+    register uint32_t ret asm("v0");
+    asm volatile ("mfc0     %[ret],     $9,0" : [ret] "=r"(ret));
+    return ret;
+};
+
+static inline unsigned int cpu_get_sp()
+{
+    register unsigned int ret asm("v0");
+    asm volatile ("move     %[ret],     $29" : [ret] "=r"(ret));
+    return ret;
+}
+
+static inline void cpu_set_sp(uint32_t sp)
+{
+    asm volatile ("move   $29,    %[addr]     \n"
+                  : /* no output */
+                  : [addr] "r"(sp)
+                  : "memory");
+}
+
+static inline void cpu_wait()
+{
+    asm volatile ("wait");
+}
+
+static inline void cpu_sync()
+{
+    asm volatile ("sync":::"memory");
+}
+
+static inline void cpu_sleep(uint32_t cycles)
+{
+    asm volatile (".set noreorder             \n"
+                  "1:                         \n"
+                  "bnez   %[c],   1b          \n"
+                  "addiu  %[c],   %[c],   -1  \n"
+                  ".set reorder               \n"
+                  :  /* no output */
+                  : [c] "r"(cycles));
+}
+
+static inline void cpu_set_ptpr(uint32_t ptpr)
+{
+    asm volatile ("mtc2   %[ptpr],    $0\n"
+                  :  /* no output */
+                  : [ptpr] "r"(ptpr)
+                  : "memory");
+}
+
+static inline uint32_t cpu_get_ptpr()
+{
+    register uint32_t ret asm("v0");
+    asm volatile ("mfc2     %[ret],     $0\n" : [ret] "=r"(ret));
+    return ret;
+}
+
+static inline uint32_t cpu_get_mmu_detr()
+{
+    register uint32_t ret asm("v0");
+    asm volatile ("mfc2     %[ret],     $12\n" : [ret] "=r"(ret));
+    return ret;
+}
+
+static inline uint32_t cpu_get_cr_exccode()
+{
+    register uint32_t ret asm("v0");
+    asm volatile ("mfc0     %[ret],     $13\n" : [ret] "=r"(ret));
+    return ((ret >> 2) & 0x1F);
+}
+
+static inline void cpu_set_wdt_max(uint32_t max)
+{
+    asm volatile ("mtc2     %[max],     $26\n"
+                  :
+                  : [max] "r"(max)
+                  : "memory");
+}
+
+static inline uint32_t cpu_get_wdt_max()
+{
+    register uint32_t ret asm("v0");
+    asm volatile ("mfc2     %[ret],     $12\n" : [ret] "=r"(ret));
+    return ret;
+}
+
+#endif                          /* _CPU_H */
+
+/*
+ * vim: tabstop=4 : softtabstop=4 : shiftwidth=4 : expandtab
+ */
Index: /branches/reconfiguration/softs/mach/cpu_registers.h
===================================================================
--- /branches/reconfiguration/softs/mach/cpu_registers.h	(revision 850)
+++ /branches/reconfiguration/softs/mach/cpu_registers.h	(revision 850)
@@ -0,0 +1,122 @@
+/**
+ * \file   cpu_registers.h
+ * \author Cesar Fuguet <cesar.fuguet-tortolero@lip6.fr>
+ * \date   26/03/2012
+ * \note   The mnemonics definitions for MIPS32 registers
+ */
+
+#ifndef _CPU_REGISTERS_H
+#define _CPU_REGISTERS_H
+
+/* processor registers */
+
+#define zero $0
+#define at   $at
+#define v0   $2
+#define v1   $3
+#define a0   $4
+#define a1   $5
+#define a2   $6
+#define a3   $7
+#define t0   $8
+#define t1   $9
+#define t2   $10
+#define t3   $11
+#define t4   $12
+#define t5   $13
+#define t6   $14
+#define t7   $15
+#define s0   $16
+#define s1   $17
+#define s2   $18
+#define s3   $19
+#define s4   $20
+#define s5   $21
+#define s6   $22
+#define s7   $23
+#define t8   $24
+#define t9   $25
+#define k0   $26
+#define k1   $27
+#define gp   $28
+#define sp   $29
+#define fp   $30
+#define ra   $31
+
+/* CP0 registers */
+
+#define CP0_COUNT  $9
+#define CP0_STATUS $12,0
+#define CP0_CAUSE  $13,0
+#define CP0_EPC    $14,0
+#define CP0_EBASE  $15,1
+#define CP0_PROCID $15,1
+
+/* CP0 cause register exception codes */
+
+#define CR_INT  0x0
+#define CR_ADEL 0x4
+#define CR_ADES 0x5
+#define CR_IBE  0x6
+#define CR_DBE  0x7
+#define CR_SYS  0x8
+#define CR_RI   0xA
+
+/* MMU (CP2) registers */
+
+#define MMU_PTPR            $0
+#define MMU_MODE            $1
+#define MMU_ICACHE_FLUSH    $2
+#define MMU_DCACHE_FLUSH    $3
+#define MMU_ITLB_INVAL      $4
+#define MMU_DTLB_INVAL      $5
+#define MMU_ICACHE_INVAL    $6
+#define MMU_DCACHE_INVAL    $7
+#define MMU_ICACHE_PREFETCH $8
+#define MMU_DCACHE_PREFETCH $9
+#define MMU_SYNC            $10
+#define MMU_IETR            $11
+#define MMU_DETR            $12
+#define MMU_IBVAR           $13
+#define MMU_DBVAR           $14
+#define MMU_PARAMS          $15
+#define MMU_RELEASE         $16
+#define MMU_DATA_LO         $17
+#define MMU_DATA_HI         $18
+#define MMU_ICACHE_INVAL_PA $19
+#define MMU_DCACHE_INVAL_PA $20
+#define MMU_DATA_PADDR_EXT  $24
+#define MMU_INST_PADDR_EXT  $25
+
+/* MMU IETR and DETR exception types */
+#define MMU_NONE                      0x0000
+#define MMU_WRITE_PT1_UNMAPPED        0x0001
+#define MMU_WRITE_PT2_UNMAPPED        0x0002
+#define MMU_WRITE_PRIVILEGE_VIOLATION 0x0004
+#define MMU_WRITE_ACCES_VIOLATION     0x0008
+#define MMU_WRITE_UNDEFINED_XTN       0x0020
+#define MMU_WRITE_PT1_ILLEGAL_ACCESS  0x0040
+#define MMU_WRITE_PT2_ILLEGAL_ACCESS  0x0080
+#define MMU_WRITE_DATA_ILLEGAL_ACCESS 0x0100
+#define MMU_READ_PT1_UNMAPPED         0x1001
+#define MMU_READ_PT2_UNMAPPED         0x1002
+#define MMU_READ_PRIVILEGE_VIOLATION  0x1004
+#define MMU_READ_EXEC_VIOLATION       0x1010
+#define MMU_READ_UNDEFINED_XTN        0x1020
+#define MMU_READ_PT1_ILLEGAL_ACCESS   0x1040
+#define MMU_READ_PT2_ILLEGAL_ACCESS   0x1080
+#define MMU_READ_DATA_ILLEGAL_ACCESS  0x1100
+#define MMU_READ_DATA_TIMEOUT         0x1200
+
+/* CP2 MODE bit masks */
+
+#define CP2_DCACHE_EN 0x1
+#define CP2_ICACHE_EN 0x2
+#define CP2_DTLB_EN   0x4
+#define CP2_ITLB_EN   0x8
+
+#endif                          /* _CPU_REGISTERS_H */
+
+/*
+ * vim: tabstop=4 : softtabstop=4 : shiftwidth=4 : expandtab
+ */
