Helo a relative newbie figure out software task switching

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.
Post Reply
ctkrohn

Helo a relative newbie figure out software task switching

Post by ctkrohn »

I've been working on a simple OS (code at keyos.sf.net), and I've gotten a few things done.  I'd like to figure out how to do software task switching on x86, since I hear that it is faster and easier than hardware TSS-based switching.

So I have a simple function which should switch between two tasks:

;C prototype is void context_switch(unsigned int **old_esp, unsigned int *new_esp);
context_switch:
        pushad
mov eax, [esp + 36]
mov [eax], esp
mov eax, [esp + 40]
mov esp, eax
popad
retn

...but when I call that, I get an int13 (general protection exception).  I think it is because I'm passing an invalid old esp.  Also, I've done nothing to set up the stacks of either thread... they are simply 4k chunks of memory.

I'm sure I'm doing a zillion things wrong, might someone help me figure this out?
geezer

RE:Helo a relative newbie figure out software task switching

Post by geezer »

Did you point the initial stack pointer to the TOP of the 4k chunk?

Well, not really the top -- did you push some valid register values onto the stack before the first task-switch?

If you use pre-emptive multitasking, does the code above run with interrupts disabled (so you don't get an timer interrupt in the middle of a task-switch)?
Post Reply