All user-space apps ware moved to 8MB virtual address address (link.ld changes);...
[ZeXOS.git] / kernel / arch / arm / fault.S
blob846a36f6865cda79f70b780dbf1fc5f6df0e7b92
1 /*
2  *  ZeX/OS
3  *  Copyright (C) 2008  Tomas 'ZeXx86' Jedrzejek (zexx86@gmail.com)
4  *
5  *  This program is free software: you can redistribute it and/or modify
6  *  it under the terms of the GNU General Public License as published by
7  *  the Free Software Foundation, either version 3 of the License, or
8  *  (at your option) any later version.
9  *
10  *  This program is distributed in the hope that it will be useful,
11  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
12  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13  *  GNU General Public License for more details.
14  *
15  *  You should have received a copy of the GNU General Public License
16  *  along with this program.  If not, see <http://www.gnu.org/licenses/>.
17  */
20  * Thanks for lk project maintained by Geist for usefully parts of code
21  */
23 /* Just make it simplier - EXP create new function accesible from C */
24 #define EXP(f) .global f; f:
26 /* handler for undefined exceptions */
27 EXP(arm_undefined)
28         stmfd   sp!, { r0-r12, r14 }
29         sub     sp, sp, #12
30         mov     r0, sp
31         mrs     r1, spsr
32         stmia   r0, { r1, r13-r14 }^
33         b       arm_undefined_handler
34         b       .
36 /* handler for system calls */
37 EXP(arm_syscall)
38         stmfd   sp!, { r0-r12, r14 }
39         sub     sp, sp, #12
40         mov     r0, sp
41         mrs     r1, spsr
42         stmia   r0, { r1, r13-r14 }^
43         b       arm_syscall_handler
44         b       .
46 /* handler for prefetch abortion */
47 EXP(arm_prefetch_abort)
48         stmfd   sp!, { r0-r12, r14 }
49         sub     sp, sp, #12
50         mov     r0, sp
51         mrs     r1, spsr
52         stmia   r0, { r1, r13-r14 }^
53         b       arm_prefetch_abort_handler
54         b       .
56 /* handler for data abortion */
57 EXP(arm_data_abort)
58         stmfd   sp!, { r0-r12, r14 }
59         sub     sp, sp, #12
60         mov     r0, sp
61         mrs     r1, spsr
62         stmia   r0, { r1, r13-r14 }^
63         b       arm_data_abort_handler
64         b       .
66 /* handler for reserved exception */
67 EXP(arm_reserved)
68         b       .
69         
70 EXP(arm_irq)
71         /* save r4-r6 and use as a temporary place to save while we switch into supervisor mode */
72         stmia   r13, { r4-r6 }
73         mov     r4, r13
74         sub     r5, lr, #4
75         mrs     r6, spsr
77         /* move into supervisor mode. irq/fiq disabled */
78         msr     cpsr_c, #(3<<6 | 0x13)
80         /* save the return address */
81         stmfd   sp!, { r5 }
83         /* save C trashed regs, supervisor lr */
84         stmfd   sp!, { r0-r3, r12, lr }
86         /* save spsr */
87         stmfd   sp!, { r6 }
89         /* restore r4-r6 */
90         ldmia   r4, { r4-r6 }
92         /* increment the global critical section count */
93         ldr     r1, =arm_critical_section
94         ldr     r0, [r1]
95         add     r0, r0, #1
96         str     r0, [r1]
97         
98         /* call into higher level code */
99         mov     r0, sp /* iframe */
100         bl      platform_irq
102         /* reschedule if the handler returns nonzero */
103         cmp     r0, #0
104         blne    arch_task_preempt
106         /* decrement the global critical section count */
107         ldr     r1, =arm_critical_section
108         ldr     r0, [r1]
109         sub     r0, r0, #1
110         str     r0, [r1]
112         /* restore spsr */
113         ldmfd   sp!, { r0 }
114         msr     spsr, r0
116         /* restore back to where we came from */
117         ldmfd   sp!, { r0-r3, r12, lr, pc }^
119 .bss
121 .align 2
123 .global irq_save_spot
124 irq_save_spot:
125         .word   0       /* r4 */
126         .word   0       /* r5 */
127         .word   0       /* r6 */
128         
129 .text
130 EXP(arm_fiq)
131         sub     lr, lr, #4
132         stmfd   sp!, { r0-r3, r12, lr }
134         bl      platform_fiq
135         
136         ldmfd   sp!, { r0-r3, r12, pc }^
138 .ltorg