Subversion Repositories HelenOS-historic

Rev

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

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