Subversion Repositories HelenOS-historic

Rev

Rev 1480 | Rev 1716 | Go to most recent revision | Only display areas with differences | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 1480 Rev 1609
1
#
1
#
2
# Copyright (C) 2006 Martin Decky
2
# Copyright (C) 2006 Martin Decky
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
#include <arch/asm/regname.h>
29
#include <arch/asm/regname.h>
30
#include <arch/mm/page.h>
30
#include <arch/mm/page.h>
31
 
31
 
32
.section K_UNMAPPED_TEXT_START, "ax"
32
.section K_UNMAPPED_TEXT_START, "ax"
33
 
33
 
34
.macro CONTEXT_STORE
34
.macro CONTEXT_STORE
35
	
35
	
36
	# save R12 in SPRG1, backup CR in R12
36
	# save R12 in SPRG1, backup CR in R12
37
	# save SP in SPRG2
37
	# save SP in SPRG2
38
 
38
 
39
	mtsprg1 r12
39
	mtsprg1 r12
40
	mfcr r12
40
	mfcr r12
41
	mtsprg2 sp
41
	mtsprg2 sp
42
	
42
	
43
	# check whether SP is in kernel
43
	# check whether SP is in kernel
44
	
44
	
45
	andis. sp, sp, 0x8000
45
	andis. sp, sp, 0x8000
46
	bne 1f
46
	bne 1f
47
	
47
	
48
		# stack is in user-space
48
		# stack is in user-space
49
		
49
		
50
		mfsprg0 sp
50
		mfsprg0 sp
51
	
51
	
52
	b 2f
52
	b 2f
53
	
53
	
54
	1:
54
	1:
55
	
55
	
56
		# stack is in kernel
56
		# stack is in kernel
57
		
57
		
58
		mfsprg2 sp
58
		mfsprg2 sp
59
		subis sp, sp, 0x8000
59
		subis sp, sp, 0x8000
60
	
60
	
61
	2:
61
	2:
62
	
62
	
63
	subi sp, sp, 160
63
	subi sp, sp, 160
64
	stw r0, 8(sp)
64
	stw r0, 8(sp)
65
	stw r2, 12(sp)
65
	stw r2, 12(sp)
66
	stw r3, 16(sp)
66
	stw r3, 16(sp)
67
	stw r4, 20(sp)
67
	stw r4, 20(sp)
68
	stw r5, 24(sp)
68
	stw r5, 24(sp)
69
	stw r6, 28(sp)
69
	stw r6, 28(sp)
70
	stw r7, 32(sp)
70
	stw r7, 32(sp)
71
	stw r8, 36(sp)
71
	stw r8, 36(sp)
72
	stw r9, 40(sp)
72
	stw r9, 40(sp)
73
	stw r10, 44(sp)
73
	stw r10, 44(sp)
74
	stw r11, 48(sp)
74
	stw r11, 48(sp)
75
	stw r13, 52(sp)
75
	stw r13, 52(sp)
76
	stw r14, 56(sp)
76
	stw r14, 56(sp)
77
	stw r15, 60(sp)
77
	stw r15, 60(sp)
78
	stw r16, 64(sp)
78
	stw r16, 64(sp)
79
	stw r17, 68(sp)
79
	stw r17, 68(sp)
80
	stw r18, 72(sp)
80
	stw r18, 72(sp)
81
	stw r19, 76(sp)
81
	stw r19, 76(sp)
82
	stw r20, 80(sp)
82
	stw r20, 80(sp)
83
	stw r21, 84(sp)
83
	stw r21, 84(sp)
84
	stw r22, 88(sp)
84
	stw r22, 88(sp)
85
	stw r23, 92(sp)
85
	stw r23, 92(sp)
86
	stw r24, 96(sp)
86
	stw r24, 96(sp)
87
	stw r25, 100(sp)
87
	stw r25, 100(sp)
88
	stw r26, 104(sp)
88
	stw r26, 104(sp)
89
	stw r27, 108(sp)
89
	stw r27, 108(sp)
90
	stw r28, 112(sp)
90
	stw r28, 112(sp)
91
	stw r29, 116(sp)
91
	stw r29, 116(sp)
92
	stw r30, 120(sp)
92
	stw r30, 120(sp)
93
	stw r31, 124(sp)
93
	stw r31, 124(sp)
94
	
94
	
95
	stw r12, 128(sp)
95
	stw r12, 128(sp)
96
	
96
	
97
	mfsrr0 r12
97
	mfsrr0 r12
98
	stw r12, 132(sp)
98
	stw r12, 132(sp)
99
	
99
	
100
	mfsrr1 r12
100
	mfsrr1 r12
101
	stw r12, 136(sp)
101
	stw r12, 136(sp)
102
	
102
	
103
	mflr r12
103
	mflr r12
104
	stw r12, 140(sp)
104
	stw r12, 140(sp)
105
	
105
	
