Index: /soft/giet_vm/Makefile
===================================================================
--- /soft/giet_vm/Makefile	(revision 231)
+++ /soft/giet_vm/Makefile	(revision 232)
@@ -1,14 +1,14 @@
 export # export all variable to sub-Makefile
-CC=mipsel-unknown-elf-gcc
-AS=mipsel-unknown-elf-as
-LD=mipsel-unknown-elf-ld
-DU=mipsel-unknown-elf-objdump
+CC = mipsel-unknown-elf-gcc
+AS = mipsel-unknown-elf-as
+LD = mipsel-unknown-elf-ld
+DU = mipsel-unknown-elf-objdump
 
 MAP_XML      = mappings/4c_1p_four.xml
 
 SYS_OBJS     = build/sys/vm_handler.o \
-		       build/sys/sys_handler.o \
+               build/sys/sys_handler.o \
                build/sys/giet.o \
-       	       build/sys/switch.o \
+               build/sys/switch.o \
                build/sys/common.o \
                build/sys/ctx_handler.o \
@@ -38,12 +38,10 @@
                build/libs/utils.o
 
-CFLAGS=-Wall -ffreestanding -mno-gpopt -mips32 -g
+CFLAGS = -Wall -ffreestanding -mno-gpopt -mips32 -g
 
 INCLUDE = -Iboot -Isys -Ixml -Ilibs -I.
 
-TRASH= /dev/null||true
+all: map.bin soft.elf
 
-all: map.bin soft.elf
-	
 ## merge all *.elf and map.bin to soft.elf
 soft.elf: build/boot/boot.elf \
@@ -107,5 +105,5 @@
 
 build/hello/main.o: hello/main.c
-	$(CC) $(INCLUDE) $(CFLAGS)  -c -o $@ $<
+	$(CC) $(INCLUDE) $(CFLAGS) -c -o $@ $<
 
 ### pgcd compilation
@@ -115,27 +113,31 @@
 
 build/pgcd/main.o: pgcd/main.c
-	$(CC) $(INCLUDE) $(CFLAGS)  -c -o $@ $<
+	$(CC) $(INCLUDE) $(CFLAGS) -c -o $@ $<
 
 ### libs compilation
 build/libs/utils.o: libs/utils.c giet_config.h
-	$(CC) $(CFLAGS) $(INCLUDE)  -c -o $@ $<
+	$(CC) $(CFLAGS) $(INCLUDE) -c -o $@ $<
 
 build/libs/stdio.o: libs/stdio.c giet_config.h  
-	$(CC) $(CFLAGS) $(INCLUDE)  -c -o $@ $<
+	$(CC) $(CFLAGS) $(INCLUDE) -c -o $@ $<
 
 build/libs/mwmr_channel.o: libs/mwmr_channel.c
-	$(CC) $(CFLAGS) $(INCLUDE)  -c -o $@ $<
+	$(CC) $(CFLAGS) $(INCLUDE) -c -o $@ $<
+
+build/libs/malloc.o: libs/malloc.c libs/malloc.h libs/malloc_private.h giet_config.h
+	$(CC) $(CFLAGS) $(INCLUDE) -c -o $@ $<
+
 
 
 ### clean 
 clean:
-	rm -f *.o *.elf *.bin *.txt core  giet_vsegs.ld hard_config.h *~ 2>$(TRASH)
-	$(MAKE) -s clean -C xml	2>$(TRASH)
-	$(MAKE) -s clean -C memo 2>$(TRASH)
-	rm -r build/boot/* 2>$(TRASH)
-	rm -r build/sys/* 2>$(TRASH)
-	rm -r build/libs/* 2>$(TRASH)
-	rm -r build/pgcd/* 2>$(TRASH)
-	rm -r build/hello/* 2>$(TRASH)
-	rm -r build/display/* 2>$(TRASH)
-	rm -r build/router/* 2>$(TRASH)
+	rm -f *.o *.elf *.bin *.txt core  giet_vsegs.ld hard_config.h *~
+	$(MAKE) -s clean -C xml
+	$(MAKE) -s clean -C memo
+	rm -rf build/boot/*
+	rm -rf build/sys/*
+	rm -rf build/libs/*
+	rm -rf build/pgcd/*
+	rm -rf build/hello/*
+	rm -rf build/display/*
+	rm -rf build/router/*
Index: /soft/giet_vm/boot/boot_init.c
===================================================================
--- /soft/giet_vm/boot/boot_init.c	(revision 231)
+++ /soft/giet_vm/boot/boot_init.c	(revision 232)
@@ -1387,5 +1387,5 @@
                 //FIXME: the vspace_id should be the same for all ports: put it in the coproc?
                 unsigned int vspace_id = cp_port[cp_port_id].vspaceid;
-                unsigned int vobj_id = cp_port[cp_port_id].vobjlocid + vspace[vspace_id].vobj_offset;
+                unsigned int vobj_id = cp_port[cp_port_id].mwmr_vobjid + vspace[vspace_id].vobj_offset;
 
                 mwmr_channel_t * pmwmr = (mwmr_channel_t *) (vobj[vobj_id].paddr);
@@ -1669,5 +1669,5 @@
 
             // ctx_sp :  Get the vobj containing the stack 
-            unsigned int vobj_id = task[task_id].vobjlocid + vspace[vspace_id].vobj_offset;
+            unsigned int vobj_id = task[task_id].stack_vobjid + vspace[vspace_id].vobj_offset;
             unsigned int ctx_sp = vobj[vobj_id].vaddr + vobj[vobj_id].length;
 
@@ -1706,4 +1706,5 @@
             boot_scheduler_set_context(gpid, ltid, CTX_LTID_ID, ltid);
             boot_scheduler_set_context(gpid, ltid, CTX_VSID_ID, vspace_id);
+            boot_scheduler_set_context(gpid, ltid, CTX_GTID_ID, task_id);
             boot_scheduler_set_context(gpid, ltid, CTX_RUN_ID, 1);
 
Index: /soft/giet_vm/giet_config.h
===================================================================
--- /soft/giet_vm/giet_config.h	(revision 231)
+++ /soft/giet_vm/giet_config.h	(revision 232)
@@ -29,5 +29,5 @@
 
 #define GIET_NB_VSPACE_MAX	64			/* max number of virtual spaces */
