Index: soft/giet_vm/giet_libs/stdio.c
===================================================================
--- soft/giet_vm/giet_libs/stdio.c	(revision 331)
+++ soft/giet_vm/giet_libs/stdio.c	(revision 345)
@@ -23,11 +23,7 @@
 
 ////////////////////////////////////////
-void giet_tty_printf( char* format, ...) 
-{
-    va_list args;
-    va_start( args, format );
-
-    int          ret;                    // return value from the syscalls 
-    unsigned int channel = 0xFFFFFFFF;   // channel defined in task context
+static int __printf( char* format, unsigned int channel, va_list* args) 
+{
+    int ret;                    // return value from the syscalls 
 
 printf_text:
@@ -56,6 +52,5 @@
     }
 
-    va_end( args );
-    return;
+    return 0;
 
 printf_arguments:
@@ -72,5 +67,5 @@
             case ('c'):             /* char conversion */
             {
-                int val = va_arg( args, int );
+                int val = va_arg( *args, int );
                 len = 1;
                 buf[0] = val;
@@ -80,5 +75,5 @@
             case ('d'):             /* 32 bits decimal signed integer */
             {
-                int val = va_arg( args, int );
+                int val = va_arg( *args, int );
                 if (val < 0) 
                 {
@@ -102,5 +97,5 @@
             case ('u'):             /* 32 bits decimal unsigned integer */
             {
-                unsigned int val = va_arg( args, unsigned int );
+                unsigned int val = va_arg( *args, unsigned int );
                 for(i = 0; i < 10; i++) 
                 {
@@ -114,5 +109,5 @@
             case ('x'):             /* 32 bits hexadecimal integer */
             {
-                unsigned int val = va_arg( args, unsigned int );
+                unsigned int val = va_arg( *args, unsigned int );
                 ret = sys_call(SYSCALL_TTY_WRITE,
                                (unsigned int)"0x",
@@ -132,5 +127,5 @@
             case ('l'):            /* 64 bits hexadecimal unsigned */
             {
-                unsigned long long val = va_arg( args, unsigned long long );
+                unsigned long long val = va_arg( *args, unsigned long long );
                 ret = sys_call(SYSCALL_TTY_WRITE,
                                (unsigned int)"0x",
@@ -150,5 +145,5 @@
             case ('s'):             /* string */
             {
-                char* str = va_arg( args, char* );
+                char* str = va_arg( *args, char* );
                 while (str[len]) 
                 {
@@ -173,7 +168,21 @@
 
 return_error:
-
+    return 1;
+} // end __printf()
+
+
+////////////////////////////////////////
+void giet_tty_printf( char* format, ...) 
+{
+    va_list args;
+
+    va_start( args, format );
+    int ret = __printf(format, 0xFFFFFFFF, &args);
     va_end( args );
-    giet_exit("error in giet_tty_printf()");
+
+    if (ret)
+    {
+        giet_exit("error in giet_tty_printf()");
+    }
 } // end giet_tty_printf()
 
@@ -182,9 +191,6 @@
 {
     va_list args;
-    va_start( args, format );
-
-    int          ret;     // return value from the syscalls 
-    unsigned int channel = 0;
-    unsigned int sr_save;
+    const int channel = 0;
+    volatile unsigned int sr_save;
 
     sys_call( SYSCALL_TTY_GET_LOCK,
@@ -193,28 +199,7 @@
               0, 0 );
 
-printf_text:
-
-    while (*format) 
-    {
-        unsigned int i;
-        for (i = 0 ; format[i] && (format[i] != '%') ; i++);
-        if (i) 
-        {
-            ret = sys_call(SYSCALL_TTY_WRITE, 
-                           (unsigned int)format,
-                           i, 
-                           channel,
-                           0);
-
-            if (ret != i) goto return_error;
-
-            format += i;
-        }
-        if (*format == '%') 
-        {
-            format++;
-            goto printf_arguments;
-        }
-    }
+    va_start( args, format );
+    int ret = __printf(format, channel, &args);
+    va_end( args );
 
     sys_call( SYSCALL_TTY_RELEASE_LOCK,
@@ -222,132 +207,10 @@
               (unsigned int)&sr_save,
               0, 0 );
- 
-    va_end( args );
-    return;
-
-printf_arguments:
-
-    {
-        char buf[20];
-        char * pbuf;
-        unsigned int len = 0;
-        static const char HexaTab[] = "0123456789ABCDEF";
-        unsigned int i;
-
-        switch (*format++) 
-        {
-            case ('c'):             /* char conversion */
-            {
-                int val = va_arg( args, int );
-                len = 1;
-                buf[0] = val;
-                pbuf = &buf[0];
-                break;
-            }
-            case ('d'):             /* 32 bits decimal signed integer */
-            {
-                int val = va_arg( args, int );
-                if (val < 0) 
-                {
-                    val = -val;
-                    ret = sys_call(SYSCALL_TTY_WRITE, 
-                                   (unsigned int)"-",
-                                   1,
-                                   channel,
-                                   0);
-                    if (ret != 1) goto return_error;
-                }
-                for(i = 0; i < 10; i++) 
-                {
-                    buf[9 - i] = HexaTab[val % 10];
-                    if (!(val /= 10)) break;
-                }
-                len =  i + 1;
-                pbuf = &buf[9 - i];
-                break;
-            }
-            case ('u'):             /* 32 bits decimal unsigned integer */
-            {
-                unsigned int val = va_arg( args, unsigned int );
-                for(i = 0; i < 10; i++) 
-                {
-                    buf[9 - i] = HexaTab[val % 10];
-                    if (!(val /= 10)) break;
-                }
-                len =  i + 1;
-                pbuf = &buf[9 - i];
-                break;
-            }
-            case ('x'):             /* 32 bits hexadecimal integer */
-            {
-                unsigned int val = va_arg( args, unsigned int );
-                ret = sys_call(SYSCALL_TTY_WRITE,
-                               (unsigned int)"0x",
-                               2,
-                               channel,
-                               0);
-                if (ret != 2) goto return_error;       
-                for(i = 0; i < 8; i++) 
-                {
-                    buf[7 - i] = HexaTab[val % 16];
-                    if (!(val /= 16))  break;
-                }
-                len =  i + 1;
-                pbuf = &buf[7 - i];
-                break;
-            }
-            case ('l'):            /* 64 bits hexadecimal unsigned */
-            {
-                unsigned long long val = va_arg( args, unsigned long long );
-                ret = sys_call(SYSCALL_TTY_WRITE,
-                               (unsigned int)"0x",
-                               2,
-                               channel,
-                               0);
-                if (ret != 2) goto return_error;
-                for(i = 0; i < 16; i++) 
-                {
-                    buf[15 - i] = HexaTab[val % 16];
-                    if (!(val /= 16))  break;
-                }
-                len =  i + 1;
-                pbuf = &buf[15 - i];
-                break;
-            }
-            case ('s'):             /* string */
-            {
-                char* str = va_arg( args, char* );
-                while (str[len]) 
-                {
-                    len++;
-                }
-                pbuf = str;
-                break;
-            }
-            default:
-                goto return_error;
-        }
-
-        ret = sys_call(SYSCALL_TTY_WRITE, 
-                       (unsigned int)pbuf,
-                       len,
-                       channel, 
-                       0);
-        if (ret != len)  goto return_error;
-        
-        goto printf_text;
-    }
-
-return_error:
-
-    sys_call( SYSCALL_TTY_RELEASE_LOCK,
-              channel,
-              (unsigned int)&sr_save,
-              0, 0 );
-
-    va_end( args );
-    giet_exit("error in giet_shr_printf()");
-}  // end giet_shr_printf()
-
+
+    if (ret)
+    {
+        giet_exit("error in giet_shr_printf()");
+    }
+} // end giet_shr_printf()
 
 /////////////////////////////////
