Subversion Repositories HelenOS-historic

Rev

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

Rev 1690 Rev 1702
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
 /** @addtogroup ia32interrupt ia32
-
 
30
 * @ingroup interrupt
-
 
31
 * @{
-
 
32
 */
-
 
33
/** @file
-
 
34
 */
-
 
35
 
29
#include <arch/interrupt.h>
36
#include <arch/interrupt.h>
30
#include <syscall/syscall.h>
37
#include <syscall/syscall.h>
31
#include <print.h>
38
#include <print.h>
32
#include <debug.h>
39
#include <debug.h>
33
#include <panic.h>
40
#include <panic.h>
34
#include <arch/drivers/i8259.h>
41
#include <arch/drivers/i8259.h>
35
#include <func.h>
42
#include <func.h>
36
#include <cpu.h>
43
#include <cpu.h>
37
#include <arch/asm.h>
44
#include <arch/asm.h>
38
#include <mm/tlb.h>
45
#include <mm/tlb.h>
39
#include <mm/as.h>
46
#include <mm/as.h>
40
#include <arch.h>
47
#include <arch.h>
41
#include <symtab.h>
48
#include <symtab.h>
42
#include <proc/thread.h>
49
#include <proc/thread.h>
43
#include <proc/task.h>
50
#include <proc/task.h>
44
#include <synch/spinlock.h>
51
#include <synch/spinlock.h>
45
#include <arch/ddi/ddi.h>
52
#include <arch/ddi/ddi.h>
46
#include <ipc/sysipc.h>
53
#include <ipc/sysipc.h>
47
#include <interrupt.h>
54
#include <interrupt.h>
48
 
55
 
49
/*
56
/*
50
 * Interrupt and exception dispatching.
57
 * Interrupt and exception dispatching.
51
 */
58
 */
52
 
59
 
53
void (* disable_irqs_function)(__u16 irqmask) = NULL;
60
void (* disable_irqs_function)(__u16 irqmask) = NULL;
54
void (* enable_irqs_function)(__u16 irqmask) = NULL;
61
void (* enable_irqs_function)(__u16 irqmask) = NULL;
55
void (* eoi_function)(void) = NULL;
62
void (* eoi_function)(void) = NULL;
56
 
63
 
57
void PRINT_INFO_ERRCODE(istate_t *istate)
64
void PRINT_INFO_ERRCODE(istate_t *istate)
58
{
65
{
59
    char *symbol = get_symtab_entry(istate->eip);
66
    char *symbol = get_symtab_entry(istate->eip);
60
 
67
 
61
    if (!symbol)
68
    if (!symbol)
62
        symbol = "";
69
        symbol = "";
63
 
70
 
64
    if (CPU)
71
    if (CPU)
65
        printf("----------------EXCEPTION OCCURED (cpu%d)----------------\n", CPU->id);
72
        printf("----------------EXCEPTION OCCURED (cpu%d)----------------\n", CPU->id);
66
    else
73
    else
67
        printf("----------------EXCEPTION OCCURED----------------\n");
74
        printf("----------------EXCEPTION OCCURED----------------\n");
68
       
75
       
69
    printf("%%eip: %#x (%s)\n",istate->eip,symbol);
76
    printf("%%eip: %#x (%s)\n",istate->eip,symbol);
70
    printf("ERROR_WORD=%#x\n", istate->error_word);
77
    printf("ERROR_WORD=%#x\n", istate->error_word);
71
    printf("%%cs=%#x,flags=%#x\n", istate->cs, istate->eflags);
78
    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]);
79
    printf("%%eax=%#x, %%ecx=%#x, %%edx=%#x, %%esp=%#x\n",  istate->eax,istate->ecx,istate->edx,&istate->stack[0]);
73
#ifdef CONFIG_DEBUG_ALLREGS
80
#ifdef CONFIG_DEBUG_ALLREGS
74
    printf("%%esi=%#x, %%edi=%#x, %%ebp=%#x, %%ebx=%#x\n",  istate->esi,istate->edi,istate->ebp,istate->ebx);
81
    printf("%%esi=%#x, %%edi=%#x, %%ebp=%#x, %%ebx=%#x\n",  istate->esi,istate->edi,istate->ebp,istate->ebx);
