Subversion Repositories HelenOS

Rev

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

Rev 1855 Rev 1856
1
#
1
#
2
# Copyright (C) 2005 Jakub Jermar
2
# Copyright (C) 2005 Jakub Jermar
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
/**
29
/**
30
 * This file contains kernel trap table.
30
 * This file contains kernel trap table.
31
 */
31
 */
32
 
32
 
33
.register %g2, #scratch
33
.register %g2, #scratch
34
.register %g3, #scratch
34
.register %g3, #scratch
35
 
35
 
36
.text
36
.text
37
 
37
 
38
#include <arch/trap/trap_table.h>
38
#include <arch/trap/trap_table.h>
39
#include <arch/trap/regwin.h>
39
#include <arch/trap/regwin.h>
40
#include <arch/trap/interrupt.h>
40
#include <arch/trap/interrupt.h>
41
#include <arch/trap/exception.h>
41
#include <arch/trap/exception.h>
42
#include <arch/trap/mmu.h>
42
#include <arch/trap/mmu.h>
43
#include <arch/stack.h>
43
#include <arch/stack.h>
44
#include <arch/regdef.h>
44
#include <arch/regdef.h>
45
 
45
 
46
#define TABLE_SIZE	TRAP_TABLE_SIZE
46
#define TABLE_SIZE	TRAP_TABLE_SIZE
47
#define ENTRY_SIZE	TRAP_TABLE_ENTRY_SIZE
47
#define ENTRY_SIZE	TRAP_TABLE_ENTRY_SIZE
48
 
48
 
49
/*
49
/*
50
 * Kernel trap table.
50
 * Kernel trap table.
51
 */
51
 */
52
.align TABLE_SIZE
52
.align TABLE_SIZE
53
.global trap_table
53
.global trap_table
54
trap_table:
54
trap_table:
55
 
55
 
56
/* TT = 0x08, TL = 0, instruction_access_exception */
56
/* TT = 0x08, TL = 0, instruction_access_exception */
57
.org trap_table + TT_INSTRUCTION_ACCESS_EXCEPTION*ENTRY_SIZE
57
.org trap_table + TT_INSTRUCTION_ACCESS_EXCEPTION*ENTRY_SIZE
58
.global instruction_access_exception
58
.global instruction_access_exception
59
instruction_access_exception:
59
instruction_access_exception:
60
	SIMPLE_HANDLER do_instruction_access_exc
60
	SIMPLE_HANDLER do_instruction_access_exc
61
 
61
 
62
/* TT = 0x10, TL = 0, illegal_instruction */
62
/* TT = 0x10, TL = 0, illegal_instruction */
63
.org trap_table + TT_ILLEGAL_INSTRUCTION*ENTRY_SIZE
63
.org trap_table + TT_ILLEGAL_INSTRUCTION*ENTRY_SIZE
64
.global illegal_instruction
64
.global illegal_instruction
65
illegal_instruction:
65
illegal_instruction:
66
	SIMPLE_HANDLER do_illegal_instruction
66
	SIMPLE_HANDLER do_illegal_instruction
67
 
67
 
68
/* TT = 0x24, TL = 0, clean_window handler */
68
/* TT = 0x24, TL = 0, clean_window handler */
69
.org trap_table + TT_CLEAN_WINDOW*ENTRY_SIZE
69
.org trap_table + TT_CLEAN_WINDOW*ENTRY_SIZE
70
.global clean_window_handler
70
.global clean_window_handler
71
clean_window_handler:
71
clean_window_handler:
72
	CLEAN_WINDOW_HANDLER
72
	CLEAN_WINDOW_HANDLER
73
 
73
 
74
/* TT = 0x32, TL = 0, data_access_error */
74
/* TT = 0x32, TL = 0, data_access_error */
75
.org trap_table + TT_DATA_ACCESS_ERROR*ENTRY_SIZE
75
.org trap_table + TT_DATA_ACCESS_ERROR*ENTRY_SIZE
76
.global data_access_error
76
.global data_access_error
77
data_access_error:
77
data_access_error:
78
	SIMPLE_HANDLER do_data_access_error
78
	SIMPLE_HANDLER do_data_access_error
79
 
79
 
80
/* TT = 0x34, TL = 0, mem_address_not_aligned */
80
/* TT = 0x34, TL = 0, mem_address_not_aligned */
81
.org trap_table + TT_MEM_ADDRESS_NOT_ALIGNED*ENTRY_SIZE
81
.org trap_table + TT_MEM_ADDRESS_NOT_ALIGNED*ENTRY_SIZE
82
.global mem_address_not_aligned
82
.global mem_address_not_aligned
83
mem_address_not_aligned:
83
mem_address_not_aligned:
84
	SIMPLE_HANDLER do_mem_address_not_aligned
84
	SIMPLE_HANDLER do_mem_address_not_aligned
85
 
85
 
86
/* TT = 0x41, TL = 0, interrupt_level_1 handler */
86
/* TT = 0x41, TL = 0, interrupt_level_1 handler */
87
.org trap_table + TT_INTERRUPT_LEVEL_1*ENTRY_SIZE
87
.org trap_table + TT_INTERRUPT_LEVEL_1*ENTRY_SIZE
88
.global interrupt_level_1_handler
88
.global interrupt_level_1_handler
89
interrupt_level_1_handler:
89
interrupt_level_1_handler:
90
	INTERRUPT_LEVEL_N_HANDLER 1
90
	INTERRUPT_LEVEL_N_HANDLER 1
91
 
91
 
