Got mm0 to compile. A lot of issues expected.

This commit is contained in:
Bahadir Balban
2008-03-12 22:58:26 +00:00
parent cd79fa8f58
commit d718b8efd5
7 changed files with 59 additions and 75 deletions

View File

@@ -28,8 +28,18 @@
/* Private copy of a file */ /* Private copy of a file */
#define VMA_PRIVATE (1 << 6) #define VMA_PRIVATE (1 << 6)
/* Copy-on-write semantics */ /* Copy-on-write semantics */
#define VMA_COW (1 << 7) #define VMA_FIXED (1 << 7)
#define VMA_FIXED (1 << 8)
/* Defines the type of file. A device file? Regular file? One used at boot? */
enum VM_FILE_TYPE {
VM_FILE_DEVZERO = 0,
VM_FILE_REGULAR,
VM_FILE_BOOTFILE,
};
/* Defines the type of object. A file? Just a standalone object? */
#define VM_OBJ_SHADOW (1 << 8) /* Anonymous pages, swap_pager */
#define VM_OBJ_FILE (1 << 9) /* VFS file and device pages */
struct page { struct page {
int refcnt; /* Refcount */ int refcnt; /* Refcount */
@@ -80,18 +90,6 @@ struct vm_pager {
struct vm_pager_ops ops; /* The ops the pager does on area */ struct vm_pager_ops ops; /* The ops the pager does on area */
}; };
/* Defines the type of file. A device file? Regular file? One used at boot? */
enum VM_FILE_TYPE {
VM_FILE_DEVZERO = 0,
VM_FILE_REGULAR,
VM_FILE_BOOTFILE,
};
/* Defines the type of object. A file? Just a standalone object? */
enum VM_OBJ_TYPE {
VM_OBJ_SHADOW = 1, /* Anonymous pages, swap_pager */
VM_OBJ_FILE, /* VFS file and device pages */
};
/* TODO: /* TODO:
* How to distinguish different devices handling page faults ??? * How to distinguish different devices handling page faults ???
@@ -184,11 +182,13 @@ extern struct vm_pager bootfile_pager;
extern struct vm_pager devzero_pager; extern struct vm_pager devzero_pager;
extern struct vm_pager swap_pager; extern struct vm_pager swap_pager;
/* Pager initialisation, Special files */
/* vm object and vm file lists */ /* vm object and vm file lists */
extern struct list_head vm_object_list; extern struct list_head vm_object_list;
/* vm object link related functions */
struct vm_obj_link *vma_next_link(struct list_head *link,
struct list_head *head);
/* vm file and object initialisation */ /* vm file and object initialisation */
struct vm_file *vm_file_alloc_init(void); struct vm_file *vm_file_alloc_init(void);
struct vm_object *vm_object_alloc_init(void); struct vm_object *vm_object_alloc_init(void);

View File

@@ -168,12 +168,12 @@ int read_file_pages(struct vm_file *vmfile, unsigned long pfn_start,
for (int f_offset = pfn_start; f_offset < pfn_end; f_offset++) { for (int f_offset = pfn_start; f_offset < pfn_end; f_offset++) {
page = vmfile->vm_obj.pager->ops.page_in(&vmfile->vm_obj, page = vmfile->vm_obj.pager->ops.page_in(&vmfile->vm_obj,
f_offset); f_offset);
if (IS_ERR(page)) { if (IS_ERR(page)) {
printf("%s: %s:Could not read page %d " printf("%s: %s:Could not read page %d "
"from file with vnum: 0x%x\n", __TASKNAME__, "from file with vnum: 0x%x\n", __TASKNAME__,
__FUNCTION__, f_offset, vmfile->vnum); __FUNCTION__, f_offset, vmfile->vnum);
break; return (int)page;
} }
} }

View File

@@ -1,9 +1,9 @@
/* /*
* Initialise the memory structures. * Initialise the memory structures.
* *
* Copyright (C) 2007 Bahadir Balban * Copyright (C) 2007, 2008 Bahadir Balban
*/ */
#include <kdata.h> #include <init.h>
#include <memory.h> #include <memory.h>
#include <l4/macros.h> #include <l4/macros.h>
#include <l4/config.h> #include <l4/config.h>
@@ -78,7 +78,7 @@ void init_physmem(struct initdata *initdata, struct membank *membank)
/* Set use counts for pages the kernel has already used up */ /* Set use counts for pages the kernel has already used up */
if (!(pmap->map[BITWISE_GETWORD(i)] & BITWISE_GETBIT(i))) if (!(pmap->map[BITWISE_GETWORD(i)] & BITWISE_GETBIT(i)))
membank[0].page_array[i].count = -1; membank[0].page_array[i].refcnt = -1;
else /* Last page used +1 is free */ else /* Last page used +1 is free */
ffree_addr = (i + 1) * PAGE_SIZE; ffree_addr = (i + 1) * PAGE_SIZE;
} }

