Haavard Skinnemoen | 5f97f7f | 2006-09-25 23:32:13 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2004-2006 Atmel Corporation |
| 3 | * |
| 4 | * This program is free software; you can redistribute it and/or modify |
| 5 | * it under the terms of the GNU General Public License version 2 as |
| 6 | * published by the Free Software Foundation. |
| 7 | */ |
| 8 | |
| 9 | #include <asm/sysreg.h> |
| 10 | |
| 11 | .text |
| 12 | .global __switch_to |
| 13 | .type __switch_to, @function |
| 14 | |
| 15 | /* Switch thread context from "prev" to "next", returning "last" |
| 16 | * r12 : prev |
| 17 | * r11 : &prev->thread + 1 |
| 18 | * r10 : &next->thread |
| 19 | */ |
| 20 | __switch_to: |
| 21 | stm --r11, r0,r1,r2,r3,r4,r5,r6,r7,sp,lr |
| 22 | mfsr r9, SYSREG_SR |
| 23 | st.w --r11, r9 |
| 24 | ld.w r8, r10++ |
| 25 | /* |
| 26 | * schedule() may have been called from a mode with a different |
| 27 | * set of registers. Make sure we don't lose anything here. |
| 28 | */ |
| 29 | pushm r10,r12 |
| 30 | mtsr SYSREG_SR, r8 |
| 31 | frs /* flush the return stack */ |
| 32 | sub pc, -2 /* flush the pipeline */ |
| 33 | popm r10,r12 |
| 34 | ldm r10++, r0,r1,r2,r3,r4,r5,r6,r7,sp,pc |
| 35 | .size __switch_to, . - __switch_to |