Subversion Repositories HelenOS

Rev

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

Rev 1860 Rev 1861
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/mm/mmu.h>
43
#include <arch/mm/mmu.h>
44
#include <arch/mm/page.h>
44
#include <arch/mm/page.h>
45
#include <arch/stack.h>
45
#include <arch/stack.h>
46
#include <arch/regdef.h>
46
#include <arch/regdef.h>
47
 
47
 
48
#define TABLE_SIZE	TRAP_TABLE_SIZE
48
#define TABLE_SIZE	TRAP_TABLE_SIZE
49
#define ENTRY_SIZE	TRAP_TABLE_ENTRY_SIZE
49
#define ENTRY_SIZE	TRAP_TABLE_ENTRY_SIZE
50
 
50
 
51
/*
51
/*
52
 * Kernel trap table.
52
 * Kernel trap table.
53
 */
53
 */
54
.align TABLE_SIZE
54
.align TABLE_SIZE
55
.global trap_table
55
.global trap_table
56
trap_table:
56
trap_table:
57
 
57
 
58
/* TT = 0x08, TL = 0, instruction_access_exception */
58
/* TT = 0x08, TL = 0, instruction_access_exception */
59
.org trap_table + TT_INSTRUCTION_ACCESS_EXCEPTION*ENTRY_SIZE
59
.org trap_table + TT_INSTRUCTION_ACCESS_EXCEPTION*ENTRY_SIZE
60
.global instruction_access_exception
60
.global instruction_access_exception
61
instruction_access_exception:
61
instruction_access_exception:
62
	SIMPLE_HANDLER do_instruction_access_exc
62
	PREEMPTIBLE_HANDLER do_instruction_access_exc
63
 
63
 
64
/* TT = 0x10, TL = 0, illegal_instruction */
64
/* TT = 0x10, TL = 0, illegal_instruction */
65
.org trap_table + TT_ILLEGAL_INSTRUCTION*ENTRY_SIZE
65
.org trap_table + TT_ILLEGAL_INSTRUCTION*ENTRY_SIZE
66
.global illegal_instruction
66
.global illegal_instruction
67
illegal_instruction:
67
illegal_instruction:
68
	SIMPLE_HANDLER do_illegal_instruction
68
	PREEMPTIBLE_HANDLER do_illegal_instruction
69
 
69
 
70
/* TT = 0x24, TL = 0, clean_window handler */
70
/* TT = 0x24, TL = 0, clean_window handler */
71
.org trap_table + TT_CLEAN_WINDOW*ENTRY_SIZE
71
.org trap_table + TT_CLEAN_WINDOW*ENTRY_SIZE
72
.global clean_window_handler
72
.global clean_window_handler
73
clean_window_handler:
73
clean_window_handler:
74
	CLEAN_WINDOW_HANDLER
74
	CLEAN_WINDOW_HANDLER
75
 
75
 
76
/* TT = 0x32, TL = 0, data_access_error */
76
/* TT = 0x32, TL = 0, data_access_error */
77
.org trap_table + TT_DATA_ACCESS_ERROR*ENTRY_SIZE
77
.org trap_table + TT_DATA_ACCESS_ERROR*ENTRY_SIZE
78
.global data_access_error
78
.global data_access_error
79
data_access_error:
79
data_access_error:
80
	SIMPLE_HANDLER do_data_access_error
80
	PREEMPTIBLE_HANDLER do_data_access_error
81
 
81
 
82
/* TT = 0x34, TL = 0, mem_address_not_aligned */
82
/* TT = 0x34, TL = 0, mem_address_not_aligned */
83
.org trap_table + TT_MEM_ADDRESS_NOT_ALIGNED*ENTRY_SIZE
83
.org trap_table + TT_MEM_ADDRESS_NOT_ALIGNED*ENTRY_SIZE
84
.global mem_address_not_aligned
84
.global mem_address_not_aligned
85
mem_address_not_aligned:
85
mem_address_not_aligned:
86
	SIMPLE_HANDLER do_mem_address_not_aligned
86
	PREEMPTIBLE_HANDLER do_mem_address_not_aligned
87
 
87
 
88
/* TT = 0x41, TL = 0, interrupt_level_1 handler */
88
/* TT = 0x41, TL = 0, interrupt_level_1 handler */
89
.org trap_table + TT_INTERRUPT_LEVEL_1*ENTRY_SIZE
89
.org trap_table + TT_INTERRUPT_LEVEL_1*ENTRY_SIZE
90
.global interrupt_level_1_handler
90
.global interrupt_level_1_handler
91
interrupt_level_1_handler:
91
interrupt_level_1_handler:
92
	INTERRUPT_LEVEL_N_HANDLER 1
92
	INTERRUPT_LEVEL_N_HANDLER 1
93
 
93
 
94
/* TT = 0x42, TL = 0, interrupt_level_2 handler */
94
/* TT = 0x42, TL = 0, interrupt_level_2 handler */
95
.org trap_table + TT_INTERRUPT_LEVEL_2*ENTRY_SIZE
95
.org trap_table + TT_INTERRUPT_LEVEL_2*ENTRY_SIZE
96
.global interrupt_level_2_handler
96
.global interrupt_level_2_handler
97
interrupt_level_2_handler:
97
interrupt_level_2_handler:
98
	INTERRUPT_LEVEL_N_HANDLER 2
98
	INTERRUPT_LEVEL_N_HANDLER 2
99
 
99
 
100
/* TT = 0x43, TL = 0, interrupt_level_3 handler */
100
/* TT = 0x43, TL = 0, interrupt_level_3 handler */
101
.org trap_table + TT_INTERRUPT_LEVEL_3*ENTRY_SIZE
101
.org trap_table + TT_INTERRUPT_LEVEL_3*ENTRY_SIZE
102
.global interrupt_level_3_handler
102
.global interrupt_level_3_handler
103
interrupt_level_3_handler:
103
interrupt_level_3_handler:
104
	INTERRUPT_LEVEL_N_HANDLER 3
104
	INTERRUPT_LEVEL_N_HANDLER 3
105
 
105
 
106
/* TT = 0x44, TL = 0, interrupt_level_4 handler */
106
/* TT = 0x44, TL = 0, interrupt_level_4 handler */
107
.org trap_table + TT_INTERRUPT_LEVEL_4*ENTRY_SIZE
107
.org trap_table + TT_INTERRUPT_LEVEL_4*ENTRY_SIZE
108
.global interrupt_level_4_handler
108
.global interrupt_level_4_handler
109
interrupt_level_4_handler:
109
interrupt_level_4_handler:
110
	INTERRUPT_LEVEL_N_HANDLER 4
110
	INTERRUPT_LEVEL_N_HANDLER 4
111
 
111
 
112
/* TT = 0x45, TL = 0, interrupt_level_5 handler */
112
/* TT = 0x45, TL = 0, interrupt_level_5 handler */
113
.org trap_table + TT_INTERRUPT_LEVEL_5*ENTRY_SIZE
113
.org trap_table + TT_INTERRUPT_LEVEL_5*ENTRY_SIZE
114
.global interrupt_level_5_handler
114
.global interrupt_level_5_handler
115
interrupt_level_5_handler:
115
interrupt_level_5_handler:
116
	INTERRUPT_LEVEL_N_HANDLER 5
