Subversion Repositories HelenOS

Rev

Rev 899 | Rev 912 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
212 vana 1
#
2
# Copyright (C) 2005 Jakub Vana
478 jermar 3
# Copyright (C) 2005 Jakub Jermar
212 vana 4
# All rights reserved.
5
#
6
# Redistribution and use in source and binary forms, with or without
7
# modification, are permitted provided that the following conditions
8
# are met:
9
#
10
# - Redistributions of source code must retain the above copyright
11
#   notice, this list of conditions and the following disclaimer.
12
# - Redistributions in binary form must reproduce the above copyright
13
#   notice, this list of conditions and the following disclaimer in the
14
#   documentation and/or other materials provided with the distribution.
15
# - The name of the author may not be used to endorse or promote products
16
#   derived from this software without specific prior written permission.
17
#
18
# THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
19
# IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
20
# OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
21
# IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
22
# INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
23
# NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
24
# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
25
# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
26
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
27
# THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28
#
29
 
443 jermar 30
#include <arch/stack.h>
478 jermar 31
#include <arch/register.h>
212 vana 32
 
443 jermar 33
#define STACK_ITEMS		12
34
#define STACK_FRAME_SIZE	((STACK_ITEMS*STACK_ITEM_SIZE) + STACK_SCRATCH_AREA_SIZE)
35
 
36
#if (STACK_FRAME_SIZE % STACK_ALIGNMENT != 0)
37
#error Memory stack must be 16-byte aligned.
38
#endif
39
 
911 jermar 40
/** Partitioning of bank 0 registers. */
41
#define R_OFFS 		r16
42
#define R_HANDLER	r17
43
#define R_RET		r18
44
#define R_KSTACK	r23	/* keep in sync with before_thread_runs_arch() */
45
 
438 jermar 46
/** Heavyweight interrupt handler
47
 *
435 jermar 48
 * This macro roughly follows steps from 1 to 19 described in
49
 * Intel Itanium Architecture Software Developer's Manual, Chapter 3.4.2.
50
 *
438 jermar 51
 * HEAVYWEIGHT_HANDLER macro must cram into 16 bundles (48 instructions).
52
 * This goal is achieved by using procedure calls after RSE becomes operational.
53
 *
435 jermar 54
 * Some steps are skipped (enabling and disabling interrupts).
55
 * Some steps are not fully supported yet (e.g. interruptions
438 jermar 56
 * from userspace and floating-point context).
456 jermar 57
 *
58
 * @param offs Offset from the beginning of IVT.
59
 * @param handler Interrupt handler address.
435 jermar 60
 */
470 jermar 61
.macro HEAVYWEIGHT_HANDLER offs, handler=universal_handler
62
    .org ivt + \offs
911 jermar 63
	mov R_OFFS = \offs
64
	movl R_HANDLER = \handler ;;
470 jermar 65
	br heavyweight_handler
66
.endm
212 vana 67
 
470 jermar 68
.global heavyweight_handler
69
heavyweight_handler:
435 jermar 70
    /* 1. copy interrupt registers into bank 0 */
911 jermar 71
 
72
	/*
73
	 * Note that r24-r31 from bank0 can be used only as long as PSR.ic = 0.
74
	 */
435 jermar 75
	mov r24 = cr.iip
76
	mov r25 = cr.ipsr
77
	mov r26 = cr.iipa
78
	mov r27 = cr.isr
79
	mov r28 = cr.ifa
80
 
81
    /* 2. preserve predicate register into bank 0 */
82
	mov r29 = pr ;;
83
 
438 jermar 84
    /* 3. switch to kernel memory stack */
435 jermar 85
	/* TODO: support interruptions from userspace */
86
	/* assume kernel stack */
87
 
443 jermar 88
	add r31 = -8, r12 ;;
470 jermar 89
	add r12 = -STACK_FRAME_SIZE, r12
90
 
91
    /* 4. save registers in bank 0 into memory stack */	
