Subversion Repositories HelenOS

Rev

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

Rev 3071 Rev 3139
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
/** @addtogroup mips32debug
29
/** @addtogroup mips32debug
30
 * @{
30
 * @{
31
 */
31
 */
32
/** @file
32
/** @file
33
 */
33
 */
34
 
34
 
35
#include <arch/debugger.h>
35
#include <arch/debugger.h>
-
 
36
#include <arch/barrier.h>
36
#include <memstr.h>
37
#include <memstr.h>
37
#include <console/kconsole.h>
38
#include <console/kconsole.h>
38
#include <console/cmd.h>
39
#include <console/cmd.h>
39
#include <symtab.h>
40
#include <symtab.h>
40
#include <print.h>
41
#include <print.h>
41
#include <panic.h>
42
#include <panic.h>
42
#include <arch.h>
43
#include <arch.h>
43
#include <arch/cp0.h>
44
#include <arch/cp0.h>
44
#include <func.h>
45
#include <func.h>
45
 
46
 
46
bpinfo_t breakpoints[BKPOINTS_MAX];
47
bpinfo_t breakpoints[BKPOINTS_MAX];
47
SPINLOCK_INITIALIZE(bkpoint_lock);
48
SPINLOCK_INITIALIZE(bkpoint_lock);
48
 
49
 
49
static int cmd_print_breakpoints(cmd_arg_t *argv);
50
static int cmd_print_breakpoints(cmd_arg_t *argv);
50
static cmd_info_t bkpts_info = {
51
static cmd_info_t bkpts_info = {
51
    .name = "bkpts",
52
    .name = "bkpts",
52
    .description = "Print breakpoint table.",
53
    .description = "Print breakpoint table.",
53
    .func = cmd_print_breakpoints,
54
    .func = cmd_print_breakpoints,
54
    .argc = 0,
55
    .argc = 0,
55
};
56
};
56
 
57
 
57
static int cmd_del_breakpoint(cmd_arg_t *argv);
58
static int cmd_del_breakpoint(cmd_arg_t *argv);
58
static cmd_arg_t del_argv = {
59
static cmd_arg_t del_argv = {
59
    .type = ARG_TYPE_INT
60
    .type = ARG_TYPE_INT
60
};
61
};
61
static cmd_info_t delbkpt_info = {
62
static cmd_info_t delbkpt_info = {
62
    .name = "delbkpt",
63
    .name = "delbkpt",
63
    .description = "delbkpt <number> - Delete breakpoint.",
64
    .description = "delbkpt <number> - Delete breakpoint.",
64
    .func = cmd_del_breakpoint,
65
    .func = cmd_del_breakpoint,
65
    .argc = 1,
66
    .argc = 1,
66
    .argv = &del_argv
67
    .argv = &del_argv
67
};
68
};
68
 
69
 
69
static int cmd_add_breakpoint(cmd_arg_t *argv);
70
static int cmd_add_breakpoint(cmd_arg_t *argv);
70
static cmd_arg_t add_argv = {
71
static cmd_arg_t add_argv = {
71
    .type = ARG_TYPE_INT
72
    .type = ARG_TYPE_INT
72
};
73
};
73
static cmd_info_t addbkpt_info = {
74
static cmd_info_t addbkpt_info = {
74
    .name = "addbkpt",
75
    .name = "addbkpt",
75
    .description = "addbkpt <&symbol> - new bkpoint. Break on J/Branch insts unsupported.",
76
    .description = "addbkpt <&symbol> - new bkpoint. Break on J/Branch "
-
 
77
        "insts unsupported.",
76
    .func = cmd_add_breakpoint,
78
    .func = cmd_add_breakpoint,
77
    .argc = 1,
79
    .argc = 1,
78
    .argv = &add_argv
80
    .argv = &add_argv
79
};
81
};
80
 
82
 
81
static cmd_arg_t adde_argv[] = {
83
static cmd_arg_t adde_argv[] = {
82
    { .type = ARG_TYPE_INT },
84
    { .type = ARG_TYPE_INT },
83
    { .type = ARG_TYPE_INT }
85
    { .type = ARG_TYPE_INT }
84
};
86
};
85
static cmd_info_t addbkpte_info = {
87
static cmd_info_t addbkpte_info = {
86
    .name = "addbkpte",
88
    .name = "addbkpte",
87
    .description = "addebkpte <&symbol> <&func> - new bkpoint. Call func(or Nothing if 0).",
89
    .description = "addebkpte <&symbol> <&func> - new bkpoint. Call "
-
 
90
        "func(or Nothing if 0).",
88
    .func = cmd_add_breakpoint,
91
    .func = cmd_add_breakpoint,
89
    .argc = 2,
92
    .argc = 2,
90
    .argv = adde_argv
93
    .argv = adde_argv
91
};
94
};
92
 