92
/* TT = 0x42, TL = 0, interrupt_level_2 handler */
92
/* TT = 0x42, TL = 0, interrupt_level_2 handler */
93
.org trap_table + TT_INTERRUPT_LEVEL_2*ENTRY_SIZE
93
.org trap_table + TT_INTERRUPT_LEVEL_2*ENTRY_SIZE
94
.global interrupt_level_2_handler
94
.global interrupt_level_2_handler
95
interrupt_level_2_handler:
95
interrupt_level_2_handler:
96
	INTERRUPT_LEVEL_N_HANDLER 2
96
	INTERRUPT_LEVEL_N_HANDLER 2
97
 
97
 
98
/* TT = 0x43, TL = 0, interrupt_level_3 handler */
98
/* TT = 0x43, TL = 0, interrupt_level_3 handler */
99
.org trap_table + TT_INTERRUPT_LEVEL_3*ENTRY_SIZE
99
.org trap_table + TT_INTERRUPT_LEVEL_3*ENTRY_SIZE
100
.global interrupt_level_3_handler
100
.global interrupt_level_3_handler
101
interrupt_level_3_handler:
101
interrupt_level_3_handler:
102
	INTERRUPT_LEVEL_N_HANDLER 3
102
	INTERRUPT_LEVEL_N_HANDLER 3
103
 
103
 
104
/* TT = 0x44, TL = 0, interrupt_level_4 handler */
104
/* TT = 0x44, TL = 0, interrupt_level_4 handler */
105
.org trap_table + TT_INTERRUPT_LEVEL_4*ENTRY_SIZE
105
.org trap_table + TT_INTERRUPT_LEVEL_4*ENTRY_SIZE
106
.global interrupt_level_4_handler
106
.global interrupt_level_4_handler
107
interrupt_level_4_handler:
107
interrupt_level_4_handler:
108
	INTERRUPT_LEVEL_N_HANDLER 4
108
	INTERRUPT_LEVEL_N_HANDLER 4
109
 
109
 
110
/* TT = 0x45, TL = 0, interrupt_level_5 handler */
110
/* TT = 0x45, TL = 0, interrupt_level_5 handler */
111
.org trap_table + TT_INTERRUPT_LEVEL_5*ENTRY_SIZE
111
.org trap_table + TT_INTERRUPT_LEVEL_5*ENTRY_SIZE
112
.global interrupt_level_5_handler
112
.global interrupt_level_5_handler
113
interrupt_level_5_handler:
113
interrupt_level_5_handler:
114
	INTERRUPT_LEVEL_N_HANDLER 5
114
	INTERRUPT_LEVEL_N_HANDLER 5
115
 
115
 
116
/* TT = 0x46, TL = 0, interrupt_level_6 handler */
116
/* TT = 0x46, TL = 0, interrupt_level_6 handler */
117
.org trap_table + TT_INTERRUPT_LEVEL_6*ENTRY_SIZE
117
.org trap_table + TT_INTERRUPT_LEVEL_6*ENTRY_SIZE
118
.global interrupt_level_6_handler
118
.global interrupt_level_6_handler
119
interrupt_level_6_handler:
119
interrupt_level_6_handler:
120
	INTERRUPT_LEVEL_N_HANDLER 6
120
	INTERRUPT_LEVEL_N_HANDLER 6
121
 
121
 
122
/* TT = 0x47, TL = 0, interrupt_level_7 handler */
122
/* TT = 0x47, TL = 0, interrupt_level_7 handler */
123
.org trap_table + TT_INTERRUPT_LEVEL_7*ENTRY_SIZE
123
.org trap_table + TT_INTERRUPT_LEVEL_7*ENTRY_SIZE
124
.global interrupt_level_7_handler
124
.global interrupt_level_7_handler
125
interrupt_level_7_handler:
125
interrupt_level_7_handler:
126
	INTERRUPT_LEVEL_N_HANDLER 7
126
	INTERRUPT_LEVEL_N_HANDLER 7
127
 
127
 
128
/* TT = 0x48, TL = 0, interrupt_level_8 handler */
128
/* TT = 0x48, TL = 0, interrupt_level_8 handler */
129
.org trap_table + TT_INTERRUPT_LEVEL_8*ENTRY_SIZE
129
.org trap_table + TT_INTERRUPT_LEVEL_8*ENTRY_SIZE
130
.global interrupt_level_8_handler
130
.global interrupt_level_8_handler
131
interrupt_level_8_handler:
131
interrupt_level_8_handler:
132
	INTERRUPT_LEVEL_N_HANDLER 8
132
	INTERRUPT_LEVEL_N_HANDLER 8
133
 
133
 
134
/* TT = 0x49, TL = 0, interrupt_level_9 handler */
134
/* TT = 0x49, TL = 0, interrupt_level_9 handler */
135
.org trap_table + TT_INTERRUPT_LEVEL_9*ENTRY_SIZE
135
.org trap_table + TT_INTERRUPT_LEVEL_9*ENTRY_SIZE
136
.global interrupt_level_9_handler
136
.global interrupt_level_9_handler
137
interrupt_level_9_handler:
137
interrupt_level_9_handler:
138
	INTERRUPT_LEVEL_N_HANDLER 9
138
	INTERRUPT_LEVEL_N_HANDLER 9
139
 
139
 
140
/* TT = 0x4a, TL = 0, interrupt_level_10 handler */
140
/* TT = 0x4a, TL = 0, interrupt_level_10 handler */
141
.org trap_table + TT_INTERRUPT_LEVEL_10*ENTRY_SIZE
141
.org trap_table + TT_INTERRUPT_LEVEL_10*ENTRY_SIZE
142
.global interrupt_level_10_handler
142
.global interrupt_level_10_handler
143
interrupt_level_10_handler:
143
interrupt_level_10_handler:
144
	INTERRUPT_LEVEL_N_HANDLER 10
144
	INTERRUPT_LEVEL_N_HANDLER 10
145
 
145
 
