Subversion Repositories HelenOS-historic

Rev

Rev 1221 | Rev 1258 | 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>
34
#include <arch/i8259.h>
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>
1 jermar 46
 
47
/*
48
 * Interrupt and exception dispatching.
49
 */
50
 
51
void (* disable_irqs_function)(__u16 irqmask) = NULL;
52
void (* enable_irqs_function)(__u16 irqmask) = NULL;
53
void (* eoi_function)(void) = NULL;
54
 
1008 jermar 55
static void PRINT_INFO_ERRCODE(istate_t *istate)
56
{
57
    char *symbol = get_symtab_entry(istate->eip);
268 palkovsky 58
 
1008 jermar 59
    if (!symbol)
60
        symbol = "";
61
 
62
    if (CPU)
63
        printf("----------------EXCEPTION OCCURED (cpu%d)----------------\n", CPU->id);
64
    else
65
        printf("----------------EXCEPTION OCCURED----------------\n");
66
 
1221 decky 67
    printf("%%eip: %#x (%s)\n",istate->eip,symbol);
68
    printf("ERROR_WORD=%#x\n", istate->error_word);
69
    printf("%%cs=%#x,flags=%#x\n", istate->cs, istate->eflags);
70
    printf("%%eax=%#x, %%ecx=%#x, %%edx=%#x, %%esp=%#x\n",  istate->eax,istate->ecx,istate->edx,&istate->stack[0]);
1100 palkovsky 71
#ifdef CONFIG_DEBUG_ALLREGS
1221 decky 72
    printf("%%esi=%#x, %%edi=%#x, %%ebp=%#x, %%ebx=%#x\n",  istate->esi,istate->edi,istate->ebp,istate->ebx);
1100 palkovsky 73
#endif
1221 decky 74
    printf("stack: %#x, %#x, %#x, %#x\n", istate->stack[0], istate->stack[1], istate->stack[2], istate->stack[3]);
75
    printf("       %#x, %#x, %#x, %#x\n", istate->stack[4], istate->stack[5], istate->stack[6], istate->stack[7]);
1008 jermar 76
}
77
 
958 jermar 78
void null_interrupt(int n, istate_t *istate)
1 jermar 79
{
958 jermar 80
    PRINT_INFO_ERRCODE(istate);
81
    panic("unserviced interrupt: %d\n", n);
1 jermar 82
}
83
 
1256 jermar 84
/** General Protection Fault. */
958 jermar 85
void gp_fault(int n, istate_t *istate)
1 jermar 86
{
1256 jermar 87
    if (TASK) {
88
        count_t ver;
89
 
90
        spinlock_lock(&TASK->lock);
91
        ver = TASK->arch.iomapver;
92
        spinlock_unlock(&TASK->lock);
93
 
94
        if (CPU->arch.iomapver_copy != ver) {
95
            /*
96
             * This fault can be caused by an early access
97
             * to I/O port because of an out-dated
98
             * I/O Permission bitmap installed on CPU.
99
             * Install the fresh copy and restart
100
             * the instruction.
101
             */
102
            io_perm_bitmap_install();
103
            return;
104
        }
105
    }
106
 
958 jermar 107
    PRINT_INFO_ERRCODE(istate);
168 jermar 108
    panic("general protection fault\n");
1 jermar 109
}
110
 
958 jermar 111
void ss_fault(int n, istate_t *istate)
84 vana 112
{
958 jermar 113
    PRINT_INFO_ERRCODE(istate);
103 jermar 114
    panic("stack fault\n");
84 vana 115
}
116
 
1019 vana 117
void simd_fp_exception(int n, istate_t *istate)
118
{
119
 
120
    PRINT_INFO_ERRCODE(istate);
121
    __u32 mxcsr;
122
    asm
123
    (
124
        "stmxcsr %0;\n"
125
        :"=m"(mxcsr)
126
    );
1196 cejka 127
    printf("MXCSR: %#zX\n",(__native)(mxcsr));
1019 vana 128
    panic("SIMD FP exception(19)\n");
129
}
130
 
958 jermar 131
void nm_fault(int n, istate_t *istate)
73 vana 132
{
458 decky 133
#ifdef CONFIG_FPU_LAZY     
309 palkovsky 134
    scheduler_fpu_lazy_request();
135
#else
136
    panic("fpu fault");
137
#endif
73 vana 138
}
139
 
958 jermar 140
void page_fault(int n, istate_t *istate)
1 jermar 141
{
703 jermar 142
    __address page;
143
 
144
    page = read_cr2();
145
    if (!as_page_fault(page)) {
958 jermar 146
        PRINT_INFO_ERRCODE(istate);
1221 decky 147
        printf("page fault address: %#x\n", page);
703 jermar 148
        panic("page fault\n");
149
    }
1 jermar 150
}
151
 
958 jermar 152
void syscall(int n, istate_t *istate)
1 jermar 153
{
1100 palkovsky 154
    panic("Obsolete syscall handler.");
1 jermar 155
}
156
 
958 jermar 157
void tlb_shootdown_ipi(int n, istate_t *istate)
5 jermar 158
{
159
    trap_virtual_eoi();
6 jermar 160
    tlb_shootdown_ipi_recv();
5 jermar 161
}
162
 
1 jermar 163
void trap_virtual_enable_irqs(__u16 irqmask)
164
{
165
    if (enable_irqs_function)
166
        enable_irqs_function(irqmask);
167
    else
68 decky 168
        panic("no enable_irqs_function\n");
1 jermar 169
}
170
 
171
void trap_virtual_disable_irqs(__u16 irqmask)
172
{
173
    if (disable_irqs_function)
174
        disable_irqs_function(irqmask);
175
    else
68 decky 176
        panic("no disable_irqs_function\n");
1 jermar 177
}
178
 
179
void trap_virtual_eoi(void)
180
{
181
    if (eoi_function)
182
        eoi_function();
183
    else
68 decky 184
        panic("no eoi_function\n");
1 jermar 185
 
186
}