wip: multiple pds and switch to kernel pd when needed

This commit is contained in:
2025-02-10 13:25:19 +01:00
parent 8dd5373e7f
commit 5e561bfa15
9 changed files with 41 additions and 27 deletions

View File

@ -15,36 +15,36 @@ uint32_t esp_backup;
struct task *create_task(uint8_t uid)
{
static uint32_t pid = 1;
uint32_t *old_pd = current_task->heap;
current_task->heap = page_directory; // kernel pd
switch_pd(kernel_pd, (uint32_t *)((uint32_t)kernel_pd - HEAP_END));
struct task *new_task = vmalloc(sizeof(struct task));
current_task->heap = old_pd;
if (!new_task)
if (!new_task) {
switch_pd(current_task->heap, current_task->cr3);
return NULL;
}
switch_pd(current_task->heap, current_task->cr3);
new_task->status = RUN;
new_task->uid = uid;
new_task->esp = new_task->esp0 + STACK_SIZE;
new_task->pid = pid++;
// Allocate new pd
old_pd = current_task->heap;
current_task->heap = alloc_pages(4096, (void **)&new_task->cr3);
new_task->heap = alloc_pages(4096, (void **)&new_task->cr3);
if (!new_task->heap) {
current_task->heap = old_pd;
vfree(new_task);
return NULL;
}
new_task->heap = current_task->heap;
new_task->heap[768] = ((uint32_t)boot_page_table1 - HEAP_END) | 0x03;
memcpy(new_task->heap, current_task->heap, 4096);
switch_pd(new_task->heap, new_task->cr3);
// Allocate new stack on the newly allocated pd
new_task->esp0 = alloc_pages(STACK_SIZE, NULL);
current_task->heap = old_pd;
switch_pd(current_task->heap, current_task->cr3);
if (!new_task->esp0) {
vfree(new_task);
free_pages(new_task->heap, 4096);
return NULL;
}
new_task->heap[768] = ((uint32_t)boot_page_table1 - HEAP_END) | 0x03;
new_task->next = current_task->next;
new_task->prev = current_task;
@ -60,8 +60,8 @@ int8_t create_kernel_task(void)
new_task->status = RUN;
new_task->uid = 0;
new_task->pid = 0;
new_task->heap = page_directory;
new_task->cr3 = page_directory - KERNEL_START;
new_task->heap = kernel_pd;
new_task->cr3 = (uint32_t *)((uint32_t)kernel_pd - HEAP_END);
new_task->prev = new_task;
new_task->next = new_task;
current_task = new_task;