tart: match new coding conventions.
[tart.git] / arch / arm / exceptions.S
bloba22a5a458d9586cd11da28cbb6bbf61095e69d38
1 /*
2  * Exceptions support.
3  */
5 #include <asm.h>
6 #include <arm.h>
8 // Text section.
9 .text
11 #if ARMV >= 6
14  * Macro for exception prologue.
15  *     Offset -> offset to PC, to the particular instruction to return to.
16  */
17 .macro EXCEPTION_PROLOGUE offset, switch_mode
18     # Adjust LR to offset.
19     sub lr, \offset
20     
21     // Save SPSR and LR onto the SVC stack.
22     srsdb #SVC_MODE!
24     // Switch to SVC mode, interrupts disabled.
25     cpsid i, #SVC_MODE
27     // Save registers (r0 - r15) on stack.
28     // Go down 60 bytes.
29     sub sp, #64
30     stmia sp, {r0 - r15}
32     // First argument is pointer to the structure above.
33     mov r0, sp
34 .endm
37  * Macro for exception epilogue.
38  */
39 .macro EXCEPTION_EPILOGUE
40     // Get back registers (r0 - r14), while skipping r15, from stack.
41     ldmia sp, {r0 - r14}
42     // Get back up 64 bytes.
43     add sp, #64
45     // Return from exception (via the SPSR and LR we saved before).
46     rfeia sp!
47 .endm
49 #else
50     #error ARM versions below ARMv6 not supported yet.
51 #endif
54  * Stub (for all exceptions I haven't bothered with yet).
55  */
56 GLOBAL(stub)
57 FUNCTION(stub)
58     EXCEPTION_PROLOGUE #0, #1
59     EXCEPTION_EPILOGUE