-#define GIET_TICK_VALUE	    0x1000		/* context switch period (number of cycles) */
+#define GIET_TICK_VALUE	    0x100000		/* context switch period (number of cycles) */
 
 #endif
Index: /soft/giet_vm/libs/stdio.c
===================================================================
--- /soft/giet_vm/libs/stdio.c	(revision 231)
+++ /soft/giet_vm/libs/stdio.c	(revision 232)
@@ -21,5 +21,7 @@
 #define SYSCALL_GCD_WRITE       0x06
 #define SYSCALL_GCD_READ        0x07
-#define SYSCALL_TASK_ID         0x09
+#define SYSCALL_HEAP_INFO       0x08
+#define SYSCALL_PROC_TASK_ID    0x09
+#define SYSCALL_GLOBAL_TASK_ID  0x0A
 #define SYSCALL_CTX_SWITCH      0x0D
 #define SYSCALL_EXIT            0x0E
@@ -742,12 +744,28 @@
 
 //////////////////////////////////////////////////////////////////////////////////
-// giet_get_task_id()
-// The user task calling this function is descheduled and
-// the processor is allocated to another task.
-//////////////////////////////////////////////////////////////////////////////////
-unsigned int giet_task_id() {
-    return sys_call(SYSCALL_TASK_ID, 0, 0, 0, 0);
-}
-
+// giet_proc_task_id()
+// This functions returns the local task id, i.e. the processor task id (ranging
+// from 0 to n-1(p) for each processor if p has n tasks)
+//////////////////////////////////////////////////////////////////////////////////
+unsigned int giet_proc_task_id() {
+    return sys_call(SYSCALL_PROC_TASK_ID, 0, 0, 0, 0);
+}
+
+//////////////////////////////////////////////////////////////////////////////////
+// giet_heap_info()
+// This function returns the base address and size of the current task's heap
+//////////////////////////////////////////////////////////////////////////////////
+unsigned int giet_heap_info(unsigned int * vaddr, unsigned int * length) {
+    return sys_call(SYSCALL_HEAP_INFO, (unsigned int) vaddr, (unsigned int) length, 0, 0);
+}
+
+
+//////////////////////////////////////////////////////////////////////////////////
+// giet_global_task_id()
+// This functions returns the global task id, which is unique in all the giet
+//////////////////////////////////////////////////////////////////////////////////
+unsigned int giet_global_task_id() {
+    return sys_call(SYSCALL_GLOBAL_TASK_ID, 0, 0, 0, 0);
+}
 
 // Local Variables:
Index: /soft/giet_vm/libs/stdio.h
===================================================================
--- /soft/giet_vm/libs/stdio.h	(revision 231)
+++ /soft/giet_vm/libs/stdio.h	(revision 232)
@@ -50,5 +50,8 @@
 unsigned int giet_rand();
 unsigned int giet_context_switch();
-unsigned int giet_task_id();
+unsigned int giet_proc_task_id();
+unsigned int giet_heap_info(unsigned int * vaddr, unsigned int * size);
+unsigned int giet_global_task_id();
+
 unsigned int giet_procnumber();
 
Index: /soft/giet_vm/mappings/1c_4p_four.xml
===================================================================
--- /soft/giet_vm/mappings/1c_4p_four.xml	(revision 231)
+++ /soft/giet_vm/mappings/1c_4p_four.xml	(revision 232)
@@ -147,33 +147,37 @@
 
             <vseg name = "seg_data"     vbase = "0x00800000" mode = "__WU" clusterid = "0" psegname  = "PSEG_RAM" > 
-                <vobj name = "data"     type = "ELF" length  = "0x00010000" binpath = "build/router/router.elf" /> 
-            </vseg>
-            <vseg name = "seg_code"     vbase = "0x00400000" mode = "CX_U" clusterid = "0" psegname  = "PSEG_RAM" > 
-                <vobj name = "code"     type = "ELF" length  = "0x00010000" binpath = "build/router/router.elf" /> 
-            </vseg>
-            <vseg name = "seg_ptab"     vbase = "0x00300000" mode = "C___" clusterid = "0" psegname  = "PSEG_RAM" > 
-                <vobj name = "ptab"     type = "PTAB" length  = "0x00012000" align   = "13" /> 
+                <vobj name = "data"     type = "ELF" length = "0x00010000" binpath = "build/router/router.elf" /> 
+            </vseg>
+            <vseg name = "seg_code"     vbase = "0x00400000" mode = "CX_U" clusterid = "0" psegname  = "PSEG_RAM" > 
+                <vobj name = "code"     type = "ELF" length = "0x00010000" binpath = "build/router/router.elf" /> 
+            </vseg>
+            <vseg name = "seg_ptab"     vbase = "0x00300000" mode = "C___" clusterid = "0" psegname  = "PSEG_RAM" > 
+                <vobj name = "ptab"     type = "PTAB" length = "0x00012000" align   = "13" /> 
             </vseg>
             <vseg name = "seg_stack_p"  vbase = "0x00010000" mode = "C_WU" clusterid = "0" psegname  = "PSEG_RAM" > 
-                <vobj name = "stack_p"  type = "BUFFER" length  = "0x00010000" />
-			</vseg>
-            <vseg name = "seg_stack_c"  vbase = "0x00020000" mode = "C_WU" clusterid = "0" psegname  = "PSEG_RAM" >
-                <vobj name = "stack_c"  type = "BUFFER" length  = "0x00010000" />
+                <vobj name = "stack_p"  type = "BUFFER" length = "0x00010000" />
+                <vobj name = "heap_p"   type = "BUFFER" length = "0x00010000" />
+			   </vseg>
+            <vseg name = "seg_stack_c"  vbase = "0x00030000" mode = "C_WU" clusterid = "0" psegname  = "PSEG_RAM" >
+                <vobj name = "stack_c"  type = "BUFFER" length = "0x00010000" />
+                <vobj name = "heap_c"   type = "BUFFER" length = "0x00010000" />
 						</vseg>