95
 
93
static struct {
96
static struct {
94
    uint32_t andmask;
97
    uint32_t andmask;
95
    uint32_t value;
98
    uint32_t value;
96
}jmpinstr[] = {
99
} jmpinstr[] = {
97
    {0xf3ff0000, 0x41000000}, /* BCzF */
100
    {0xf3ff0000, 0x41000000}, /* BCzF */
98
    {0xf3ff0000, 0x41020000}, /* BCzFL */
101
    {0xf3ff0000, 0x41020000}, /* BCzFL */
99
    {0xf3ff0000, 0x41010000}, /* BCzT */
102
    {0xf3ff0000, 0x41010000}, /* BCzT */
100
    {0xf3ff0000, 0x41030000}, /* BCzTL */
103
    {0xf3ff0000, 0x41030000}, /* BCzTL */
101
    {0xfc000000, 0x10000000}, /* BEQ */
104
    {0xfc000000, 0x10000000}, /* BEQ */
102
    {0xfc000000, 0x50000000}, /* BEQL */
105
    {0xfc000000, 0x50000000}, /* BEQL */
103
    {0xfc1f0000, 0x04010000}, /* BEQL */
106
    {0xfc1f0000, 0x04010000}, /* BEQL */
104
    {0xfc1f0000, 0x04110000}, /* BGEZAL */
107
    {0xfc1f0000, 0x04110000}, /* BGEZAL */
105
    {0xfc1f0000, 0x04130000}, /* BGEZALL */
108
    {0xfc1f0000, 0x04130000}, /* BGEZALL */
106
    {0xfc1f0000, 0x04030000}, /* BGEZL */
109
    {0xfc1f0000, 0x04030000}, /* BGEZL */
107
    {0xfc1f0000, 0x1c000000}, /* BGTZ */
110
    {0xfc1f0000, 0x1c000000}, /* BGTZ */
108
    {0xfc1f0000, 0x5c000000}, /* BGTZL */
111
    {0xfc1f0000, 0x5c000000}, /* BGTZL */
109
    {0xfc1f0000, 0x18000000}, /* BLEZ */
112
    {0xfc1f0000, 0x18000000}, /* BLEZ */
110
    {0xfc1f0000, 0x58000000}, /* BLEZL */
113
    {0xfc1f0000, 0x58000000}, /* BLEZL */
111
    {0xfc1f0000, 0x04000000}, /* BLTZ */
114
    {0xfc1f0000, 0x04000000}, /* BLTZ */
112
    {0xfc1f0000, 0x04100000}, /* BLTZAL */
115
    {0xfc1f0000, 0x04100000}, /* BLTZAL */
113
    {0xfc1f0000, 0x04120000}, /* BLTZALL */
116
    {0xfc1f0000, 0x04120000}, /* BLTZALL */
114
    {0xfc1f0000, 0x04020000}, /* BLTZL */
117
    {0xfc1f0000, 0x04020000}, /* BLTZL */
115
    {0xfc000000, 0x14000000}, /* BNE */
118
    {0xfc000000, 0x14000000}, /* BNE */
116
    {0xfc000000, 0x54000000}, /* BNEL */
119
    {0xfc000000, 0x54000000}, /* BNEL */
117
    {0xfc000000, 0x08000000}, /* J */
120
    {0xfc000000, 0x08000000}, /* J */
118
    {0xfc000000, 0x0c000000}, /* JAL */
121
    {0xfc000000, 0x0c000000}, /* JAL */
119
    {0xfc1f07ff, 0x00000009}, /* JALR */
122
    {0xfc1f07ff, 0x00000009}, /* JALR */
120
    {0,0} /* EndOfTable */
123
    {0, 0} /* EndOfTable */
121
};
124
};
122
 
125
 
