// vmm.c // Author: Josh Holtrop // Date: 09/30/03 // Rewritten from scratch: 12/23/03 void vmm_init() { dword *pageTables = (dword *)0xC0104000; //this is the location of the page directory pageTables[0x3FF] = 0x104000|0x03; //the last page directory entry points to the page directory itself if (videoMode) //we are in a graphical mode { dword vidPages = video_mode.XResolution * video_mode.YResolution * (video_mode.BitsPerPixel >> 3); if (vidPages % 4096) vidPages = (vidPages >> 12) + 1; else vidPages = (vidPages >> 12); vmm_mapn(0xF0000000, video_mode.PhysBasePtr, vidPages); } } void vmm_map1(dword virt, dword physical) { dword pde = virt >> 22; dword pte = (virt & 0x003FF000) >> 12; dword *pageTables = (dword *)0xC0104000; //this is the location of the page directory if (!(pageTables[pde] & 0x01)) //the page directory entry does not exist, we must allocate a page for it { dword *newpagetable = mm_palloc(); pageTables[pde] = ((dword)newpagetable) | 0x03; invlpg(virt); dword *newpteptr = (dword *)(0xFFC00000 | (pde << 12)); //points to first dword of newly allocated page table int a; for (a = 0; a < 1024; a++) { newpteptr[a] = 0; } } dword *pteptr = (dword *)(0xFFC00000 | (pde << 12) | (pte << 2)); *pteptr = physical | 0x03; } void vmm_mapn(dword virt, dword physical, dword n) { for (; n > 0; n--) { vmm_map1(virt, physical); virt += 4096; physical += 4096; } } void *malloc(dword bytes) { } int free(void *ptr) { }