"MM.H" : #Include #Include #Include
"MM.H" : #Include #Include #Include
/*
* PAGING based Memory Management
* Memory management unit mm/mm.c
*/
#include "mm.h"
#include <stdlib.h>
#include <stdio.h>
/*
* init_pte - Initialize PTE entry
*/
int init_pte(uint32_t *pte,
int pre, // present
int fpn, // FPN
int drt, // dirty
int swp, // swap
int swptyp, // swap type
int swpoff) //swap offset
{
if (pre != 0) {
if (swp == 0) { // Non swap ~ page online
if (fpn == 0)
return -1; // Invalid setting
/*
* pte_set_swap - Set PTE entry for swapped page
* @pte : target page table entry (PTE)
* @swptyp : swap type
* @swpoff : swap offset
*/
int pte_set_swap(uint32_t *pte, int swptyp, int swpoff)
{
SETBIT(*pte, PAGING_PTE_PRESENT_MASK);
SETBIT(*pte, PAGING_PTE_SWAPPED_MASK);
return 0;
}
/*
* pte_set_swap - Set PTE entry for on-line page
* @pte : target page table entry (PTE)
* @fpn : frame page number (FPN)
*/
int pte_set_fpn(uint32_t *pte, int fpn)
{
SETBIT(*pte, PAGING_PTE_PRESENT_MASK);
CLRBIT(*pte, PAGING_PTE_SWAPPED_MASK);
return 0;
}
/*
* vmap_page_range - map a range of page at aligned address
*/
int vmap_page_range(struct pcb_t *caller, // process call
int addr, // start address which is
aligned to pagesz
int pgnum, // num of mapping page
struct framephy_struct *frames,// list of the mapped frames
struct vm_rg_struct *ret_rg)// return mapped region, the
real mapped fp
{ // no guarantee all given
pages are mapped
//uint32_t * pte = malloc(sizeof(uint32_t));
struct framephy_struct *fpit = malloc(sizeof(struct
framephy_struct));
//int fpn;
int pgit = 0;
int pgn = PAGING_PGN(addr);
fpit->fp_next = frames;
return 0;
}
/*
* alloc_pages_range - allocate req_pgnum of frame in ram
* @caller : caller
* @req_pgnum : request page num
* @frm_lst : frame list
*/
return 0;
}
/*
* vm_map_ram - do the mapping all vm are to ram storage device
* @caller : caller
* @astart : vm area start
* @aend : vm area end
* @mapstart : start mapping point
* @incpgnum : number of mapped page
* @ret_rg : returned region
*/
int vm_map_ram(struct pcb_t *caller, int astart, int aend, int
mapstart, int incpgnum, struct vm_rg_struct *ret_rg)
{
struct framephy_struct *frm_lst = NULL;
int ret_alloc;
return 0;
}
BYTE data;
MEMPHY_read(mpsrc, addrsrc, &data);
MEMPHY_write(mpdst, addrdst, data);
}
return 0;
}
/*
*Initialize a empty Memory Management instance
* @mm: self mm
* @caller: mm owner
*/
int init_mm(struct mm_struct *mm, struct pcb_t *caller)
{
struct vm_area_struct * vma = malloc(sizeof(struct vm_area_struct));
mm->pgd = malloc(PAGING_MAX_PGN*sizeof(uint32_t));
vma->vm_next = NULL;
vma->vm_mm = mm; /*point back to vma owner */
mm->mmap = vma;
return 0;
}
rgnode->rg_start = rg_start;
rgnode->rg_end = rg_end;
rgnode->rg_next = NULL;
return rgnode;
}
pnode->pgn = pgn;
pnode->pg_next = *plist;
*plist = pnode;
return 0;
}
printf("print_list_fp: ");
if (fp == NULL) {printf("NULL list\n"); return -1;}
printf("\n");
while (fp != NULL )
{
printf("fp[%d]\n",fp->fpn);
fp = fp->fp_next;
}
printf("\n");
return 0;
}
printf("print_list_rg: ");
if (rg == NULL) {printf("NULL list\n"); return -1;}
printf("\n");
while (rg != NULL)
{
printf("rg[%ld->%ld]\n",rg->rg_start, rg->rg_end);
rg = rg->rg_next;
}
printf("\n");
return 0;
}
printf("print_list_vma: ");
if (vma == NULL) {printf("NULL list\n"); return -1;}
printf("\n");
while (vma != NULL )
{
printf("va[%ld->%ld]\n",vma->vm_start, vma->vm_end);
vma = vma->vm_next;
}
printf("\n");
return 0;
}
if(end == -1){
pgn_start = 0;
struct vm_area_struct *cur_vma = get_vma_by_num(caller->mm, 0);
end = cur_vma->vm_end;
}
pgn_start = PAGING_PGN(start);
pgn_end = PAGING_PGN(end);
return 0;
}
//#endif
Code of mm.c