Subversion Repositories HelenOS-historic

Rev

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

Rev 1702 Rev 1705
1
/*
1
/*
2
 * Copyright (C) 2006 Ondrej Palkovsky
2
 * Copyright (C) 2006 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 amd64debug ia32/amd64
29
 /** @addtogroup amd64debug
30
 * @ingroup debug
-
 
31
 * @{
30
 * @{
32
 */
31
 */
33
/** @file
32
/** @file
34
 */
33
 */
35
 
34
 
36
#include <arch/debugger.h>
35
#include <arch/debugger.h>
37
#include <console/kconsole.h>
36
#include <console/kconsole.h>
38
#include <console/cmd.h>
37
#include <console/cmd.h>
39
#include <symtab.h>
38
#include <symtab.h>
40
#include <print.h>
39
#include <print.h>
41
#include <panic.h>
40
#include <panic.h>
42
#include <interrupt.h>
41
#include <interrupt.h>
43
#include <arch/asm.h>
42
#include <arch/asm.h>
44
#include <arch/cpu.h>
43
#include <arch/cpu.h>
45
#include <debug.h>
44
#include <debug.h>
46
#include <func.h>
45
#include <func.h>
47
#include <smp/ipi.h>
46
#include <smp/ipi.h>
48
 
47
 
49
typedef struct  {
48
typedef struct  {
50
    __address address;      /**< Breakpoint address */
49
    __address address;      /**< Breakpoint address */
51
    int flags;              /**< Flags regarding breakpoint */
50
    int flags;              /**< Flags regarding breakpoint */
52
    int counter;            /**< How many times the exception occured */
51
    int counter;            /**< How many times the exception occured */
53
} bpinfo_t;
52
} bpinfo_t;
54
 
53
 
55
static bpinfo_t breakpoints[BKPOINTS_MAX];
54
static bpinfo_t breakpoints[BKPOINTS_MAX];
56
SPINLOCK_INITIALIZE(bkpoint_lock);
55
SPINLOCK_INITIALIZE(bkpoint_lock);
57
 
56
 
58
static int cmd_print_breakpoints(cmd_arg_t *argv);
57
static int cmd_print_breakpoints(cmd_arg_t *argv);
59
static cmd_info_t bkpts_info = {
58
static cmd_info_t bkpts_info = {
60
    .name = "bkpts",
59
    .name = "bkpts",
61
    .description = "Print breakpoint table.",
60
    .description = "Print breakpoint table.",
62
    .func = cmd_print_breakpoints,
61
    .func = cmd_print_breakpoints,
63
    .argc = 0,
62
    .argc = 0,
64
};
63
};
65
 
64
 
66
#ifndef CONFIG_DEBUG_AS_WATCHPOINT
65
#ifndef CONFIG_DEBUG_AS_WATCHPOINT
67
 
66
 
68
static int cmd_del_breakpoint(cmd_arg_t *argv);
67
static int cmd_del_breakpoint(cmd_arg_t *argv);
69
static cmd_arg_t del_argv = {
68
static cmd_arg_t del_argv = {
70
    .type = ARG_TYPE_INT
69
    .type = ARG_TYPE_INT
71
};
70
};
72
static cmd_info_t delbkpt_info = {
71
static cmd_info_t delbkpt_info = {
73
    .name = "delbkpt",
72
    .name = "delbkpt",
74
    .description = "delbkpt <number> - Delete breakpoint.",
73
    .description = "delbkpt <number> - Delete breakpoint.",
75
    .func = cmd_del_breakpoint,
74
    .func = cmd_del_breakpoint,
76
    .argc = 1,
75
    .argc = 1,
77
    .argv = &del_argv
76
    .argv = &del_argv
78
};
77
};
79
 
78
 
