MCPcopy Create free account
hub / github.com/F-Stack/f-stack / pmap_create_kernel_pagetable

Function pmap_create_kernel_pagetable

freebsd/mips/mips/pmap.c:431–488  ·  view source on GitHub ↗

* Bootstrap the system enough to run with virtual memory. This * assumes that the phys_avail array has been initialized. */

Source from the content-addressed store, hash-verified

429 * assumes that the phys_avail array has been initialized.
430 */
431static void
432pmap_create_kernel_pagetable(void)
433{
434 int i, j;
435 vm_offset_t ptaddr;
436 pt_entry_t *pte;
437#ifdef __mips_n64
438 pd_entry_t *pde;
439 vm_offset_t pdaddr;
440 int npt, npde;
441#endif
442
443 /*
444 * Allocate segment table for the kernel
445 */
446 kernel_segmap = (pd_entry_t *)pmap_steal_memory(PAGE_SIZE);
447
448 /*
449 * Allocate second level page tables for the kernel
450 */
451#ifdef __mips_n64
452 npde = howmany(NKPT, NPDEPG);
453 pdaddr = pmap_steal_memory(PAGE_SIZE * npde);
454#endif
455 nkpt = NKPT;
456 ptaddr = pmap_steal_memory(PAGE_SIZE * nkpt);
457
458 /*
459 * The R[4-7]?00 stores only one copy of the Global bit in the
460 * translation lookaside buffer for each 2 page entry. Thus invalid
461 * entrys must have the Global bit set so when Entry LO and Entry HI
462 * G bits are anded together they will produce a global bit to store
463 * in the tlb.
464 */
465 for (i = 0, pte = (pt_entry_t *)ptaddr; i < (nkpt * NPTEPG); i++, pte++)
466 *pte = PTE_G;
467
468#ifdef __mips_n64
469 for (i = 0, npt = nkpt; npt > 0; i++) {
470 kernel_segmap[i] = (pd_entry_t)(pdaddr + i * PAGE_SIZE);
471 pde = (pd_entry_t *)kernel_segmap[i];
472
473 for (j = 0; j < NPDEPG && npt > 0; j++, npt--)
474 pde[j] = (pd_entry_t)(ptaddr + (i * NPDEPG + j) * PAGE_SIZE);
475 }
476#else
477 for (i = 0, j = pmap_seg_index(VM_MIN_KERNEL_ADDRESS); i < nkpt; i++, j++)
478 kernel_segmap[j] = (pd_entry_t)(ptaddr + (i * PAGE_SIZE));
479#endif
480
481 PMAP_LOCK_INIT(kernel_pmap);
482 kernel_pmap->pm_segtab = kernel_segmap;
483 CPU_FILL(&kernel_pmap->pm_active);
484 TAILQ_INIT(&kernel_pmap->pm_pvchunk);
485 kernel_pmap->pm_asid[0].asid = PMAP_ASID_RESERVED;
486 kernel_pmap->pm_asid[0].gen = 0;
487 kernel_vm_end += nkpt * NPTEPG * PAGE_SIZE;
488}

Callers 1

pmap_bootstrapFunction · 0.85

Calls 1

pmap_steal_memoryFunction · 0.85

Tested by

no test coverage detected