aboutsummaryrefslogtreecommitdiff
path: root/src/core
diff options
context:
space:
mode:
Diffstat (limited to 'src/core')
-rw-r--r--src/core/scheduler.c11
-rw-r--r--src/core/scheduler.h2
2 files changed, 10 insertions, 3 deletions
diff --git a/src/core/scheduler.c b/src/core/scheduler.c
index 224c20d..59f3b9d 100644
--- a/src/core/scheduler.c
+++ b/src/core/scheduler.c
@@ -80,11 +80,16 @@ void clock(){
schedule(stack);
}
-void task_create(int *page_dir, void *task, int task_size, int stack_offset){
+void task_create(void *task, int task_size){
if(nproc<=MAX_PROC){
+ // Allocate at least 1 page and 1 page for the user stack
+ int allocated=1+task_size/4096+1;
+ int* page_dir=paging_allocate(allocated);
+
// Compute various addresses
void *entry_point=PAGING_ENTRY_POINT_VIRT;
- void *ustack=(void*)(PAGING_ENTRY_POINT_VIRT+stack_offset);
+ // User stack start at the end of last allocated page (since addresses are going down)
+ void *ustack=(void*)(PAGING_ENTRY_POINT_VIRT+allocated*4096);
// Load the task into memory
memcpy(task,PAGING_ENTRY_POINT_PHY(page_dir), task_size);
@@ -119,6 +124,8 @@ void task_create(int *page_dir, void *task, int task_size, int stack_offset){
p->page_dir=page_dir;
nproc++;
}
+ else
+ print("Could not create more task!");
}
void scheduler_start(){
diff --git a/src/core/scheduler.h b/src/core/scheduler.h
index 62d6561..3410ba1 100644
--- a/src/core/scheduler.h
+++ b/src/core/scheduler.h
@@ -47,7 +47,7 @@ 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);
+void task_create(void *task, int task_size);
/**
* Stack the scheduler starting by task with PID 0