aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/bringelle.c6
-rw-r--r--src/core/paging.c26
-rw-r--r--src/core/paging.h4
3 files changed, 14 insertions, 22 deletions
diff --git a/src/bringelle.c b/src/bringelle.c
index dbd83af..17d3845 100644
--- a/src/bringelle.c
+++ b/src/bringelle.c
@@ -8,7 +8,7 @@
extern void interrupt_enable();
void utask(){
- char *msg=(char*)4206592+300;
+ char *msg=(char*)PAGING_ENTRY_POINT_VIRT+300;
msg[0]='A';
msg[1]='\0';
while(1){
@@ -20,7 +20,7 @@ void utask(){
}
void utask2(){
- char *msg=(char*)4206592+300;
+ char *msg=(char*)PAGING_ENTRY_POINT_VIRT+300;
msg[0]='B';
msg[1]='\0';
while(1){
@@ -53,8 +53,6 @@ void bringelle(){
int* page_dir=paging_allocate(2);
task_create(page_dir, utask,100, 0xFF);
-
-
int* page_dir2=paging_allocate(2);
task_create(page_dir2, utask2,100,0xFF);
diff --git a/src/core/paging.c b/src/core/paging.c
index 0ab5498..cf5b951 100644
--- a/src/core/paging.c
+++ b/src/core/paging.c
@@ -89,42 +89,36 @@ char* paging_allocate_next_page(){
asm("hlt");
}
-// TODO: Take p into account
int *paging_allocate(int p){
- // ----- Allow kernel access during interruption
+ // ----- Populate kernel adresses (to be able to execute interrupts codes)
int *page_dir=(int*)paging_allocate_next_page();
int *k_page_table=(int*)paging_allocate_next_page();
- // Init page directory
+ // Kernel is located in the first 4Mb (page dir entry 0)
page_dir[0]=(int)k_page_table|3;
- // Init page table 0
int addr_offset=0;
for(int i=0;i<1024;i++){
k_page_table[i]=addr_offset;
- k_page_table[i]|=3; // Permission
+ k_page_table[i]|=3; // Permissions
addr_offset+=PAGING_PAGE_SIZE; // 4Ko pages
}
- // ----- Task table
- int *u_page_table=(int*)paging_allocate_next_page();
+ // ----- Populate task adresses
+ int *u_page_table=(int)paging_allocate_next_page();
page_dir[1]=(int)u_page_table|7;
- u_page_table[0]=(int)page_dir|7; // Virtual address is 1024*4096/4
- u_page_table[1]=(int)k_page_table|7;
- u_page_table[2]=(int)u_page_table|7;
-
- int dir_entry=1;
- int pt_entry=3;
+ int dir_entry=1; // Entry point is at 1024*4096=4194304 (page dir entry 1 and page table entry 0)
+ int pt_entry=0;
int p_current=max(1,p); // Allocate at least 1 page
while(p_current!=0){
+ u_page_table[pt_entry]=(int)paging_allocate_next_page()|7;
+ p_current--;
+ pt_entry++;
if(pt_entry%1024==0){
dir_entry++;
pt_entry=0;
u_page_table=(int*)paging_allocate_next_page();
page_dir[dir_entry]=(int)u_page_table|7;
}
- u_page_table[pt_entry]=(int)paging_allocate_next_page()|7;
- p_current--;
}
-
return page_dir;
}
diff --git a/src/core/paging.h b/src/core/paging.h
index 53014db..3ecb663 100644
--- a/src/core/paging.h
+++ b/src/core/paging.h
@@ -10,8 +10,8 @@
#define PAGING_MAX_DIR_ENTRY PAGING_MAX_PAGES/1024
#endif
#define PAGING_PADDR(entry) ((int*)(((u32)entry)&0xFFFFF000))
-#define PAGING_ENTRY_POINT_VIRT (1024*PAGING_PAGE_SIZE+3*PAGING_PAGE_SIZE)
-#define PAGING_ENTRY_POINT_PHY(page_dir) ((int*)(((int*)((((int*)page_dir)[1])&0xFFFFF000))[3]&0xFFFFF000))
+#define PAGING_ENTRY_POINT_VIRT (1024*PAGING_PAGE_SIZE)
+#define PAGING_ENTRY_POINT_PHY(page_dir) ((int*)(((int*)((((int*)page_dir)[1])&0xFFFFF000))[0]&0xFFFFF000))
/**
* Configure and enable paging