Scheduler: add a reset_task function
This can be used later to implement execve()
This commit is contained in:
parent
4e3ef9593d
commit
136c0b3ae9
@ -22,4 +22,6 @@ namespace Scheduler
|
||||
|
||||
void reap_task(Task* task);
|
||||
void reap_tasks();
|
||||
|
||||
void reset_task(Task* task, ELFImage* new_image);
|
||||
}
|
@ -152,6 +152,25 @@ void Scheduler::load_user_task(const char* filename)
|
||||
new_task->id, new_task->regs.rsp, task_num);
|
||||
}
|
||||
|
||||
void Scheduler::reset_task(Task* task, ELFImage* new_image)
|
||||
{
|
||||
task->state = task->Running;
|
||||
task->regs.rip = new_image->entry;
|
||||
task->image = new_image;
|
||||
task->allocated_stack = (uint64_t)MemoryManager::get_pages(
|
||||
TASK_PAGES_IN_STACK, MAP_READ_WRITE | MAP_USER); // 16 KB is enough for everyone, right?
|
||||
task->regs.rsp = Utilities::get_top_of_stack(task->allocated_stack, TASK_PAGES_IN_STACK);
|
||||
task->regs.cs = 0x18 | 0x03;
|
||||
task->regs.ss = 0x20 | 0x03;
|
||||
task->regs.ds = 0x20 | 0x03;
|
||||
task->regs.rflags = (1 << 21) | (1 << 9); // enable interrupts
|
||||
task->task_sleep = 0;
|
||||
task->task_time = 0;
|
||||
task->cpu_time = 0;
|
||||
kinfoln("Resetting task: loaded at %lx, tid %ld, stack at %lx, total tasks: %ld", task->regs.rip, task->id,
|
||||
task->regs.rsp, task_num);
|
||||
}
|
||||
|
||||
void Scheduler::reap_task(Task* task)
|
||||
{
|
||||
ASSERT(!Interrupts::is_in_handler());
|
||||
|
Loading…
Reference in New Issue
Block a user