00001
00002
00003 #ifndef _CORE_MEMORY_PAGER_HPP
00004 #define _CORE_MEMORY_PAGER_HPP
00005
00006
00007 #include "src/memory/mmap.hpp"
00008 #include "src/arch/x86/interr.hpp"
00009 #include "src/arch/x86/except_c.hpp"
00010
00011 struct env_t;
00012
00013
00014 const uint32 PTE_PRESENT = 0x0001;
00015 const uint32 PTE_WRITEABLE = 0x0002;
00016 const uint32 PTE_RO = 0x0000;
00017 const uint32 PTE_USER = 0x0004;
00018 const uint32 PTE_ACCESSED = 0x0020;
00019 const uint32 PTE_DIRTY = 0x0040;
00020 const uint32 PTE_OS = 0x0e00;
00021 const uint32 PTE_MASK = 0x0fff;
00022
00023 const uint32 PTE_LAZY = 0x0200;
00024 const uint32 PTE_STACKGUARD = 0x0004;
00025 const uint32 PTE_SHMEM = 0x0400;
00026
00027
00028
00029 extern char CRT_STACK;
00030 extern uint32 CRT_STACK_SIZE;
00031
00032 extern int shmem_paging_pfh(struct env_t *en, uint32 virt, uint32 phys);
00033
00034 namespace Memory {
00035 namespace Pager {
00036
00037 extern uint32 lazy_enable;
00038 extern void *virtual_frame;
00039
00040
00041
00042
00043 class memtree
00044 {
00045 public:
00046 addr_t *page_directory;
00047 uint32 cr3;
00048
00049 mmap_t memory_map;
00050
00051 void init(addr_t *pgd, class Memory::Heap::heapbox *hp);
00052 void done();
00053
00054
00055 void pte_map (addr_t virt, uint32 value);
00056 uint32 pte_val (addr_t virt);
00057 void pte_umap (addr_t virt);
00058
00059
00060 void pte_lazy(addr_t virt, uint32 flags);
00061 int pte_alloc(addr_t virt, uint32 flags);
00062 };
00063 extern memtree kmem;
00064
00065 void init();
00066 int allocate_memtree(class memtree *mtree, bool supervisor, class Memory::Heap::heapbox *hp);
00067 void init_pf();
00068 int PageFaultHandler(struct Arch::x86::Interr::except2_t *code);
00069 int lazy_paging_pfh(struct env_t *en, uint32 virt, uint32 phys);
00070
00071
00072
00073
00074
00075 void frame_assign (addr_t physical);
00076 void frame_release();
00077
00078 void FrameAssign (void *frame, class IPC::Lock::lock_t *l, addr_t physical);
00079 void FrameRelease(class IPC::Lock::lock_t *l);
00080
00081
00082 #define invalidate(virt) do { \
00083 __asm__ __volatile__("invlpg (%%eax)" : :"a"(virt)); \
00084 } while (0)
00085
00086
00087 void cpypage(uint32 dest, uint32 src);
00088
00089 void memmove2(class memtree *d1, void *d2, class memtree *s1, void *s2, uint32 cnt);
00090
00091 }
00092 };
00093
00094 #endif