Subversion Repositories HelenOS-historic

Rev

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

Rev 576 Rev 703
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 <print.h>
30
#include <print.h>
31
#include <debug.h>
31
#include <debug.h>
32
#include <panic.h>
32
#include <panic.h>
33
#include <arch/i8259.h>
33
#include <arch/i8259.h>
34
#include <func.h>
34
#include <func.h>
35
#include <cpu.h>
35
#include <cpu.h>
36
#include <arch/asm.h>
36
#include <arch/asm.h>
37
#include <mm/tlb.h>
37
#include <mm/tlb.h>
-
 
38
#include <mm/as.h>
38
#include <arch.h>
39
#include <arch.h>
39
#include <symtab.h>
40
#include <symtab.h>
40
#include <arch/asm.h>
41
#include <arch/asm.h>
41
#include <proc/scheduler.h>
42
#include <proc/scheduler.h>
42
#include <proc/thread.h>
43
#include <proc/thread.h>
43
 
44
 
44
 
45
 
45
static void messy_stack_trace(__native *stack)
46
static void messy_stack_trace(__native *stack)
46
{
47
{
47
    __native *upper_limit = (__native *)(((__native)get_stack_base()) + STACK_SIZE);
48
    __native *upper_limit = (__native *)(((__native)get_stack_base()) + STACK_SIZE);
48
    char *symbol;
49
    char *symbol;
49
 
50
 
50
    printf("Stack contents: ");
51
    printf("Stack contents: ");
51
    while (stack < upper_limit) {
52
    while (stack < upper_limit) {
52
        symbol = get_symtab_entry((__address)*stack);
53
        symbol = get_symtab_entry((__address)*stack);
53
        if (symbol)
54
        if (symbol)
54
            printf("%s, ", symbol);
55
            printf("%s, ", symbol);
55
        stack++;
56
        stack++;
56
    }
57
    }
57
    printf("\n");
58
    printf("\n");
58
}
59
}
59
 
60
 
60
static void print_info_errcode(int n, void *st)
61
static void print_info_errcode(int n, void *st)
61
{
62
{
62
    char *symbol;
63
    char *symbol;
63
    __native *x = (__native *) st;
64
    __native *x = (__native *) st;
64
 
65
 
65
    if (!(symbol=get_symtab_entry(x[1])))
66
    if (!(symbol=get_symtab_entry(x[1])))
66
        symbol = "";
67
        symbol = "";
67
 
68
 
68
    printf("-----EXCEPTION(%d) OCCURED----- ( %s )\n",n,__FUNCTION__);
69
    printf("-----EXCEPTION(%d) OCCURED----- ( %s )\n",n,__FUNCTION__);
69
    printf("%%rip: %Q (%s)\n",x[1],symbol);
70
    printf("%%rip: %Q (%s)\n",x[1],symbol);
70
    printf("ERROR_WORD=%Q\n", x[0]);
71
    printf("ERROR_WORD=%Q\n", x[0]);
71
    printf("%%rcs=%Q,flags=%Q, %%cr0=%Q\n", x[2], x[3],read_cr0());
72
    printf("%%rcs=%Q,flags=%Q, %%cr0=%Q\n", x[2], x[3],read_cr0());
72
    printf("%%rax=%Q, %%rbx=%Q, %%rcx=%Q\n",x[-2],x[-3],x[-4]);
73
    printf("%%rax=%Q, %%rbx=%Q, %%rcx=%Q\n",x[-2],x[-3],x[-4]);
73
    printf("%%rdx=%Q, %%rsi=%Q, %%rdi=%Q\n",x[-5],x[-6],x[-7]);
74
    printf("%%rdx=%Q, %%rsi=%Q, %%rdi=%Q\n",x[-5],x[-6],x[-7]);
74
    printf("%%r8 =%Q, %%r9 =%Q, %%r10=%Q\n",x[-8],x[-9],x[-10]);
75
    printf("%%r8 =%Q, %%r9 =%Q, %%r10=%Q\n",x[-8],x[-9],x[-10]);
75
    printf("%%r11=%Q, %%r12=%Q, %%r13=%Q\n",x[-11],x[-12],x[-13]);
76
    printf("%%r11=%Q, %%r12=%Q, %%r13=%Q\n",x[-11],x[-12],x[-13]);
76
    printf("%%r14=%Q, %%r15=%Q, %%rsp=%Q\n",x[-14],x[-15],x);
77
    printf("%%r14=%Q, %%r15=%Q, %%rsp=%Q\n",x[-14],x[-15],x);
77
    printf("%%rbp=%Q\n",x[-1]);
78
    printf("%%rbp=%Q\n",x[-1]);
78
    printf("stack: %Q, %Q, %Q\n", x[5], x[6], x[7]);
79
    printf("stack: %Q, %Q, %Q\n", x[5], x[6], x[7]);
79
    printf("       %Q, %Q, %Q\n", x[8], x[9], x[10]);
80
    printf("       %Q, %Q, %Q\n", x[8], x[9], x[10]);
80
    printf("       %Q, %Q, %Q\n", x[11], x[12], x[13]);
81
    printf("       %Q, %Q, %Q\n", x[11], x[12], x[13]);
81
    printf("       %Q, %Q, %Q\n", x[14], x[15], x[16]);
82
    printf("       %Q, %Q, %Q\n", x[14], x[15], x[16]);
82
    printf("       %Q, %Q, %Q\n", x[17], x[18], x[19]);
83
    printf("       %Q, %Q, %Q\n", x[17], x[18], x[19]);
83
    printf("       %Q, %Q, %Q\n", x[20], x[21], x[22]);
84
    printf("       %Q, %Q, %Q\n", x[20], x[21], x[22]);
84
    printf("       %Q, %Q, %Q\n", x[23], x[24], x[25]);
85
    printf("       %Q, %Q, %Q\n", x[23], x[24], x[25]);
85
    messy_stack_trace(&x[5]);
86
    messy_stack_trace(&x[5]);
86
}
87
}
87
 