146
/* TT = 0x4b, TL = 0, interrupt_level_11 handler */
146
/* TT = 0x4b, TL = 0, interrupt_level_11 handler */
147
.org trap_table + TT_INTERRUPT_LEVEL_11*ENTRY_SIZE
147
.org trap_table + TT_INTERRUPT_LEVEL_11*ENTRY_SIZE
148
.global interrupt_level_11_handler
148
.global interrupt_level_11_handler
149
interrupt_level_11_handler:
149
interrupt_level_11_handler:
150
	INTERRUPT_LEVEL_N_HANDLER 11
150
	INTERRUPT_LEVEL_N_HANDLER 11
151
 
151
 
152
/* TT = 0x4c, TL = 0, interrupt_level_12 handler */
152
/* TT = 0x4c, TL = 0, interrupt_level_12 handler */
153
.org trap_table + TT_INTERRUPT_LEVEL_12*ENTRY_SIZE
153
.org trap_table + TT_INTERRUPT_LEVEL_12*ENTRY_SIZE
154
.global interrupt_level_12_handler
154
.global interrupt_level_12_handler
155
interrupt_level_12_handler:
155
interrupt_level_12_handler:
156
	INTERRUPT_LEVEL_N_HANDLER 12
156
	INTERRUPT_LEVEL_N_HANDLER 12
157
 
157
 
158
/* TT = 0x4d, TL = 0, interrupt_level_13 handler */
158
/* TT = 0x4d, TL = 0, interrupt_level_13 handler */
159
.org trap_table + TT_INTERRUPT_LEVEL_13*ENTRY_SIZE
159
.org trap_table + TT_INTERRUPT_LEVEL_13*ENTRY_SIZE
160
.global interrupt_level_13_handler
160
.global interrupt_level_13_handler
161
interrupt_level_13_handler:
161
interrupt_level_13_handler:
162
	INTERRUPT_LEVEL_N_HANDLER 13
162
	INTERRUPT_LEVEL_N_HANDLER 13
163
 
163
 
164
/* TT = 0x4e, TL = 0, interrupt_level_14 handler */
164
/* TT = 0x4e, TL = 0, interrupt_level_14 handler */
165
.org trap_table + TT_INTERRUPT_LEVEL_14*ENTRY_SIZE
165
.org trap_table + TT_INTERRUPT_LEVEL_14*ENTRY_SIZE
166
.global interrupt_level_14_handler
166
.global interrupt_level_14_handler
167
interrupt_level_14_handler:
167
interrupt_level_14_handler:
168
	INTERRUPT_LEVEL_N_HANDLER 14
168
	INTERRUPT_LEVEL_N_HANDLER 14
169
 
169
 
170
/* TT = 0x4f, TL = 0, interrupt_level_15 handler */
170
/* TT = 0x4f, TL = 0, interrupt_level_15 handler */
171
.org trap_table + TT_INTERRUPT_LEVEL_15*ENTRY_SIZE
171
.org trap_table + TT_INTERRUPT_LEVEL_15*ENTRY_SIZE
172
.global interrupt_level_15_handler
172
.global interrupt_level_15_handler
173
interrupt_level_15_handler:
173
interrupt_level_15_handler:
174
	INTERRUPT_LEVEL_N_HANDLER 15
174
	INTERRUPT_LEVEL_N_HANDLER 15
175
 
175
 
176
/* TT = 0x60, TL = 0, interrupt_vector_trap handler */
176
/* TT = 0x60, TL = 0, interrupt_vector_trap handler */
177
.org trap_table + TT_INTERRUPT_VECTOR_TRAP*ENTRY_SIZE
177
.org trap_table + TT_INTERRUPT_VECTOR_TRAP*ENTRY_SIZE
178
.global interrupt_vector_trap_handler
178
.global interrupt_vector_trap_handler
179
interrupt_vector_trap_handler:
179
interrupt_vector_trap_handler:
180
	INTERRUPT_VECTOR_TRAP_HANDLER
180
	INTERRUPT_VECTOR_TRAP_HANDLER
181
 
181
 
182
/* TT = 0x64, TL = 0, fast_instruction_access_MMU_miss */
182
/* TT = 0x64, TL = 0, fast_instruction_access_MMU_miss */
183
.org trap_table + TT_FAST_INSTRUCTION_ACCESS_MMU_MISS*ENTRY_SIZE
183
.org trap_table + TT_FAST_INSTRUCTION_ACCESS_MMU_MISS*ENTRY_SIZE
184
.global fast_instruction_access_mmu_miss_handler
184
.global fast_instruction_access_mmu_miss_handler
185
fast_instruction_access_mmu_miss_handler:
185
fast_instruction_access_mmu_miss_handler:
186
	FAST_INSTRUCTION_ACCESS_MMU_MISS_HANDLER
186
	FAST_INSTRUCTION_ACCESS_MMU_MISS_HANDLER
187
 
187
 
188
/* TT = 0x68, TL = 0, fast_data_access_MMU_miss */
188
/* TT = 0x68, TL = 0, fast_data_access_MMU_miss */
189
.org trap_table + TT_FAST_DATA_ACCESS_MMU_MISS*ENTRY_SIZE
189
.org trap_table + TT_FAST_DATA_ACCESS_MMU_MISS*ENTRY_SIZE
190
.global fast_data_access_mmu_miss_handler
190
.global fast_data_access_mmu_miss_handler
191
fast_data_access_mmu_miss_handler:
191
fast_data_access_mmu_miss_handler:
192
	FAST_DATA_ACCESS_MMU_MISS_HANDLER
192
	FAST_DATA_ACCESS_MMU_MISS_HANDLER
193
 
193
 
