Subversion Repositories HelenOS-historic

Rev

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

Rev 1221 Rev 1256
1
/*
1
/*
2
 * Copyright (C) 2001-2004 Jakub Jermar
2
 * Copyright (C) 2001-2004 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
#include <arch/interrupt.h>
29
#include <arch/interrupt.h>
30
#include <syscall/syscall.h>
30
#include <syscall/syscall.h>
31
#include <print.h>
31
#include <print.h>
32
#include <debug.h>
32
#include <debug.h>
33
#include <panic.h>
33
#include <panic.h>
34
#include <arch/i8259.h>
34
#include <arch/i8259.h>
35
#include <func.h>
35
#include <func.h>
36
#include <cpu.h>
36
#include <cpu.h>
37
#include <arch/asm.h>
37
#include <arch/asm.h>
38
#include <mm/tlb.h>
38
#include <mm/tlb.h>
39
#include <mm/as.h>
39
#include <mm/as.h>
40
#include <arch.h>
40
#include <arch.h>
41
#include <symtab.h>
41
#include <symtab.h>
42
#include <proc/thread.h>
42
#include <proc/thread.h>
-
 
43
#include <proc/task.h>
-
 
44
#include <synch/spinlock.h>
-
 
45
#include <arch/ddi/ddi.h>
43
 
46
 
44
/*
47
/*
45
 * Interrupt and exception dispatching.
48
 * Interrupt and exception dispatching.
46
 */
49
 */
47
 
50
 
48
void (* disable_irqs_function)(__u16 irqmask) = NULL;
51
void (* disable_irqs_function)(__u16 irqmask) = NULL;
49
void (* enable_irqs_function)(__u16 irqmask) = NULL;
52
void (* enable_irqs_function)(__u16 irqmask) = NULL;
50
void (* eoi_function)(void) = NULL;
53
void (* eoi_function)(void) = NULL;
51
 
54
 
52
static void PRINT_INFO_ERRCODE(istate_t *istate)
55
static void PRINT_INFO_ERRCODE(istate_t *istate)
53
{
56
{
54
    char *symbol = get_symtab_entry(istate->eip);
57
    char *symbol = get_symtab_entry(istate->eip);
55
 
58
 
56
    if (!symbol)
59
    if (!symbol)
57
        symbol = "";
60
        symbol = "";
58
 
61
 
59
    if (CPU)
62
    if (CPU)
60
        printf("----------------EXCEPTION OCCURED (cpu%d)----------------\n", CPU->id);
63
        printf("----------------EXCEPTION OCCURED (cpu%d)----------------\n", CPU->id);
61
    else
64
    else
62
        printf("----------------EXCEPTION OCCURED----------------\n");
65
        printf("----------------EXCEPTION OCCURED----------------\n");
63
       
66
       
64
    printf("%%eip: %#x (%s)\n",istate->eip,symbol);
67
    printf("%%eip: %#x (%s)\n",istate->eip,symbol);
65
    printf("ERROR_WORD=%#x\n", istate->error_word);
68
    printf("ERROR_WORD=%#x\n", istate->error_word);
66
    printf("%%cs=%#x,flags=%#x\n", istate->cs, istate->eflags);
69
    printf("%%cs=%#x,flags=%#x\n", istate->cs, istate->eflags);
67
    printf("%%eax=%#x, %%ecx=%#x, %%edx=%#x, %%esp=%#x\n",  istate->eax,istate->ecx,istate->edx,&istate->stack[0]);
70
    printf("%%eax=%#x, %%ecx=%#x, %%edx=%#x, %%esp=%#x\n",  istate->eax,istate->ecx,istate->edx,&istate->stack[0]);
68
#ifdef CONFIG_DEBUG_ALLREGS
71
#ifdef CONFIG_DEBUG_ALLREGS
69
    printf("%%esi=%#x, %%edi=%#x, %%ebp=%#x, %%ebx=%#x\n",  istate->esi,istate->edi,istate->ebp,istate->ebx);
72
    printf("%%esi=%#x, %%edi=%#x, %%ebp=%#x, %%ebx=%#x\n",  istate->esi,istate->edi,istate->ebp,istate->ebx);
70
#endif
73
#endif
71
    printf("stack: %#x, %#x, %#x, %#x\n", istate->stack[0], istate->stack[1], istate->stack[2], istate->stack[3]);
74
    printf("stack: %#x, %#x, %#x, %#x\n", istate->stack[0], istate->stack[1], istate->stack[2], istate->stack[3]);
72
    printf("       %#x, %#x, %#x, %#x\n", istate->stack[4], istate->stack[5], istate->stack[6], istate->stack[7]);
75
    printf("       %#x, %#x, %#x, %#x\n", istate->stack[4], istate->stack[5], istate->stack[6], istate->stack[7]);
73
}
76
}
74
 
77
 
