Ignore:
Timestamp:
Jun 18, 2017, 10:06:41 PM (7 years ago)
Author:
alain
Message:

Introduce syscalls.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/kernel/libk/bits.h

    r14 r23  
    7878
    7979/**********************************************************************************************
    80  * This macro returns the number of 32 bits words required to register size entries.
     80 * This macro returns the number of 32 bits words required to register <size> entries.
    8181 *********************************************************************************************/
    8282
    8383#define BITMAP_SIZE(size) ( ((size) & 31) ? (((size)>>5) + 1) : ((size)>>5) )
    84  
    85 /**********************************************************************************************
    86  * This macro declare a bitmap data structure. It is actually an array of uint32_t.
    87  * size is the total number of entries in the bitmap.
    88  *********************************************************************************************/
    89 
    90 #define BITMAP( name , size )     uint32_t name[BITMAP_SIZE(size)]
    9184
    9285typedef uint32_t    bitmap_t;
    9386
    94 /**********************************************************************************************
     87/*********************************************************************************************
     88 * This function reset all bits in a bitmap. (array ot 32 bits words).
     89 *********************************************************************************************
     90 * @ bitmap  : pointer on first word in the bitmap.
     91 * @ len     : number of bits to reset.
     92 ********************************************************************************************/
     93void bitmap_init( bitmap_t * bitmap,
     94                  uint32_t   len );
     95
     96/*********************************************************************************************
    9597 * This function set a specific bit in a bitmap.
    96  **********************************************************************************************
     98 *********************************************************************************************
    9799 * @ bitmap  : pointer on the bitmap
    98100 * @ index   : bit index in the bitmap
    99  *********************************************************************************************/
     101 ********************************************************************************************/
    100102extern inline void bitmap_set( bitmap_t * bitmap,
    101103                               uint32_t   index );
    102104
    103 /**********************************************************************************************
     105/*********************************************************************************************
    104106 * This function clear a specific bit in a bitmap.
    105  **********************************************************************************************
     107 *********************************************************************************************
    106108 * @ bitmap  : pointer on the bitmap
    107109 * @ index   : bit index in the bitmap
    108  *********************************************************************************************/
     110 ********************************************************************************************/
    109111extern inline void bitmap_clear( bitmap_t * bitmap,
    110112                                 uint32_t   index );
    111113
    112 /**********************************************************************************************
     114/*********************************************************************************************
    113115 * This function returns a specific bit in a bitmap.
    114  **********************************************************************************************
     116 *********************************************************************************************
    115117 * @ bitmap  : pointer on the bitmap
    116118 * @ index   : bit index in the bitmap
    117  * @ returns tru if bitmap[index] is set
    118  *********************************************************************************************/
     119 * @ returns true if bitmap[index] is set
     120 ********************************************************************************************/
    119121extern inline bool_t bitmap_state( bitmap_t * bitmap,
    120122                                   uint32_t   index );
    121123
    122 /**********************************************************************************************
     124/*********************************************************************************************
    123125 * This function set a range of bits in a bitmap : [index ... (index + len)[
    124  **********************************************************************************************
     126 *********************************************************************************************
    125127 * @ bitmap  : pointer on the bitmap
    126128 * @ index   : first bit index in the bitmap
    127129 * @ len     : number of bits to set
    128  *********************************************************************************************/
     130 ********************************************************************************************/
    129131extern void bitmap_set_range( bitmap_t * bitmap,
    130132                              uint32_t   index,
    131133                              uint32_t   len );
    132134
    133 /**********************************************************************************************
     135/*********************************************************************************************
    134136 * This function reset a range of bits in a bitmap : [index ... (index + len)[
    135  **********************************************************************************************
     137 *********************************************************************************************
    136138 * @ bitmap  : pointer on the bitmap
    137139 * @ index   : first bit index in the bitmap
    138140 * @ len     : number of bits to clear
    139  *********************************************************************************************/
     141 ********************************************************************************************/
    140142extern void bitmap_clear_range( bitmap_t * bitmap,
    141143                                uint32_t   index,
    142144                                uint32_t   len );
    143145
    144 /**********************************************************************************************
     146/*********************************************************************************************
    145147 * This function returns the index of first bit set in a bitmap, starting from index.
    146  **********************************************************************************************
     148 *********************************************************************************************
    147149 * @ bitmap  : pointer on the bitmap
    148150 * @ index   : first bit to analyse in the bitmap
    149151 * @ size    : number of bits to analyse in bitmap
    150152 * @ returns index if found / returns 0xFFFFFFFF if bit not found
    151  *********************************************************************************************/
     153 ********************************************************************************************/
    152154extern uint32_t bitmap_ffs2( bitmap_t * bitmap,
    153155                             uint32_t   index,
    154156                             uint32_t   size );
    155157
    156 /**********************************************************************************************
     158/*********************************************************************************************
    157159 * This function returns the index of first bit cleared in a bitmap, starting from index.
    158  **********************************************************************************************
     160 *********************************************************************************************
    159161 * @ bitmap  : pointer on the bitmap
    160162 * @ index   : first bit to analyse in the bitmap
    161163 * @ size    : number of bits to analyse in bitmap
    162164 * @ returns index if found / returns 0xFFFFFFFF if bit not found
    163  *********************************************************************************************/
     165 ********************************************************************************************/
    164166extern uint32_t bitmap_ffc2( bitmap_t * bitmap,
    165167                             uint32_t   index,
    166168                             uint32_t   size );
    167169
    168 /**********************************************************************************************
     170/*********************************************************************************************
    169171 * This function returns the index of first bit set in a bitmap, starting from bit 0.
    170  **********************************************************************************************
     172 *********************************************************************************************
    171173 * @ bitmap  : pointer on the bitmap
    172174 * @ size    : number of bits to analyse in bitmap
    173175 * @ returns index if found / returns 0xFFFFFFFF if bit not found
    174  *********************************************************************************************/
     176 ********************************************************************************************/
    175177extern uint32_t bitmap_ffs( bitmap_t * bitmap,
    176178                            uint32_t   size );
    177179
    178 /**********************************************************************************************
     180/*********************************************************************************************
    179181 * This function returns the index of first bit cleared in a bitmap, starting from bit 0.
    180  **********************************************************************************************
     182 *********************************************************************************************
    181183 * @ bitmap  : pointer on the bitmap
    182184 * @ size    : number of bits to alalyse in bitmap
    183185 * @ returns index if found / returns 0xFFFFFFFF if bit not found
    184  *********************************************************************************************/
     186 ********************************************************************************************/
    185187extern uint32_t bitmap_ffc( bitmap_t * bitmap,
    186188                            uint32_t   size );
    187189
    188 /**********************************************************************************************
     190/*********************************************************************************************
    189191 * This function returns the number of bits to code a non-zero unsigned integer value.
    190  **********************************************************************************************
     192 *********************************************************************************************
    191193 * @ val   : value to analyse
    192194 * @ returns number of bits
    193  *********************************************************************************************/
     195 ********************************************************************************************/
    194196static inline uint32_t bits_nr( uint32_t val )
    195197{
     
    202204}
    203205
    204 /**********************************************************************************************
     206/*********************************************************************************************
    205207 * This function takes an unsigned integer value as input argument, and returns another
    206208 * unsigned integer, that is the (base 2) logarithm of the smallest power of 2 contained
    207209 * in the input value.
    208  **********************************************************************************************
     210 *********************************************************************************************
    209211 * @ val   : value to analyse
    210212 * @ returns logarithm value
    211  *********************************************************************************************/
     213 ********************************************************************************************/
    212214static inline uint32_t bits_log2( uint32_t val )
    213215{
Note: See TracChangeset for help on using the changeset viewer.