pag.cpp
Code: Select all
#include "inc/page.h"
#include "inc/phmman.h"
#include "inc/video.h"
#include "inc/system.h"
/**********************/
dir_t *kdir=0,*cdir=0;
/**********************/
void load(uint *dir)
{ uint cr0;
asm volatile("mov %0, %%cr3":: "r"(dir));
asm volatile("mov %%cr0, %0": "=r"(cr0));
cr0 |= 0x80000000;
asm volatile("mov %0, %%cr0":: "r"(cr0));
}
void vmem::alloc(uint add,int pre,int rw,int us)
{
video v;
phmman phm; // phiscal memory manger
int page = add / 0x1000;
int table= page/ 1024;
if(kdir->tables[table].pre==1)
{
page_t *otable = (page_t *)kdir->tables[table].add;
if(otable->pages[page].pre == 1)
{return;
}else{
otable->pages[page].pre = pre;
otable->pages[page].r_w = rw;
otable->pages[page].u_s = us;
otable->pages[page].add = add;
}
}else{
page_t *ntable = (page_t *)phm.allocpg();
kdir->tables[table].pre = pre;
kdir->tables[table].r_w = rw;
kdir->tables[table].u_s = us;
kdir->tables[table].add = (uint)ntable;
ntable->pages[page].pre = pre;
ntable->pages[page].r_w = rw;
ntable->pages[page].u_s = us;
ntable->pages[page].add = add;
}
}
void vmem::install()
{
video v;
phmman phm;extern uint knl_end;
kdir = (dir_t *)phm.allocpg();
kdir = (dir_t *)phm.allocpg();
for(int i=0;i<= knl_end;i += 4096)
{
alloc(i,1,1,0);
}
//v.puthex("",(int)kdir);
load((uint*)kdir);
}
Code: Select all
#ifndef _H_virtual_memory_
#define _H_virtual_memory_
#include "phmem.h"
#include "system.h"
typedef struct page_entery
{
uint pre:1;
uint r_w:1;
uint u_s:1;
uint acc:1;
uint dir:1;
uint rev:7;
uint add:20;
}page_e;
typedef struct page_table
{
page_e pages[1024];
}page_t;
typedef struct dir_entry
{
uint pre:1;
uint r_w:1;
uint u_s:1;
uint acc:1;
uint dir:1;
uint rev:7;
uint add:20;
}dir_e;
typedef struct dir_table
{
dir_e tables[1024];
}dir_t;
class vmem
{
public:
void install();
void alloc(uint add,int pre,int rw,int us);
};
#endif
bochs error msg is
rip = 101dbd
cr0 = 0xe0000011 cr1=0x0 cr2=0xc0000022
cr3= 0x1efe000 cr4=0000000
>> add byte ptr ds:[eax+eax],cl:000c00
exception():3rd (13)exception with no resolution shutdown status is 00,reseting