Subversion Repositories HelenOS

Rev

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

Rev Author Line No. Line
431 jermar 1
/*
2
 * Copyright (C) 2005 Jakub Jermar
470 jermar 3
 * Copyright (C) 2005 Jakub Vana
431 jermar 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
 */
30
 
31
#include <arch/interrupt.h>
32
#include <panic.h>
433 jermar 33
#include <print.h>
583 jermar 34
#include <console/console.h>
431 jermar 35
#include <arch/types.h>
36
#include <arch/asm.h>
37
#include <arch/barrier.h>
432 jermar 38
#include <arch/register.h>
435 jermar 39
#include <arch/drivers/it.h>
433 jermar 40
#include <arch.h>
470 jermar 41
#include <symtab.h>
42
#include <debug.h>
921 jermar 43
#include <syscall/syscall.h>
44
#include <print.h>
1023 vana 45
#include <proc/scheduler.h>
431 jermar 46
 
470 jermar 47
#define VECTORS_64_BUNDLE	20
48
#define VECTORS_16_BUNDLE	48
49
#define VECTORS_16_BUNDLE_START	0x5000
50
#define VECTOR_MAX		0x7f00
51
 
52
#define BUNDLE_SIZE		16
53
 
54
char *vector_names_64_bundle[VECTORS_64_BUNDLE] = {
55
	"VHPT Translation vector",
56
	"Instruction TLB vector",
57
	"Data TLB vector",
58
	"Alternate Instruction TLB vector",
59
	"Alternate Data TLB vector",
60
	"Data Nested TLB vector",
61
	"Instruction Key Miss vector",
62
	"Data Key Miss vector",
63
	"Dirty-Bit vector",
64
	"Instruction Access-Bit vector",
65
	"Data Access-Bit vector"
66
	"Break Instruction vector",
67
	"External Interrupt vector"
68
	"Reserved",
69
	"Reserved",
70
	"Reserved",
71
	"Reserved",
72
	"Reserved",
73
	"Reserved",
74
	"Reserved"
75
};
76
 
77
char *vector_names_16_bundle[VECTORS_16_BUNDLE] = {
78
	"Page Not Present vector",
79
	"Key Permission vector",
80
	"Instruction Access rights vector",
81
	"Data Access Rights vector",
82
	"General Exception vector",
83
	"Disabled FP-Register vector",
84
	"NaT Consumption vector",
85
	"Speculation vector",
86
	"Reserved",
87
	"Debug vector",
88
	"Unaligned Reference vector",
89
	"Unsupported Data Reference vector",
90
	"Floating-point Fault vector",
91
	"Floating-point Trap vector",
92
	"Lower-Privilege Transfer Trap vector",
93
	"Taken Branch Trap vector",
94
	"Single STep Trap vector",
95
	"Reserved",
96
	"Reserved",
97
	"Reserved",
98
	"Reserved",
99
	"Reserved",
100
	"Reserved",
101
	"Reserved",
102
	"Reserved",
103
	"IA-32 Exception vector",
104
	"IA-32 Intercept vector",
105
	"IA-32 Interrupt vector",
106
	"Reserved",
107
	"Reserved",
108
	"Reserved"
109
};
110
 
111
static char *vector_to_string(__u16 vector);
958 jermar 112
static void dump_interrupted_context(istate_t *istate);
470 jermar 113
 
114
char *vector_to_string(__u16 vector)
431 jermar 115
{
470 jermar 116
	ASSERT(vector <= VECTOR_MAX);
117
 
118
	if (vector >= VECTORS_16_BUNDLE_START)
119
		return vector_names_16_bundle[(vector-VECTORS_16_BUNDLE_START)/(16*BUNDLE_SIZE)];
120
	else
121
		return vector_names_64_bundle[vector/(64*BUNDLE_SIZE)];
122
}
123
 
