ITchimp wrote:
since eax, edx, and ecx are scratch register, there should not be a need to preserve those.. that was what system V abi says...
are you saying I have to do a pusha and popa to make the code work, and jmp *%3, will them work, be it register or memory?
The part of the ABI you're referring to covers register use across function calls.
You're not calling a function. Therefore, all the registers at the point you're doing the inline assembly, belong to the compiler to use at it sees fit.
If it helps, move away from inline assembly, and do context switching in a self contained assembly, in either a single context switch function (which can trash eax, edx, and ecx) or in a pair of save/restore context functions (which can do the same.)
setjmp/longjmp is an example of the latter, as is getcontext/setcontext (but these are for user context, mentioned here for reference.)
https://wiki.osdev.org/Kernel_Multitasking contains an example of the former.