194
/* TT = 0x6c, TL = 0, fast_data_access_protection */
194
/* TT = 0x6c, TL = 0, fast_data_access_protection */
195
.org trap_table + TT_FAST_DATA_ACCESS_PROTECTION*ENTRY_SIZE
195
.org trap_table + TT_FAST_DATA_ACCESS_PROTECTION*ENTRY_SIZE
196
.global fast_data_access_protection_handler
196
.global fast_data_access_protection_handler
197
fast_data_access_protection_handler:
197
fast_data_access_protection_handler:
198
	FAST_DATA_ACCESS_PROTECTION_HANDLER
198
	FAST_DATA_ACCESS_PROTECTION_HANDLER
199
 
199
 
200
/* TT = 0x80, TL = 0, spill_0_normal handler */
200
/* TT = 0x80, TL = 0, spill_0_normal handler */
201
.org trap_table + TT_SPILL_0_NORMAL*ENTRY_SIZE
201
.org trap_table + TT_SPILL_0_NORMAL*ENTRY_SIZE
202
.global spill_0_normal
202
.global spill_0_normal
203
spill_0_normal:
203
spill_0_normal:
204
	SPILL_NORMAL_HANDLER_KERNEL
204
	SPILL_NORMAL_HANDLER_KERNEL
205
 
205
 
-
 
206
/* TT = 0x84, TL = 0, spill_1_normal handler */
-
 
207
.org trap_table + TT_SPILL_1_NORMAL*ENTRY_SIZE
-
 
208
.global spill_1_normal
-
 
209
spill_1_normal:
-
 
210
	SPILL_NORMAL_HANDLER_USERSPACE
-
 
211
 
-
 
212
/* TT = 0x88, TL = 0, spill_2_normal handler */
-
 
213
.org trap_table + TT_SPILL_2_NORMAL*ENTRY_SIZE
-
 
214
.global spill_2_normal
-
 
215
spill_2_normal:
-
 
216
	SPILL_TO_USPACE_WINDOW_BUFFER
-
 
217
 
206
/* TT = 0xc0, TL = 0, fill_0_normal handler */
218
/* TT = 0xc0, TL = 0, fill_0_normal handler */
207
.org trap_table + TT_FILL_0_NORMAL*ENTRY_SIZE
219
.org trap_table + TT_FILL_0_NORMAL*ENTRY_SIZE
208
.global fill_0_normal
220
.global fill_0_normal
209
fill_0_normal:
221
fill_0_normal:
210
	FILL_NORMAL_HANDLER_KERNEL
222
	FILL_NORMAL_HANDLER_KERNEL
211
 
223
 
-
 
224
/* TT = 0xc4, TL = 0, fill_1_normal handler */
-
 
225
.org trap_table + TT_FILL_1_NORMAL*ENTRY_SIZE
-
 
226
.global fill_1_normal
-
 
227
fill_1_normal:
-
 
228
	FILL_NORMAL_HANDLER_USERSPACE
-
 
229
 
212
/*
230
/*
213
 * Handlers for TL>0.
231
 * Handlers for TL>0.
214
 */
232
 */
215
 
233
 
216
/* TT = 0x08, TL > 0, instruction_access_exception */
234
/* TT = 0x08, TL > 0, instruction_access_exception */
217
.org trap_table + (TT_INSTRUCTION_ACCESS_EXCEPTION+512)*ENTRY_SIZE
235
.org trap_table + (TT_INSTRUCTION_ACCESS_EXCEPTION+512)*ENTRY_SIZE
218
.global instruction_access_exception_high
236
.global instruction_access_exception_high
219
instruction_access_exception_high:
237
instruction_access_exception_high:
220
	SIMPLE_HANDLER do_instruction_access_exc
238
	SIMPLE_HANDLER do_instruction_access_exc
221
 
239
 
222
/* TT = 0x10, TL > 0, illegal_instruction */
240
/* TT = 0x10, TL > 0, illegal_instruction */
223
.org trap_table + (TT_ILLEGAL_INSTRUCTION+512)*ENTRY_SIZE
241
.org trap_table + (TT_ILLEGAL_INSTRUCTION+512)*ENTRY_SIZE
224
.global illegal_instruction_high
242
.global illegal_instruction_high
225
illegal_instruction_high:
243
illegal_instruction_high:
226
	SIMPLE_HANDLER do_illegal_instruction
244
	SIMPLE_HANDLER do_illegal_instruction
227
 
245
 
228
/* TT = 0x24, TL > 0, clean_window handler */
246
/* TT = 0x24, TL > 0, clean_window handler */
229
.org trap_table + (TT_CLEAN_WINDOW+512)*ENTRY_SIZE
247
.org trap_table + (TT_CLEAN_WINDOW+512)*ENTRY_SIZE
230
.global clean_window_handler_high
248
.global clean_window_handler_high
231
clean_window_handler_high:
249
clean_window_handler_high:
232
	CLEAN_WINDOW_HANDLER
250
	CLEAN_WINDOW_HANDLER
233
 
251
 
234
/* TT = 0x32, TL > 0, data_access_error */
252
/* TT = 0x32, TL > 0, data_access_error */
235
.org trap_table + (TT_DATA_ACCESS_ERROR+512)*ENTRY_SIZE
253
.org trap_table + (TT_DATA_ACCESS_ERROR+512)*ENTRY_SIZE
236
.global data_access_error_high
254
.global data_access_error_high
237
data_access_error_high:
255
data_access_error_high:
238
	SIMPLE_HANDLER do_data_access_error
256
	SIMPLE_HANDLER do_data_access_error
239
 
257
 
