Index: trunk/kernel/syscalls/sys_read.c
===================================================================
--- trunk/kernel/syscalls/sys_read.c	(revision 313)
+++ trunk/kernel/syscalls/sys_read.c	(revision 407)
@@ -33,9 +33,26 @@
 #include <process.h>
 
-/* TODO: user page(s) need to be locked  [AG] */
+// TODO: concurrent user page(s) munmap need to be handled [AG] 
+
+// instrumentation
+extern uint32_t enter_sys_read;
+extern uint32_t enter_devfs_move;
+extern uint32_t enter_txt_read;
+extern uint32_t enter_chdev_cmd;
+extern uint32_t enter_chdev_server;
+extern uint32_t enter_tty_cmd;
+extern uint32_t enter_tty_isr;
+extern uint32_t exit_tty_isr;
+extern uint32_t exit_tty_cmd;
+extern uint32_t exit_chdev_server;
+extern uint32_t exit_chdev_cmd;
+extern uint32_t exit_txt_read;
+extern uint32_t exit_devfs_move;
+extern uint32_t exit_sys_read;
+
 
 /////////////////////////////////
 int sys_read( uint32_t   file_id,
-              void     * buf,
+              void     * vaddr,
               uint32_t   count )
 {
@@ -43,4 +60,14 @@
     paddr_t      paddr;       // required for user space checking
 	xptr_t       file_xp;     // remote file extended pointer
+    uint32_t     nbytes;      // number of bytes actually read
+
+	uint32_t     tm_start;
+	uint32_t     tm_end;
+
+	tm_start = hal_get_cycles();
+
+#if CONFIG_READ_START
+enter_sys_read = tm_start;
+#endif
 
 	thread_t  *  this    = CURRENT_THREAD;
@@ -51,5 +78,5 @@
 	{
         printk("\n[ERROR] in %s : illegal file descriptor index = %d\n",
-               __FUNCTION__ , file_id );
+        __FUNCTION__ , file_id );
 		this->errno = EBADFD;
 		return -1;
@@ -57,10 +84,10 @@
 
     // check user buffer in user space
-    error = vmm_v2p_translate( false , buf , &paddr );
+    error = vmm_v2p_translate( false , vaddr , &paddr );
 
     if ( error )
     {
         printk("\n[ERROR] in %s : user buffer unmapped = %x\n",
-               __FUNCTION__ , (intptr_t)buf );
+        __FUNCTION__ , (intptr_t)vaddr );
 		this->errno = EINVAL;
 		return -1;
@@ -72,6 +99,6 @@
     if( file_xp == XPTR_NULL )
     {
-        printk("\n[ERROR] in %s : undefined file descriptor index = %d\n",
-               __FUNCTION__ , file_id );
+        printk("\n[ERROR] in %s : undefined file descriptor index = %d in process %x\n",
+        __FUNCTION__ , file_id , process->pid );
         this->errno = EBADFD;
         return -1;
@@ -86,20 +113,38 @@
     if( (attr & FD_ATTR_READ_ENABLE) == 0 )
 	{
-        printk("\n[ERROR] in %s : file %d not readable\n",
-               __FUNCTION__ , file_id );
+        printk("\n[ERROR] in %s : file %d not readable in process %x\n",
+        __FUNCTION__ , file_id , process->pid );
 		this->errno = EBADFD;
 		return -1;
 	}
     
-    // transfer count bytes directly from mapper to user buffer
-    error = vfs_user_move( true,               // to_buffer
-                           file_xp , 
-                           buf, 
-                           count );
+    // get file type
+    vfs_inode_type_t type = hal_remote_lw( XPTR( file_cxy , &file_ptr->type ) );
 
-    if( error )
+    // action depend on file type
+    if( type == INODE_TYPE_FILE )      // transfer count bytes from file mapper 
     {
-        printk("\n[ERROR] in %s cannot read data from file %d\n",
-               __FUNCTION__ , file_id );
+        nbytes = vfs_user_move( true,               // from mapper to buffer
+                                file_xp,
+                                vaddr, 
+                                count );
+    }
+    else if( type == INODE_TYPE_DEV )  // transfer count bytes from device
+    {
+        nbytes = devfs_user_move( true,             // from device to buffer
+                                  file_xp,
+                                  vaddr,
+                                  count );
+    }
+    else
+    {
+        nbytes = 0;
+        panic("file type %d non supported yet", type );
+    }
+
+    if( nbytes != count )
+    {
+        printk("\n[ERROR] in %s cannot read data from file %d in process %x\n",
+        __FUNCTION__ , file_id , process->pid );
         this->errno = error;
         return -1;
@@ -108,5 +153,47 @@
     hal_fence();
 
-	return 0;
+    tm_end = hal_get_cycles();
+
+#if CONFIG_READ_DEBUG
+exit_sys_read = tm_end;
+
+printk("\n@@@@@@@@@@@@ timing ro read character %c\n"
+" - enter_sys_read     = %d / delta %d\n"
+" - enter_devfs_move   = %d / delta %d\n"
+" - enter_txt_read     = %d / delta %d\n"
+" - enter_chdev_cmd    = %d / delta %d\n"
+" - enter_chdev_server = %d / delta %d\n"
+" - enter_tty_cmd      = %d / delta %d\n"
+" - enter_tty_isr      = %d / delta %d\n"
+" - exit_tty_isr       = %d / delta %d\n"
+" - exit_tty_cmd       = %d / delta %d\n"
+" - exit_chdev_server  = %d / delta %d\n"
+" - exit_chdev_cmd     = %d / delta %d\n"
+" - exit_txt_read      = %d / delta %d\n"
+" - exit_devfs_move    = %d / delta %d\n"
+" - exit_sys_read      = %d / delta %d\n",
+*((char *)(intptr_t)paddr) ,
+enter_sys_read     , 0 ,
+enter_devfs_move   , enter_devfs_move   - enter_sys_read     ,
+enter_txt_read     , enter_txt_read     - enter_devfs_move   ,
+enter_chdev_cmd    , enter_chdev_cmd    - enter_txt_read     ,
+enter_chdev_server , enter_chdev_server - enter_chdev_cmd    ,
+enter_tty_cmd      , enter_tty_cmd      - enter_chdev_server ,
+enter_tty_isr      , enter_tty_isr      - enter_tty_cmd      ,
+exit_tty_isr       , exit_tty_isr       - enter_tty_isr      ,
+exit_tty_cmd       , exit_tty_cmd       - exit_tty_isr       ,
+exit_chdev_server  , exit_chdev_server  - exit_tty_cmd       ,
+exit_chdev_cmd     , exit_chdev_cmd     - exit_chdev_server  ,
+exit_txt_read      , exit_txt_read      - exit_chdev_cmd     ,
+exit_devfs_move    , exit_devfs_move    - exit_txt_read      ,
+exit_sys_read      , exit_sys_read      - exit_devfs_move    );
+#endif
+
+syscall_dmsg("\n[DBG] %s : core[%x,%d] / thread %x / nbytes = %d / cycle %d\n"
+" first byte = %c / file_id = %d / cost = %d\n",
+__FUNCTION__ , local_cxy , this->core->lid , this->trdid , nbytes , tm_start ,
+*((char *)(intptr_t)paddr) , file_id , tm_end - tm_start );
+ 
+	return nbytes;
 
 }  // end sys_read()
