p2v -> P2V
This commit is contained in:
		
							parent
							
								
									7a77375d64
								
							
						
					
					
						commit
						a7c03bd914
					
				
					 5 changed files with 19 additions and 26 deletions
				
			
		
							
								
								
									
										2
									
								
								kalloc.c
									
										
									
									
									
								
							
							
						
						
									
										2
									
								
								kalloc.c
									
										
									
									
									
								
							| 
						 | 
				
			
			@ -61,7 +61,7 @@ kfree(char *v)
 | 
			
		|||
{
 | 
			
		||||
  struct run *r;
 | 
			
		||||
 | 
			
		||||
  if((uint)v % PGSIZE || v < end || v2p(v) >= PHYSTOP)
 | 
			
		||||
  if((uint)v % PGSIZE || v < end || V2P(v) >= PHYSTOP)
 | 
			
		||||
    panic("kfree");
 | 
			
		||||
 | 
			
		||||
  // Fill with junk to catch dangling refs.
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
							
								
								
									
										6
									
								
								main.c
									
										
									
									
									
								
							
							
						
						
									
										6
									
								
								main.c
									
										
									
									
									
								
							| 
						 | 
				
			
			@ -74,7 +74,7 @@ startothers(void)
 | 
			
		|||
  // Write entry code to unused memory at 0x7000.
 | 
			
		||||
  // The linker has placed the image of entryother.S in
 | 
			
		||||
  // _binary_entryother_start.
 | 
			
		||||
  code = p2v(0x7000);
 | 
			
		||||
  code = P2V(0x7000);
 | 
			
		||||
  memmove(code, _binary_entryother_start, (uint)_binary_entryother_size);
 | 
			
		||||
 | 
			
		||||
  for(c = cpus; c < cpus+ncpu; c++){
 | 
			
		||||
| 
						 | 
				
			
			@ -87,9 +87,9 @@ startothers(void)
 | 
			
		|||
    stack = kalloc();
 | 
			
		||||
    *(void**)(code-4) = stack + KSTACKSIZE;
 | 
			
		||||
    *(void**)(code-8) = mpenter;
 | 
			
		||||
    *(int**)(code-12) = (void *) v2p(entrypgdir);
 | 
			
		||||
    *(int**)(code-12) = (void *) V2P(entrypgdir);
 | 
			
		||||
 | 
			
		||||
    lapicstartap(c->id, v2p(code));
 | 
			
		||||
    lapicstartap(c->id, V2P(code));
 | 
			
		||||
 | 
			
		||||
    // wait for cpu to finish mpmain()
 | 
			
		||||
    while(c->started == 0)
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -8,13 +8,6 @@
 | 
			
		|||
#define KERNBASE 0x80000000         // First kernel virtual address
 | 
			
		||||
#define KERNLINK (KERNBASE+EXTMEM)  // Address where kernel is linked
 | 
			
		||||
 | 
			
		||||
#ifndef __ASSEMBLER__
 | 
			
		||||
 | 
			
		||||
static inline uint v2p(void *a) { return ((uint) (a))  - KERNBASE; }
 | 
			
		||||
static inline void *p2v(uint a) { return (void *) ((a) + KERNBASE); }
 | 
			
		||||
 | 
			
		||||
#endif
 | 
			
		||||
 | 
			
		||||
#define V2P(a) (((uint) (a)) - KERNBASE)
 | 
			
		||||
#define P2V(a) (((void *) (a)) + KERNBASE)
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
							
								
								
									
										4
									
								
								mp.c
									
										
									
									
									
								
							
							
						
						
									
										4
									
								
								mp.c
									
										
									
									
									
								
							| 
						 | 
				
			
			@ -33,7 +33,7 @@ mpsearch1(uint a, int len)
 | 
			
		|||
{
 | 
			
		||||
  uchar *e, *p, *addr;
 | 
			
		||||
 | 
			
		||||
  addr = p2v(a);
 | 
			
		||||
  addr = P2V(a);
 | 
			
		||||
  e = addr+len;
 | 
			
		||||
  for(p = addr; p < e; p += sizeof(struct mp))
 | 
			
		||||
    if(memcmp(p, "_MP_", 4) == 0 && sum(p, sizeof(struct mp)) == 0)
 | 
			
		||||
| 
						 | 
				
			
			@ -78,7 +78,7 @@ mpconfig(struct mp **pmp)
 | 
			
		|||
 | 
			
		||||
  if((mp = mpsearch()) == 0 || mp->physaddr == 0)
 | 
			
		||||
    return 0;
 | 
			
		||||
  conf = (struct mpconf*) p2v((uint) mp->physaddr);
 | 
			
		||||
  conf = (struct mpconf*) P2V((uint) mp->physaddr);
 | 
			
		||||
  if(memcmp(conf, "PCMP", 4) != 0)
 | 
			
		||||
    return 0;
 | 
			
		||||
  if(conf->version != 1 && conf->version != 4)
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
							
								
								
									
										26
									
								
								vm.c
									
										
									
									
									
								
							
							
						
						
									
										26
									
								
								vm.c
									
										
									
									
									
								
							| 
						 | 
				
			
			@ -49,7 +49,7 @@ walkpgdir(pde_t *pgdir, const void *va, int alloc)
 | 
			
		|||
 | 
			
		||||
  pde = &pgdir[PDX(va)];
 | 
			
		||||
  if(*pde & PTE_P){
 | 
			
		||||
    pgtab = (pte_t*)p2v(PTE_ADDR(*pde));
 | 
			
		||||
    pgtab = (pte_t*)P2V(PTE_ADDR(*pde));
 | 
			
		||||
  } else {
 | 
			
		||||
    if(!alloc || (pgtab = (pte_t*)kalloc()) == 0)
 | 
			
		||||
      return 0;
 | 
			
		||||
| 
						 | 
				
			
			@ -58,7 +58,7 @@ walkpgdir(pde_t *pgdir, const void *va, int alloc)
 | 
			
		|||
    // The permissions here are overly generous, but they can
 | 
			
		||||
    // be further restricted by the permissions in the page table 
 | 
			
		||||
    // entries, if necessary.
 | 
			
		||||
    *pde = v2p(pgtab) | PTE_P | PTE_W | PTE_U;
 | 
			
		||||
    *pde = V2P(pgtab) | PTE_P | PTE_W | PTE_U;
 | 
			
		||||
  }
 | 
			
		||||
  return &pgtab[PTX(va)];
 | 
			
		||||
}
 | 
			
		||||
| 
						 | 
				
			
			@ -133,7 +133,7 @@ setupkvm(void)
 | 
			
		|||
  if((pgdir = (pde_t*)kalloc()) == 0)
 | 
			
		||||
    return 0;
 | 
			
		||||
  memset(pgdir, 0, PGSIZE);
 | 
			
		||||
  if (p2v(PHYSTOP) > (void*)DEVSPACE)
 | 
			
		||||
  if (P2V(PHYSTOP) > (void*)DEVSPACE)
 | 
			
		||||
    panic("PHYSTOP too high");
 | 
			
		||||
  for(k = kmap; k < &kmap[NELEM(kmap)]; k++)
 | 
			
		||||
    if(mappages(pgdir, k->virt, k->phys_end - k->phys_start, 
 | 
			
		||||
| 
						 | 
				
			
			@ -156,7 +156,7 @@ kvmalloc(void)
 | 
			
		|||
void
 | 
			
		||||
switchkvm(void)
 | 
			
		||||
{
 | 
			
		||||
  lcr3(v2p(kpgdir));   // switch to the kernel page table
 | 
			
		||||
  lcr3(V2P(kpgdir));   // switch to the kernel page table
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// Switch TSS and h/w page table to correspond to process p.
 | 
			
		||||
| 
						 | 
				
			
			@ -171,7 +171,7 @@ switchuvm(struct proc *p)
 | 
			
		|||
  ltr(SEG_TSS << 3);
 | 
			
		||||
  if(p->pgdir == 0)
 | 
			
		||||
    panic("switchuvm: no pgdir");
 | 
			
		||||
  lcr3(v2p(p->pgdir));  // switch to process's address space
 | 
			
		||||
  lcr3(V2P(p->pgdir));  // switch to process's address space
 | 
			
		||||
  popcli();
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			@ -186,7 +186,7 @@ inituvm(pde_t *pgdir, char *init, uint sz)
 | 
			
		|||
    panic("inituvm: more than a page");
 | 
			
		||||
  mem = kalloc();
 | 
			
		||||
  memset(mem, 0, PGSIZE);
 | 
			
		||||
  mappages(pgdir, 0, PGSIZE, v2p(mem), PTE_W|PTE_U);
 | 
			
		||||
  mappages(pgdir, 0, PGSIZE, V2P(mem), PTE_W|PTE_U);
 | 
			
		||||
  memmove(mem, init, sz);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			@ -208,7 +208,7 @@ loaduvm(pde_t *pgdir, char *addr, struct inode *ip, uint offset, uint sz)
 | 
			
		|||
      n = sz - i;
 | 
			
		||||
    else
 | 
			
		||||
      n = PGSIZE;
 | 
			
		||||
    if(readi(ip, p2v(pa), offset+i, n) != n)
 | 
			
		||||
    if(readi(ip, P2V(pa), offset+i, n) != n)
 | 
			
		||||
      return -1;
 | 
			
		||||
  }
 | 
			
		||||
  return 0;
 | 
			
		||||
| 
						 | 
				
			
			@ -236,7 +236,7 @@ allocuvm(pde_t *pgdir, uint oldsz, uint newsz)
 | 
			
		|||
      return 0;
 | 
			
		||||
    }
 | 
			
		||||
    memset(mem, 0, PGSIZE);
 | 
			
		||||
    if(mappages(pgdir, (char*)a, PGSIZE, v2p(mem), PTE_W|PTE_U) < 0){
 | 
			
		||||
    if(mappages(pgdir, (char*)a, PGSIZE, V2P(mem), PTE_W|PTE_U) < 0){
 | 
			
		||||
      cprintf("allocuvm out of memory (2)\n");
 | 
			
		||||
      deallocuvm(pgdir, newsz, oldsz);
 | 
			
		||||
      kfree(mem);
 | 
			
		||||
| 
						 | 
				
			
			@ -268,7 +268,7 @@ deallocuvm(pde_t *pgdir, uint oldsz, uint newsz)
 | 
			
		|||
      pa = PTE_ADDR(*pte);
 | 
			
		||||
      if(pa == 0)
 | 
			
		||||
        panic("kfree");
 | 
			
		||||
      char *v = p2v(pa);
 | 
			
		||||
      char *v = P2V(pa);
 | 
			
		||||
      kfree(v);
 | 
			
		||||
      *pte = 0;
 | 
			
		||||
    }
 | 
			
		||||
| 
						 | 
				
			
			@ -288,7 +288,7 @@ freevm(pde_t *pgdir)
 | 
			
		|||
  deallocuvm(pgdir, KERNBASE, 0);
 | 
			
		||||
  for(i = 0; i < NPDENTRIES; i++){
 | 
			
		||||
    if(pgdir[i] & PTE_P){
 | 
			
		||||
      char * v = p2v(PTE_ADDR(pgdir[i]));
 | 
			
		||||
      char * v = P2V(PTE_ADDR(pgdir[i]));
 | 
			
		||||
      kfree(v);
 | 
			
		||||
    }
 | 
			
		||||
  }
 | 
			
		||||
| 
						 | 
				
			
			@ -329,8 +329,8 @@ copyuvm(pde_t *pgdir, uint sz)
 | 
			
		|||
    flags = PTE_FLAGS(*pte);
 | 
			
		||||
    if((mem = kalloc()) == 0)
 | 
			
		||||
      goto bad;
 | 
			
		||||
    memmove(mem, (char*)p2v(pa), PGSIZE);
 | 
			
		||||
    if(mappages(d, (void*)i, PGSIZE, v2p(mem), flags) < 0)
 | 
			
		||||
    memmove(mem, (char*)P2V(pa), PGSIZE);
 | 
			
		||||
    if(mappages(d, (void*)i, PGSIZE, V2P(mem), flags) < 0)
 | 
			
		||||
      goto bad;
 | 
			
		||||
  }
 | 
			
		||||
  return d;
 | 
			
		||||
| 
						 | 
				
			
			@ -352,7 +352,7 @@ uva2ka(pde_t *pgdir, char *uva)
 | 
			
		|||
    return 0;
 | 
			
		||||
  if((*pte & PTE_U) == 0)
 | 
			
		||||
    return 0;
 | 
			
		||||
  return (char*)p2v(PTE_ADDR(*pte));
 | 
			
		||||
  return (char*)P2V(PTE_ADDR(*pte));
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// Copy len bytes from p to user address va in page table pgdir.
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
	Add table
		
		Reference in a new issue