Subversion Repositories HelenOS-historic

Rev

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

Rev 1100 Rev 1196
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
 
43
 
44
/*
44
/*
45
 * Interrupt and exception dispatching.
45
 * Interrupt and exception dispatching.
46
 */
46
 */
47
 
47
 
48
void (* disable_irqs_function)(__u16 irqmask) = NULL;
48
void (* disable_irqs_function)(__u16 irqmask) = NULL;
49
void (* enable_irqs_function)(__u16 irqmask) = NULL;
49
void (* enable_irqs_function)(__u16 irqmask) = NULL;
50
void (* eoi_function)(void) = NULL;
50
void (* eoi_function)(void) = NULL;
51
 
51
 
52
static void PRINT_INFO_ERRCODE(istate_t *istate)
52
static void PRINT_INFO_ERRCODE(istate_t *istate)
53
{
53
{
54
    char *symbol = get_symtab_entry(istate->eip);
54
    char *symbol = get_symtab_entry(istate->eip);
55
 
55
 
56
    if (!symbol)
56
    if (!symbol)
57
        symbol = "";
57
        symbol = "";
58
 
58
 
59
    if (CPU)
59
    if (CPU)
60
        printf("----------------EXCEPTION OCCURED (cpu%d)----------------\n", CPU->id);
60
        printf("----------------EXCEPTION OCCURED (cpu%d)----------------\n", CPU->id);
61
    else
61
    else
62
        printf("----------------EXCEPTION OCCURED----------------\n");
62
        printf("----------------EXCEPTION OCCURED----------------\n");
63
       
63
       
64
    printf("%%eip: %X (%s)\n",istate->eip,symbol);
64
    printf("%%eip: %#X (%s)\n",istate->eip,symbol);
65
    printf("ERROR_WORD=%X\n", istate->error_word);
65
    printf("ERROR_WORD=%#X\n", istate->error_word);
66
    printf("%%cs=%X,flags=%X\n", istate->cs, istate->eflags);
66
    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]);
67
    printf("%%eax=%#X, %%ecx=%#X, %%edx=%#X, %%esp=%#X\n",  istate->eax,istate->ecx,istate->edx,&istate->stack[0]);
68
#ifdef CONFIG_DEBUG_ALLREGS
68
#ifdef CONFIG_DEBUG_ALLREGS
69
    printf("%%esi=%X, %%edi=%X, %%ebp=%X, %%ebx=%X\n",  istate->esi,istate->edi,istate->ebp,istate->ebx);
69
    printf("%%esi=%#X, %%edi=%#X, %%ebp=%#X, %%ebx=%#X\n",  istate->esi,istate->edi,istate->ebp,istate->ebx);
70
#endif
70
#endif
71
    printf("stack: %X, %X, %X, %X\n", istate->stack[0], istate->stack[1], istate->stack[2], istate->stack[3]);
71
    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]);
72
    printf("       %#X, %#X, %#X, %#X\n", istate->stack[4], istate->stack[5], istate->stack[6], istate->stack[7]);
73
}
73
}
74
 
74
 
75
void null_interrupt(int n, istate_t *istate)
75
void null_interrupt(int n, istate_t *istate)
76
{
76
{
77
    PRINT_INFO_ERRCODE(istate);
77
    PRINT_INFO_ERRCODE(istate);
78
    panic("unserviced interrupt: %d\n", n);
78
    panic("unserviced interrupt: %d\n", n);
79
}
79
}
80
 
80
 
81
void gp_fault(int n, istate_t *istate)
81
void gp_fault(int n, istate_t *istate)
82
{
82
{
83
    PRINT_INFO_ERRCODE(istate);
83
    PRINT_INFO_ERRCODE(istate);
84
    panic("general protection fault\n");
84
    panic("general protection fault\n");
85
}
85
}
86
 
86
 
87
void ss_fault(int n, istate_t *istate)
87
void ss_fault(int n, istate_t *istate)
88
{
88
{
89
    PRINT_INFO_ERRCODE(istate);
89
    PRINT_INFO_ERRCODE(istate);
90
    panic("stack fault\n");
90
    panic("stack fault\n");
91
}
91
}
92
 