-            <vseg name = "seg_stack_rA" vbase = "0x00030000" mode = "C_WU" clusterid = "0" psegname  = "PSEG_RAM" >
-                <vobj name = "stack_rA" type = "BUFFER" length  = "0x00010000" /> 
-            </vseg>
-            <vseg name = "seg_stack_rB" vbase = "0x00040000" mode = "C_WU" clusterid = "0" psegname  = "PSEG_RAM" >
+            <vseg name = "seg_stack_rA" vbase = "0x00050000" mode = "C_WU" clusterid = "0" psegname  = "PSEG_RAM" >
+                <vobj name = "stack_rA" type = "BUFFER" length = "0x00010000" /> 
+                <vobj name = "heap_rA"  type = "BUFFER" length = "0x00010000" />
+            </vseg>
+            <vseg name = "seg_stack_rB" vbase = "0x00070000" mode = "C_WU" clusterid = "0" psegname  = "PSEG_RAM" >
                 <vobj name = "stack_rB" type = "BUFFER" length  = "0x00010000" /> 
-            </vseg>
-            <vseg name = "seg_mwmrs"    vbase = "0x00050000" mode = "__WU" clusterid = "0" psegname  = "PSEG_RAM" >
-                <vobj name = "mwmr_in"  type = "MWMR" length  = "0x00000020" init = "1" />
-                <vobj name = "mwmr_out" type = "MWMR" length  = "0x00000020" init = "1" />
-            </vseg>
-
-            <task name = "producer" clusterid = "0" proclocid = "0" stackname = "stack_p"  startid = "0" usetty = "1" />
-            <task name = "consumer" clusterid = "0" proclocid = "1" stackname = "stack_c"  startid = "1" usetty = "1" />
-            <task name = "router_A" clusterid = "0" proclocid = "2" stackname = "stack_rA" startid = "2" usetty = "1" />
-            <task name = "router_B" clusterid = "0" proclocid = "3" stackname = "stack_rB" startid = "2" usetty = "1" />
+                <vobj name = "heap_rB"  type = "BUFFER" length = "0x00010000" />
+            </vseg>
+            <vseg name = "seg_mwmrs"    vbase = "0x00090000" mode = "__WU" clusterid = "0" psegname  = "PSEG_RAM" >
+                <vobj name = "mwmr_in"  type = "MWMR" length = "0x00000020" init = "1" />
+                <vobj name = "mwmr_out" type = "MWMR" length = "0x00000020" init = "1" />
+            </vseg>
+
+            <task name = "producer" clusterid = "0" proclocid = "0" stackname = "stack_p"  heapname = "heap_p"  startid = "0" usetty = "1" />
+            <task name = "consumer" clusterid = "0" proclocid = "1" stackname = "stack_c"  heapname = "heap_c"  startid = "1" usetty = "1" />
+            <task name = "router_A" clusterid = "0" proclocid = "2" stackname = "stack_rA" heapname = "heap_rA" startid = "2" usetty = "1" />
+            <task name = "router_B" clusterid = "0" proclocid = "3" stackname = "stack_rB" heapname = "heap_rB" startid = "2" usetty = "1" />
 
         </vspace>
Index: /soft/giet_vm/mappings/4c_1p_display.xml
===================================================================
--- /soft/giet_vm/mappings/4c_1p_display.xml	(revision 231)
+++ /soft/giet_vm/mappings/4c_1p_display.xml	(revision 232)
@@ -171,18 +171,19 @@
     <vspaceset>
         <vspace name = "display" startname = "data" >
-            <vseg name = "seg_data"        vbase = "0x00800000" mode = "C_WU" clusterid = "3" psegname = "PSEG_RAM" >
-                <vobj name = "data"        type	= "ELF" length = "0x00010000" binpath = "build/display/display.elf" />
+            <vseg name = "seg_data"  vbase = "0x00800000" mode = "C_WU" clusterid = "3" psegname = "PSEG_RAM" >
+                <vobj name = "data"  type	= "ELF" length = "0x00010000" binpath = "build/display/display.elf" />
 			</vseg>
-            <vseg name = "seg_ptab"        vbase = "0x00300000" mode = "C___" clusterid = "3" psegname = "PSEG_RAM" >
-                <vobj name = "ptab"        type	= "PTAB" length  = "0x00012000" align   = "13" />
+            <vseg name = "seg_ptab"  vbase = "0x00300000" mode = "C___" clusterid = "3" psegname = "PSEG_RAM" >
+                <vobj name = "ptab"  type	= "PTAB" length  = "0x00012000" align   = "13" />
             </vseg>
-            <vseg name = "seg_code"        vbase = "0x00400000" mode = "CX_U" clusterid = "3" psegname = "PSEG_RAM" >
-                <vobj name = "code"        type	= "ELF" length = "0x00010000" binpath = "build/display/display.elf" />
+            <vseg name = "seg_code"  vbase = "0x00400000" mode = "CX_U" clusterid = "3" psegname = "PSEG_RAM" >
+                <vobj name = "code"  type	= "ELF" length = "0x00010000" binpath = "build/display/display.elf" />
             </vseg>
-            <vseg name = "seg_stack"       vbase = "0x00010000" mode = "C_WU" clusterid = "3" psegname = "PSEG_RAM" >
-                <vobj name = "stack"       type	= "BUFFER" length = "0x00010000" />
+            <vseg name = "seg_stack" vbase = "0x00010000" mode = "C_WU" clusterid = "3" psegname = "PSEG_RAM" >
+                <vobj name = "stack" type	= "BUFFER" length = "0x00010000" />
+                <vobj name = "heap"  type = "BUFFER" length = "0x00010000" />
             </vseg>
 
