Subversion Repositories HelenOS

Rev

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

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