443 jermar 92
	st8 [r31] = r29, -8 ;;	/* save predicate registers */
438 jermar 93
 
443 jermar 94
	st8 [r31] = r24, -8 ;;	/* save cr.iip */
95
	st8 [r31] = r25, -8 ;;	/* save cr.ipsr */
96
	st8 [r31] = r26, -8 ;;	/* save cr.iipa */
97
	st8 [r31] = r27, -8 ;;	/* save cr.isr */
470 jermar 98
	st8 [r31] = r28, -8	/* save cr.ifa */		
438 jermar 99
 
100
    /* 5. RSE switch from interrupted context */
435 jermar 101
	mov r24 = ar.rsc
102
	mov r25 = ar.pfs
103
	cover
104
	mov r26 = cr.ifs
105
 
470 jermar 106
	st8 [r31] = r24, -8;;	/* save ar.rsc */
107
	st8 [r31] = r25, -8;;	/* save ar.pfs */
443 jermar 108
	st8 [r31] = r26, -8	/* save ar.ifs */
435 jermar 109
 
470 jermar 110
	and r30 = ~3, r24 ;;
111
	mov ar.rsc = r30 ;;	/* place RSE in enforced lazy mode */
435 jermar 112
 
113
	mov r27 = ar.rnat
470 jermar 114
	mov r28 = ar.bspstore ;;
435 jermar 115
 
116
	/* assume kernel backing store */
478 jermar 117
	/* mov ar.bspstore = r28 ;; */
435 jermar 118
 
119
	mov r29 = ar.bsp
120
 
470 jermar 121
	st8 [r31] = r27, -8 ;;	/* save ar.rnat */
122
	st8 [r31] = r28, -8 ;;	/* save ar.bspstore */
456 jermar 123
	st8 [r31] = r29, -8	/* save ar.bsp */
435 jermar 124
 
125
	mov ar.rsc = r24	/* restore RSE's setting */
126
 
470 jermar 127
    /* steps 6 - 15 are done by heavyweight_handler_inner() */
911 jermar 128
	mov R_RET = b0 		/* save b0 belonging to interrupted context */
129
	br.call.sptk.many b0 = heavyweight_handler_inner
130
0:	mov b0 = R_RET		/* restore b0 belonging to the interrupted context */
438 jermar 131
 
470 jermar 132
    /* 16. RSE switch to interrupted context */
133
	cover			/* allocate zerro size frame (step 1 (from Intel Docs)) */
438 jermar 134
 
470 jermar 135
	add r31 = STACK_SCRATCH_AREA_SIZE, r12 ;;
136
 
137
	mov r28 = ar.bspstore   	/* calculate loadrs (step 2) */
138
	ld8 r29 = [r31], +8 ;;		/* load ar.bsp */
139
	sub r27 = r29 , r28 ;;
140
	shl r27 = r27, 16
141
 
142
	mov r24 = ar.rsc ;;
143
	and r30 = ~3, r24 ;;
144
	or  r24 = r30 , r27 ;;     
145
	mov ar.rsc = r24 ;;		/* place RSE in enforced lazy mode */
146
 
147
	loadrs 				/* (step 3) */
148
 
149
	ld8 r28 = [r31], +8 ;;    	/* load ar.bspstore */
150
	ld8 r27 = [r31], +8 ;;		/* load ar.rnat */
151
	ld8 r26 = [r31], +8 ;;		/* load cr.ifs */
152
	ld8 r25 = [r31], +8 ;;		/* load ar.pfs */
153
	ld8 r24 = [r31], +8 ;;		/* load ar.rsc */
154
 
478 jermar 155
	/* mov ar.bspstore = r28 ;; */	/* (step 4) */
156
	/* mov ar.rnat = r27 */		/* (step 5) */
470 jermar 157
 
158
	mov ar.pfs = r25		/* (step 6) */
159
	mov cr.ifs = r26	
160
 
161
	mov ar.rsc = r24		/* (step 7) */
162
 
