Index: trunk/kernel/libk/xlist.h
===================================================================
--- trunk/kernel/libk/xlist.h	(revision 690)
+++ trunk/kernel/libk/xlist.h	(revision 1)
@@ -1,6 +1,6 @@
 /*
- * xlist.h - Trans-cluster double circular linked list, using extended pointers.
- *
- * Author : Alain Greiner (2016,2017,2018,2019,2020)
+ * xlist.h - Double Circular Linked lists, using extended pointers.
+ *
+ * Author : Alain Greiner (2016)
  *
  * Copyright (c) UPMC Sorbonne Universites
@@ -22,11 +22,10 @@
  */
 
-#ifndef _XLIST_H_
-#define _XLIST_H_
-
-#include <kernel_config.h>
-#include <hal_kernel_types.h>
+#ifndef _ALMOS_XLIST_H_
+#define _ALMOS_XLIST_H_
+
+#include <almos_config.h>
+#include <hal_types.h>
 #include <hal_remote.h>
-#include <printk.h>
 
 /**** global variables ***/
@@ -50,5 +49,4 @@
 /***************************************************************************
  * This macro returns the offset (in bytes) of a field in a structure.
- ***************************************************************************
  * @ type   : structure type
  * @ member : name of the field
@@ -56,5 +54,5 @@
 
 #ifndef OFFSETOF
-#define OFFSETOF( type , member ) ((intptr_t) & ((type *)0)->member)
+#define OFFSETOF( type , member ) ((unsigned int) & ((type *)0)->member)
 #endif
 
@@ -62,5 +60,4 @@
  * This macro returns an extended pointer on the structure containing an
  * embedded xlist_entry_t field.
- ***************************************************************************
  * @ xlist_xp : extended pointer on the xlist_entry_t field
  * @ type     : type of the structure containing the xlist_entry_t
@@ -75,6 +72,4 @@
  * extended double linked list, identified by the extended pointer on 
  * the root xlist_entry_t.
- * WARNING : check list non empty before using this macro.
- ***************************************************************************
  * @ root_xp : extended pointer on the root xlist_entry_t 
  * @ type    : type of the linked elements
@@ -82,6 +77,6 @@
  **************************************************************************/
 