75
void null_interrupt(int n, istate_t *istate)
78
void null_interrupt(int n, istate_t *istate)
76
{
79
{
77
    PRINT_INFO_ERRCODE(istate);
80
    PRINT_INFO_ERRCODE(istate);
78
    panic("unserviced interrupt: %d\n", n);
81
    panic("unserviced interrupt: %d\n", n);
79
}
82
}
80
 
83
 
-
 
84
/** General Protection Fault. */
81
void gp_fault(int n, istate_t *istate)
85
void gp_fault(int n, istate_t *istate)
82
{
86
{
-
 
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
 
83
    PRINT_INFO_ERRCODE(istate);
107
    PRINT_INFO_ERRCODE(istate);
84
    panic("general protection fault\n");
108
    panic("general protection fault\n");
85
}
109
}
86
 
110
 
87
void ss_fault(int n, istate_t *istate)
111
void ss_fault(int n, istate_t *istate)
88
{
112
{
89
    PRINT_INFO_ERRCODE(istate);
113
    PRINT_INFO_ERRCODE(istate);
90
    panic("stack fault\n");
114
    panic("stack fault\n");
91
}
115
}
92
 
116
 
93
void simd_fp_exception(int n, istate_t *istate)
117
void simd_fp_exception(int n, istate_t *istate)
94
{
118
{
95
 
119
 
96
    PRINT_INFO_ERRCODE(istate);
120
    PRINT_INFO_ERRCODE(istate);
97
    __u32 mxcsr;
121
    __u32 mxcsr;
98
    asm
122
    asm
99
    (
123
    (
100
        "stmxcsr %0;\n"
124
        "stmxcsr %0;\n"
101
        :"=m"(mxcsr)
125
        :"=m"(mxcsr)
102
    );
126
    );
103
    printf("MXCSR: %#zX\n",(__native)(mxcsr));
127
    printf("MXCSR: %#zX\n",(__native)(mxcsr));
104
    panic("SIMD FP exception(19)\n");
128
    panic("SIMD FP exception(19)\n");
105
}
129
}
106
 
130
 
107
void nm_fault(int n, istate_t *istate)
131
void nm_fault(int n, istate_t *istate)
108
{
132
{
109
#ifdef CONFIG_FPU_LAZY     
133
#ifdef CONFIG_FPU_LAZY     
110
    scheduler_fpu_lazy_request();
134
    scheduler_fpu_lazy_request();
111
#else
135
#else
112
    panic("fpu fault");
136
    panic("fpu fault");
113
#endif
137
#endif
114
}
138
}
115
 
139
 
116
void page_fault(int n, istate_t *istate)
140
void page_fault(int n, istate_t *istate)
117
{
141
{
118
    __address page;
142
    __address page;
119
 
143
 
120
    page = read_cr2();
144
    page = read_cr2();
121
    if (!as_page_fault(page)) {
145
    if (!as_page_fault(page)) {
122
        PRINT_INFO_ERRCODE(istate);
146
        PRINT_INFO_ERRCODE(istate);
123
        printf("page fault address: %#x\n", page);
147
        printf("page fault address: %#x\n", page);
124
        panic("page fault\n");
148
        panic("page fault\n");
125
    }
149
    }
126
}
150
}
127
 
151
 
128
void syscall(int n, istate_t *istate)
152
void syscall(int n, istate_t *istate)
129
{
153
{
130
    panic("Obsolete syscall handler.");
154
    panic("Obsolete syscall handler.");
131
}
155
}
132
 
156
 
133
void tlb_shootdown_ipi(int n, istate_t *istate)
157
void tlb_shootdown_ipi(int n, istate_t *istate)
134
{
158
{
135
    trap_virtual_eoi();
159
    trap_virtual_eoi();
136
    tlb_shootdown_ipi_recv();
160
    tlb_shootdown_ipi_recv();
137
}
161
}
138
 
162
 
139
void trap_virtual_enable_irqs(__u16 irqmask)
163
void trap_virtual_enable_irqs(__u16 irqmask)
140
{
164
{
141
    if (enable_irqs_function)
165
    if (enable_irqs_function)
142
        enable_irqs_function(irqmask);
166
        enable_irqs_function(irqmask);
143
    else
167
    else
144
        panic("no enable_irqs_function\n");
168
        panic("no enable_irqs_function\n");
145
}
169
}
146
 
170
 
147
void trap_virtual_disable_irqs(__u16 irqmask)
171
void trap_virtual_disable_irqs(__u16 irqmask)
148
{
172
{
149
    if (disable_irqs_function)
173
    if (disable_irqs_function)
150
        disable_irqs_function(irqmask);
174
        disable_irqs_function(irqmask);
151
    else
175
    else
152
        panic("no disable_irqs_function\n");
176
        panic("no disable_irqs_function\n");
153
}
177
}
154
 
178
 
155
void trap_virtual_eoi(void)
179
void trap_virtual_eoi(void)
156
{
180
{
157
    if (eoi_function)
181
    if (eoi_function)
158
        eoi_function();
182
        eoi_function();
159
    else
183
    else
160
        panic("no eoi_function\n");
184
        panic("no eoi_function\n");
161
 
185
 
162
}
186
}
163
 
187