tasking: make tasks run with arguments
This commit is contained in:
+2
-1
@@ -24,7 +24,8 @@ typedef struct Process
|
|||||||
struct Process* next; // Pointer to the next task in the list
|
struct Process* next; // Pointer to the next task in the list
|
||||||
} Process;
|
} Process;
|
||||||
|
|
||||||
Process* task_create(EntryPoint func);
|
//Process* task_create(EntryPoint func);
|
||||||
|
Process* task_create(EntryPoint func, void** args, uint32_t arg_count);
|
||||||
void scheduler_init();
|
void scheduler_init();
|
||||||
void schedule();
|
void schedule();
|
||||||
void scheduler_lock();
|
void scheduler_lock();
|
||||||
|
|||||||
+30
-13
@@ -2,6 +2,8 @@
|
|||||||
#include "../include/stdio.h"
|
#include "../include/stdio.h"
|
||||||
#include "../include/paging.h"
|
#include "../include/paging.h"
|
||||||
|
|
||||||
|
#include <stddef.h>
|
||||||
|
|
||||||
Process* current = 0;
|
Process* current = 0;
|
||||||
Process* queue = 0;
|
Process* queue = 0;
|
||||||
|
|
||||||
@@ -19,7 +21,7 @@ static void processStartup()
|
|||||||
scheduler_unlock();
|
scheduler_unlock();
|
||||||
}
|
}
|
||||||
|
|
||||||
Process* task_create(EntryPoint func)
|
Process* task_create(void(*func)(), void** args, uint32_t arg_count)
|
||||||
{
|
{
|
||||||
Process* p = heap_alloc(sizeof(Process));
|
Process* p = heap_alloc(sizeof(Process));
|
||||||
p->pid = ++pid_counter;
|
p->pid = ++pid_counter;
|
||||||
@@ -28,12 +30,19 @@ Process* task_create(EntryPoint func)
|
|||||||
p->stackBase = heap_alloc(STACK_SIZE);
|
p->stackBase = heap_alloc(STACK_SIZE);
|
||||||
p->stackPointer = (uintptr_t*)((uint32_t)p->stackBase + STACK_SIZE);
|
p->stackPointer = (uintptr_t*)((uint32_t)p->stackBase + STACK_SIZE);
|
||||||
|
|
||||||
*(--p->stackPointer) = (uintptr_t)func;//TODO: check this shit
|
//put the arguments in stack
|
||||||
|
for(int i = arg_count-1; i >=0; i--)
|
||||||
|
*(--p->stackPointer) = (uintptr_t)args[i];
|
||||||
|
|
||||||
|
// Добавляем адрес возврата (фиктивный, для выравнивания)
|
||||||
|
*(--p->stackPointer) = 0; // Фиктивный адрес возврата (не используется напрямую)
|
||||||
|
|
||||||
|
*(--p->stackPointer) = (uintptr_t)func;
|
||||||
*(--p->stackPointer) = (uintptr_t)processStartup;
|
*(--p->stackPointer) = (uintptr_t)processStartup;
|
||||||
*(--p->stackPointer) = 0;
|
*(--p->stackPointer) = 0;//ebp
|
||||||
*(--p->stackPointer) = 0;
|
*(--p->stackPointer) = 0;//edi
|
||||||
*(--p->stackPointer) = 0;
|
*(--p->stackPointer) = 0;//esi
|
||||||
*(--p->stackPointer) = 0;
|
*(--p->stackPointer) = 0;//ebx
|
||||||
|
|
||||||
p->next = 0;
|
p->next = 0;
|
||||||
|
|
||||||
@@ -83,19 +92,27 @@ void idle()
|
|||||||
while(1){}
|
while(1){}
|
||||||
}
|
}
|
||||||
|
|
||||||
void task1()
|
void task1(int arg1, char* arg2)
|
||||||
{
|
{
|
||||||
while(1){printf("task1\n");}
|
while(1){
|
||||||
|
if(arg1 == 42)
|
||||||
|
printf("task1 0x%x %s\n", arg1, arg2);
|
||||||
|
else
|
||||||
|
printf("ZHOPA %s\n", arg2);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void task2()
|
void task2(int arg1, int arg2)
|
||||||
{
|
{
|
||||||
while(1){printf("task2\n");}
|
while(1){printf("task2 %X %X\n", arg1, arg2);}
|
||||||
}
|
}
|
||||||
|
|
||||||
void scheduler_init()
|
void scheduler_init()
|
||||||
{
|
{
|
||||||
task_create(&idle);
|
task_create(&idle, NULL, 0);
|
||||||
task_create(&task1);
|
|
||||||
task_create(&task2);
|
void* args1[] = {(void*)42, (void*)"ebalo"};
|
||||||
|
task_create((void (*)())&task1, args1, 2);
|
||||||
|
void* args2[] = {(void*)69, (void*)420};
|
||||||
|
task_create((void (*)())&task2, args2, 2);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user