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

Function create_pagetables

freebsd/amd64/amd64/pmap.c:1610–1767  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1608}
1609
1610static void
1611create_pagetables(vm_paddr_t *firstaddr)
1612{
1613 int i, j, ndm1g, nkpdpe, nkdmpde;
1614 pd_entry_t *pd_p;
1615 pdp_entry_t *pdp_p;
1616 pml4_entry_t *p4_p;
1617 uint64_t DMPDkernphys;
1618
1619 /* Allocate page table pages for the direct map */
1620 ndmpdp = howmany(ptoa(Maxmem), NBPDP);
1621 if (ndmpdp < 4) /* Minimum 4GB of dirmap */
1622 ndmpdp = 4;
1623 ndmpdpphys = howmany(ndmpdp, NPDPEPG);
1624 if (ndmpdpphys > NDMPML4E) {
1625 /*
1626 * Each NDMPML4E allows 512 GB, so limit to that,
1627 * and then readjust ndmpdp and ndmpdpphys.
1628 */
1629 printf("NDMPML4E limits system to %d GB\n", NDMPML4E * 512);
1630 Maxmem = atop(NDMPML4E * NBPML4);
1631 ndmpdpphys = NDMPML4E;
1632 ndmpdp = NDMPML4E * NPDEPG;
1633 }
1634 DMPDPphys = allocpages(firstaddr, ndmpdpphys);
1635 ndm1g = 0;
1636 if ((amd_feature & AMDID_PAGE1GB) != 0) {
1637 /*
1638 * Calculate the number of 1G pages that will fully fit in
1639 * Maxmem.
1640 */
1641 ndm1g = ptoa(Maxmem) >> PDPSHIFT;
1642
1643 /*
1644 * Allocate 2M pages for the kernel. These will be used in
1645 * place of the first one or more 1G pages from ndm1g.
1646 */
1647 nkdmpde = howmany((vm_offset_t)(brwsection - KERNBASE), NBPDP);
1648 DMPDkernphys = allocpages(firstaddr, nkdmpde);
1649 }
1650 if (ndm1g < ndmpdp)
1651 DMPDphys = allocpages(firstaddr, ndmpdp - ndm1g);
1652 dmaplimit = (vm_paddr_t)ndmpdp << PDPSHIFT;
1653
1654 /* Allocate pages */
1655 KPML4phys = allocpages(firstaddr, 1);
1656 KPDPphys = allocpages(firstaddr, NKPML4E);
1657
1658 /*
1659 * Allocate the initial number of kernel page table pages required to
1660 * bootstrap. We defer this until after all memory-size dependent
1661 * allocations are done (e.g. direct map), so that we don't have to
1662 * build in too much slop in our estimate.
1663 *
1664 * Note that when NKPML4E > 1, we have an empty page underneath
1665 * all but the KPML4I'th one, so we need NKPML4E-1 extra (zeroed)
1666 * pages. (pmap_enter requires a PD page to exist for each KPML4E.)
1667 */

Callers 1

pmap_bootstrapFunction · 0.85

Calls 4

nkpt_initFunction · 0.85
bootaddr_rwxFunction · 0.85
allocpagesFunction · 0.70
printfFunction · 0.50

Tested by

no test coverage detected