240
/* TT = 0x34, TL > 0, mem_address_not_aligned */
258
/* TT = 0x34, TL > 0, mem_address_not_aligned */
241
.org trap_table + (TT_MEM_ADDRESS_NOT_ALIGNED+512)*ENTRY_SIZE
259
.org trap_table + (TT_MEM_ADDRESS_NOT_ALIGNED+512)*ENTRY_SIZE
242
.global mem_address_not_aligned_high
260
.global mem_address_not_aligned_high
243
mem_address_not_aligned_high:
261
mem_address_not_aligned_high:
244
	SIMPLE_HANDLER do_mem_address_not_aligned
262
	SIMPLE_HANDLER do_mem_address_not_aligned
245
 
263
 
246
/* TT = 0x64, TL > 0, fast_instruction_access_MMU_miss */
264
/* TT = 0x64, TL > 0, fast_instruction_access_MMU_miss */
247
.org trap_table + (TT_FAST_INSTRUCTION_ACCESS_MMU_MISS+512)*ENTRY_SIZE
265
.org trap_table + (TT_FAST_INSTRUCTION_ACCESS_MMU_MISS+512)*ENTRY_SIZE
248
.global fast_instruction_access_mmu_miss_handler_high
266
.global fast_instruction_access_mmu_miss_handler_high
249
fast_instruction_access_mmu_miss_handler_high:
267
fast_instruction_access_mmu_miss_handler_high:
250
	FAST_INSTRUCTION_ACCESS_MMU_MISS_HANDLER
268
	FAST_INSTRUCTION_ACCESS_MMU_MISS_HANDLER
251
 
269
 
252
/* TT = 0x68, TL > 0, fast_data_access_MMU_miss */
270
/* TT = 0x68, TL > 0, fast_data_access_MMU_miss */
253
.org trap_table + (TT_FAST_DATA_ACCESS_MMU_MISS+512)*ENTRY_SIZE
271
.org trap_table + (TT_FAST_DATA_ACCESS_MMU_MISS+512)*ENTRY_SIZE
254
.global fast_data_access_mmu_miss_handler_high
272
.global fast_data_access_mmu_miss_handler_high
255
fast_data_access_mmu_miss_handler_high:
273
fast_data_access_mmu_miss_handler_high:
256
	FAST_DATA_ACCESS_MMU_MISS_HANDLER
274
	FAST_DATA_ACCESS_MMU_MISS_HANDLER
257
 
275
 
258
/* TT = 0x6c, TL > 0, fast_data_access_protection */
276
/* TT = 0x6c, TL > 0, fast_data_access_protection */
259
.org trap_table + (TT_FAST_DATA_ACCESS_PROTECTION+512)*ENTRY_SIZE
277
.org trap_table + (TT_FAST_DATA_ACCESS_PROTECTION+512)*ENTRY_SIZE
260
.global fast_data_access_protection_handler_high
278
.global fast_data_access_protection_handler_high
261
fast_data_access_protection_handler_high:
279
fast_data_access_protection_handler_high:
262
	FAST_DATA_ACCESS_PROTECTION_HANDLER
280
	FAST_DATA_ACCESS_PROTECTION_HANDLER
263
 
281
 
264
/* TT = 0x80, TL > 0, spill_0_normal handler */
282
/* TT = 0x80, TL > 0, spill_0_normal handler */
265
.org trap_table + (TT_SPILL_0_NORMAL+512)*ENTRY_SIZE
283
.org trap_table + (TT_SPILL_0_NORMAL+512)*ENTRY_SIZE
266
.global spill_0_normal_high
284
.global spill_0_normal_high
267
spill_0_normal_high:
285
spill_0_normal_high:
268
	SPILL_NORMAL_HANDLER_KERNEL
286
	SPILL_NORMAL_HANDLER_KERNEL
269
 
287
 
-
 
288
/* TT = 0x88, TL > 0, spill_2_normal handler */
-
 
289
.org trap_table + (TT_SPILL_2_NORMAL+512)*ENTRY_SIZE
-
 
290
.global spill_2_normal_high
-
 
291
spill_2_normal_high:
-
 
292
	SPILL_TO_USPACE_WINDOW_BUFFER
-
 
293
 
-
 
294
/* TT = 0xa0, TL > 0, spill_0_other handler */
-
 
295
.org trap_table + (TT_SPILL_0_OTHER+512)*ENTRY_SIZE
-
 
296
.global spill_0_other_high
-
 
297
spill_0_other_high:
-
 
298
	SPILL_TO_USPACE_WINDOW_BUFFER
-
 
299
 
270
/* TT = 0xc0, TL > 0, fill_0_normal handler */
300
/* TT = 0xc0, TL > 0, fill_0_normal handler */
271
.org trap_table + (TT_FILL_0_NORMAL+512)*ENTRY_SIZE
301
.org trap_table + (TT_FILL_0_NORMAL+512)*ENTRY_SIZE
272
.global fill_0_normal_high
302
.global fill_0_normal_high
273
fill_0_normal_high:
303
fill_0_normal_high:
274
	FILL_NORMAL_HANDLER_KERNEL
304
	FILL_NORMAL_HANDLER_KERNEL
275
 
305
 
276
 
306
 
277
/* Preemptible trap handler for TL=1.
307
/* Preemptible trap handler for TL=1.
278
 *
308
 *
279
 * This trap handler makes arrangements to make calling of scheduler() from
309
 * This trap handler makes arrangements to make calling of scheduler() from
280
 * within a trap context possible. It is called from several other trap
310
 * within a trap context possible. It is called from several other trap
281
 * handlers.
311
 * handlers.
282
 *
312
 *
283
 * This function can be entered either with interrupt globals or alternate globals.
313
 * This function can be entered either with interrupt globals or alternate globals.
284
 * Memory management trap handlers are obliged to switch to one of those global sets
314
 * Memory management trap handlers are obliged to switch to one of those global sets
285
 * prior to calling this function. Register window management functions are not
315
 * prior to calling this function. Register window management functions are not
286
 * allowed to modify the alternate global registers.
316
 * allowed to modify the alternate global registers.
287
 *
317
 *
288
 * Input registers:
318
 * Input registers:
289
 *	%g1		Address of function to call.
319
 *	%g1		Address of function to call.
290
 * 	%g2	 	Argument for the function.
320
 * 	%g2	 	Argument for the function.
291
 *	%g6		Pre-set as kernel stack base if trap from userspace.
321
 *	%g6		Pre-set as kernel stack base if trap from userspace.
292
 *	%g7		Reserved.
322
 *	%g7		Pre-set as address of the userspace window buffer.
293
 */
