Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • kernel/generic/src/adt/bitmap.c

    r4fe18151 r98000fb  
    3232/**
    3333 * @file
    34  * @brief Implementation of bitmap ADT.
     34 * @brief       Implementation of bitmap ADT.
    3535 *
    3636 * This file implements bitmap ADT and provides functions for
     
    3939
    4040#include <adt/bitmap.h>
    41 #include <typedefs.h>
     41#include <arch/types.h>
    4242#include <align.h>
    4343#include <debug.h>
     
    5151 * No portion of the bitmap is set or cleared by this function.
    5252 *
    53  * @param bitmap        Bitmap structure.
    54  * @param map           Address of the memory used to hold the map.
    55  * @param bits          Number of bits stored in bitmap.
     53 * @param bitmap Bitmap structure.
     54 * @param map Address of the memory used to hold the map.
     55 * @param bits Number of bits stored in bitmap.
    5656 */
    5757void bitmap_initialize(bitmap_t *bitmap, uint8_t *map, size_t bits)
     
    6363/** Set range of bits.
    6464 *
    65  * @param bitmap        Bitmap structure.
    66  * @param start         Starting bit.
    67  * @param bits          Number of bits to set.
     65 * @param bitmap Bitmap structure.
     66 * @param start Starting bit.
     67 * @param bits Number of bits to set.
    6868 */
    6969void bitmap_set_range(bitmap_t *bitmap, size_t start, size_t bits)
     
    7171        size_t i = 0;
    7272        size_t aligned_start;
    73         size_t lub;     /* leading unaligned bits */
    74         size_t amb;     /* aligned middle bits */
    75         size_t tab;     /* trailing aligned bits */
     73        size_t lub;             /* leading unaligned bits */
     74        size_t amb;             /* aligned middle bits */
     75        size_t tab;             /* trailing aligned bits */
    7676       
    7777        ASSERT(start + bits <= bitmap->bits);
     
    8282        tab = amb % 8;
    8383       
    84         if (!bits)
    85                 return;
    86 
    87         if (start + bits < aligned_start) {
    88                 /* Set bits in the middle of byte. */
    89                 bitmap->map[start / 8] |= ((1 << lub) - 1) << (start & 7);
    90                 return;
     84        if ( start + bits < aligned_start ) {
     85            /*
     86            * Set bits in the middle of byte
     87            */
     88            bitmap->map[start / 8] |= ((1 << lub)-1) << (start&7);
     89            return;
    9190        }
    9291       
    9392        if (lub) {
    94                 /* Make sure to set any leading unaligned bits. */
     93                /*
     94                 * Make sure to set any leading unaligned bits.
     95                 */
    9596                bitmap->map[start / 8] |= ~((1 << (8 - lub)) - 1);
    9697        }
    9798        for (i = 0; i < amb / 8; i++) {
    98                 /* The middle bits can be set byte by byte. */
     99                /*
     100                 * The middle bits can be set byte by byte.
     101                 */
    99102                bitmap->map[aligned_start / 8 + i] = ALL_ONES;
    100103        }
    101104        if (tab) {
    102                 /* Make sure to set any trailing aligned bits. */
     105                /*
     106                 * Make sure to set any trailing aligned bits.
     107                 */
    103108                bitmap->map[aligned_start / 8 + i] |= (1 << tab) - 1;
    104109        }
     
    108113/** Clear range of bits.
    109114 *
    110  * @param bitmap        Bitmap structure.
    111  * @param start         Starting bit.
    112  * @param bits          Number of bits to clear.
     115 * @param bitmap Bitmap structure.
     116 * @param start Starting bit.
     117 * @param bits Number of bits to clear.
    113118 */
    114119void bitmap_clear_range(bitmap_t *bitmap, size_t start, size_t bits)
     
    116121        size_t i = 0;
    117122        size_t aligned_start;
    118         size_t lub;     /* leading unaligned bits */
    119         size_t amb;     /* aligned middle bits */
    120         size_t tab;     /* trailing aligned bits */
     123        size_t lub;             /* leading unaligned bits */
     124        size_t amb;             /* aligned middle bits */
     125        size_t tab;             /* trailing aligned bits */
    121126       
    122127        ASSERT(start + bits <= bitmap->bits);
     
    127132        tab = amb % 8;
    128133
    129         if (!bits)
    130                 return;
    131 
    132         if (start + bits < aligned_start) {
    133                 /* Set bits in the middle of byte */
    134                 bitmap->map[start / 8] &= ~(((1 << lub) - 1) << (start & 7));
    135                 return;
     134        if ( start + bits < aligned_start )
     135        {
     136            /*
     137            * Set bits in the middle of byte
     138            */
     139            bitmap->map[start / 8] &= ~(((1 << lub)-1) << (start&7));
     140            return;
    136141        }
    137142
     143
    138144        if (lub) {
    139                 /* Make sure to clear any leading unaligned bits. */
     145                /*
     146                 * Make sure to clear any leading unaligned bits.
     147                 */
    140148                bitmap->map[start / 8] &= (1 << (8 - lub)) - 1;
    141149        }
    142150        for (i = 0; i < amb / 8; i++) {
    143                 /* The middle bits can be cleared byte by byte. */
     151                /*
     152                 * The middle bits can be cleared byte by byte.
     153                 */
    144154                bitmap->map[aligned_start / 8 + i] = ALL_ZEROES;
    145155        }
    146156        if (tab) {
    147                 /* Make sure to clear any trailing aligned bits. */
     157                /*
     158                 * Make sure to clear any trailing aligned bits.
     159                 */
    148160                bitmap->map[aligned_start / 8 + i] &= ~((1 << tab) - 1);
    149161        }
     
    153165/** Copy portion of one bitmap into another bitmap.
    154166 *
    155  * @param dst           Destination bitmap.
    156  * @param src           Source bitmap.
    157  * @param bits          Number of bits to copy.
     167 * @param dst Destination bitmap.
     168 * @param src Source bitmap.
     169 * @param bits Number of bits to copy.
    158170 */
    159171void bitmap_copy(bitmap_t *dst, bitmap_t *src, size_t bits)
Note: See TracChangeset for help on using the changeset viewer.