Subversion Repositories HelenOS-historic

Rev

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

Rev Author Line No. Line
1 jermar 1
/*
2
 * Copyright (C) 2001-2004 Jakub Jermar
3
 * All rights reserved.
4
 *
5
 * Redistribution and use in source and binary forms, with or without
6
 * modification, are permitted provided that the following conditions
7
 * are met:
8
 *
9
 * - Redistributions of source code must retain the above copyright
10
 *   notice, this list of conditions and the following disclaimer.
11
 * - Redistributions in binary form must reproduce the above copyright
12
 *   notice, this list of conditions and the following disclaimer in the
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
15
 *   derived from this software without specific prior written permission.
16
 *
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
19
 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
20
 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
21
 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
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
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
26
 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27
 */
28
 
29
#include <arch/interrupt.h>
712 decky 30
#include <syscall/syscall.h>
1 jermar 31
#include <print.h>
68 decky 32
#include <debug.h>
1 jermar 33
#include <panic.h>
1477 decky 34
#include <arch/drivers/i8259.h>
1 jermar 35
#include <func.h>
36
#include <cpu.h>
37
#include <arch/asm.h>
5 jermar 38
#include <mm/tlb.h>
703 jermar 39
#include <mm/as.h>
22 jermar 40
#include <arch.h>
268 palkovsky 41
#include <symtab.h>
391 jermar 42
#include <proc/thread.h>
1256 jermar 43
#include <proc/task.h>
44
#include <synch/spinlock.h>
45
#include <arch/ddi/ddi.h>
1258 palkovsky 46
#include <ipc/sysipc.h>
47
#include <interrupt.h>
1 jermar 48
 
49
/*
50
 * Interrupt and exception dispatching.
51
 */
52
 
53
void (* disable_irqs_function)(__u16 irqmask) = NULL;
54
void (* enable_irqs_function)(__u16 irqmask) = NULL;
55
void (* eoi_function)(void) = NULL;
56
 
1411 jermar 57
void PRINT_INFO_ERRCODE(istate_t *istate)
1008 jermar 58
{
59
	char *symbol = get_symtab_entry(istate->eip);
268 palkovsky 60
 
1008 jermar 61
	if (!symbol)
62
		symbol = "";
63
 
64
	if (CPU)
65
		printf("----------------EXCEPTION OCCURED (cpu%d)----------------\n", CPU->id);
66
	else
67
		printf("----------------EXCEPTION OCCURED----------------\n");
68
 
1221 decky 69
	printf("%%eip: %#x (%s)\n",istate->eip,symbol);
70
	printf("ERROR_WORD=%#x\n", istate->error_word);
71
	printf("%%cs=%#x,flags=%#x\n", istate->cs, istate->eflags);
72
	printf("%%eax=%#x, %%ecx=%#x, %%edx=%#x, %%esp=%#x\n",  istate->eax,istate->ecx,istate->edx,&istate->stack[0]);
1100 palkovsky 73
#ifdef CONFIG_DEBUG_ALLREGS
1221 decky 74
	printf("%%esi=%#x, %%edi=%#x, %%ebp=%#x, %%ebx=%#x\n",  istate->esi,istate->edi,istate->ebp,istate->ebx);
1100 palkovsky 75
#endif
1221 decky 76
	printf("stack: %#x, %#x, %#x, %#x\n", istate->stack[0], istate->stack[1], istate->stack[2], istate->stack[3]);
77
	printf("       %#x, %#x, %#x, %#x\n", istate->stack[4], istate->stack[5], istate->stack[6], istate->stack[7]);
1008 jermar 78
}
79
 
958 jermar 80
void null_interrupt(int n, istate_t *istate)
1 jermar 81
{
1595 palkovsky 82
	fault_if_from_uspace(istate, "unserviced interrupt: %d", n);
83
 
958 jermar 84
	PRINT_INFO_ERRCODE(istate);
85
	panic("unserviced interrupt: %d\n", n);
1 jermar 86
}
87
 