75
#endif
82
#endif
76
    printf("stack: %#x, %#x, %#x, %#x\n", istate->stack[0], istate->stack[1], istate->stack[2], istate->stack[3]);
83
    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]);
84
    printf("       %#x, %#x, %#x, %#x\n", istate->stack[4], istate->stack[5], istate->stack[6], istate->stack[7]);
78
}
85
}
79
 
86
 
80
void null_interrupt(int n, istate_t *istate)
87
void null_interrupt(int n, istate_t *istate)
81
{
88
{
82
    fault_if_from_uspace(istate, "unserviced interrupt: %d", n);
89
    fault_if_from_uspace(istate, "unserviced interrupt: %d", n);
83
 
90
 
84
    PRINT_INFO_ERRCODE(istate);
91
    PRINT_INFO_ERRCODE(istate);
85
    panic("unserviced interrupt: %d\n", n);
92
    panic("unserviced interrupt: %d\n", n);
86
}
93
}
87
 
94
 
88
/** General Protection Fault. */
95
/** General Protection Fault. */
89
void gp_fault(int n, istate_t *istate)
96
void gp_fault(int n, istate_t *istate)
90
{
97
{
91
    if (TASK) {
98
    if (TASK) {
92
        count_t ver;
99
        count_t ver;
93
       
100
       
94
        spinlock_lock(&TASK->lock);
101
        spinlock_lock(&TASK->lock);
95
        ver = TASK->arch.iomapver;
102
        ver = TASK->arch.iomapver;
96
        spinlock_unlock(&TASK->lock);
103
        spinlock_unlock(&TASK->lock);
97
   
104
   
98
        if (CPU->arch.iomapver_copy != ver) {
105
        if (CPU->arch.iomapver_copy != ver) {
99
            /*
106
            /*
100
             * This fault can be caused by an early access
107
             * This fault can be caused by an early access
101
             * to I/O port because of an out-dated
108
             * to I/O port because of an out-dated
102
             * I/O Permission bitmap installed on CPU.
109
             * I/O Permission bitmap installed on CPU.
103
             * Install the fresh copy and restart
110
             * Install the fresh copy and restart
104
             * the instruction.
111
             * the instruction.
105
             */
112
             */
106
            io_perm_bitmap_install();
113
            io_perm_bitmap_install();
107
            return;
114
            return;
108
        }
115
        }
109
        fault_if_from_uspace(istate, "general protection fault");
116
        fault_if_from_uspace(istate, "general protection fault");
110
    }
117
    }
111
 
118
 
112
    PRINT_INFO_ERRCODE(istate);
119
    PRINT_INFO_ERRCODE(istate);
113
    panic("general protection fault\n");
120
    panic("general protection fault\n");
114
}
121
}
115
 
122
 
116
void ss_fault(int n, istate_t *istate)
123
void ss_fault(int n, istate_t *istate)
117
{
124
{
118
    fault_if_from_uspace(istate, "stack fault");
125
    fault_if_from_uspace(istate, "stack fault");
119
 
126
 
120
    PRINT_INFO_ERRCODE(istate);
127
    PRINT_INFO_ERRCODE(istate);
121
    panic("stack fault\n");
128
    panic("stack fault\n");
122
}
129
}
123
 
130
 
124
void simd_fp_exception(int n, istate_t *istate)
131
void simd_fp_exception(int n, istate_t *istate)
125
{
132
{
126
    __u32 mxcsr;
133
    __u32 mxcsr;
127
    asm
134
    asm
128
    (
135
    (
129
        "stmxcsr %0;\n"
136
        "stmxcsr %0;\n"
130
        :"=m"(mxcsr)
137
        :"=m"(mxcsr)
131
    );
138
    );
132
    fault_if_from_uspace(istate, "SIMD FP exception(19), MXCSR: %#zX",
139
    fault_if_from_uspace(istate, "SIMD FP exception(19), MXCSR: %#zX",
133
                 (__native)mxcsr);
140
                 (__native)mxcsr);
134
 
141
 
135
    PRINT_INFO_ERRCODE(istate);
142
    PRINT_INFO_ERRCODE(istate);
136
    printf("MXCSR: %#zX\n",(__native)(mxcsr));
143
    printf("MXCSR: %#zX\n",(__native)(mxcsr));
137
    panic("SIMD FP exception(19)\n");
144
    panic("SIMD FP exception(19)\n");
138
}
145
}
139
 
