Nucleus
Barry Page functions + User memory functions 73145c0 (3 years, 3 months ago)
diff --git a/memory/page.c b/memory/page.c
index 8dd07d8..6e1e67a 100644
--- a/memory/page.c
+++ b/memory/page.c
@@ -24,6 +24,7 @@ static void page_delete(Object *);
/* Page object type */
ObjectType pageType = {
+ .name = "PAGE",
.size = sizeof(Page),
.delete = page_delete,
};
@@ -49,16 +50,41 @@ compare_page_offset(void *object, void *data)
return 0;
}
+/* Create a new Page entry */
+Page *
+create_page(ObjectList *cache, page_t frame, off_t offset)
+{
+ Page *page = new(&pageType);
+ page->frame = frame;
+ page->offset = offset;
+ add(cache, page);
+ return page;
+}
+
/* Find a Page by offset in a cache */
Page *
find_page(ObjectList *cache, off_t offset)
{
- lock(cache);
struct FindData data = {
.offset = offset,
.result = NULL,
};
iterate(cache, compare_page_offset, &data);
- unlock(cache);
return data.result;
}
+
+/* Get the virtual address for the mapping of a page */
+void *
+map_page(Page *page)
+{
+ /*
+ * Since this x86 kernel doesn't keep all physical memory mapped into
+ * the virtual address space, the page needs to be mapped into memory.
+ * If more virtual memory was available (e.g. x86_64) all of physical
+ * memory could be mapped to an offset, and this function would just
+ * return (page->frame + offset);
+ */
+ set_page(0x7FF000, page->frame | PTE_PRESENT | PTE_WRITE);
+ flush_tlb(0x7FF000);
+ return (void *) 0x7FF000;
+}