116
	INTERRUPT_LEVEL_N_HANDLER 5
117
 
117
 
118
/* TT = 0x46, TL = 0, interrupt_level_6 handler */
118
/* TT = 0x46, TL = 0, interrupt_level_6 handler */
119
.org trap_table + TT_INTERRUPT_LEVEL_6*ENTRY_SIZE
119
.org trap_table + TT_INTERRUPT_LEVEL_6*ENTRY_SIZE
120
.global interrupt_level_6_handler
120
.global interrupt_level_6_handler
121
interrupt_level_6_handler:
121
interrupt_level_6_handler:
122
	INTERRUPT_LEVEL_N_HANDLER 6
122
	INTERRUPT_LEVEL_N_HANDLER 6
123
 
123
 
124
/* TT = 0x47, TL = 0, interrupt_level_7 handler */
124
/* TT = 0x47, TL = 0, interrupt_level_7 handler */
125
.org trap_table + TT_INTERRUPT_LEVEL_7*ENTRY_SIZE
125
.org trap_table + TT_INTERRUPT_LEVEL_7*ENTRY_SIZE
126
.global interrupt_level_7_handler
126
.global interrupt_level_7_handler
127
interrupt_level_7_handler:
127
interrupt_level_7_handler:
128
	INTERRUPT_LEVEL_N_HANDLER 7
128
	INTERRUPT_LEVEL_N_HANDLER 7
129
 
129
 
130
/* TT = 0x48, TL = 0, interrupt_level_8 handler */
130
/* TT = 0x48, TL = 0, interrupt_level_8 handler */
131
.org trap_table + TT_INTERRUPT_LEVEL_8*ENTRY_SIZE
131
.org trap_table + TT_INTERRUPT_LEVEL_8*ENTRY_SIZE
132
.global interrupt_level_8_handler
132
.global interrupt_level_8_handler
133
interrupt_level_8_handler:
133
interrupt_level_8_handler:
134
	INTERRUPT_LEVEL_N_HANDLER 8
134
	INTERRUPT_LEVEL_N_HANDLER 8
135
 
135
 
136
/* TT = 0x49, TL = 0, interrupt_level_9 handler */
136
/* TT = 0x49, TL = 0, interrupt_level_9 handler */
137
.org trap_table + TT_INTERRUPT_LEVEL_9*ENTRY_SIZE
137
.org trap_table + TT_INTERRUPT_LEVEL_9*ENTRY_SIZE
138
.global interrupt_level_9_handler
138
.global interrupt_level_9_handler
139
interrupt_level_9_handler:
139
interrupt_level_9_handler:
140
	INTERRUPT_LEVEL_N_HANDLER 9
140
	INTERRUPT_LEVEL_N_HANDLER 9
141
 
141
 
142
/* TT = 0x4a, TL = 0, interrupt_level_10 handler */
142
/* TT = 0x4a, TL = 0, interrupt_level_10 handler */
143
.org trap_table + TT_INTERRUPT_LEVEL_10*ENTRY_SIZE
143
.org trap_table + TT_INTERRUPT_LEVEL_10*ENTRY_SIZE
144
.global interrupt_level_10_handler
144
.global interrupt_level_10_handler
145
interrupt_level_10_handler:
145
interrupt_level_10_handler:
146
	INTERRUPT_LEVEL_N_HANDLER 10
146
	INTERRUPT_LEVEL_N_HANDLER 10
147
 
147
 
148
/* TT = 0x4b, TL = 0, interrupt_level_11 handler */
148
/* TT = 0x4b, TL = 0, interrupt_level_11 handler */
149
.org trap_table + TT_INTERRUPT_LEVEL_11*ENTRY_SIZE
149
.org trap_table + TT_INTERRUPT_LEVEL_11*ENTRY_SIZE
150
.global interrupt_level_11_handler
150
.global interrupt_level_11_handler
151
interrupt_level_11_handler:
151
interrupt_level_11_handler:
152
	INTERRUPT_LEVEL_N_HANDLER 11
152
	INTERRUPT_LEVEL_N_HANDLER 11
153
 
153
 
154
/* TT = 0x4c, TL = 0, interrupt_level_12 handler */
154
/* TT = 0x4c, TL = 0, interrupt_level_12 handler */
155
.org trap_table + TT_INTERRUPT_LEVEL_12*ENTRY_SIZE
155
.org trap_table + TT_INTERRUPT_LEVEL_12*ENTRY_SIZE
156
.global interrupt_level_12_handler
156
.global interrupt_level_12_handler
157
interrupt_level_12_handler:
157
interrupt_level_12_handler:
158
	INTERRUPT_LEVEL_N_HANDLER 12
158
	INTERRUPT_LEVEL_N_HANDLER 12
159
 
159
 
160
/* TT = 0x4d, TL = 0, interrupt_level_13 handler */
160
/* TT = 0x4d, TL = 0, interrupt_level_13 handler */
161
.org trap_table + TT_INTERRUPT_LEVEL_13*ENTRY_SIZE
161
.org trap_table + TT_INTERRUPT_LEVEL_13*ENTRY_SIZE
162
.global interrupt_level_13_handler
162
.global interrupt_level_13_handler
163
interrupt_level_13_handler:
163
interrupt_level_13_handler:
164
	INTERRUPT_LEVEL_N_HANDLER 13
164
	INTERRUPT_LEVEL_N_HANDLER 13
165
 
165
 
166
/* TT = 0x4e, TL = 0, interrupt_level_14 handler */
166
/* TT = 0x4e, TL = 0, interrupt_level_14 handler */
167
.org trap_table + TT_INTERRUPT_LEVEL_14*ENTRY_SIZE
167
.org trap_table + TT_INTERRUPT_LEVEL_14*ENTRY_SIZE
168
.global interrupt_level_14_handler
168
.global interrupt_level_14_handler
169
interrupt_level_14_handler:
169
interrupt_level_14_handler:
170
	INTERRUPT_LEVEL_N_HANDLER 14
170
	INTERRUPT_LEVEL_N_HANDLER 14
171
 
171
 
172
/* TT = 0x4f, TL = 0, interrupt_level_15 handler */
172
/* TT = 0x4f, TL = 0, interrupt_level_15 handler */
173
.org trap_table + TT_INTERRUPT_LEVEL_15*ENTRY_SIZE
173
.org trap_table + TT_INTERRUPT_LEVEL_15*ENTRY_SIZE
174
.global interrupt_level_15_handler
174
.global interrupt_level_15_handler
175
interrupt_level_15_handler:
175
interrupt_level_15_handler:
176
	INTERRUPT_LEVEL_N_HANDLER 15
176
	INTERRUPT_LEVEL_N_HANDLER 15
177
 
177
 
178
/* TT = 0x60, TL = 0, interrupt_vector_trap handler */
178
/* TT = 0x60, TL = 0, interrupt_vector_trap handler */
179
.org trap_table + TT_INTERRUPT_VECTOR_TRAP*ENTRY_SIZE
179
.org trap_table + TT_INTERRUPT_VECTOR_TRAP*ENTRY_SIZE
180
.global interrupt_vector_trap_handler
180
.global interrupt_vector_trap_handler
181
interrupt_vector_trap_handler:
181
interrupt_vector_trap_handler:
182
	INTERRUPT_VECTOR_TRAP_HANDLER