106
	mfctr r12
106
	mfctr r12
107
	stw r12, 144(sp)
107
	stw r12, 144(sp)
108
	
108
	
109
	mfxer r12
109
	mfxer r12
110
	stw r12, 148(sp)
110
	stw r12, 148(sp)
111
	
111
	
112
	mfsprg1 r12
112
	mfsprg1 r12
113
	stw r12, 152(sp)
113
	stw r12, 152(sp)
114
	
114
	
115
	mfsprg2 r12
115
	mfsprg2 r12
116
	stw r12, 156(sp)
116
	stw r12, 156(sp)
117
.endm
117
.endm
118
 
118
 
119
.org 0x060
119
.org 0x060
120
jump_to_kernel:
120
jump_to_kernel:
121
	lis r12, iret@ha
121
	lis r12, iret@ha
122
	addi r12, r12, iret@l
122
	addi r12, r12, iret@l
123
	mtlr r12
123
	mtlr r12
124
 
124
 
125
	mfmsr r12
125
	mfmsr r12
126
	ori r12, r12, (msr_ir | msr_dr)@l
126
	ori r12, r12, (msr_ir | msr_dr)@l
127
	mtsrr1 r12
127
	mtsrr1 r12
128
	
128
	
129
	addis sp, sp, 0x8000
129
	addis sp, sp, 0x8000
130
	mr r4, sp
130
	mr r4, sp
131
	addi r4, r4, 8
131
	addi r4, r4, 8
132
	
132
	
133
	rfi
133
	rfi
134
 
134
 
135
jump_to_kernel_syscall:
135
jump_to_kernel_syscall:
136
	lis r12, syscall_handler@ha
136
	lis r12, syscall_handler@ha
137
	addi r12, r12, syscall_handler@l
137
	addi r12, r12, syscall_handler@l
138
	mtsrr0 r12
138
	mtsrr0 r12
139
	
139
	
140
	lis r12, iret_syscall@ha
140
	lis r12, iret_syscall@ha
141
	addi r12, r12, iret_syscall@l
141
	addi r12, r12, iret_syscall@l
142
	mtlr r12
142
	mtlr r12
143
 
143
 
144
	mfmsr r12
144
	mfmsr r12
145
	ori r12, r12, (msr_ir | msr_dr)@l
145
	ori r12, r12, (msr_ir | msr_dr)@l
146
	mtsrr1 r12
146
	mtsrr1 r12
147
	
147
	
148
	addis sp, sp, 0x8000
148
	addis sp, sp, 0x8000
149
	rfi
149
	rfi
150
 
150
 
151
.org 0x100
151
.org 0x100
152
.global exc_system_reset
152
.global exc_system_reset
153
exc_system_reset:
153
exc_system_reset:
-
 
154
	CONTEXT_STORE
-
 
155
	
-
 
156
	lis r12, exc_dispatch@ha
-
 
157
	addi r12, r12, exc_dispatch@l
-
 
158
	mtsrr0 r12
-
 
159
	
-
 
160
	li r3, 0
154
	b exc_system_reset
161
	b jump_to_kernel
155
 
162
 
156
.org 0x200
163
.org 0x200
157
.global exc_machine_check
164
.global exc_machine_check
158
exc_machine_check:
165
exc_machine_check:
-
 
166
	CONTEXT_STORE
-
 
167
	
-
 
168
	lis r12, exc_dispatch@ha
-
 
169
	addi r12, r12, exc_dispatch@l
-
 
170
	mtsrr0 r12
-
 
171
	
-
 
172
	li r3, 1
159
	b exc_machine_check
173
	b jump_to_kernel
160
 
174
 
161
.org 0x300
175
.org 0x300
162
.global exc_data_storage
176
.global exc_data_storage
163
exc_data_storage:
177
exc_data_storage:
164
	CONTEXT_STORE
178
	CONTEXT_STORE
165
	
179
	
166
	lis r12, pht_refill@ha
180
	lis r12, exc_dispatch@ha
167
	addi r12, r12, pht_refill@l
181
	addi r12, r12, exc_dispatch@l
168
	mtsrr0 r12
182
	mtsrr0 r12
169
	
183
	
170
	li r3, 1
184
	li r3, 2
171
	b jump_to_kernel
185
	b jump_to_kernel
172
 
186
 
173
.org 0x400
187
.org 0x400
174
.global exc_instruction_storage
188
.global exc_instruction_storage
175
exc_instruction_storage:
189
exc_instruction_storage:
176
	CONTEXT_STORE
190
	CONTEXT_STORE
177
	
191
	
178
	lis r12, pht_refill@ha
192
	lis r12, exc_dispatch@ha
179
	addi r12, r12, pht_refill@l
193
	addi r12, r12, exc_dispatch@l
180
	mtsrr0 r12
194
	mtsrr0 r12
181
	
195
	
182
	li r3, 0
196
	li r3, 3
