121 |
#define MAX_FPAGES (sizeof (l4_word_t) * 8 - 10) |
#define MAX_FPAGES (sizeof (l4_word_t) * 8 - 10) |
122 |
|
|
123 |
|
|
|
/* Find the first bit set. The least significant bit is 1. If no bit |
|
|
is set, return 0. FIXME: This can be optimized a lot, in an |
|
|
archtecture dependent way. Add to libl4, like __l4_msb(). */ |
|
|
static inline unsigned int |
|
|
wffs (l4_word_t nr) |
|
|
{ |
|
|
unsigned int bit = 0; |
|
|
|
|
|
while (bit < sizeof (l4_word_t) * 8) |
|
|
{ |
|
|
if ((1ULL << bit) & nr) |
|
|
{ |
|
|
return bit + 1; |
|
|
} |
|
|
bit++; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
124 |
/* Determine the fpages required to cover the bytes from START to END |
/* Determine the fpages required to cover the bytes from START to END |
125 |
(exclusive). START must be aligned to the minimal page size |
(exclusive). START must be aligned to the minimal page size |
126 |
supported by the system. Returns the number of fpages required to |
supported by the system. Returns the number of fpages required to |
145 |
nr_fpages = 0; |
nr_fpages = 0; |
146 |
while (start < end) |
while (start < end) |
147 |
{ |
{ |
148 |
|
unsigned int addr_align; |
149 |
|
unsigned int size_align; |
150 |
|
|
151 |
/* Each fpage must be self-aligned. */ |
/* Each fpage must be self-aligned. */ |
152 |
unsigned int fpsize_log2 = wffs (start | (end - start)) - 1; |
addr_align = l4_lsb (start) - 1; |
153 |
|
size_align = l4_msb (end - start) - 1; |
154 |
|
if (addr_align < size_align) |
155 |
|
size_align = addr_align; |
156 |
|
|
157 |
fpages[nr_fpages] |
fpages[nr_fpages] |
158 |
= l4_fpage_add_rights (l4_fpage_log2 (start, fpsize_log2), |
= l4_fpage_add_rights (l4_fpage_log2 (start, size_align), |
159 |
l4_fully_accessible); |
l4_fully_accessible); |
160 |
start += l4_size (fpages[nr_fpages]); |
start += l4_size (fpages[nr_fpages]); |
161 |
nr_fpages++; |
nr_fpages++; |