Subversion Repositories HelenOS-historic

Rev

Rev 1221 | Rev 1595 | 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>
431 jermar 47
 
1265 jermar 48
 
470 jermar 49
#define VECTORS_64_BUNDLE   20
50
#define VECTORS_16_BUNDLE   48
51
#define VECTORS_16_BUNDLE_START 0x5000
52
#define VECTOR_MAX      0x7f00
53
 
54
#define BUNDLE_SIZE     16
55
 
56
char *vector_names_64_bundle[VECTORS_64_BUNDLE] = {
57
    "VHPT Translation vector",
58
    "Instruction TLB vector",
59
    "Data TLB vector",
60
    "Alternate Instruction TLB vector",
61
    "Alternate Data TLB vector",
62
    "Data Nested TLB vector",
63
    "Instruction Key Miss vector",
64
    "Data Key Miss vector",
65
    "Dirty-Bit vector",
66
    "Instruction Access-Bit vector",
67
    "Data Access-Bit vector"
68
    "Break Instruction vector",
69
    "External Interrupt vector"
70
    "Reserved",
71
    "Reserved",
72
    "Reserved",
73
    "Reserved",
74
    "Reserved",
75
    "Reserved",
76
    "Reserved"
77
};
78
 
79
char *vector_names_16_bundle[VECTORS_16_BUNDLE] = {
80
    "Page Not Present vector",
81
    "Key Permission vector",
82
    "Instruction Access rights vector",
83
    "Data Access Rights vector",
84
    "General Exception vector",
85
    "Disabled FP-Register vector",
86
    "NaT Consumption vector",
87
    "Speculation vector",
88
    "Reserved",
89
    "Debug vector",
90
    "Unaligned Reference vector",
91
    "Unsupported Data Reference vector",
92
    "Floating-point Fault vector",
93
    "Floating-point Trap vector",
94
    "Lower-Privilege Transfer Trap vector",
95
    "Taken Branch Trap vector",
96
    "Single STep Trap vector",
97
    "Reserved",
98
    "Reserved",
99
    "Reserved",
100
    "Reserved",
101
    "Reserved",
102
    "Reserved",
103
    "Reserved",
104
    "Reserved",
105
    "IA-32 Exception vector",
106
    "IA-32 Intercept vector",
107
    "IA-32 Interrupt vector",
108
    "Reserved",
109
    "Reserved",
110
    "Reserved"
111
};
112
 
113
static char *vector_to_string(__u16 vector);
958 jermar 114
static void dump_interrupted_context(istate_t *istate);
470 jermar 115
 
116
char *vector_to_string(__u16 vector)
431 jermar 117
{
470 jermar 118
    ASSERT(vector <= VECTOR_MAX);
119
 
120
    if (vector >= VECTORS_16_BUNDLE_START)
121
        return vector_names_16_bundle[(vector-VECTORS_16_BUNDLE_START)/(16*BUNDLE_SIZE)];
122
    else
123
        return vector_names_64_bundle[vector/(64*BUNDLE_SIZE)];
124
}
125
 
958 jermar 126
void dump_interrupted_context(istate_t *istate)
470 jermar 127
{
128
    char *ifa, *iipa, *iip;
129
 
958 jermar 130
    ifa = get_symtab_entry(istate->cr_ifa);
131
    iipa = get_symtab_entry(istate->cr_iipa);
132
    iip = get_symtab_entry(istate->cr_iip);
470 jermar 133
 
134
    putchar('\n');
472 jermar 135
    printf("Interrupted context dump:\n");
1221 decky 136
    printf("ar.bsp=%p\tar.bspstore=%p\n", istate->ar_bsp, istate->ar_bspstore);
137
    printf("ar.rnat=%#llx\tar.rsc=%$llx\n", istate->ar_rnat, istate->ar_rsc);
138
    printf("ar.ifs=%#llx\tar.pfs=%#llx\n", istate->ar_ifs, istate->ar_pfs);
139
    printf("cr.isr=%#llx\tcr.ipsr=%#llx\t\n", istate->cr_isr.value, istate->cr_ipsr);
470 jermar 140
 
1221 decky 141
    printf("cr.iip=%#llx, #%d\t(%s)\n", istate->cr_iip, istate->cr_isr.ei, iip ? iip : "?");
142
    printf("cr.iipa=%#llx\t(%s)\n", istate->cr_iipa, iipa ? iipa : "?");
143
    printf("cr.ifa=%#llx\t(%s)\n", istate->cr_ifa, ifa ? ifa : "?");
470 jermar 144
}
145
 