-#define XLIST_FIRST( root_xp , type , member )       \
-    ({ xptr_t __first = hal_remote_l64( root_xp );   \
+#define XLIST_FIRST_ELEMENT( root_xp , type , member ) \
+    ({ xptr_t __first = hal_remote_lwd( root_xp );     \
 	   XLIST_ELEMENT( __first , type , member ); })
 
@@ -90,6 +85,4 @@
  * extended double linked list, identified by the extended pointer on 
  * the root xlist_entry_t.
- * WARNING : check list non empty before using this macro.
- ***************************************************************************
  * @ root_xp : extended pointer on the root xlist_entry_t
  * @ type    : type of the linked elements
@@ -97,12 +90,11 @@
  **************************************************************************/
 
-#define XLIST_LAST( root_xp , type , member )                       \
-    ({ xptr_t __last = hal_remote_l64( root_xp + sizeof(xptr_t) );  \
+#define XLIST_LAST_ELEMENT( root_xp , type , member )  \
+    ({ xptr_t __last = hal_remote_lwd( root_xp + 8 );  \
 	   XLIST_ELEMENT( __last , type , member ); })
 
 /***************************************************************************
  * This macro traverses an extended double linked list in forward order.
- * WARNING : the iter variable should NOT be deleted during traversal. 
- ***************************************************************************
+ * The iter variable should NOT be deleted during traversal. 
  * @ root_xp  : extended pointer on the root xlist_entry_t
  * @ iter_xp  : current extended pointer on a xlist_entry_t
@@ -110,25 +102,23 @@
 
 #define XLIST_FOREACH( root_xp , iter_xp )    \
-for( (iter_xp) = hal_remote_l64( root_xp ) ;  \
+for( (iter_xp) = hal_remote_lwd( root_xp ) ;  \
      (iter_xp) != (root_xp) ;                 \
-     (iter_xp) = hal_remote_l64( iter_xp ) )
+     (iter_xp) = hal_remote_lwd( iter_xp ) )
 
 /***************************************************************************
  * This macro traverses an extended double linked list in backward order.
- * WARNING : the iter variable should NOT be deleted during traversal. 
- ***************************************************************************
+ * The iter variable should NOT be deleted during traversal. 
  * @ root_xp  : extended pointer on the root xlist_entry_t
  * @ iter_xp  : current extended pointer on a xlist_entry_t
  **************************************************************************/
 
-#define XLIST_FOREACH_BACKWARD( root_xp , iter_xp )              \
-for( (iter_xp) = hal_remote_l64( (root_xp) + sizeof(xptr_t) ) ;  \
-     (iter_xp) != (root_xp) ;                                    \
-     (iter_xp) = hal_remote_l64( (iter_xp) + sizeof(xptr_t) ) )
+#define XLIST_FOREACH_BACKWARD( root_xp , iter_xp )  \
+for( (iter_xp) = hal_remote_lwd( (root_xp) + 8 ) ;   \
+     (iter_xp) != (root_xp) ;                        \
+     (iter_xp) = hal_remote_lwd( (iter_xp) + 8 ) )
 
 /***************************************************************************
  * This function returns an extended pointer on the next xlist_entry_t,
  * from an extended pointer on a reference xlist_entry_t.
- ***************************************************************************
  * @ root    : extended pointer on the root xlist_entry_t
  * @ ref     : extended pointer on the reference xlist_entry_t
@@ -138,8 +128,8 @@
 {
     // get root->next
-    xptr_t root_next = (xptr_t)hal_remote_l64( root );
+    xptr_t root_next = (xptr_t)hal_remote_lwd( root );
 
     // get ref->next
-    xptr_t ref_next  = (xptr_t)hal_remote_l64( ref );
+    xptr_t ref_next  = (xptr_t)hal_remote_lwd( ref );
 
     // test if list is empty or ref is the last element  
@@ -151,5 +141,4 @@
 /***************************************************************************
  * This function returns an extended pointer on the previous xlist_entry_t.
- ***************************************************************************
  * @ root    : extended pointer on the root xlist_entry_t
  * @ ref     : extended pointer on the reference xlist_entry_t
@@ -159,8 +148,8 @@
 {
     // get root->next
-    xptr_t root_next = (xptr_t)hal_remote_l64( root );
+    xptr_t root_next = (xptr_t)hal_remote_lwd( root );
 
     // get ref->pred
-    xptr_t ref_pred  = (xptr_t)hal_remote_l64( ref + sizeof(xptr_t) );
+    xptr_t ref_pred  = (xptr_t)hal_remote_lwd( ref + 8 );
 
     // test if list is empty or ref is the first element  
@@ -173,11 +162,10 @@
  * This function initialises the root of an extended double linked list.
  * The root can be located in any cluster.
- ***************************************************************************
  * @ root_xp   :  extended pointer on the root xlist_entry_t
  **************************************************************************/
 static inline void xlist_root_init( xptr_t root_xp )
 {
-    hal_remote_s64( root_xp                  , root_xp );
-    hal_remote_s64( root_xp + sizeof(xptr_t) , root_xp );
+    hal_remote_swd(  root_xp   , root_xp );
+    hal_remote_swd(  root_xp+8 , root_xp );
 }
 
@@ -185,11 +173,10 @@
  * This function initialises an entry of an extended double linked list.
  * The entry can be located in any cluster.
- ***************************************************************************
  * @ entry_xp  : extended pointer on the xlist_entry_t
  **************************************************************************/
 static inline void xlist_entry_init( xptr_t entry_xp )
 {
-    hal_remote_s64( entry_xp                  , 0 );
-    hal_remote_s64( entry_xp + sizeof(xptr_t) , 0 );
+    hal_remote_swd(  entry_xp   , 0 );
+    hal_remote_swd(  entry_xp+8 , 0 );
 }
 
@@ -198,25 +185,24 @@
  * double linked list. Four extended pointers must be modified.
  * The lock protecting the list should have been previously taken.
- ***************************************************************************
- * @ root_xp   : extended pointer on the root xlist_entry_t
- * @ entry_xp  : extended pointer on the xlist_entry_t to be inserted
- **************************************************************************/
-static inline void xlist_add_first( xptr_t root_xp, 
-                                    xptr_t entry_xp )
+ * @ root   : extended pointer on the root xlist_entry_t
+ * @ entry  : extended pointer on the xlist_entry_t to be inserted
+ **************************************************************************/
+static inline void xlist_add_first( xptr_t root, 
+                                    xptr_t entry )
 {
     // get the extended pointer on the first element in list
-    xptr_t first_xp = hal_remote_l64( root_xp );
-
-    // update root_xp->next <= entry_xp
-    hal_remote_s64( root_xp , entry_xp );
-
-    // update entry_xp->next <= first_xp
-    hal_remote_s64( entry_xp , first_xp );
-
-    // update entry_xp->pred <= root_xp 
-    hal_remote_s64( entry_xp + sizeof(xptr_t) , root_xp );
+    xptr_t first = (xptr_t)hal_remote_lwd( root );
+
+    // update root.next <= entry
+    hal_remote_swd( root , (uint64_t)entry );
+
+    // update entry.next <= first
+    hal_remote_swd( entry , (uint64_t)first );
+
+    // entry.pred <= root 
+    hal_remote_swd( entry + 8 , (uint64_t)root );
     
-    // update first_xp->pred <= entry_xp
-    hal_remote_s64( first_xp + sizeof(xptr_t) , entry_xp );
+    // first.pred <= new
+    hal_remote_swd( first + 8 , (uint64_t)entry );
 }
 
@@ -225,25 +211,24 @@
  * double linked list.  Four extended pointers must be modified.
  * The lock protecting the list should have been previously taken.
- ***************************************************************************
- * @ root_xp   : extended pointer on the root xlist_entry_t
- * @ entry_xp  : extended pointer on the xlist_entry_t to be inserted
- **************************************************************************/
-static inline void xlist_add_last( xptr_t root_xp, 
-                                   xptr_t entry_xp )
+ * @ root   : extended pointer on the root xlist_entry_t
+ * @ entry  : extended pointer on the xlist_entry_t to be inserted
+ **************************************************************************/
+static inline void xlist_add_last( xptr_t root, 
+                                   xptr_t entry )
 {
     // get the extended pointer on the last element in list
-    xptr_t last_xp = hal_remote_l64( root_xp + sizeof(xptr_t) );
-
-    // update root_xp->pred <= entry_xp
-    hal_remote_s64( root_xp + sizeof(xptr_t) , entry_xp );
-
-    // update entry_xp->pred <= last_xp
-    hal_remote_s64( entry_xp + sizeof(xptr_t) , last_xp );
-
-    // update entry_xp->next <= root_xp
-    hal_remote_s64( entry_xp , root_xp );
+    xptr_t last = (xptr_t)hal_remote_lwd( root + 8 );
+
+    // update root.pred <= entry
+    hal_remote_swd( root + 8 , (uint64_t)entry );
+
+    // update entry.pred <= last
+    hal_remote_swd( entry + 8 , (uint64_t)last );
+
+    // entry.next <= root 
+    hal_remote_swd( entry , (uint64_t)root );
     
-    // update last_xp->next <= entry_xp
-    hal_remote_s64( last_xp , entry_xp );
+    // last.next <= entry
+    hal_remote_swd( last , (uint64_t)entry );
 }
 
@@ -251,19 +236,18 @@
 /***************************************************************************
  * This function returns true if the list is empty.
- ***************************************************************************
- * @ root_xp  : extended pointer on the root xlist_entry_t.
- **************************************************************************/
-static inline bool_t xlist_is_empty( xptr_t root_xp )
+ * @ root  : extended pointer on the root xlist_entry_t
+ **************************************************************************/
+static inline bool_t xlist_is_empty( xptr_t root )
 {
     // get the extended pointer root.next value
-    xptr_t next = (xptr_t)hal_remote_l64( root_xp );
-
-    return ( root_xp == next );
+    xptr_t next = (xptr_t)hal_remote_lwd( root );
+
+    return ( root == next );
 } 
 
 /***************************************************************************
  * This function removes an entry from an extended  double linked list.
+ * Two extended pointers must be modified.
  * The memory allocated to the removed entry is not released.
- ***************************************************************************
  * @ xp : extended pointer on the xlist_entry_t to be removed.
  **************************************************************************/
@@ -273,17 +257,15 @@
     xlist_entry_t entry;
     hal_remote_memcpy( XPTR( local_cxy , &entry ) ,
-                       xp , 
-                       sizeof(xlist_entry_t) );
+                                  xp , 
+                                  sizeof(xlist_entry_t) );
 
     xptr_t next = entry.next;
     xptr_t pred = entry.pred;
 
-    // update pred.next & next.pred
-    hal_remote_s64( pred , (uint64_t)next );
-    hal_remote_s64( next + sizeof(xptr_t) , (uint64_t)pred );
-
-    // reset the removed entry itself
-    hal_remote_s64( xp , XPTR_NULL );
-    hal_remote_s64( xp + sizeof(xptr_t) , XPTR_NULL );
+    // update pred.next <= next
+    hal_remote_swd( pred , (uint64_t)next );
+
+    // update next.pred <= pred
+    hal_remote_swd( next + 8 , (uint64_t)pred );
 }
 
@@ -292,7 +274,6 @@
  * Four extended pointers must be modified.
  * The memory allocated to the removed entry is not released.
- ***************************************************************************
- * @ old      : extended pointer on the xlist_entry_t to be removed.
- * @ new      : extended pointer on the xlist_entry_t to be inserted.
+ * @old      : extended pointer on the xlist_entry_t to be removed.
+ * @new      : extended pointer on the xlist_entry_t to be inserted.
  **************************************************************************/
 static inline void xlist_replace( xptr_t old,
@@ -309,80 +290,15 @@
 
 	// update new.next <= next
-    hal_remote_s64( new , (uint64_t)next );
+    hal_remote_swd( new , (uint64_t)next );
 
     // update new.pred <= pred
-    hal_remote_s64( new + sizeof(xptr_t) , (uint64_t)pred );
+    hal_remote_swd( new + 8 , (uint64_t)pred );
 
 	// update pred.next <= new
-    hal_remote_s64( pred , (uint64_t)new );
+    hal_remote_swd( pred , (uint64_t)new );
 
     // update next.pred <= new
-    hal_remote_s64( next + sizeof(xptr_t) , (uint64_t)new );
-}
-
-/***************************************************************************
- * This debug function displays <max> entries of an xlist.
- ***************************************************************************
- * @ root_xp : extended pointer on the root xlist_entry_t.
- * @ string  : list identifier displayed in header.
- * @ max     : max number of éléments to display.
- **************************************************************************/
-static inline void xlist_display( xptr_t  root_xp,
-                                  char  * string,
-                                  uint32_t max )
-{
-    cxy_t           root_cxy;
-    xlist_entry_t * root_ptr;
-
-    xptr_t          iter_xp;
-    cxy_t           iter_cxy;
-    xlist_entry_t * iter_ptr;
-
-    xptr_t          next_xp;
-    cxy_t           next_cxy;
-    xlist_entry_t * next_ptr;
-
-    xptr_t          pred_xp;
-    cxy_t           pred_cxy;
-    xlist_entry_t * pred_ptr;
-
-    uint32_t        index;
-
-    root_cxy = GET_CXY( root_xp );
-    root_ptr = GET_PTR( root_xp );
-
-    next_xp  = hal_remote_l64( XPTR( root_cxy , &root_ptr->next ) );
-    next_cxy = GET_CXY( next_xp );
-    next_ptr = GET_PTR( next_xp );
-
-    pred_xp  = hal_remote_l64( XPTR( root_cxy , &root_ptr->pred ) );
-    pred_cxy = GET_CXY( pred_xp );
-    pred_ptr = GET_PTR( pred_xp );
-
-    printk("\n***** root (%x,%x) / next (%x,%x) / pred (%x,%x) / %s *****\n",
-    root_cxy, root_ptr, next_cxy, next_ptr, pred_cxy, pred_ptr, string );
-
-    if( xlist_is_empty( root_xp ) == false )
-    {
-        for( iter_xp = hal_remote_l64( XPTR( root_cxy , &root_ptr->next) ) , index = 0 ;
-             (iter_xp != root_xp) && (index < max) ;
-             iter_xp = next_xp , index++ )
-        {
-            iter_cxy = GET_CXY( iter_xp );
-            iter_ptr = GET_PTR( iter_xp );
-
-            next_xp  = hal_remote_l64( XPTR( iter_cxy , &iter_ptr->next ) );
-            next_cxy = GET_CXY( next_xp );
-            next_ptr = GET_PTR( next_xp );
-
-            pred_xp  = hal_remote_l64( XPTR( iter_cxy , &iter_ptr->pred ) );
-            pred_cxy = GET_CXY( pred_xp );
-            pred_ptr = GET_PTR( pred_xp );
-
-            printk(" - %d : iter (%x,%x) / next (%x,%x) / pred (%x,%x)\n",
-            index, iter_cxy, iter_ptr, next_cxy, next_ptr, pred_cxy, pred_ptr );
-        }
-    }
-}  // end xlist_display()
-
-#endif	/* _XLIST_H_ */
+    hal_remote_swd( next + 8 , (uint64_t)new );
+}
+
+#endif	/* _ALMOS_LIST_H_ */
