Subversion Repositories HelenOS-historic

Rev

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

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