-            <task name = "main_display" clusterid = "3" proclocid = "0" stackname = "stack" startid = "0" usetty = "1" usefbdma = "1" />
+            <task name = "main_display" clusterid = "3" proclocid = "0" stackname = "stack" heapname = "heap" startid = "0" usetty = "1" usefbdma = "1" />
         </vspace>
     </vspaceset>
Index: /soft/giet_vm/mappings/4c_1p_four.xml
===================================================================
--- /soft/giet_vm/mappings/4c_1p_four.xml	(revision 231)
+++ /soft/giet_vm/mappings/4c_1p_four.xml	(revision 232)
@@ -182,23 +182,27 @@
             <vseg name = "seg_stack_prod"  vbase = "0x00010000" mode = "C_WU" clusterid = "0" psegname = "PSEG_RAM" >
                 <vobj name = "stack_prod"  type	= "BUFFER" length = "0x00010000" /> 
-            </vseg>
-            <vseg name = "seg_stack_cons"  vbase = "0x00020000" mode = "C_WU" clusterid = "1" psegname = "PSEG_RAM" > 
+                <vobj name = "heap_prod"   type	= "BUFFER" length = "0x00010000" /> 
+            </vseg>
+            <vseg name = "seg_stack_cons"  vbase = "0x00030000" mode = "C_WU" clusterid = "1" psegname = "PSEG_RAM" > 
                 <vobj name = "stack_cons"  type	= "BUFFER" length = "0x00010000" />
-            </vseg>
-            <vseg name = "seg_stack_routA" vbase = "0x00030000" mode = "C_WU" clusterid = "2" psegname = "PSEG_RAM" > 
+                <vobj name = "heap_cons"   type	= "BUFFER" length = "0x00010000" /> 
+            </vseg>
+            <vseg name = "seg_stack_routA" vbase = "0x00050000" mode = "C_WU" clusterid = "2" psegname = "PSEG_RAM" > 
                 <vobj name = "stack_routA" type	= "BUFFER" length = "0x00010000" />
-            </vseg>
-            <vseg name = "seg_stack_routB" vbase = "0x00040000" mode = "C_WU" clusterid = "3" psegname = "PSEG_RAM" > 
+                <vobj name = "heap_routA"  type	= "BUFFER" length = "0x00010000" /> 
+            </vseg>
+            <vseg name = "seg_stack_routB" vbase = "0x00070000" mode = "C_WU" clusterid = "3" psegname = "PSEG_RAM" > 
                 <vobj name = "stack_routB" type	= "BUFFER" length = "0x00010000" />
-            </vseg>
-            <vseg name = "seg_mwmrs"       vbase = "0x00050000" mode = "__WU" clusterid = "0" psegname = "PSEG_RAM" > 
+                <vobj name = "heap_routB"  type	= "BUFFER" length = "0x00010000" /> 
+            </vseg>
+            <vseg name = "seg_mwmrs"       vbase = "0x00090000" mode = "__WU" clusterid = "0" psegname = "PSEG_RAM" > 
                 <vobj name = "mwmr_in"     type = "MWMR" length = "0x00000020" init = "1" />
                 <vobj name = "mwmr_out"    type = "MWMR" length = "0x00000020" init = "1" />
 		    </vseg>
 
-            <task name = "producer" clusterid = "0" proclocid = "0" stackname = "stack_prod"  startid = "0" usetty = "1" />
-            <task name = "consumer" clusterid = "1" proclocid = "0" stackname = "stack_cons"  startid = "1" usetty = "1" />
-            <task name = "router_A" clusterid = "2" proclocid = "0" stackname = "stack_routA" startid = "2" usetty = "1" />
-            <task name = "router_B" clusterid = "3" proclocid = "0" stackname = "stack_routB" startid = "2" usetty = "1" />
+            <task name = "producer" clusterid = "0" proclocid = "0" stackname = "stack_prod"  heapname = "heap_prod"  startid = "0" usetty = "1" />
+            <task name = "consumer" clusterid = "1" proclocid = "0" stackname = "stack_cons"  heapname = "heap_cons"  startid = "1" usetty = "1" />
+            <task name = "router_A" clusterid = "2" proclocid = "0" stackname = "stack_routA" heapname = "heap_routA" startid = "2" usetty = "1" />
+            <task name = "router_B" clusterid = "3" proclocid = "0" stackname = "stack_routB" heapname = "heap_routB" startid = "2" usetty = "1" />
         </vspace>
 
@@ -215,7 +219,8 @@
             <vseg name = "seg_stack"       vbase = "0x00010000" mode = "C_WU" clusterid = "1" psegname = "PSEG_RAM" >
                 <vobj name = "stack"       type	= "BUFFER" length = "0x00010000" />
-            </vseg>
-
-            <task name = "main_hello" clusterid = "1" proclocid = "0" stackname = "stack" startid = "0" usetty = "1" />
+                <vobj name = "heap"        type	= "BUFFER" length = "0x00010000" />
+            </vseg>
+
+            <task name = "main_hello" clusterid = "1" proclocid = "0" stackname = "stack" heapname = "heap" startid = "0" usetty = "1" />
         </vspace>
 
@@ -232,7 +237,8 @@
             <vseg name = "seg_stack"       vbase = "0x00010000" mode = "C_WU" clusterid = "2" psegname = "PSEG_RAM" >
                 <vobj name = "stack"       type = "BUFFER" length = "0x00010000" /> 
-            </vseg>
-
-            <task name = "main_pgcd" clusterid = "2" proclocid = "0" stackname = "stack" startid = "0" usetty = "1" />
+                <vobj name = "heap"        type = "BUFFER" length = "0x00010000" /> 
+            </vseg>
+
+            <task name = "main_pgcd" clusterid = "2" proclocid = "0" stackname = "stack" heapname = "heap" startid = "0" usetty = "1" />
         </vspace>
 
