pg = NULL;
pmap_enter(pmap_t pmap, vaddr_t va, paddr_t pa, vm_prot_t prot, int flags){	int spl;	pt_entry_t *pte, template;	paddr_t old_pa;	pv_entry_t pv_e, pvl;	u_int users;	boolean_t kflush;	boolean_t wired = (flags & PMAP_WIRED) != 0;	struct vm_page *pg;	CHECK_PAGE_ALIGN(va, "pmap_entry - va");	CHECK_PAGE_ALIGN(pa, "pmap_entry - pa");#ifdef DEBUG	if (pmap_con_dbg & CD_ENT) {		if (pmap == kernel_pmap)			printf("(pmap_enter: %x) pmap kernel va %x pa %x\n", curproc, va, pa);		else			printf("(pmap_enter: %x) pmap %x va %x pa %x\n", curproc, pmap, va, pa);	}#endif	template = m88k_protection(pmap, prot);	PMAP_LOCK(pmap, spl);	users = pmap->pm_cpus;	/*	 * Expand pmap to include this pte.	 */	while ((pte = pmap_pte(pmap, va)) == PT_ENTRY_NULL) {		if (pmap == kernel_pmap) {			pmap_expand_kmap(va, VM_PROT_READ | VM_PROT_WRITE);		} else {			/*			 * Must unlock to expand the pmap.			 */			simple_unlock(&pmap->pm_lock);			pmap_expand(pmap, va);			simple_lock(&pmap->pm_lock);		}	}	/*	 * Special case if the physical page is already mapped at this address.	 */	old_pa = ptoa(PG_PFNUM(*pte));#ifdef DEBUG	if (pmap_con_dbg & CD_ENT)		printf("(pmap_enter) old_pa %x pte %x\n", old_pa, *pte);#endif	if (old_pa == pa) {		if (pmap == kernel_pmap) {			kflush = TRUE;		} else {			kflush = FALSE;		}		/*		 * May be changing its wired attributes or protection		 */		if (wired && !(pmap_pte_w(pte)))			pmap->pm_stats.wired_count++;		else if (!wired && pmap_pte_w(pte))			pmap->pm_stats.wired_count--;	} else { /* if (pa == old_pa) */		/*		 * Remove old mapping from the PV list if necessary.		 */		if (va >= phys_map_vaddr1 && va < phys_map_vaddr_end) {			flush_atc_entry(users, va, TRUE);		} else {			pmap_remove_pte(pmap, va, pte);		}		pg = PHYS_TO_VM_PAGE(pa);#ifdef DEBUG		if (pmap_con_dbg & CD_ENT) {			if (va >= phys_map_vaddr1 && va < phys_map_vaddr_end) {				printf("vaddr1 0x%x vaddr2 0x%x va 0x%x pa 0x%x managed %x\n",				    phys_map_vaddr1, phys_map_vaddr2, va, old_pa,				    pg != NULL ? 1 : 0);				printf("pte %x pfn %x valid %x\n",				    pte, PG_PFNUM(*pte), PDT_VALID(pte));			}		}#endif		if (pg != NULL) {#ifdef DEBUG			if (pmap_con_dbg & CD_ENT) {				if (va >= phys_map_vaddr1 && va < phys_map_vaddr_end) {					printf("va 0x%x and managed pa 0x%x\n", va, pa);				}			}#endif			/*			 *	Enter the mapping in the PV list for this			 *	physical page.			 */			pvl = pg_to_pvh(pg);			if (pvl->pv_pmap == PMAP_NULL) {				/*				 *	No mappings yet				 */				pvl->pv_va = va;				pvl->pv_pmap = pmap;				pvl->pv_next = PV_ENTRY_NULL;				pvl->pv_flags = 0;			} else {#ifdef DEBUG				/*				 * check that this mapping is not already there				 */				{					pv_entry_t e = pvl;					while (e != PV_ENTRY_NULL) {						if (e->pv_pmap == pmap && e->pv_va == va)							panic("pmap_enter: already in pv_list");						e = e->pv_next;					}				}#endif				/*				 * Add new pv_entry after header.				 */				pv_e = pool_get(&pvpool, PR_NOWAIT);				if (pv_e == NULL) {					if (flags & PMAP_CANFAIL) {						PMAP_UNLOCK(pmap, spl);						return (ENOMEM);					} else						panic("pmap_enter: "						    "pvpool exhausted");				}				pv_e->pv_va = va;				pv_e->pv_pmap = pmap;				pv_e->pv_next = pvl->pv_next;				pv_e->pv_flags = 0;				pvl->pv_next = pv_e;			}		}		/*		 * And count the mapping.		 */		pmap->pm_stats.resident_count++;		if (wired)			pmap->pm_stats.wired_count++;	} /* if (pa == old_pa) ... else */	template |= PG_V;	if (wired)		template |= PG_W;	if ((unsigned long)pa >= MAXPHYSMEM)		template |= CACHE_INH;	else		template |= CACHE_GLOBAL;	if (flags & VM_PROT_WRITE)		template |= PG_U | PG_M;	else if (flags & VM_PROT_ALL)		template |= PG_U;	/*	 * Invalidate pte temporarily to avoid being written	 * back the modified bit and/or the reference bit by	 * any other cpu.	 */	template |= invalidate_pte(pte) & (PG_U | PG_M);	*pte = template | pa;	flush_atc_entry(users, va, kflush);#ifdef DEBUG	if (pmap_con_dbg & CD_ENT)		printf("(pmap_enter) set pte to %x\n", *pte);#endif	/*	 * Cache attribute flags	 */	if (pg != NULL) {		pvl = pg_to_pvh(pg);		pvl->pv_flags |= (template & (PG_U | PG_M));	}	PMAP_UNLOCK(pmap, spl);	return 0;}