Improve task stack management
This commit is contained in:
parent
dcadede2d4
commit
3259715b0e
3 changed files with 17 additions and 9 deletions
|
@ -5,6 +5,8 @@
|
|||
#include "core/paging.h"
|
||||
#include "core/scheduler.h"
|
||||
|
||||
#define TASK_WAIT 50000000
|
||||
|
||||
extern void interrupt_enable();
|
||||
|
||||
void utask(){
|
||||
|
@ -13,7 +15,7 @@ void utask(){
|
|||
msg[1]='\0';
|
||||
while(1){
|
||||
asm("mov $0x1, %%eax;int $0x30"::"b"(msg));
|
||||
for(int i=0;i<5000;i++){
|
||||
for(int i=0;i<TASK_WAIT;i++){
|
||||
|
||||
}
|
||||
}
|
||||
|
@ -25,7 +27,7 @@ void utask2(){
|
|||
msg[1]='\0';
|
||||
while(1){
|
||||
asm("mov $0x1, %%eax;int $0x30"::"b"(msg));
|
||||
for(int i=0;i<5000;i++){
|
||||
for(int i=0;i<TASK_WAIT;i++){
|
||||
|
||||
}
|
||||
}
|
||||
|
@ -51,10 +53,9 @@ void bringelle(){
|
|||
// Utask
|
||||
print("Launch user tasks \n");
|
||||
|
||||
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);
|
||||
task_create(utask,100);
|
||||
task_create(utask2,100);
|
||||
|
||||
|
||||
scheduler_start();
|
||||
|
||||
|
|
|
@ -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(){
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Add table
Reference in a new issue