182
	INTERRUPT_VECTOR_TRAP_HANDLER
183
 
183
 
184
/* TT = 0x64, TL = 0, fast_instruction_access_MMU_miss */
184
/* TT = 0x64, TL = 0, fast_instruction_access_MMU_miss */
185
.org trap_table + TT_FAST_INSTRUCTION_ACCESS_MMU_MISS*ENTRY_SIZE
185
.org trap_table + TT_FAST_INSTRUCTION_ACCESS_MMU_MISS*ENTRY_SIZE
186
.global fast_instruction_access_mmu_miss_handler
186
.global fast_instruction_access_mmu_miss_handler
187
fast_instruction_access_mmu_miss_handler:
187
fast_instruction_access_mmu_miss_handler:
188
	FAST_INSTRUCTION_ACCESS_MMU_MISS_HANDLER
188
	FAST_INSTRUCTION_ACCESS_MMU_MISS_HANDLER
189
 
189
 
190
/* TT = 0x68, TL = 0, fast_data_access_MMU_miss */
190
/* TT = 0x68, TL = 0, fast_data_access_MMU_miss */
191
.org trap_table + TT_FAST_DATA_ACCESS_MMU_MISS*ENTRY_SIZE
191
.org trap_table + TT_FAST_DATA_ACCESS_MMU_MISS*ENTRY_SIZE
192
.global fast_data_access_mmu_miss_handler
192
.global fast_data_access_mmu_miss_handler
193
fast_data_access_mmu_miss_handler:
193
fast_data_access_mmu_miss_handler:
194
	FAST_DATA_ACCESS_MMU_MISS_HANDLER
194
	FAST_DATA_ACCESS_MMU_MISS_HANDLER
195
 
195
 
196
/* TT = 0x6c, TL = 0, fast_data_access_protection */
196
/* TT = 0x6c, TL = 0, fast_data_access_protection */
197
.org trap_table + TT_FAST_DATA_ACCESS_PROTECTION*ENTRY_SIZE
197
.org trap_table + TT_FAST_DATA_ACCESS_PROTECTION*ENTRY_SIZE
198
.global fast_data_access_protection_handler
198
.global fast_data_access_protection_handler
199
fast_data_access_protection_handler:
199
fast_data_access_protection_handler:
200
	FAST_DATA_ACCESS_PROTECTION_HANDLER
200
	FAST_DATA_ACCESS_PROTECTION_HANDLER
201
 
201
 
202
/* TT = 0x80, TL = 0, spill_0_normal handler */
202
/* TT = 0x80, TL = 0, spill_0_normal handler */
203
.org trap_table + TT_SPILL_0_NORMAL*ENTRY_SIZE
203
.org trap_table + TT_SPILL_0_NORMAL*ENTRY_SIZE
204
.global spill_0_normal
204
.global spill_0_normal
205
spill_0_normal:
205
spill_0_normal:
206
	SPILL_NORMAL_HANDLER_KERNEL
206
	SPILL_NORMAL_HANDLER_KERNEL
207
 
207
 
208
/* TT = 0x84, TL = 0, spill_1_normal handler */
208
/* TT = 0x84, TL = 0, spill_1_normal handler */
209
.org trap_table + TT_SPILL_1_NORMAL*ENTRY_SIZE
209
.org trap_table + TT_SPILL_1_NORMAL*ENTRY_SIZE
210
.global spill_1_normal
210
.global spill_1_normal
211
spill_1_normal:
211
spill_1_normal:
212
	SPILL_NORMAL_HANDLER_USERSPACE
212
	SPILL_NORMAL_HANDLER_USERSPACE
213
 
213
 
214
/* TT = 0x88, TL = 0, spill_2_normal handler */
214
/* TT = 0x88, TL = 0, spill_2_normal handler */
215
.org trap_table + TT_SPILL_2_NORMAL*ENTRY_SIZE
215
.org trap_table + TT_SPILL_2_NORMAL*ENTRY_SIZE
216
.global spill_2_normal
216
.global spill_2_normal
217
spill_2_normal:
217
spill_2_normal:
218
	SPILL_TO_USPACE_WINDOW_BUFFER
218
	SPILL_TO_USPACE_WINDOW_BUFFER
219
 
219
 
220
/* TT = 0xc0, TL = 0, fill_0_normal handler */
220
/* TT = 0xc0, TL = 0, fill_0_normal handler */
221
.org trap_table + TT_FILL_0_NORMAL*ENTRY_SIZE
221
.org trap_table + TT_FILL_0_NORMAL*ENTRY_SIZE
222
.global fill_0_normal
222
.global fill_0_normal
223
fill_0_normal:
223
fill_0_normal:
224
	FILL_NORMAL_HANDLER_KERNEL
224
	FILL_NORMAL_HANDLER_KERNEL
225
 
225
 
226
/* TT = 0xc4, TL = 0, fill_1_normal handler */
226
/* TT = 0xc4, TL = 0, fill_1_normal handler */
227
.org trap_table + TT_FILL_1_NORMAL*ENTRY_SIZE
227
.org trap_table + TT_FILL_1_NORMAL*ENTRY_SIZE
228
.global fill_1_normal
228
.global fill_1_normal
229
fill_1_normal:
229
fill_1_normal:
230
	FILL_NORMAL_HANDLER_USERSPACE
230
	FILL_NORMAL_HANDLER_USERSPACE
231
 
231
 
232
/*
232
/*
233
 * Handlers for TL>0.
233
 * Handlers for TL>0.
234
 */
234
 */
235
 
235
 
236
/* TT = 0x08, TL > 0, instruction_access_exception */
236
/* TT = 0x08, TL > 0, instruction_access_exception */
237
.org trap_table + (TT_INSTRUCTION_ACCESS_EXCEPTION+512)*ENTRY_SIZE
237
.org trap_table + (TT_INSTRUCTION_ACCESS_EXCEPTION+512)*ENTRY_SIZE
238
.global instruction_access_exception_high
238
.global instruction_access_exception_high
239
instruction_access_exception_high:
239
instruction_access_exception_high:
240
	SIMPLE_HANDLER do_instruction_access_exc
240
	PREEMPTIBLE_HANDLER do_instruction_access_exc
241
 
241
 
242
/* TT = 0x10, TL > 0, illegal_instruction */
242
/* TT = 0x10, TL > 0, illegal_instruction */
243
.org trap_table + (TT_ILLEGAL_INSTRUCTION+512)*ENTRY_SIZE
243
.org trap_table + (TT_ILLEGAL_INSTRUCTION+512)*ENTRY_SIZE
244
.global illegal_instruction_high
244
.global illegal_instruction_high
245
illegal_instruction_high:
245
illegal_instruction_high:
246
	SIMPLE_HANDLER do_illegal_instruction
246
	PREEMPTIBLE_HANDLER do_illegal_instruction
247
 
247
 
