kernel/arm/pmap.c
/*
 * 4k page tables,  1k real PTEs,  3k virtual-page linked list and flags (packed
 * 12 bytes)
 */
4k page tables,  1k real PTEs,  3k virtual-page linked list and flags (packed
12 bytes)
4k page tables 1k real PTEs 3k virtual - page linked list and flags ( packed 12 bytes )
int PmapCacheEnter(vm_addr addr, vm_addr paddr) {
  uint32_t *pt, *phys_pt;
  int pde_idx, pte_idx;
  uint32_t pa_bits;
  struct Pageframe *pf;
  struct PmapVPTE *vpte;
  struct PmapVPTE *vpte_base;
  pa_bits = L2_TYPE_S | L2_AP(AP_U);
  pa_bits |= L2_AP(AP_W);
  pa_bits |= L2_NX;
  pa_bits |= L2_B | L2_C;
  pde_idx = (addr & L1_ADDR_BITS) >> L1_IDX_SHIFT;
  phys_pt = (uint32_t *)(root_pagedir[pde_idx] & L1_C_ADDR_MASK);
  pt = (uint32_t *)PmapPaToVa((vm_addr)phys_pt);
  pte_idx = (addr & L2_ADDR_BITS) >> L2_IDX_SHIFT;
  vpte_base = (struct PmapVPTE *)((uint8_t *)pt + VPTE_TABLE_OFFS);
  vpte = vpte_base + pte_idx;
  pf = &pageframe_table[paddr / PAGE_SIZE];
  vpte->flags = PROT_READ | PROT_WRITE;
  LIST_ADD_HEAD(&pf->pmap_pageframe.vpte_list, vpte, link);
  pt[pte_idx] = paddr | pa_bits;
  return 0;
}
int PmapCacheEnter ( vm_addr addr , vm_addr paddr ) { uint32_t * pt , * phys_pt ; int pde_idx , pte_idx ; uint32_t pa_bits ; struct Pageframe * pf ; struct PmapVPTE * vpte ; struct PmapVPTE * vpte_base ; pa_bits = L2_TYPE_S | L2_AP ( AP_U ) ; pa_bits |= L2_AP ( AP_W ) ; pa_bits |= L2_NX ; pa_bits |= L2_B | L2_C ; pde_idx = ( addr & L1_ADDR_BITS ) >> L1_IDX_SHIFT ; phys_pt = ( uint32_t * ) ( root_pagedir [ pde_idx ] & L1_C_ADDR_MASK ) ; pt = ( uint32_t * ) PmapPaToVa ( ( vm_addr ) phys_pt ) ; pte_idx = ( addr & L2_ADDR_BITS ) >> L2_IDX_SHIFT ; vpte_base = ( struct PmapVPTE * ) ( ( uint8_t * ) pt + VPTE_TABLE_OFFS ) ; vpte = vpte_base + pte_idx ; pf = & pageframe_table [ paddr / PAGE_SIZE ] ; vpte -> flags = PROT_READ | PROT_WRITE ; LIST_ADD_HEAD ( & pf -> pmap_pageframe . vpte_list , vpte , link ) ; pt [ pte_idx ] = paddr | pa_bits ; return 0 ; }
4k page tables,  1k real PTEs,  3k virtual-page linked list and flags (packed
 12 bytes)
4k page tables 1k real PTEs 3k virtual - page linked list and flags ( packed 12 bytes )
// TODO: Increment/Decrement pf reference cnt or not?