163
    /* 17. restore interruption state from memory stack */
164
	ld8 r28 = [r31], +8 ;;	/* load cr.ifa */		
165
	ld8 r27 = [r31], +8 ;;	/* load cr.isr */
166
	ld8 r26 = [r31], +8 ;;	/* load cr.iipa */
167
	ld8 r25 = [r31], +8 ;;	/* load cr.ipsr */
168
	ld8 r24 = [r31], +8 ;;	/* load cr.iip */
169
 
170
	mov cr.iip = r24
171
	mov cr.ipsr = r25
172
	mov cr.iipa = r26
173
	mov cr.isr = r27
174
	mov cr.ifa = r28
175
 
176
    /* 18. restore predicate registers from memory stack */
177
	ld8 r29 = [r31] , -8 ;;	/* load predicate registers */
178
	mov pr = r29
179
 
180
    /* 19. return from interruption */
181
    	add r12 = STACK_FRAME_SIZE, r12
182
	rfi ;;
183
 
438 jermar 184
.global heavyweight_handler_inner
185
heavyweight_handler_inner:
186
	/*
187
	 * From this point, the rest of the interrupted context
188
	 * will be preserved in stacked registers and backing store.
189
	 */
470 jermar 190
	alloc loc0 = ar.pfs, 0, 47, 2, 0 ;;
438 jermar 191
 
470 jermar 192
	/* bank 0 is going to be shadowed, copy essential data from there */
911 jermar 193
	mov loc1 = R_RET	/* b0 belonging to interrupted context */
194
	mov loc2 = R_HANDLER
195
	mov out0 = R_OFFS
470 jermar 196
 
197
	add out1 = STACK_SCRATCH_AREA_SIZE, r12
438 jermar 198
 
435 jermar 199
    /* 6. switch to bank 1 and reenable PSR.ic */
478 jermar 200
	ssm PSR_IC_MASK
435 jermar 201
	bsw.1 ;;
202
	srlz.d
203
 
204
    /* 7. preserve branch and application registers */
470 jermar 205
    	mov loc3 = ar.unat
206
	mov loc4 = ar.lc
207
	mov loc5 = ar.ec
208
	mov loc6 = ar.ccv
209
	mov loc7 = ar.csd
210
	mov loc8 = ar.ssd
435 jermar 211
 
470 jermar 212
	mov loc9 = b0
213
	mov loc10 = b1
214
	mov loc11 = b2
215
	mov loc12 = b3
216
	mov loc13 = b4
217
	mov loc14 = b5
218
	mov loc15 = b6
219
	mov loc16 = b7
438 jermar 220
 
435 jermar 221
    /* 8. preserve general and floating-point registers */
222
	/* TODO: save floating-point context */
470 jermar 223
	mov loc17 = r1
224
	mov loc18 = r2
225
	mov loc19 = r3
226
	mov loc20 = r4
227
	mov loc21 = r5
228
	mov loc22 = r6
229
	mov loc23 = r7
230
	mov loc24 = r8
231
	mov loc25 = r9
232
	mov loc26 = r10
233
	mov loc27 = r11
438 jermar 234
	/* skip r12 (stack pointer) */
470 jermar 235
	mov loc28 = r13
236
	mov loc29 = r14
237
	mov loc30 = r15
238
	mov loc31 = r16
239
	mov loc32 = r17
240
	mov loc33 = r18
241
	mov loc34 = r19
242
	mov loc35 = r20
243
	mov loc36 = r21
244
	mov loc37 = r22
245
	mov loc38 = r23
246
	mov loc39 = r24
247
	mov loc40 = r25
248
	mov loc41 = r26
249
	mov loc42 = r27
250
	mov loc43 = r28
251
	mov loc44 = r29
252
	mov loc45 = r30
253
	mov loc46 = r31
438 jermar 254
 
435 jermar 255
    /* 9. skipped (will not enable interrupts) */