View File

@@ -329,6 +329,13 @@ pgtable_unmap:
#endif #endif
return 0; return 0;
} }
#endif
int do_munmap(void *vaddr, unsigned long size, struct tcb *task)
{
return 0;
}
int sys_munmap(l4id_t sender, void *vaddr, unsigned long size) int sys_munmap(l4id_t sender, void *vaddr, unsigned long size)
{ {
@@ -338,7 +345,6 @@ int sys_munmap(l4id_t sender, void *vaddr, unsigned long size)
return do_munmap(vaddr, size, task); return do_munmap(vaddr, size, task);
} }
#endif
struct vm_area *vma_new(unsigned long pfn_start, unsigned long npages, struct vm_area *vma_new(unsigned long pfn_start, unsigned long npages,
unsigned int flags, unsigned long file_offset, unsigned int flags, unsigned long file_offset,

View File

@@ -117,23 +117,6 @@ out_err:
return PTR_ERR(err); return PTR_ERR(err);
} }
/*
* This reads-in a range of pages from a file and populates the page cache
* just like a page fault, but its not in the page fault path.
*/
int read_file_pages(struct vm_file *f, unsigned long pfn_start,
unsigned long pfn_end)
{
struct page *p;
for (int f_offset = pfn_start; f_offset < pfn_end; f_offset++)
if (IS_ERR(p = f->vm_obj.pager->ops.page_in(&f->vm_obj,
f_offset)))
return (int)p;
return 0;
}
/* /*
* All non-mmapable char devices are handled by this. * All non-mmapable char devices are handled by this.
* VFS calls those devices to read their pages * VFS calls those devices to read their pages
@@ -236,7 +219,7 @@ int init_boot_files(struct initdata *initdata)
for (int i = 0; i < bd->total_images; i++) { for (int i = 0; i < bd->total_images; i++) {
img = &bd->images[i]; img = &bd->images[i];
boot_file = vm_file_alloc_init(); boot_file = vm_file_create();
boot_file->priv_data = img; boot_file->priv_data = img;
boot_file->length = img->phys_end - img->phys_start; boot_file->length = img->phys_end - img->phys_start;
boot_file->type = VM_FILE_BOOTFILE; boot_file->type = VM_FILE_BOOTFILE;
@@ -303,7 +286,7 @@ int init_devzero(void)
zpage->refcnt++; zpage->refcnt++;
/* Allocate and initialise devzero file */ /* Allocate and initialise devzero file */
devzero = vmfile_alloc_init(); devzero = vm_file_create();
devzero->vm_obj.npages = ~0; devzero->vm_obj.npages = ~0;
devzero->vm_obj.pager = &devzero_pager; devzero->vm_obj.pager = &devzero_pager;
devzero->vm_obj.flags = VM_OBJ_FILE; devzero->vm_obj.flags = VM_OBJ_FILE;

View File

