blob: 2953bd65de235b92ccc54772c48814fb694f1fcd [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
50 /* load new regs */
51 ldmia r1, { r4-r11, r12, r13, r14 }^
52 mov lr, r12 /* restore lr */
53 add sp, r1, #(11*4) /* restore sp */
54 bx lr
55
56FUNCTION(arm_save_mode_regs)
57 mrs r1, cpsr
58
59#if ARM_ISA_ARMv6
60 cps #0x11 /* fiq */
61 str r13, [r0], #4
62 str r14, [r0], #4
63 cps #0x12 /* irq */
64 str r13, [r0], #4
65 str r14, [r0], #4
66 cps #0x13 /* svc */
67 str r13, [r0], #4
68 str r14, [r0], #4
69 cps #0x17 /* abt */
70 str r13, [r0], #4
71 str r14, [r0], #4
72 cps #0x1b /* und */
73 str r13, [r0], #4
74 str r14, [r0], #4
75 cps #0x1f /* sys */
76 str r13, [r0], #4
77 str r14, [r0], #4
78#else
79 // XXX implement
80 b .
81#endif
82
83 msr cpsr, r1
84
85 bx lr
86
87
88