Subversion Repositories HelenOS-historic

Rev

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

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