248
/* TT = 0x24, TL > 0, clean_window handler */
248
/* TT = 0x24, TL > 0, clean_window handler */
249
.org trap_table + (TT_CLEAN_WINDOW+512)*ENTRY_SIZE
249
.org trap_table + (TT_CLEAN_WINDOW+512)*ENTRY_SIZE
250
.global clean_window_handler_high
250
.global clean_window_handler_high
251
clean_window_handler_high:
251
clean_window_handler_high:
252
	CLEAN_WINDOW_HANDLER
252
	CLEAN_WINDOW_HANDLER
253
 
253
 
254
/* TT = 0x32, TL > 0, data_access_error */
254
/* TT = 0x32, TL > 0, data_access_error */
255
.org trap_table + (TT_DATA_ACCESS_ERROR+512)*ENTRY_SIZE
255
.org trap_table + (TT_DATA_ACCESS_ERROR+512)*ENTRY_SIZE
256
.global data_access_error_high
256
.global data_access_error_high
257
data_access_error_high:
257
data_access_error_high:
258
	SIMPLE_HANDLER do_data_access_error
258
	PREEMPTIBLE_HANDLER do_data_access_error
259
 
259
 
260
/* TT = 0x34, TL > 0, mem_address_not_aligned */
260
/* TT = 0x34, TL > 0, mem_address_not_aligned */
261
.org trap_table + (TT_MEM_ADDRESS_NOT_ALIGNED+512)*ENTRY_SIZE
261
.org trap_table + (TT_MEM_ADDRESS_NOT_ALIGNED+512)*ENTRY_SIZE
262
.global mem_address_not_aligned_high
262
.global mem_address_not_aligned_high
263
mem_address_not_aligned_high:
263
mem_address_not_aligned_high:
264
	SIMPLE_HANDLER do_mem_address_not_aligned
264
	PREEMPTIBLE_HANDLER do_mem_address_not_aligned
265
 
265
 
266
/* TT = 0x64, TL > 0, fast_instruction_access_MMU_miss */
266
/* TT = 0x64, TL > 0, fast_instruction_access_MMU_miss */
267
.org trap_table + (TT_FAST_INSTRUCTION_ACCESS_MMU_MISS+512)*ENTRY_SIZE
267
.org trap_table + (TT_FAST_INSTRUCTION_ACCESS_MMU_MISS+512)*ENTRY_SIZE
268
.global fast_instruction_access_mmu_miss_handler_high
268
.global fast_instruction_access_mmu_miss_handler_high
269
fast_instruction_access_mmu_miss_handler_high:
269
fast_instruction_access_mmu_miss_handler_high:
270
	FAST_INSTRUCTION_ACCESS_MMU_MISS_HANDLER
270
	FAST_INSTRUCTION_ACCESS_MMU_MISS_HANDLER
271
 
271
 
272
/* TT = 0x68, TL > 0, fast_data_access_MMU_miss */
272
/* TT = 0x68, TL > 0, fast_data_access_MMU_miss */
273
.org trap_table + (TT_FAST_DATA_ACCESS_MMU_MISS+512)*ENTRY_SIZE
273
.org trap_table + (TT_FAST_DATA_ACCESS_MMU_MISS+512)*ENTRY_SIZE
274
.global fast_data_access_mmu_miss_handler_high
274
.global fast_data_access_mmu_miss_handler_high
275
fast_data_access_mmu_miss_handler_high:
275
fast_data_access_mmu_miss_handler_high:
276
	FAST_DATA_ACCESS_MMU_MISS_HANDLER
276
	FAST_DATA_ACCESS_MMU_MISS_HANDLER
277
 
277
 
278
/* TT = 0x6c, TL > 0, fast_data_access_protection */
278
/* TT = 0x6c, TL > 0, fast_data_access_protection */
279
.org trap_table + (TT_FAST_DATA_ACCESS_PROTECTION+512)*ENTRY_SIZE
279
.org trap_table + (TT_FAST_DATA_ACCESS_PROTECTION+512)*ENTRY_SIZE
280
.global fast_data_access_protection_handler_high
280
.global fast_data_access_protection_handler_high
281
fast_data_access_protection_handler_high:
281
fast_data_access_protection_handler_high:
282
	FAST_DATA_ACCESS_PROTECTION_HANDLER
282
	FAST_DATA_ACCESS_PROTECTION_HANDLER
283
 
283
 
284
/* TT = 0x80, TL > 0, spill_0_normal handler */
284
/* TT = 0x80, TL > 0, spill_0_normal handler */
285
.org trap_table + (TT_SPILL_0_NORMAL+512)*ENTRY_SIZE
285
.org trap_table + (TT_SPILL_0_NORMAL+512)*ENTRY_SIZE
286
.global spill_0_normal_high
286
.global spill_0_normal_high
287
spill_0_normal_high:
287
spill_0_normal_high:
288
	SPILL_NORMAL_HANDLER_KERNEL
288
	SPILL_NORMAL_HANDLER_KERNEL
289
 
289
 
290
/* TT = 0x88, TL > 0, spill_2_normal handler */
290
/* TT = 0x88, TL > 0, spill_2_normal handler */
291
.org trap_table + (TT_SPILL_2_NORMAL+512)*ENTRY_SIZE
291
.org trap_table + (TT_SPILL_2_NORMAL+512)*ENTRY_SIZE
292
.global spill_2_normal_high
292
.global spill_2_normal_high
293
spill_2_normal_high:
293
spill_2_normal_high:
294
	SPILL_TO_USPACE_WINDOW_BUFFER
294
	SPILL_TO_USPACE_WINDOW_BUFFER
295
 
295
 
296
/* TT = 0xa0, TL > 0, spill_0_other handler */
296
/* TT = 0xa0, TL > 0, spill_0_other handler */
297
.org trap_table + (TT_SPILL_0_OTHER+512)*ENTRY_SIZE
297
.org trap_table + (TT_SPILL_0_OTHER+512)*ENTRY_SIZE
298
.global spill_0_other_high
298
.global spill_0_other_high
299
spill_0_other_high:
299
spill_0_other_high:
300
	SPILL_TO_USPACE_WINDOW_BUFFER
300
	SPILL_TO_USPACE_WINDOW_BUFFER
301
 
301
 
302
/* TT = 0xc0, TL > 0, fill_0_normal handler */
302
/* TT = 0xc0, TL > 0, fill_0_normal handler */
303
.org trap_table + (TT_FILL_0_NORMAL+512)*ENTRY_SIZE
303
.org trap_table + (TT_FILL_0_NORMAL+512)*ENTRY_SIZE
304
.global fill_0_normal_high
304
.global fill_0_normal_high
305
fill_0_normal_high:
305
fill_0_normal_high:
306
	FILL_NORMAL_HANDLER_KERNEL
306
	FILL_NORMAL_HANDLER_KERNEL
307
 
307
 
308
 
308
 
