From 7c2441cce736c879c91b07297cf260d4d42d5102 Mon Sep 17 00:00:00 2001
From: Matteo <mat.p@live.com>
Date: Tue, 15 Jan 2013 18:27:37 +0100
Subject: [PATCH] Updated mpu testsuite. Almost complete.

---
 Makefile                                  |   3 +-
 mpu_testsuite/mpu_apps/test1/main.c       |   2 +-
 mpu_testsuite/mpu_apps/test10.h           |  24 ++++
 mpu_testsuite/mpu_apps/test2/main.c       |   2 +-
 mpu_testsuite/mpu_apps/test3/main.c       |   2 +-
 mpu_testsuite/mpu_apps/test4/main.c       |   2 +-
 mpu_testsuite/mpu_apps/test5/main.c       |   4 +-
 mpu_testsuite/mpu_apps/test6/Makefile     |  51 ++++++++
 mpu_testsuite/mpu_apps/test6/crt0.s       | 130 ++++++++++++++++++
 mpu_testsuite/mpu_apps/test6/main.c       |  16 +++
 mpu_testsuite/mpu_apps/test6/miosix.ld    |  66 ++++++++++
 mpu_testsuite/mpu_apps/test7/Makefile     |  51 ++++++++
 mpu_testsuite/mpu_apps/test7/crt0.s       | 130 ++++++++++++++++++
 mpu_testsuite/mpu_apps/test7/includes.h   |   2 +
 mpu_testsuite/mpu_apps/test7/main.c       |  27 ++++
 mpu_testsuite/mpu_apps/test7/miosix.ld    |  66 ++++++++++
 mpu_testsuite/mpu_apps/test8_1/Makefile   |  50 +++++++
 mpu_testsuite/mpu_apps/test8_1/crt0.s     | 130 ++++++++++++++++++
 mpu_testsuite/mpu_apps/test8_1/includes.h |   2 +
 mpu_testsuite/mpu_apps/test8_1/main.c     |  15 +++
 mpu_testsuite/mpu_apps/test8_1/miosix.ld  |  66 ++++++++++
 mpu_testsuite/mpu_apps/test8_2/Makefile   |  50 +++++++
 mpu_testsuite/mpu_apps/test8_2/crt0.s     | 130 ++++++++++++++++++
 mpu_testsuite/mpu_apps/test8_2/main.c     |  16 +++
 mpu_testsuite/mpu_apps/test8_2/miosix.ld  |  66 ++++++++++
 mpu_testsuite/mpu_apps/test9/Makefile     |  50 +++++++
 mpu_testsuite/mpu_apps/test9/crt0.s       | 130 ++++++++++++++++++
 mpu_testsuite/mpu_apps/test9/main.c       |  14 ++
 mpu_testsuite/mpu_apps/test9/miosix.ld    |  66 ++++++++++
 mpu_testsuite/mpu_apps/test9_1.h          |  23 ++++
 mpu_testsuite/mpu_apps/test9_2.h          |  22 ++++
 mpu_testsuite/mpu_testsuite.cpp           | 152 +++++++++++++++++++++-
 32 files changed, 1546 insertions(+), 14 deletions(-)
 create mode 100644 mpu_testsuite/mpu_apps/test10.h
 create mode 100644 mpu_testsuite/mpu_apps/test6/Makefile
 create mode 100644 mpu_testsuite/mpu_apps/test6/crt0.s
 create mode 100644 mpu_testsuite/mpu_apps/test6/main.c
 create mode 100644 mpu_testsuite/mpu_apps/test6/miosix.ld
 create mode 100644 mpu_testsuite/mpu_apps/test7/Makefile
 create mode 100644 mpu_testsuite/mpu_apps/test7/crt0.s
 create mode 100644 mpu_testsuite/mpu_apps/test7/includes.h
 create mode 100644 mpu_testsuite/mpu_apps/test7/main.c
 create mode 100644 mpu_testsuite/mpu_apps/test7/miosix.ld
 create mode 100644 mpu_testsuite/mpu_apps/test8_1/Makefile
 create mode 100644 mpu_testsuite/mpu_apps/test8_1/crt0.s
 create mode 100644 mpu_testsuite/mpu_apps/test8_1/includes.h
 create mode 100644 mpu_testsuite/mpu_apps/test8_1/main.c
 create mode 100644 mpu_testsuite/mpu_apps/test8_1/miosix.ld
 create mode 100644 mpu_testsuite/mpu_apps/test8_2/Makefile
 create mode 100644 mpu_testsuite/mpu_apps/test8_2/crt0.s
 create mode 100644 mpu_testsuite/mpu_apps/test8_2/main.c
 create mode 100644 mpu_testsuite/mpu_apps/test8_2/miosix.ld
 create mode 100644 mpu_testsuite/mpu_apps/test9/Makefile
 create mode 100644 mpu_testsuite/mpu_apps/test9/crt0.s
 create mode 100644 mpu_testsuite/mpu_apps/test9/main.c
 create mode 100644 mpu_testsuite/mpu_apps/test9/miosix.ld
 create mode 100644 mpu_testsuite/mpu_apps/test9_1.h
 create mode 100644 mpu_testsuite/mpu_apps/test9_2.h

diff --git a/Makefile b/Makefile
index 9253f0b3..936a9817 100644
--- a/Makefile
+++ b/Makefile
@@ -14,8 +14,7 @@ SUBDIRS := miosix
 ## List here your source files (both .s, .c and .cpp)
 ##
 SRC :=                                  \
-miosix/testsuite/testsuite.cpp
-#main.cpp
+main.cpp
 
 
 ##
diff --git a/mpu_testsuite/mpu_apps/test1/main.c b/mpu_testsuite/mpu_apps/test1/main.c
index e4df7ce5..36d4f252 100644
--- a/mpu_testsuite/mpu_apps/test1/main.c
+++ b/mpu_testsuite/mpu_apps/test1/main.c
@@ -12,5 +12,5 @@ int main()
 	// and owned by the kernel. The program tries to write the location.
 	volatile unsigned int *address = 0x64100000;
 	*address = 0xbbbbbbbb;
-	return 123;
+	return 0;
 }
diff --git a/mpu_testsuite/mpu_apps/test10.h b/mpu_testsuite/mpu_apps/test10.h
new file mode 100644
index 00000000..d8acf4d5
--- /dev/null
+++ b/mpu_testsuite/mpu_apps/test10.h
@@ -0,0 +1,24 @@
+const unsigned char __attribute__((aligned(8))) test10_elf[] = {
+  0x7f, 0x45, 0x4c, 0x46, 0x01, 0x01, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00,
+  0x00, 0x00, 0x00, 0x00, 0x02, 0x00, 0x28, 0x00, 0x01, 0x00, 0x00, 0x00,
+  0x99, 0x00, 0x00, 0x00, 0x34, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+  0x02, 0x00, 0x00, 0x05, 0x34, 0x00, 0x20, 0x00, 0x03, 0x00, 0x00, 0x00,
+  0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x98, 0x00, 0x00, 0x00,
+  0x98, 0x00, 0x00, 0x00, 0x98, 0x00, 0x00, 0x00, 0x26, 0x00, 0x00, 0x00,
+  0x26, 0x00, 0x00, 0x00, 0x05, 0x00, 0x00, 0x00, 0x08, 0x00, 0x00, 0x00,
+  0x01, 0x00, 0x00, 0x00, 0xc0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x10,
+  0x00, 0x00, 0x00, 0x10, 0x34, 0x00, 0x00, 0x00, 0x34, 0x00, 0x00, 0x00,
+  0x06, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00,
+  0xcc, 0x00, 0x00, 0x00, 0x0c, 0x00, 0x00, 0x10, 0x0c, 0x00, 0x00, 0x10,
+  0x28, 0x00, 0x00, 0x00, 0x28, 0x00, 0x00, 0x00, 0x06, 0x00, 0x00, 0x00,
+  0x04, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xf0, 0x02, 0xf8,
+  0x00, 0xf0, 0x0a, 0xf8, 0x49, 0xf2, 0x80, 0x60, 0x08, 0xb5, 0xc0, 0xf2,
+  0x98, 0x00, 0x00, 0xf0, 0x05, 0xf8, 0x00, 0x20, 0x08, 0xbd, 0x00, 0xbf,
+  0x02, 0x23, 0x00, 0xdf, 0x05, 0x23, 0x00, 0xdf, 0x70, 0x47, 0x00, 0x00,
+  0x0c, 0x00, 0x00, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+  0x15, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x10,
+  0x00, 0x40, 0x00, 0x00, 0x01, 0x00, 0x00, 0x10, 0x00, 0x08, 0x00, 0x00,
+  0x4d, 0x69, 0x6f, 0x73, 0x69, 0x78, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+  0x00, 0x00, 0x00, 0x00
+};
+unsigned int test10_elf_len = 244;
diff --git a/mpu_testsuite/mpu_apps/test2/main.c b/mpu_testsuite/mpu_apps/test2/main.c
index 61be3f43..d4bf9153 100644
--- a/mpu_testsuite/mpu_apps/test2/main.c
+++ b/mpu_testsuite/mpu_apps/test2/main.c
@@ -12,5 +12,5 @@ int main()
 	// and owned by the kernel. The program tries to read the location.
 	volatile unsigned int *address = 0x64100200;
 	volatile unsigned int c = *address;
