Subversion Repositories HelenOS-historic

Rev

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

Rev 1196 Rev 1224
1
/*
1
/*
2
 * Copyright (C) 2005 Ondrej Palkovsky
2
 * Copyright (C) 2005 Ondrej Palkovsky
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 <interrupt.h>
29
#include <interrupt.h>
30
#include <debug.h>
30
#include <debug.h>
31
#include <console/kconsole.h>
31
#include <console/kconsole.h>
32
#include <console/console.h>
32
#include <console/console.h>
33
#include <console/chardev.h>
33
#include <console/chardev.h>
34
#include <console/cmd.h>
34
#include <console/cmd.h>
35
#include <panic.h>
35
#include <panic.h>
36
#include <print.h>
36
#include <print.h>
37
#include <symtab.h>
37
#include <symtab.h>
38
 
38
 
39
static struct {
39
static struct {
40
    const char *name;
40
    const char *name;
41
    iroutine f;
41
    iroutine f;
42
} exc_table[IVT_ITEMS];
42
} exc_table[IVT_ITEMS];
43
 
43
 
44
SPINLOCK_INITIALIZE(exctbl_lock);
44
SPINLOCK_INITIALIZE(exctbl_lock);
45
 
45
 
46
/** Register exception handler
46
/** Register exception handler
47
 *
47
 *
48
 * @param n Exception number
48
 * @param n Exception number
49
 * @param name Description
49
 * @param name Description
50
 * @param f Exception handler
50
 * @param f Exception handler
51
 */
51
 */
52
iroutine exc_register(int n, const char *name, iroutine f)
52
iroutine exc_register(int n, const char *name, iroutine f)
53
{
53
{
54
    ASSERT(n < IVT_ITEMS);
54
    ASSERT(n < IVT_ITEMS);
55
   
55
   
56
    iroutine old;
56
    iroutine old;
57
   
57
   
58
    spinlock_lock(&exctbl_lock);
58
    spinlock_lock(&exctbl_lock);
59
 
59
 
60
    old = exc_table[n].f;
60
    old = exc_table[n].f;
61
    exc_table[n].f = f;
61
    exc_table[n].f = f;
62
    exc_table[n].name = name;
62
    exc_table[n].name = name;
63
 
63
 
64
    spinlock_unlock(&exctbl_lock); 
64
    spinlock_unlock(&exctbl_lock); 
65
 
65
 
66
    return old;
66
    return old;
67
}
67
}
68
 
68
 
69
/** Dispatch exception according to exception table
69
/** Dispatch exception according to exception table
70
 *
70
 *
71
 * Called directly from the assembler code.
71
 * Called directly from the assembler code.
72
 * CPU is interrupts_disable()'d.
72
 * CPU is interrupts_disable()'d.
73
 */
73
 */
74
void exc_dispatch(int n, istate_t *istate)
74
void exc_dispatch(int n, istate_t *istate)
75
{
75
{
76
    ASSERT(n < IVT_ITEMS);
76
    ASSERT(n < IVT_ITEMS);
77
   
77
   
78
    exc_table[n].f(n + IVT_FIRST, istate);
78
    exc_table[n].f(n + IVT_FIRST, istate);
79
}
79
}
80
 
80
 
81
/** Default 'null' exception handler */
81
/** Default 'null' exception handler */
82
static void exc_undef(int n, istate_t *istate)
82
static void exc_undef(int n, istate_t *istate)
83
{
83
{
84
    panic("Unhandled exception %d.", n);
84
    panic("Unhandled exception %d.", n);
85
}
85
}
86
 
86
 
87
/** kconsole cmd - print all exceptions */
87
/** kconsole cmd - print all exceptions */
88
static int exc_print_cmd(cmd_arg_t *argv)
88
static int exc_print_cmd(cmd_arg_t *argv)
89
{
89
{
90
    int i;
90
    int i;
91
    char *symbol;
91
    char *symbol;
92
 
92
 
93
    spinlock_lock(&exctbl_lock);
93
    spinlock_lock(&exctbl_lock);
94
    printf("Exc Description Handler\n");
94
    printf("Exc Description Handler\n");
95
    for (i=0; i < IVT_ITEMS; i++) {
95
    for (i=0; i < IVT_ITEMS; i++) {
96
        symbol = get_symtab_entry((__native)exc_table[i].f);
96
        symbol = get_symtab_entry((__native)exc_table[i].f);
97
        if (!symbol)
97
        if (!symbol)
98
            symbol = "not found";
98
            symbol = "not found";
99
        printf("%d %s %p(%s)\n", i + IVT_FIRST, exc_table[i].name,
99
        printf("%d %s %.*p(%s)\n", i + IVT_FIRST, exc_table[i].name,
100
               exc_table[i].f,symbol);     
100
               sizeof(__address) * 2, exc_table[i].f,symbol);      
101
        if (!((i+1) % 20)) {
101
        if (!((i+1) % 20)) {
102
            printf("Press any key to continue.");
102
            printf("Press any key to continue.");
103
            spinlock_unlock(&exctbl_lock);
103
            spinlock_unlock(&exctbl_lock);
104
            getc(stdin);
104
            getc(stdin);
105
            spinlock_lock(&exctbl_lock);
105
            spinlock_lock(&exctbl_lock);
106
            printf("\n");
106
            printf("\n");
107
        }
107
        }
108
    }
108
    }
109
    spinlock_unlock(&exctbl_lock);
109
    spinlock_unlock(&exctbl_lock);
110
   
110
   
111
    return 1;
111
    return 1;
112
}
112
}
113
 
113
 
114
static cmd_info_t exc_info = {
114
static cmd_info_t exc_info = {
115
    .name = "exc",
115
    .name = "exc",
116
    .description = "Print exception table.",
116
    .description = "Print exception table.",
117
    .func = exc_print_cmd,
117
    .func = exc_print_cmd,
118
    .help = NULL,
118
    .help = NULL,
119
    .argc = 0,
119
    .argc = 0,
120
    .argv = NULL
120
    .argv = NULL
121
};
121
};
122
 
122
 
123
/** Initialize generic exception handling support */
123
/** Initialize generic exception handling support */
124
void exc_init(void)
124
void exc_init(void)
125
{
125
{
126
    int i;
126
    int i;
127
 
127
 
128
    for (i=0;i < IVT_ITEMS; i++)
128
    for (i=0;i < IVT_ITEMS; i++)
129
        exc_register(i, "undef", (iroutine) exc_undef);
129
        exc_register(i, "undef", (iroutine) exc_undef);
130
 
130
 
131
    cmd_initialize(&exc_info);
131
    cmd_initialize(&exc_info);
132
    if (!cmd_register(&exc_info))
132
    if (!cmd_register(&exc_info))
133
        panic("could not register command %s\n", exc_info.name);
133
        panic("could not register command %s\n", exc_info.name);
134
}
134
}
135
 
135
 
136
 
136