aha~! That was from my old code. But my task point to a stack like so.
Code: Select all
unsigned int create_task(void (*function)(), unsigned int priority)//, priority)
{
//store all the regs into task_state_info by save reg
interrupt_off();
kprintf("\n---- Creating task---- \n");
unsigned int *task_stack;
kstack_end = 0;
if(!first_task )
{
free_id += 1;
/*-------------------------------<<< remember to check this!!! And add recovery used number.*/
}
else
{
free_id = 0;
}
task_stack = &kstacks[free_id][(unsigned int)kstack_top];
*task_stack--;
*task_stack--=0x0202;
*task_stack--=0x08;
*task_stack--=function;
*task_stack--=0; //ebp
*task_stack--=0; //esp
*task_stack--=0; //edi
*task_stack--=0; //esi
*task_stack--=0; //edx
*task_stack--=0; //ecx
*task_stack--=0; //ebx
*task_stack--=0; //eax
*task_stack--=0x10; //ds
*task_stack--=0x10; //es
*task_stack--=0x10; //fs
*task_stack--=0x10; //gs
struct task_control_block *this_task = (struct task_control_block *)page_allocator(sizeof(struct task_control_block));
this_task[0].task_esp = (unsigned int)task_stack;//(unsigned int *)task_stack;160805//getesp();
this_task[0].task_ss = 0x10;
this_task[0].task_kstack = (unsigned int) &kstacks[free_id][(unsigned int)kstack_top]; //rows, columns
this_task[0].task_time_to_run = 10;
this_task[0].task_cr3 = first_page_directory;
this_task[0].task_priority = priority;
this_task[0].task_number = free_id ;
kprintf(" this_task.task_kstacks:%h task_stack: %h\n",this_task[0].task_kstack, task_stack);
kprintf("functions:%h %h %h\n",function, &function, (unsigned int) function);
interrupt_on();
kprintf("------Task created------\n.");
return (unsigned int) this_task;
}
As I said, I use it to create my very first task where you mention about initialize a stack before hand. And I use it for creating other tasks for testing.
I asked about on my last post or 2, about initialize the stack like above, do I need to do just for the first task? or do I do it in every task. Thats where I got confuse.
Also, any idea how to fix the selector->index*8 problem?
Here is my context switch code in case you are interested to help with that too. I use switch 2 simple tasks by pressing key.
Thank you~ You are my only hope at the moment~
Code: Select all
context_switch:
cld
;;cli
pushad ;;pusha
;;pushfd
push ds
push es
push fs
push gs
;;--------------
;;mov eax, [current_task_esp]
;;mov [eax], esp
;;lea eax, [kstack_end]
;;mov esp,eax
;;--------------
mov [current_task_esp],esp
call scheduler_handler
mov esp, [current_task_esp]
;;mov eax,[current_task_esp]
;;mov esp,[eax]
;;mov ebx, [eax+8]
;;mov [tss+4], ebx
;;mov al, 0x20
;;out 0x20, al
pop gs
pop fs
pop es
pop ds
;;popfd
popad ;;popa
iretd;;d