80
static int cmd_add_breakpoint(cmd_arg_t *argv);
79
static int cmd_add_breakpoint(cmd_arg_t *argv);
81
static cmd_arg_t add_argv = {
80
static cmd_arg_t add_argv = {
82
    .type = ARG_TYPE_INT
81
    .type = ARG_TYPE_INT
83
};
82
};
84
static cmd_info_t addbkpt_info = {
83
static cmd_info_t addbkpt_info = {
85
    .name = "addbkpt",
84
    .name = "addbkpt",
86
    .description = "addbkpt <&symbol> - new breakpoint.",
85
    .description = "addbkpt <&symbol> - new breakpoint.",
87
    .func = cmd_add_breakpoint,
86
    .func = cmd_add_breakpoint,
88
    .argc = 1,
87
    .argc = 1,
89
    .argv = &add_argv
88
    .argv = &add_argv
90
};
89
};
91
 
90
 
92
static cmd_arg_t addw_argv = {
91
static cmd_arg_t addw_argv = {
93
    .type = ARG_TYPE_INT
92
    .type = ARG_TYPE_INT
94
};
93
};
95
static cmd_info_t addwatchp_info = {
94
static cmd_info_t addwatchp_info = {
96
    .name = "addwatchp",
95
    .name = "addwatchp",
97
    .description = "addbwatchp <&symbol> - new write watchpoint.",
96
    .description = "addbwatchp <&symbol> - new write watchpoint.",
98
    .func = cmd_add_breakpoint,
97
    .func = cmd_add_breakpoint,
99
    .argc = 1,
98
    .argc = 1,
100
    .argv = &addw_argv
99
    .argv = &addw_argv
101
};
100
};
102
 
101
 
103
#endif
102
#endif
104
 
103
 
105
/** Print table of active breakpoints */
104
/** Print table of active breakpoints */
106
int cmd_print_breakpoints(cmd_arg_t *argv)
105
int cmd_print_breakpoints(cmd_arg_t *argv)
107
{
106
{
108
    int i;
107
    int i;
109
    char *symbol;
108
    char *symbol;
110
 
109
 
111
    printf("Breakpoint table.\n");
110
    printf("Breakpoint table.\n");
112
    for (i=0; i < BKPOINTS_MAX; i++)
111
    for (i=0; i < BKPOINTS_MAX; i++)
113
        if (breakpoints[i].address) {
112
        if (breakpoints[i].address) {
114
            symbol = get_symtab_entry(breakpoints[i].address);
113
            symbol = get_symtab_entry(breakpoints[i].address);
115
            printf("%d. %p in %s\n",i,
114
            printf("%d. %p in %s\n",i,
116
                   breakpoints[i].address, symbol);
115
                   breakpoints[i].address, symbol);
117
            printf("     Count(%d) ", breakpoints[i].counter);
116
            printf("     Count(%d) ", breakpoints[i].counter);
118
            printf("\n");
117
            printf("\n");
119
        }
118
        }
120
    return 1;
119
    return 1;
121
}
120
}
122
 
121
 