-	return 124;
+	return 0;
 }
diff --git a/mpu_testsuite/mpu_apps/test3/main.c b/mpu_testsuite/mpu_apps/test3/main.c
index aca7d41a..93f2819c 100644
--- a/mpu_testsuite/mpu_apps/test3/main.c
+++ b/mpu_testsuite/mpu_apps/test3/main.c
@@ -12,5 +12,5 @@ int main()
 	// the kernel. The program tries to write the location.
 	volatile unsigned int *address = 0x63F0FFFF;
 	*address = 0xbbbbbbbb;
-	return 125;
+	return 0;
 }
diff --git a/mpu_testsuite/mpu_apps/test4/main.c b/mpu_testsuite/mpu_apps/test4/main.c
index 62d1feb0..81c73f92 100644
--- a/mpu_testsuite/mpu_apps/test4/main.c
+++ b/mpu_testsuite/mpu_apps/test4/main.c
@@ -12,5 +12,5 @@ int main()
 	// the available memory and writes to it;
 	volatile unsigned char array[16 * 1024 + 1];
 	array[0] = 0;
-	return 126;
+	return 0;
 }
diff --git a/mpu_testsuite/mpu_apps/test5/main.c b/mpu_testsuite/mpu_apps/test5/main.c
index cfe98339..3ab4d4fc 100644
--- a/mpu_testsuite/mpu_apps/test5/main.c
+++ b/mpu_testsuite/mpu_apps/test5/main.c
@@ -10,7 +10,7 @@ int main()
 {
 	// 'address' points to a memory location inside the code
 	// segment of the program. The program tries to write the location.
-	volatile unsigned int *address = 0x64100800;
+	volatile unsigned int *address = 0x64101000;
 	*address = 0xbbbbbbbb;
-	return 127;
+	return 0;
 }