123
/** Test, if the given instruction is a jump or branch instruction
126
/** Test, if the given instruction is a jump or branch instruction
124
 *
127
 *
125
 * @param instr Instruction code
128
 * @param instr Instruction code
126
 * @return true - it is jump instruction, false otherwise
129
 * @return true - it is jump instruction, false otherwise
127
 */
130
 */
128
static bool is_jump(unative_t instr)
131
static bool is_jump(unative_t instr)
129
{
132
{
130
    int i;
133
    int i;
131
 
134
 
132
    for (i=0;jmpinstr[i].andmask;i++) {
135
    for (i = 0; jmpinstr[i].andmask; i++) {
133
        if ((instr & jmpinstr[i].andmask) == jmpinstr[i].value)
136
        if ((instr & jmpinstr[i].andmask) == jmpinstr[i].value)
134
            return true;
137
            return true;
135
    }
138
    }
136
 
139
 
137
    return false;
140
    return false;
138
}
141
}
139
 
142
 
140
/** Add new breakpoint to table */
143
/** Add new breakpoint to table */
141
int cmd_add_breakpoint(cmd_arg_t *argv)
144
int cmd_add_breakpoint(cmd_arg_t *argv)
142
{
145
{
143
    bpinfo_t *cur = NULL;
146
    bpinfo_t *cur = NULL;
144
    ipl_t ipl;
147
    ipl_t ipl;
145
    int i;
148
    int i;
146
 
149
 
147
    if (argv->intval & 0x3) {
150
    if (argv->intval & 0x3) {
148
        printf("Not aligned instruction, forgot to use &symbol?\n");
151
        printf("Not aligned instruction, forgot to use &symbol?\n");
149
        return 1;
152
        return 1;
150
    }
153
    }
151
    ipl = interrupts_disable();
154
    ipl = interrupts_disable();
152
    spinlock_lock(&bkpoint_lock);
155
    spinlock_lock(&bkpoint_lock);
153
 
156
 
154
    /* Check, that the breakpoints do not conflict */
157
    /* Check, that the breakpoints do not conflict */
155
    for (i = 0; i < BKPOINTS_MAX; i++) {
158
    for (i = 0; i < BKPOINTS_MAX; i++) {
156
        if (breakpoints[i].address == (uintptr_t)argv->intval) {
159
        if (breakpoints[i].address == (uintptr_t)argv->intval) {
157
            printf("Duplicate breakpoint %d.\n", i);
160
            printf("Duplicate breakpoint %d.\n", i);
158
            spinlock_unlock(&bkpoints_lock);
161
            spinlock_unlock(&bkpoints_lock);
159
            return 0;
162
            return 0;
160
        } else if (breakpoints[i].address == (uintptr_t)argv->intval + sizeof(unative_t) || \
163
        } else if (breakpoints[i].address == (uintptr_t)argv->intval +
-
 
164
            sizeof(unative_t) || breakpoints[i].address ==
161
               breakpoints[i].address == (uintptr_t)argv->intval - sizeof(unative_t)) {
165
            (uintptr_t)argv->intval - sizeof(unative_t)) {
162
            printf("Adjacent breakpoints not supported, conflict with %d.\n", i);
166
            printf("Adjacent breakpoints not supported, conflict "
-
 
167
                "with %d.\n", i);
163
            spinlock_unlock(&bkpoints_lock);
168
            spinlock_unlock(&bkpoints_lock);
164
            return 0;
169
            return 0;
165
        }
170
        }
166
           
171
           
167
    }
172
    }
168
 
173
 
169
    for (i=0; i<BKPOINTS_MAX; i++)
174
    for (i = 0; i < BKPOINTS_MAX; i++)
170
        if (!breakpoints[i].address) {
175
        if (!breakpoints[i].address) {
171
            cur = &breakpoints[i];
176
            cur = &breakpoints[i];
172
            break;
177
            break;
173
        }
178
        }
174
    if (!cur) {
179
    if (!cur) {
175
        printf("Too many breakpoints.\n");
180
        printf("Too many breakpoints.\n");
176
        spinlock_unlock(&bkpoint_lock);
181
        spinlock_unlock(&bkpoint_lock);
177
        interrupts_restore(ipl);
182
        interrupts_restore(ipl);
178
        return 0;
183
        return 0;
179
    }
184
    }
180
    cur->address = (uintptr_t) argv->intval;
185
    cur->address = (uintptr_t) argv->intval;
181
    printf("Adding breakpoint on address: %p\n", argv->intval);
186
    printf("Adding breakpoint on address: %p\n", argv->intval);
182
    cur->instruction = ((unative_t *)cur->address)[0];
187
    cur->instruction = ((unative_t *)cur->address)[0];
183
    cur->nextinstruction = ((unative_t *)cur->address)[1];
188
    cur->nextinstruction = ((unative_t *)cur->address)[1];
184
    if (argv == &add_argv) {
189
    if (argv == &add_argv) {
185
        cur->flags = 0;
190
        cur->flags = 0;
186
    } else { /* We are add extended */
191
    } else { /* We are add extended */
187
        cur->flags = BKPOINT_FUNCCALL;
192
        cur->flags = BKPOINT_FUNCCALL;
188
        cur->bkfunc =   (void (*)(void *, istate_t *)) argv[1].intval;
193
        cur->bkfunc = (void (*)(void *, istate_t *)) argv[1].intval;
189
    }
194
    }
190
    if (is_jump(cur->instruction))
195
    if (is_jump(cur->instruction))
191
        cur->flags |= BKPOINT_ONESHOT;
196
        cur->flags |= BKPOINT_ONESHOT;
192
    cur->counter = 0;
197
    cur->counter = 0;
193
 
198
 
194
    /* Set breakpoint */
199
    /* Set breakpoint */
195
    *((unative_t *)cur->address) = 0x0d;
200
    *((unative_t *)cur->address) = 0x0d;
-
 
201
    smc_coherence(cur->address);
196
 
202
 
197
    spinlock_unlock(&bkpoint_lock);
203
    spinlock_unlock(&bkpoint_lock);
198
    interrupts_restore(ipl);
204
    interrupts_restore(ipl);
199
 
205
 
200
    return 1;
206
    return 1;
201
}
207
}
202
 