309
/* Preemptible trap handler for TL=1.
309
/* Preemptible trap handler for TL=1.
310
 *
310
 *
311
 * This trap handler makes arrangements to make calling of scheduler() from
311
 * This trap handler makes arrangements to make calling of scheduler() from
312
 * within a trap context possible. It is called from several other trap
312
 * within a trap context possible. It is called from several other trap
313
 * handlers.
313
 * handlers.
314
 *
314
 *
315
 * This function can be entered either with interrupt globals or alternate globals.
315
 * This function can be entered either with interrupt globals or alternate globals.
316
 * Memory management trap handlers are obliged to switch to one of those global sets
316
 * Memory management trap handlers are obliged to switch to one of those global sets
317
 * prior to calling this function. Register window management functions are not
317
 * prior to calling this function. Register window management functions are not
318
 * allowed to modify the alternate global registers.
318
 * allowed to modify the alternate global registers.
319
 *
319
 *
320
 * Input registers:
320
 * Input registers:
321
 *	%g1		Address of function to call.
321
 *	%g1		Address of function to call.
322
 * 	%g2	 	Argument for the function.
322
 * 	%g2	 	Argument for the function.
323
 *	%g6		Pre-set as kernel stack base if trap from userspace.
323
 *	%g6		Pre-set as kernel stack base if trap from userspace.
324
 *	%g7		Pre-set as address of the userspace window buffer.
324
 *	%g7		Pre-set as address of the userspace window buffer.
325
 */
325
 */
326
.global preemptible_handler
326
.global preemptible_handler
327
preemptible_handler:
327
preemptible_handler:
328
	rdpr %tstate, %g3
328
	rdpr %tstate, %g3
329
	andcc %g3, TSTATE_PRIV_BIT, %g0		! if this trap came from the privileged mode...
329
	andcc %g3, TSTATE_PRIV_BIT, %g0		! if this trap came from the privileged mode...
330
	bnz 0f					! ...skip setting of kernel stack and primary context
330
	bnz 0f					! ...skip setting of kernel stack and primary context
331
	nop
331
	nop
332
 
332
 
333
	/*
333
	/*
334
	 * Normal window spills will go to the userspace window buffer.
334
	 * Normal window spills will go to the userspace window buffer.
335
	 */
335
	 */
336
	wrpr %g0, WSTATE_OTHER(0) | WSTATE_NORMAL(2), %wstate
336
	wrpr %g0, WSTATE_OTHER(0) | WSTATE_NORMAL(2), %wstate
337
 
337
 
338
	/*
338
	/*
339
	 * Switch to kernel stack. The old stack is
339
	 * Switch to kernel stack. The old stack is
340
	 * automatically saved in the old window's %sp
340
	 * automatically saved in the old window's %sp
341
	 * and the new window's %fp.
341
	 * and the new window's %fp.
342
	 */
342
	 */
343
	save %g6, -PREEMPTIBLE_HANDLER_STACK_FRAME_SIZE, %sp
343
	save %g6, -PREEMPTIBLE_HANDLER_STACK_FRAME_SIZE, %sp
344
 
344
 
345
	/*
345
	/*
346
	 * Mark the CANSAVE windows as OTHER windows.
346
	 * Mark the CANSAVE windows as OTHER windows.
347
	 * Set CLEANWIN to NWINDOW-1 so that clean_window traps do not occur.
347
	 * Set CLEANWIN to NWINDOW-1 so that clean_window traps do not occur.
348
	 */
348
	 */
349
	rdpr %cansave, %l0
349
	rdpr %cansave, %l0
350
	wrpr %l0, %otherwin
350
	wrpr %l0, %otherwin
351
	wrpr %g0, %cansave
351
	wrpr %g0, %cansave
352
	wrpr %g0, NWINDOW - 1, %cleanwin
352
	wrpr %g0, NWINDOW - 1, %cleanwin
353
 
353
 
354
	/*
354
	/*
355
	 * Switch to primary context 0.
355
	 * Switch to primary context 0.
356
	 */
356
	 */
357
	mov VA_PRIMARY_CONTEXT_REG, %l0
357
	mov VA_PRIMARY_CONTEXT_REG, %l0
358
	stxa %g0, [%l0] ASI_DMMU
358
	stxa %g0, [%l0] ASI_DMMU
359
	rd %pc, %l0
359
	rd %pc, %l0
360
	flush %l0
360
	flush %l0
361
 
361
 
362
	ba 1f
362
	ba 1f
363
	nop
363
	nop
364
 
364
 
365
0:
365
0:
366
	save %sp, -PREEMPTIBLE_HANDLER_STACK_FRAME_SIZE, %sp
366
	save %sp, -PREEMPTIBLE_HANDLER_STACK_FRAME_SIZE, %sp
367
 
367
 
368
	/*
368
	/*
369
	 * At this moment, we are using the kernel stack 
369
	 * At this moment, we are using the kernel stack 
370
	 * and have successfully allocated a register window.
370
	 * and have successfully allocated a register window.
371
	 */
371
	 */
372
1:
372
1:
373
	
373
	
374
	/*
374
	/*
375
	 * Other window spills will go to the userspace window buffer
375
	 * Other window spills will go to the userspace window buffer
376
	 * and normal spills will go to the kernel stack.
376
	 * and normal spills will go to the kernel stack.
377
	 */
377
	 */
378
	wrpr %g0, WSTATE_OTHER(0) | WSTATE_NORMAL(0), %wstate
378
	wrpr %g0, WSTATE_OTHER(0) | WSTATE_NORMAL(0), %wstate
379
	
379
	
380
	/*
380
	/*
381
	 * Copy arguments.
381
	 * Copy arguments.
382
	 */
382
	 */
383
	mov %g1, %l0
383
	mov %g1, %l0
384
	mov %g2, %o0
384
	mov %g2, %o0
385
 
385
 
386
	/*
386
	/*
387
	 * Save TSTATE, TPC and TNPC aside.
387
	 * Save TSTATE, TPC and TNPC aside.
388
	 */
388
	 */
389
	rdpr %tstate, %g1
389
	rdpr %tstate, %g1
390
	rdpr %tpc, %g2
390
	rdpr %tpc, %g2
391
	rdpr %tnpc, %g3
391
	rdpr %tnpc, %g3
392
 
392
 
393
	/*
393
	/*
394
	 * The following memory accesses will not fault
394
	 * The following memory accesses will not fault
395
	 * because special provisions are made to have
395
	 * because special provisions are made to have
396
	 * the kernel stack of THREAD locked in DTLB.
396
	 * the kernel stack of THREAD locked in DTLB.
397
	 */
397
	 */
398
	stx %g1, [%sp + PREEMPTIBLE_HANDLER_STACK_FRAME_SIZE + STACK_BIAS + SAVED_TSTATE]
398
	stx %g1, [%sp + PREEMPTIBLE_HANDLER_STACK_FRAME_SIZE + STACK_BIAS + SAVED_TSTATE]
399
	stx %g2, [%sp + PREEMPTIBLE_HANDLER_STACK_FRAME_SIZE + STACK_BIAS + SAVED_TPC]
399
	stx %g2, [%sp + PREEMPTIBLE_HANDLER_STACK_FRAME_SIZE + STACK_BIAS + SAVED_TPC]
400
	stx %g3, [%sp + PREEMPTIBLE_HANDLER_STACK_FRAME_SIZE + STACK_BIAS + SAVED_TNPC]
400
	stx %g3, [%sp + PREEMPTIBLE_HANDLER_STACK_FRAME_SIZE + STACK_BIAS + SAVED_TNPC]
401
	
401
	
402
	wrpr %g0, 0, %tl
402
	wrpr %g0, 0, %tl
403
	wrpr %g0, PSTATE_PRIV_BIT, %pstate