diff --git a/mpu_testsuite/mpu_apps/test6/Makefile b/mpu_testsuite/mpu_apps/test6/Makefile
new file mode 100644
index 00000000..ac9e07ca
--- /dev/null
+++ b/mpu_testsuite/mpu_apps/test6/Makefile
@@ -0,0 +1,51 @@
+##
+## Makefile for writing PROGRAMS for the Miosix embedded OS
+## TFT:Terraneo Federico Technlogies
+##
+
+SRC := \
+main.c
+
+## Replaces both "foo.cpp"-->"foo.o" and "foo.c"-->"foo.o"
+OBJ := $(addsuffix .o, $(basename $(SRC)))
+
+AS  := arm-miosix-eabi-as
+CC  := arm-miosix-eabi-gcc
+CXX := arm-miosix-eabi-g++
+SZ  := arm-miosix-eabi-size
+
+AFLAGS   := -mcpu=cortex-m3 -mthumb
+CFLAGS   := -mcpu=cortex-m3 -mthumb -mfix-cortex-m3-ldrd -fpie -msingle-pic-base \
+            -ffunction-sections -O2 -Wall -c
+CXXFLAGS := $(CFLAGS)
+LFLAGS   := -mcpu=cortex-m3 -mthumb -mfix-cortex-m3-ldrd -fpie -msingle-pic-base \
+            -Wl,--gc-sections,-Map,test.map,-T./miosix.ld,-n,-pie,--spare-dynamic-tags,3 \
+            -O2 -nostdlib
+DFLAGS    := -MMD -MP
+
+LINK_LIBS := -Wl,--start-group -lstdc++ -lc -lm -lgcc -Wl,--end-group
+
+all: $(OBJ) crt0.o
+	$(CXX) $(LFLAGS) -o test.elf $(OBJ) crt0.o $(LINK_LIBS)
+	$(SZ)  test.elf
+	@arm-miosix-eabi-objdump -Dslx test.elf > test.txt
+	@mx-postlinker test.elf --ramsize=16384 --stacksize=2048 --strip-sectheader
+	@xxd -i test.elf | sed 's/unsigned char/const unsigned char __attribute__((aligned(8)))/' > mpuTest.h
+
+clean:
+	-rm $(OBJ) crt0.o test.elf test.map test.txt mpuTest.h $(OBJ:.o=.d)
+
+%.o: %.s
+	@echo "========Compiling $<========"
+	$(AS) $(AFLAGS) $< -o $@
+
+%.o : %.c
+	@echo "========Compiling $<========"
+	$(CC) $(DFLAGS) $(CFLAGS) $< -o $@
+
+%.o : %.cpp
+	@echo "========Compiling $<========"
+	$(CXX) $(DFLAGS) $(CXXFLAGS) $< -o $@	
+
+#pull in dependecy info for existing .o files
+-include $(OBJ:.o=.d)
diff --git a/mpu_testsuite/mpu_apps/test6/crt0.s b/mpu_testsuite/mpu_apps/test6/crt0.s
new file mode 100644
index 00000000..7733008e
--- /dev/null
+++ b/mpu_testsuite/mpu_apps/test6/crt0.s
@@ -0,0 +1,130 @@
+/*
+ * Startup script for writing PROGRAMS for the Miosix embedded OS
+ * TFT:Terraneo Federico Technlogies
+ */
+
+.syntax unified
+.cpu cortex-m3
+.thumb
+
+.section .text
+
+/**
+ * _start, program entry point
+ */
+.global _start
+.type _start, %function
+_start:
+	/* TODO: .ctor */
+	bl   main
+	/* TODO: .dtor */
+	bl   _exit
+
+/**
+ * _exit, terminate process
+ * \param v exit value 
+ */
+.section .text._exit
+.global _exit
+.type _exit, %function
+_exit:
+	movs r3, #2
+	svc  0
+
+/**
+ * open, open a file
+ * \param fd file descriptor
+ * \param file access mode
+ * \param xxx access permisions
+ * \return file descriptor or -1 if errors
+ */
+.section .text.open
+.global open
+.type open, %function
+open:
+	movs r3, #6
+	svc 0
+	bx lr
+
+/**
+ * close, close a file
+ * \param fd file descriptor
+ */
+.section .text.close
+.global close
+.type close, %function
+close:
+	movs r3, #7
+	svc 0
+	bx lr
+
+/**
+ * lseek
+ * \param fd file descriptor
+ * \param pos moving offset
+ * \param start position, SEEK_SET, SEEK_CUR or SEEK_END
+ 
+.section .text.lseek
+.global lseek
+.type lseek, %function
+	
+	movs r3, #8
+	svc 0
+	bx lr
+*/
+
+/**
+ * system, fork and execture a program, blocking
+ * \param program to execute
+ */
+.section .text.system
+.global system
+.type system, %function
+system:
+	movs r3, #9
+	svc 0
+	bx lr
+/**
+ * write, write to file
+ * \param fd file descriptor
+ * \param buf data to be written
+ * \param len buffer length
+ * \return number of written bytes or -1 if errors
+ */
+.section .text.write
+.global	write
+.type	write, %function
+write:
+    movs r3, #3
+    svc  0
+    bx   lr
+
+/**
+ * read, read from file
+ * \param fd file descriptor
+ * \param buf data to be read
+ * \param len buffer length
+ * \return number of read bytes or -1 if errors
+ */
+.section .text.read
+.global	read
+.type	read, %function
+read:
+    movs r3, #4
+    svc  0
+    bx   lr
+
+/**
+ * usleep, sleep a specified number of microseconds
+ * \param us number of microseconds to sleep
+ * \return 0 on success or -1 if errors
+ */
+.section .text.usleep
+.global	usleep
+.type	usleep, %function
+usleep:
+    movs r3, #5
+    svc  0
+    bx   lr
+
+.end
diff --git a/mpu_testsuite/mpu_apps/test6/main.c b/mpu_testsuite/mpu_apps/test6/main.c
new file mode 100644
index 00000000..ed0796b8
--- /dev/null
+++ b/mpu_testsuite/mpu_apps/test6/main.c
@@ -0,0 +1,16 @@
+#include <unistd.h>
+
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <fcntl.h>
+#include <string.h>
+#include <stdio.h>
+
+int main()
+{
+	// 'address' points to a memory location between the
+	// code segment and the data segment.
+	volatile unsigned int *address = 0x64101404;
+	*address = 0xbbbbbbbb;
+	return 0;
+}
diff --git a/mpu_testsuite/mpu_apps/test6/miosix.ld b/mpu_testsuite/mpu_apps/test6/miosix.ld
new file mode 100644
index 00000000..c91c803e
--- /dev/null
+++ b/mpu_testsuite/mpu_apps/test6/miosix.ld
@@ -0,0 +1,66 @@
+/*
+ * Linker script for writing PROGRAMS for the Miosix embedded OS
+ * TFT:Terraneo Federico Technlogies
+ */
+
+OUTPUT_FORMAT("elf32-littlearm")
+OUTPUT_ARCH(arm)
+ENTRY(_start)
+
+SECTIONS
+{
+    /* Here starts the first elf segment, that stays in flash */
+    . = 0 + SIZEOF_HEADERS;
+
+    .text : ALIGN(8)
+    {
+        *(.text)
+        *(.text.*)
+        *(.gnu.linkonce.t.*)
+    }
+
+    .rel.data : { *(.rel.data .rel.data.* .rel.gnu.linkonce.d.*) }
+    .rel.got  : { *(.rel.got) }
+
+    /* Here starts the second segment, that is copied in RAM and relocated */
+    . = 0x10000000;
+
+    .got      : { *(.got.plt) *(.igot.plt) *(.got) *(.igot) }
+
+    /* FIXME: If this is put in the other segment, it makes it writable */
+    .dynamic  : { *(.dynamic) }
+
+    /* FIXME: The compiler insists in addressing rodata relative to r9 */
+    .rodata : ALIGN(8)
+    {
+        *(.rodata)
+        *(.rodata.*)
+        *(.gnu.linkonce.r.*)
+    }
+
+    .data : ALIGN(8)
+    {
+        *(.data)
+        *(.data.*)
+        *(.gnu.linkonce.d.*)
+    }
+
+    .bss : ALIGN(8)
+    {
+        *(.bss)
+        *(.bss.*)
+        *(.gnu.linkonce.b.*)
+        *(COMMON)
+    }
+
+    /* These are removed since are unused and increase binary size */
+    /DISCARD/ :
+    {
+        *(.interp)
+        *(.dynsym)
+        *(.dynstr)
+        *(.hash)
+        *(.comment)
+        *(.ARM.attributes)
+    }
+}
diff --git a/mpu_testsuite/mpu_apps/test7/Makefile b/mpu_testsuite/mpu_apps/test7/Makefile
new file mode 100644
index 00000000..ac9e07ca
--- /dev/null
+++ b/mpu_testsuite/mpu_apps/test7/Makefile
@@ -0,0 +1,51 @@
+##
+## Makefile for writing PROGRAMS for the Miosix embedded OS
+## TFT:Terraneo Federico Technlogies
+##
+
+SRC := \
+main.c
+
+## Replaces both "foo.cpp"-->"foo.o" and "foo.c"-->"foo.o"
+OBJ := $(addsuffix .o, $(basename $(SRC)))
+
+AS  := arm-miosix-eabi-as
+CC  := arm-miosix-eabi-gcc
+CXX := arm-miosix-eabi-g++
+SZ  := arm-miosix-eabi-size
+
+AFLAGS   := -mcpu=cortex-m3 -mthumb
+CFLAGS   := -mcpu=cortex-m3 -mthumb -mfix-cortex-m3-ldrd -fpie -msingle-pic-base \
+            -ffunction-sections -O2 -Wall -c
+CXXFLAGS := $(CFLAGS)
+LFLAGS   := -mcpu=cortex-m3 -mthumb -mfix-cortex-m3-ldrd -fpie -msingle-pic-base \
+            -Wl,--gc-sections,-Map,test.map,-T./miosix.ld,-n,-pie,--spare-dynamic-tags,3 \
+            -O2 -nostdlib
+DFLAGS    := -MMD -MP
+
+LINK_LIBS := -Wl,--start-group -lstdc++ -lc -lm -lgcc -Wl,--end-group
+
+all: $(OBJ) crt0.o
+	$(CXX) $(LFLAGS) -o test.elf $(OBJ) crt0.o $(LINK_LIBS)
+	$(SZ)  test.elf
+	@arm-miosix-eabi-objdump -Dslx test.elf > test.txt
+	@mx-postlinker test.elf --ramsize=16384 --stacksize=2048 --strip-sectheader
+	@xxd -i test.elf | sed 's/unsigned char/const unsigned char __attribute__((aligned(8)))/' > mpuTest.h
+
+clean:
+	-rm $(OBJ) crt0.o test.elf test.map test.txt mpuTest.h $(OBJ:.o=.d)
+
+%.o: %.s
+	@echo "========Compiling $<========"
+	$(AS) $(AFLAGS) $< -o $@
+
+%.o : %.c
+	@echo "========Compiling $<========"
+	$(CC) $(DFLAGS) $(CFLAGS) $< -o $@
+
+%.o : %.cpp
+	@echo "========Compiling $<========"
+	$(CXX) $(DFLAGS) $(CXXFLAGS) $< -o $@	
+
+#pull in dependecy info for existing .o files
+-include $(OBJ:.o=.d)
diff --git a/mpu_testsuite/mpu_apps/test7/crt0.s b/mpu_testsuite/mpu_apps/test7/crt0.s
new file mode 100644
index 00000000..7733008e
--- /dev/null
+++ b/mpu_testsuite/mpu_apps/test7/crt0.s
@@ -0,0 +1,130 @@
+/*
+ * Startup script for writing PROGRAMS for the Miosix embedded OS
+ * TFT:Terraneo Federico Technlogies
+ */
+
+.syntax unified
+.cpu cortex-m3
+.thumb
+
+.section .text
+
+/**
+ * _start, program entry point
+ */
+.global _start
+.type _start, %function
+_start:
+	/* TODO: .ctor */
+	bl   main
+	/* TODO: .dtor */
+	bl   _exit
+
+/**
+ * _exit, terminate process
+ * \param v exit value 
+ */
+.section .text._exit
+.global _exit
+.type _exit, %function
+_exit:
+	movs r3, #2
+	svc  0
+
+/**
+ * open, open a file
+ * \param fd file descriptor
+ * \param file access mode
+ * \param xxx access permisions
+ * \return file descriptor or -1 if errors
+ */
+.section .text.open
+.global open
+.type open, %function
+open:
+	movs r3, #6
+	svc 0
+	bx lr
+
+/**
+ * close, close a file
+ * \param fd file descriptor
+ */
+.section .text.close
+.global close
+.type close, %function
+close:
+	movs r3, #7
+	svc 0
+	bx lr
+
+/**
+ * lseek
+ * \param fd file descriptor
+ * \param pos moving offset
+ * \param start position, SEEK_SET, SEEK_CUR or SEEK_END
+ 
+.section .text.lseek
+.global lseek
+.type lseek, %function
+	
+	movs r3, #8
+	svc 0
+	bx lr
+*/
+
+/**
+ * system, fork and execture a program, blocking
+ * \param program to execute
+ */
+.section .text.system
+.global system
+.type system, %function
+system:
+	movs r3, #9
+	svc 0
+	bx lr
+/**
+ * write, write to file
+ * \param fd file descriptor
+ * \param buf data to be written
+ * \param len buffer length
+ * \return number of written bytes or -1 if errors
+ */
+.section .text.write
+.global	write
+.type	write, %function
+write:
+    movs r3, #3
+    svc  0
+    bx   lr
+
+/**
+ * read, read from file
+ * \param fd file descriptor
+ * \param buf data to be read
+ * \param len buffer length
+ * \return number of read bytes or -1 if errors
+ */
+.section .text.read
+.global	read
+.type	read, %function
+read:
+    movs r3, #4
+    svc  0
+    bx   lr
+
+/**
+ * usleep, sleep a specified number of microseconds
+ * \param us number of microseconds to sleep
+ * \return 0 on success or -1 if errors
+ */
+.section .text.usleep
+.global	usleep
+.type	usleep, %function
+usleep:
+    movs r3, #5
+    svc  0
+    bx   lr
+
+.end
diff --git a/mpu_testsuite/mpu_apps/test7/includes.h b/mpu_testsuite/mpu_apps/test7/includes.h
new file mode 100644
index 00000000..15f9f034
--- /dev/null
+++ b/mpu_testsuite/mpu_apps/test7/includes.h
@@ -0,0 +1,2 @@
+#include "mpu_testsuite/mpu_apps/test7.h"
+#endif //_APP_MPU_TESTS_1_
diff --git a/mpu_testsuite/mpu_apps/test7/main.c b/mpu_testsuite/mpu_apps/test7/main.c
new file mode 100644
index 00000000..3898ab02
--- /dev/null
+++ b/mpu_testsuite/mpu_apps/test7/main.c
@@ -0,0 +1,27 @@
+#include <unistd.h>
+
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <fcntl.h>
+#include <string.h>
+#include <stdio.h>
+
+int main()
+{
+	// The process tries to fill almost all the stack with an array
+	// and then tries to save the context by calling a syscall.
+	// 16376 = (16 * 1024) - 8
+
+//volatile unsigned char array[16345];
+	//volatile unsigned char array[100];
+	//array[0] = 0;
+	//itoa(array + 16200/*16012*/, array, 16);
+//write(1, "asd", 3);
+//array[0]=1;
+	//itoa(str+10, str, 16);
+	//write(1, str, 8);
+//write(1, "asd\n", 4);
+	//usleep(2000000);
+	
+	return 0;
+}
diff --git a/mpu_testsuite/mpu_apps/test7/miosix.ld b/mpu_testsuite/mpu_apps/test7/miosix.ld
new file mode 100644
index 00000000..c91c803e
--- /dev/null
+++ b/mpu_testsuite/mpu_apps/test7/miosix.ld
@@ -0,0 +1,66 @@
+/*
+ * Linker script for writing PROGRAMS for the Miosix embedded OS
+ * TFT:Terraneo Federico Technlogies
+ */
+
+OUTPUT_FORMAT("elf32-littlearm")
+OUTPUT_ARCH(arm)
+ENTRY(_start)
+
+SECTIONS
+{
+    /* Here starts the first elf segment, that stays in flash */
+    . = 0 + SIZEOF_HEADERS;
+
+    .text : ALIGN(8)
+    {
+        *(.text)
+        *(.text.*)
+        *(.gnu.linkonce.t.*)
+    }
+
+    .rel.data : { *(.rel.data .rel.data.* .rel.gnu.linkonce.d.*) }
+    .rel.got  : { *(.rel.got) }
+
+    /* Here starts the second segment, that is copied in RAM and relocated */
+    . = 0x10000000;
+
+    .got      : { *(.got.plt) *(.igot.plt) *(.got) *(.igot) }
+
+    /* FIXME: If this is put in the other segment, it makes it writable */
+    .dynamic  : { *(.dynamic) }
+
+    /* FIXME: The compiler insists in addressing rodata relative to r9 */
+    .rodata : ALIGN(8)
+    {
+        *(.rodata)
+        *(.rodata.*)
+        *(.gnu.linkonce.r.*)
+    }
+
+    .data : ALIGN(8)
+    {
+        *(.data)
+        *(.data.*)
+        *(.gnu.linkonce.d.*)
+    }
+
+    .bss : ALIGN(8)
+    {
+        *(.bss)
+        *(.bss.*)
+        *(.gnu.linkonce.b.*)
+        *(COMMON)
+    }
+
+    /* These are removed since are unused and increase binary size */
+    /DISCARD/ :
+    {
+        *(.interp)
+        *(.dynsym)
+        *(.dynstr)
+        *(.hash)
+        *(.comment)
+        *(.ARM.attributes)
+    }
+}
diff --git a/mpu_testsuite/mpu_apps/test8_1/Makefile b/mpu_testsuite/mpu_apps/test8_1/Makefile
new file mode 100644
index 00000000..994dae76
--- /dev/null
+++ b/mpu_testsuite/mpu_apps/test8_1/Makefile
@@ -0,0 +1,50 @@
+##
+## Makefile for writing PROGRAMS for the Miosix embedded OS
+## TFT:Terraneo Federico Technlogies
+##
+
+SRC := \
+main.c
+
+## Replaces both "foo.cpp"-->"foo.o" and "foo.c"-->"foo.o"
+OBJ := $(addsuffix .o, $(basename $(SRC)))
+
+AS  := arm-miosix-eabi-as
+CC  := arm-miosix-eabi-gcc
+CXX := arm-miosix-eabi-g++
+SZ  := arm-miosix-eabi-size
+
+AFLAGS   := -mcpu=cortex-m3 -mthumb
+CFLAGS   := -mcpu=cortex-m3 -mthumb -mfix-cortex-m3-ldrd -fpie -msingle-pic-base \
+            -ffunction-sections -O2 -Wall -c
+CXXFLAGS := $(CFLAGS)
+LFLAGS   := -mcpu=cortex-m3 -mthumb -mfix-cortex-m3-ldrd -fpie -msingle-pic-base \
+            -Wl,--gc-sections,-Map,test.map,-T./miosix.ld,-n,-pie,--spare-dynamic-tags,3 \
+            -O2 -nostdlib
+DFLAGS    := -MM
+
+LINK_LIBS := -Wl,--start-group -lstdc++ -lc -lm -lgcc -Wl,--end-group
+
+all: $(OBJ) crt0.o
+	$(CXX) $(LFLAGS) -o test.elf $(OBJ) crt0.o $(LINK_LIBS)
+	$(SZ)  test.elf
+	@arm-miosix-eabi-objdump -Dslx test.elf > test.txt
+	@mx-postlinker test.elf --ramsize=16384 --stacksize=2048 --strip-sectheader
+	@xxd -i test.elf | sed 's/unsigned char/const unsigned char __attribute__((aligned(8)))/' > mpuTest.h
+
+clean:
+	-rm $(OBJ) crt0.o test.elf test.map test.txt mpuTest.h *.d
+
+#pull in dependecy info for existing .o files
+-include $(OBJ:.o=.d)
+
+%.o: %.s
+	$(AS) $(AFLAGS) $< -o $@
+
+%.o : %.c
+	$(CC) $(CFLAGS) $< -o $@
+	$(CC) $(DFLAGS) $(CFLAGS) $*.c > $*.d
+
+%.o : %.cpp
+	$(CXX) $(CXXFLAGS) $< -o $@
+	$(CXX) $(DFLAGS) $(CXXFLAGS) $*.cpp > $*.d
diff --git a/mpu_testsuite/mpu_apps/test8_1/crt0.s b/mpu_testsuite/mpu_apps/test8_1/crt0.s
new file mode 100644
index 00000000..7733008e
--- /dev/null
+++ b/mpu_testsuite/mpu_apps/test8_1/crt0.s
@@ -0,0 +1,130 @@
+/*
+ * Startup script for writing PROGRAMS for the Miosix embedded OS
+ * TFT:Terraneo Federico Technlogies
+ */
+
+.syntax unified
+.cpu cortex-m3
+.thumb
+
+.section .text
+
+/**
+ * _start, program entry point
+ */
+.global _start
+.type _start, %function
+_start:
+	/* TODO: .ctor */
+	bl   main
+	/* TODO: .dtor */
+	bl   _exit
+
+/**
+ * _exit, terminate process
+ * \param v exit value 
+ */
+.section .text._exit
+.global _exit
+.type _exit, %function
+_exit:
+	movs r3, #2
+	svc  0
+
+/**
+ * open, open a file
+ * \param fd file descriptor
+ * \param file access mode
+ * \param xxx access permisions
+ * \return file descriptor or -1 if errors
+ */
+.section .text.open
+.global open
+.type open, %function
+open:
+	movs r3, #6
+	svc 0
+	bx lr
+
+/**
+ * close, close a file
+ * \param fd file descriptor
+ */
+.section .text.close
+.global close
+.type close, %function
+close:
+	movs r3, #7
+	svc 0
+	bx lr
+
+/**
+ * lseek
+ * \param fd file descriptor
+ * \param pos moving offset
+ * \param start position, SEEK_SET, SEEK_CUR or SEEK_END
+ 
+.section .text.lseek
+.global lseek
+.type lseek, %function
+	
+	movs r3, #8
+	svc 0
+	bx lr
+*/
+
+/**
+ * system, fork and execture a program, blocking
+ * \param program to execute
+ */
+.section .text.system
+.global system
+.type system, %function
+system:
+	movs r3, #9
+	svc 0
+	bx lr
+/**
+ * write, write to file
+ * \param fd file descriptor
+ * \param buf data to be written
+ * \param len buffer length
+ * \return number of written bytes or -1 if errors
+ */
+.section .text.write
+.global	write
+.type	write, %function
+write:
+    movs r3, #3
+    svc  0
+    bx   lr
+
+/**
+ * read, read from file
+ * \param fd file descriptor
+ * \param buf data to be read
+ * \param len buffer length
+ * \return number of read bytes or -1 if errors
+ */
+.section .text.read
+.global	read
+.type	read, %function
+read:
+    movs r3, #4
+    svc  0
+    bx   lr
+
+/**
+ * usleep, sleep a specified number of microseconds
+ * \param us number of microseconds to sleep
+ * \return 0 on success or -1 if errors
+ */
+.section .text.usleep
+.global	usleep
+.type	usleep, %function
+usleep:
+    movs r3, #5
+    svc  0
+    bx   lr
+
+.end
diff --git a/mpu_testsuite/mpu_apps/test8_1/includes.h b/mpu_testsuite/mpu_apps/test8_1/includes.h
new file mode 100644
index 00000000..d9e2fa61
--- /dev/null
+++ b/mpu_testsuite/mpu_apps/test8_1/includes.h
@@ -0,0 +1,2 @@
+#include "mpu_testsuite/mpu_apps/test8_1.h"
+#endif //_APP_MPU_TESTS_1_
diff --git a/mpu_testsuite/mpu_apps/test8_1/main.c b/mpu_testsuite/mpu_apps/test8_1/main.c
new file mode 100644
index 00000000..6ad36ce8
--- /dev/null
+++ b/mpu_testsuite/mpu_apps/test8_1/main.c
@@ -0,0 +1,15 @@
+#include <unistd.h>
+
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <fcntl.h>
+#include <string.h>
+#include <stdio.h>
+
+int main()
+{
+	// This process goes to sleep for 2 seconds, while the second
+	// process tries to access the data region of this process.
+	usleep(2000000);
+	return 0;
+}
diff --git a/mpu_testsuite/mpu_apps/test8_1/miosix.ld b/mpu_testsuite/mpu_apps/test8_1/miosix.ld
new file mode 100644
index 00000000..c91c803e
--- /dev/null
+++ b/mpu_testsuite/mpu_apps/test8_1/miosix.ld
@@ -0,0 +1,66 @@
+/*
+ * Linker script for writing PROGRAMS for the Miosix embedded OS
+ * TFT:Terraneo Federico Technlogies
+ */
+
+OUTPUT_FORMAT("elf32-littlearm")
+OUTPUT_ARCH(arm)
+ENTRY(_start)
+
+SECTIONS
+{
+    /* Here starts the first elf segment, that stays in flash */
+    . = 0 + SIZEOF_HEADERS;
+
+    .text : ALIGN(8)
+    {
+        *(.text)
+        *(.text.*)
+        *(.gnu.linkonce.t.*)
+    }
+
+    .rel.data : { *(.rel.data .rel.data.* .rel.gnu.linkonce.d.*) }
+    .rel.got  : { *(.rel.got) }
+
+    /* Here starts the second segment, that is copied in RAM and relocated */
+    . = 0x10000000;
+
+    .got      : { *(.got.plt) *(.igot.plt) *(.got) *(.igot) }
+
+    /* FIXME: If this is put in the other segment, it makes it writable */
+    .dynamic  : { *(.dynamic) }
+
+    /* FIXME: The compiler insists in addressing rodata relative to r9 */
+    .rodata : ALIGN(8)
+    {
+        *(.rodata)
+        *(.rodata.*)
+        *(.gnu.linkonce.r.*)
+    }
+
+    .data : ALIGN(8)
+    {
+        *(.data)
+        *(.data.*)
+        *(.gnu.linkonce.d.*)
+    }
+
+    .bss : ALIGN(8)
+    {
+        *(.bss)
+        *(.bss.*)
+        *(.gnu.linkonce.b.*)
+        *(COMMON)
+    }
+
+    /* These are removed since are unused and increase binary size */
+    /DISCARD/ :
+    {
+        *(.interp)
+        *(.dynsym)
+        *(.dynstr)
+        *(.hash)
+        *(.comment)
+        *(.ARM.attributes)
+    }
+}
diff --git a/mpu_testsuite/mpu_apps/test8_2/Makefile b/mpu_testsuite/mpu_apps/test8_2/Makefile
new file mode 100644
index 00000000..994dae76
--- /dev/null
+++ b/mpu_testsuite/mpu_apps/test8_2/Makefile
@@ -0,0 +1,50 @@
+##
+## Makefile for writing PROGRAMS for the Miosix embedded OS
+## TFT:Terraneo Federico Technlogies
+##
+
+SRC := \
+main.c
+
+## Replaces both "foo.cpp"-->"foo.o" and "foo.c"-->"foo.o"
+OBJ := $(addsuffix .o, $(basename $(SRC)))
+
+AS  := arm-miosix-eabi-as
+CC  := arm-miosix-eabi-gcc
+CXX := arm-miosix-eabi-g++
+SZ  := arm-miosix-eabi-size
+
+AFLAGS   := -mcpu=cortex-m3 -mthumb
+CFLAGS   := -mcpu=cortex-m3 -mthumb -mfix-cortex-m3-ldrd -fpie -msingle-pic-base \
+            -ffunction-sections -O2 -Wall -c
+CXXFLAGS := $(CFLAGS)
+LFLAGS   := -mcpu=cortex-m3 -mthumb -mfix-cortex-m3-ldrd -fpie -msingle-pic-base \
+            -Wl,--gc-sections,-Map,test.map,-T./miosix.ld,-n,-pie,--spare-dynamic-tags,3 \
+            -O2 -nostdlib
+DFLAGS    := -MM
+
+LINK_LIBS := -Wl,--start-group -lstdc++ -lc -lm -lgcc -Wl,--end-group
+
+all: $(OBJ) crt0.o
+	$(CXX) $(LFLAGS) -o test.elf $(OBJ) crt0.o $(LINK_LIBS)
+	$(SZ)  test.elf
+	@arm-miosix-eabi-objdump -Dslx test.elf > test.txt
+	@mx-postlinker test.elf --ramsize=16384 --stacksize=2048 --strip-sectheader
+	@xxd -i test.elf | sed 's/unsigned char/const unsigned char __attribute__((aligned(8)))/' > mpuTest.h
+
+clean:
+	-rm $(OBJ) crt0.o test.elf test.map test.txt mpuTest.h *.d
+
+#pull in dependecy info for existing .o files
+-include $(OBJ:.o=.d)
+
+%.o: %.s
+	$(AS) $(AFLAGS) $< -o $@
+
+%.o : %.c
+	$(CC) $(CFLAGS) $< -o $@
+	$(CC) $(DFLAGS) $(CFLAGS) $*.c > $*.d
+
+%.o : %.cpp
+	$(CXX) $(CXXFLAGS) $< -o $@
+	$(CXX) $(DFLAGS) $(CXXFLAGS) $*.cpp > $*.d
diff --git a/mpu_testsuite/mpu_apps/test8_2/crt0.s b/mpu_testsuite/mpu_apps/test8_2/crt0.s
new file mode 100644
index 00000000..7733008e
--- /dev/null
+++ b/mpu_testsuite/mpu_apps/test8_2/crt0.s
@@ -0,0 +1,130 @@
+/*
+ * Startup script for writing PROGRAMS for the Miosix embedded OS
+ * TFT:Terraneo Federico Technlogies
+ */
+
+.syntax unified
+.cpu cortex-m3
+.thumb
+
+.section .text
+
+/**
+ * _start, program entry point
+ */
+.global _start
+.type _start, %function
+_start:
+	/* TODO: .ctor */
+	bl   main
+	/* TODO: .dtor */
+	bl   _exit
+
+/**
+ * _exit, terminate process
+ * \param v exit value 
+ */
+.section .text._exit
+.global _exit
+.type _exit, %function
+_exit:
+	movs r3, #2
+	svc  0
+
+/**
+ * open, open a file
+ * \param fd file descriptor
+ * \param file access mode
+ * \param xxx access permisions
+ * \return file descriptor or -1 if errors
+ */
+.section .text.open
+.global open
+.type open, %function
+open:
+	movs r3, #6
+	svc 0
+	bx lr
+
+/**
+ * close, close a file
+ * \param fd file descriptor
+ */
+.section .text.close
+.global close
+.type close, %function
+close:
+	movs r3, #7
+	svc 0
+	bx lr
+
+/**
+ * lseek
+ * \param fd file descriptor
+ * \param pos moving offset
+ * \param start position, SEEK_SET, SEEK_CUR or SEEK_END
+ 
+.section .text.lseek
+.global lseek
+.type lseek, %function
+	
+	movs r3, #8
+	svc 0
+	bx lr
+*/
+
+/**
+ * system, fork and execture a program, blocking
+ * \param program to execute
+ */
+.section .text.system
+.global system
+.type system, %function
+system:
+	movs r3, #9
+	svc 0
+	bx lr
+/**
+ * write, write to file
+ * \param fd file descriptor
+ * \param buf data to be written
+ * \param len buffer length
+ * \return number of written bytes or -1 if errors
+ */
+.section .text.write
+.global	write
+.type	write, %function
+write:
+    movs r3, #3
+    svc  0
+    bx   lr
+
+/**
+ * read, read from file
+ * \param fd file descriptor
+ * \param buf data to be read
+ * \param len buffer length
+ * \return number of read bytes or -1 if errors
+ */
+.section .text.read
+.global	read
+.type	read, %function
+read:
+    movs r3, #4
+    svc  0
+    bx   lr
+
+/**
+ * usleep, sleep a specified number of microseconds
+ * \param us number of microseconds to sleep
+ * \return 0 on success or -1 if errors
+ */
+.section .text.usleep
+.global	usleep
+.type	usleep, %function
+usleep:
+    movs r3, #5
+    svc  0
+    bx   lr
+
+.end
diff --git a/mpu_testsuite/mpu_apps/test8_2/main.c b/mpu_testsuite/mpu_apps/test8_2/main.c
new file mode 100644
index 00000000..b45aa841
--- /dev/null
+++ b/mpu_testsuite/mpu_apps/test8_2/main.c
@@ -0,0 +1,16 @@
+#include <unistd.h>
+
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <fcntl.h>
+#include <string.h>
+#include <stdio.h>
+
+int main()
+{
+	// 'address' points to a memory location of the program 8.1.
+	// The program tries to write the location.
+	volatile int *address = 0x64104004;
+	*address = 0xbbbbbbbb;
+	return 0;
+}
diff --git a/mpu_testsuite/mpu_apps/test8_2/miosix.ld b/mpu_testsuite/mpu_apps/test8_2/miosix.ld
new file mode 100644
index 00000000..c91c803e
--- /dev/null
+++ b/mpu_testsuite/mpu_apps/test8_2/miosix.ld
@@ -0,0 +1,66 @@
+/*
+ * Linker script for writing PROGRAMS for the Miosix embedded OS
+ * TFT:Terraneo Federico Technlogies
+ */
+
+OUTPUT_FORMAT("elf32-littlearm")
+OUTPUT_ARCH(arm)
+ENTRY(_start)
+
+SECTIONS
+{
+    /* Here starts the first elf segment, that stays in flash */
+    . = 0 + SIZEOF_HEADERS;
+
+    .text : ALIGN(8)
+    {
+        *(.text)
+        *(.text.*)
+        *(.gnu.linkonce.t.*)
+    }
+
+    .rel.data : { *(.rel.data .rel.data.* .rel.gnu.linkonce.d.*) }
+    .rel.got  : { *(.rel.got) }
+
+    /* Here starts the second segment, that is copied in RAM and relocated */
+    . = 0x10000000;
+
+    .got      : { *(.got.plt) *(.igot.plt) *(.got) *(.igot) }
+
+    /* FIXME: If this is put in the other segment, it makes it writable */
+    .dynamic  : { *(.dynamic) }
+
+    /* FIXME: The compiler insists in addressing rodata relative to r9 */
+    .rodata : ALIGN(8)
+    {
+        *(.rodata)
+        *(.rodata.*)
+        *(.gnu.linkonce.r.*)
+    }
+
+    .data : ALIGN(8)
+    {
+        *(.data)
+        *(.data.*)
+        *(.gnu.linkonce.d.*)
+    }
+
+    .bss : ALIGN(8)
+    {
+        *(.bss)
+        *(.bss.*)
+        *(.gnu.linkonce.b.*)
+        *(COMMON)
+    }
+
+    /* These are removed since are unused and increase binary size */
+    /DISCARD/ :
+    {
+        *(.interp)
+        *(.dynsym)
+        *(.dynstr)
+        *(.hash)
+        *(.comment)
+        *(.ARM.attributes)
+    }
+}
diff --git a/mpu_testsuite/mpu_apps/test9/Makefile b/mpu_testsuite/mpu_apps/test9/Makefile
new file mode 100644
index 00000000..994dae76
--- /dev/null
+++ b/mpu_testsuite/mpu_apps/test9/Makefile
@@ -0,0 +1,50 @@
+##
+## Makefile for writing PROGRAMS for the Miosix embedded OS
+## TFT:Terraneo Federico Technlogies
+##
+
+SRC := \
+main.c
+
+## Replaces both "foo.cpp"-->"foo.o" and "foo.c"-->"foo.o"
+OBJ := $(addsuffix .o, $(basename $(SRC)))
+
+AS  := arm-miosix-eabi-as
+CC  := arm-miosix-eabi-gcc
+CXX := arm-miosix-eabi-g++
+SZ  := arm-miosix-eabi-size
+
+AFLAGS   := -mcpu=cortex-m3 -mthumb
+CFLAGS   := -mcpu=cortex-m3 -mthumb -mfix-cortex-m3-ldrd -fpie -msingle-pic-base \
+            -ffunction-sections -O2 -Wall -c
+CXXFLAGS := $(CFLAGS)
+LFLAGS   := -mcpu=cortex-m3 -mthumb -mfix-cortex-m3-ldrd -fpie -msingle-pic-base \
+            -Wl,--gc-sections,-Map,test.map,-T./miosix.ld,-n,-pie,--spare-dynamic-tags,3 \
+            -O2 -nostdlib
+DFLAGS    := -MM
+
+LINK_LIBS := -Wl,--start-group -lstdc++ -lc -lm -lgcc -Wl,--end-group
+
+all: $(OBJ) crt0.o
+	$(CXX) $(LFLAGS) -o test.elf $(OBJ) crt0.o $(LINK_LIBS)
+	$(SZ)  test.elf
+	@arm-miosix-eabi-objdump -Dslx test.elf > test.txt
+	@mx-postlinker test.elf --ramsize=16384 --stacksize=2048 --strip-sectheader
+	@xxd -i test.elf | sed 's/unsigned char/const unsigned char __attribute__((aligned(8)))/' > mpuTest.h
+
+clean:
+	-rm $(OBJ) crt0.o test.elf test.map test.txt mpuTest.h *.d
+
+#pull in dependecy info for existing .o files
+-include $(OBJ:.o=.d)
+
+%.o: %.s
+	$(AS) $(AFLAGS) $< -o $@
+
+%.o : %.c
+	$(CC) $(CFLAGS) $< -o $@
+	$(CC) $(DFLAGS) $(CFLAGS) $*.c > $*.d
+
+%.o : %.cpp
+	$(CXX) $(CXXFLAGS) $< -o $@
+	$(CXX) $(DFLAGS) $(CXXFLAGS) $*.cpp > $*.d
diff --git a/mpu_testsuite/mpu_apps/test9/crt0.s b/mpu_testsuite/mpu_apps/test9/crt0.s
new file mode 100644
index 00000000..7733008e
--- /dev/null
+++ b/mpu_testsuite/mpu_apps/test9/crt0.s
@@ -0,0 +1,130 @@
+/*
+ * Startup script for writing PROGRAMS for the Miosix embedded OS
+ * TFT:Terraneo Federico Technlogies
+ */
+
+.syntax unified
+.cpu cortex-m3
+.thumb
+
+.section .text
+
+/**
+ * _start, program entry point
+ */
+.global _start
+.type _start, %function
+_start:
+	/* TODO: .ctor */
+	bl   main
+	/* TODO: .dtor */
+	bl   _exit
+
+/**
+ * _exit, terminate process
+ * \param v exit value 
+ */
+.section .text._exit
+.global _exit
+.type _exit, %function
+_exit:
+	movs r3, #2
+	svc  0
+
+/**
+ * open, open a file
+ * \param fd file descriptor
+ * \param file access mode
+ * \param xxx access permisions
+ * \return file descriptor or -1 if errors
+ */
+.section .text.open
+.global open
+.type open, %function
+open:
+	movs r3, #6
+	svc 0
+	bx lr
+
+/**
+ * close, close a file
+ * \param fd file descriptor
+ */
+.section .text.close
+.global close
+.type close, %function
+close:
+	movs r3, #7
+	svc 0
+	bx lr
+
+/**
+ * lseek
+ * \param fd file descriptor
+ * \param pos moving offset
+ * \param start position, SEEK_SET, SEEK_CUR or SEEK_END
+ 
+.section .text.lseek
+.global lseek
+.type lseek, %function
+	
+	movs r3, #8
+	svc 0
+	bx lr
+*/
+
+/**
+ * system, fork and execture a program, blocking
+ * \param program to execute
+ */
+.section .text.system
+.global system
+.type system, %function
+system:
+	movs r3, #9
+	svc 0
+	bx lr
+/**
+ * write, write to file
+ * \param fd file descriptor
+ * \param buf data to be written
+ * \param len buffer length
+ * \return number of written bytes or -1 if errors
+ */
+.section .text.write
+.global	write
+.type	write, %function
+write:
+    movs r3, #3
+    svc  0
+    bx   lr
+
+/**
+ * read, read from file
+ * \param fd file descriptor
+ * \param buf data to be read
+ * \param len buffer length
+ * \return number of read bytes or -1 if errors
+ */
+.section .text.read
+.global	read
+.type	read, %function
+read:
+    movs r3, #4
+    svc  0
+    bx   lr
+
+/**
+ * usleep, sleep a specified number of microseconds
+ * \param us number of microseconds to sleep
+ * \return 0 on success or -1 if errors
+ */
+.section .text.usleep
+.global	usleep
+.type	usleep, %function
+usleep:
+    movs r3, #5
+    svc  0
+    bx   lr
+
+.end
diff --git a/mpu_testsuite/mpu_apps/test9/main.c b/mpu_testsuite/mpu_apps/test9/main.c
new file mode 100644
index 00000000..c062c0b7
--- /dev/null
+++ b/mpu_testsuite/mpu_apps/test9/main.c
@@ -0,0 +1,14 @@
+#include <unistd.h>
+
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <fcntl.h>
+#include <string.h>
+#include <stdio.h>
+
+int main()
+{
+	//This process sleeps for 5 seconds;
+	usleep(5000000);
+	return 0;
+}
diff --git a/mpu_testsuite/mpu_apps/test9/miosix.ld b/mpu_testsuite/mpu_apps/test9/miosix.ld
new file mode 100644
index 00000000..c91c803e
--- /dev/null
+++ b/mpu_testsuite/mpu_apps/test9/miosix.ld
@@ -0,0 +1,66 @@
+/*
+ * Linker script for writing PROGRAMS for the Miosix embedded OS
+ * TFT:Terraneo Federico Technlogies
+ */
+
+OUTPUT_FORMAT("elf32-littlearm")
+OUTPUT_ARCH(arm)
+ENTRY(_start)
+
+SECTIONS
+{
+    /* Here starts the first elf segment, that stays in flash */
+    . = 0 + SIZEOF_HEADERS;
+
+    .text : ALIGN(8)
+    {
+        *(.text)
+        *(.text.*)
+        *(.gnu.linkonce.t.*)
+    }
+
+    .rel.data : { *(.rel.data .rel.data.* .rel.gnu.linkonce.d.*) }
+    .rel.got  : { *(.rel.got) }
+
+    /* Here starts the second segment, that is copied in RAM and relocated */
+    . = 0x10000000;
+
+    .got      : { *(.got.plt) *(.igot.plt) *(.got) *(.igot) }
+
+    /* FIXME: If this is put in the other segment, it makes it writable */
+    .dynamic  : { *(.dynamic) }
+
+    /* FIXME: The compiler insists in addressing rodata relative to r9 */
+    .rodata : ALIGN(8)
+    {
+        *(.rodata)
+        *(.rodata.*)
+        *(.gnu.linkonce.r.*)
+    }
+
+    .data : ALIGN(8)
+    {
+        *(.data)
+        *(.data.*)
+        *(.gnu.linkonce.d.*)
+    }
+
+    .bss : ALIGN(8)
+    {
+        *(.bss)
+        *(.bss.*)
+        *(.gnu.linkonce.b.*)
+        *(COMMON)
+    }
+
+    /* These are removed since are unused and increase binary size */
+    /DISCARD/ :
+    {
+        *(.interp)
+        *(.dynsym)
+        *(.dynstr)
+        *(.hash)
+        *(.comment)
+        *(.ARM.attributes)
+    }
+}
diff --git a/mpu_testsuite/mpu_apps/test9_1.h b/mpu_testsuite/mpu_apps/test9_1.h
new file mode 100644
index 00000000..ecdc9548
--- /dev/null
+++ b/mpu_testsuite/mpu_apps/test9_1.h
@@ -0,0 +1,23 @@
+const unsigned char __attribute__((aligned(8))) test9_1_elf[] = {
+  0x7f, 0x45, 0x4c, 0x46, 0x01, 0x01, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00,
+  0x00, 0x00, 0x00, 0x00, 0x02, 0x00, 0x28, 0x00, 0x01, 0x00, 0x00, 0x00,
+  0x99, 0x00, 0x00, 0x00, 0x34, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+  0x02, 0x00, 0x00, 0x05, 0x34, 0x00, 0x20, 0x00, 0x03, 0x00, 0x00, 0x00,
+  0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x98, 0x00, 0x00, 0x00,
+  0x98, 0x00, 0x00, 0x00, 0x98, 0x00, 0x00, 0x00, 0x1c, 0x00, 0x00, 0x00,
+  0x1c, 0x00, 0x00, 0x00, 0x05, 0x00, 0x00, 0x00, 0x08, 0x00, 0x00, 0x00,
+  0x01, 0x00, 0x00, 0x00, 0xb4, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x10,
+  0x00, 0x00, 0x00, 0x10, 0x34, 0x00, 0x00, 0x00, 0x34, 0x00, 0x00, 0x00,
+  0x06, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00,
+  0xc0, 0x00, 0x00, 0x00, 0x0c, 0x00, 0x00, 0x10, 0x0c, 0x00, 0x00, 0x10,
+  0x28, 0x00, 0x00, 0x00, 0x28, 0x00, 0x00, 0x00, 0x06, 0x00, 0x00, 0x00,
+  0x04, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xf0, 0x02, 0xf8,
+  0x00, 0xf0, 0x08, 0xf8, 0x4f, 0xf4, 0x08, 0x43, 0xc6, 0xf2, 0x10, 0x43,
+  0x7b, 0x22, 0x1a, 0x60, 0x80, 0x20, 0x70, 0x47, 0x02, 0x23, 0x00, 0xdf,
+  0x0c, 0x00, 0x00, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+  0x15, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x10,
+  0x00, 0x40, 0x00, 0x00, 0x01, 0x00, 0x00, 0x10, 0x00, 0x08, 0x00, 0x00,
+  0x4d, 0x69, 0x6f, 0x73, 0x69, 0x78, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+  0x00, 0x00, 0x00, 0x00
+};
+unsigned int test9_1_elf_len = 232;
diff --git a/mpu_testsuite/mpu_apps/test9_2.h b/mpu_testsuite/mpu_apps/test9_2.h
new file mode 100644
index 00000000..e3cf07c1
--- /dev/null
+++ b/mpu_testsuite/mpu_apps/test9_2.h
@@ -0,0 +1,22 @@
+const unsigned char __attribute__((aligned(8))) test9_2_elf[] = {
+  0x7f, 0x45, 0x4c, 0x46, 0x01, 0x01, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00,
+  0x00, 0x00, 0x00, 0x00, 0x02, 0x00, 0x28, 0x00, 0x01, 0x00, 0x00, 0x00,
+  0x99, 0x00, 0x00, 0x00, 0x34, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+  0x02, 0x00, 0x00, 0x05, 0x34, 0x00, 0x20, 0x00, 0x03, 0x00, 0x00, 0x00,
+  0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x98, 0x00, 0x00, 0x00,
+  0x98, 0x00, 0x00, 0x00, 0x98, 0x00, 0x00, 0x00, 0x10, 0x00, 0x00, 0x00,
+  0x10, 0x00, 0x00, 0x00, 0x05, 0x00, 0x00, 0x00, 0x08, 0x00, 0x00, 0x00,
+  0x01, 0x00, 0x00, 0x00, 0xa8, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x10,
+  0x00, 0x00, 0x00, 0x10, 0x34, 0x00, 0x00, 0x00, 0x34, 0x00, 0x00, 0x00,
+  0x06, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00,
+  0xb4, 0x00, 0x00, 0x00, 0x0c, 0x00, 0x00, 0x10, 0x0c, 0x00, 0x00, 0x10,
+  0x28, 0x00, 0x00, 0x00, 0x28, 0x00, 0x00, 0x00, 0x06, 0x00, 0x00, 0x00,
+  0x04, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xf0, 0x02, 0xf8,
+  0x00, 0xf0, 0x02, 0xf8, 0x81, 0x20, 0x70, 0x47, 0x02, 0x23, 0x00, 0xdf,
+  0x0c, 0x00, 0x00, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+  0x15, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x10,
+  0x00, 0x40, 0x00, 0x00, 0x01, 0x00, 0x00, 0x10, 0x00, 0x08, 0x00, 0x00,
+  0x4d, 0x69, 0x6f, 0x73, 0x69, 0x78, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+  0x00, 0x00, 0x00, 0x00
+};
+unsigned int test9_2_elf_len = 220;
diff --git a/mpu_testsuite/mpu_testsuite.cpp b/mpu_testsuite/mpu_testsuite.cpp
index a9abe0d7..1a741dcb 100644
--- a/mpu_testsuite/mpu_testsuite.cpp
+++ b/mpu_testsuite/mpu_testsuite.cpp
@@ -15,6 +15,7 @@ using namespace std;
 using namespace miosix;
 
 unsigned int* memAllocation(unsigned int size);
