Subversion Repositories HelenOS-historic

Rev

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

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