403
	wrpr %g0, PSTATE_PRIV_BIT, %pstate
404
	SAVE_GLOBALS
404
	SAVE_GLOBALS
405
	
405
	
406
	/*
406
	/*
407
	 * Call the higher-level handler and pass istate as second parameter.
407
	 * Call the higher-level handler and pass istate as second parameter.
408
	 */
408
	 */
409
	call %l0
409
	call %l0
410
	add %sp, PREEMPTIBLE_HANDLER_STACK_FRAME_SIZE + STACK_BIAS + SAVED_TNPC, %o1
410
	add %sp, PREEMPTIBLE_HANDLER_STACK_FRAME_SIZE + STACK_BIAS + SAVED_TNPC, %o1
411
 
411
 
412
	RESTORE_GLOBALS
412
	RESTORE_GLOBALS
413
	wrpr %g0, PSTATE_AG_BIT | PSTATE_PRIV_BIT, %pstate
413
	wrpr %g0, PSTATE_AG_BIT | PSTATE_PRIV_BIT, %pstate
414
	wrpr %g0, 1, %tl
414
	wrpr %g0, 1, %tl
415
	
415
	
416
	/*
416
	/*
417
	 * Read TSTATE, TPC and TNPC from saved copy.
417
	 * Read TSTATE, TPC and TNPC from saved copy.
418
	 */
418
	 */
419
	ldx [%sp + PREEMPTIBLE_HANDLER_STACK_FRAME_SIZE + STACK_BIAS + SAVED_TSTATE], %g1
419
	ldx [%sp + PREEMPTIBLE_HANDLER_STACK_FRAME_SIZE + STACK_BIAS + SAVED_TSTATE], %g1
420
	ldx [%sp + PREEMPTIBLE_HANDLER_STACK_FRAME_SIZE + STACK_BIAS + SAVED_TPC], %g2
420
	ldx [%sp + PREEMPTIBLE_HANDLER_STACK_FRAME_SIZE + STACK_BIAS + SAVED_TPC], %g2
421
	ldx [%sp + PREEMPTIBLE_HANDLER_STACK_FRAME_SIZE + STACK_BIAS + SAVED_TNPC], %g3
421
	ldx [%sp + PREEMPTIBLE_HANDLER_STACK_FRAME_SIZE + STACK_BIAS + SAVED_TNPC], %g3
422
 
422
 
423
	/*
423
	/*
424
	 * Restore TSTATE, TPC and TNPC from saved copies.
424
	 * Restore TSTATE, TPC and TNPC from saved copies.
425
	 */
425
	 */
426
	wrpr %g1, 0, %tstate
426
	wrpr %g1, 0, %tstate
427
	wrpr %g2, 0, %tpc
427
	wrpr %g2, 0, %tpc
428
	wrpr %g3, 0, %tnpc
428
	wrpr %g3, 0, %tnpc
429
 
429
 
430
	/*
430
	/*
431
	 * If OTHERWIN is zero, then all the userspace windows have been
431
	 * If OTHERWIN is zero, then all the userspace windows have been
432
	 * spilled to kernel memory (i.e. register window buffer). If
432
	 * spilled to kernel memory (i.e. register window buffer). If
433
	 * OTHERWIN is non-zero, then some userspace windows are still
433
	 * OTHERWIN is non-zero, then some userspace windows are still
434
	 * valid. Others might have been spilled. However, the CWP pointer
434
	 * valid. Others might have been spilled. However, the CWP pointer
435
	 * needs no fixing because the scheduler had not been called.
435
	 * needs no fixing because the scheduler had not been called.
436
	 */
436
	 */
437
	rdpr %otherwin, %l0
437
	rdpr %otherwin, %l0
438
	brnz %l0, 0f
438
	brnz %l0, 0f
439
	nop
439
	nop
440
 
440
 
441
	/*
441
	/*
442
	 * OTHERWIN == 0
442
	 * OTHERWIN == 0
443
	 */
443
	 */
444
 
444
 
445
	/*
445
	/*
446
	 * If TSTATE.CWP + 1 == CWP, then we still do not have to fix CWP.
446
	 * If TSTATE.CWP + 1 == CWP, then we still do not have to fix CWP.
447
	 */
447
	 */
448
	and %g1, TSTATE_CWP_MASK, %l0
448
	and %g1, TSTATE_CWP_MASK, %l0
449
	inc %l0
449
	inc %l0
450
	and %l0, TSTATE_CWP_MASK, %l0	! %l0 mod NWINDOW
450
	and %l0, TSTATE_CWP_MASK, %l0	! %l0 mod NWINDOW
451
	rdpr %cwp, %l1
451
	rdpr %cwp, %l1
452
	cmp %l0, %l1
452
	cmp %l0, %l1
453
	bz 0f				! CWP is ok
453
	bz 0f				! CWP is ok
454
	nop
454
	nop
455
 
455
 
456
	/*
456
	/*
457
	 * Fix CWP.
457
	 * Fix CWP.
458
	 * Just for reminder, the input registers in the current window
458
	 * Just for reminder, the input registers in the current window
459
	 * are the output registers of the window to which we want to
459
	 * are the output registers of the window to which we want to
460
	 * restore. Because the fill trap fills only input and local
460
	 * restore. Because the fill trap fills only input and local
461
	 * registers of a window, we need to preserve those output
461
	 * registers of a window, we need to preserve those output
462
	 * registers manually.
462
	 * registers manually.
463
	 */
463
	 */
464
	flushw
464
	flushw
465
	mov %sp, %g2
465
	mov %sp, %g2
466
	stx %i0, [%sp + PREEMPTIBLE_HANDLER_STACK_FRAME_SIZE + STACK_BIAS + SAVED_I0]
466
	stx %i0, [%sp + PREEMPTIBLE_HANDLER_STACK_FRAME_SIZE + STACK_BIAS + SAVED_I0]
467
	stx %i1, [%sp + PREEMPTIBLE_HANDLER_STACK_FRAME_SIZE + STACK_BIAS + SAVED_I1]
467
	stx %i1, [%sp + PREEMPTIBLE_HANDLER_STACK_FRAME_SIZE + STACK_BIAS + SAVED_I1]
468
	stx %i2, [%sp + PREEMPTIBLE_HANDLER_STACK_FRAME_SIZE + STACK_BIAS + SAVED_I2]
468
	stx %i2, [%sp + PREEMPTIBLE_HANDLER_STACK_FRAME_SIZE + STACK_BIAS + SAVED_I2]
469
	stx %i3, [%sp + PREEMPTIBLE_HANDLER_STACK_FRAME_SIZE + STACK_BIAS + SAVED_I3]
469
	stx %i3, [%sp + PREEMPTIBLE_HANDLER_STACK_FRAME_SIZE + STACK_BIAS + SAVED_I3]
470
	stx %i4, [%sp + PREEMPTIBLE_HANDLER_STACK_FRAME_SIZE + STACK_BIAS + SAVED_I4]
470
	stx %i4, [%sp + PREEMPTIBLE_HANDLER_STACK_FRAME_SIZE + STACK_BIAS + SAVED_I4]
471
	stx %i5, [%sp + PREEMPTIBLE_HANDLER_STACK_FRAME_SIZE + STACK_BIAS + SAVED_I5]