+bool memCheck(unsigned int *base, unsigned int size);
 void runElfTest(const char *name, const unsigned char *filename, unsigned int file_length);
 
 int runProgram(const unsigned char *filename, unsigned int file_length);
@@ -24,10 +25,29 @@ void mpuTest2();
 void mpuTest3();
 void mpuTest4();
 void mpuTest5();
+void mpuTest6();
+void mpuTest7();
+void mpuTest8();
+void mpuTest9();
+
+unsigned int *allocatedMem;
 
 int main()
 {
-	//ProcessPool allocates memory starting from address 0x64100000
+	// ProcessPool allocates 4096 bytes starting from address 0x64100000
+	// Range : 0x64100000 - 0x64101000
+	
+	// First process memory layout
+	// Code region : 0x64101000 - 0x64101400
+	// Data region : 0x64104000 - 0x64108000
+
+	// Second process memory layout
+	// Code region : 0x64101400 - 0x64101800
+	// Data region : 0x64108000 - 0x6410c000
+
+	// Third process memory layout
+	// Code region : 0x64101800 - 0x64101c00
+	// Data region : 0x6410c000 - 0x64110000
 
 	// Altered elfs tests
 	iprintf("\nExecuting ELF tests.\n");
@@ -43,22 +63,38 @@ int main()
 	 //Mpu tests
 	iprintf("\n\nExecuting MPU tests.\n");
 	iprintf("---------------------\n");
-	memAllocation(2048);
+	allocatedMem = memAllocation(4096);
 	mpuTest1();
 	mpuTest2();
 	mpuTest3();
 	mpuTest4();
 	mpuTest5();
+	mpuTest6();
+	mpuTest8();
+	mpuTest9();
+	mpuTest7();
 }
 
 unsigned int* memAllocation(unsigned int size)
 {
 	unsigned int *p = ProcessPool::instance().allocate(size);
 	memset(p, WATERMARK_FILL, size);
-	iprintf("Allocated 2048 bytes. Base: %p. Size: 0x%x.\n\n", p, size);
+	iprintf("Allocated %d bytes. Base: %p. Size: 0x%x.\n\n", size, p, size);
 	return p;
 }
 