146
 
140
void nm_fault(int n, istate_t *istate)
147
void nm_fault(int n, istate_t *istate)
141
{
148
{
142
#ifdef CONFIG_FPU_LAZY     
149
#ifdef CONFIG_FPU_LAZY     
143
    scheduler_fpu_lazy_request();
150
    scheduler_fpu_lazy_request();
144
#else
151
#else
145
    fault_if_from_uspace(istate, "fpu fault");
152
    fault_if_from_uspace(istate, "fpu fault");
146
    panic("fpu fault");
153
    panic("fpu fault");
147
#endif
154
#endif
148
}
155
}
149
 
156
 
150
void syscall(int n, istate_t *istate)
157
void syscall(int n, istate_t *istate)
151
{
158
{
152
    panic("Obsolete syscall handler.");
159
    panic("Obsolete syscall handler.");
153
}
160
}
154
 
161
 
155
void tlb_shootdown_ipi(int n, istate_t *istate)
162
void tlb_shootdown_ipi(int n, istate_t *istate)
156
{
163
{
157
    trap_virtual_eoi();
164
    trap_virtual_eoi();
158
    tlb_shootdown_ipi_recv();
165
    tlb_shootdown_ipi_recv();
159
}
166
}
160
 
167
 
161
void trap_virtual_enable_irqs(__u16 irqmask)
168
void trap_virtual_enable_irqs(__u16 irqmask)
162
{
169
{
163
    if (enable_irqs_function)
170
    if (enable_irqs_function)
164
        enable_irqs_function(irqmask);
171
        enable_irqs_function(irqmask);
165
    else
172
    else
166
        panic("no enable_irqs_function\n");
173
        panic("no enable_irqs_function\n");
167
}
174
}
168
 
175
 
169
void trap_virtual_disable_irqs(__u16 irqmask)
176
void trap_virtual_disable_irqs(__u16 irqmask)
170
{
177
{
171
    if (disable_irqs_function)
178
    if (disable_irqs_function)
172
        disable_irqs_function(irqmask);
179
        disable_irqs_function(irqmask);
173
    else
180
    else
174
        panic("no disable_irqs_function\n");
181
        panic("no disable_irqs_function\n");
175
}
182
}
176
 
183
 
177
void trap_virtual_eoi(void)
184
void trap_virtual_eoi(void)
178
{
185
{
179
    if (eoi_function)
186
    if (eoi_function)
180
        eoi_function();
187
        eoi_function();
181
    else
188
    else
182
        panic("no eoi_function\n");
189
        panic("no eoi_function\n");
183
 
190
 
184
}
191
}
185
 
192
 
186
static void ipc_int(int n, istate_t *istate)
193
static void ipc_int(int n, istate_t *istate)
187
{
194
{
188
    ipc_irq_send_notif(n-IVT_IRQBASE);
195
    ipc_irq_send_notif(n-IVT_IRQBASE);
189
    trap_virtual_eoi();
196
    trap_virtual_eoi();
190
}
197
}
191
 
198
 
192
 
199
 
193
/* Reregister irq to be IPC-ready */
200
/* Reregister irq to be IPC-ready */
194
void irq_ipc_bind_arch(__native irq)
201
void irq_ipc_bind_arch(__native irq)
195
{
202
{
196
    if (irq == IRQ_CLK)
203
    if (irq == IRQ_CLK)
197
        return;
204
        return;
198
    trap_virtual_enable_irqs(1 << irq);
205
    trap_virtual_enable_irqs(1 << irq);
199
    exc_register(IVT_IRQBASE+irq, "ipc_int", ipc_int);
206
    exc_register(IVT_IRQBASE+irq, "ipc_int", ipc_int);
200
}
207
}
-
 
208
 
-
 
209
 /** @}
-
 
210
 */
-
 
211
 
201
 
212