• Share
  • Email
  • Embed
  • Like
  • Save
  • Private Content
Lab2
 

Lab2

on

  • 362 views

MIT6.828 lab2

MIT6.828 lab2

Statistics

Views

Total Views
362
Views on SlideShare
362
Embed Views
0

Actions

Likes
0
Downloads
0
Comments
0

0 Embeds 0

No embeds

Accessibility

Upload Details

Uploaded via as Apple Keynote

Usage Rights

© All Rights Reserved

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Processing…
Post Comment
Edit your comment
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n

Lab2 Lab2 Presentation Transcript

  • Lab 2Memory Management
  • Virtual Memory When we into protected mode SelectorSoftware Segmentation Paging RAM Offset Virtual Linear Physical
  • Virtual Memory Hence the “selector” has no effect and the linear address always equals the offset of the virtual address. so, we only care .... Virtual Paging RAM address Linear Physical
  • Virtual Memory Linear address Physical address 10 10 12 20 12 Dir Table Offset PPN Offset 1023 20 12 20 12 PPN Offset 1023 0 PPN Offset Page Table 0 Page Directory
  • Virtual Memory 0x0fffffff 256MB Linear address 10 10 12 Extended Dir Table Offset Memory 0x00100000 BIOS ROM 4GB ROM VGA Display 0x000A0000 RAM 0x00000000
  • Virtual Memory Linear address 10 10 12 Dir Table Offset pde_t *kern_pgdir; kern_pgdir = (pde_t *)PDX(va) boot_alloc(PGSIZE); 1023 20 12 PPN Offset 0 Page Directory
  • Virtual Memory 0x0fffffff 256MB kern_pgdir 4KB Kernel ?KB 0x00100000 BIOS ROM ROM VGA Display 0x000A0000 RAM 0x00000000
  • Virtual Memory Linear address 10 10 12 Dir Table Offset 1023 20 12PDX(va) PTX(va) 20 12 PPN Offset 1023 0 PPN Offset Page Table 0 Page Directory
  • Virtual Memory Linear address 10 10 12 struct Page *pages; Dir Table Offset static struct Page *page_free_list; 1023 20 12PDX(va) PTX(va) 20 12 PPN Offset 1023 0 PPN Offset Page Table 0 Page Directory
  • Virtual Memory 0x0fffffff 256MBpage_init pages kern_pgdir 4KB kernel ?KB 0x00100000 BIOS 0x000A0000(IOPHYSMEM) page_free_list 0x00000000
  • Virtual Memorystruct Page *pages;pages = boot_alloc(npages * (sizeof(struct Page))); 0x0fffffff 256MBpage_init pages kern_pgdir 4KB kernel ?KB 0x00100000 BIOS 0x000A0000(IOPHYSMEM) page_free_list 0x00000000
  • Virtual Memory page_alloc : get page from page_free_list page_free : return page to page_free_list
  • Virtual MemoryLinear address10 10 12 Physical address 20 12 目前我們完Dir Table Offset PPN Offset 成了page的 1023 20 12 架構,但是 20 12 PPN Offset 1023 未提供一個 0 PPN Offset Page Table 外部使用的 0 Page Directory 介面
  • Interface pte_t * pgdir_walk(pde_t *pgdir, const void *va, int create) { // Fill this function in //return NULL; pde_t *dir = &pgdir[PDX(va)]; if(*dir & PTE_P){ pte_t *table = (pte_t*) KADDR(PTE_ADDR(*dir)); return &table[PTX(va)]; }else{ if(!create){ return NULL; } struct Page *page_tmp = page_alloc(ALLOC_ZERO); if(!page_tmp){ return NULL; }else{ pte_t *table = (pte_t*) page2kva(page_tmp); *dir = PADDR(table) | PTE_P | PTE_W | PTE_U; page_tmp->pp_ref = 1; return &table[PTX(va)]; } } }
  • Interface int page_insert(pde_t *pgdir, struct Page *pp, void *va, int perm) { // Fill this function in // return 0; if(!pp){ return -E_NO_MEM; } pte_t *page_entry = pgdir_walk(pgdir, va, 1); if(!page_entry){ return -E_NO_MEM; } pgdir[PDX(va)] |= perm; if(page2pa(pp) != PTE_ADDR(*page_entry)){ page_remove(pgdir, va); pp->pp_ref++; } *page_entry = page2pa(pp) | perm | PTE_P; return 0; }
  • Interface struct Page * page_lookup(pde_t *pgdir, void *va, pte_t **pte_store) { // Fill this function in // return NULL; *pte_store = pgdir_walk(pgdir, va, 0); if(!(*pte_store) || !(**pte_store & PTE_P)){ return NULL; }else{ return pa2page(PTE_ADDR(**pte_store)); } }
  • Interface void page_remove(pde_t *pgdir, void *va) { // Fill this function in pte_t *page_entry; struct Page *page = page_lookup(pgdir, va, &page_entry); if(page){ page_decref(page); } *page_entry = 0; tlb_invalidate(pgdir, va); }
  • Thanks a lot.