Subversion Repositories HelenOS-historic

Rev

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

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