208
 
203
 
-
 
204
 
-
 
205
/** Remove breakpoint from table */
209
/** Remove breakpoint from table */
206
int cmd_del_breakpoint(cmd_arg_t *argv)
210
int cmd_del_breakpoint(cmd_arg_t *argv)
207
{
211
{
208
    bpinfo_t *cur;
212
    bpinfo_t *cur;
209
    ipl_t ipl;
213
    ipl_t ipl;
210
 
214
 
211
    if (argv->intval > BKPOINTS_MAX) {
215
    if (argv->intval > BKPOINTS_MAX) {
212
        printf("Invalid breakpoint number.\n");
216
        printf("Invalid breakpoint number.\n");
213
        return 0;
217
        return 0;
214
    }
218
    }
215
    ipl = interrupts_disable();
219
    ipl = interrupts_disable();
216
    spinlock_lock(&bkpoint_lock);
220
    spinlock_lock(&bkpoint_lock);
217
 
221
 
218
    cur = &breakpoints[argv->intval];
222
    cur = &breakpoints[argv->intval];
219
    if (!cur->address) {
223
    if (!cur->address) {
220
        printf("Breakpoint does not exist.\n");
224
        printf("Breakpoint does not exist.\n");
221
        spinlock_unlock(&bkpoint_lock);
225
        spinlock_unlock(&bkpoint_lock);
222
        interrupts_restore(ipl);
226
        interrupts_restore(ipl);
223
        return 0;
227
        return 0;
224
    }
228
    }
225
    if ((cur->flags & BKPOINT_INPROG) && (cur->flags & BKPOINT_ONESHOT)) {
229
    if ((cur->flags & BKPOINT_INPROG) && (cur->flags & BKPOINT_ONESHOT)) {
226
        printf("Cannot remove one-shot breakpoint in-progress\n");
230
        printf("Cannot remove one-shot breakpoint in-progress\n");
227
        spinlock_unlock(&bkpoint_lock);
231
        spinlock_unlock(&bkpoint_lock);
228
        interrupts_restore(ipl);
232
        interrupts_restore(ipl);
229
        return 0;
233
        return 0;
230
    }
234
    }
231
    ((uint32_t *)cur->address)[0] = cur->instruction;
235
    ((uint32_t *)cur->address)[0] = cur->instruction;
-
 
236
    smc_coherence(((uint32_t *)cur->address)[0]);
232
    ((uint32_t *)cur->address)[1] = cur->nextinstruction;
237
    ((uint32_t *)cur->address)[1] = cur->nextinstruction;
-
 
238
    smc_coherence(((uint32_t *)cur->address)[1]);
233
 
239
 
234
    cur->address = NULL;
240
    cur->address = NULL;
235
 
241
 
236
    spinlock_unlock(&bkpoint_lock);
242
    spinlock_unlock(&bkpoint_lock);
237
    interrupts_restore(ipl);
243
    interrupts_restore(ipl);
238
    return 1;
244
    return 1;
239
}
245
}
240
 