323
 */
294
.global preemptible_handler
324
.global preemptible_handler
295
preemptible_handler:
325
preemptible_handler:
296
	rdpr %tstate, %g3
326
	rdpr %tstate, %g3
297
	andcc %g3, TSTATE_PRIV_BIT, %g0		! if this trap came from the privileged mode...
327
	andcc %g3, TSTATE_PRIV_BIT, %g0		! if this trap came from the privileged mode...
298
	bnz 0f					! ...skip setting of kernel stack and primary context
328
	bnz 0f					! ...skip setting of kernel stack and primary context
299
	nop
329
	nop
300
 
330
 
301
	/*
331
	/*
302
	 * Switch to kernel stack. The old stack is
332
	 * Switch to kernel stack. The old stack is
303
	 * automatically saved in the old window's %sp
333
	 * automatically saved in the old window's %sp
304
	 * and the new window's %fp.
334
	 * and the new window's %fp.
305
	 */
335
	 */
306
	save %g6, -PREEMPTIBLE_HANDLER_STACK_FRAME_SIZE, %sp
336
	save %g6, -PREEMPTIBLE_HANDLER_STACK_FRAME_SIZE, %sp
307
 
337
 
308
	/*
338
	/*
309
	 * Mark the CANSAVE windows as OTHER windows.
339
	 * Mark the CANSAVE windows as OTHER windows.
310
	 * Set CLEANWIN to NWINDOW-1 so that clean_window traps do not occur.
340
	 * Set CLEANWIN to NWINDOW-1 so that clean_window traps do not occur.
311
	 */
341
	 */
312
	rdpr %cansave, %l0
342
	rdpr %cansave, %l0
313
	wrpr %l0, %otherwin
343
	wrpr %l0, %otherwin
314
	wrpr %g0, %cansave
344
	wrpr %g0, %cansave
315
	wrpr %g0, NWINDOW-1, %cleanwin
345
	wrpr %g0, NWINDOW-1, %cleanwin
316
 
346
 
317
	/*
347
	/*
318
	 * Switch to primary context 0.
348
	 * Switch to primary context 0.
319
	 */
349
	 */
320
	mov VA_PRIMARY_CONTEXT_REG, %l0
350
	mov VA_PRIMARY_CONTEXT_REG, %l0
321
        stxa %g0, [%l0] ASI_DMMU
351
        stxa %g0, [%l0] ASI_DMMU
322
	set kernel_image_start, %l0
352
	set kernel_image_start, %l0
323
        flush %l0
353
        flush %l0
324
 
354
 
325
	ba 1f
355
	ba 1f
326
	nop
356
	nop
327
 
357
 
328
0:
358
0:
329
	save %sp, -PREEMPTIBLE_HANDLER_STACK_FRAME_SIZE, %sp
359
	save %sp, -PREEMPTIBLE_HANDLER_STACK_FRAME_SIZE, %sp
330
 
360
 
331
	/*
361
	/*
332
	 * At this moment, we are using the kernel stack 
362
	 * At this moment, we are using the kernel stack 
333
	 * and have successfully allocated a register window.
363
	 * and have successfully allocated a register window.
334
	 */
364
	 */
335
1:
365
1:
336
 
366
 
337
	/*
367
	/*
338
	 * Copy arguments.
368
	 * Copy arguments.
339
	 */
369
	 */
340
	mov %g1, %l0
370
	mov %g1, %l0
341
	mov %g2, %o0
371
	mov %g2, %o0
342
 
372
 
343
	/*
373
	/*
344
	 * Save TSTATE, TPC and TNPC aside.
374
	 * Save TSTATE, TPC and TNPC aside.
345
	 */
375
	 */
346
	rdpr %tstate, %g1
376
	rdpr %tstate, %g1
347
	rdpr %tpc, %g2
377
	rdpr %tpc, %g2
348
	rdpr %tnpc, %g3
378
	rdpr %tnpc, %g3
349
 
379
 
350
	/*
380
	/*
351
	 * The following memory accesses will not fault
381
	 * The following memory accesses will not fault
352
	 * because special provisions are made to have
382
	 * because special provisions are made to have
353
	 * the kernel stack of THREAD locked in DTLB.
383
	 * the kernel stack of THREAD locked in DTLB.
354
	 */
384
	 */
355
	stx %g1, [%sp + PREEMPTIBLE_HANDLER_STACK_FRAME_SIZE + STACK_BIAS + SAVED_TSTATE]
385
	stx %g1, [%sp + PREEMPTIBLE_HANDLER_STACK_FRAME_SIZE + STACK_BIAS + SAVED_TSTATE]
356
	stx %g2, [%sp + PREEMPTIBLE_HANDLER_STACK_FRAME_SIZE + STACK_BIAS + SAVED_TPC]
386
	stx %g2, [%sp + PREEMPTIBLE_HANDLER_STACK_FRAME_SIZE + STACK_BIAS + SAVED_TPC]
357
	stx %g3, [%sp + PREEMPTIBLE_HANDLER_STACK_FRAME_SIZE + STACK_BIAS + SAVED_TNPC]
387
	stx %g3, [%sp + PREEMPTIBLE_HANDLER_STACK_FRAME_SIZE + STACK_BIAS + SAVED_TNPC]