+// Returns true if a watermark filled memory zone is not corrupted.
+// 'base' must be 4-byte aligned
+bool memCheck(unsigned int *base, unsigned int size)
+{
+	for(unsigned int i = 0; i < size / 4; i++)
+	{
+		if(*(base + i) != WATERMARK_FILL)
+			return false;
+	}
+	return true;
+}
+
 void runElfTest(const char *name, const unsigned char *filename, unsigned int file_length)
 {
 	iprintf("Executing %s...", name);
@@ -103,7 +139,7 @@ void mpuTest1()
 	{
 		if(*addr == 0xbbbbbbbb)
 			iprintf("...not passed! The process has written a forbidden memory location.\n\n");
-		else if(*addr == 0xaaaaaaaa)
+		else if(*addr == WATERMARK_FILL)
 			iprintf("...passed!\n\n");
 		else
 			iprintf("...not passed! Memory has been somehow corrupted.\n\n");
@@ -122,7 +158,7 @@ void mpuTest2()
 	ec = runProgram(test2_elf, test2_elf_len);
 	if(isSignaled(ec))
 	{
-		if(*addr == 0xaaaaaaaa)
+		if(*addr == WATERMARK_FILL)
 			iprintf("...passed!\n\n");
 		else
 			iprintf("...not passed! Memory has been somehow corrupted.\n\n");
@@ -170,7 +206,7 @@ void mpuTest4()
 void mpuTest5()
 {
 	int ec;
-	unsigned int *addr = (unsigned int*) 0x64100800;
+	unsigned int *addr = (unsigned int*) 0x64101000;
 	iprintf("Executing MPU Test 5...\n");
 	ec = runProgram(test5_elf, test5_elf_len);
 	if(isSignaled(ec))
@@ -185,3 +221,107 @@ void mpuTest5()
 		iprintf("...not passed! Process exited normally.\n\n");
 	}
 }
+
+void mpuTest6()
+{
+	int ec;
+	unsigned int *addr = (unsigned int*) 0x64101404;
+	iprintf("Executing MPU Test 6...\n");
+	ec = runProgram(test6_elf, test6_elf_len);
+	if(isSignaled(ec))
+	{
+		if(*addr == 0xbbbbbbbb)
+			iprintf("...not passed! The process has written a forbidden memory location.\n\n");
+		else
+			iprintf("...passed!.\n\n");
+	}
+	else
+	{
+		iprintf("...not passed! Process exited normally.\n\n");
+	}
+}
+
+void mpuTest7()
+{
+	int ec;
+	unsigned int memSize = 16384;
+	unsigned int *addr = (unsigned int*) 0x64108000;
+	iprintf("Executing MPU Test 7...\n");	
+	ElfProgram prog(reinterpret_cast<const unsigned int*>(test7_elf), test7_elf_len);
+	pid_t child=Process::create(prog);
+
+	unsigned int *p = ProcessPool::instance().allocate(memSize);
+	memset(p, WATERMARK_FILL, memSize);
+	iprintf("Allocated %d bytes. Base: %p. Size: 0x%x.\n\n", memSize, p, memSize);
+	
+	Process::waitpid(child, &ec, 0);
+
+	if(isSignaled(ec))
+	{
+		iprintf("...passed!.\n\n");
+	}
+	else
+	{
+		iprintf("...not passed! Process exited normally.\n\n");
+	}
+
+	if(memCheck(p, memSize) == true)
+		iprintf("...memory sane!.\n\n");
+	else
+		iprintf("...memory NOT sane!.\n\n");
+}
+
+void mpuTest8()
+{
+	// We create two processes. The first goes to sleep for 2 seconds,
+	// while the second process tries to access the data region of the
+	// first.
+	unsigned int *addr = (unsigned int*) 0x64104004;
+	iprintf("Executing MPU Test 8...\n");
+	ElfProgram prog1(reinterpret_cast<const unsigned int*>(test8_1_elf),test8_1_elf_len);
+	ElfProgram prog2(reinterpret_cast<const unsigned int*>(test8_2_elf),test8_2_elf_len);
+	pid_t child1=Process::create(prog1);
+	pid_t child2=Process::create(prog2);
+	int ec1, ec2;
+	Process::waitpid(child1,&ec1,0);
+	Process::waitpid(child2,&ec2,0);
+	if(WIFSIGNALED(ec2) && (WTERMSIG(ec2) == SIGSEGV) && WIFEXITED(ec1))
+	{
+		if(*addr == 0xbbbbbbbb)
+			iprintf("...not passed! The process has written a forbidden memory location.\n\n");
+		else
+			iprintf("...passed!.\n\n");
+	}
+	else
+	{
+		iprintf("...not passed!\n\n");
+	}
+}
+
+void mpuTest9()
+{
+	iprintf("Executing MPU Test 9...\n");
+	ElfProgram prog(reinterpret_cast<const unsigned int*>(test9_elf),test9_elf_len);
+	std::vector<pid_t> pids;
+	int ec;
+	for(unsigned int i = 0; i < 100; i++)
+	{
+		pid_t pid;
+		try {
+			pid = Process::create(prog);
+			pids.push_back(pid);
+		}
+		catch (bad_alloc &ex)
+		{
+			iprintf("Bad alloc raised: %s\nIteration is: %d\n", ex.what(), i);
+			break;
+		}
+	}
+	iprintf("Allocated %d processes before system memory ran out.\n", pids.size());
+	for(unsigned int i = 0; i < pids.size(); i++)
+	{
+		Process::waitpid(pids[i], &ec, 0);
+		//iprintf("Process %d has terminated with return code: %d\n", pids[i], ec);
+	}
+	iprintf("Test passed\n\n");
+}
-- 
GitLab