blob: 1b0ea1edfcff6057578f74df29b743fd383ebc98 [file] [log] [blame]
Travis Geiselbrecht1d0df692008-09-01 02:26:09 -07001/*
2 * Copyright (c) 2008 Travis Geiselbrecht
3 *
4 * Permission is hereby granted, free of charge, to any person obtaining
5 * a copy of this software and associated documentation files
6 * (the "Software"), to deal in the Software without restriction,
7 * including without limitation the rights to use, copy, modify, merge,
8 * publish, distribute, sublicense, and/or sell copies of the Software,
9 * and to permit persons to whom the Software is furnished to do so,
10 * subject to the following conditions:
11 *
12 * The above copyright notice and this permission notice shall be
13 * included in all copies or substantial portions of the Software.
14 *
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
16 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
17 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
18 * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
19 * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
20 * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
21 * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
22 */
23#include <asm.h>
24
25
26 /* context switch frame is as follows:
27 * ulr
28 * usp
29 * lr
30 * r11
31 * r10
32 * r9
33 * r8
34 * r7
35 * r6
36 * r5
37 * r4
38 */
39/* arm_context_switch(addr_t *old_sp, addr_t new_sp) */
40FUNCTION(arm_context_switch)
41 /* save all the usual registers + user regs */
42 /* the spsr is saved and restored in the iframe by exceptions.S */
43 sub r3, sp, #(11*4) /* can't use sp in user mode stm */
44 mov r12, lr
45 stmia r3, { r4-r11, r12, r13, r14 }^
46
47 /* save old sp */
48 str r3, [r0]
49
Travis Geiselbrecht8d529ef2008-09-13 15:13:21 -070050 /* clear any exlusive locks that the old thread holds */
51#if ARM_ISA_ARMV7
52 /* can clear it directly */
53 .word 0xf57ff01f // clrex
54#elif ARM_ISA_ARMV6
55 /* have to do a fake strex to clear it */
56 ldr r0, =strex_spot
57 strex r3, r2, [r0]
58#endif
59
Travis Geiselbrecht1d0df692008-09-01 02:26:09 -070060 /* load new regs */
61 ldmia r1, { r4-r11, r12, r13, r14 }^
62 mov lr, r12 /* restore lr */
63 add sp, r1, #(11*4) /* restore sp */
64 bx lr
65
Travis Geiselbrecht8d529ef2008-09-13 15:13:21 -070066.ltorg
67
Travis Geiselbrecht1d0df692008-09-01 02:26:09 -070068FUNCTION(arm_save_mode_regs)
69 mrs r1, cpsr
70
71#if ARM_ISA_ARMv6
72 cps #0x11 /* fiq */
73 str r13, [r0], #4
74 str r14, [r0], #4
75 cps #0x12 /* irq */
76 str r13, [r0], #4
77 str r14, [r0], #4
78 cps #0x13 /* svc */
79 str r13, [r0], #4
80 str r14, [r0], #4
81 cps #0x17 /* abt */
82 str r13, [r0], #4
83 str r14, [r0], #4
84 cps #0x1b /* und */
85 str r13, [r0], #4
86 str r14, [r0], #4
87 cps #0x1f /* sys */
88 str r13, [r0], #4
89 str r14, [r0], #4
90#else
91 // XXX implement
92 b .
93#endif
94
Travis Geiselbrecht09eeebd2009-01-19 23:59:16 -080095 msr cpsr_c, r1
Travis Geiselbrecht1d0df692008-09-01 02:26:09 -070096
97 bx lr
98
Travis Geiselbrecht8d529ef2008-09-13 15:13:21 -070099.data
100strex_spot:
101 .word 0
Travis Geiselbrecht1d0df692008-09-01 02:26:09 -0700102
103