123
/* Setup DR register according to table */
122
/* Setup DR register according to table */
124
static void setup_dr(int curidx)
123
static void setup_dr(int curidx)
125
{
124
{
126
    __native dr7;
125
    __native dr7;
127
    bpinfo_t *cur = &breakpoints[curidx];
126
    bpinfo_t *cur = &breakpoints[curidx];
128
    int flags = breakpoints[curidx].flags;
127
    int flags = breakpoints[curidx].flags;
129
 
128
 
130
    /* Disable breakpoint in DR7 */
129
    /* Disable breakpoint in DR7 */
131
    dr7 = read_dr7();
130
    dr7 = read_dr7();
132
    dr7 &= ~(0x2 << (curidx*2));
131
    dr7 &= ~(0x2 << (curidx*2));
133
 
132
 
134
    if (cur->address) { /* Setup DR register */
133
    if (cur->address) { /* Setup DR register */
135
        /* Set breakpoint to debug registers */
134
        /* Set breakpoint to debug registers */
136
        switch (curidx) {
135
        switch (curidx) {
137
        case 0:
136
        case 0:
138
            write_dr0(cur->address);
137
            write_dr0(cur->address);
139
            break;
138
            break;
140
        case 1:
139
        case 1:
141
            write_dr1(cur->address);
140
            write_dr1(cur->address);
142
            break;
141
            break;
143
        case 2:
142
        case 2:
144
            write_dr2(cur->address);
143
            write_dr2(cur->address);
145
            break;
144
            break;
146
        case 3:
145
        case 3:
147
            write_dr3(cur->address);
146
            write_dr3(cur->address);
148
            break;
147
            break;
149
        }
148
        }
150
        /* Set type to requested breakpoint & length*/
149
        /* Set type to requested breakpoint & length*/
151
        dr7 &= ~ (0x3 << (16 + 4*curidx));
150
        dr7 &= ~ (0x3 << (16 + 4*curidx));
152
        dr7 &= ~ (0x3 << (18 + 4*curidx));
151
        dr7 &= ~ (0x3 << (18 + 4*curidx));
153
        if ((flags & BKPOINT_INSTR)) {
152
        if ((flags & BKPOINT_INSTR)) {
154
            ;
153
            ;
155
        } else {
154
        } else {
156
            if (sizeof(int) == 4)
155
            if (sizeof(int) == 4)
157
                dr7 |= ((__native) 0x3) << (18 + 4*curidx);
156
                dr7 |= ((__native) 0x3) << (18 + 4*curidx);
158
            else /* 8 */
157
            else /* 8 */
159
                dr7 |= ((__native) 0x2) << (18 + 4*curidx);
158
                dr7 |= ((__native) 0x2) << (18 + 4*curidx);
160
           
159
           
161
            if ((flags & BKPOINT_WRITE))
160
            if ((flags & BKPOINT_WRITE))
162
                dr7 |= ((__native) 0x1) << (16 + 4*curidx);
161
                dr7 |= ((__native) 0x1) << (16 + 4*curidx);
163
            else if ((flags & BKPOINT_READ_WRITE))
162
            else if ((flags & BKPOINT_READ_WRITE))
164
                dr7 |= ((__native) 0x3) << (16 + 4*curidx);
163
                dr7 |= ((__native) 0x3) << (16 + 4*curidx);
165
        }
164
        }
166
 
165
 
167
        /* Enable global breakpoint */
166
        /* Enable global breakpoint */
168
        dr7 |= 0x2 << (curidx*2);
167
        dr7 |= 0x2 << (curidx*2);
169
 
168
 
170
        write_dr7(dr7);
169
        write_dr7(dr7);
171
       
170
       
172
    }
171
    }
173
}
172
}
174
   
173
   
175
/** Enable hardware breakpoint
174
/** Enable hardware breakpoint
176
 *
175
 *
177
 *
176
 *
178
 * @param where Address of HW breakpoint
177
 * @param where Address of HW breakpoint
179
 * @param flags Type of breakpoint (EXECUTE, WRITE)
178
 * @param flags Type of breakpoint (EXECUTE, WRITE)
180
 * @return Debug slot on success, -1 - no available HW breakpoint
179
 * @return Debug slot on success, -1 - no available HW breakpoint
181
 */
180
 */
182
int breakpoint_add(void * where, int flags, int curidx)
181
int breakpoint_add(void * where, int flags, int curidx)
183
{
182
{
184
    ipl_t ipl;
183
    ipl_t ipl;
185
    int i;
184
    int i;
186
    bpinfo_t *cur;
185
    bpinfo_t *cur;
187
 
186
 
188
    ASSERT( flags & (BKPOINT_INSTR | BKPOINT_WRITE | BKPOINT_READ_WRITE));
187
    ASSERT( flags & (BKPOINT_INSTR | BKPOINT_WRITE | BKPOINT_READ_WRITE));
189
 
188
 
190
    ipl = interrupts_disable();
189
    ipl = interrupts_disable();
191
    spinlock_lock(&bkpoint_lock);
190
    spinlock_lock(&bkpoint_lock);
192
   
191
   
193
    if (curidx == -1) {
192
    if (curidx == -1) {
194
        /* Find free space in slots */
193
        /* Find free space in slots */
195
        for (i=0; i<BKPOINTS_MAX; i++)
194
        for (i=0; i<BKPOINTS_MAX; i++)
196
            if (!breakpoints[i].address) {
195
            if (!breakpoints[i].address) {
197
                curidx = i;
196
                curidx = i;
198
                break;
197
                break;
199
            }
198
            }
200
        if (curidx == -1) {
199
        if (curidx == -1) {
201
            /* Too many breakpoints */
200
            /* Too many breakpoints */
202
            spinlock_unlock(&bkpoint_lock);
201
            spinlock_unlock(&bkpoint_lock);
203
            interrupts_restore(ipl);
202
            interrupts_restore(ipl);
204
            return -1;
203
            return -1;
205
        }
204
        }
206
    }
205
    }
207
    cur = &breakpoints[curidx];
206
    cur = &breakpoints[curidx];
208
 
207
 
209
    cur->address = (__address) where;
208
    cur->address = (__address) where;
210
    cur->flags = flags;
209
    cur->flags = flags;
211
    cur->counter = 0;
210
    cur->counter = 0;
212
 
211
 
213
    setup_dr(curidx);
212
    setup_dr(curidx);
214
 
213
 
215
    spinlock_unlock(&bkpoint_lock);
214
    spinlock_unlock(&bkpoint_lock);
216
    interrupts_restore(ipl);
215
    interrupts_restore(ipl);
217
 
216
 
218
    /* Send IPI */
217
    /* Send IPI */
219
#ifdef CONFIG_SMP
218
#ifdef CONFIG_SMP
220
//  ipi_broadcast(VECTOR_DEBUG_IPI);    
219
//  ipi_broadcast(VECTOR_DEBUG_IPI);    
221
#endif  
220
#endif  
222
 
221
 
223
    return curidx;
222
    return curidx;
224
}
223
}
225
 