@@ -365,13 +365,14 @@ void init_pm(struct initdata *initdata)
/* /*
* Makes the virtual to page translation for a given user task. * Makes the virtual to page translation for a given user task.
* If page is not mapped (either not faulted or swapped), returns 0.
*/ */
struct page *task_virt_to_page(struct tcb *t, unsigned long virtual) struct page *task_virt_to_page(struct tcb *t, unsigned long virtual)
{ {
unsigned long vaddr_vma_offset; unsigned long vma_offset;
unsigned long vaddr_file_offset; unsigned long file_offset;
struct vm_obj_link *vmo_link;
struct vm_area *vma; struct vm_area *vma;
struct vm_object *vmo;
struct page *page; struct page *page;
/* First find the vma that maps that virtual address */ /* First find the vma that maps that virtual address */
@@ -384,33 +385,31 @@ struct page *task_virt_to_page(struct tcb *t, unsigned long virtual)
/* Find the pfn offset of virtual address in this vma */ /* Find the pfn offset of virtual address in this vma */
BUG_ON(__pfn(virtual) < vma->pfn_start || BUG_ON(__pfn(virtual) < vma->pfn_start ||
__pfn(virtual) > vma->pfn_end); __pfn(virtual) > vma->pfn_end);
vaddr_vma_offset = __pfn(virtual) - vma->pfn_start; vma_offset = __pfn(virtual) - vma->pfn_start;
/* Find the file offset of virtual address in this file */ /* Find the file offset of virtual address in this file */
vmo = vma->owner; file_offset = vma->file_offset + vma_offset;
vaddr_file_offset = vma->f_offset + vaddr_vma_offset;
/* TODO: /* Get the initial link */
* Traverse vm objects to find the one with the page. BUG_ON(!(vmo_link = vma_next_link(&vma->vm_obj_list,
* Check each object's cache by find page. dont page in. &vma->vm_obj_list)));
*/
/* /* Is page there in the cache ??? */
* Find the page with the same file offset with that of the while(!(page = find_page(vmo_link->obj, file_offset))) {
* virtual address, that is, if the page is resident in memory. /* No, check the next link */
*/ if (!(vmo_link = vma_next_link(&vma->vm_obj_list,
list_for_each_entry(page, &vmfile->page_cache_list, list) &vma->vm_obj_list)));
if (vaddr_file_offset == page->f_offset) { /* Exhausted the objects. The page is not there. */
printf("%s: %s: Found page @ 0x%x, f_offset: 0x%x, with vma @ 0x%x, vmfile @ 0x%x\n", __TASKNAME__, return 0;
__FUNCTION__, (unsigned long)page, page->f_offset, vma, vma->owner); }
return page;
}
/* /* Found it */
* The page is not found, meaning that it is not mapped in printf("%s: %s: Found page @ 0x%x, file_offset: 0x%x, "
* yet, e.g. via a page fault. "with vma @ 0x%x, vm object @ 0x%x\n", __TASKNAME__,
*/ __FUNCTION__, (unsigned long)page, page->offset,
return 0; vma, vmo_link->obj);
return page;
} }
struct task_data { struct task_data {

View File

@@ -12,14 +12,10 @@
/* Global list of in-memory vm objects. */ /* Global list of in-memory vm objects. */
LIST_HEAD(vm_object_list); LIST_HEAD(vm_object_list);
/* Global list of in-memory vm files */
LIST_HEAD(vm_file_list);
struct vm_object *vm_object_init(struct vm_object *obj) struct vm_object *vm_object_init(struct vm_object *obj)
{ {
INIT_LIST_HEAD(&obj->list); INIT_LIST_HEAD(&obj->list);
INIT_LIST_HEAD(&obj->page_cache); INIT_LIST_HEAD(&obj->page_cache);
INIT_LIST_HEAD(&obj->shadows);
return obj; return obj;
} }
@@ -42,9 +38,9 @@ struct vm_file *vm_file_create(void)
if (!(f = kzalloc(sizeof(*f)))) if (!(f = kzalloc(sizeof(*f))))
return PTR_ERR(-ENOMEM); return PTR_ERR(-ENOMEM);
INIT_LIST_HEAD(&f->file_list); INIT_LIST_HEAD(&f->list);
vm_object_init(&f->vm_obj); vm_object_init(&f->vm_obj);
f->vm_obj->type = VM_OBJ_FILE; f->vm_obj.flags = VM_OBJ_FILE;
return f; return f;
} }
@@ -55,7 +51,7 @@ int vm_object_delete(struct vm_object *vmo)
struct vm_file *f; struct vm_file *f;
/* Release all pages */ /* Release all pages */
vmo->pager.ops->release_pages(vmo); vmo->pager->ops.release_pages(vmo);
/* Remove from global list */ /* Remove from global list */
list_del(&vmo->list); list_del(&vmo->list);
@@ -63,14 +59,14 @@ int vm_object_delete(struct vm_object *vmo)
/* Check any references */ /* Check any references */
BUG_ON(vmo->refcnt); BUG_ON(vmo->refcnt);
BUG_ON(!list_empty(&vmo->shadowers)); BUG_ON(!list_empty(&vmo->shadowers));
BUG_ON(!list_emtpy(&vmo->page_cache)); BUG_ON(!list_empty(&vmo->page_cache));
/* Obtain and free via the base object */ /* Obtain and free via the base object */
if (vmo->flags & VM_OBJ_FILE) { if (vmo->flags & VM_OBJ_FILE) {
f = vm_object_to_file(vmo); f = vm_object_to_file(vmo);
kfree(f); kfree(f);
} else if (vmo->flags & VM_OBJ_SHADOW) } else if (vmo->flags & VM_OBJ_SHADOW)
kfree(obj); kfree(vmo);
else BUG(); else BUG();
return 0; return 0;