Subversion Repositories HelenOS

Rev

Rev 4669 | Only display areas with differences | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 4669 Rev 4692
1
#
1
#
2
# Copyright (c) 2009 Vineeth Pillai
2
# Copyright (c) 2009 Vineeth Pillai
3
# All rights reserved.
3
# All rights reserved.
4
#
4
#
5
# Redistribution and use in source and binary forms, with or without
5
# Redistribution and use in source and binary forms, with or without
6
# modification, are permitted provided that the following conditions
6
# modification, are permitted provided that the following conditions
7
# are met:
7
# are met:
8
#
8
#
9
# - Redistributions of source code must retain the above copyright
9
# - Redistributions of source code must retain the above copyright
10
#   notice, this list of conditions and the following disclaimer.
10
#   notice, this list of conditions and the following disclaimer.
11
# - Redistributions in binary form must reproduce the above copyright
11
# - Redistributions in binary form must reproduce the above copyright
12
#   notice, this list of conditions and the following disclaimer in the
12
#   notice, this list of conditions and the following disclaimer in the
13
#   documentation and/or other materials provided with the distribution.
13
#   documentation and/or other materials provided with the distribution.
14
# - The name of the author may not be used to endorse or promote products
14
# - The name of the author may not be used to endorse or promote products
15
#   derived from this software without specific prior written permission.
15
#   derived from this software without specific prior written permission.
16
#
16
#
17
# THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
17
# THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
18
# IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
18
# IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
19
# OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
19
# OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
20
# IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
20
# IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
21
# INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
21
# INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
22
# NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
22
# NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23
# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
23
# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24
# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24
# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
25
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
26
# THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26
# THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27
#
27
#
28
 
28
 
29
.text   
29
.text   
30
 
30
 
31
.global irq_exception_entry
31
.global irq_exception_entry
32
.global fiq_exception_entry
32
.global fiq_exception_entry
33
.global data_abort_exception_entry
33
.global data_abort_exception_entry
34
.global prefetch_abort_exception_entry
34
.global prefetch_abort_exception_entry
35
.global undef_instr_exception_entry
35
.global undef_instr_exception_entry
36
.global swi_exception_entry
36
.global swi_exception_entry
37
.global reset_exception_entry
37
.global reset_exception_entry
38
 
38
 
39
 
39
 
40
# Switches to kernel stack and saves all registers there.
40
# Switches to kernel stack and saves all registers there.
41
#
41
#
42
#  The stack frame created by the function looks like:
42
#  The stack frame created by the function looks like:
43
#
43
#
44
#              |_________________|
44
#              |_________________|
45
#              |                 |
45
#              |                 |
46
#              |     SPSR        |
46
#              |     SPSR        |
47
#              |                 |
47
#              |                 |
48
#              |_________________|
48
#              |_________________|
49
#              | Stack Pointer   |
49
#              | Stack Pointer   |
50
#              |      of         |
50
#              |      of         |
51
#              | Previous Mode   |
51
#              | Previous Mode   |
52
#              |_________________|
52
#              |_________________|
53
#              | Return address  |
53
#              | Return address  |
54
#              |      of         |
54
#              |      of         |
55
#              | Previous Mode   |
55
#              | Previous Mode   |
56
#              |_________________|
56
#              |_________________|
57
#              |   R0  - R12     |
57
#              |   R0  - R12     |
58
#              |      of         |
58
#              |      of         |
59
#              | Previous Mode   |
59
#              | Previous Mode   |
60
#              |_________________|
60
#              |_________________|
61
#              | Return address  |
61
#              | Return address  |
62
#              |     from        |
62
#              |     from        |
63
#              |Exception Handler|
63
#              |Exception Handler|
64
#              |_________________|
64
#              |_________________|
65
#              |                 |
65
#              |                 |
66
#
66
#
67
#
67
#
68
 
68
 
69
.macro SAVE_REGS_TO_STACK
69
.macro SAVE_REGS_TO_STACK
70
	stmfd r13!, {r0-r3}
70
	stmfd r13!, {r0-r3}
71
	mov r3, sp
71
	mov r3, sp
72
	add sp, sp, #16