224
 
226
#ifdef amd64
225
#ifdef amd64
227
# define getip(x)  ((x)->rip)
226
# define getip(x)  ((x)->rip)
228
#else
227
#else
229
# define getip(x)  ((x)->eip)
228
# define getip(x)  ((x)->eip)
230
#endif
229
#endif
231
 
230
 
232
static void handle_exception(int slot, istate_t *istate)
231
static void handle_exception(int slot, istate_t *istate)
233
{
232
{
234
    ASSERT(breakpoints[slot].address);
233
    ASSERT(breakpoints[slot].address);
235
 
234
 
236
    /* Handle zero checker */
235
    /* Handle zero checker */
237
    if (! (breakpoints[slot].flags & BKPOINT_INSTR)) {
236
    if (! (breakpoints[slot].flags & BKPOINT_INSTR)) {
238
        if ((breakpoints[slot].flags & BKPOINT_CHECK_ZERO)) {
237
        if ((breakpoints[slot].flags & BKPOINT_CHECK_ZERO)) {
239
            if (*((__native *) breakpoints[slot].address) != 0)
238
            if (*((__native *) breakpoints[slot].address) != 0)
240
                return;
239
                return;
241
            printf("**** Found ZERO on address %p ****\n",
240
            printf("**** Found ZERO on address %p ****\n",
242
                   slot, breakpoints[slot].address);
241
                   slot, breakpoints[slot].address);
243
        } else {
242
        } else {
244
            printf("Data watchpoint - new data: %p\n",
243
            printf("Data watchpoint - new data: %p\n",
245
                   *((__native *) breakpoints[slot].address));
244
                   *((__native *) breakpoints[slot].address));
246
        }
245
        }
247
    }
246
    }
248
    printf("Reached breakpoint %d:%p(%s)\n", slot, getip(istate),
247
    printf("Reached breakpoint %d:%p(%s)\n", slot, getip(istate),
249
           get_symtab_entry(getip(istate)));
248
           get_symtab_entry(getip(istate)));
250
    printf("***Type 'exit' to exit kconsole.\n");
249
    printf("***Type 'exit' to exit kconsole.\n");
251
    atomic_set(&haltstate,1);
250
    atomic_set(&haltstate,1);
252
    kconsole("debug");
251
    kconsole("debug");
253
    atomic_set(&haltstate,0);
252
    atomic_set(&haltstate,0);
254
}
253
}
255
 
254
 
