I've also had it do thisswitching from 0 to 1
switching from 1 to 2
Switching from 2 to 0
GPF
Here's my task creation codeSwitching from 0 to 2
Switching from 2 to 0
Switching from 0 to 2
GPF
Code: Select all
void create_task(void (*task)(),char *name,unsigned char access)
{
unsigned int *stack;
unsigned short c;
for(c=0;c<MAX_TASKS;c++)
{
if(tasks[c].status==0) break;
}
stack=kmalloc(4096)+4096;
*stack--=0x202;
*stack--=0x08;
*stack--=(unsigned int)task;
*stack--=0;
*stack--=0;
*stack--=0;
*stack--=0;
*stack--=0;
*stack--=0;
*stack--=0;
*stack--=0;
*stack--=0x10;
*stack--=0x10;
*stack--=0x10;
*stack--=0x10;
tasks[c].esp=(unsigned int)stack;
tasks[c].status=TASK_ACTIVE;
strcpy(tasks[c].name,name);
}
Code: Select all
unsigned int task_switcher(unsigned int addr)
{
unsigned short buffer=current_task;
unsigned short c;
buffer++;
if(tasks[buffer].status!=0)
{
Printf("switching from %d to %d\n",current_task,buffer);
if(just_init)
{
just_init=0;
buffer=current_task;
current_task++;
return tasks[buffer].esp;
}
else
{
tasks[current_task].esp=addr;
current_task=buffer;
return tasks[current_task].esp;
}
}
else
{
c=current_task;
c++;
while(tasks[c].status==0)
{
if(c>=MAX_TASKS) break;
c++;
}
if(c>=MAX_TASKS) c=0;
Printf("Switching from %d ",current_task);
current_task=c;
Printf("to %d\n",current_task);
return tasks[current_task].esp;
}
}
Code: Select all
pusha
mov %ds, %eax
push %eax
mov %es, %eax
push %eax
mov %fs, %eax
push %eax
mov %gs, %eax
push %eax
mov %esp, %eax
push %eax
call task_switcher
mov %eax, %esp
mov $0x20, %al
out %al, $0x20
pop %eax
pop %eax
pop %eax
pop %eax
pop %eax
popa
sti
iret
Code: Select all
void idle_task(void) //0
{
for(;;);
}
void task1(void) //1
{
for(;;);
}
void task2(void) //2
{
for(;;);
}