Subversion Repositories HelenOS-historic

Rev

Rev 1595 | Rev 1702 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
431 jermar 1
/*
2
 * Copyright (C) 2005 Jakub Jermar
470 jermar 3
 * Copyright (C) 2005 Jakub Vana
431 jermar 4
 * All rights reserved.
5
 *
6
 * Redistribution and use in source and binary forms, with or without
7
 * modification, are permitted provided that the following conditions
8
 * are met:
9
 *
10
 * - Redistributions of source code must retain the above copyright
11
 *   notice, this list of conditions and the following disclaimer.
12
 * - Redistributions in binary form must reproduce the above copyright
13
 *   notice, this list of conditions and the following disclaimer in the
14
 *   documentation and/or other materials provided with the distribution.
15
 * - The name of the author may not be used to endorse or promote products
16
 *   derived from this software without specific prior written permission.
17
 *
18
 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
19
 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
20
 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
21
 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
22
 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
23
 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
24
 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
25
 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
26
 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
27
 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28
 *
29
 */
30
 
31
#include <arch/interrupt.h>
32
#include <panic.h>
433 jermar 33
#include <print.h>
583 jermar 34
#include <console/console.h>
431 jermar 35
#include <arch/types.h>
36
#include <arch/asm.h>
37
#include <arch/barrier.h>
432 jermar 38
#include <arch/register.h>
435 jermar 39
#include <arch/drivers/it.h>
433 jermar 40
#include <arch.h>
470 jermar 41
#include <symtab.h>
42
#include <debug.h>
921 jermar 43
#include <syscall/syscall.h>
44
#include <print.h>
1023 vana 45
#include <proc/scheduler.h>
1265 jermar 46
#include <ipc/sysipc.h>
1507 vana 47
#include <ipc/irq.h>
48
#include <ipc/ipc.h>
1595 palkovsky 49
#include <interrupt.h>
431 jermar 50
 
1265 jermar 51
 
470 jermar 52
#define VECTORS_64_BUNDLE   20
53
#define VECTORS_16_BUNDLE   48
54
#define VECTORS_16_BUNDLE_START 0x5000
55
#define VECTOR_MAX      0x7f00
56
 
57
#define BUNDLE_SIZE     16
58
 
1507 vana 59
 
470 jermar 60
char *vector_names_64_bundle[VECTORS_64_BUNDLE] = {
61
    "VHPT Translation vector",
62
    "Instruction TLB vector",
63
    "Data TLB vector",
64
    "Alternate Instruction TLB vector",
65
    "Alternate Data TLB vector",
66
    "Data Nested TLB vector",
67
    "Instruction Key Miss vector",
68
    "Data Key Miss vector",
69
    "Dirty-Bit vector",
70
    "Instruction Access-Bit vector",
71
    "Data Access-Bit vector"
72
    "Break Instruction vector",
73
    "External Interrupt vector"
74
    "Reserved",
75
    "Reserved",
76
    "Reserved",
77
    "Reserved",
78
    "Reserved",
79
    "Reserved",
80
    "Reserved"
81
};
82
 
83
char *vector_names_16_bundle[VECTORS_16_BUNDLE] = {
84
    "Page Not Present vector",
85
    "Key Permission vector",
86
    "Instruction Access rights vector",
87
    "Data Access Rights vector",
88
    "General Exception vector",
89
    "Disabled FP-Register vector",
90
    "NaT Consumption vector",
91
    "Speculation vector",
92
    "Reserved",
93
    "Debug vector",
94
    "Unaligned Reference vector",
95
    "Unsupported Data Reference vector",
96
    "Floating-point Fault vector",
97
    "Floating-point Trap vector",
98
    "Lower-Privilege Transfer Trap vector",
99
    "Taken Branch Trap vector",
100
    "Single STep Trap vector",
101
    "Reserved",
102
    "Reserved",
103
    "Reserved",
104
    "Reserved",
105
    "Reserved",
106
    "Reserved",
107
    "Reserved",
108
    "Reserved",
109
    "IA-32 Exception vector",
110
    "IA-32 Intercept vector",
111
    "IA-32 Interrupt vector",
112
    "Reserved",
113
    "Reserved",
114
    "Reserved"
115
};
116
 
117
static char *vector_to_string(__u16 vector);
958 jermar 118
static void dump_interrupted_context(istate_t *istate);
470 jermar 119
 
120
char *vector_to_string(__u16 vector)
431 jermar 121
{
470 jermar 122
    ASSERT(vector <= VECTOR_MAX);
123
 
124
    if (vector >= VECTORS_16_BUNDLE_START)
125
        return vector_names_16_bundle[(vector-VECTORS_16_BUNDLE_START)/(16*BUNDLE_SIZE)];
126
    else
127
        return vector_names_64_bundle[vector/(64*BUNDLE_SIZE)];
128
}
129
 
958 jermar 130
void dump_interrupted_context(istate_t *istate)
470 jermar 131
{
132
    char *ifa, *iipa, *iip;
133
 
958 jermar 134
    ifa = get_symtab_entry(istate->cr_ifa);
135
    iipa = get_symtab_entry(istate->cr_iipa);
136
    iip = get_symtab_entry(istate->cr_iip);
470 jermar 137
 
138
    putchar('\n');
472 jermar 139
    printf("Interrupted context dump:\n");
1221 decky 140
    printf("ar.bsp=%p\tar.bspstore=%p\n", istate->ar_bsp, istate->ar_bspstore);
1507 vana 141
    printf("ar.rnat=%#018llx\tar.rsc=%#018llx\n", istate->ar_rnat, istate->ar_rsc);
142
    printf("ar.ifs=%#018llx\tar.pfs=%#018llx\n", istate->ar_ifs, istate->ar_pfs);
143
    printf("cr.isr=%#018llx\tcr.ipsr=%#018llx\t\n", istate->cr_isr.value, istate->cr_ipsr);
470 jermar 144
 
1507 vana 145
    printf("cr.iip=%#018llx, #%d\t(%s)\n", istate->cr_iip, istate->cr_isr.ei, iip);
146
    printf("cr.iipa=%#018llx\t(%s)\n", istate->cr_iipa, iipa);
147
    printf("cr.ifa=%#018llx\t(%s)\n", istate->cr_ifa, ifa);
470 jermar 148
}
149
 