@@ -249,7 +255,8 @@
             <vseg name = "seg_stack"       vbase = "0x00010000" mode = "C_WU" clusterid = "3" psegname = "PSEG_RAM" >
                 <vobj name = "stack"       type	= "BUFFER" length = "0x00010000" />
-            </vseg>
-
-            <task name = "main_display" clusterid = "3" proclocid = "0" stackname = "stack" startid = "0" usetty = "1" usefbdma = "1" />
+                <vobj name = "heap"        type	= "BUFFER" length = "0x00010000" />
+            </vseg>
+
+            <task name = "main_display" clusterid = "3" proclocid = "0" stackname = "stack" heapname = "heap" startid = "0" usetty = "1" usefbdma = "1" />
         </vspace>
     </vspaceset>
Index: /soft/giet_vm/mappings/exemple.xml
===================================================================
--- /soft/giet_vm/mappings/exemple.xml	(revision 231)
+++ /soft/giet_vm/mappings/exemple.xml	(revision 232)
@@ -421,8 +421,12 @@
 								    	type	= "BUFFER"
 									    length  = "0x00010000" />
+                         <vobj   name	= "heap_producer"
+								    	type	= "BUFFER"
+									    length  = "0x00010000" />
+
 						</vseg>
 
                         <vseg   name      = "seg_stack_consumer"
-				                vbase     = "0x00020000" 
+				                vbase     = "0x00030000" 
                                 mode      = "C_WU"
                                 clusterid = "0"
@@ -431,8 +435,12 @@
 								    	type	= "BUFFER"
 									    length  = "0x00010000" />
+                         <vobj   name	= "heap_consumer"
+								    	type	= "BUFFER"
+									    length  = "0x00010000" />
+
 						</vseg>
 
                         <vseg   name      = "seg_stack_router_A"
-                				vbase     = "0x00030000" 
+                				vbase     = "0x00050000" 
                                 mode      = "C_WU"
                                 clusterid = "0"
@@ -441,8 +449,12 @@
 								    	type	= "BUFFER"
 									    length  = "0x00010000" />
+                         <vobj   name	= "heap_router_A"
+								    	type	= "BUFFER"
+									    length  = "0x00010000" />
+
 						</vseg>
 
                         <vseg   name      = "seg_stack_router_B"
-				                vbase     = "0x00040000" 
+				                vbase     = "0x00070000" 
                                 mode      = "C_WU"
                                 clusterid = "0"
@@ -451,8 +463,12 @@
 								    	type	= "BUFFER"
 									    length  = "0x00010000" />
+							    <vobj   name	= "heap_router_B"
+								    	type	= "BUFFER"
+									    length  = "0x00010000" />
+
 						</vseg>
 
                         <vseg   name      = "seg_mwmr_channels"
-                                vbase     = "0x00050000"
+                                vbase     = "0x00090000"
                                 mode      = "__WU"
                                 clusterid = "0"
@@ -472,4 +488,5 @@
                                 proclocid = "0"
                                 stackname = "stack_producer"
+                                heapname  = "heap_producer"
                                 startid   = "0"
                                 usetty    = "1" />
@@ -479,4 +496,5 @@
                                 proclocid = "1"
                                 stackname = "stack_consumer"
+                                heapname  = "heap_consumer"
                                 startid   = "1" 
                                 usetty    = "1" />
@@ -486,4 +504,5 @@
                                 proclocid = "2"
                                 stackname = "stack_router_A"
+                                heapname  = "heap_router_A"
                                 startid   = "2"
                                 usetty    = "1" />
@@ -493,4 +512,5 @@
                                 proclocid = "3"
                                 stackname = "stack_router_B"
+                                heapname  = "heap_router_B"
                                 startid   = "2"
                                 usetty    = "1" />
Index: /soft/giet_vm/sys/common.c
===================================================================
--- /soft/giet_vm/sys/common.c	(revision 231)
+++ /soft/giet_vm/sys/common.c	(revision 232)
@@ -375,8 +375,8 @@
 
 ////////////////////////////////////////////////////////////////////////////
-//    _get_current_task_id()
+//    _get_proc_task_id()
 // This function returns the index of the currently running task.
 ////////////////////////////////////////////////////////////////////////////
