/** * \file * * * \author Giovanni Bajo * * \brief DSP5680x task switching support */ void asm_switch_context(void ** new_sp /* R2 */, void ** save_sp /* R3 */); asm void asm_switch_context(void ** new_sp, void ** save_sp) { lea (SP)+ ; From the manual: ; The compiler uses page 0 address locations X: 0x0030 - 0x003F as register ; variables. Frequently accessed local variables are assigned to the page 0 ; registers instead of to stack locations so that load and store instructions ; are shortened. Addresses X: 0x0030 - 0x0037 (page 0 registers MR0-MR7) are ; volatile registers and can be overwritten. The remaining registers (page 0 ; registers MR8-MR15) are treated as non-volatile and, if used by a routine, ; must be saved on entry and restored on exit. ; ; So, register 0x30-0x37 are caller-save, while 0x38-0x3F are callee-save. move x:<$38,y1 move y1,x:(SP)+ move x:<$39,y1 move y1,x:(SP)+ move x:<$3A,y1 move y1,x:(SP)+ move x:<$3B,y1 move y1,x:(SP)+ move x:<$3C,y1 move y1,x:(SP)+ move x:<$3D,y1 move y1,x:(SP)+ move x:<$3E,y1 move y1,x:(SP)+ move x:<$3F,y1 move y1,x:(SP) ; ; Switch stacks nop move SP, x:(R3) nop move x:(R2), SP nop ; ; restore all saved registers ; pop y1 move y1,x:<$3F pop y1 move y1,x:<$3E pop y1 move y1,x:<$3D pop y1 move y1,x:<$3C pop y1 move y1,x:<$3B pop y1 move y1,x:<$3A pop y1 move y1,x:<$39 pop y1 move y1,x:<$38 ; SR is already pushed on the stack (normal call context). Use RTI to restore ; it, so that interrupt status is preserved across the tasks. rti }