958 jermar 150
void general_exception(__u64 vector, istate_t *istate)
470 jermar 151
{
472 jermar 152
    char *desc = "";
153
 
958 jermar 154
    switch (istate->cr_isr.ge_code) {
472 jermar 155
        case GE_ILLEGALOP:
156
        desc = "Illegal Operation fault";
157
        break;
158
        case GE_PRIVOP:
159
        desc = "Privileged Operation fault";
160
        break;
161
        case GE_PRIVREG:
162
        desc = "Privileged Register fault";
163
        break;
164
        case GE_RESREGFLD:
165
        desc = "Reserved Register/Field fault";
166
        break;
167
        case GE_DISBLDISTRAN:
168
        desc = "Disabled Instruction Set Transition fault";
169
        break;
170
        case GE_ILLEGALDEP:
171
        desc = "Illegal Dependency fault";
172
        break;
173
        default:
174
            desc = "unknown";
175
        break;
176
    }
177
 
1595 palkovsky 178
    fault_if_from_uspace(istate, "General Exception (%s)", desc);
179
 
180
    dump_interrupted_context(istate);
472 jermar 181
    panic("General Exception (%s)\n", desc);
470 jermar 182
}
183
 
1053 vana 184
void fpu_enable(void);
1023 vana 185
 
186
void disabled_fp_register(__u64 vector, istate_t *istate)
187
{
1053 vana 188
#ifdef CONFIG_FPU_LAZY 
1023 vana 189
    scheduler_fpu_lazy_request();  
1053 vana 190
#else
1595 palkovsky 191
    fault_if_from_uspace(istate, "Interruption: %#hx (%s)", (__u16) vector, vector_to_string(vector));
1053 vana 192
    dump_interrupted_context(istate);
1221 decky 193
    panic("Interruption: %#hx (%s)\n", (__u16) vector, vector_to_string(vector));
1023 vana 194
#endif
195
}
196
 
197
 
198
void nop_handler(__u64 vector, istate_t *istate)
199
{
200
}
201
 
202
 
203
 
921 jermar 204
/** Handle syscall. */
958 jermar 205
int break_instruction(__u64 vector, istate_t *istate)
470 jermar 206
{
921 jermar 207
    /*
208
     * Move to next instruction after BREAK.
209
     */
958 jermar 210
    if (istate->cr_ipsr.ri == 2) {
211
        istate->cr_ipsr.ri = 0;
212
        istate->cr_iip += 16;
921 jermar 213
    } else {
958 jermar 214
        istate->cr_ipsr.ri++;
921 jermar 215
    }
216
 
962 jermar 217
    if (istate->in4 < SYSCALL_END)
218
        return syscall_table[istate->in4](istate->in0, istate->in1, istate->in2, istate->in3);
921 jermar 219
    else
962 jermar 220
        panic("Undefined syscall %d", istate->in4);
921 jermar 221
 
222
    return -1;
470 jermar 223
}
224
 
958 jermar 225
void universal_handler(__u64 vector, istate_t *istate)
470 jermar 226
{
1621 vana 227
    fault_if_from_uspace(istate,"Interruption: %#hx (%s)\n",(__u16) vector, vector_to_string(vector));
958 jermar 228
    dump_interrupted_context(istate);
1221 decky 229
    panic("Interruption: %#hx (%s)\n", (__u16) vector, vector_to_string(vector));
470 jermar 230
}
231
 
958 jermar 232
void external_interrupt(__u64 vector, istate_t *istate)
470 jermar 233
{
433 jermar 234
    cr_ivr_t ivr;
431 jermar 235
 
433 jermar 236
    ivr.value = ivr_read();
431 jermar 237
    srlz_d();
444 vana 238
 
434 jermar 239
    switch(ivr.vector) {
433 jermar 240
        case INTERRUPT_TIMER:
435 jermar 241
        it_interrupt();
433 jermar 242
            break;
243
        case INTERRUPT_SPURIOUS:
244
            printf("cpu%d: spurious interrupt\n", CPU->id);
245
        break;
431 jermar 246
        default:
433 jermar 247
        panic("\nUnhandled External Interrupt Vector %d\n", ivr.vector);
248
        break;
431 jermar 249
    }
250
}
1265 jermar 251
 
1507 vana 252
void virtual_interrupt(__u64 irq,void *param)
253
{
254
    switch(irq) {
255
        case IRQ_KBD:
256
            if(kbd_uspace) ipc_irq_send_notif(irq);
257
            break;
258
        default:
259
            panic("\nUnhandled Virtual Interrupt request %d\n", irq);
260
        break;
261
    }
262
}
263
 
1265 jermar 264
/* Reregister irq to be IPC-ready */
265
void irq_ipc_bind_arch(__native irq)
266
{
1507 vana 267
    if(irq==IRQ_KBD) {
268
        kbd_uspace=1;
269
        return;
270
    }
1621 vana 271
    return;
1265 jermar 272
    panic("not implemented\n");
273
    /* TODO */
274
}