gbadev.org forum archive

This is a read-only mirror of the content originally found on forum.gbadev.org (now offline), salvaged from Wayback machine copies. A new forum can be found here.

DS development > Simple Context Switching Issues

#128272 - Sarev0k - Thu May 10, 2007 6:09 am

Hello,

I'm new to the ARM platform and I've implemented a very simple context switcher, but I when I spin off my first thread the execution of my application becomes very sporadic.

Here's the code I'm using to switch out the current stack pointer and spin off my new thread.
Code:
asm
(
   // changing the stack pointer to point to the new thread
   "ldr sp, =thdCurrent\n"
   "ldr sp, [sp]\n"
   "ldr sp, [sp, #8]\n"

   // popping the current thread's context off the stack
   "ldmfd sp!, {r0-r12, pc}\n"
);


Where thdCurrent is a global instance of a thread structure that I have pointing to the thread I wish to spin off. In this structure I've dynamically allocated memory for the stack and positioned the address and the stack pointer such that once those items were all popped off the stack, that thread's entry function would be placed into my program counter and I would start executing my thread.

I'm able to get to that function just fine, however when I start using printf, the ANSI escape sequences (that allow me to position my console output) completely stop working.

Is there something fundamentally wrong with the way I'm trying to spin off my first thread?

Thanks in advance for your help.

#128290 - simonjhall - Thu May 10, 2007 9:16 am

I dunno if it's related, but when I move $sp printf stops working properly for me (in particular print floats), so maybe this is somehow related?
_________________
Big thanks to everyone who donated for Quake2

#128309 - tepples - Thu May 10, 2007 2:30 pm

You can try to narrow it down to the floating-point library by using iprintf instead of printf. (The iprintf function is like printf, except iprintf doesn't handle floating-point formats.)
_________________
-- Where is he?
-- Who?
-- You know, the human.
-- I think he moved to Tilwick.

#128348 - Sarev0k - Thu May 10, 2007 10:39 pm

I've been playing around with how I'm spinning off my first thread and I've found that as long as I don't change my stack pointer the system doesn't behave erratically. However, the moment I do change my stack pointer things start behaving strangely.

Is there some registers in some of the other processing modes I need to change in order to successfully spin off a thread? All the examples I've seen do things with software interrupts, but is that really necessary to spin off a thread?