-unsigned int _get_current_task_id() {
+unsigned int _get_proc_task_id() {
     static_scheduler_t * psched = (static_scheduler_t *) _get_sched();
     return _physical_read_access(&(psched->current));
@@ -385,10 +385,19 @@
 
 ////////////////////////////////////////////////////////////////////////////
-//    _set_current_task_id()
+//    _set_proc_task_id()
 // This function returns the index of the currently running task.
 ////////////////////////////////////////////////////////////////////////////
-void _set_current_task_id(unsigned int value) {
+void _set_proc_task_id(unsigned int value) {
     static_scheduler_t * psched = (static_scheduler_t *) _get_sched();
     _physical_write_access(&(psched->current), value);
+}
+
+
+////////////////////////////////////////////////////////////////////////////
+//    _get_global_task_id()
+// This function returns the global index of the running task.
+////////////////////////////////////////////////////////////////////////////
+unsigned int _get_global_task_id() {
+  return _get_context_slot(_get_proc_task_id(), CTX_GTID_ID);
 }
 
Index: /soft/giet_vm/sys/common.h
===================================================================
--- /soft/giet_vm/sys/common.h	(revision 231)
+++ /soft/giet_vm/sys/common.h	(revision 232)
@@ -60,6 +60,9 @@
 unsigned int _get_interrupt_vector_entry(unsigned int index);
 
-unsigned int _get_current_task_id(void);
-void _set_current_task_id(unsigned int value);
+unsigned int _get_proc_task_id(void);
+void _set_proc_task_id(unsigned int value);
+
+unsigned int _get_global_task_id(void);
+
 
 unsigned int _get_tasks_number(void);
Index: /soft/giet_vm/sys/ctx_handler.c
===================================================================
--- /soft/giet_vm/sys/ctx_handler.c	(revision 231)
+++ /soft/giet_vm/sys/ctx_handler.c	(revision 232)
@@ -76,5 +76,5 @@
 
     // get current task index
-    unsigned int curr_task_id = _get_current_task_id();
+    unsigned int curr_task_id = _get_proc_task_id();
 
     // select the next task using a round-robin policy
@@ -103,5 +103,5 @@
         unsigned int * next_ctx_paddr = &(psched->context[next_task_id][0]);
 
-        _set_current_task_id(next_task_id);
+        _set_proc_task_id(next_task_id);
         //_timer_reset_irq_cpt(cluster_id, local_id); // commented until not properly supported in soclib
         // (the function is not yet present in drivers.c)
Index: /soft/giet_vm/sys/ctx_handler.h
===================================================================
--- /soft/giet_vm/sys/ctx_handler.h	(revision 231)
+++ /soft/giet_vm/sys/ctx_handler.h	(revision 232)
@@ -5,13 +5,12 @@
 
 /////////////////////////////////////////////////////////////////////////////////
-//	Definition of the scheduler structure
+//    Definition of the scheduler structure
 /////////////////////////////////////////////////////////////////////////////////
 
-typedef struct static_scheduler_s
-{
-    unsigned int	context[15][64];		// at most 15 task contexts
-    unsigned int	tasks;					// actual number of tasks
-    unsigned int	current;				// current task index
-    unsigned int	interrupt_vector[32];	// interrupt vector
+typedef struct static_scheduler_s {
+    unsigned int context[15][64];      // at most 15 task contexts
+    unsigned int tasks;                // actual number of tasks
+    unsigned int current;              // current task index
+    unsigned int interrupt_vector[32]; // interrupt vector
 } static_scheduler_t;
 
@@ -21,31 +20,32 @@
 /////////////////////////////////////////////////////////////////////////////////
 
-#define IDLE_TASK_INDEX		14
+#define IDLE_TASK_INDEX        14
 
 /////////////////////////////////////////////////////////////////////////////////
-//	Definition of the task context slots indexes
+//    Definition of the task context slots indexes
 /////////////////////////////////////////////////////////////////////////////////
 
-#define CTX_SP_ID		29
-#define CTX_RA_ID		31
+#define CTX_SP_ID        29
+#define CTX_RA_ID        31
 
-#define CTX_EPC_ID		32
-#define CTX_CR_ID		33
-#define CTX_SR_ID		34
-#define CTX_BVAR_ID		35
+#define CTX_EPC_ID       32
+#define CTX_CR_ID        33
+#define CTX_SR_ID        34
+#define CTX_BVAR_ID      35
 
-#define CTX_PTPR_ID		39
+#define CTX_PTPR_ID      39
 
-#define CTX_TTY_ID		40  // Integer : global TTY terminal index 
-#define CTX_DMA_ID	    41  // Integer : global DMA channel index
-#define CTX_NIC_ID	    42  // Integer : global NIC channel index
-#define CTX_TIMER_ID	43  // Integer : user level timer index / UNUSED
-#define CTX_PTAB_ID		44  // Pointer : page table virtual base adress
-#define CTX_LTID_ID		45  // Integer : local task index (in scheduler) / UNUSED
-#define CTX_VSID_ID		46  // Integer : vspace index
-#define CTX_RUN_ID		47  // Boolean : task runable
+#define CTX_TTY_ID       40  // Integer : global TTY terminal index 
+#define CTX_DMA_ID       41  // Integer : global DMA channel index
+#define CTX_NIC_ID       42  // Integer : global NIC channel index
+#define CTX_TIMER_ID     43  // Integer : user level timer index / UNUSED
+#define CTX_PTAB_ID      44  // Pointer : page table virtual base adress
+#define CTX_LTID_ID      45  // Integer : local task index (in scheduler) / UNUSED
+#define CTX_VSID_ID      46  // Integer : vspace index
+#define CTX_RUN_ID       47  // Boolean : task runable
+#define CTX_GTID_ID      48  // Integer : Global task id
 
 //////////////////////////////////////////////////////////////////////////////////
-// 	Prototype of the context switch function
+//     Prototype of the context switch function
 //////////////////////////////////////////////////////////////////////////////////
 
Index: /soft/giet_vm/sys/drivers.c
===================================================================
--- /soft/giet_vm/sys/drivers.c	(revision 231)
+++ /soft/giet_vm/sys/drivers.c	(revision 232)
@@ -120,5 +120,5 @@
 #if (NB_TIMERS_MAX > 0)
 in_unckdata volatile unsigned char _user_timer_event[NB_CLUSTERS * NB_TIMERS_MAX] 
-= { [0 ... ((NB_CLUSTERS * NB_TIMERS_MAX) - 1)] = 0 };
+                            = { [0 ... ((NB_CLUSTERS * NB_TIMERS_MAX) - 1)] = 0 };
 #endif
 
@@ -205,5 +205,5 @@
     bloup++; // to avoid a warning 
 #else
-    unsigned int * timer_address = (unsigned int *)((char *) &seg_tim_base + 
+    unsigned int * timer_address = (unsigned int *) ((char *) &seg_tim_base + 
             (cluster_id * CLUSTER_SIZE));
 
@@ -213,4 +213,24 @@
     return 0;
 }
+
+
+////////////////////////////////////////////////
+// _timer_reset_irq_cpt()
+////////////////////////////////////////////////
+//unsigned int _timer_reset_irq_cpt(unsigned int cluster_id, unsigned int local_id) {
+//    // parameters checking 
+//    if ( cluster_id >= NB_CLUSTERS)	 return 1;
+//    if ( local_id >= NB_TIMERS_MAX ) return 2;
+//
+//#if USE_XICU
+//#error // not implemented
+//#else
+//    unsigned int * timer_address = (unsigned int *) ((char *) &seg_tim_base + (cluster_id * CLUSTER_SIZE));
+//
+//    timer_address[local_id * TIMER_SPAN + TIMER_RESETIRQ] = 1;
+//#endif
+//
+//    return 0;
+//}
 
 
@@ -264,5 +284,5 @@
 unsigned int _tty_write(const char * buffer, unsigned int length) {
     unsigned int nwritten;
-    unsigned int task_id = _get_current_task_id();
+    unsigned int task_id = _get_proc_task_id();
     unsigned int tty_id = _get_context_slot(task_id, CTX_TTY_ID);
 
@@ -300,5 +320,5 @@
 //////////////////////////////////////////////////////////////////////////////
 unsigned int _tty_read(char * buffer, unsigned int length) {
-    unsigned int task_id = _get_current_task_id();
+    unsigned int task_id = _get_proc_task_id();
     unsigned int tty_id = _get_context_slot(task_id, CTX_TTY_ID);
 
@@ -567,5 +587,5 @@
 
     // get user space page table virtual address
-    unsigned int task_id = _get_current_task_id();
+    unsigned int task_id = _get_proc_task_id();
     unsigned int user_pt_vbase = _get_context_slot(task_id, CTX_PTAB_ID);
 
@@ -877,5 +897,5 @@
 
     // get DMA channel and compute DMA vbase address
-    unsigned int task_id    = _get_current_task_id();
+    unsigned int task_id    = _get_proc_task_id();
     unsigned int dma_id     = _get_context_slot(task_id, CTX_DMA_ID);
     unsigned int cluster_id = dma_id / NB_DMAS_MAX;
@@ -1012,5 +1032,5 @@
 unsigned int _dma_completed() {
 #if NB_DMAS_MAX > 0
-    unsigned int task_id = _get_current_task_id();
+    unsigned int task_id = _get_proc_task_id();
     unsigned int dma_id  = _get_context_slot(task_id, CTX_DMA_ID);
     unsigned int dma_ret;
@@ -1246,4 +1266,31 @@
 }
 
+///////////////////////////////////////////////////////////////////////////////////
+// _heap_info()
+// This function returns the information associated to a heap (size and vaddr)
+// It uses the global task id (CTX_GTID_ID, unique for each giet task) and the
+// vspace id (CTX_VSID_ID) defined in the context 
+///////////////////////////////////////////////////////////////////////////////////
+unsigned int _heap_info(unsigned int * vaddr, unsigned int * size) {
+    mapping_header_t * header  = (mapping_header_t *) (&seg_mapping_base);
+    mapping_task_t * tasks     = _get_task_base(header);
+    mapping_vobj_t * vobjs     = _get_vobj_base(header);
+    mapping_vspace_t * vspaces = _get_vspace_base(header);
+    unsigned int taskid        = _get_context_slot(_get_proc_task_id(), CTX_GTID_ID);
+    unsigned int vspaceid      = _get_context_slot(_get_proc_task_id(), CTX_VSID_ID);
+    int heap_local_vobjid      = tasks[taskid].heap_vobjid;
+    if (heap_local_vobjid != -1) {
+        unsigned int vobjheapid = heap_local_vobjid + vspaces[vspaceid].vobj_offset;
+        *vaddr                  = vobjs[vobjheapid].vaddr;
+        *size                   = vobjs[vobjheapid].length;
+        return 0;
+    }
+    else {
+        *vaddr = 0;
+        *size = 0;
+        return 0;
+    }
+}
+
 // Local Variables:
 // tab-width: 4
Index: /soft/giet_vm/sys/drivers.h
===================================================================
--- /soft/giet_vm/sys/drivers.h	(revision 231)
+++ /soft/giet_vm/sys/drivers.h	(revision 232)
@@ -113,4 +113,11 @@
 
 
+///////////////////////////////////////////////////////////////////////////////////
+// Heap related function(s)
+///////////////////////////////////////////////////////////////////////////////////
+
+unsigned int _heap_info(unsigned int * vaddr, unsigned int * size);
+
+
 #endif
 
Index: /soft/giet_vm/sys/exc_handler.c
===================================================================
--- /soft/giet_vm/sys/exc_handler.c	(revision 231)
+++ /soft/giet_vm/sys/exc_handler.c	(revision 232)
@@ -70,5 +70,5 @@
     _get_lock(&_tty_put_lock);
     _puts("\n[GIET] Exception for task ");
-    _putd(_get_current_task_id());
+    _putd(_get_proc_task_id());
     _puts(" on processor ");
     _putd(_procid());
@@ -86,5 +86,5 @@
 
     // goes to sleeping state
-    unsigned int task_id = _get_current_task_id();
+    unsigned int task_id = _get_proc_task_id();
     _set_context_slot( task_id, CTX_RUN_ID, 0);
 
Index: /soft/giet_vm/sys/sys_handler.c
===================================================================
--- /soft/giet_vm/sys/sys_handler.c	(revision 231)
+++ /soft/giet_vm/sys/sys_handler.c	(revision 232)
@@ -30,7 +30,7 @@
     &_gcd_write,           /* 0x06 */
     &_gcd_read,            /* 0x07 */
-    &_sys_ukn,             /* 0x08 */
-    &_get_current_task_id, /* 0x09 */
-    &_sys_ukn,             /* 0x0A */
+    &_heap_info,           /* 0x08 */
+    &_get_proc_task_id,    /* 0x09 */
+    &_get_global_task_id,  /* 0x0A */ 
     &_sys_ukn,             /* 0x0B */
     &_sys_ukn,             /* 0x0C */
@@ -77,5 +77,5 @@
     unsigned int date = _proctime();
     unsigned int proc_id = _procid();
-    unsigned int task_id = _get_current_task_id();
+    unsigned int task_id = _get_proc_task_id();
 
     // print death message
Index: /soft/giet_vm/xml/mapping_info.h
===================================================================
--- /soft/giet_vm/xml/mapping_info.h	(revision 231)
+++ /soft/giet_vm/xml/mapping_info.h	(revision 232)
@@ -178,5 +178,6 @@
     unsigned int clusterid;      // physical cluster index
     unsigned int proclocid;      // processor local index (inside cluster)
-    unsigned int vobjlocid;      // stack vobj index in vspace
+    unsigned int stack_vobjid;   // stack vobj index in vspace
+    unsigned int heap_vobjid;    // heap vobj index in vspace
     unsigned int startid;        // index in start_vector 
     unsigned int use_tty;        // TTY terminal required (global)
@@ -229,5 +230,5 @@
     unsigned int direction;      // TO_COPROC == 0 / FROM_COPROC == 1
     unsigned int vspaceid;       // index of the vspace containing the MWMR channel
-    unsigned int vobjlocid;      // local index of the vobj containing the MWMR channel
+    unsigned int mwmr_vobjid;      // local index of the vobj containing the MWMR channel
 } mapping_cp_port_t;
 
Index: /soft/giet_vm/xml/xml_driver.c
===================================================================
--- /soft/giet_vm/xml/xml_driver.c	(revision 231)
+++ /soft/giet_vm/xml/xml_driver.c	(revision 232)
@@ -271,5 +271,5 @@
                     port_id < coproc[coproc_id].port_offset + coproc[coproc_id].ports;
                     port_id++) {
-                unsigned int vobj_id = cp_port[port_id].vobjlocid + vspace[cp_port[port_id].vspaceid].vobj_offset; 
+                unsigned int vobj_id = cp_port[port_id].mwmr_vobjid + vspace[cp_port[port_id].vspaceid].vobj_offset; 
                 fprintf(fpout, "             <port direction = \"%s\" ",  port_direction[cp_port[port_id].direction]);
                 fprintf(fpout, " vspacename = \"%s\" ", vspace[cp_port[port_id].vspaceid].name);
@@ -353,10 +353,14 @@
                 task_id < (vspace[vspace_id].task_offset + vspace[vspace_id].tasks);
                 task_id++) {
-            unsigned int vobj_id = task[task_id].vobjlocid + vspace[vspace_id].vobj_offset; 
+            unsigned int stack_vobj_id = task[task_id].stack_vobjid + vspace[vspace_id].vobj_offset; 
+            unsigned int heap_vobj_id = task[task_id].heap_vobjid + vspace[vspace_id].vobj_offset; 
 
             fprintf(fpout, "            <task name = \"%s\" ", task[task_id].name);
             fprintf(fpout, "clusterid = \"%d\" ", task[task_id].clusterid);
             fprintf(fpout, "proclocid = \"%d\" ", task[task_id].proclocid);
-            fprintf(fpout, "stackname = \"%s\" ", vobj[vobj_id].name);
+            fprintf(fpout, "stackname = \"%s\" ", vobj[stack_vobj_id].name);
+            if (heap_vobj_id != -1) {
+                fprintf(fpout, "heapname = \"%s\" ", vobj[heap_vobj_id].name);
+            }
             fprintf(fpout, "startid = \"%d\" ", task[task_id].startid);
             fprintf(fpout, "usetty = \"%d\" ", task[task_id].use_tty);
Index: /soft/giet_vm/xml/xml_parser.c
===================================================================
--- /soft/giet_vm/xml/xml_parser.c	(revision 231)
+++ /soft/giet_vm/xml/xml_parser.c	(revision 232)
@@ -109,5 +109,7 @@
 unsigned int cluster_y            = 0;
 unsigned int cluster_x            = 0; 
-unsigned int nb_proc_max          = 0; // max number of processors per cluster 
+unsigned int nb_proc_max          = 0; // max number of processors per cluste 
+
+unsigned int nb_tasks_max         = 0; // max number of tasks (for all vspaces)
 unsigned int nb_timer_channel_max = 0; // max number of user timer
 unsigned int nb_dma_channel_max   = 0;
@@ -350,5 +352,5 @@
             printf("      stackid   = %d\n", index);
 #endif
-            task[task_index]->vobjlocid = index;
+            task[task_index]->stack_vobjid = index;
         }
         else {
@@ -363,4 +365,25 @@
         exit(1);
     }
+
+    ////////// get heap attribute
+    str = getStringValue(reader, "heapname", &ok);
+    if (ok) {
+        int index = getVobjLocId(vspace_index, str, vobj_loc_index);
+        if (index >= 0) {
+#if XML_PARSER_DEBUG
+            printf("      heapname = %s\n", str);
+            printf("      heapid   = %d\n", index);
+#endif
+            task[task_index]->heap_vobjid = index;
+        }
+        else {
+            printf("[XML ERROR] illegal or missing <heapname> for task (%d,%d)\n", vspace_index, task_loc_index);
+            exit(1);
+        }
+    }  
+    else {
+        task[task_index]->heap_vobjid = -1;
+    }
+
 
     ////////// get startid  attribute
@@ -715,4 +738,5 @@
     char * str;
     unsigned int ok;
+    unsigned int nb_task_vspace = 0;
 
     vobj_loc_index = 0;
@@ -782,4 +806,5 @@
         else if (strcmp(tag, "task") == 0) {
             taskNode(reader);
+            nb_task_vspace++;
         }
         else if (strcmp(tag, "#text")    == 0) { }
@@ -818,4 +843,5 @@
             }
 
+            nb_tasks_max += nb_task_vspace;
             vspace_index++;
             return;
@@ -1934,5 +1960,5 @@
             printf("      vobj_index   = %d\n", vobj_id);
 #endif
-            cp_port[i]->vobjlocid = vobj_id;
+            cp_port[i]->mwmr_vobjid = vobj_id;
 
             assert((vobj[ vspace[vspace_id]->vobj_offset + vobj_id]->type == VOBJ_TYPE_MWMR)
@@ -1990,4 +2016,5 @@
     def_int_write(fdout, "NB_IOCS"      , nb_ioc_channel);
     def_int_write(fdout, "NB_NICS"      , nb_nic_channel);
+    def_int_write(fdout, "NB_TASKS"     , nb_tasks_max);
 
     file_write(fdout, "\n");
