wip: start to add multiple pd for each task
This commit is contained in:
@ -10,36 +10,49 @@
|
||||
#include <stdbool.h>
|
||||
#include <stdint.h>
|
||||
|
||||
u32 esp_backup;
|
||||
uint32_t esp_backup;
|
||||
|
||||
struct task *create_task(u8 uid)
|
||||
struct task *create_task(uint8_t uid)
|
||||
{
|
||||
static u32 pid = 1;
|
||||
static uint32_t pid = 1;
|
||||
uint32_t *old_pd = current_task->heap;
|
||||
current_task->heap = page_directory; // kernel pd
|
||||
struct task *new_task = vmalloc(sizeof(struct task));
|
||||
current_task->heap = old_pd;
|
||||
if (!new_task)
|
||||
return NULL;
|
||||
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);
|
||||
if (!new_task->heap) {
|
||||
current_task->heap = old_pd;
|
||||
vfree(new_task);
|
||||
return NULL;
|
||||
}
|
||||
new_task->heap = current_task->heap;
|
||||
|
||||
// Allocate new stack on the newly allocated pd
|
||||
new_task->esp0 = alloc_pages(STACK_SIZE, NULL);
|
||||
current_task->heap = old_pd;
|
||||
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;
|
||||
current_task->next = new_task;
|
||||
new_task->status = RUN;
|
||||
new_task->uid = uid;
|
||||
new_task->esp0 = alloc_pages(STACK_SIZE, NULL);
|
||||
if (!new_task->esp0) {
|
||||
vfree(new_task);
|
||||
return NULL;
|
||||
}
|
||||
new_task->esp = new_task->esp0 + STACK_SIZE;
|
||||
new_task->pid = pid++;
|
||||
new_task->heap = alloc_pages(4096, (void **)&new_task->cr3);
|
||||
if (!new_task->heap) {
|
||||
free_pages(new_task->esp0, STACK_SIZE);
|
||||
vfree(new_task);
|
||||
return NULL;
|
||||
}
|
||||
return new_task;
|
||||
}
|
||||
|
||||
i8 create_kernel_task(void)
|
||||
int8_t create_kernel_task(void)
|
||||
{
|
||||
struct task *new_task = vmalloc(sizeof(struct task));
|
||||
if (!new_task)
|
||||
@ -60,7 +73,7 @@ void exec_fn(void (*fn)(void))
|
||||
struct task *new_task = create_task(OWNER_KERNEL);
|
||||
if (!new_task)
|
||||
kpanic("failed to create new task");
|
||||
new_task->eip = (u32 *)fn;
|
||||
new_task->eip = (uint32_t *)fn;
|
||||
}
|
||||
|
||||
void zombify_task(struct task *task)
|
||||
|
||||
Reference in New Issue
Block a user