92
 
93
void simd_fp_exception(int n, istate_t *istate)
93
void simd_fp_exception(int n, istate_t *istate)
94
{
94
{
95
 
95
 
96
    PRINT_INFO_ERRCODE(istate);
96
    PRINT_INFO_ERRCODE(istate);
97
    __u32 mxcsr;
97
    __u32 mxcsr;
98
    asm
98
    asm
99
    (
99
    (
100
        "stmxcsr %0;\n"
100
        "stmxcsr %0;\n"
101
        :"=m"(mxcsr)
101
        :"=m"(mxcsr)
102
    );
102
    );
103
    printf("MXCSR: %X\n",(__native)(mxcsr));
103
    printf("MXCSR: %#zX\n",(__native)(mxcsr));
104
    panic("SIMD FP exception(19)\n");
104
    panic("SIMD FP exception(19)\n");
105
}
105
}
106
 
106
 
107
void nm_fault(int n, istate_t *istate)
107
void nm_fault(int n, istate_t *istate)
108
{
108
{
109
#ifdef CONFIG_FPU_LAZY     
109
#ifdef CONFIG_FPU_LAZY     
110
    scheduler_fpu_lazy_request();
110
    scheduler_fpu_lazy_request();
111
#else
111
#else
112
    panic("fpu fault");
112
    panic("fpu fault");
113
#endif
113
#endif
114
}
114
}
115
 
115
 
116
void page_fault(int n, istate_t *istate)
116
void page_fault(int n, istate_t *istate)
117
{
117
{
118
    __address page;
118
    __address page;
119
 
119
 
120
    page = read_cr2();
120
    page = read_cr2();
121
    if (!as_page_fault(page)) {
121
    if (!as_page_fault(page)) {
122
        PRINT_INFO_ERRCODE(istate);
122
        PRINT_INFO_ERRCODE(istate);
123
        printf("page fault address: %X\n", page);
123
        printf("page fault address: %#X\n", page);
124
        panic("page fault\n");
124
        panic("page fault\n");
125
    }
125
    }
126
}
126
}
127
 
127
 
128
void syscall(int n, istate_t *istate)
128
void syscall(int n, istate_t *istate)
129
{
129
{
130
    panic("Obsolete syscall handler.");
130
    panic("Obsolete syscall handler.");
131
}
131
}
132
 
132
 
133
void tlb_shootdown_ipi(int n, istate_t *istate)
133
void tlb_shootdown_ipi(int n, istate_t *istate)
134
{
134
{
135
    trap_virtual_eoi();
135
    trap_virtual_eoi();
136
    tlb_shootdown_ipi_recv();
136
    tlb_shootdown_ipi_recv();
137
}
137
}
138
 
138
 
139
void trap_virtual_enable_irqs(__u16 irqmask)
139
void trap_virtual_enable_irqs(__u16 irqmask)
140
{
140
{
141
    if (enable_irqs_function)
141
    if (enable_irqs_function)
142
        enable_irqs_function(irqmask);
142
        enable_irqs_function(irqmask);
143
    else
143
    else
144
        panic("no enable_irqs_function\n");
144
        panic("no enable_irqs_function\n");
145
}
145
}
146
 
146
 
147
void trap_virtual_disable_irqs(__u16 irqmask)
147
void trap_virtual_disable_irqs(__u16 irqmask)
148
{
148
{
149
    if (disable_irqs_function)
149
    if (disable_irqs_function)
150
        disable_irqs_function(irqmask);
150
        disable_irqs_function(irqmask);
151
    else
151
    else
152
        panic("no disable_irqs_function\n");
152
        panic("no disable_irqs_function\n");
153
}
153
}
154
 
154
 
155
void trap_virtual_eoi(void)
155
void trap_virtual_eoi(void)
156
{
156
{
157
    if (eoi_function)
157
    if (eoi_function)
158
        eoi_function();
158
        eoi_function();
159
    else
159
    else
160
        panic("no eoi_function\n");
160
        panic("no eoi_function\n");
161
 
161
 
162
}
162
}
163
 
163