478 jermar 256
	/*
257
    	 * ssm PSR_I_MASK
258
	 * ;;
259
	 * srlz.d
260
	 */
238 vana 261
 
438 jermar 262
    /* 10. call handler */
470 jermar 263
    	mov b1 = loc2
438 jermar 264
	br.call.sptk.many b0 = b1
265
 
266
    /* 11. return from handler */
267
0:
268
 
435 jermar 269
    /* 12. skipped (will not disable interrupts) */
478 jermar 270
	/*
271
    	 * rsm PSR_I_MASK
272
	 * ;;
273
	 * srlz.d
274
	 */
438 jermar 275
 
435 jermar 276
    /* 13. restore general and floating-point registers */
277
	/* TODO: restore floating-point context */
470 jermar 278
	mov r1 = loc17
279
	mov r2 = loc18
280
	mov r3 = loc19
281
	mov r4 = loc20
282
	mov r5 = loc21
283
	mov r6 = loc22
284
	mov r7 = loc23
285
	mov r8 = loc24
286
	mov r9 = loc25
287
	mov r10 = loc26
288
	mov r11 = loc27
438 jermar 289
	/* skip r12 (stack pointer) */
470 jermar 290
	mov r13 = loc28
291
	mov r14 = loc29
292
	mov r15 = loc30
293
	mov r16 = loc31
294
	mov r17 = loc32
295
	mov r18 = loc33
296
	mov r19 = loc34
297
	mov r20 = loc35
298
	mov r21 = loc36
299
	mov r22 = loc37
300
	mov r23 = loc38
301
	mov r24 = loc39
302
	mov r25 = loc40
303
	mov r26 = loc41 
304
	mov r27 = loc42
305
	mov r28 = loc43
306
	mov r29 = loc44
307
	mov r30 = loc45
308
	mov r31 = loc46
435 jermar 309
 
310
    /* 14. restore branch and application registers */
470 jermar 311
    	mov ar.unat = loc3
312
	mov ar.lc = loc4
313
	mov ar.ec = loc5
314
	mov ar.ccv = loc6
315
	mov ar.csd = loc7
316
	mov ar.ssd = loc8
435 jermar 317
 
470 jermar 318
	mov b0 = loc9
319
	mov b1 = loc10
320
	mov b2 = loc11
321
	mov b3 = loc12
322
	mov b4 = loc13
323
	mov b5 = loc14
324
	mov b6 = loc15
325
	mov b7 = loc16
438 jermar 326
 
435 jermar 327
    /* 15. disable PSR.ic and switch to bank 0 */
478 jermar 328
	rsm PSR_IC_MASK
435 jermar 329
	bsw.0 ;;
330
	srlz.d
438 jermar 331
 
911 jermar 332
	mov R_RET = loc1
438 jermar 333
	mov ar.pfs = loc0
470 jermar 334
	br.ret.sptk.many b0
438 jermar 335
 
470 jermar 336
.global ivt
337
.align 32768
338
ivt:
339
	HEAVYWEIGHT_HANDLER 0x0000
340
	HEAVYWEIGHT_HANDLER 0x0400
341
	HEAVYWEIGHT_HANDLER 0x0800
899 jermar 342
	HEAVYWEIGHT_HANDLER 0x0c00 alternate_instruction_tlb_fault
343
	HEAVYWEIGHT_HANDLER 0x1000 alternate_data_tlb_fault
344
	HEAVYWEIGHT_HANDLER 0x1400 data_nested_tlb_fault
470 jermar 345
	HEAVYWEIGHT_HANDLER 0x1800
346
	HEAVYWEIGHT_HANDLER 0x1c00
899 jermar 347
	HEAVYWEIGHT_HANDLER 0x2000 data_dirty_bit_fault
348
	HEAVYWEIGHT_HANDLER 0x2400 instruction_access_bit_fault
349
	HEAVYWEIGHT_HANDLER 0x2800 data_access_bit_fault
470 jermar 350
	HEAVYWEIGHT_HANDLER 0x2c00 break_instruction
