Re: some quest about L4 concepts and marzipan
Espen Skoglund <[email protected]>
| Newsgroups | gmane.comp.micro-kernel.l4.l4ka.general |
|---|---|
| Message-ID | <[email protected]> |
The Sigma0_GetAny() function grabs arbitrary memory which is marked as
avaiable physical memory in sigma0. The Sigma0_GetPage() grabs memory
from a particular location. This might be special I/O memory or other
non-standard memory. Sigma0 will only hand out standard memory for
GetAny requests, but will hand out any memory if the location is
specified explicitly and it does not overlap with memory which has
already been reserved.
Here's a function that can be used in the rootserver to grab all
memory in the system (including device memory):
================================================================
static void graballmem (void)
{
L4_Word_t next_addr[sizeof (L4_Word_t) * 8 + 2];
L4_Word_t addr = 0, sz = sizeof (L4_Word_t) * 8 - 1;
L4_ThreadId_t s0 =
L4_GlobalId (L4_ThreadIdUserBase (L4_GetKernelInterface ()), 1);
// Ensure that loop below terminates when whole address space has
// been requested.
next_addr[sz+2] = ~0UL;
next_addr[sz+1] = 0;
// Explicitly request all memory (including device and other
// special memory) from sigma0 using as large page sizes as
// possible.
while (sz < sizeof (L4_Word_t) * 8)
{
if (L4_IsNilFpage (L4_Sigma0_GetPage (s0, L4_FpageLog2 (addr, sz)))
&& sz > 12)
{
next_addr[sz] = addr + (1 << sz);
sz--;
continue;
}
else
addr += (1 << sz);
while (addr == next_addr[sz + 1])
sz++;
}
}
================================================================
It attempts to request memory using as large page sizes as possible,
and decreses the page size if it fails to allocate a large page. It
also has the advantage that it remaps the current code and data using
as large page sizes as possible. That is, when the rootserver is
started it requests memory from sigma0 via the pagefault protocol.
However, this memory will be allocated using as small a page size as
possible. The function above re-allocates the memory using larger
page sizes.
eSk