Having some trouble with my multitasking system

Question about which tools to use, bugs, the best way to implement a function, etc should go here. Don't forget to see if your question is answered in the wiki first! When in doubt post here.
Pyrofan1
Member
Member
Posts: 234
Joined: Sun Apr 29, 2007 1:13 am

Post by Pyrofan1 »

even after adding that code it still doesn't work. As far as i can tell the interrupt is only firing onces
my interrupt handling code

Code: Select all

.type irq0,@function
irq0:
call timer_handler
push $0
push $0
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 switch_tasks
mov %eax, %esp
mov $0x20, %al
out %al, $0x20 
pop %eax

pop %eax
pop %eax
pop %eax
pop %eax
popa
add $8, %esp
sti
iret
my timer_handler function

Code: Select all

void timer_handler(void)
{
	ticks++;
	Printf("timer handler\n");
	update_time();
	update_cursor();
}
and my tasking code

Code: Select all

unsigned int switch_tasks(struct REGS *r)
{
	Printf("Task switcher\n");
	if(current_task==MAX_TASKS) current_task=0;

	if(tasks[current_task++].status!=0)
	{
		tasks[current_task].r->eax=r->eax;
		tasks[current_task].r->ebx=r->ebx;
		tasks[current_task].r->ecx=r->ecx;
		tasks[current_task].r->edx=r->edx;
		tasks[current_task].r->esi=r->esi;
		tasks[current_task].r->edi=r->edi;
		tasks[current_task].r->esp=r->esp;
		tasks[current_task].r->ebp=r->ebp;
		tasks[current_task].r->ss=r->ss;
		tasks[current_task].r->cs=r->cs;
		tasks[current_task].r->es=r->es;
		tasks[current_task].r->ds=r->ds;
		tasks[current_task].r->fs=r->fs;
		tasks[current_task].r->gs=r->gs;
		tasks[current_task].r->eip=r->eip;
		tasks[current_task].r->eflags=r->eflags;
		tasks[current_task].r->int_no=r->int_no;
		tasks[current_task].r->err_code=r->err_code;

		current_task++;
	}
	else
	{
		tasks[current_task].r->eax=r->eax;
		tasks[current_task].r->ebx=r->ebx;
		tasks[current_task].r->ecx=r->ecx;
		tasks[current_task].r->edx=r->edx;
		tasks[current_task].r->esi=r->esi;
		tasks[current_task].r->edi=r->edi;
		tasks[current_task].r->esp=r->esp;
		tasks[current_task].r->ebp=r->ebp;
		tasks[current_task].r->ss=r->ss;
		tasks[current_task].r->cs=r->cs;
		tasks[current_task].r->es=r->es;
		tasks[current_task].r->ds=r->ds;
		tasks[current_task].r->fs=r->fs;
		tasks[current_task].r->gs=r->gs;
		tasks[current_task].r->eip=r->eip;
		tasks[current_task].r->eflags=r->eflags;
		tasks[current_task].r->int_no=r->int_no;
		tasks[current_task].r->err_code=r->err_code;

		current_task++;
		while(tasks[current_task].status==0)
		{
			if(current_task==MAX_TASKS) current_task=0;
			else current_task++;
		}

		
	}
	return tasks[current_task].stack;
}
User avatar
t0xic
Member
Member
Posts: 216
Joined: Sat May 05, 2007 3:16 pm
Location: VA
Contact:

Post by t0xic »

do you have stack setup code anywhere? That is not a proper stack.
Just one field.
*--stack = ...;
*--stack = ...;

tasks[0].stack = stack;
and just do that for every switch. Just scrap your code, use the tutorial code, and modify it from the working model.
User avatar
Combuster
Member
Member
Posts: 9301
Joined: Wed Oct 18, 2006 3:45 am
Libera.chat IRC: [com]buster
Location: On the balcony, where I can actually keep 1½m distance
Contact:

Post by Combuster »

how about that function call from an interrupt without saving the registers first? :shock:
"Certainly avoid yourself. He is a newbie and might not realize it. You'll hate his code deeply a few years down the road." - Sortie
[ My OS ] [ VDisk/SFS ]
Post Reply