256
void breakpoint_del(int slot)
255
void breakpoint_del(int slot)
257
{
256
{
258
    bpinfo_t *cur;
257
    bpinfo_t *cur;
259
    ipl_t ipl;
258
    ipl_t ipl;
260
 
259
 
261
    ipl = interrupts_disable();
260
    ipl = interrupts_disable();
262
    spinlock_lock(&bkpoint_lock);
261
    spinlock_lock(&bkpoint_lock);
263
 
262
 
264
    cur = &breakpoints[slot];
263
    cur = &breakpoints[slot];
265
    if (!cur->address) {
264
    if (!cur->address) {
266
        spinlock_unlock(&bkpoint_lock);
265
        spinlock_unlock(&bkpoint_lock);
267
        interrupts_restore(ipl);
266
        interrupts_restore(ipl);
268
        return;
267
        return;
269
    }
268
    }
270
 
269
 
271
    cur->address = NULL;
270
    cur->address = NULL;
272
 
271
 
273
    setup_dr(slot);
272
    setup_dr(slot);
274
 
273
 
275
    spinlock_unlock(&bkpoint_lock);
274
    spinlock_unlock(&bkpoint_lock);
276
    interrupts_restore(ipl);
275
    interrupts_restore(ipl);
277
#ifdef CONFIG_SMP
276
#ifdef CONFIG_SMP
278
//  ipi_broadcast(VECTOR_DEBUG_IPI);    
277
//  ipi_broadcast(VECTOR_DEBUG_IPI);    
279
#endif
278
#endif
280
}
279
}
281
 
280
 
282
#ifndef CONFIG_DEBUG_AS_WATCHPOINT
281
#ifndef CONFIG_DEBUG_AS_WATCHPOINT
283
 
282
 
284
/** Remove breakpoint from table */
283
/** Remove breakpoint from table */
285
int cmd_del_breakpoint(cmd_arg_t *argv)
284
int cmd_del_breakpoint(cmd_arg_t *argv)
286
{
285
{
287
    if (argv->intval < 0 || argv->intval > BKPOINTS_MAX) {
286
    if (argv->intval < 0 || argv->intval > BKPOINTS_MAX) {
288
        printf("Invalid breakpoint number.\n");
287
        printf("Invalid breakpoint number.\n");
289
        return 0;
288
        return 0;
290
    }
289
    }
291
    breakpoint_del(argv->intval);
290
    breakpoint_del(argv->intval);
292
    return 1;
291
    return 1;
293
}
292
}
294
 
293
 
295
/** Add new breakpoint to table */
294
/** Add new breakpoint to table */
296
static int cmd_add_breakpoint(cmd_arg_t *argv)
295
static int cmd_add_breakpoint(cmd_arg_t *argv)
297
{
296
{
298
    int flags;
297
    int flags;
299
    int id;
298
    int id;
300
 
299
 
301
    if (argv == &add_argv) {
300
    if (argv == &add_argv) {
302
        flags = BKPOINT_INSTR;
301
        flags = BKPOINT_INSTR;
303
    } else { /* addwatchp */
302
    } else { /* addwatchp */
304
        flags = BKPOINT_WRITE;
303
        flags = BKPOINT_WRITE;
305
    }
304
    }
306
    printf("Adding breakpoint on address: %p\n", argv->intval);
305
    printf("Adding breakpoint on address: %p\n", argv->intval);
307
    id = breakpoint_add((void *)argv->intval, flags, -1);
306
    id = breakpoint_add((void *)argv->intval, flags, -1);
308
    if (id < 0)
307
    if (id < 0)
309
        printf("Add breakpoint failed.\n");
308
        printf("Add breakpoint failed.\n");
310
    else
309
    else
311
        printf("Added breakpoint %d.\n", id);
310
        printf("Added breakpoint %d.\n", id);
312
   
311
   
313
    return 1;
312
    return 1;
314
}
313
}
315
#endif
314
#endif
316
 
315
 
317
static void debug_exception(int n, istate_t *istate)
316
static void debug_exception(int n, istate_t *istate)
318
{
317
{
319
    __native dr6;
318
    __native dr6;
320
    int i;
319
    int i;
321
   
320
   
322
    /* Set RF to restart the instruction  */
321
    /* Set RF to restart the instruction  */
323
#ifdef amd64       
322
#ifdef amd64       
324
    istate->rflags |= RFLAGS_RF;
323
    istate->rflags |= RFLAGS_RF;
325
#else
324
#else
326
    istate->eflags |= EFLAGS_RF;
325
    istate->eflags |= EFLAGS_RF;
327
#endif
326
#endif
328
 
327
 
329
    dr6 = read_dr6();
328
    dr6 = read_dr6();
330
    for (i=0; i < BKPOINTS_MAX; i++) {
329
    for (i=0; i < BKPOINTS_MAX; i++) {
331
        if (dr6 & (1 << i)) {
330
        if (dr6 & (1 << i)) {
332
            dr6 &= ~ (1 << i);
331
            dr6 &= ~ (1 << i);
333
            write_dr6(dr6);
332
            write_dr6(dr6);
334
           
333
           
335
            handle_exception(i, istate);
334
            handle_exception(i, istate);
336
        }
335
        }
337
    }
336
    }
338
}
337
}
339
 
