change 4 pages of stack per stack to a #define

This commit is contained in:
apio 2022-09-25 18:13:20 +02:00
parent d3527b8824
commit 57bb1164e9

View File

@ -13,6 +13,8 @@
#include "thread/PIT.h"
#include "thread/Task.h"
#define TASK_PAGES_IN_STACK 4
static uint64_t task_num = 0;
static Task idle_task;
@ -63,7 +65,8 @@ void Scheduler::add_kernel_task(void (*task)(void))
ASSERT(new_task);
new_task->id = free_tid++;
new_task->regs.rip = (uint64_t)task;
new_task->allocated_stack = (uint64_t)MemoryManager::get_pages(4); // 16 KB is enough for everyone, right?
new_task->allocated_stack =
(uint64_t)MemoryManager::get_pages(TASK_PAGES_IN_STACK); // 16 KB is enough for everyone, right?
new_task->regs.rsp = new_task->allocated_stack + (4096 * 4) - sizeof(uintptr_t);
new_task->regs.cs = 0x08;
new_task->regs.ss = 0x10;
@ -88,8 +91,8 @@ void Scheduler::add_user_task(void* task)
ASSERT(new_task);
new_task->id = free_tid++;
new_task->regs.rip = (uint64_t)task;
new_task->allocated_stack =
(uint64_t)MemoryManager::get_pages(4, MAP_READ_WRITE | MAP_USER); // 16 KB is enough for everyone, right?
new_task->allocated_stack = (uint64_t)MemoryManager::get_pages(
TASK_PAGES_IN_STACK, MAP_READ_WRITE | MAP_USER); // 16 KB is enough for everyone, right?
new_task->regs.rsp = new_task->allocated_stack + (4096 * 4) - sizeof(uintptr_t);
new_task->regs.cs = 0x18 | 0x03;
new_task->regs.ss = 0x20 | 0x03;
@ -113,7 +116,8 @@ void Scheduler::reap_task(Task* task)
task_num--;
Task* exiting_task = task;
kinfoln("reaping task %ld", exiting_task->id);
if (exiting_task->allocated_stack) MemoryManager::release_pages((void*)exiting_task->allocated_stack, 4);
if (exiting_task->allocated_stack)
MemoryManager::release_pages((void*)exiting_task->allocated_stack, TASK_PAGES_IN_STACK);
delete exiting_task;
}