958 jermar 146
void general_exception(__u64 vector, istate_t *istate)
470 jermar 147
{
472 jermar 148
    char *desc = "";
149
 
958 jermar 150
    dump_interrupted_context(istate);
472 jermar 151
 
958 jermar 152
    switch (istate->cr_isr.ge_code) {
472 jermar 153
        case GE_ILLEGALOP:
154
        desc = "Illegal Operation fault";
155
        break;
156
        case GE_PRIVOP:
157
        desc = "Privileged Operation fault";
158
        break;
159
        case GE_PRIVREG:
160
        desc = "Privileged Register fault";
161
        break;
162
        case GE_RESREGFLD:
163
        desc = "Reserved Register/Field fault";
164
        break;
165
        case GE_DISBLDISTRAN:
166
        desc = "Disabled Instruction Set Transition fault";
167
        break;
168
        case GE_ILLEGALDEP:
169
        desc = "Illegal Dependency fault";
170
        break;
171
        default:
172
            desc = "unknown";
173
        break;
174
    }
175
 
176
    panic("General Exception (%s)\n", desc);
470 jermar 177
}
178
 
1053 vana 179
void fpu_enable(void);
1023 vana 180
 
181
void disabled_fp_register(__u64 vector, istate_t *istate)
182
{
1053 vana 183
#ifdef CONFIG_FPU_LAZY 
1023 vana 184
    scheduler_fpu_lazy_request();  
1053 vana 185
#else
186
    dump_interrupted_context(istate);
1221 decky 187
    panic("Interruption: %#hx (%s)\n", (__u16) vector, vector_to_string(vector));
1023 vana 188
#endif
189
}
190
 
191
 
192
void nop_handler(__u64 vector, istate_t *istate)
193
{
194
}
195
 
196
 
197
 
921 jermar 198
/** Handle syscall. */
958 jermar 199
int break_instruction(__u64 vector, istate_t *istate)
470 jermar 200
{
921 jermar 201
    /*
202
     * Move to next instruction after BREAK.
203
     */
958 jermar 204
    if (istate->cr_ipsr.ri == 2) {
205
        istate->cr_ipsr.ri = 0;
206
        istate->cr_iip += 16;
921 jermar 207
    } else {
958 jermar 208
        istate->cr_ipsr.ri++;
921 jermar 209
    }
210
 
962 jermar 211
    if (istate->in4 < SYSCALL_END)
212
        return syscall_table[istate->in4](istate->in0, istate->in1, istate->in2, istate->in3);
921 jermar 213
    else
962 jermar 214
        panic("Undefined syscall %d", istate->in4);
921 jermar 215
 
216
    return -1;
470 jermar 217
}
218
 
958 jermar 219
void universal_handler(__u64 vector, istate_t *istate)
470 jermar 220
{
958 jermar 221
    dump_interrupted_context(istate);
1221 decky 222
    panic("Interruption: %#hx (%s)\n", (__u16) vector, vector_to_string(vector));
470 jermar 223
}
224
 
958 jermar 225
void external_interrupt(__u64 vector, istate_t *istate)
470 jermar 226
{
433 jermar 227
    cr_ivr_t ivr;
431 jermar 228
 
433 jermar 229
    ivr.value = ivr_read();
431 jermar 230
    srlz_d();
444 vana 231
 
434 jermar 232
    switch(ivr.vector) {
433 jermar 233
        case INTERRUPT_TIMER:
435 jermar 234
        it_interrupt();
433 jermar 235
            break;
236
        case INTERRUPT_SPURIOUS:
237
            printf("cpu%d: spurious interrupt\n", CPU->id);
238
        break;
431 jermar 239
        default:
433 jermar 240
        panic("\nUnhandled External Interrupt Vector %d\n", ivr.vector);
241
        break;
431 jermar 242
    }
243
}
1265 jermar 244
 
245
/* Reregister irq to be IPC-ready */
246
void irq_ipc_bind_arch(__native irq)
247
{
248
    panic("not implemented\n");
249
    /* TODO */
250
}