351
	HEAVYWEIGHT_HANDLER 0x3000 external_interrupt	/* For external interrupt, heavyweight handler is used. */
352
	HEAVYWEIGHT_HANDLER 0x3400
353
	HEAVYWEIGHT_HANDLER 0x3800
354
	HEAVYWEIGHT_HANDLER 0x3c00
355
	HEAVYWEIGHT_HANDLER 0x4000
356
	HEAVYWEIGHT_HANDLER 0x4400
357
	HEAVYWEIGHT_HANDLER 0x4800
358
	HEAVYWEIGHT_HANDLER 0x4c00
444 vana 359
 
899 jermar 360
	HEAVYWEIGHT_HANDLER 0x5000 page_not_present
470 jermar 361
	HEAVYWEIGHT_HANDLER 0x5100
362
	HEAVYWEIGHT_HANDLER 0x5200
363
	HEAVYWEIGHT_HANDLER 0x5300
364
	HEAVYWEIGHT_HANDLER 0x5400 general_exception
365
	HEAVYWEIGHT_HANDLER 0x5500
366
	HEAVYWEIGHT_HANDLER 0x5600
367
	HEAVYWEIGHT_HANDLER 0x5700
368
	HEAVYWEIGHT_HANDLER 0x5800
369
	HEAVYWEIGHT_HANDLER 0x5900
370
	HEAVYWEIGHT_HANDLER 0x5a00
371
	HEAVYWEIGHT_HANDLER 0x5b00
372
	HEAVYWEIGHT_HANDLER 0x5c00
373
	HEAVYWEIGHT_HANDLER 0x5d00
374
	HEAVYWEIGHT_HANDLER 0x5e00
375
	HEAVYWEIGHT_HANDLER 0x5f00
435 jermar 376
 
470 jermar 377
	HEAVYWEIGHT_HANDLER 0x6000
378
	HEAVYWEIGHT_HANDLER 0x6100
379
	HEAVYWEIGHT_HANDLER 0x6200
380
	HEAVYWEIGHT_HANDLER 0x6300
381
	HEAVYWEIGHT_HANDLER 0x6400
382
	HEAVYWEIGHT_HANDLER 0x6500
383
	HEAVYWEIGHT_HANDLER 0x6600
384
	HEAVYWEIGHT_HANDLER 0x6700
385
	HEAVYWEIGHT_HANDLER 0x6800
386
	HEAVYWEIGHT_HANDLER 0x6900
387
	HEAVYWEIGHT_HANDLER 0x6a00
388
	HEAVYWEIGHT_HANDLER 0x6b00
389
	HEAVYWEIGHT_HANDLER 0x6c00
390
	HEAVYWEIGHT_HANDLER 0x6d00
391
	HEAVYWEIGHT_HANDLER 0x6e00
392
	HEAVYWEIGHT_HANDLER 0x6f00
435 jermar 393
 
470 jermar 394
	HEAVYWEIGHT_HANDLER 0x7000
395
	HEAVYWEIGHT_HANDLER 0x7100
396
	HEAVYWEIGHT_HANDLER 0x7200
397
	HEAVYWEIGHT_HANDLER 0x7300
398
	HEAVYWEIGHT_HANDLER 0x7400
399
	HEAVYWEIGHT_HANDLER 0x7500
400
	HEAVYWEIGHT_HANDLER 0x7600
401
	HEAVYWEIGHT_HANDLER 0x7700
402
	HEAVYWEIGHT_HANDLER 0x7800
403
	HEAVYWEIGHT_HANDLER 0x7900
404
	HEAVYWEIGHT_HANDLER 0x7a00
405
	HEAVYWEIGHT_HANDLER 0x7b00
406
	HEAVYWEIGHT_HANDLER 0x7c00
407
	HEAVYWEIGHT_HANDLER 0x7d00
408
	HEAVYWEIGHT_HANDLER 0x7e00
409
	HEAVYWEIGHT_HANDLER 0x7f00