summaryrefslogtreecommitdiff
path: root/kernel/vmem.c
diff options
context:
space:
mode:
authorMichal Idziorek <m.i@gmx.at>2015-05-15 02:06:48 +0200
committerMichal Idziorek <m.i@gmx.at>2015-05-15 02:06:48 +0200
commit0365bbb5c58912fd24b3d33b90477d3de5d46d96 (patch)
tree0e171394f0e9f508b6ff1a7971ce61ddf8b2f989 /kernel/vmem.c
parentfb8a5f18835e8811dd1a98b8eb5352151fc2df31 (diff)
fixes and imporvements
Diffstat (limited to 'kernel/vmem.c')
-rw-r--r--kernel/vmem.c56
1 files changed, 31 insertions, 25 deletions
diff --git a/kernel/vmem.c b/kernel/vmem.c
index 402580a..491f486 100644
--- a/kernel/vmem.c
+++ b/kernel/vmem.c
@@ -224,25 +224,33 @@ void vmem_free_dir(pdirectory *dir)
x86_paging_enable();
}
+
+
//
-// vmem init and also copies all the shit for FORK
-// for now it allocates always 3 * 1024 * 4096 bytes at for the kernel
-// virtual / physical 0x0-0xc00000 (~12MB)
-// 2*1024*4096 for the loaded prog
-// virtual 0x8000000-0x8800000 (~8MB)
-// and 1*1024*4096 for the loaded programms stack
-// 0x8c00000-0x9000000 (~4MB)
+// vmem init / also copies all the shit over for FORK
+// if copy_dir==NULL creates brandnew dir
+// otherwise copies kernel pages and copies
+// programm pages procreates new programmspace
//
+// TODO: FIX
+// KERNEL SPACE HARDCODED TO 5 first PAGES
+// PROGRAMM SPACE HARDCODED TO 0x8000000+2 pages and 0x8c00000+1 pages
+//
+
pdirectory* vmem_new_space_dir(pdirectory *copy_dir)
{
x86_paging_disable();
-
- pdirectory* dir = (pdirectory*) pmmngr_alloc_block ();
- if (!dir)panic(FOOLOS_MODULE_NAME,"unable to alloc pdirectory");
+
+ //
+ pdirectory* dir = (pdirectory*) kballoc(1);
+
log(FOOLOS_MODULE_NAME,FOOLOS_LOG_INFO,"new pdirectory: 0x%X",dir);
+ if (!dir)panic(FOOLOS_MODULE_NAME,"unable to alloc pdirectory");
+ // first of all let's zero all the entries
for(int i=0;i<1024;i++)dir->m_entries [i]=0;
+ // identity mapping for first blocks
uint32_t phys_addr=0;
uint32_t virt_addr=0;
@@ -257,7 +265,7 @@ pdirectory* vmem_new_space_dir(pdirectory *copy_dir)
if(copy_dir==NULL)
{
// alloc space for our new table
- table = (ptable*) pmmngr_alloc_block ();
+ table = (ptable*) kballoc(1);
if (!table)panic(FOOLOS_MODULE_NAME,"unable to alloc table");
//! idenitity mapping
@@ -280,6 +288,7 @@ pdirectory* vmem_new_space_dir(pdirectory *copy_dir)
pd_entry_set_frame (entry, (physical_addr)table);
}
+
// otherwise simply take existing stuff from pdir 0
else
{
@@ -292,12 +301,13 @@ pdirectory* vmem_new_space_dir(pdirectory *copy_dir)
virt_addr+=1024*4096;
}
+
// programm space
virt_addr=0x8000000;
for(int j=0;j<2;j++)
{
- ptable* table = (ptable*) pmmngr_alloc_block ();
+ ptable* table = (ptable*) kballoc (1);
pd_entry *oldentry=NULL;
ptable* oldtable=NULL;
@@ -355,7 +365,7 @@ pdirectory* vmem_new_space_dir(pdirectory *copy_dir)
for(int j=0;j<1;j++)
{
- ptable* table = (ptable*) pmmngr_alloc_block ();
+ ptable* table = (ptable*) kballoc (1);
pd_entry *oldentry=NULL;
ptable* oldtable=NULL;
@@ -407,7 +417,14 @@ pdirectory* vmem_new_space_dir(pdirectory *copy_dir)
}
- if(copy_dir!=NULL)x86_paging_enable();
+ if(copy_dir==NULL) // this happens only on init
+ {
+ log(FOOLOS_MODULE_NAME,FOOLOS_LOG_INFO,"initializing virtual memory (paging)");
+ vmem_set_dir(dir);
+ }
+
+//while(1);
+ x86_paging_enable();
return dir;
}
@@ -417,14 +434,3 @@ void vmem_set_dir(pdirectory *dir)
x86_set_pdbr(dir);
}
-
-
-pdirectory* vmem_init(uint32_t mem_block_start)
-{
- log(FOOLOS_MODULE_NAME,FOOLOS_LOG_INFO,"init paging");
- pdirectory *dir=vmem_new_space_dir(0);
- vmem_set_dir(dir);
- x86_paging_enable();
- return dir;
-}
-