72
	add sp, sp, #16
73
	mrs r1, cpsr
73
	mrs r1, cpsr
74
	bic r1, r1, #0x1f
74
	bic r1, r1, #0x1f
75
	mrs r2, spsr
75
	mrs r2, spsr
76
	and r0, r2, #0x1f
76
	and r0, r2, #0x1f
77
	cmp r0, #0x10
77
	cmp r0, #0x10
78
	bne 1f
78
	bne 1f
79
 
79
 
80
	# prev mode was usermode
80
	# prev mode was usermode
81
	mov r0, lr
81
	mov r0, lr
82
 
82
 
83
	# Switch to supervisor mode
83
	# Switch to supervisor mode
84
	orr r1, r1, #0x13
84
	orr r1, r1, #0x13
85
	msr cpsr_c, r1
85
	msr cpsr_c, r1
86
 
86
 
87
	# Load sp with [supervisor_sp]
87
	# Load sp with [supervisor_sp]
88
	ldr r13, =supervisor_sp
88
	ldr r13, =supervisor_sp
89
	ldr r13, [r13]
89
	ldr r13, [r13]
90
 
90
 
91
	# Populate the stack frame
91
	# Populate the stack frame
92
	msr spsr, r2
92
	msr spsr, r2
93
	mov lr, r0
93
	mov lr, r0
94
	stmfd r13!, {lr}
94
	stmfd r13!, {lr}
95
	stmfd r13!, {r4-r12}
95
	stmfd r13!, {r4-r12}
96
	ldmfd r3!, {r4-r7}
96
	ldmfd r3!, {r4-r7}
97
	stmfd r13!, {r4-r7}
97
	stmfd r13!, {r4-r7}
98
	stmfd r13!, {r13, lr}^
98
	stmfd r13!, {r13, lr}^
99
	stmfd r13!, {r2}
99
	stmfd r13!, {r2}
100
	b 2f
100
	b 2f
101
 
101
 
102
	# mode was not usermode
102
	# mode was not usermode
103
1:
103
1:
104
	# Switch to previous mode which is undoubtedly the supervisor mode
104
	# Switch to previous mode which is undoubtedly the supervisor mode
105
	orr r1, r1, r0
105
	orr r1, r1, r0
106
	mov r0, lr
106
	mov r0, lr
107
	msr cpsr_c, r1
107
	msr cpsr_c, r1
108
 
108
 
109
	# Populate the stack frame
109
	# Populate the stack frame
110
	mov r1, sp
110
	mov r1, sp
111
	stmfd r13!, {r0}
111
	stmfd r13!, {r0}
112
	stmfd r13!, {r4-r12}
112
	stmfd r13!, {r4-r12}
113
 
113
 
114
	# Store r0-r3 in r4-r7 and then push it on to stack
114
	# Store r0-r3 in r4-r7 and then push it on to stack
115
	ldmfd r3!, {r4-r7}
115
	ldmfd r3!, {r4-r7}
116
	stmfd r13!, {r4-r7}
116
	stmfd r13!, {r4-r7}
117
 
117
 
118
	# Push return address and stack pointer on to stack
118
	# Push return address and stack pointer on to stack
119
	stmfd r13!, {lr}
119
	stmfd r13!, {lr}
120
	stmfd r13!, {r1}
120
	stmfd r13!, {r1}
121
	mov lr, r0
121
	mov lr, r0
122
	msr spsr, r2
122
	msr spsr, r2
123
	stmfd r13!, {r2}
123
	stmfd r13!, {r2}
124
2:
124
2:
125
.endm
125
.endm
126
 
126
 
127
.macro LOAD_REGS_FROM_STACK
127
.macro LOAD_REGS_FROM_STACK
128
	ldmfd r13!, {r0}
128
	ldmfd r13!, {r0}
129
	msr spsr, r0
129
	msr spsr, r0
130
	and r0, r0, #0x1f
130
	and r0, r0, #0x1f
131
	cmp r0, #0x10
131
	cmp r0, #0x10
132
	bne 1f
132
	bne 1f
133
 
133
 
134
	# return to user mode
134
	# return to user mode
135
	ldmfd r13!, {r13, lr}^