1256 jermar 88
/** General Protection Fault. */
958 jermar 89
void gp_fault(int n, istate_t *istate)
1 jermar 90
{
1256 jermar 91
	if (TASK) {
92
		count_t ver;
93
 
94
		spinlock_lock(&TASK->lock);
95
		ver = TASK->arch.iomapver;
96
		spinlock_unlock(&TASK->lock);
97
 
98
		if (CPU->arch.iomapver_copy != ver) {
99
			/*
100
			 * This fault can be caused by an early access
101
			 * to I/O port because of an out-dated
102
			 * I/O Permission bitmap installed on CPU.
103
			 * Install the fresh copy and restart
104
			 * the instruction.
105
			 */
106
			io_perm_bitmap_install();
107
			return;
108
		}
1595 palkovsky 109
		fault_if_from_uspace(istate, "general protection fault");
1256 jermar 110
	}
111
 
958 jermar 112
	PRINT_INFO_ERRCODE(istate);
168 jermar 113
	panic("general protection fault\n");
1 jermar 114
}
115
 
958 jermar 116
void ss_fault(int n, istate_t *istate)
84 vana 117
{
1595 palkovsky 118
	fault_if_from_uspace(istate, "stack fault");
119
 
958 jermar 120
	PRINT_INFO_ERRCODE(istate);
103 jermar 121
	panic("stack fault\n");
84 vana 122
}
123
 
1019 vana 124
void simd_fp_exception(int n, istate_t *istate)
125
{
126
	__u32 mxcsr;
127
	asm
128
	(
129
		"stmxcsr %0;\n"
130
		:"=m"(mxcsr)
131
	);
1595 palkovsky 132
	fault_if_from_uspace(istate, "SIMD FP exception(19), MXCSR: %#zX",
133
			     (__native)mxcsr);
134
 
135
	PRINT_INFO_ERRCODE(istate);
1196 cejka 136
	printf("MXCSR: %#zX\n",(__native)(mxcsr));
1019 vana 137
	panic("SIMD FP exception(19)\n");
138
}
139
 
958 jermar 140
void nm_fault(int n, istate_t *istate)
73 vana 141
{
458 decky 142
#ifdef CONFIG_FPU_LAZY     
309 palkovsky 143
	scheduler_fpu_lazy_request();
144
#else
1595 palkovsky 145
	fault_if_from_uspace(istate, "fpu fault");
309 palkovsky 146
	panic("fpu fault");
147
#endif
73 vana 148
}
149
 
958 jermar 150
void syscall(int n, istate_t *istate)
1 jermar 151
{
1100 palkovsky 152
	panic("Obsolete syscall handler.");
1 jermar 153
}
154
 
958 jermar 155
void tlb_shootdown_ipi(int n, istate_t *istate)
5 jermar 156
{
157
	trap_virtual_eoi();
6 jermar 158
	tlb_shootdown_ipi_recv();
5 jermar 159
}
160
 
1 jermar 161
void trap_virtual_enable_irqs(__u16 irqmask)
162
{
163
	if (enable_irqs_function)
164
		enable_irqs_function(irqmask);
165
	else
68 decky 166
		panic("no enable_irqs_function\n");
1 jermar 167
}
168
 
169
void trap_virtual_disable_irqs(__u16 irqmask)
170
{
171
	if (disable_irqs_function)
172
		disable_irqs_function(irqmask);
173
	else
68 decky 174
		panic("no disable_irqs_function\n");
1 jermar 175
}
176
 
177
void trap_virtual_eoi(void)
178
{
179
	if (eoi_function)
180
		eoi_function();
181
	else
68 decky 182
		panic("no eoi_function\n");
1 jermar 183
 
184
}
1258 palkovsky 185
 
186
static void ipc_int(int n, istate_t *istate)
187
{
1690 palkovsky 188
	ipc_irq_send_notif(n-IVT_IRQBASE);
1258 palkovsky 189
	trap_virtual_eoi();
190
}
191
 
192
 
193
/* Reregister irq to be IPC-ready */
194
void irq_ipc_bind_arch(__native irq)
195
{
196
	if (irq == IRQ_CLK)
197
		return;
1690 palkovsky 198
	trap_virtual_enable_irqs(1 << irq);
1258 palkovsky 199
	exc_register(IVT_IRQBASE+irq, "ipc_int", ipc_int);
200
}