358
	
388
	
359
	wrpr %g0, 0, %tl
389
	wrpr %g0, 0, %tl
360
	wrpr %g0, PSTATE_PRIV_BIT, %pstate
390
	wrpr %g0, PSTATE_PRIV_BIT, %pstate
361
	SAVE_GLOBALS
391
	SAVE_GLOBALS
362
	
392
	
363
	/*
393
	/*
364
	 * Call the higher-level handler and pass istate as second parameter.
394
	 * Call the higher-level handler and pass istate as second parameter.
365
	 */
395
	 */
366
	call %l0
396
	call %l0
367
	add %sp, PREEMPTIBLE_HANDLER_STACK_FRAME_SIZE + STACK_BIAS + SAVED_TNPC, %o1
397
	add %sp, PREEMPTIBLE_HANDLER_STACK_FRAME_SIZE + STACK_BIAS + SAVED_TNPC, %o1
368
 
398
 
369
	RESTORE_GLOBALS
399
	RESTORE_GLOBALS
370
	wrpr %g0, PSTATE_AG_BIT | PSTATE_PRIV_BIT, %pstate
400
	wrpr %g0, PSTATE_AG_BIT | PSTATE_PRIV_BIT, %pstate
371
	wrpr %g0, 1, %tl
401
	wrpr %g0, 1, %tl
372
	
402
	
373
	/*
403
	/*
374
	 * Read TSTATE, TPC and TNPC from saved copy.
404
	 * Read TSTATE, TPC and TNPC from saved copy.
375
	 */
405
	 */
376
	ldx [%sp + PREEMPTIBLE_HANDLER_STACK_FRAME_SIZE + STACK_BIAS + SAVED_TSTATE], %g1
406
	ldx [%sp + PREEMPTIBLE_HANDLER_STACK_FRAME_SIZE + STACK_BIAS + SAVED_TSTATE], %g1
377
	ldx [%sp + PREEMPTIBLE_HANDLER_STACK_FRAME_SIZE + STACK_BIAS + SAVED_TPC], %g2
407
	ldx [%sp + PREEMPTIBLE_HANDLER_STACK_FRAME_SIZE + STACK_BIAS + SAVED_TPC], %g2
378
	ldx [%sp + PREEMPTIBLE_HANDLER_STACK_FRAME_SIZE + STACK_BIAS + SAVED_TNPC], %g3
408
	ldx [%sp + PREEMPTIBLE_HANDLER_STACK_FRAME_SIZE + STACK_BIAS + SAVED_TNPC], %g3
379
 
409
 
380
	/*
410
	/*
381
	 * Restore TSTATE, TPC and TNPC from saved copies.
411
	 * Restore TSTATE, TPC and TNPC from saved copies.
382
	 */
412
	 */
383
	wrpr %g1, 0, %tstate
413
	wrpr %g1, 0, %tstate
384
	wrpr %g2, 0, %tpc
414
	wrpr %g2, 0, %tpc
385
	wrpr %g3, 0, %tnpc
415
	wrpr %g3, 0, %tnpc
386
 
416
 
387
	/*
417
	/*
388
	 * If OTHERWIN is zero, then all the userspace windows have been
418
	 * If OTHERWIN is zero, then all the userspace windows have been
389
	 * spilled to kernel memory (i.e. register window buffer). If
419
	 * spilled to kernel memory (i.e. register window buffer). If
390
	 * OTHERWIN is non-zero, then some userspace windows are still
420
	 * OTHERWIN is non-zero, then some userspace windows are still
391
	 * valid. Others might have been spilled. However, the CWP pointer
421
	 * valid. Others might have been spilled. However, the CWP pointer
392
	 * needs no fixing because the scheduler had not been called.
422
	 * needs no fixing because the scheduler had not been called.
393
	 */
423
	 */
394
	rdpr %otherwin, %l0
424
	rdpr %otherwin, %l0
395
	brnz %l0, 0f
425
	brnz %l0, 0f
396
	nop
426
	nop
397
 
427
 
398
	/*
428
	/*
399
	 * OTHERWIN == 0
429
	 * OTHERWIN == 0
400
	 */
430
	 */
401
 
431
 
402
	/*
432
	/*
403
	 * If TSTATE.CWP + 1 == CWP, then we still do not have to fix CWP.
433
	 * If TSTATE.CWP + 1 == CWP, then we still do not have to fix CWP.
404
	 */
434
	 */
405
	and %g1, TSTATE_CWP_MASK, %l0
435
	and %g1, TSTATE_CWP_MASK, %l0
406
	inc %l0
436
	inc %l0
407
	and %l0, TSTATE_CWP_MASK, %l0	! %l0 mod NWINDOW
437
	and %l0, TSTATE_CWP_MASK, %l0	! %l0 mod NWINDOW
408
	rdpr %cwp, %l1
438
	rdpr %cwp, %l1
409
	cmp %l0, %l1
439
	cmp %l0, %l1
410
	bz 0f				! CWP is ok
440
	bz 0f				! CWP is ok
411
	nop
441
	nop
412
 
442
 
413
	/*
443
	/*
414
	 * Fix CWP.
444
	 * Fix CWP.
415
	 * Just for reminder, the input registers in the current window
445
	 * Just for reminder, the input registers in the current window
416
	 * are the output registers of the window to which we want to
446
	 * are the output registers of the window to which we want to
417
	 * restore. Because the fill trap fills only input and local
447
	 * restore. Because the fill trap fills only input and local
418
	 * registers of a window, we need to preserve those output
448
	 * registers of a window, we need to preserve those output
419
	 * registers manually.
449
	 * registers manually.
420
	 */
450
	 */
421
	flushw
451
	flushw
