Subversion Repositories HelenOS-historic

Rev

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

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