183
	b jump_to_kernel
197
	b jump_to_kernel
184
 
198
 
185
.org 0x500
199
.org 0x500
186
.global exc_external
200
.global exc_external
187
exc_external:
201
exc_external:
188
	CONTEXT_STORE
202
	CONTEXT_STORE
189
 
203
	
190
	lis r12, extint_handler@ha
204
	lis r12, exc_dispatch@ha
191
	addi r12, r12, extint_handler@l
205
	addi r12, r12, exc_dispatch@l
192
	mtsrr0 r12
206
	mtsrr0 r12
193
 
207
	
194
	li r3, 0
208
	li r3, 4
195
	b jump_to_kernel
209
	b jump_to_kernel
196
 
210
 
197
.org 0x600
211
.org 0x600
198
.global exc_alignment
212
.global exc_alignment
199
exc_alignment:
213
exc_alignment:
-
 
214
	CONTEXT_STORE
-
 
215
	
-
 
216
	lis r12, exc_dispatch@ha
-
 
217
	addi r12, r12, exc_dispatch@l
-
 
218
	mtsrr0 r12
-
 
219
	
-
 
220
	li r3, 5
200
	b exc_alignment
221
	b jump_to_kernel
201
 
222
 
202
.org 0x700
223
.org 0x700
203
.global exc_program
224
.global exc_program
204
exc_program:
225
exc_program:
-
 
226
	CONTEXT_STORE
-
 
227
	
-
 
228
	lis r12, exc_dispatch@ha
-
 
229
	addi r12, r12, exc_dispatch@l
-
 
230
	mtsrr0 r12
-
 
231
	
-
 
232
	li r3, 6
205
	b exc_program
233
	b jump_to_kernel
206
 
234
 
207
.org 0x800
235
.org 0x800
208
.global exc_fp_unavailable
236
.global exc_fp_unavailable
209
exc_fp_unavailable:
237
exc_fp_unavailable:
-
 
238
	CONTEXT_STORE
-
 
239
	
-
 
240
	lis r12, exc_dispatch@ha
-
 
241
	addi r12, r12, exc_dispatch@l
-
 
242
	mtsrr0 r12
-
 
243
	
-
 
244
	li r3, 7
210
	b exc_fp_unavailable
245
	b jump_to_kernel
211
 
246
 
212
.org 0x900
247
.org 0x900
213
.global exc_decrementer
248
.global exc_decrementer
214
exc_decrementer:
249
exc_decrementer:
215
	CONTEXT_STORE
250
	CONTEXT_STORE
216
 
251
 
217
	lis r12, exc_dispatch@ha
252
	lis r12, exc_dispatch@ha
218
	addi r12, r12, exc_dispatch@l
253
	addi r12, r12, exc_dispatch@l
219
	mtsrr0 r12
254
	mtsrr0 r12
220
	
255
	
221
	li r3, 10
256
	li r3, 8
222
	b jump_to_kernel
257
	b jump_to_kernel
223
 
258
 
224
.org 0xa00
259
.org 0xa00
225
.global exc_reserved0
260
.global exc_reserved0
226
exc_reserved0:
261
exc_reserved0:
-
 
262
	CONTEXT_STORE
-
 
263
	
-
 
264
	lis r12, exc_dispatch@ha
-
 
265
	addi r12, r12, exc_dispatch@l
-
 
266
	mtsrr0 r12
-
 
267
	
-
 
268
	li r3, 9
227
	b exc_reserved0
269
	b jump_to_kernel
228
 
270
 
229
.org 0xb00
271
.org 0xb00
230
.global exc_reserved1
272
.global exc_reserved1
231
exc_reserved1:
273
exc_reserved1:
-
 
274
	CONTEXT_STORE
-
 
275
	
-
 
276
	lis r12, exc_dispatch@ha
-
 
277
	addi r12, r12, exc_dispatch@l
-
 
278
	mtsrr0 r12
-
 
279
	
-
 
280
	li r3, 10
232
	b exc_reserved1
281
	b jump_to_kernel
233
 
282
 
234
.org 0xc00
283
.org 0xc00
235
.global exc_syscall
284
.global exc_syscall
236
exc_syscall:
285
exc_syscall:
237
	CONTEXT_STORE	
286
	CONTEXT_STORE	
238
	
287
	
239
	b jump_to_kernel_syscall
288
	b jump_to_kernel_syscall
240
 
289
 
241
.org 0xd00
290
.org 0xd00
242
.global exc_trace
291
.global exc_trace
243
exc_trace:
292
exc_trace:
-
 
293
	CONTEXT_STORE
-
 
294
	
-
 
295
	lis r12, exc_dispatch@ha
-
 
296
	addi r12, r12, exc_dispatch@l
-
 
297
	mtsrr0 r12
-
 
298
	
-
 
299
	li r3, 12
244
	b exc_trace
300
	b jump_to_kernel
245
 
301