[Barrelfish-users] A question about init_page_tables in file Startup_arch.c

bill yaungjw at gmail.com
Thu Apr 21 11:09:11 CEST 2011


Hi

>From line 276 to line 285 in "file kernel/arch/x86_64/Startup_arch.c", the
function "init_page_tables" initializes the page
directories(init_pml4,init_pdpt,init_pdir) and page tables(init_ptable) as
the following:

    /* Page table setup */
    /* Initialize init page tables */
276    for(size_t i = 0; i < INIT_PDPT_SIZE; i++) {
277        paging_x86_64_clear_pdir(&init_pdpt[i]);
278        for(size_t j = 0; j < INIT_PDIR_SIZE; j++) {
279            paging_x86_64_clear_pdir(&init_pdir[i * PTABLE_SIZE + j]);
280            for(size_t k = 0; k < INIT_PTABLE_SIZE; k++) {
281                paging_x86_64_clear_ptable(
282                &init_ptable[i * PTABLE_SIZE * PTABLE_SIZE + j *
PTABLE_SIZE + k]);
283            }
284        }
285    }

The statement above call function "paging_x86_64_clear_pdir" and "
paging_x86_64_clear_ptable " to clear the page directories and page tables
separately. 
Function "paging_x86_64_clear_pdir" and " paging_x86_64_clear_ptable " in
file "kernel/include/target/x86_64/Paging_kernel_target.h " is as the
following

/**
 * \brief Clear page directory.
 *
 * Clears page directory pointed to by 'p'.
 *
 * \param p     Pointer to page directory to clear.
 */
static inline void paging_x86_64_clear_pdir(union x86_64_pdir_entry *
COUNT(X86_64_PTABLE_SIZE)
                                            NONNULL p)
{
    for (int i = 0; i < X86_64_PTABLE_SIZE; i++) {
        p[i].raw = X86_64_PTABLE_CLEAR;
    }
}

/**
 * \brief Clear page table.
 *
 * Clears page table pointed to by 'p'.
 *
 * \param p     Pointer to page table to clear.
 */
static inline void paging_x86_64_clear_ptable(union x86_64_ptable_entry *
COUNT(X86_64_PTABLE_SIZE)
                                              NONNULL p)
{
    for (int i = 0; i < X86_64_PTABLE_SIZE; i++) {
        p[i].raw = X86_64_PTABLE_CLEAR;
    }
}

In the body of this two functions we can find that what they do is to clear
a whole page pointed by 'p', the size of the page is
X86_64_PTABLE_SIZE*sizeof(p[i]). But during line 276 and line 285 in
function "init_page_tables" I think what the statement meant to do is to
just clear an entry of the page directories or page tables with the separate
function every time. Take the statement between line 280~283 for example,
this "for" loop can only initializes the memory space of 
init_ptable[i * PTABLE_SIZE * PTABLE_SIZE + j * PTABLE_SIZE +   0]-------->
init_ptable[i * PTABLE_SIZE * PTABLE_SIZE + j * PTABLE_SIZE +
INIT_PTABLE_SIZE-1+ X86_64_PTABLE_SIZE], 
but not all of the page tables, which I think should be the space of:
init_ptable[i * PTABLE_SIZE * PTABLE_SIZE * PTABLE_SIZE + j * PTABLE_SIZE *
PTABLE_SIZE +   0 * PTABLE_SIZE]--------> init_ptable[i * PTABLE_SIZE *
PTABLE_SIZE * PTABLE_SIZE + j * PTABLE_SIZE * PTABLE_SIZE +
(INIT_PTABLE_SIZE-1) * PTABLE_SIZE+ X86_64_PTABLE_SIZE].
So I think the statement between line 276 and 285 in function
"init_page_tables" should be as the following:
276    for(size_t i = 0; i < INIT_PDPT_SIZE; i++) {
277        paging_x86_64_clear_pdir(&init_pdpt[i * PTABLE_SIZE]);
278        for(size_t j = 0; j < INIT_PDIR_SIZE; j++) {
279            paging_x86_64_clear_pdir(&init_pdir[i * PTABLE_SIZE *
PTABLE_SIZE + j * PTABLE_SIZE]);
280            for(size_t k = 0; k < INIT_PTABLE_SIZE; k++) {
281                paging_x86_64_clear_ptable(
282                &init_ptable[i * PTABLE_SIZE * PTABLE_SIZE * PTABLE_SIZE
+ j * PTABLE_SIZE * PTABLE_SIZE + k * PTABLE_SIZE]);
283            }
284        }
285    }


Hope it makes sense!


Regards
Bill




More information about the Barrelfish-users mailing list