246
 
241
/** Print table of active breakpoints */
247
/** Print table of active breakpoints */
242
int cmd_print_breakpoints(cmd_arg_t *argv)
248
int cmd_print_breakpoints(cmd_arg_t *argv)
243
{
249
{
244
    unsigned int i;
250
    unsigned int i;
245
    char *symbol;
251
    char *symbol;
246
   
252
   
247
    printf("#  Count Address    INPROG ONESHOT FUNCCALL In symbol\n");
253
    printf("#  Count Address    INPROG ONESHOT FUNCCALL In symbol\n");
248
    printf("-- ----- ---------- ------ ------- -------- ---------\n");
254
    printf("-- ----- ---------- ------ ------- -------- ---------\n");
249
   
255
   
250
    for (i = 0; i < BKPOINTS_MAX; i++)
256
    for (i = 0; i < BKPOINTS_MAX; i++)
251
        if (breakpoints[i].address) {
257
        if (breakpoints[i].address) {
252
            symbol = get_symtab_entry(breakpoints[i].address);
258
            symbol = get_symtab_entry(breakpoints[i].address);
253
           
259
           
254
            printf("%-2u %-5d %#10zx %-6s %-7s %-8s %s\n", i,
260
            printf("%-2u %-5d %#10zx %-6s %-7s %-8s %s\n", i,
255
                breakpoints[i].counter, breakpoints[i].address,
261
                breakpoints[i].counter, breakpoints[i].address,
256
                ((breakpoints[i].flags & BKPOINT_INPROG) ? "true" : "false"),
262
                ((breakpoints[i].flags & BKPOINT_INPROG) ? "true" :
257
                ((breakpoints[i].flags & BKPOINT_ONESHOT) ? "true" : "false"),
263
                "false"), ((breakpoints[i].flags & BKPOINT_ONESHOT)
-
 
264
                ? "true" : "false"), ((breakpoints[i].flags &
258
                ((breakpoints[i].flags & BKPOINT_FUNCCALL) ? "true" : "false"),
265
                BKPOINT_FUNCCALL) ? "true" : "false"), symbol);
259
                symbol);
-
 
260
        }
266
        }
261
    return 1;
267
    return 1;
262
}
268
}
263
 
269
 
264
/** Initialize debugger */
270
/** Initialize debugger */
265
void debugger_init()
271
void debugger_init()
266
{
272
{
267
    int i;
273
    int i;
268
 
274
 
269
    for (i=0; i<BKPOINTS_MAX; i++)
275
    for (i = 0; i < BKPOINTS_MAX; i++)
270
        breakpoints[i].address = NULL;
276
        breakpoints[i].address = NULL;
271
   
277
   
272
    cmd_initialize(&bkpts_info);
278
    cmd_initialize(&bkpts_info);
273
    if (!cmd_register(&bkpts_info))
279
    if (!cmd_register(&bkpts_info))
274
        panic("could not register command %s\n", bkpts_info.name);
280
        panic("could not register command %s\n", bkpts_info.name);
275
 
281
 
276
    cmd_initialize(&delbkpt_info);
282
    cmd_initialize(&delbkpt_info);
277
    if (!cmd_register(&delbkpt_info))
283
    if (!cmd_register(&delbkpt_info))
278
        panic("could not register command %s\n", delbkpt_info.name);
284
        panic("could not register command %s\n", delbkpt_info.name);
279
 
285
 
280
    cmd_initialize(&addbkpt_info);
286
    cmd_initialize(&addbkpt_info);
281
    if (!cmd_register(&addbkpt_info))
287
    if (!cmd_register(&addbkpt_info))
282
        panic("could not register command %s\n", addbkpt_info.name);
288
        panic("could not register command %s\n", addbkpt_info.name);
283
 
289
 
284
    cmd_initialize(&addbkpte_info);
290
    cmd_initialize(&addbkpte_info);
285
    if (!cmd_register(&addbkpte_info))
291
    if (!cmd_register(&addbkpte_info))
286
        panic("could not register command %s\n", addbkpte_info.name);
292
        panic("could not register command %s\n", addbkpte_info.name);
287
}
293
}
288
 
