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