88
 
88
/*
89
/*
89
 * Interrupt and exception dispatching.
90
 * Interrupt and exception dispatching.
90
 */
91
 */
91
 
92
 
92
void (* disable_irqs_function)(__u16 irqmask) = NULL;
93
void (* disable_irqs_function)(__u16 irqmask) = NULL;
93
void (* enable_irqs_function)(__u16 irqmask) = NULL;
94
void (* enable_irqs_function)(__u16 irqmask) = NULL;
94
void (* eoi_function)(void) = NULL;
95
void (* eoi_function)(void) = NULL;
95
 
96
 
96
void null_interrupt(int n, void *st)
97
void null_interrupt(int n, void *st)
97
{
98
{
98
    __native *stack = (__native *) st;
99
    __native *stack = (__native *) st;
99
 
100
 
100
    printf("-----EXCEPTION(%d) OCCURED----- ( %s )\n",n,__FUNCTION__); \
101
    printf("-----EXCEPTION(%d) OCCURED----- ( %s )\n",n,__FUNCTION__); \
101
    printf("stack: %L, %L, %L, %L\n", stack[0], stack[1], stack[2], stack[3]);
102
    printf("stack: %L, %L, %L, %L\n", stack[0], stack[1], stack[2], stack[3]);
102
    panic("unserviced interrupt\n");
103
    panic("unserviced interrupt\n");
103
}
104
}
104
 
105
 
105
void gp_fault(int n, void *stack)
106
void gp_fault(int n, void *stack)
106
{
107
{
107
    print_info_errcode(n,stack);
108
    print_info_errcode(n,stack);
108
    panic("general protection fault\n");
109
    panic("general protection fault\n");
109
}
110
}
110
 
111
 
111
void ss_fault(int n, void *stack)
112
void ss_fault(int n, void *stack)
112
{
113
{
113
    print_info_errcode(n,stack);
114
    print_info_errcode(n,stack);
114
    panic("stack fault\n");
115
    panic("stack fault\n");
115
}
116
}
116
 
117
 
117
 
118
 
118
void nm_fault(int n, void *stack)
119
void nm_fault(int n, void *stack)
119
{
120
{
120
#ifdef CONFIG_FPU_LAZY     
121
#ifdef CONFIG_FPU_LAZY     
121
    scheduler_fpu_lazy_request();
122
    scheduler_fpu_lazy_request();
122
#else
123
#else
123
    panic("fpu fault");
124
    panic("fpu fault");
124
#endif
125
#endif
125
}
126
}
126
 
127
 
127
 
-
 
128
 
-
 
129
void page_fault(int n, void *stack)
128
void page_fault(int n, void *stack)
130
{
129
{
-
 
130
    __address page;
-
 
131
   
-
 
132
    page = read_cr2();
-
 
133
    if (!as_page_fault(page)) {
131
    print_info_errcode(n,stack);
134
        print_info_errcode(n,stack);
132
    printf("Page fault address: %Q\n", read_cr2());
135
        printf("Page fault address: %Q\n", page);
133
    panic("page fault\n");
136
        panic("page fault\n");
-
 
137
    }
134
}
138
}
135
 
139
 
136
void syscall(int n, void *stack)
140
void syscall(int n, void *stack)
137
{
141
{
138
    printf("cpu%d: syscall\n", CPU->id);
142
    printf("cpu%d: syscall\n", CPU->id);
139
    thread_usleep(1000);
143
    thread_usleep(1000);
140
}
144
}
141
 
145
 
142
void tlb_shootdown_ipi(int n, void *stack)
146
void tlb_shootdown_ipi(int n, void *stack)
143
{
147
{
144
    trap_virtual_eoi();
148
    trap_virtual_eoi();
145
    tlb_shootdown_ipi_recv();
149
    tlb_shootdown_ipi_recv();
146
}
150
}
147
 
151
 
148
void wakeup_ipi(int n, void *stack)
152
void wakeup_ipi(int n, void *stack)
149
{
153
{
150
    trap_virtual_eoi();
154
    trap_virtual_eoi();
151
}
155
}
152
 
156
 
153
void trap_virtual_enable_irqs(__u16 irqmask)
157
void trap_virtual_enable_irqs(__u16 irqmask)
154
{
158
{
155
    if (enable_irqs_function)
159
    if (enable_irqs_function)
156
        enable_irqs_function(irqmask);
160
        enable_irqs_function(irqmask);
157
    else
161
    else
158
        panic("no enable_irqs_function\n");
162
        panic("no enable_irqs_function\n");
159
}
163
}
160
 
164
 
161
void trap_virtual_disable_irqs(__u16 irqmask)
165
void trap_virtual_disable_irqs(__u16 irqmask)
162
{
166
{
163
    if (disable_irqs_function)
167
    if (disable_irqs_function)
164
        disable_irqs_function(irqmask);
168
        disable_irqs_function(irqmask);
165
    else
169
    else
166
        panic("no disable_irqs_function\n");
170
        panic("no disable_irqs_function\n");
167
}
171
}
168
 
172
 
169
void trap_virtual_eoi(void)
173
void trap_virtual_eoi(void)
170
{
174
{
171
    if (eoi_function)
175
    if (eoi_function)
172
        eoi_function();
176
        eoi_function();
173
    else
177
    else
174
        panic("no eoi_function\n");
178
        panic("no eoi_function\n");
175
 
179
 
176
}
180
}
177
 
181