471
	stx %i5, [%sp + PREEMPTIBLE_HANDLER_STACK_FRAME_SIZE + STACK_BIAS + SAVED_I5]
472
	stx %i6, [%sp + PREEMPTIBLE_HANDLER_STACK_FRAME_SIZE + STACK_BIAS + SAVED_I6]
472
	stx %i6, [%sp + PREEMPTIBLE_HANDLER_STACK_FRAME_SIZE + STACK_BIAS + SAVED_I6]
473
	stx %i7, [%sp + PREEMPTIBLE_HANDLER_STACK_FRAME_SIZE + STACK_BIAS + SAVED_I7]
473
	stx %i7, [%sp + PREEMPTIBLE_HANDLER_STACK_FRAME_SIZE + STACK_BIAS + SAVED_I7]
474
	wrpr %l0, 0, %cwp
474
	wrpr %l0, 0, %cwp
475
	mov %g2, %sp
475
	mov %g2, %sp
476
	ldx [%sp + PREEMPTIBLE_HANDLER_STACK_FRAME_SIZE + STACK_BIAS + SAVED_I0], %i0
476
	ldx [%sp + PREEMPTIBLE_HANDLER_STACK_FRAME_SIZE + STACK_BIAS + SAVED_I0], %i0
477
	ldx [%sp + PREEMPTIBLE_HANDLER_STACK_FRAME_SIZE + STACK_BIAS + SAVED_I1], %i1
477
	ldx [%sp + PREEMPTIBLE_HANDLER_STACK_FRAME_SIZE + STACK_BIAS + SAVED_I1], %i1
478
	ldx [%sp + PREEMPTIBLE_HANDLER_STACK_FRAME_SIZE + STACK_BIAS + SAVED_I2], %i2
478
	ldx [%sp + PREEMPTIBLE_HANDLER_STACK_FRAME_SIZE + STACK_BIAS + SAVED_I2], %i2
479
	ldx [%sp + PREEMPTIBLE_HANDLER_STACK_FRAME_SIZE + STACK_BIAS + SAVED_I3], %i3
479
	ldx [%sp + PREEMPTIBLE_HANDLER_STACK_FRAME_SIZE + STACK_BIAS + SAVED_I3], %i3
480
	ldx [%sp + PREEMPTIBLE_HANDLER_STACK_FRAME_SIZE + STACK_BIAS + SAVED_I4], %i4
480
	ldx [%sp + PREEMPTIBLE_HANDLER_STACK_FRAME_SIZE + STACK_BIAS + SAVED_I4], %i4
481
	ldx [%sp + PREEMPTIBLE_HANDLER_STACK_FRAME_SIZE + STACK_BIAS + SAVED_I5], %i5
481
	ldx [%sp + PREEMPTIBLE_HANDLER_STACK_FRAME_SIZE + STACK_BIAS + SAVED_I5], %i5
482
	ldx [%sp + PREEMPTIBLE_HANDLER_STACK_FRAME_SIZE + STACK_BIAS + SAVED_I6], %i6
482
	ldx [%sp + PREEMPTIBLE_HANDLER_STACK_FRAME_SIZE + STACK_BIAS + SAVED_I6], %i6
483
	ldx [%sp + PREEMPTIBLE_HANDLER_STACK_FRAME_SIZE + STACK_BIAS + SAVED_I7], %i7
483
	ldx [%sp + PREEMPTIBLE_HANDLER_STACK_FRAME_SIZE + STACK_BIAS + SAVED_I7], %i7
484
 
484
 
485
	/*
485
	/*
486
	 * OTHERWIN != 0 or fall-through from the OTHERWIN == 0 case.
486
	 * OTHERWIN != 0 or fall-through from the OTHERWIN == 0 case.
487
	 * The CWP has already been restored to the value it had prior to the SAVE
487
	 * The CWP has already been restored to the value it had prior to the SAVE
488
	 * at the beginning of this function.
488
	 * at the beginning of this function.
489
	 */
489
	 */
490
0:
490
0:
491
	rdpr %tstate, %g1
491
	rdpr %tstate, %g1
492
	andcc %g1, TSTATE_PRIV_BIT, %g0		! if we are not returning to userspace...,
492
	andcc %g1, TSTATE_PRIV_BIT, %g0		! if we are not returning to userspace...,
493
	bnz 1f					! ...skip restoring userspace windows
493
	bnz 1f					! ...skip restoring userspace windows
494
	nop
494
	nop
495
 
495
 
496
	/*
496
	/*
497
	 * Spills and fills will be processed by the {spill,fill}_1_normal
497
	 * Spills and fills will be processed by the {spill,fill}_1_normal
498
	 * handlers.
498
	 * handlers.
499
	 */
499
	 */
500
	wrpr %g0, WSTATE_OTHER(0) | WSTATE_NORMAL(1), %wstate
500
	wrpr %g0, WSTATE_OTHER(0) | WSTATE_NORMAL(1), %wstate
501
 
501
 
502
	/*
502
	/*
503
	 * Set primary context according to secondary context.
503
	 * Set primary context according to secondary context.
504
	 */
504
	 */
505
	wr %g0, ASI_DMMU, %asi
505
	wr %g0, ASI_DMMU, %asi
506
	ldxa [VA_SECONDARY_CONTEXT_REG] %asi, %g1
506
	ldxa [VA_SECONDARY_CONTEXT_REG] %asi, %g1
507
	stxa %g1, [VA_PRIMARY_CONTEXT_REG] %asi
507
	stxa %g1, [VA_PRIMARY_CONTEXT_REG] %asi
508
	flush %o7
508
	flush %o7
509
	
509
	
510
	rdpr %cwp, %g1
510
	rdpr %cwp, %g1
511
	rdpr %otherwin, %g2
511
	rdpr %otherwin, %g2
512
 
512
 
513
	/*
513
	/*
514
	 * Skip all OTHERWIN windows and descend to the first window
514
	 * Skip all OTHERWIN windows and descend to the first window
515
	 * in the userspace window buffer.
515
	 * in the userspace window buffer.
516
	 */
516
	 */
517
	sub %g1, %g2, %g3
517
	sub %g1, %g2, %g3
518
	dec %g3
518
	dec %g3
519
	and %g3, NWINDOW - 1, %g3
519
	and %g3, NWINDOW - 1, %g3
520
	wrpr %g3, 0, %cwp
520
	wrpr %g3, 0, %cwp
521
 
521
 
522
	/*
522
	/*
523
	 * CWP is now in the window last saved in the userspace window buffer.
523
	 * CWP is now in the window last saved in the userspace window buffer.
524
	 * Fill all windows stored in the buffer.
524
	 * Fill all windows stored in the buffer.
525
	 */
525
	 */
526
	clr %g4
526
	clr %g4
527
0:	andcc %g7, PAGE_WIDTH - 1, %g0		! PAGE_SIZE alignment check
527
0:	andcc %g7, PAGE_WIDTH - 1, %g0		! PAGE_SIZE alignment check
528
	bz 0f					! %g7 is page-aligned, no more windows to refill
528
	bz 0f					! %g7 is page-aligned, no more windows to refill
529
	nop