135
	ldmfd r13!, {r13, lr}^
136
	b 2f
136
	b 2f
137
 
137
 
138
	# return to non-user mode
138
	# return to non-user mode
139
1:
139
1:
140
	ldmfd r13!, {r1, lr}
140
	ldmfd r13!, {r1, lr}
141
 
141
 
142
2:
142
2:
143
	ldmfd r13!, {r0-r12, pc}^
143
	ldmfd r13!, {r0-r12, pc}^
144
.endm
144
.endm
145
 
145
 
146
reset_exception_entry:
146
reset_exception_entry:
147
	SAVE_REGS_TO_STACK
147
	SAVE_REGS_TO_STACK
148
	mov r0, #0
148
	mov r0, #0
149
	mov r1, r13
149
	mov r1, r13
150
	bl exc_dispatch
150
	bl exc_dispatch
151
	LOAD_REGS_FROM_STACK
151
	LOAD_REGS_FROM_STACK
152
 
152
 
153
irq_exception_entry:
153
irq_exception_entry:
154
	sub lr, lr, #4
154
	sub lr, lr, #4
155
	SAVE_REGS_TO_STACK
155
	SAVE_REGS_TO_STACK
156
	mov r0, #5
156
	mov r0, #5
157
	mov r1, r13
157
	mov r1, r13
158
	bl exc_dispatch
158
	bl exc_dispatch
159
	LOAD_REGS_FROM_STACK
159
	LOAD_REGS_FROM_STACK
160
 
160
 
161
fiq_exception_entry:
161
fiq_exception_entry:
162
	sub lr, lr, #4
162
	sub lr, lr, #4
163
	SAVE_REGS_TO_STACK
163
	SAVE_REGS_TO_STACK
164
	mov r0, #6
164
	mov r0, #6
165
	mov r1, r13
165
	mov r1, r13
166
	bl exc_dispatch
166
	bl exc_dispatch
167
	LOAD_REGS_FROM_STACK
167
	LOAD_REGS_FROM_STACK
168
 
168
 
169
undef_instr_exception_entry:
169
undef_instr_exception_entry:
170
	SAVE_REGS_TO_STACK
170
	SAVE_REGS_TO_STACK
171
	mov r0, #1
171
	mov r0, #1
172
	mov r1, r13
172
	mov r1, r13
173
	bl exc_dispatch
173
	bl exc_dispatch
174
	LOAD_REGS_FROM_STACK
174
	LOAD_REGS_FROM_STACK
175
 
175
 
176
prefetch_abort_exception_entry:
176
prefetch_abort_exception_entry:
177
	sub lr, lr, #4
177
	sub lr, lr, #4
178
	SAVE_REGS_TO_STACK
178
	SAVE_REGS_TO_STACK
179
	mov r0, #3
179
	mov r0, #3
180
	mov r1, r13
180
	mov r1, r13
181
	bl exc_dispatch
181
	bl exc_dispatch
182
	LOAD_REGS_FROM_STACK
182
	LOAD_REGS_FROM_STACK
183
 
183
 
184
data_abort_exception_entry:
184
data_abort_exception_entry:
185
	sub lr, lr, #8
185
	sub lr, lr, #8
186
	SAVE_REGS_TO_STACK
186
	SAVE_REGS_TO_STACK
187
	mov r0, #4
187
	mov r0, #4
188
	mov r1, r13
188
	mov r1, r13
189
	bl exc_dispatch
189
	bl exc_dispatch
190
	LOAD_REGS_FROM_STACK
190
	LOAD_REGS_FROM_STACK
191
 
191
 
192
swi_exception_entry:
192
swi_exception_entry:
193
	ldr r13, =exc_stack
193
	ldr r13, =exc_stack
194
	SAVE_REGS_TO_STACK
194
	SAVE_REGS_TO_STACK
195
	mov r0, #2
195
	mov r0, #2
196
	mov r1, r13
196
	mov r1, r13
197
	bl exc_dispatch
197
	bl exc_dispatch
198
	LOAD_REGS_FROM_STACK
198
	LOAD_REGS_FROM_STACK
199
 
199
 
200
 
200