422
	mov %sp, %g1
452
	mov %sp, %g1
423
	stx %i0, [%sp + PREEMPTIBLE_HANDLER_STACK_FRAME_SIZE + STACK_BIAS + SAVED_I0]
453
	stx %i0, [%sp + PREEMPTIBLE_HANDLER_STACK_FRAME_SIZE + STACK_BIAS + SAVED_I0]
424
	stx %i1, [%sp + PREEMPTIBLE_HANDLER_STACK_FRAME_SIZE + STACK_BIAS + SAVED_I1]
454
	stx %i1, [%sp + PREEMPTIBLE_HANDLER_STACK_FRAME_SIZE + STACK_BIAS + SAVED_I1]
425
	stx %i2, [%sp + PREEMPTIBLE_HANDLER_STACK_FRAME_SIZE + STACK_BIAS + SAVED_I2]
455
	stx %i2, [%sp + PREEMPTIBLE_HANDLER_STACK_FRAME_SIZE + STACK_BIAS + SAVED_I2]
426
	stx %i3, [%sp + PREEMPTIBLE_HANDLER_STACK_FRAME_SIZE + STACK_BIAS + SAVED_I3]
456
	stx %i3, [%sp + PREEMPTIBLE_HANDLER_STACK_FRAME_SIZE + STACK_BIAS + SAVED_I3]
427
	stx %i4, [%sp + PREEMPTIBLE_HANDLER_STACK_FRAME_SIZE + STACK_BIAS + SAVED_I4]
457
	stx %i4, [%sp + PREEMPTIBLE_HANDLER_STACK_FRAME_SIZE + STACK_BIAS + SAVED_I4]
428
	stx %i5, [%sp + PREEMPTIBLE_HANDLER_STACK_FRAME_SIZE + STACK_BIAS + SAVED_I5]
458
	stx %i5, [%sp + PREEMPTIBLE_HANDLER_STACK_FRAME_SIZE + STACK_BIAS + SAVED_I5]
429
	stx %i6, [%sp + PREEMPTIBLE_HANDLER_STACK_FRAME_SIZE + STACK_BIAS + SAVED_I6]
459
	stx %i6, [%sp + PREEMPTIBLE_HANDLER_STACK_FRAME_SIZE + STACK_BIAS + SAVED_I6]
430
	stx %i7, [%sp + PREEMPTIBLE_HANDLER_STACK_FRAME_SIZE + STACK_BIAS + SAVED_I7]
460
	stx %i7, [%sp + PREEMPTIBLE_HANDLER_STACK_FRAME_SIZE + STACK_BIAS + SAVED_I7]
431
	wrpr %l0, 0, %cwp
461
	wrpr %l0, 0, %cwp
432
	mov %g1, %sp
462
	mov %g1, %sp
433
	ldx [%sp + PREEMPTIBLE_HANDLER_STACK_FRAME_SIZE + STACK_BIAS + SAVED_I0], %i0
463
	ldx [%sp + PREEMPTIBLE_HANDLER_STACK_FRAME_SIZE + STACK_BIAS + SAVED_I0], %i0
434
	ldx [%sp + PREEMPTIBLE_HANDLER_STACK_FRAME_SIZE + STACK_BIAS + SAVED_I1], %i1
464
	ldx [%sp + PREEMPTIBLE_HANDLER_STACK_FRAME_SIZE + STACK_BIAS + SAVED_I1], %i1
435
	ldx [%sp + PREEMPTIBLE_HANDLER_STACK_FRAME_SIZE + STACK_BIAS + SAVED_I2], %i2
465
	ldx [%sp + PREEMPTIBLE_HANDLER_STACK_FRAME_SIZE + STACK_BIAS + SAVED_I2], %i2
436
	ldx [%sp + PREEMPTIBLE_HANDLER_STACK_FRAME_SIZE + STACK_BIAS + SAVED_I3], %i3
466
	ldx [%sp + PREEMPTIBLE_HANDLER_STACK_FRAME_SIZE + STACK_BIAS + SAVED_I3], %i3
437
	ldx [%sp + PREEMPTIBLE_HANDLER_STACK_FRAME_SIZE + STACK_BIAS + SAVED_I4], %i4
467
	ldx [%sp + PREEMPTIBLE_HANDLER_STACK_FRAME_SIZE + STACK_BIAS + SAVED_I4], %i4
438
	ldx [%sp + PREEMPTIBLE_HANDLER_STACK_FRAME_SIZE + STACK_BIAS + SAVED_I5], %i5
468
	ldx [%sp + PREEMPTIBLE_HANDLER_STACK_FRAME_SIZE + STACK_BIAS + SAVED_I5], %i5
439
	ldx [%sp + PREEMPTIBLE_HANDLER_STACK_FRAME_SIZE + STACK_BIAS + SAVED_I6], %i6
469
	ldx [%sp + PREEMPTIBLE_HANDLER_STACK_FRAME_SIZE + STACK_BIAS + SAVED_I6], %i6
440
	ldx [%sp + PREEMPTIBLE_HANDLER_STACK_FRAME_SIZE + STACK_BIAS + SAVED_I7], %i7
470
	ldx [%sp + PREEMPTIBLE_HANDLER_STACK_FRAME_SIZE + STACK_BIAS + SAVED_I7], %i7
441
 
471
 
442
	/*
472
	/*
443
	 * OTHERWIN != 0 or fall-through from the OTHERWIN == 0 case.
473
	 * OTHERWIN != 0 or fall-through from the OTHERWIN == 0 case.
444
	 */
474
	 */
445
0:
475
0:
446
	! TODO: restore register windows from register window memory buffer
476
	! TODO: restore register windows from register window memory buffer
447
 
477
 
448
	restore
478
	restore
449
	retry
479
	retry
450
 
480