338
 
340
#ifdef CONFIG_SMP
339
#ifdef CONFIG_SMP
341
static void debug_ipi(int n, istate_t *istate)
340
static void debug_ipi(int n, istate_t *istate)
342
{
341
{
343
    int i;
342
    int i;
344
 
343
 
345
    spinlock_lock(&bkpoint_lock);
344
    spinlock_lock(&bkpoint_lock);
346
    for (i=0; i < BKPOINTS_MAX; i++)
345
    for (i=0; i < BKPOINTS_MAX; i++)
347
        setup_dr(i);
346
        setup_dr(i);
348
    spinlock_unlock(&bkpoint_lock);
347
    spinlock_unlock(&bkpoint_lock);
349
}
348
}
350
#endif
349
#endif
351
 
350
 
352
/** Initialize debugger */
351
/** Initialize debugger */
353
void debugger_init()
352
void debugger_init()
354
{
353
{
355
    int i;
354
    int i;
356
 
355
 
357
    for (i=0; i<BKPOINTS_MAX; i++)
356
    for (i=0; i<BKPOINTS_MAX; i++)
358
        breakpoints[i].address = NULL;
357
        breakpoints[i].address = NULL;
359
   
358
   
360
    cmd_initialize(&bkpts_info);
359
    cmd_initialize(&bkpts_info);
361
    if (!cmd_register(&bkpts_info))
360
    if (!cmd_register(&bkpts_info))
362
        panic("could not register command %s\n", bkpts_info.name);
361
        panic("could not register command %s\n", bkpts_info.name);
363
 
362
 
364
#ifndef CONFIG_DEBUG_AS_WATCHPOINT
363
#ifndef CONFIG_DEBUG_AS_WATCHPOINT
365
    cmd_initialize(&delbkpt_info);
364
    cmd_initialize(&delbkpt_info);
366
    if (!cmd_register(&delbkpt_info))
365
    if (!cmd_register(&delbkpt_info))
367
        panic("could not register command %s\n", delbkpt_info.name);
366
        panic("could not register command %s\n", delbkpt_info.name);
368
 
367
 
369
    cmd_initialize(&addbkpt_info);
368
    cmd_initialize(&addbkpt_info);
370
    if (!cmd_register(&addbkpt_info))
369
    if (!cmd_register(&addbkpt_info))
371
        panic("could not register command %s\n", addbkpt_info.name);
370
        panic("could not register command %s\n", addbkpt_info.name);
372
 
371
 
373
    cmd_initialize(&addwatchp_info);
372
    cmd_initialize(&addwatchp_info);
374
    if (!cmd_register(&addwatchp_info))
373
    if (!cmd_register(&addwatchp_info))
375
        panic("could not register command %s\n", addwatchp_info.name);
374
        panic("could not register command %s\n", addwatchp_info.name);
376
#endif
375
#endif
377
   
376
   
378
    exc_register(VECTOR_DEBUG, "debugger",
377
    exc_register(VECTOR_DEBUG, "debugger",
379
             debug_exception);
378
             debug_exception);
380
#ifdef CONFIG_SMP
379
#ifdef CONFIG_SMP
381
    exc_register(VECTOR_DEBUG_IPI, "debugger_smp",
380
    exc_register(VECTOR_DEBUG_IPI, "debugger_smp",
382
             debug_ipi);
381
             debug_ipi);
383
#endif
382
#endif
384
}
383
}
385
 
384
 
386
 /** @}
385
 /** @}
387
 */
386
 */
388
 
387
 
389
 
388