294
 
289
/** Handle breakpoint
295
/** Handle breakpoint
290
 *
296
 *
291
 * Find breakpoint in breakpoint table.
297
 * Find breakpoint in breakpoint table.
292
 * If found, call kconsole, set break on next instruction and reexecute.
298
 * If found, call kconsole, set break on next instruction and reexecute.
293
 * If we are on "next instruction", set it back on the first and reexecute.
299
 * If we are on "next instruction", set it back on the first and reexecute.
294
 * If breakpoint not found in breakpoint table, call kconsole and start
300
 * If breakpoint not found in breakpoint table, call kconsole and start
295
 * next instruction.
301
 * next instruction.
296
 */
302
 */
297
void debugger_bpoint(istate_t *istate)
303
void debugger_bpoint(istate_t *istate)
298
{
304
{
299
    bpinfo_t *cur = NULL;
305
    bpinfo_t *cur = NULL;
300
    uintptr_t fireaddr = istate->epc;
306
    uintptr_t fireaddr = istate->epc;
301
    int i;
307
    int i;
302
 
308
 
303
    /* test branch delay slot */
309
    /* test branch delay slot */
304
    if (cp0_cause_read() & 0x80000000)
310
    if (cp0_cause_read() & 0x80000000)
305
        panic("Breakpoint in branch delay slot not supported.\n");
311
        panic("Breakpoint in branch delay slot not supported.\n");
306
 
312
 
307
    spinlock_lock(&bkpoint_lock);
313
    spinlock_lock(&bkpoint_lock);
308
    for (i=0; i<BKPOINTS_MAX; i++) {
314
    for (i = 0; i < BKPOINTS_MAX; i++) {
309
        /* Normal breakpoint */
315
        /* Normal breakpoint */
310
        if (fireaddr == breakpoints[i].address \
316
        if (fireaddr == breakpoints[i].address &&
311
            && !(breakpoints[i].flags & BKPOINT_REINST)) {
317
            !(breakpoints[i].flags & BKPOINT_REINST)) {
312
            cur = &breakpoints[i];
318
            cur = &breakpoints[i];
313
            break;
319
            break;
314
        }
320
        }
315
        /* Reinst only breakpoint */
321
        /* Reinst only breakpoint */
316
        if ((breakpoints[i].flags & BKPOINT_REINST) \
322
        if ((breakpoints[i].flags & BKPOINT_REINST) &&
317
            && (fireaddr == breakpoints[i].address + sizeof(unative_t))) {
323
            (fireaddr == breakpoints[i].address + sizeof(unative_t))) {
318
            cur = &breakpoints[i];
324
            cur = &breakpoints[i];
319
            break;
325
            break;
320
        }
326
        }
321
    }
327
    }
322
    if (cur) {
328
    if (cur) {
323
        if (cur->flags & BKPOINT_REINST) {
329
        if (cur->flags & BKPOINT_REINST) {
324
            /* Set breakpoint on first instruction */
330
            /* Set breakpoint on first instruction */
325
            ((uint32_t *)cur->address)[0] = 0x0d;
331
            ((uint32_t *)cur->address)[0] = 0x0d;
-
 
332
            smc_coherence(((uint32_t *)cur->address)[0]);
326
            /* Return back the second */
333
            /* Return back the second */
327
            ((uint32_t *)cur->address)[1] = cur->nextinstruction;
334
            ((uint32_t *)cur->address)[1] = cur->nextinstruction;
-
 
335
            smc_coherence(((uint32_t *)cur->address)[1]);
328
            cur->flags &= ~BKPOINT_REINST;
336
            cur->flags &= ~BKPOINT_REINST;
329
            spinlock_unlock(&bkpoint_lock);
337
            spinlock_unlock(&bkpoint_lock);
330
            return;
338
            return;
331
        }
339
        }
332
        if (cur->flags & BKPOINT_INPROG)
340
        if (cur->flags & BKPOINT_INPROG)
333
            printf("Warning: breakpoint recursion\n");
341
            printf("Warning: breakpoint recursion\n");
334
       
342
       
335
        if (!(cur->flags & BKPOINT_FUNCCALL))
343
        if (!(cur->flags & BKPOINT_FUNCCALL))
336
            printf("***Breakpoint %d: %p in %s.\n", i,
344
            printf("***Breakpoint %d: %p in %s.\n", i, fireaddr,
337
                   fireaddr, get_symtab_entry(istate->epc));
345
                get_symtab_entry(istate->epc));
338
 
346
 
339
        /* Return first instruction back */
347
        /* Return first instruction back */
340
        ((uint32_t *)cur->address)[0] = cur->instruction;
348
        ((uint32_t *)cur->address)[0] = cur->instruction;
-
 
349
        smc_coherence(cur->address);
341
 
350
 
342
        if (! (cur->flags & BKPOINT_ONESHOT)) {
351
        if (! (cur->flags & BKPOINT_ONESHOT)) {
343
            /* Set Breakpoint on next instruction */
352
            /* Set Breakpoint on next instruction */
344
            ((uint32_t *)cur->address)[1] = 0x0d;
353
            ((uint32_t *)cur->address)[1] = 0x0d;
345
            cur->flags |= BKPOINT_REINST;
354
            cur->flags |= BKPOINT_REINST;
346
        }
355
        }
347
        cur->flags |= BKPOINT_INPROG;
356
        cur->flags |= BKPOINT_INPROG;
348
    } else {
357
    } else {
349
        printf("***Breakpoint %p in %s.\n", fireaddr,
358
        printf("***Breakpoint %p in %s.\n", fireaddr,
350
               get_symtab_entry(fireaddr));
359
               get_symtab_entry(fireaddr));
351
        /* Move on to next instruction */
360
        /* Move on to next instruction */
352
        istate->epc += 4;
361
        istate->epc += 4;
353
    }
362
    }
354
    if (cur)
363
    if (cur)
355
        cur->counter++;
364
        cur->counter++;
356
    if (cur && (cur->flags & BKPOINT_FUNCCALL)) {
365
    if (cur && (cur->flags & BKPOINT_FUNCCALL)) {
357
        /* Allow zero bkfunc, just for counting */
366
        /* Allow zero bkfunc, just for counting */
358
        if (cur->bkfunc)
367
        if (cur->bkfunc)
359
            cur->bkfunc(cur, istate);
368
            cur->bkfunc(cur, istate);
360
    } else {
369
    } else {
361
        printf("***Type 'exit' to exit kconsole.\n");
370
        printf("***Type 'exit' to exit kconsole.\n");
362
        /* This disables all other processors - we are not SMP,
371
        /* This disables all other processors - we are not SMP,
363
         * actually this gets us to cpu_halt, if scheduler() is run
372
         * actually this gets us to cpu_halt, if scheduler() is run
364
         * - we generally do not want scheduler to be run from debug,
373
         * - we generally do not want scheduler to be run from debug,
365
         *   so this is a good idea
374
         *   so this is a good idea
366
         */
375
         */
367
        atomic_set(&haltstate,1);
376
        atomic_set(&haltstate,1);
368
        spinlock_unlock(&bkpoint_lock);
377
        spinlock_unlock(&bkpoint_lock);
369
 
378
 
370
        kconsole("debug");
379
        kconsole("debug");
371
 
380
 
372
        spinlock_lock(&bkpoint_lock);
381
        spinlock_lock(&bkpoint_lock);
373
        atomic_set(&haltstate,0);
382
        atomic_set(&haltstate,0);
374
    }
383
    }
375
    if (cur && cur->address == fireaddr && (cur->flags & BKPOINT_INPROG)) {
384
    if (cur && cur->address == fireaddr && (cur->flags & BKPOINT_INPROG)) {
376
        /* Remove one-shot breakpoint */
385
        /* Remove one-shot breakpoint */
377
        if ((cur->flags & BKPOINT_ONESHOT))
386
        if ((cur->flags & BKPOINT_ONESHOT))
378
            cur->address = NULL;
387
            cur->address = NULL;
379
        /* Remove in-progress flag */
388
        /* Remove in-progress flag */
380
        cur->flags &= ~BKPOINT_INPROG;
389
        cur->flags &= ~BKPOINT_INPROG;
381
    }
390
    }
382
    spinlock_unlock(&bkpoint_lock);
391
    spinlock_unlock(&bkpoint_lock);
383
}
392
}
384
 
393
 
385
/** @}
394
/** @}
386
 */
395
 */
387
 
396