529
	nop
530
 
530
 
531
	add %g7, -STACK_WINDOW_SAVE_AREA_SIZE, %g7
531
	add %g7, -STACK_WINDOW_SAVE_AREA_SIZE, %g7
532
	ldx [%g7 + L0_OFFSET], %l0
532
	ldx [%g7 + L0_OFFSET], %l0
533
	ldx [%g7 + L1_OFFSET], %l1
533
	ldx [%g7 + L1_OFFSET], %l1
534
	ldx [%g7 + L2_OFFSET], %l2
534
	ldx [%g7 + L2_OFFSET], %l2
535
	ldx [%g7 + L3_OFFSET], %l3
535
	ldx [%g7 + L3_OFFSET], %l3
536
	ldx [%g7 + L4_OFFSET], %l4
536
	ldx [%g7 + L4_OFFSET], %l4
537
	ldx [%g7 + L5_OFFSET], %l5
537
	ldx [%g7 + L5_OFFSET], %l5
538
	ldx [%g7 + L6_OFFSET], %l6
538
	ldx [%g7 + L6_OFFSET], %l6
539
	ldx [%g7 + L7_OFFSET], %l7
539
	ldx [%g7 + L7_OFFSET], %l7
540
	ldx [%g7 + I0_OFFSET], %i0
540
	ldx [%g7 + I0_OFFSET], %i0
541
	ldx [%g7 + I1_OFFSET], %i1
541
	ldx [%g7 + I1_OFFSET], %i1
542
	ldx [%g7 + I2_OFFSET], %i2
542
	ldx [%g7 + I2_OFFSET], %i2
543
	ldx [%g7 + I3_OFFSET], %i3
543
	ldx [%g7 + I3_OFFSET], %i3
544
	ldx [%g7 + I4_OFFSET], %i4
544
	ldx [%g7 + I4_OFFSET], %i4
545
	ldx [%g7 + I5_OFFSET], %i5
545
	ldx [%g7 + I5_OFFSET], %i5
546
	ldx [%g7 + I6_OFFSET], %i6
546
	ldx [%g7 + I6_OFFSET], %i6
547
	ldx [%g7 + I7_OFFSET], %i7
547
	ldx [%g7 + I7_OFFSET], %i7
548
 
548
 
549
	dec %g3
549
	dec %g3
550
	and %g3, NWINDOW - 1, %g3
550
	and %g3, NWINDOW - 1, %g3
551
	wrpr %g3, 0, %cwp			! switch to the preceeding window
551
	wrpr %g3, 0, %cwp			! switch to the preceeding window
552
 
552
 
553
	ba 0b
553
	ba 0b
554
	inc %g4
554
	inc %g4
555
 
555
 
556
0:
556
0:
557
	/*
557
	/*
558
	 * Switch back to the proper current window and adjust
558
	 * Switch back to the proper current window and adjust
559
	 * OTHERWIN, CANRESTORE, CANSAVE and CLEANWIN.
559
	 * OTHERWIN, CANRESTORE, CANSAVE and CLEANWIN.
560
	 */
560
	 */
561
	wrpr %g1, 0, %cwp
561
	wrpr %g1, 0, %cwp
562
	add %g4, %g2, %g2
562
	add %g4, %g2, %g2
563
	cmp %g2, NWINDOW - 2
563
	cmp %g2, NWINDOW - 2
564
	bg 2f					! fix the CANRESTORE=NWINDOW-1 anomaly
564
	bg 2f					! fix the CANRESTORE=NWINDOW-1 anomaly
565
	mov NWINDOW - 2, %g1			! use dealy slot for both cases
565
	mov NWINDOW - 2, %g1			! use dealy slot for both cases
566
	sub %g1, %g2, %g1
566
	sub %g1, %g2, %g1
567
	
567
	
568
	wrpr %g0, 0, %otherwin
568
	wrpr %g0, 0, %otherwin
569
	wrpr %g1, 0, %cansave			! NWINDOW - 2 - CANRESTORE
569
	wrpr %g1, 0, %cansave			! NWINDOW - 2 - CANRESTORE
570
	wrpr %g2, 0, %canrestore		! OTHERWIN + windows in the buffer
570
	wrpr %g2, 0, %canrestore		! OTHERWIN + windows in the buffer
571
	wrpr %g2, 0, %cleanwin			! avoid information leak
571
	wrpr %g2, 0, %cleanwin			! avoid information leak
572
 
572
 
573
1:
573
1:
574
	restore
574
	restore
575
	retry
575
	retry
576
 
576
 
577
	/*
577
	/*
578
	 * We got here in order to avoid inconsistency of the window state registers.
578
	 * We got here in order to avoid inconsistency of the window state registers.
579
	 * If the:
579
	 * If the:
580
	 *
580
	 *
581
	 * 	save %g6, -PREEMPTIBLE_HANDLER_STACK_FRAME_SIZE, %sp
581
	 * 	save %g6, -PREEMPTIBLE_HANDLER_STACK_FRAME_SIZE, %sp
582
	 *
582
	 *
583
	 * instruction trapped and spilled a register window into the userspace
583
	 * instruction trapped and spilled a register window into the userspace
584
	 * window buffer, we have just restored NWINDOW - 1 register windows.
584
	 * window buffer, we have just restored NWINDOW - 1 register windows.
585
	 * However, CANRESTORE can be only NWINDOW - 2 at most.
585
	 * However, CANRESTORE can be only NWINDOW - 2 at most.
586
	 *
586
	 *
587
	 * The solution is to manually switch to (CWP - 1) mod NWINDOW
587
	 * The solution is to manually switch to (CWP - 1) mod NWINDOW
588
	 * and set the window state registers so that:
588
	 * and set the window state registers so that:
589
	 *
589
	 *
590
	 * 	CANRESTORE 	= NWINDOW - 2
590
	 * 	CANRESTORE 	= NWINDOW - 2
591
	 *	CLEANWIN	= NWINDOW - 2
591
	 *	CLEANWIN	= NWINDOW - 2
592
	 *	CANSAVE 	= 0
592
	 *	CANSAVE 	= 0
593
	 *	OTHERWIN	= 0
593
	 *	OTHERWIN	= 0
594
	 *
594
	 *
595
	 * The RESTORE isntruction is therfore to be skipped.
595
	 * The RESTORE isntruction is therfore to be skipped.
596
	 */
596
	 */
597
2:
597
2:
598
	wrpr %g0, 0, %otherwin
598
	wrpr %g0, 0, %otherwin
599
	wrpr %g0, 0, %cansave
599
	wrpr %g0, 0, %cansave
600
	wrpr %g1, 0, %canrestore
600
	wrpr %g1, 0, %canrestore
601
	wrpr %g1, 0, %cleanwin
601
	wrpr %g1, 0, %cleanwin
602
 
602
 
603
	rdpr %cwp, %g1
603
	rdpr %cwp, %g1
604
	dec %g1
604
	dec %g1
605
	and %g1, NWINDOW - 1, %g1
605
	and %g1, NWINDOW - 1, %g1
606
	wrpr %g1, 0, %cwp			! CWP--
606
	wrpr %g1, 0, %cwp			! CWP--
607
	
607
	
608
	retry
608
	retry
609
 
609