Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1 | /* arch/arm/mach-msm/fiq_glue.S |
| 2 | * |
| 3 | * Copyright (C) 2008 Google, Inc. |
| 4 | * |
| 5 | * This software is licensed under the terms of the GNU General Public |
| 6 | * License version 2, as published by the Free Software Foundation, and |
| 7 | * may be copied, distributed, and modified under those terms. |
| 8 | * |
| 9 | * This program is distributed in the hope that it will be useful, |
| 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 12 | * GNU General Public License for more details. |
| 13 | * |
| 14 | */ |
| 15 | |
| 16 | #include <linux/linkage.h> |
| 17 | #include <asm/assembler.h> |
| 18 | |
| 19 | .text |
| 20 | |
| 21 | .global fiq_glue_end |
| 22 | |
| 23 | /* fiq stack: r0-r15,cpsr,spsr of interrupted mode */ |
| 24 | |
| 25 | ENTRY(fiq_glue) |
| 26 | /* store pc, cpsr from previous mode */ |
| 27 | mrs r12, spsr |
| 28 | sub r11, lr, #4 |
| 29 | subs r10, #1 |
| 30 | bne nested_fiq |
| 31 | |
| 32 | stmfd sp!, {r11-r12, lr} |
| 33 | |
| 34 | /* store r8-r14 from previous mode */ |
| 35 | sub sp, sp, #(7 * 4) |
| 36 | stmia sp, {r8-r14}^ |
| 37 | nop |
| 38 | |
| 39 | /* store r0-r7 from previous mode */ |
| 40 | stmfd sp!, {r0-r7} |
| 41 | |
| 42 | /* setup func(data,regs) arguments */ |
| 43 | mov r0, r9 |
| 44 | mov r1, sp |
| 45 | mov r3, r8 |
| 46 | |
| 47 | mov r7, sp |
| 48 | |
| 49 | /* Get sp and lr from non-user modes */ |
| 50 | and r4, r12, #MODE_MASK |
| 51 | cmp r4, #USR_MODE |
| 52 | beq fiq_from_usr_mode |
| 53 | |
| 54 | mov r7, sp |
| 55 | orr r4, r4, #(PSR_I_BIT | PSR_F_BIT) |
| 56 | msr cpsr_c, r4 |
| 57 | str sp, [r7, #(4 * 13)] |
| 58 | str lr, [r7, #(4 * 14)] |
| 59 | mrs r5, spsr |
| 60 | str r5, [r7, #(4 * 17)] |
| 61 | |
| 62 | cmp r4, #(SVC_MODE | PSR_I_BIT | PSR_F_BIT) |
| 63 | /* use fiq stack if we reenter this mode */ |
| 64 | subne sp, r7, #(4 * 3) |
| 65 | |
| 66 | fiq_from_usr_mode: |
| 67 | msr cpsr_c, #(SVC_MODE | PSR_I_BIT | PSR_F_BIT) |
| 68 | mov r2, sp |
| 69 | sub sp, r7, #12 |
| 70 | stmfd sp!, {r2, ip, lr} |
| 71 | /* call func(data,regs) */ |
| 72 | blx r3 |
| 73 | ldmfd sp, {r2, ip, lr} |
| 74 | mov sp, r2 |
| 75 | |
| 76 | /* restore/discard saved state */ |
| 77 | cmp r4, #USR_MODE |
| 78 | beq fiq_from_usr_mode_exit |
| 79 | |
| 80 | msr cpsr_c, r4 |
| 81 | ldr sp, [r7, #(4 * 13)] |
| 82 | ldr lr, [r7, #(4 * 14)] |
| 83 | msr spsr_cxsf, r5 |
| 84 | |
| 85 | fiq_from_usr_mode_exit: |
| 86 | msr cpsr_c, #(FIQ_MODE | PSR_I_BIT | PSR_F_BIT) |
| 87 | |
| 88 | ldmfd sp!, {r0-r7} |
| 89 | add sp, sp, #(7 * 4) |
| 90 | ldmfd sp!, {r11-r12, lr} |
| 91 | exit_fiq: |
| 92 | msr spsr_cxsf, r12 |
| 93 | add r10, #1 |
| 94 | movs pc, r11 |
| 95 | |
| 96 | nested_fiq: |
| 97 | orr r12, r12, #(PSR_F_BIT) |
| 98 | b exit_fiq |
| 99 | |
| 100 | fiq_glue_end: |
| 101 | |
| 102 | ENTRY(fiq_glue_setup) /* func, data, sp */ |
| 103 | mrs r3, cpsr |
| 104 | msr cpsr_c, #(FIQ_MODE | PSR_I_BIT | PSR_F_BIT) |
| 105 | movs r8, r0 |
| 106 | mov r9, r1 |
| 107 | mov sp, r2 |
| 108 | moveq r10, #0 |
| 109 | movne r10, #1 |
| 110 | msr cpsr_c, r3 |
| 111 | bx lr |
| 112 | |