958 jermar 124
void dump_interrupted_context(istate_t *istate)
470 jermar 125
{
126
	char *ifa, *iipa, *iip;
127
 
958 jermar 128
	ifa = get_symtab_entry(istate->cr_ifa);
129
	iipa = get_symtab_entry(istate->cr_iipa);
130
	iip = get_symtab_entry(istate->cr_iip);
470 jermar 131
 
132
	putchar('\n');
472 jermar 133
	printf("Interrupted context dump:\n");
958 jermar 134
	printf("ar.bsp=%P\tar.bspstore=%P\n", istate->ar_bsp, istate->ar_bspstore);
135
	printf("ar.rnat=%Q\tar.rsc=%Q\n", istate->ar_rnat, istate->ar_rsc);
136
	printf("ar.ifs=%Q\tar.pfs=%Q\n", istate->ar_ifs, istate->ar_pfs);
137
	printf("cr.isr=%Q\tcr.ipsr=%Q\t\n", istate->cr_isr.value, istate->cr_ipsr);
470 jermar 138
 
958 jermar 139
	printf("cr.iip=%Q, #%d\t(%s)\n", istate->cr_iip, istate->cr_isr.ei ,iip ? iip : "?");
140
	printf("cr.iipa=%Q\t(%s)\n", istate->cr_iipa, iipa ? iipa : "?");
141
	printf("cr.ifa=%Q\t(%s)\n", istate->cr_ifa, ifa ? ifa : "?");
470 jermar 142
}
143
 
958 jermar 144
void general_exception(__u64 vector, istate_t *istate)
470 jermar 145
{
472 jermar 146
	char *desc = "";
147
 
958 jermar 148
	dump_interrupted_context(istate);
472 jermar 149
 
958 jermar 150
	switch (istate->cr_isr.ge_code) {
472 jermar 151
	    case GE_ILLEGALOP:
152
		desc = "Illegal Operation fault";
153
		break;
154
	    case GE_PRIVOP:
155
		desc = "Privileged Operation fault";
156
		break;
157
	    case GE_PRIVREG:
158
		desc = "Privileged Register fault";
159
		break;
160
	    case GE_RESREGFLD:
161
		desc = "Reserved Register/Field fault";
162
		break;
163
	    case GE_DISBLDISTRAN:
164
		desc = "Disabled Instruction Set Transition fault";
165
		break;
166
	    case GE_ILLEGALDEP:
167
		desc = "Illegal Dependency fault";
168
		break;
169
	    default:
170
	    	desc = "unknown";
171
		break;
172
	}
173
 
174
	panic("General Exception (%s)\n", desc);
470 jermar 175
}
176
 
1053 vana 177
void fpu_enable(void);
1023 vana 178
 
179
void disabled_fp_register(__u64 vector, istate_t *istate)
180
{
1053 vana 181
#ifdef CONFIG_FPU_LAZY 
1023 vana 182
	scheduler_fpu_lazy_request();	
1053 vana 183
#else
184
	dump_interrupted_context(istate);
185
	panic("Interruption: %W (%s)\n", (__u16) vector, vector_to_string(vector));
1023 vana 186
#endif
187
}
188
 
189
 
190
void nop_handler(__u64 vector, istate_t *istate)
191
{
192
}
193
 
194
 
195
 
921 jermar 196
/** Handle syscall. */
958 jermar 197
int break_instruction(__u64 vector, istate_t *istate)
470 jermar 198
{
921 jermar 199
	/*
200
	 * Move to next instruction after BREAK.
201
	 */
958 jermar 202
	if (istate->cr_ipsr.ri == 2) {
203
		istate->cr_ipsr.ri = 0;
204
		istate->cr_iip += 16;
921 jermar 205
	} else {
958 jermar 206
		istate->cr_ipsr.ri++;
921 jermar 207
	}
208
 
962 jermar 209
	if (istate->in4 < SYSCALL_END)
210
		return syscall_table[istate->in4](istate->in0, istate->in1, istate->in2, istate->in3);
921 jermar 211
	else
962 jermar 212
		panic("Undefined syscall %d", istate->in4);
921 jermar 213
 
214
	return -1;
470 jermar 215
}
216
 
958 jermar 217
void universal_handler(__u64 vector, istate_t *istate)
470 jermar 218
{
958 jermar 219
	dump_interrupted_context(istate);
470 jermar 220
	panic("Interruption: %W (%s)\n", (__u16) vector, vector_to_string(vector));
221
}
222
 
958 jermar 223
void external_interrupt(__u64 vector, istate_t *istate)
470 jermar 224
{
433 jermar 225
	cr_ivr_t ivr;
431 jermar 226
 
433 jermar 227
	ivr.value = ivr_read();
431 jermar 228
	srlz_d();
444 vana 229
 
434 jermar 230
	switch(ivr.vector) {
433 jermar 231
	    case INTERRUPT_TIMER:
435 jermar 232
		it_interrupt();
433 jermar 233
	    	break;
234
	    case INTERRUPT_SPURIOUS:
235
	    	printf("cpu%d: spurious interrupt\n", CPU->id);
236
		break;
431 jermar 237
	    default:
433 jermar 238
		panic("\nUnhandled External Interrupt Vector %d\n", ivr.vector);
239
		break;
431 jermar 240
	}
241
}