diff options
Diffstat (limited to 'src/core')
| -rw-r--r-- | src/core/paging.c | 20 | ||||
| -rw-r--r-- | src/core/paging.h | 13 | ||||
| -rw-r--r-- | src/core/scheduler.c | 14 | ||||
| -rw-r--r-- | src/core/scheduler.h | 3 |
4 files changed, 39 insertions, 11 deletions
diff --git a/src/core/paging.c b/src/core/paging.c index ab853bb..0ab5498 100644 --- a/src/core/paging.c +++ b/src/core/paging.c @@ -1,5 +1,6 @@ #include "paging.h" #include "libc/stdio.h" +#include "libc/math.h" /// Use a bitmap to keep track of allocated pages char pages_status[PAGING_MAX_PAGES/8]; @@ -105,11 +106,24 @@ int *paging_allocate(int p){ // ----- Task table int *u_page_table=(int*)paging_allocate_next_page(); - page_dir[1]=(int)u_page_table|7; // 1024*1024*4096/4 - u_page_table[0]=(int)page_dir|7; + 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; - u_page_table[3]=(int)paging_allocate_next_page()|7; + + int dir_entry=1; + int pt_entry=3; + int p_current=max(1,p); // Allocate at least 1 page + while(p_current!=0){ + 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 34eddff..53014db 100644 --- a/src/core/paging.h +++ b/src/core/paging.h @@ -13,30 +13,35 @@ #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)) - - - - /** * Configure and enable paging */ void paging_enable(); + /** * Allocate a new page and return its address */ char* paging_allocate_next_page(); + /** * Set usage status of a page */ void paging_set_usage(int addr,char state); + /** * Create a new page directory containing * p pages. */ int *paging_allocate(int p); + +/** + * Simple dump + */ void paging_dump(int min,int max); + /** * Handler of page fault */ void paging_page_fault(); + #endif
\ No newline at end of file diff --git a/src/core/scheduler.c b/src/core/scheduler.c index d046298..224c20d 100644 --- a/src/core/scheduler.c +++ b/src/core/scheduler.c @@ -123,19 +123,25 @@ void task_create(int *page_dir, void *task, int task_size, int stack_offset){ void scheduler_start(){ if(nproc>0){ + // Disable interrupt to not be interrupted asm("cli"); - scheduler_on=1; // Enable scheduling + // Enable scheduling + scheduler_on=1; + + // Save kernel stack state u32 *stack; asm("mov %%ebp, %0":"=r" (stack)); - TSS.esp0=(u32)stack+1; // Remove ebp (c call convention) + // Remove ebp from the (c call convention) and return address (call) + TSS.esp0=(u32)stack+2; asm("mov %%ss, %0": "=m" (TSS.ss0)); - current_id=1; + // Get first stack + current_id=0; PROC *p=&procs[current_id]; - // Ensure interrupts are activated and NT flag is clear p->regs.eflags|=0x200; p->regs.eflags&=0xffffbfff; + // Switch to user task asm( "push %0 \n\t" "jmp task_switch" diff --git a/src/core/scheduler.h b/src/core/scheduler.h index ecb9428..62d6561 100644 --- a/src/core/scheduler.h +++ b/src/core/scheduler.h @@ -35,6 +35,7 @@ extern u16 nproc; // Number of active tasks * Must be called at each clock interrupt */ void clock(); + /** * Called by clock() and schedule the next task * Stack is a pointer pointing to the gs register on the stack. @@ -42,10 +43,12 @@ void clock(); * order: gs,fs,es,ds,edi,esi,ebp,UNUSED,edx,ecx,ebx,eax,eip,cs,eflags,esp,ss */ void schedule(u32 *stack); + /** * Create a new task to be schedule */ void task_create(int *page_dir, void *task, int task_size, int stack_offset); + /** * Stack the scheduler starting by task with PID 0 */ |
