tech-kern archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

Re: Using emap for i386/amd64 early during boot



On Sun, Jun 20, 2010 at 07:45:32PM +0200, Jean-Yves Migeon wrote:
> For convenience, here's i386_cpu_switch_pmap:

I know that a lot of legacy code uses the preprocessor the way that you
have in i386_cpu_switch_pmap(), but I don't think that the preprocessor
should be used in that way any longer.  In my experience, code that uses
the preprocessor heavily is harder to read and to change and to test.
Why don't you let config(1) and ld(1) do the work that the preprocessor
does?  For example:

file switch_pmap_pae_xen.c      pae & xen

/*
 * Switches pmap for the current CPU. Hides the implementation
 * differences between the PAE and non-PAE cases.
 */
void
i386_cpu_switch_pmap(struct pmap *pmap)
{
        int i;
        int s = splvm(); /* just to be safe */
        struct cpu_info *ci = curcpu();
        paddr_t l3_pd = xpmap_ptom_masked(ci->ci_l3_pdirpa);
        /* don't update the kernel L3 slot */
        for (i = 0 ; i < PDP_SIZE - 1; i++) {
                xpq_queue_pte_update(l3_pd + i * sizeof(pd_entry_t),
                    xpmap_ptom(pmap->pm_pdirpa[i]) | PG_V);
        }
        splx(s);

        u_int gen = uvm_emap_gen_return();
        tlbflush();
        uvm_emap_update(gen);
}

file switch_pmap_pae.c          pae & !xen
/*
 * Switches pmap for the current CPU. Hides the implementation
 * differences between the PAE and non-PAE cases.
 */
void
i386_cpu_switch_pmap(struct pmap *pmap)
{
        int i;
        int s = splvm(); /* just to be safe */
        struct cpu_info *ci = curcpu();
        pd_entry_t *l3_pd = ci->ci_l3_pdir;
        for (i = 0 ; i < PDP_SIZE; i++) {
                l3_pd[i] = pmap->pm_pdirpa[i] | PG_V;
        }
        splx(s);

        u_int gen = uvm_emap_gen_return();
        tlbflush();
        uvm_emap_update(gen);
}

file switch_pmap.c              !pae

/*
 * Switches pmap for the current CPU. Hides the implementation
 * differences between the PAE and non-PAE cases.
 */
void
i386_cpu_switch_pmap(struct pmap *pmap)
{
        u_int gen = uvm_emap_gen_return();
        lcr3(pmap_pdirpa(pmap, 0));
        uvm_emap_update(gen);
}

-- 
David Young             OJC Technologies
dyoung%ojctech.com@localhost      Urbana, IL * (217) 278-3933


Home | Main Index | Thread Index | Old Index